Commit 2807bb5b authored by Matthias Braun's avatar Matthias Braun
Browse files

- cleanup and simplify inlining code

- remove a bunch of code which unexpectedly dependent on current_ir_graph being
  set to something
- fix unnecessary double creation of backedge arrays in some cases

[r27265]
parent 08ada326
......@@ -116,18 +116,6 @@ void free_survive_dce(survive_dce_t *sd);
*/
void survive_dce_register_irn(survive_dce_t *sd, ir_node **place);
/** Cleans the control flow from Bad predecessors.
*
* Removes Bad predecessors from Blocks and the corresponding
* inputs to Phi nodes as in dead_node_elimination but without
* copying the graph.
*
* Conserves loop information.
*
* @param irg The graph to be optimized.
*/
void remove_bad_predecessors(ir_graph *irg);
/** Inlines a method at the given call site.
*
* Removes the call node and splits the basic block the call node
......
......@@ -53,7 +53,15 @@
* @param env environment, passed to pre and post
*
*/
void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env);
/**
* core walker function. Does NOT touch current_ir_graph and does not call
* inc_irg_visited before walking
*/
void irg_walk_core(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env);
/**
* Walks over all reachable nodes in the ir graph.
......
......@@ -1304,8 +1304,9 @@ int is_irn_forking(const ir_node *node);
/**
* Copies all attributes stored in the old node to the new node.
* Assumes both have the same opcode and sufficient size.
* @param irg The irg of the new_node (get_irn_irg on it might not work yet)
*/
void copy_node_attr(const ir_node *old_node, ir_node *new_node);
void copy_node_attr(ir_graph *irg, const ir_node *old_node, ir_node *new_node);
/** Return the type associated with the value produced by n
* if the node remarks this type as it is the case for
......
......@@ -304,7 +304,7 @@ typedef int (*reassociate_func)(ir_node **n);
* The copy attribute operation.
* Copy the node attributes from an 'old' node to a 'new' one.
*/
typedef void (*copy_attr_func)(const ir_node *old_node, ir_node *new_node);
typedef void (*copy_attr_func)(ir_graph *irg, const ir_node *old_node, ir_node *new_node);
/**
* The get_type operation.
......
......@@ -225,21 +225,3 @@ unsigned *new_backedge_arr(struct obstack *obst, unsigned size)
{
return rbitset_w_size_obstack_alloc(obst, size);
}
/* TODO: add an ir_op operation */
void new_backedge_info(ir_node *n)
{
switch (get_irn_opcode(n)) {
case iro_Block:
n->attr.block.cg_backedge = NULL;
n->attr.block.backedge = new_backedge_arr(current_ir_graph->obst, get_irn_arity(n));
break;
case iro_Phi:
n->attr.phi.u.backedge = new_backedge_arr(current_ir_graph->obst, get_irn_arity(n));
break;
case iro_Filter:
n->attr.filter.backedge = new_backedge_arr(current_ir_graph->obst, get_irn_arity(n));
break;
default: ;
}
}
......@@ -35,11 +35,6 @@
*/
unsigned *new_backedge_arr(struct obstack *obst, unsigned size);
/**
* Allocate new backedge info for a given node.
*/
void new_backedge_info(ir_node *n);
/**
* Adapts backedges array to new size.
* Must be called if the in array of an IR node is changed. Else
......
......@@ -512,7 +512,7 @@ static void init_tmp_dom_info(ir_node *bl, tmp_dom_info *parent,
int i;
assert(is_Block(bl));
if (get_irg_block_visited(current_ir_graph) == get_Block_block_visited(bl))
if (Block_block_visited(bl))
return;
mark_Block_block_visited(bl);
set_Block_dom_pre_num(bl, *used);
......@@ -649,46 +649,11 @@ static void count_and_init_blocks_dom(ir_node *bl, void *env)
*/
static int init_construction(ir_graph *irg, irg_walk_func *pre)
{
ir_graph *rem = current_ir_graph;
ir_node *end;
int arity;
int n_blocks = 0;
current_ir_graph = irg;
/* this visits only the reachable blocks */
irg_block_walk(get_irg_end_block(irg), pre, NULL, &n_blocks);
/* now visit the unreachable (from End) Blocks and remove unnecessary keep-alives */
end = get_irg_end(irg);
arity = get_End_n_keepalives(end);
if (arity) { /* we have keep-alives */
ir_node **in;
int i, j;
NEW_ARR_A(ir_node *, in, arity);
for (i = j = 0; i < arity; i++) {
ir_node *pred = get_End_keepalive(end, i);
if (!is_Block(pred)) {
pred = get_nodes_block(pred);
if (!is_Block(pred)) {
/* a node which has a bad block input: kill it */
continue;
}
}
dec_irg_block_visited(irg);
irg_block_walk(pred, pre, NULL, &n_blocks);
in[j++] = pred;
}
if (j != arity) {
/* we kill some keep-alives */
set_End_keepalives(end, j, in);
set_irg_outs_inconsistent(irg);
}
}
irg_block_walk_graph(irg, pre, NULL, &n_blocks);
current_ir_graph = rem;
return n_blocks;
}
......
......@@ -496,14 +496,14 @@ static int cmp_attr_arm_cmp(ir_node *a, ir_node *b)
}
/** copies the ARM attributes of a node. */
static void arm_copy_attr(const ir_node *old_node, ir_node *new_node)
static void arm_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
ir_graph *irg = get_irn_irg(new_node);
struct obstack *obst = get_irg_obstack(irg);
struct obstack *obst = get_irg_obstack(irg);
const arm_attr_t *attr_old = get_arm_attr_const(old_node);
arm_attr_t *attr_new = get_arm_attr(new_node);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
/* copy the attributes */
memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
......
......@@ -1501,7 +1501,7 @@ static ir_node *gen_Phi(ir_node *node)
* and fix this later */
phi = new_ir_node(dbgi, irg, block, op_Phi, mode, get_irn_arity(node),
get_irn_in(node) + 1);
copy_node_attr(node, phi);
copy_node_attr(irg, node, phi);
be_duplicate_deps(node, phi);
arch_set_out_register_req(phi, 0, req);
......
......@@ -62,14 +62,15 @@ void be_info_new_node(ir_node *node)
}
}
static void new_Phi_copy_attr(const ir_node *old_node, ir_node *new_node)
static void new_Phi_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
*new_info = *old_info;
old_phi_copy_attr(old_node, new_node);
old_phi_copy_attr(irg, old_node, new_node);
}
int be_infos_equal(const backend_info_t *info1, const backend_info_t *info2)
......
......@@ -1436,11 +1436,10 @@ static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
* ir_op-Operation:
* Copies the backend specific attributes from old node to new node.
*/
static void copy_attr(const ir_node *old_node, ir_node *new_node)
static void copy_attr(ir_graph *irg, const ir_node *old_node, ir_node *new_node)
{
const be_node_attr_t *old_attr = get_irn_attr_const(old_node);
be_node_attr_t *new_attr = get_irn_attr(new_node);
ir_graph *irg = get_irn_irg(new_node);
struct obstack *obst = be_get_birg_obst(irg);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
......
......@@ -677,9 +677,8 @@ static ir_node *do_remat(spill_env_t *env, ir_node *spilled, ir_node *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(spilled, res);
copy_node_attr(env->irg, spilled, res);
arch_env_mark_remat(env->arch_env, res);
new_backedge_info(res);
DBG((dbg, LEVEL_1, "Insert remat %+F of %+F before reloader %+F\n", res, spilled, reloader));
......
......@@ -123,7 +123,7 @@ ir_node *be_duplicate_node(ir_node *node)
new_node = new_ir_node(dbgi, irg, block, op, mode, arity, ins);
}
copy_node_attr(node, new_node);
copy_node_attr(irg, node, new_node);
be_duplicate_deps(node, new_node);
new_node->node_nr = node->node_nr;
......@@ -358,7 +358,7 @@ static ir_node *gen_Block(ir_node *node)
block = new_ir_node(dbgi, irg, NULL, get_irn_op(node), get_irn_mode(node),
get_irn_arity(node), get_irn_in(node) + 1);
copy_node_attr(node, block);
copy_node_attr(irg, node, block);
block->node_nr = node->node_nr;
if (node == macroblock) {
......@@ -385,7 +385,7 @@ static ir_node *gen_End(ir_node *node)
ir_node *new_end;
new_end = new_ir_node(dbgi, irg, block, op_End, mode_X, -1, NULL);
copy_node_attr(node, new_end);
copy_node_attr(irg, node, new_end);
be_duplicate_deps(node, new_end);
set_irg_end(irg, new_end);
......
......@@ -1145,9 +1145,9 @@ static int ia32_compare_climbframe_attr(ir_node *a, ir_node *b)
}
/* copies the ia32 attributes */
static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
static void ia32_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
ir_graph *irg = get_irn_irg(new_node);
struct obstack *obst = get_irg_obstack(irg);
const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
ia32_attr_t *attr_new = get_ia32_attr(new_node);
......
......@@ -3981,7 +3981,7 @@ static ir_node *gen_be_Return(ir_node *node)
new_barrier = new_ir_node(dbgi, irg, block,
get_irn_op(barrier), get_irn_mode(barrier),
arity, in);
copy_node_attr(barrier, new_barrier);
copy_node_attr(irg, barrier, new_barrier);
be_duplicate_deps(barrier, new_barrier);
be_set_transformed_node(barrier, new_barrier);
......@@ -4047,7 +4047,7 @@ static ir_node *gen_Phi(ir_node *node)
* and fix this later */
phi = new_ir_node(dbgi, irg, block, op_Phi, mode, get_irn_arity(node),
get_irn_in(node) + 1);
copy_node_attr(node, phi);
copy_node_attr(irg, node, phi);
be_duplicate_deps(node, phi);
arch_set_out_register_req(phi, 0, req);
......
......@@ -257,9 +257,9 @@ static int mips_compare_load_store_attr(ir_node *node_a, ir_node *node_b)
return 0;
}
static void mips_copy_attr(const ir_node *old_node , ir_node *new_node)
static void mips_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
ir_graph *irg = get_irn_irg(new_node);
struct obstack *obst = get_irg_obstack(irg);
const mips_attr_t *attr_old = get_mips_attr_const(old_node);
mips_attr_t *attr_new = get_mips_attr(new_node);
......
......@@ -543,7 +543,7 @@ static ir_node *gen_Phi(ir_node *node)
* and fix this later */
phi = new_ir_node(dbgi, irg, block, op_Phi, mode, get_irn_arity(node),
get_irn_in(node) + 1);
copy_node_attr(node, phi);
copy_node_attr(irg, node, phi);
be_duplicate_deps(node, phi);
be_enqueue_preds(node);
......
......@@ -294,14 +294,14 @@ static void init_sparc_symconst_attributes(ir_node *res, ir_entity *entity)
/**
* copies sparc attributes of node
*/
static void sparc_copy_attr(const ir_node *old_node, ir_node *new_node)
static void sparc_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
ir_graph *irg = get_irn_irg(new_node);
struct obstack *obst = get_irg_obstack(irg);
const sparc_attr_t *attr_old = get_sparc_attr_const(old_node);
struct obstack *obst = get_irg_obstack(irg);
const sparc_attr_t *attr_old = get_sparc_attr_const(old_node);
sparc_attr_t *attr_new = get_sparc_attr(new_node);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
/* copy the attributes */
memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
......
......@@ -641,7 +641,7 @@ static ir_node *gen_Phi(ir_node *node)
/* phi nodes allow loops, so we use the old arguments for now
* and fix this later */
phi = new_ir_node(dbgi, irg, block, op_Phi, mode, get_irn_arity(node), get_irn_in(node) + 1);
copy_node_attr(node, phi);
copy_node_attr(irg, node, phi);
be_duplicate_deps(node, phi);
arch_set_out_register_req(phi, 0, req);
be_enqueue_preds(node);
......
......@@ -113,8 +113,7 @@ void copy_irn_to_irg(ir_node *n, ir_graph *irg)
/* Copy the attributes. These might point to additional data. If this
was allocated on the old obstack the pointers now are dangling. This
frees e.g. the memory of the graph_arr allocated in new_immBlock. */
copy_node_attr(n, nn);
new_backedge_info(nn);
copy_node_attr(irg, n, nn);
set_irn_link(n, nn);
/* fix the irg for blocks */
......@@ -150,8 +149,7 @@ ir_node *exact_copy(const ir_node *n)
/* Copy the attributes. These might point to additional data. If this
was allocated on the old obstack the pointers now are dangling. This
frees e.g. the memory of the graph_arr allocated in new_immBlock. */
copy_node_attr(n, res);
new_backedge_info(res);
copy_node_attr(irg, n, res);
if (is_Block(n)) {
set_Block_MacroBlock(res, get_Block_MacroBlock(n));
......
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