X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fifconv.c;h=0d1307a9a4f4b2b7a231003bc1794fbb60080c08;hb=a570fca6677ea8d74f2f5aa5462636696bb92559;hp=84a93f7a435a62a393808bb3f73a5572a817ad0b;hpb=ece28efeab3e5f39163eea2730582fa2c8f5b665;p=libfirm diff --git a/ir/opt/ifconv.c b/ir/opt/ifconv.c index 84a93f7a4..0d1307a9a 100644 --- a/ir/opt/ifconv.c +++ b/ir/opt/ifconv.c @@ -23,7 +23,6 @@ * @author Christoph Mallon * @version $Id$ */ - #include "config.h" #include @@ -40,8 +39,8 @@ #include "irtools.h" #include "array_t.h" #include "irpass_t.h" +#include "be.h" -// debug #include "irdump.h" #include "debug.h" @@ -49,32 +48,12 @@ * Environment for if-conversion. */ typedef struct walker_env { - const ir_settings_if_conv_t *params; /**< Conversion parameter. */ - int changed; /**< Set if the graph was changed. */ + arch_allow_ifconv_func allow_ifconv; + bool changed; /**< Set if the graph was changed. */ } walker_env; DEBUG_ONLY(static firm_dbg_module_t *dbg); -/** - * Default callback for Mux creation: don't allow any Mux nodes - */ -static int default_allow_ifconv(ir_node *sel, ir_node *mux_false, - ir_node *mux_true) -{ - (void) sel; - (void) mux_false; - (void) mux_true; - return 0; -} - -/** - * Default options. - */ -static const ir_settings_if_conv_t default_info = { - 0, /* doesn't matter for Mux */ - default_allow_ifconv -}; - /** * Returns non-zero if a Block can be emptied. * @@ -210,7 +189,7 @@ static void rewire(ir_node* node, int i, int j, ir_node* new_pred) /** - * Remove the j-th predecessors from the i-th predecessor of block and add it to block + * Remove the j-th predecessor from the i-th predecessor of block and add it to block */ static void split_block(ir_node* block, int i, int j) { @@ -282,7 +261,7 @@ static void prepare_path(ir_node* block, int i, const ir_node* dependency) for (j = 0; j < pred_arity; ++j) { ir_node* pred_pred = get_nodes_block(get_irn_n(pred, j)); - if (is_cdep_on(pred_pred, dependency)) { + if (pred_pred != dependency && is_cdep_on(pred_pred, dependency)) { prepare_path(pred, j, dependency); split_block(block, i, j); break; @@ -295,7 +274,7 @@ static void prepare_path(ir_node* block, int i, const ir_node* dependency) */ static void if_conv_walker(ir_node *block, void *ctx) { - walker_env *env = ctx; + walker_env *env = (walker_env*)ctx; int arity; int i; @@ -357,7 +336,7 @@ restart: mux_true = get_Phi_pred(p, i); mux_false = get_Phi_pred(p, j); } - if (!env->params->allow_ifconv(sel, mux_false, mux_true)) { + if (!env->allow_ifconv(sel, mux_false, mux_true)) { supported = false; break; } @@ -369,14 +348,15 @@ restart: cond, projx0, projx1 )); - env->changed = 1; + /* remove critical edges */ + env->changed = true; prepare_path(block, i, dependency); prepare_path(block, j, dependency); arity = get_irn_arity(block); mux_block = get_nodes_block(cond); cond_dbg = get_irn_dbg_info(cond); - do { + do { /* generate Mux nodes in mux_block for Phis in block */ ir_node* val_i = get_irn_n(phi, i); ir_node* val_j = get_irn_n(phi, j); ir_node* mux; @@ -414,6 +394,7 @@ restart: phi = next_phi; } while (phi != NULL); + /* move mux operands into mux_block */ exchange(get_nodes_block(get_irn_n(block, i)), mux_block); exchange(get_nodes_block(get_irn_n(block, j)), mux_block); @@ -471,7 +452,7 @@ static void collect_phis(ir_node *node, void *env) add_Block_phi(block, node); } else { - if (is_no_Block(node) && get_irn_pinned(node) == op_pin_state_pinned) { + if (!is_Block(node) && get_irn_pinned(node) == op_pin_state_pinned) { /* * Ignore control flow nodes (except Raise), these will be removed. */ @@ -485,13 +466,14 @@ static void collect_phis(ir_node *node, void *env) } } -void opt_if_conv(ir_graph *irg, const ir_settings_if_conv_t *params) +void opt_if_conv(ir_graph *irg) { - walker_env env; + walker_env env; + const backend_params *be_params = be_get_backend_param(); /* get the parameters */ - env.params = (params != NULL ? params : &default_info); - env.changed = 0; + env.allow_ifconv = be_params->allow_ifconv; + env.changed = false; FIRM_DBG_REGISTER(dbg, "firm.opt.ifconv"); @@ -523,27 +505,7 @@ void opt_if_conv(ir_graph *irg, const ir_settings_if_conv_t *params) free_cdep(irg); } -struct pass_t { - ir_graph_pass_t pass; - const ir_settings_if_conv_t *params; -}; - -/** - * Wrapper for running opt_if_conv() as an ir_graph pass. - */ -static int pass_wrapper(ir_graph *irg, void *context) -{ - struct pass_t *pass = context; - opt_if_conv(irg, pass->params); - return 0; -} - -ir_graph_pass_t *opt_if_conv_pass(const char *name, - const ir_settings_if_conv_t *params) +ir_graph_pass_t *opt_if_conv_pass(const char *name) { - struct pass_t *pass = XMALLOCZ(struct pass_t); - pass->params = params; - - return def_graph_pass_constructor( - &pass->pass, name ? name : "ifconv", pass_wrapper); + return def_graph_pass(name ? name : "ifconv", opt_if_conv); }