cvsuser 03/02/10 02:04:15
Modified: languages/imcc instructions.c instructions.h main.c
optimizer.c
Log:
run optimizer with pasm too; optimize mops
Revision Changes Path
1.24 +18 -0 parrot/languages/imcc/instructions.c
Index: instructions.c
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/instructions.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -w -r1.23 -r1.24
--- instructions.c 8 Feb 2003 17:16:16 -0000 1.23
+++ instructions.c 10 Feb 2003 10:04:15 -0000 1.24
@@ -235,6 +235,24 @@
tmp->line = ins->line;
}
+/*
+ * subst tmp for ins
+ */
+
+void subst_ins(Instruction *ins, Instruction * tmp, int needs_freeing)
+{
+ Instruction *prev = ins->prev;
+ if (prev)
+ prev->next = tmp;
+ tmp->prev = prev;
+ tmp->next = ins->next;
+ if (ins->next)
+ ins->next->prev = tmp;
+ if (!tmp->line)
+ tmp->line = ins->line;
+ if (needs_freeing)
+ free_ins(ins);
+}
/* move instruction ins to to */
Instruction *move_ins(Instruction *ins, Instruction *to)
{
1.17 +1 -0 parrot/languages/imcc/instructions.h
Index: instructions.h
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/instructions.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -w -r1.16 -r1.17
--- instructions.h 31 Jan 2003 10:54:08 -0000 1.16
+++ instructions.h 10 Feb 2003 10:04:15 -0000 1.17
@@ -86,6 +86,7 @@
Instruction *delete_ins(Instruction *ins, int needs_freeing);
void insert_ins(Instruction *ins, Instruction * tmp);
Instruction *move_ins(Instruction *cur, Instruction *to);
+void subst_ins(Instruction *ins, Instruction * tmp, int);
int get_branch_regno(Instruction * ins);
SymReg *get_branch_reg(Instruction * ins);
1.15 +3 -2 parrot/languages/imcc/main.c
Index: main.c
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/main.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -w -r1.14 -r1.15
--- main.c 8 Feb 2003 14:41:28 -0000 1.14
+++ main.c 10 Feb 2003 10:04:15 -0000 1.15
@@ -216,6 +216,7 @@
}
ext = strrchr(sourcefile, '.');
if (ext && strcmp (ext, ".pasm") == 0) {
+ if (*optimizer_opt == '0')
pasm_file = 1;
if (output)
write_pbc = 1;
@@ -260,7 +261,7 @@
line = 1;
emit_open(per_pbc, per_pbc ? (void*)interpreter : (void*)output);
- debug(1, "Starting parse...\n");
+ info(1, "Starting parse...\n");
yyparse((void *) interpreter);
emit_close(interpreter);
1.14 +25 -0 parrot/languages/imcc/optimizer.c
Index: optimizer.c
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/optimizer.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- optimizer.c 8 Feb 2003 17:16:16 -0000 1.13
+++ optimizer.c 10 Feb 2003 10:04:15 -0000 1.14
@@ -52,6 +52,8 @@
static void if_branch(struct Parrot_Interp *);
static void branch_branch(void);
static void unused_label(void);
+static void strength_reduce(struct Parrot_Interp *interp);
+
static int used_once(void);
static int loop_optimization(struct Parrot_Interp *);
static int clone_remove(void);
@@ -62,6 +64,7 @@
branch_branch();
/* XXX cfg / loop detection breaks e.g. in t/compiler/5_3 */
unused_label();
+ strength_reduce(interp);
}
}
@@ -229,6 +232,28 @@
}
}
+static void strength_reduce(struct Parrot_Interp *interp)
+{
+ Instruction *ins, *tmp;
+ const char *ops[] = { "add", "sub", "mul", "div" };
+ int i;
+
+ for (ins = instructions; ins; ins = ins->next) {
+ /*
+ * sub Ix, Ix, Iy => sub Ix, Iy
+ */
+ for (i = 0; i < 4; i++)
+ if (!strcmp(ins->op, ops[i]) && ins->opsize == 4 &&
+ ins->r[0] == ins->r[1]) {
+ debug(DEBUG_OPT1, "opt1 %s => ", ins_string(ins));
+ ins->r[1] = ins->r[2];
+ tmp = INS(interp, ins->op, "", ins->r, 2, 0, 0);
+ debug(DEBUG_OPT1, "%s\n", ins_string(tmp));
+ subst_ins(ins, tmp, 1);
+ }
+ }
+
+}
/* optimizations with CFG built */
int dead_code_remove(void)
{