X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=ir%2Fir%2Firgopt.c;h=87b0cb20c5025a55c5f86c2b7b7a8785124ec06d;hb=2b84102b8f003a13d083330fbc6aaff92b6563e9;hp=283ff31a55ece6dc3b0c0c3b2318838ffe4fc11f;hpb=255a9cc77e3cdf878406d722cf8414063c87e99b;p=libfirm diff --git a/ir/ir/irgopt.c b/ir/ir/irgopt.c index 283ff31a5..87b0cb20c 100644 --- a/ir/ir/irgopt.c +++ b/ir/ir/irgopt.c @@ -22,7 +22,6 @@ * @brief Optimizations for a whole ir graph, i.e., a procedure. * @author Christian Schaefer, Goetz Lindenmaier, Sebastian Felis, * Michael Beck - * @version $Id$ */ #include "config.h" @@ -36,6 +35,7 @@ #include "irgopt.h" #include "irgmod.h" #include "irgwalk.h" +#include "ircons.h" #include "adt/pdeq.h" @@ -44,10 +44,6 @@ #include "iredges_t.h" #include "irtools.h" -/*------------------------------------------------------------------*/ -/* apply optimizations of iropt to all nodes. */ -/*------------------------------------------------------------------*/ - /** * A wrapper around optimize_inplace_2() to be called from a walker. */ @@ -73,12 +69,9 @@ static inline void do_local_optimize(ir_node *n) { ir_graph *irg = get_irn_irg(n); - /* Handle graph state */ - assert(get_irg_phase_state(irg) != phase_building); - if (get_opt_global_cse()) set_irg_pinned(irg, op_pin_state_floats); - clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE); + clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE); /* Clean the value_table in irg for the CSE. */ new_identities(irg); @@ -87,7 +80,6 @@ static inline void do_local_optimize(ir_node *n) irg_walk(n, firm_clear_link, optimize_in_place_wrapper, NULL); } -/* Applies local optimizations (see iropt.h) to all nodes reachable from node n */ void local_optimize_node(ir_node *n) { ir_graph *rem = current_ir_graph; @@ -112,13 +104,21 @@ static void enqueue_node(ir_node *node, pdeq *waitq) */ static void enqueue_users(ir_node *n, pdeq *waitq) { - const ir_edge_t *edge; - foreach_out_edge(n, edge) { - ir_node *succ = get_edge_src_irn(edge); + ir_node *succ = get_edge_src_irn(edge); enqueue_node(succ, waitq); - if (get_irn_mode(succ) == mode_T) { + + /* Also enqueue Phis to prevent inconsistencies. */ + if (is_Block(succ)) { + foreach_out_edge(succ, edge2) { + ir_node *succ2 = get_edge_src_irn(edge2); + + if (is_Phi(succ2)) { + enqueue_node(succ2, waitq); + } + } + } else if (get_irn_mode(succ) == mode_T) { /* A mode_T node has Proj's. Because most optimizations run on the Proj's we have to enqueue them also. */ enqueue_users(succ, waitq); @@ -137,9 +137,7 @@ static void find_unreachable_blocks(ir_node *block, void *env) ir_graph *irg = get_irn_irg(block); ir_node *end = get_irg_end(irg); - const ir_edge_t *edge; foreach_block_succ(block, edge) { - const ir_edge_t *edge2; ir_node *succ_block = get_edge_src_irn(edge); enqueue_node(succ_block, waitq); foreach_out_edge(succ_block, edge2) { @@ -152,7 +150,6 @@ static void find_unreachable_blocks(ir_node *block, void *env) } } -/* Applies local optimizations (see iropt.h) to all nodes reachable from node n. */ void local_optimize_graph(ir_graph *irg) { ir_graph *rem = current_ir_graph; @@ -194,11 +191,11 @@ int optimize_graph_df(ir_graph *irg) set_irg_pinned(irg, op_pin_state_floats); /* enable unreachable code elimination */ - assert(!is_irg_state(irg, IR_GRAPH_STATE_OPTIMIZE_UNREACHABLE_CODE)); - set_irg_state(irg, IR_GRAPH_STATE_OPTIMIZE_UNREACHABLE_CODE); + assert(!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_OPTIMIZE_UNREACHABLE_CODE)); + add_irg_constraints(irg, IR_GRAPH_CONSTRAINT_OPTIMIZE_UNREACHABLE_CODE); new_identities(irg); - edges_assure(irg); + assure_edges(irg); assure_doms(irg); @@ -222,13 +219,12 @@ int optimize_graph_df(ir_graph *irg) ir_free_resources(irg, IR_RESOURCE_IRN_LINK); /* disable unreachable code elimination */ - clear_irg_state(irg, IR_GRAPH_STATE_OPTIMIZE_UNREACHABLE_CODE); - set_irg_state(irg, IR_GRAPH_STATE_NO_UNREACHABLE_CODE); + clear_irg_constraints(irg, IR_GRAPH_CONSTRAINT_OPTIMIZE_UNREACHABLE_CODE); + add_irg_properties(irg, IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE); /* invalidate infos */ - clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE); - clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_LOOPINFO); - clear_irg_state(irg, IR_GRAPH_STATE_VALID_EXTENDED_BLOCKS); + clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE); + clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO); edges_deactivate(irg); /* Finally kill BAD and doublets from the keep alives. @@ -244,6 +240,15 @@ int optimize_graph_df(ir_graph *irg) return true; } +void local_opts_const_code(void) +{ + ir_graph *irg = get_const_code_irg(); + /* Clean the value_table in irg for the CSE. */ + new_identities(irg); + + walk_const_code(firm_clear_link, optimize_in_place_wrapper, NULL); +} + ir_graph_pass_t *optimize_graph_df_pass(const char *name) { return def_graph_pass_ret(name ? name : "optimize_graph_df", optimize_graph_df);