cvsuser 03/06/04 05:34:57
Modified: languages/imcc optimizer.c symreg.h
languages/imcc/t/imcpasm opt2.t
Log:
constant-prop #22558 by Matt Fowles - remove some warns with gcc3.3
Revision Changes Path
1.28 +11 -32 parrot/languages/imcc/optimizer.c
Index: optimizer.c
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/optimizer.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -w -r1.27 -r1.28
--- optimizer.c 31 May 2003 23:37:42 -0000 1.27
+++ optimizer.c 4 Jun 2003 12:34:55 -0000 1.28
@@ -57,7 +57,7 @@
static void subst_constants_c(struct Parrot_Interp *interp);
static void subst_constants_if(struct Parrot_Interp *interp);
-/* static void constant_propagation(struct Parrot_Interp *interp); */
+static void constant_propagation(struct Parrot_Interp *interp);
static int used_once(void);
static int loop_optimization(struct Parrot_Interp *);
static int clone_remove(void);
@@ -97,7 +97,7 @@
if (optimizer_level & OPT_CFG) {
info(2, "optimize\n");
- /* constant_propagation(interp); */
+ constant_propagation(interp);
if (clone_remove())
return 1;
if (used_once())
@@ -292,32 +292,11 @@
}
}
-#if 0
+
/*
- * Patch #22387 modified so that its working -- somehow
- * BUT: a register might get different constant values in different code
- * paths, there may be loops and so on
- *
- * ...
- * set I2, 10
- * set I1, P0["key"] # some value coming out of the aggregate
- * if I1, nxt
- * add:
- * add I0, I2, I2
- * print I0
- * end
- * nxt:
- * set I2, 20
- * branch add
- *
- * now I0 is what?
- *
- * The patch could be ok inside one basic block.
- *
- * So this patch is left here to show just the necessary code piese
- * how to substitute the constant.
- *
- * This code is only for documentation -lt
+ * does conservative constant propogation
+ * this code will not propogate constants past labels or saves
+ * even though sometimes it may be safe
*/
static void
@@ -340,7 +319,9 @@
debug(DEBUG_OPT1, "propagating constant %s => \n", ins_string(ins));
for (ins2 = ins->next; ins2; ins2 = ins2->next) {
- if (ins2->type & ITSAVES)
+ if (ins2->type & ITSAVES ||
+ /* restrict to within a basic block */
+ ins2->bbindex != ins->bbindex)
goto next_constant;
/* parrot opsize has opcode too, so argument count is
* opsize - 1
@@ -361,7 +342,7 @@
debug(DEBUG_OPT2," - no %s\n", fullname);
}
else {
- --ins2->r[i]->use_count;
+ --old->use_count;
ins2->opnum = op;
debug(DEBUG_OPT2," -> %s\n", ins_string(ins2));
}
@@ -376,7 +357,6 @@
}/*for(ins ... )*/
}
-#endif
/*
* rewrite e.g. add_n_nc_ic => add_n_nc_nc
@@ -754,7 +734,6 @@
const char *ops[] = { "if", "unless" };
size_t i;
int res;
- char *s;
info(2, "\tsubst_constants_if\n");
for (ins = instructions; ins; ins = ins->next) {
1.17 +1 -1 parrot/languages/imcc/symreg.h
Index: symreg.h
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/symreg.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -w -r1.16 -r1.17
--- symreg.h 31 May 2003 23:37:42 -0000 1.16
+++ symreg.h 4 Jun 2003 12:34:55 -0000 1.17
@@ -48,7 +48,7 @@
char * name;
enum VARTYPE type; /* Variable type */
enum USAGE usage; /* s. USAGE above */
- char set; /* Which register set/file it belongs to */
+ int set; /* Which register set/file it belongs to */
int color; /* Color: parrot register number
and parrot const table index of VTCONST*/
int score; /* How costly is to spill this symbol */
1.4 +61 -6 parrot/languages/imcc/t/imcpasm/opt2.t
Index: opt2.t
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/t/imcpasm/opt2.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- opt2.t 27 Apr 2003 07:42:25 -0000 1.3
+++ opt2.t 4 Jun 2003 12:34:57 -0000 1.4
@@ -1,6 +1,6 @@
#!perl
use strict;
-use TestCompiler tests => 2;
+use TestCompiler tests => 4;
# these tests are run with -O2 by TestCompiler and show
# generated PASM code for various optimizations at level 2
@@ -15,20 +15,70 @@
.end
CODE
_main:
- set I0, 2
+ print 2
+ end
+OUT
+
+##############################
+output_is(<<'CODE', <<'OUT', "constant propogation and resulting dead code");
+.sub _main
+ set I0, 5
+loop:
+ set I1, 2
+ add I0, I1
+ lt I0, 20, loop
+ print I0
+ end
+.end
+CODE
+_main:
+ set I0, 5
+loop:
+ add I0, 2
+ lt I0, 20, loop
print I0
end
OUT
##############################
-output_is(<<'CODE', <<'OUT', "move invariant out of loop");
+output_is(<<'CODE', <<'OUT', "don't move constant past a label");
+.sub _main
+ set I1, 10
+ set I0, 5
+ lt I1, 20, nxt
+add:
+ add I0, I1, I1
+ print I0
+nxt:
+ set I1, 20
+ branch add
+.end
+CODE
+_main:
+ set I1, 10
+ set I0, 5
+ lt 10, 20, nxt
+add:
+ add I0, I1, I1
+ print I0
+nxt:
+ set I1, 20
+ branch add
+OUT
+
+##############################
+output_is(<<'CODE', <<'OUT', "remove invariant from loop");
.sub _main
set I0, 5
loop:
set I1, 2
add I0, I1
lt I0, 20, loop
+next:
+ print I0
+ add I0, I1
print I0
+ lt I1, 4, next
end
.end
CODE
@@ -36,8 +86,13 @@
set I0, 5
set I1, 2
loop:
- add I0, I1
+ add I0, 2
lt I0, 20, loop
+next:
+ print I0
+ add I0, I1
print I0
+ lt I1, 4, next
end
OUT
+