Commit 04cb38b6 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

ir: Add and use new_similar_node().

parent d2d0422f
......@@ -562,7 +562,6 @@ static int check_remat_conditions_costs(spill_env_t *env,
*/
static ir_node *do_remat(spill_env_t *env, ir_node *spilled, ir_node *reloader)
{
ir_node *res;
ir_node **ins;
ins = ALLOCAN(ir_node*, get_irn_arity(spilled));
......@@ -577,11 +576,8 @@ static ir_node *do_remat(spill_env_t *env, ir_node *spilled, ir_node *reloader)
}
/* create a copy of the node */
ir_node *const bl = get_nodes_block(reloader);
res = new_ir_node(get_irn_dbg_info(spilled), env->irg, bl,
get_irn_op(spilled), get_irn_mode(spilled),
get_irn_arity(spilled), ins);
copy_node_attr(env->irg, spilled, res);
ir_node *const bl = get_nodes_block(reloader);
ir_node *const res = new_similar_node(spilled, bl, ins);
arch_env_mark_remat(env->arch_env, res);
DBG((dbg, LEVEL_1, "Insert remat %+F of %+F before reloader %+F\n", res, spilled, reloader));
......
......@@ -128,6 +128,18 @@ ir_node *new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op,
return res;
}
ir_node *new_similar_node(ir_node *const old, ir_node *const block, ir_node **const in)
{
dbg_info *const dbgi = get_irn_dbg_info(old);
ir_graph *const irg = get_Block_irg(block);
ir_op *const op = get_irn_op(old);
ir_mode *const mode = get_irn_mode(old);
int const arity = get_irn_arity(old);
ir_node *const n = new_ir_node(dbgi, irg, block, op, mode, arity, in);
copy_node_attr(irg, old, n);
return n;
}
int (is_ir_node)(const void *thing)
{
return is_ir_node_(thing);
......
......@@ -548,6 +548,12 @@ void ir_register_getter_ops(void);
*/
bool only_used_by_keepalive(const ir_node *node);
/**
* Create a node similar to @p old. Except for @p block and @p in all aspects
* are copied from @p old.
*/
ir_node *new_similar_node(ir_node *old, ir_node *block, ir_node **in);
#define foreach_irn_in(irn, idx, pred) \
for (bool pred##__b = true; pred##__b;) \
for (ir_node const *const pred##__irn = (irn); pred##__b; pred##__b = false) \
......
......@@ -346,15 +346,7 @@ static ir_node *remember(ir_node *irn)
if (changed && !is_memop(irn) && get_irn_mode(irn) != mode_X) {
/* create representative for */
ir_node *nn = new_ir_node(
get_irn_dbg_info(irn),
get_irn_irg(irn),
get_nodes_block(irn),
get_irn_op(irn),
get_irn_mode(irn),
get_irn_arity(irn),
in);
copy_node_attr(environ->graph, irn, nn);
ir_node *nn = new_similar_node(irn, get_nodes_block(irn), in);
#if OPTIMIZE_NODES
/* TODO optimize_node() uses the valuetable and thus the custom
......@@ -806,7 +798,6 @@ static ir_node *phi_translate(ir_node *node, ir_node *block, int pos, ir_valuese
int arity;
ir_node **in;
ir_node *pred_block = get_Block_cfgpred_block(block, pos);
ir_node *nn;
unsigned needed;
if (is_Phi(node)) {
......@@ -897,17 +888,7 @@ static ir_node *phi_translate(ir_node *node, ir_node *block, int pos, ir_valuese
so we use the newly created nodes as value representatives only.
Their block is not important, because we create new ones during
the insert node phase. */
nn = new_ir_node(
get_irn_dbg_info(node),
environ->graph,
pred_block,
get_irn_op(node),
get_irn_mode(node),
arity,
in);
/* We need the attribute copy here, because the Hash value of a
node might depend on it. */
copy_node_attr(environ->graph, node, nn);
ir_node *const nn = new_similar_node(node, pred_block, in);
/* Optimizing nn here is tempting but might be against the GVN-PRE algorithm
because it already uses availability. */
......@@ -1473,18 +1454,8 @@ static void insert_nodes_walker(ir_node *block, void *ctx)
We use translated nodes as value representatives only.
They have anti leaders as predecessors, not leaders!
So we have to create a new node using leaders. */
trans = new_ir_node(
get_irn_dbg_info(expr),
environ->graph,
target_block,
get_irn_op(expr),
get_irn_mode(expr),
get_irn_arity(expr),
in);
trans = new_similar_node(expr, target_block, in);
free(in);
/* We need the attribute copy here, because the Hash value of a
node might depend on it. */
copy_node_attr(environ->graph, expr, trans);
/* value is now available in target block through trans
insert (not replace) because it has not been available */
......@@ -1694,7 +1665,6 @@ static void hoist_high(ir_node *block, void *ctx)
block_info *target_info = get_block_info(new_target);
int nn_arity = get_irn_arity(avail);
ir_node **in = XMALLOCN(ir_node *, nn_arity);
ir_node *nn;
DB((dbg, LEVEL_2, "Hoisting %+F into %+F\n", avail, new_target));
DEBUG_ONLY(inc_stats(gvnpre_stats->hoist_high);)
......@@ -1704,14 +1674,7 @@ static void hoist_high(ir_node *block, void *ctx)
assert(avail_pred);
in[i] = avail_pred;
}
nn = new_ir_node(
get_irn_dbg_info(avail),
environ->graph,
new_target,
get_irn_op(avail),
get_irn_mode(avail),
nn_arity,
in);
ir_node *const nn = new_similar_node(avail, new_target, in);
free(in);
identify_or_remember(nn);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment