Author: cgrawls
Date: Sun Aug 14 20:14:40 2005
New Revision: 8965
Modified:
trunk/imcc/optimizer.c
trunk/imcc/optimizer.h
trunk/imcc/reg_alloc.c
Log:
-Rewrites optimization loop to iterate through all optimizations optimally
-Makes pre_optimize() and if_branch() return TRUE if a change is made
Modified: trunk/imcc/optimizer.c
==============================================================================
--- trunk/imcc/optimizer.c (original)
+++ trunk/imcc/optimizer.c Sun Aug 14 20:14:40 2005
@@ -64,7 +64,7 @@
/* buggy - turned off */
#define DO_LOOP_OPTIMIZATION 0
-static void if_branch(Interp *, IMC_Unit *);
+static int if_branch(Interp *, IMC_Unit *);
static int branch_branch(Interp *interpreter, IMC_Unit *);
static int unused_label(Interp *interpreter, IMC_Unit *);
@@ -82,16 +82,19 @@ static int clone_remove(Interp *, IMC_Un
/*
* Handles optimizations occuring before the construction of the CFG.
*/
-void
+int
pre_optimize(Interp *interpreter, IMC_Unit * unit)
{
+ int changed = 0;
+
if (IMCC_INFO(interpreter)->optimizer_level & OPT_PRE) {
IMCC_info(interpreter, 2, "pre_optimize\n");
/* TODO integrate all in one pass */
- strength_reduce(interpreter, unit);
+ changed += strength_reduce(interpreter, unit);
if (!IMCC_INFO(interpreter)->dont_optimize)
- if_branch(interpreter, unit);
+ changed += if_branch(interpreter, unit);
}
+ return changed;
}
/*
@@ -175,15 +178,15 @@ get_neg_op(char *op, int *n)
* unless cond L2
*
*/
-static void
+static int
if_branch(Interp *interpreter, IMC_Unit * unit)
{
Instruction *ins, *last;
- int reg;
+ int reg, changed = 0;
last = unit->instructions;
if (!last->next)
- return;
+ return changed;
IMCC_info(interpreter, 2, "\tif_branch\n");
for (ins = last->next; ins; ) {
if ((last->type & ITBRANCH) && /* if ...L1 */
@@ -215,12 +218,14 @@ if_branch(Interp *interpreter, IMC_Unit
ostat.deleted_ins++;
ins = delete_ins(unit, ins, 1);
ostat.if_branch++;
+ changed = 1;
}
} /* label found */
} /* branch detected */
last = ins;
ins = ins->next;
}
+ return changed;
}
/*
Modified: trunk/imcc/optimizer.h
==============================================================================
--- trunk/imcc/optimizer.h (original)
+++ trunk/imcc/optimizer.h Sun Aug 14 20:14:40 2005
@@ -1,6 +1,6 @@
#if !defined(PARROT_IMCC_OPTIMIZER_H_GUARD)
#define PARROT_IMCC_OPTIMIZER_H_GUARD
-void pre_optimize(Interp *, IMC_Unit *);
+int pre_optimize(Interp *, IMC_Unit *);
int cfg_optimize(Interp *, IMC_Unit *);
int optimize(Interp *, IMC_Unit *);
void post_optimize(Interp *, IMC_Unit *);
Modified: trunk/imcc/reg_alloc.c
==============================================================================
--- trunk/imcc/reg_alloc.c (original)
+++ trunk/imcc/reg_alloc.c Sun Aug 14 20:14:40 2005
@@ -105,8 +105,7 @@ static unsigned int* ig_allocate(int N)
void
imc_reg_alloc(Interp *interpreter, IMC_Unit * unit)
{
- int todo, first;
- int loop_counter;
+ int first;
char *function;
if (!unit)
@@ -136,48 +135,31 @@ imc_reg_alloc(Interp *interpreter, IMC_U
(IMCC_INFO(interpreter)->debug & DEBUG_IMC))
imc_stat_init(unit);
- /* consecutive labels, if_branch, unused_labels ... */
- pre_optimize(interpreter, unit);
- if (IMCC_INFO(interpreter)->optimizer_level == OPT_PRE && unit->pasm_file)
+ if (IMCC_INFO(interpreter)->optimizer_level == OPT_PRE && unit->pasm_file)
{
+ while (pre_optimize(interpreter, unit));
return;
+ }
nodeStack = imcstack_new();
unit->n_spilled = 0;
- todo = first = 1;
- loop_counter = 0;
- while (todo) {
- loop_counter++;
- find_basic_blocks(interpreter, unit, first);
- build_cfg(interpreter, unit);
+ /* build CFG and life info, and optimize iteratively */
+ do {
+ first = 1;
+ do {
+ while (pre_optimize(interpreter, unit));
- first = 0;
- todo = cfg_optimize(interpreter, unit);
- }
- todo = first = 1;
- loop_counter = 0;
- while (todo) {
- loop_counter++;
- if (!first) {
- find_basic_blocks(interpreter, unit, 0);
+ find_basic_blocks(interpreter, unit, first);
build_cfg(interpreter, unit);
- }
- first = 0;
+ first = 0;
+ } while (cfg_optimize(interpreter, unit));
compute_dominators(interpreter, unit);
find_loops(interpreter, unit);
build_reglist(interpreter, unit, 1);
life_analysis(interpreter, unit);
- /* optimize, as long as there is something to do */
- if (IMCC_INFO(interpreter)->dont_optimize)
- todo = 0;
- else {
- todo = optimize(interpreter, unit);
- if (todo)
- pre_optimize(interpreter, unit);
- }
- }
+ } while (!IMCC_INFO(interpreter)->dont_optimize && optimize(interpreter,
unit));
graph_coloring_reg_alloc(interpreter, unit);