X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fgvn_pre.c;h=0c5dba6f3b211968e0efa8b0f89ab33a6abf8912;hb=94e9283b212f0f10b460248de945576a0bb61703;hp=aa0c34c71b7a521985c2a6ff4bb53d5114222b8e;hpb=0f200789b5c71ffebbf39c7111a6f1104e464369;p=libfirm diff --git a/ir/opt/gvn_pre.c b/ir/opt/gvn_pre.c index aa0c34c71..0c5dba6f3 100644 --- a/ir/opt/gvn_pre.c +++ b/ir/opt/gvn_pre.c @@ -23,11 +23,9 @@ * (VanDrunen Hosking 2004) * @author Michael Beck * @version $Id$ - * @summary + * @brief */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" #include "irflag.h" #include "irdom.h" @@ -42,6 +40,7 @@ #include "iredges.h" #include "iropt_dbg.h" #include "debug.h" +#include "irpass.h" #include "irgraph_t.h" #include "irnode_t.h" @@ -76,7 +75,7 @@ typedef struct pre_env { struct obstack *obst; /**< The obstack to allocate on. */ ir_node *start_block; /**< The start block of the current graph. */ ir_node *end_block; /**< The end block of the current graph */ - block_info *list; /**< Links all block info entires for easier recovery. */ + block_info *list; /**< Links all block info entries for easier recovery. */ elim_pair *pairs; /**< A list of node pairs that must be eliminated. */ unsigned last_idx; /**< last node index of "old" nodes, all higher indexes are newly created once. */ char changes; /**< Non-zero, if calculation of Antic_in has changed. */ @@ -121,7 +120,7 @@ static ir_node *add(ir_node *e, ir_node *v) if (v_pred != pred) { /* must create a new value here */ - v = new_r_Proj(current_ir_graph, get_nodes_block(v_pred), v_pred, get_irn_mode(v), get_Proj_proj(v)); + v = new_r_Proj(v_pred, get_irn_mode(v), get_Proj_proj(v)); } } v = identify_remember(value_table, v); @@ -150,7 +149,8 @@ static ir_node *lookup(ir_node *e) * * @param block the block */ -static block_info *get_block_info(ir_node *block) { +static block_info *get_block_info(ir_node *block) +{ return get_irn_link(block); } /* get_block_info */ @@ -160,8 +160,9 @@ static block_info *get_block_info(ir_node *block) { * @param block the block * @param env the environment */ -static void alloc_blk_info(ir_node *block, pre_env *env) { - block_info *info = obstack_alloc(env->obst, sizeof(*info)); +static void alloc_blk_info(ir_node *block, pre_env *env) +{ + block_info *info = OALLOC(env->obst, block_info); set_irn_link(block, info); info->exp_gen = ir_valueset_new(16); @@ -180,7 +181,8 @@ static void alloc_blk_info(ir_node *block, pre_env *env) { * * @param n the node */ -static int is_nice_value(ir_node *n) { +static int is_nice_value(ir_node *n) +{ ir_mode *mode; while (is_Proj(n)) @@ -205,7 +207,8 @@ static int is_nice_value(ir_node *n) { * @param txt a text to describe the set * @param block the owner block of the set */ -static void dump_value_set(ir_valueset_t *set, char *txt, ir_node *block) { +static void dump_value_set(ir_valueset_t *set, char *txt, ir_node *block) +{ ir_valueset_iterator_t iter; ir_node *value, *expr; int i; @@ -232,7 +235,8 @@ static void dump_value_set(ir_valueset_t *set, char *txt, ir_node *block) { * Topological walker. Allocates block info for every block and place nodes in topological * order into the nodes set. */ -static void topo_walker(ir_node *irn, void *ctx) { +static void topo_walker(ir_node *irn, void *ctx) +{ pre_env *env = ctx; ir_node *block; block_info *info; @@ -312,7 +316,8 @@ static void compute_avail_top_down(ir_node *block, void *ctx) * @param block the block * @param set a value set, containing the already processed predecessors */ -static int is_clean_in_block(ir_node *n, ir_node *block, ir_valueset_t *set) { +static int is_clean_in_block(ir_node *n, ir_node *block, ir_valueset_t *set) +{ int i; if (is_Phi(n)) @@ -396,7 +401,7 @@ static ir_node *phi_translate(ir_node *node, ir_node *block, int pos, ir_valuese get_irn_in(node)); /* We need the attribute copy here, because the Hash value of a node might depend on that. */ - copy_node_attr(node, nn); + copy_node_attr(current_ir_graph, node, nn); set_nodes_block(nn, get_nodes_block(node)); for (i = 0; i < arity; ++i) { @@ -424,7 +429,8 @@ static ir_node *phi_translate(ir_node *node, ir_node *block, int pos, ir_valuese * @param block the block * @param ctx the walker environment */ -static void compute_antic(ir_node *block, void *ctx) { +static void compute_antic(ir_node *block, void *ctx) +{ pre_env *env = ctx; block_info *succ_info; block_info *info = get_block_info(block); @@ -456,16 +462,11 @@ static void compute_antic(ir_node *block, void *ctx) { n_succ = get_Block_n_cfg_outs(block); if (n_succ == 1) { - int i, pos = -1; + int pos = -1; /* find blocks position in succ's block predecessors */ succ = get_Block_cfg_out(block, 0); - for (i = get_Block_n_cfgpreds(succ) - 1; i >= 0; --i) { - if (get_Block_cfgpred_block(succ, i) == block) { - pos = i; - break; - } - } + pos = get_Block_cfgpred_pos(succ, block); assert(pos >= 0); succ_info = get_block_info(succ); @@ -631,7 +632,7 @@ static void insert_nodes(ir_node *block, void *ctx) DB((dbg, LEVEL_1, "Partial redundant %+F from block %+F found\n", expr, block)); - in = xmalloc(arity * sizeof(*in)); + in = XMALLOCN(ir_node*, arity); /* for all predecessor blocks */ for (pos = 0; pos < arity; ++pos) { ir_node *pred_blk = get_Block_cfgpred_block(block, pos); @@ -659,7 +660,7 @@ static void insert_nodes(ir_node *block, void *ctx) mode, get_irn_arity(pred), get_irn_in(pred) + 1); - copy_node_attr(pred, nn); + copy_node_attr(current_ir_graph, pred, nn); DB((dbg, LEVEL_1, "New node %+F in block %+F created\n", nn, pred_blk)); proj_pred = nn; @@ -672,7 +673,7 @@ static void insert_nodes(ir_node *block, void *ctx) mode, get_irn_arity(e_prime), get_irn_in(e_prime) + 1); - copy_node_attr(e_prime, nn); + copy_node_attr(current_ir_graph, e_prime, nn); if (proj_pred != NULL) { set_Proj_pred(nn, proj_pred); } @@ -688,7 +689,7 @@ static void insert_nodes(ir_node *block, void *ctx) } in[pos] = pred_info->avail; } /* for */ - phi = new_r_Phi(current_ir_graph, block, arity, in, mode); + phi = new_r_Phi(block, arity, in, mode); l = lookup(expr); if (l == NULL) { l = add(expr, value); @@ -713,7 +714,8 @@ static void insert_nodes(ir_node *block, void *ctx) * @param irn the node * @param ctx the walker environment */ -static void eliminate(ir_node *irn, void *ctx) { +static void eliminate(ir_node *irn, void *ctx) +{ pre_env *env = ctx; if (is_no_Block(irn)) { @@ -725,7 +727,7 @@ static void eliminate(ir_node *irn, void *ctx) { ir_node *expr = ir_valueset_lookup(bl->avail_out, value); if (expr != NULL && expr != irn) { - elim_pair *p = obstack_alloc(env->obst, sizeof(*p)); + elim_pair *p = OALLOC(env->obst, elim_pair); p->old_node = irn; p->new_node = expr; @@ -743,7 +745,8 @@ static void eliminate(ir_node *irn, void *ctx) { * * @param pairs list of elimination pairs */ -static void eliminate_nodes(elim_pair *pairs) { +static void eliminate_nodes(elim_pair *pairs) +{ elim_pair *p; for (p = pairs; p != NULL; p = p->next) { @@ -786,7 +789,7 @@ static void eliminate_nodes(elim_pair *pairs) { * references the origin. These nodes are translated again and again... * * The current fix is to use post-dominance. This simple ignores - * endless loops, ie we cannot optimize them. + * endless loops, i.e. we cannot optimize them. */ void do_gvn_pre(ir_graph *irg) { @@ -799,7 +802,6 @@ void do_gvn_pre(ir_graph *irg) /* register a debug mask */ FIRM_DBG_REGISTER(dbg, "firm.opt.gvn_pre"); - firm_dbg_set_mask(dbg, 3); /* edges will crash if enabled due to our allocate on other obstack trick */ edges_deactivate(irg); @@ -829,7 +831,8 @@ void do_gvn_pre(ir_graph *irg) /* * Switch on GCSE. We need it to correctly compute - * the leader of a node by hashing. + * the value of a node, which is independent from + * its block. */ save_optimization_state(&state); set_opt_global_cse(1); @@ -837,7 +840,7 @@ void do_gvn_pre(ir_graph *irg) DB((dbg, LEVEL_1, "Doing GVN-PRE for %+F\n", irg)); /* allocate block info for all blocks */ - irg_walk_blkwise_graph(irg, NULL, topo_walker, &a_env); + irg_walk_blkwise_dom_top_down(irg, NULL, topo_walker, &a_env); /* clean the exp_gen set. Doing this here saves the cleanup in the iteration. */ for (bl_info = a_env.list; bl_info != NULL; bl_info = bl_info->next) { @@ -899,6 +902,11 @@ void do_gvn_pre(ir_graph *irg) if (a_env.pairs) { set_irg_outs_inconsistent(irg); set_irg_loopinfo_inconsistent(irg); - } } /* do_gvn_pre */ + +/* Creates an ir_graph pass for do_gvn_pre. */ +ir_graph_pass_t *do_gvn_pre_pass(const char *name) +{ + return def_graph_pass(name ? name : "gvn_pre", do_gvn_pre); +} /* do_gvn_pre_pass */