cvsuser 03/11/03 23:47:02
Modified: imcc optimizer.h optimizer.c parser.h parser_util.c
pbc.h pbc.c
Log:
Huge ugly patch that I've been dreading. Finally IMCC collects all
compilation units before proceeding to the compile and emit steps.
This is vital for us to move forward. This breaks a couple of things
with bytecode loading (sub and eval tests failing), will fix soon
if Leo doesn't get to it first. :)
Revision Changes Path
1.9 +4 -4 parrot/imcc/optimizer.h
Index: optimizer.h
===================================================================
RCS file: /cvs/public/parrot/imcc/optimizer.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -r1.8 -r1.9
--- optimizer.h 23 Oct 2003 17:02:49 -0000 1.8
+++ optimizer.h 4 Nov 2003 07:47:01 -0000 1.9
@@ -1,8 +1,8 @@
#ifndef __OPTIMIZER_H
#define __OPTIMIZER_H
-void pre_optimize(struct Parrot_Interp *);
-int cfg_optimize(struct Parrot_Interp *);
-int optimize(struct Parrot_Interp *);
-void post_optimize(struct Parrot_Interp *);
+void pre_optimize(struct Parrot_Interp *, IMC_Unit *);
+int cfg_optimize(struct Parrot_Interp *, IMC_Unit *);
+int optimize(struct Parrot_Interp *, IMC_Unit *);
+void post_optimize(struct Parrot_Interp *, IMC_Unit *);
#endif
1.42 +132 -129 parrot/imcc/optimizer.c
Index: optimizer.c
===================================================================
RCS file: /cvs/public/parrot/imcc/optimizer.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -w -r1.41 -r1.42
--- optimizer.c 4 Nov 2003 01:25:07 -0000 1.41
+++ optimizer.c 4 Nov 2003 07:47:01 -0000 1.42
@@ -44,71 +44,72 @@
* because Px where different before
*
*/
-static void if_branch(struct Parrot_Interp *);
+static void if_branch(struct Parrot_Interp *, IMC_Unit *);
-static int branch_branch(struct Parrot_Interp *interpreter);
-static int unused_label(struct Parrot_Interp *interpreter);
-static int dead_code_remove(struct Parrot_Interp *interpreter);
-
-static void strength_reduce(struct Parrot_Interp *interpreter);
-static void subst_constants_mix(struct Parrot_Interp *interpreter);
-static void subst_constants_umix(struct Parrot_Interp *interpreter);
-static void subst_constants(struct Parrot_Interp *interpreter);
-static void subst_constants_c(struct Parrot_Interp *interpreter);
-static void subst_constants_if(struct Parrot_Interp *interpreter);
-
-static int constant_propagation(struct Parrot_Interp *interpreter);
-static int used_once(struct Parrot_Interp *);
-static int loop_optimization(struct Parrot_Interp *);
-static int clone_remove(struct Parrot_Interp *);
+static int branch_branch(struct Parrot_Interp *interpreter, IMC_Unit *);
+static int unused_label(struct Parrot_Interp *interpreter, IMC_Unit *);
+static int dead_code_remove(struct Parrot_Interp *interpreter, IMC_Unit *);
+
+static void strength_reduce(struct Parrot_Interp *interpreter, IMC_Unit *);
+static void subst_constants_mix(struct Parrot_Interp *interpreter, IMC_Unit *);
+static void subst_constants_umix(struct Parrot_Interp *interpreter, IMC_Unit *);
+static void subst_constants(struct Parrot_Interp *interpreter, IMC_Unit *);
+static void subst_constants_c(struct Parrot_Interp *interpreter, IMC_Unit *);
+static void subst_constants_if(struct Parrot_Interp *interpreter, IMC_Unit *);
+
+static int constant_propagation(struct Parrot_Interp *interpreter, IMC_Unit *);
+static int used_once(struct Parrot_Interp *, IMC_Unit *);
+static int loop_optimization(struct Parrot_Interp *, IMC_Unit *);
+static int clone_remove(struct Parrot_Interp *, IMC_Unit *);
void
-pre_optimize(struct Parrot_Interp *interpreter)
+pre_optimize(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
if (optimizer_level & OPT_PRE) {
info(interpreter, 2, "pre_optimize\n");
- subst_constants_mix(interpreter);
- subst_constants_umix(interpreter);
- subst_constants(interpreter);
- subst_constants_c(interpreter);
- subst_constants_if(interpreter);
- strength_reduce(interpreter);
+ subst_constants_mix(interpreter, unit);
+ subst_constants_umix(interpreter, unit);
+ subst_constants(interpreter, unit);
+ subst_constants_c(interpreter, unit);
+ subst_constants_if(interpreter, unit);
+ strength_reduce(interpreter, unit);
if (!dont_optimize)
- if_branch(interpreter);
+ if_branch(interpreter, unit);
}
}
int
-cfg_optimize(struct Parrot_Interp *interpreter)
+cfg_optimize(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
UNUSED(interpreter);
+
if (dont_optimize)
return 0;
if (optimizer_level & OPT_PRE) {
info(interpreter, 2, "cfg_optimize\n");
- if (branch_branch(interpreter))
+ if (branch_branch(interpreter, unit))
return 1;
/* XXX cfg / loop detection breaks e.g. in t/compiler/5_3 */
- if (unused_label(interpreter))
+ if (unused_label(interpreter, unit))
return 1;
- if (dead_code_remove(interpreter))
+ if (dead_code_remove(interpreter, unit))
return 1;
}
return 0;
}
int
-optimize(struct Parrot_Interp *interpreter)
+optimize(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
int any = 0;
if (optimizer_level & OPT_CFG) {
info(interpreter, 2, "optimize\n");
- any = constant_propagation(interpreter);
- if (0 && clone_remove(interpreter))
+ any = constant_propagation(interpreter, unit);
+ if (0 && clone_remove(interpreter, unit))
return 1;
- if (used_once(interpreter))
+ if (used_once(interpreter, unit))
return 1;
- if (loop_optimization(interpreter))
+ if (loop_optimization(interpreter, unit))
return 1;
}
return any;
@@ -145,12 +146,12 @@
* L1: L2:
*/
static void
-if_branch(struct Parrot_Interp *interpreter)
+if_branch(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *last;
int reg;
- last = instructions;
+ last = unit->instructions;
if (!last->next)
return;
info(interpreter, 2, "\tif_branch\n");
@@ -173,7 +174,7 @@
if ((neg_op = get_neg_op(last->op, &args)) != 0) {
Instruction * tmp;
last->r[reg] = go;
- tmp = INS(interpreter, (char*)neg_op, "", last->r, args, 0, 0);
+ tmp = INS(interpreter, unit, (char*)neg_op, "", last->r, args,
0, 0);
last->opnum = tmp->opnum;
last->opsize = tmp->opsize;
free(last->op);
@@ -182,7 +183,7 @@
/* delete branch */
ostat.deleted_ins++;
- ins = delete_ins(ins, 1);
+ ins = delete_ins(unit, ins, 1);
ostat.if_branch++;
}
} /* label found */
@@ -196,7 +197,7 @@
* guaranteed, that one operand is non constant, if opsize == 4
*/
static void
-strength_reduce(struct Parrot_Interp *interpreter)
+strength_reduce(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *tmp;
const char *ops[] = { "add", "sub", "mul", "div" };
@@ -204,7 +205,7 @@
SymReg *r;
info(interpreter, 2, "\tstrength_reduce\n");
- for (ins = instructions; ins; ins = ins->next) {
+ for (ins = unit->instructions; ins; ins = ins->next) {
/*
* add Ix, Ix, Iy => add Ix, Iy
* sub Ix, Ix, Iy => sub Ix, Iy
@@ -218,9 +219,9 @@
!strcmp(ins->op, ops[i])) {
debug(interpreter, DEBUG_OPT1, "opt1 %I => ", ins);
ins->r[1] = ins->r[2];
- tmp = INS(interpreter, ins->op, "", ins->r, 2, 0, 0);
+ tmp = INS(interpreter, unit, ins->op, "", ins->r, 2, 0, 0);
debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
- subst_ins(ins, tmp, 1);
+ subst_ins(unit, ins, tmp, 1);
ins = tmp;
found = 1;
break;
@@ -246,9 +247,9 @@
if (ins->opsize == 4)
--ins->r[2]->use_count;
ins->r[1] = r;
- tmp = INS(interpreter, "set", "", ins->r, 2, 0, 0);
+ tmp = INS(interpreter, unit, "set", "", ins->r, 2, 0, 0);
debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
- subst_ins(ins, tmp, 1);
+ subst_ins(unit, ins, tmp, 1);
ins = tmp;
continue;
}
@@ -268,8 +269,8 @@
debug(interpreter, DEBUG_OPT1, "opt1 %I => ", ins);
if (ins->opsize == 3) {
/* mul Ix, 1 */
- ins = delete_ins(ins, 1);
- ins = ins->prev ? ins->prev : instructions;
+ ins = delete_ins(unit, ins, 1);
+ ins = ins->prev ? ins->prev : unit->instructions;
debug(interpreter, DEBUG_OPT1, "deleted\n");
continue;
}
@@ -280,9 +281,9 @@
else {
--ins->r[2]->use_count;
}
- tmp = INS(interpreter, "set", "", ins->r, 2, 0, 0);
+ tmp = INS(interpreter, unit, "set", "", ins->r, 2, 0, 0);
debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
- subst_ins(ins, tmp, 1);
+ subst_ins(unit, ins, tmp, 1);
ins = tmp;
continue;
}
@@ -310,7 +311,7 @@
*/
static int
-constant_propagation(struct Parrot_Interp *interpreter)
+constant_propagation(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *ins2;
int op;
@@ -320,7 +321,7 @@
int any = 0;
info(interpreter, 2, "\tconstant_propagation\n");
- for (ins = instructions; ins; ins = ins->next) {
+ for (ins = unit->instructions; ins; ins = ins->next) {
if (!strcmp(ins->op, "set") &&
ins->opsize == 3 && /* no keyed set */
ins->r[1]->type == VTCONST &&
@@ -377,7 +378,7 @@
* rewrite e.g. add_n_nc_ic => add_n_nc_nc
*/
static void
-subst_constants_mix(struct Parrot_Interp *interpreter)
+subst_constants_mix(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *tmp;
const char *ops[] = {
@@ -388,7 +389,7 @@
SymReg *r;
info(interpreter, 2, "\tsubst_constants_mix\n");
- for (ins = instructions; ins; ins = ins->next) {
+ for (ins = unit->instructions; ins; ins = ins->next) {
for (i = 0; i < sizeof(ops)/sizeof(ops[0]); i++) {
/* TODO compare ins->opnum with a list of instructions
* containing add_n_nc_ic, ...
@@ -403,9 +404,9 @@
r = mk_const(str_dup(b), 'N');
--ins->r[2]->use_count;
ins->r[2] = r;
- tmp = INS(interpreter, ins->op, "", ins->r, 3, 0, 0);
+ tmp = INS(interpreter, unit, ins->op, "", ins->r, 3, 0, 0);
debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
- subst_ins(ins, tmp, 1);
+ subst_ins(unit, ins, tmp, 1);
ins = tmp;
}
}
@@ -416,7 +417,7 @@
* rewrite e.g. add_n_ic => add_n_nc
*/
static void
-subst_constants_umix(struct Parrot_Interp *interpreter)
+subst_constants_umix(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *tmp;
const char *ops[] = {
@@ -427,7 +428,7 @@
SymReg *r;
info(interpreter, 2, "\tsubst_constants_umix\n");
- for (ins = instructions; ins; ins = ins->next) {
+ for (ins = unit->instructions; ins; ins = ins->next) {
for (i = 0; i < sizeof(ops)/sizeof(ops[0]); i++) {
/* TODO compare ins->opnum with a list of instructions
* containing add_n_ic, ...
@@ -442,9 +443,9 @@
r = mk_const(str_dup(b), 'N');
--ins->r[1]->use_count;
ins->r[1] = r;
- tmp = INS(interpreter, ins->op, "", ins->r, 2, 0, 0);
+ tmp = INS(interpreter, unit, ins->op, "", ins->r, 2, 0, 0);
debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
- subst_ins(ins, tmp, 1);
+ subst_ins(unit, ins, tmp, 1);
ins = tmp;
}
}
@@ -508,7 +509,7 @@
* or abs_i_ic => set_i_ic
*/
static void
-subst_constants(struct Parrot_Interp *interpreter)
+subst_constants(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *tmp;
const char *ops[] = {
@@ -546,7 +547,7 @@
break;
}
- for (ins = instructions; ins; ins = ins->next) {
+ for (ins = unit->instructions; ins; ins = ins->next) {
found = 0;
for (i = 0; i < sizeof(ops)/sizeof(ops[0]); i++) {
/* TODO compare ins->opnum with a list of instructions
@@ -591,9 +592,9 @@
if (ins->opsize == 4)
--ins->r[2]->use_count;
ins->r[1] = r;
- tmp = INS(interpreter, "set", "", ins->r, 2, 0, 0);
+ tmp = INS(interpreter, unit, "set", "", ins->r, 2, 0, 0);
debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
- subst_ins(ins, tmp, 1);
+ subst_ins(unit, ins, tmp, 1);
ins = tmp;
}
mem_sys_memcopy(&interpreter->ctx, ctx, sizeof(struct Parrot_Context));
@@ -604,7 +605,7 @@
* rewrite e.g. eq_ic_ic_ic => branch_ic/nothing
*/
static void
-subst_constants_c(struct Parrot_Interp *interpreter)
+subst_constants_c(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *tmp;
const char *ops[] = { "eq", "ne", "gt", "ge", "lt", "le" };
@@ -612,7 +613,7 @@
int res;
info(interpreter, 2, "\tsubst_constants_c\n");
- for (ins = instructions; ins; ins = ins->next) {
+ for (ins = unit->instructions; ins; ins = ins->next) {
for (i = 0; i < sizeof(ops)/sizeof(ops[0]); i++) {
/* TODO s. above */
if (ins->opsize == 4 &&
@@ -631,16 +632,16 @@
--ins->r[1]->use_count;
if (res) {
ins->r[0] = ins->r[2];
- tmp = INS(interpreter, "branch", "", ins->r,
+ tmp = INS(interpreter, unit, "branch", "",
ins->r,
1, 0, 0);
debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
- subst_ins(ins, tmp, 1);
+ subst_ins(unit, ins, tmp, 1);
ins = tmp;
}
else {
debug(interpreter, DEBUG_OPT1, "deleted\n");
- ins = delete_ins(ins, 1);
- ins = ins->prev ? ins->prev : instructions;
+ ins = delete_ins(unit, ins, 1);
+ ins = ins->prev ? ins->prev :
unit->instructions;
}
break;
case 'N':
@@ -743,7 +744,7 @@
* rewrite e.g. if_ic_ic => branch_ic/nothing
*/
static void
-subst_constants_if(struct Parrot_Interp *interpreter)
+subst_constants_if(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *tmp;
const char *ops[] = { "if", "unless" };
@@ -751,7 +752,7 @@
int res;
info(interpreter, 2, "\tsubst_constants_if\n");
- for (ins = instructions; ins; ins = ins->next) {
+ for (ins = unit->instructions; ins; ins = ins->next) {
for (i = 0; i < sizeof(ops)/sizeof(ops[0]); i++) {
/* TODO s. above */
if (ins->opsize == 3 &&
@@ -770,16 +771,16 @@
res = !res;
if (res) {
ins->r[0] = ins->r[1];
- tmp = INS(interpreter, "branch", "", ins->r,
+ tmp = INS(interpreter, unit, "branch", "",
ins->r,
1, 0, 0);
debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
- subst_ins(ins, tmp, 1);
+ subst_ins(unit, ins, tmp, 1);
ins = tmp;
}
else {
debug(interpreter, DEBUG_OPT1, "deleted\n");
- ins = delete_ins(ins, 1);
- ins = ins->prev ? ins->prev : instructions;
+ ins = delete_ins(unit, ins, 1);
+ ins = ins->prev ? ins->prev :
unit->instructions;
}
break;
case 'N':
@@ -815,7 +816,7 @@
*
*/
static int
-branch_branch(struct Parrot_Interp *interpreter)
+branch_branch(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *next;
SymReg * r;
@@ -823,7 +824,7 @@
info(interpreter, 2, "\tbranch_branch\n");
/* reset statistic globals */
- for (ins = instructions; ins; ins = ins->next) {
+ for (ins = unit->instructions; ins; ins = ins->next) {
if ((ins->type & IF_goto) && !strcmp(ins->op, "branch")) {
r = get_sym(ins->r[0]->name);
@@ -847,7 +848,7 @@
}
static int
-unused_label(struct Parrot_Interp *interpreter)
+unused_label(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins;
int used;
@@ -855,8 +856,8 @@
int changed = 0;
info(interpreter, 2, "\tunused_label\n");
- for (i=1; i < IMCC_INFO(interpreter)->n_basic_blocks; i++) {
- ins = IMCC_INFO(interpreter)->bb_list[i]->start;
+ for (i=1; i < unit->n_basic_blocks; i++) {
+ ins = unit->bb_list[i]->start;
if ((ins->type & ITLABEL) && *ins->r[0]->name != '_') {
SymReg * lab = ins->r[0];
used = 0;
@@ -872,12 +873,12 @@
Instruction *ins2;
int j;
SymReg * addr;
- for (j=0; IMCC_INFO(interpreter)->bb_list[j]; j++) {
+ for (j=0; unit->bb_list[j]; j++) {
/* a branch can be the first ins in a block
* (if prev ins was a label)
* or the last ins in a block
*/
- ins2 = IMCC_INFO(interpreter)->bb_list[j]->start;
+ ins2 = unit->bb_list[j]->start;
if ((ins2->type & ITBRANCH) &&
(addr = get_branch_reg(ins2)) != 0) {
if (addr == lab && addr->type == VTADDRESS) {
@@ -885,7 +886,7 @@
break;
}
}
- ins2 = IMCC_INFO(interpreter)->bb_list[j]->end;
+ ins2 = unit->bb_list[j]->end;
if ((ins2->type & ITBRANCH) &&
(addr = get_branch_reg(ins2)) != 0) {
if (addr == lab && addr->type == VTADDRESS) {
@@ -900,7 +901,7 @@
ostat.deleted_labels++;
debug(interpreter, DEBUG_OPT1, "block %d label %s deleted\n", i,
lab->name);
ostat.deleted_ins++;
- ins = delete_ins(ins, 1);
+ ins = delete_ins(unit, ins, 1);
changed = 1;
}
@@ -910,7 +911,7 @@
}
static int
-dead_code_remove(struct Parrot_Interp *interpreter)
+dead_code_remove(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
Basic_block *bb;
int i;
@@ -921,8 +922,8 @@
if (!(optimizer_level & OPT_PRE))
return 0;
info(interpreter, 2, "\tdead_code_remove\n");
- for (i=1; i < IMCC_INFO(interpreter)->n_basic_blocks; i++) {
- bb = IMCC_INFO(interpreter)->bb_list[i];
+ for (i=1; i < unit->n_basic_blocks; i++) {
+ bb = unit->bb_list[i];
if ((bb->start->type & ITLABEL) && *bb->start->r[0]->name == '_')
continue;
/* this block isn't entered from anywhere */
@@ -932,18 +933,18 @@
for (ins = bb->start; ins && ins->bbindex == bbi; ) {
debug(interpreter, DEBUG_OPT1,
"\tins deleted (dead block) %I\n", ins);
- ins = delete_ins(ins, 1);
+ ins = delete_ins(unit, ins, 1);
ostat.deleted_ins++;
changed++;
}
}
}
- for (last = instructions, ins=last->next; last && ins; ins = ins->next) {
+ for (last = unit->instructions, ins=last->next; last && ins; ins = ins->next) {
if ((last->type & IF_goto) && !(ins->type & ITLABEL) &&
!strcmp(last->op, "branch")) {
debug(interpreter, DEBUG_OPT1,
"unreachable ins deleted (after branch) %I\n", ins);
- ins = delete_ins(ins, 1);
+ ins = delete_ins(unit, ins, 1);
ostat.deleted_ins++;
changed++;
}
@@ -955,7 +956,7 @@
!strcmp(last->op, "branch") &&
!strcmp(last->r[0]->name, ins->r[0]->name)) {
debug(interpreter, DEBUG_OPT1, "dead branch deleted %I\n", ins);
- ins = delete_ins(last, 1);
+ ins = delete_ins(unit, last, 1);
ostat.deleted_ins++;
changed++;
}
@@ -968,13 +969,13 @@
/* optimizations with CFG & life info built */
static int
-used_once(Parrot_Interp interpreter)
+used_once(Parrot_Interp interpreter, IMC_Unit * unit)
{
Instruction *ins;
SymReg * r;
int opt = 0;
- for (ins = instructions; ins; ins = ins->next) {
+ for (ins = unit->instructions; ins; ins = ins->next) {
if (!ins->r)
continue;
r = ins->r[0];
@@ -982,8 +983,8 @@
continue;
if (r->use_count == 1 && r->lhs_use_count == 1) {
debug(interpreter, DEBUG_OPT2, "used once '%I' deleted\n", ins);
- ins = delete_ins(ins, 1);
- ins = ins->prev ? ins->prev : instructions;
+ ins = delete_ins(unit, ins, 1);
+ ins = ins->prev ? ins->prev : unit->instructions;
ostat.deleted_ins++;
ostat.used_once++;
opt++;
@@ -993,13 +994,13 @@
}
static int
-max_loop_depth(Parrot_Interp interpreter)
+max_loop_depth(IMC_Unit * unit)
{
int i, d;
d = 0;
- for (i = 0; i < IMCC_INFO(interpreter)->n_basic_blocks; i++)
- if (IMCC_INFO(interpreter)->bb_list[i]->loop_depth > d)
- d = IMCC_INFO(interpreter)->bb_list[i]->loop_depth;
+ for (i = 0; i < unit->n_basic_blocks; i++)
+ if (unit->bb_list[i]->loop_depth > d)
+ d = unit->bb_list[i]->loop_depth;
return d;
}
@@ -1007,7 +1008,7 @@
enum check_t { CHK_INV_NEW, CHK_INV_SET, CHK_CLONE };
static int
-_is_ins_save(Parrot_Interp interpreter, Instruction *check_ins,
+_is_ins_save(IMC_Unit * unit, Instruction *check_ins,
SymReg *r, int what)
{
Instruction *ins;
@@ -1035,7 +1036,7 @@
use_count = r->use_count;
lhs_use_count = r->lhs_use_count;
- for (bb = 0; bb < IMCC_INFO(interpreter)->n_basic_blocks; bb++) {
+ for (bb = 0; bb < unit->n_basic_blocks; bb++) {
Life_range *lr = r->life_info[bb];
for (ins = lr->first_ins; ins; ins = ins->next) {
@@ -1096,11 +1097,12 @@
}
static int
-is_ins_save(Parrot_Interp interpreter, Instruction *ins, SymReg *r, int what) {
+is_ins_save(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins, SymReg
*r, int what)
+{
int save;
reason = 0;
- save = _is_ins_save(interpreter, ins, r, what);
+ save = _is_ins_save(unit, ins, r, what);
if (!save && reason)
debug(interpreter, DEBUG_OPT2, "ins not save var %s reason %d %I\n",
r->name, reason, ins);
@@ -1108,7 +1110,7 @@
}
static int
-is_invariant(Parrot_Interp interpreter, Instruction *ins)
+is_invariant(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins)
{
int ok = 0;
int what = 0;
@@ -1125,32 +1127,33 @@
what = CHK_INV_SET;
}
if (ok)
- return is_ins_save(interpreter, ins, ins->r[0], what);
+ return is_ins_save(interpreter, unit, ins, ins->r[0], what);
return 0;
}
#define MOVE_INS_1_BL
#ifdef MOVE_INS_1_BL
static Basic_block *
-find_outer(Parrot_Interp interpreter, Basic_block * blk)
+find_outer(IMC_Unit * unit, Basic_block * blk)
{
int bb = blk->index;
int i;
- int n_loops = IMCC_INFO(interpreter)->n_loops;
- Loop_info ** loop_info = IMCC_INFO(interpreter)->loop_info;
+ int n_loops = unit->n_loops;
+ Loop_info ** loop_info = unit->loop_info;
/* loops are sorted depth last */
for (i = n_loops-1; i >= 0; i--)
if (set_contains(loop_info[i]->loop, bb))
if (loop_info[i]->entry >= 0)
- return IMCC_INFO(interpreter)->bb_list[loop_info[i]->entry];
+ return unit->bb_list[loop_info[i]->entry];
return 0;
}
#endif
/* move the instruction ins before loop in bb */
static int
-move_ins_out(struct Parrot_Interp *interpreter, Instruction **ins, Basic_block *bb)
+move_ins_out(struct Parrot_Interp *interpreter, IMC_Unit * unit,
+ Instruction **ins, Basic_block *bb)
{
Basic_block *pred;
Instruction * next, *out;
@@ -1158,10 +1161,10 @@
/* check loop_info, where this loop started
* actually, this moves instruction to block 0 */
#ifdef MOVE_INS_1_BL
- pred = find_outer(interpreter, bb);
+ pred = find_outer(unit, bb);
#else
UNUSED(bb);
- pred = IMCC_INFO(interpreter)->bb_list[0];
+ pred = unit->bb_list[0];
#endif
if (!pred) {
debug(interpreter, DEBUG_OPT2, "outer loop not found (CFG?)\n");
@@ -1172,7 +1175,7 @@
(*ins)->bbindex = pred->index;
debug(interpreter, DEBUG_OPT2, "inserting it in blk %d after %I\n",
pred->index, out);
- *ins = move_ins(*ins, out);
+ *ins = move_ins(unit, *ins, out);
if (0 && (DEBUG_OPT2 & IMCC_INFO(interpreter)->debug)) {
char buf[256];
SymReg * regs[IMCC_MAX_REGS];
@@ -1180,8 +1183,8 @@
regs[0] = 0;
sprintf(buf, "# Invar moved: %s",out->next->op);
- tmp = INS(interpreter, "", buf, regs, 0, 0, 0);
- insert_ins((*ins)->prev, tmp);
+ tmp = INS(interpreter, unit, "", buf, regs, 0, 0, 0);
+ insert_ins(unit, (*ins)->prev, tmp);
}
ostat.invariants_moved++;
/* XXX CFG is changed here, which also means
@@ -1191,9 +1194,9 @@
}
static int
-loop_one(struct Parrot_Interp *interpreter, int bnr)
+loop_one(struct Parrot_Interp *interpreter, IMC_Unit * unit, int bnr)
{
- Basic_block *bb = IMCC_INFO(interpreter)->bb_list[bnr];
+ Basic_block *bb = unit->bb_list[bnr];
Instruction *ins;
int changed = 0;
@@ -1204,9 +1207,9 @@
debug(interpreter, DEBUG_OPT2, "loop_one blk %d\n", bnr);
for (ins = bb->start ; ins ; ins = ins->next) {
reason = 0;
- if (is_invariant(interpreter, ins)) {
+ if (is_invariant(interpreter, unit, ins)) {
debug(interpreter, DEBUG_OPT2, "found invariant %I\n", ins);
- if (move_ins_out(interpreter, &ins, bb)) {
+ if (move_ins_out(interpreter, unit, &ins, bb)) {
changed++;
ins = ins->prev;
}
@@ -1219,20 +1222,20 @@
}
static int
-loop_optimization(struct Parrot_Interp *interpreter)
+loop_optimization(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
int l, bb, loop_depth;
int changed = 0;
static int prev_depth;
- loop_depth = prev_depth ? prev_depth : max_loop_depth(interpreter);
+ loop_depth = prev_depth ? prev_depth : max_loop_depth(unit);
/* work from inside out */
debug(interpreter, DEBUG_OPT2, "loop_optimization\n");
for (l = loop_depth; l > 0; l--) {
debug(interpreter, DEBUG_OPT2, "loop_depth %d\n", l);
- for (bb = 0; bb < IMCC_INFO(interpreter)->n_basic_blocks; bb++)
- if (IMCC_INFO(interpreter)->bb_list[bb]->loop_depth == l) {
- changed |= loop_one(interpreter, bb);
+ for (bb = 0; bb < unit->n_basic_blocks; bb++)
+ if (unit->bb_list[bb]->loop_depth == l) {
+ changed |= loop_one(interpreter, unit, bb);
}
/* currently e.g. mandel.p6 breaks, if not only the most
* inner loop is changed, but outer loops too */
@@ -1240,7 +1243,7 @@
prev_depth = l-1;
debug(interpreter, DEBUG_OPT2,"after loop_opt\n");
if (IMCC_INFO(interpreter)->debug>1)
- dump_instructions(interpreter);
+ dump_instructions(unit);
return changed;
}
}
@@ -1249,12 +1252,12 @@
}
static int
-check_clone(Parrot_Interp interpreter, Instruction *ins)
+check_clone(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins)
{
SymReg * rl = ins->r[0];
SymReg * rr = ins->r[1];
- if (0 && is_ins_save(interpreter, ins, rl, CHK_CLONE) &&
- is_ins_save(interpreter, ins, rr, CHK_CLONE)) {
+ if (0 && is_ins_save(interpreter, unit, ins, rl, CHK_CLONE) &&
+ is_ins_save(interpreter, unit, ins, rr, CHK_CLONE)) {
debug(interpreter, DEBUG_OPT2, "clone %I removed\n", ins);
free(ins->op);
ins->op = str_dup("set");
@@ -1264,14 +1267,14 @@
}
static int
-clone_remove(Parrot_Interp interpreter)
+clone_remove(Parrot_Interp interpreter, IMC_Unit * unit)
{
Instruction *ins;
int changes = 0;
debug(interpreter, DEBUG_OPT2, "clone_remove\n");
- for (ins = instructions; ins; ins = ins->next)
+ for (ins = unit->instructions; ins; ins = ins->next)
if (!strcmp(ins->op, "clone"))
- changes |= check_clone(interpreter, ins);
+ changes |= check_clone(interpreter, unit, ins);
return changes;
}
1.14 +2 -2 parrot/imcc/parser.h
Index: parser.h
===================================================================
RCS file: /cvs/public/parrot/imcc/parser.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- parser.h 23 Oct 2003 17:02:49 -0000 1.13
+++ parser.h 4 Nov 2003 07:47:01 -0000 1.14
@@ -30,8 +30,8 @@
void register_compilers(Parrot_Interp);
void *imcc_eval_pasm(Parrot_Interp, const char *s);
void *imcc_eval_pir (Parrot_Interp, const char *s);
-int try_find_op(Parrot_Interp, char *, SymReg **, int, int, int);
-Instruction * multi_keyed(struct Parrot_Interp *interpreter,char *name,
+int try_find_op(Parrot_Interp, IMC_Unit *, char *, SymReg **, int, int, int);
+Instruction * multi_keyed(struct Parrot_Interp *interpreter, IMC_Unit *, char *name,
SymReg ** r, int nr, int keyvec, int emit);
extern void compile_file(Interp *interp, FILE *file);
1.45 +34 -26 parrot/imcc/parser_util.c
Index: parser_util.c
===================================================================
RCS file: /cvs/public/parrot/imcc/parser_util.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -w -r1.44 -r1.45
--- parser_util.c 4 Nov 2003 00:37:30 -0000 1.44
+++ parser_util.c 4 Nov 2003 07:47:01 -0000 1.45
@@ -31,7 +31,7 @@
* best would be to have a flag in core.ops, where a PMC type is expected
*/
Instruction *
-iNEW(struct Parrot_Interp *interpreter, SymReg * r0, char * type,
+iNEW(struct Parrot_Interp *interpreter, IMC_Unit * unit, SymReg * r0, char * type,
SymReg *init, int emit)
{
char fmt[256];
@@ -62,7 +62,7 @@
i = nargs;
while (i < IMCC_MAX_REGS)
regs[i++] = NULL;
- return INS(interpreter, "new", fmt, regs, nargs,0, emit);
+ return INS(interpreter, unit, "new", fmt, regs, nargs,0, emit);
}
/*
@@ -80,7 +80,7 @@
*/
Instruction *
-iNEWSUB(struct Parrot_Interp *interpreter, SymReg * r0, int type,
+iNEWSUB(struct Parrot_Interp *interpreter, IMC_Unit * unit, SymReg * r0, int type,
SymReg *init, int emit)
{
char fmt[256];
@@ -121,7 +121,7 @@
i = nargs;
while (i < IMCC_MAX_REGS)
regs[i++] = NULL;
- return INS(interpreter, "newsub", NULL, regs, nargs,0, emit);
+ return INS(interpreter, unit, "newsub", NULL, regs, nargs,0, emit);
}
void
@@ -182,7 +182,8 @@
}
-int is_op(struct Parrot_Interp *interpreter, char *name)
+int
+is_op(struct Parrot_Interp *interpreter, char *name)
{
return interpreter->op_lib->op_code(name, 0) >= 0
|| interpreter->op_lib->op_code(name, 1) >= 0;
@@ -199,8 +200,8 @@
* s. e.g. imc.c for usage
*/
Instruction *
-INS(struct Parrot_Interp *interpreter, char *name, const char *fmt, SymReg **r,
- int n, int keyvec, int emit)
+INS(struct Parrot_Interp *interpreter, IMC_Unit * unit, char *name, const char *fmt,
+ SymReg **r, int n, int keyvec, int emit)
{
char fullname[64];
int i;
@@ -209,7 +210,7 @@
Instruction * ins;
#if 1
- ins = multi_keyed(interpreter, name, r, n, keyvec, emit);
+ ins = multi_keyed(interpreter, unit, name, r, n, keyvec, emit);
if (ins)
return ins;
#endif
@@ -218,7 +219,7 @@
if (op < 0) /* maybe we got a fullname */
op = interpreter->op_lib->op_code(name, 1);
if (op < 0) /* still wrong, try to find an existing op */
- op = try_find_op(interpreter, name, r, n, keyvec, emit);
+ op = try_find_op(interpreter, unit, name, r, n, keyvec, emit);
if (op >= 0) {
op_info_t * op_info = &interpreter->op_info_table[op];
char format[128];
@@ -321,7 +322,7 @@
++has_compile;
if (emit)
- emitb(ins);
+ emitb(unit, ins);
} else {
fataly(EX_SOFTWARE, sourcefile, line,"op not found '%s' (%s<%d>)\n",
fullname, name, n);
@@ -339,7 +340,8 @@
*/
extern void* yy_scan_string(const char *);
-static void *imcc_compile(Parrot_Interp interp, const char *s)
+static void *
+imcc_compile(Parrot_Interp interp, const char *s)
{
/* imcc always compiles to interp->code->byte_code
* save old cs, make new
@@ -387,7 +389,8 @@
return pf;
}
-static void *imcc_compile_pasm(Parrot_Interp interp, const char *s)
+static void *
+imcc_compile_pasm(Parrot_Interp interp, const char *s)
{
int pasm = pasm_file;
void *pf;
@@ -399,7 +402,8 @@
return pf;
}
-static void *imcc_compile_pir (Parrot_Interp interp, const char *s)
+static void *
+imcc_compile_pir (Parrot_Interp interp, const char *s)
{
int pasm = pasm_file;
void *pf;
@@ -412,7 +416,8 @@
}
-static void *imcc_compile_file (Parrot_Interp interp, const char *s)
+static void *
+imcc_compile_file (Parrot_Interp interp, const char *s)
{
struct PackFile *pf_save = interp->code;
struct PackFile *pf;
@@ -441,6 +446,8 @@
pasm_file = 0;
line = 1;
+
+ /* see imcc.l */
compile_file(interp, new);
(void)Parrot_switch_to_cs(interp, pf_save->cur_cs);
@@ -451,7 +458,8 @@
}
/* tell the parrot core, which compilers we provide */
-void register_compilers(Parrot_Interp interp)
+void
+register_compilers(Parrot_Interp interp)
{
STRING *pasm = string_from_cstring(interp, "PASM", 0);
STRING *pir = string_from_cstring(interp, "PIR", 0);
@@ -475,7 +483,7 @@
* ge_n_ic_ic => ge_n_nc_ic
*/
int
-try_find_op(Parrot_Interp interpreter, char *name, SymReg ** r,
+try_find_op(Parrot_Interp interpreter, IMC_Unit * unit, char *name, SymReg ** r,
int n, int keyvec, int emit)
{
char fullname[64];
@@ -506,7 +514,7 @@
rr[0] = mk_temp_reg('N');
rr[1] = r[1];
- INS(interpreter, "set", NULL, rr, 2, 0, 1);
+ INS(interpreter, unit, "set", NULL, rr, 2, 0, 1);
r[1] = rr[0];
changed = 1;
}
@@ -520,7 +528,7 @@
}
Instruction *
-multi_keyed(struct Parrot_Interp *interpreter,char *name,
+multi_keyed(struct Parrot_Interp *interpreter, IMC_Unit * unit, char *name,
SymReg ** r, int nr, int keyvec, int emit)
{
int i, keyf, kv, n;
@@ -571,14 +579,14 @@
nreg[1] = r[i+1];
nreg[2] = preg[n];
/* set p_k px */
- ins = INS(interpreter, str_dup("set"), 0, nreg, 3,KEY_BIT(1),0);
+ ins = INS(interpreter, unit, str_dup("set"), 0, nreg,
3,KEY_BIT(1),0);
}
else {
nreg[0] = preg[n];
nreg[1] = r[i];
nreg[2] = r[i+1];
/* set py|z p_k */
- INS(interpreter, str_dup("set"), 0, nreg, 3, KEY_BIT(2), 1);
+ INS(interpreter, unit, str_dup("set"), 0, nreg, 3, KEY_BIT(2), 1);
}
i++;
}
@@ -588,22 +596,22 @@
nreg[0] = r[i];
nreg[1] = preg[n];
/* set n, px */
- ins = INS(interpreter, str_dup("set"), 0, nreg, 2, 0, 0);
+ ins = INS(interpreter, unit, str_dup("set"), 0, nreg, 2, 0, 0);
}
else {
nreg[0] = preg[n];
nreg[1] = r[i];
/* set px, n */
- INS(interpreter, str_dup("set"), 0, nreg, 2, 0, 1);
+ INS(interpreter, unit, str_dup("set"), 0, nreg, 2, 0, 1);
}
}
}
/* make a new undef */
- iNEW(interpreter, preg[0], str_dup("PerlUndef"), NULL, 1);
+ iNEW(interpreter, unit, preg[0], str_dup("PerlUndef"), NULL, 1);
/* emit the operand */
- INS(interpreter, name, 0, preg, 3, 0, 1);
+ INS(interpreter, unit, name, 0, preg, 3, 0, 1);
/* emit the LHS op */
- emitb(ins);
+ emitb(unit, ins);
return ins;
}
1.7 +4 -4 parrot/imcc/pbc.h
Index: pbc.h
===================================================================
RCS file: /cvs/public/parrot/imcc/pbc.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -r1.6 -r1.7
--- pbc.h 23 Oct 2003 17:02:49 -0000 1.6
+++ pbc.h 4 Nov 2003 07:47:01 -0000 1.7
@@ -2,11 +2,11 @@
#define __PBC_H
int e_pbc_open(void *);
-int e_pbc_emit(void *, Instruction * ins);
-int e_pbc_new_sub(void *);
+int e_pbc_emit(void *, IMC_Unit *, Instruction * ins);
+int e_pbc_new_sub(void *, IMC_Unit *);
int e_pbc_close(void *);
void fixup_bsrs(struct Parrot_Interp *interpreter);
-void allocate_jit(struct Parrot_Interp *interpreter);
-opcode_t * make_jit_info(struct Parrot_Interp *interpreter);
+void allocate_jit(struct Parrot_Interp *interpreter, IMC_Unit *);
+opcode_t * make_jit_info(struct Parrot_Interp *interpreter, IMC_Unit *);
#endif
1.56 +21 -21 parrot/imcc/pbc.c
Index: pbc.c
===================================================================
RCS file: /cvs/public/parrot/imcc/pbc.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -w -r1.55 -r1.56
--- pbc.c 4 Nov 2003 01:11:25 -0000 1.55
+++ pbc.c 4 Nov 2003 07:47:01 -0000 1.56
@@ -88,9 +88,9 @@
while (s) {
prev_s = s->prev;
h = s->labels;
- clear_tables(interpreter, h);
+ clear_tables(NULL, h);
h = s->bsrs;
- clear_tables(interpreter, h);
+ clear_tables(NULL, h);
mem_sys_free(s);
s = prev_s;
}
@@ -154,7 +154,7 @@
/* free previous cached key constants if any */
if (globals.cs) {
SymReg **h = globals.cs->key_consts;
- clear_tables(interpreter, h);
+ clear_tables(NULL, h);
}
cs->next = NULL;
cs->subs = NULL;
@@ -190,7 +190,7 @@
}
opcode_t *
-make_jit_info(struct Parrot_Interp *interpreter)
+make_jit_info(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
char *name;
size_t size, old;
@@ -203,9 +203,9 @@
PF_UNKNOWN_SEG, name, 1);
free(name);
}
- size = IMCC_INFO(interpreter)->n_basic_blocks + (old = old_blocks());
+ size = unit->n_basic_blocks + (old = old_blocks());
/* store current size */
- globals.cs->subs->n_basic_blocks = IMCC_INFO(interpreter)->n_basic_blocks;
+ globals.cs->subs->n_basic_blocks = unit->n_basic_blocks;
/* offset of block start and end, 4 * registers_used */
globals.cs->jit_info->data = realloc(globals.cs->jit_info->data,
size * sizeof(opcode_t) * 6);
@@ -216,7 +216,7 @@
/* allocate a new globals.cs->subs structure */
static void
-make_new_sub(struct Parrot_Interp *interpreter)
+make_new_sub(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
struct subs *s = mem_sys_allocate_zeroed(sizeof(struct subs));
if (!s)
@@ -230,7 +230,7 @@
globals.cs->subs = s;
#ifdef HAS_JIT
if ((optimizer_level & OPT_J)) {
- allocate_jit(interpreter);
+ allocate_jit(interpreter, unit);
}
#else
UNUSED(interpreter);
@@ -303,7 +303,7 @@
* return size in ops
*/
static int
-store_labels(struct Parrot_Interp *interpreter, int *src_lines, int oldsize)
+store_labels(struct Parrot_Interp *interpreter, IMC_Unit * unit, int *src_lines,
int oldsize)
{
Instruction * ins;
int code_size;
@@ -316,7 +316,7 @@
* - calc nr of src lines for debug info
*/
*src_lines = 0;
- for (code_size = 0, ins = instructions; ins ; ins = ins->next) {
+ for (code_size = 0, ins = unit->instructions; ins ; ins = ins->next) {
if (ins->op && *ins->op) {
(*src_lines)++;
if (ins->opnum < 0)
@@ -332,7 +332,7 @@
* remember subroutine calls (bsr, addr (closures)) and labels
* for fixup
* */
- for (pc = 0, ins = instructions; ins ; ins = ins->next) {
+ for (pc = 0, ins = unit->instructions; ins ; ins = ins->next) {
if (ins->type & ITLABEL) {
store_label(ins->r[0], pc);
ins->r[0]->color = pc;
@@ -365,7 +365,7 @@
* for all local labels
* and write fixup records for global _labels.
*/
- for (ins = instructions; ins ; ins = ins->next) {
+ for (ins = unit->instructions; ins ; ins = ins->next) {
SymReg *addr, *label;
if ((ins->type & ITLABEL) &&
(has_compile || *ins->r[0]->name == '_')) {
@@ -407,7 +407,7 @@
/* append inter_cs jump */
sprintf(buf, "#isc_%d", globals.inter_seg_n++);
addr->name = str_dup(buf);
- INS_LABEL(addr, 1);
+ INS_LABEL(unit, addr, 1);
/* this is the new location */
store_label(addr, code_size);
/* increase code_size by 2 ops */
@@ -415,7 +415,7 @@
/* add inter_segment jump */
r[0] = mk_const(glabel, 'S');
r[0]->color = add_const_str(interpreter, glabel);
- INS(interpreter, "branch_cs", "", r, 1, 0, 1);
+ INS(interpreter, unit, "branch_cs", "", r, 1, 0, 1);
}
}
/* return code size */
@@ -799,13 +799,13 @@
}
int
-e_pbc_new_sub(void *param)
+e_pbc_new_sub(void *param, IMC_Unit * unit)
{
struct Parrot_Interp *interpreter = (struct Parrot_Interp *)param;
- if (!instructions)
+ if (!unit->instructions)
return 0;
- make_new_sub(interpreter); /* we start a new compilation unit */
+ make_new_sub(interpreter, unit); /* we start a new compilation unit */
return 0;
}
@@ -814,7 +814,7 @@
*/
int
-e_pbc_emit(void *param, Instruction * ins)
+e_pbc_emit(void *param, IMC_Unit * unit, Instruction * ins)
{
struct Parrot_Interp *interpreter = (struct Parrot_Interp *)param;
int ok = 0;
@@ -825,13 +825,13 @@
static int ins_line;
/* first instruction, do initialisation ... */
- if (ins == instructions) {
+ if (ins == unit->instructions) {
int code_size, ins_size;
int oldsize;
int bytes;
oldsize = get_old_size(interpreter, &ins_line);
- code_size = store_labels(interpreter, &ins_size, oldsize);
+ code_size = store_labels(interpreter, unit, &ins_size, oldsize);
debug(interpreter, DEBUG_PBC, "code_size(ops) %d oldsize %d\n",
code_size, oldsize);
constant_folding(interpreter);
@@ -940,7 +940,7 @@
struct Parrot_Interp *interpreter = (struct Parrot_Interp *)param;
fixup_bsrs(interpreter);
- clear_tables(interpreter, ghash);
+ clear_tables(NULL, ghash);
return 0;
}