From cd54f7ca7241d39efc69b33d103f91738641310a Mon Sep 17 00:00:00 2001 From: Moritz Kroll Date: Sun, 5 Oct 2008 00:44:22 +0000 Subject: [PATCH] Let some optimizations return non-zero, if they changed something (for fixpoint iteration). Updated Visual Studio project. [r22486] --- include/libfirm/irgopt.h | 14 ++++++++------ include/libfirm/iroptimize.h | 12 ++++++++---- ir/ir/irgopt.c | 9 +++++++-- ir/opt/convopt.c | 3 ++- ir/opt/ldstopt.c | 3 ++- ir/opt/reassoc.c | 3 ++- vc2005/libfirm.vcproj | 32 ++++---------------------------- 7 files changed, 33 insertions(+), 43 deletions(-) diff --git a/include/libfirm/irgopt.h b/include/libfirm/irgopt.h index aeaf02cdb..dac94fdda 100644 --- a/include/libfirm/irgopt.h +++ b/include/libfirm/irgopt.h @@ -39,20 +39,22 @@ void local_optimize_node(ir_node *n); * @param irg The graph to be optimized. * * After applying local_optimize_graph() to a IR-graph, Bad nodes - * only occure as predecessor of Block and Phi nodes. + * only occur as predecessor of Block and Phi nodes. */ void local_optimize_graph(ir_graph *irg); /** Applies local optimizations (see iropt.h) to all nodes in the graph. * - * @param irg The graph to be optimized. + * After applying optimize_graph_df() to a IR-graph, Bad nodes + * only occur as predecessor of Block and Phi nodes. * - * After applying local_optimize_graph() to a IR-graph, Bad nodes - * only occure as predecessor of Block and Phi nodes. + * This version uses fixpoint iteration. + * + * @param irg The graph to be optimized. * - * This version used a fixpoint iteration. + * @return non-zero if the optimization could be applied, 0 else */ -void optimize_graph_df(ir_graph *irg); +int optimize_graph_df(ir_graph *irg); /** Performs dead node elimination by copying the ir graph to a new obstack. * diff --git a/include/libfirm/iroptimize.h b/include/libfirm/iroptimize.h index 44edd025f..61103da18 100644 --- a/include/libfirm/iroptimize.h +++ b/include/libfirm/iroptimize.h @@ -63,8 +63,10 @@ void opt_bool(ir_graph *irg); * Try to reduce the number of conv nodes in the given ir graph. * * @param irg the graph + * + * @return non-zero if the optimization could be applied, 0 else */ -void conv_opt(ir_graph *irg); +int conv_opt(ir_graph *irg); /** * Do the scalar replacement optimization. @@ -235,8 +237,10 @@ ir_node *can_replace_load_by_const(const ir_node *load, ir_node *c); * * Store after Load: A Store after a Load is removed, if the * Store doesn't have an exception handler. + * + * @return non-zero if the optimization could be applied, 0 else */ -void optimize_load_store(ir_graph *irg); +int optimize_load_store(ir_graph *irg); /** * Do Loop unrolling in the given graph. @@ -372,9 +376,9 @@ void proc_cloning(float threshold); * See Muchnik 12.3.1 Algebraic Simplification and Reassociation of * Addressing Expressions. * - * + * @return non-zero if the optimization could be applied, 0 else */ -void optimize_reassociation(ir_graph *irg); +int optimize_reassociation(ir_graph *irg); /** * Normalize the Returns of a graph by creating a new End block diff --git a/ir/ir/irgopt.c b/ir/ir/irgopt.c index 207c92238..ed973803b 100644 --- a/ir/ir/irgopt.c +++ b/ir/ir/irgopt.c @@ -166,11 +166,11 @@ static void opt_walker(ir_node *n, void *env) { } /* Applies local optimizations to all nodes in the graph until fixpoint. */ -void optimize_graph_df(ir_graph *irg) { +int optimize_graph_df(ir_graph *irg) { pdeq *waitq = new_pdeq(); ir_graph *rem = current_ir_graph; ir_node *end; - int i, state, n_ka; + int i, state, n_ka, changed; current_ir_graph = irg; @@ -220,6 +220,10 @@ void optimize_graph_df(ir_graph *irg) { set_irg_visited(current_ir_graph, get_irg_visited(irg) - 1); irg_walk(get_irg_end(irg), NULL, opt_walker, waitq); + /* any optimized nodes are stored in the wait queue, + * so if it's not empty, the graph has been changed */ + changed = !pdeq_empty(waitq); + /* finish the wait queue */ while (! pdeq_empty(waitq)) { ir_node *n = pdeq_getl(waitq); @@ -235,4 +239,5 @@ void optimize_graph_df(ir_graph *irg) { edges_deactivate(irg); current_ir_graph = rem; + return changed; } diff --git a/ir/opt/convopt.c b/ir/opt/convopt.c index 354c2d5ff..09b5cd7a8 100644 --- a/ir/opt/convopt.c +++ b/ir/opt/convopt.c @@ -274,7 +274,7 @@ void conv_opt_walker(ir_node *node, void *data) } } -void conv_opt(ir_graph *irg) +int conv_opt(ir_graph *irg) { char invalidate = 0; FIRM_DBG_REGISTER(dbg, "firm.opt.conv"); @@ -292,4 +292,5 @@ void conv_opt(ir_graph *irg) if (invalidate) { set_irg_outs_inconsistent(irg); } + return invalidate; } diff --git a/ir/opt/ldstopt.c b/ir/opt/ldstopt.c index 4c29efa0c..2ef7cece0 100644 --- a/ir/opt/ldstopt.c +++ b/ir/opt/ldstopt.c @@ -2211,7 +2211,7 @@ static int optimize_loops(ir_graph *irg) { /* * do the load store optimization */ -void optimize_load_store(ir_graph *irg) { +int optimize_load_store(ir_graph *irg) { walk_env_t env; FIRM_DBG_REGISTER(dbg, "firm.opt.ldstopt"); @@ -2258,4 +2258,5 @@ void optimize_load_store(ir_graph *irg) { have Bad() predecessors. */ set_irg_doms_inconsistent(irg); } + return (int) env.changes; } /* optimize_load_store */ diff --git a/ir/opt/reassoc.c b/ir/opt/reassoc.c index 28b452626..5bcdbb9c4 100644 --- a/ir/opt/reassoc.c +++ b/ir/opt/reassoc.c @@ -872,7 +872,7 @@ static void reverse_rules(ir_node *node, void *env) { /* * do the reassociation */ -void optimize_reassociation(ir_graph *irg) +int optimize_reassociation(ir_graph *irg) { walker_t env; irg_loopinfo_state state; @@ -931,6 +931,7 @@ void optimize_reassociation(ir_graph *irg) del_waitq(env.wq); current_ir_graph = rem; + return env.changes; } /* optimize_reassociation */ /* Sets the default reassociation operation for an ir_op_ops. */ diff --git a/vc2005/libfirm.vcproj b/vc2005/libfirm.vcproj index a65f6eb9c..033d4d8a9 100644 --- a/vc2005/libfirm.vcproj +++ b/vc2005/libfirm.vcproj @@ -322,6 +322,10 @@ /> + + @@ -4469,34 +4473,6 @@ /> - - - - - - - - - - - -- 2.20.1