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
......@@ -410,8 +410,7 @@ static void copy_all_nodes(ir_node *n, void *env)
/* 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: as Bad nodes are NOT copied, no
......
......@@ -144,11 +144,11 @@ static void collect_irgs(ir_node * node, pset_new_t *irg_set)
*
* @return number of visited nodes
*/
static unsigned irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void * env)
static unsigned irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void *env)
{
int i;
unsigned cnt = 1;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -172,11 +172,11 @@ static unsigned irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void * env)
*
* @return number of visited nodes
*/
static unsigned irg_walk_2_post(ir_node *node, irg_walk_func *post, void * env)
static unsigned irg_walk_2_post(ir_node *node, irg_walk_func *post, void *env)
{
int i;
unsigned cnt = 1;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -201,11 +201,12 @@ static unsigned irg_walk_2_post(ir_node *node, irg_walk_func *post, void * env)
*
* @return number of visited nodes
*/
static unsigned irg_walk_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env)
static unsigned irg_walk_2_both(ir_node *node, irg_walk_func *pre,
irg_walk_func *post, void *env)
{
int i;
unsigned cnt = 1;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -235,21 +236,19 @@ static unsigned irg_walk_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func
unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env)
{
if (node->visited < current_ir_graph->visited) {
if (!post) return irg_walk_2_pre (node, pre, env);
else if (!pre) return irg_walk_2_post(node, post, env);
else return irg_walk_2_both(node, pre, post, env);
}
return 0;
if (irn_visited(node))
return 0;
if (!post) return irg_walk_2_pre (node, pre, env);
else if (!pre) return irg_walk_2_post(node, post, env);
else return irg_walk_2_both(node, pre, post, env);
}
/* a counter */
static unsigned nodes_touched = 0;
/*
* generic graph walker
*/
void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
void irg_walk_core(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env)
{
assert(is_ir_node(node));
......@@ -275,15 +274,22 @@ void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
pset_new_destroy(&irg_set);
} else {
#endif
ir_reserve_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
inc_irg_visited(current_ir_graph);
nodes_touched = irg_walk_2(node, pre, post, env);
ir_free_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
#ifdef INTERPROCEDURAL_VIEW
}
#endif
}
void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env)
{
ir_reserve_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
inc_irg_visited(current_ir_graph);
assert(current_ir_graph == get_irn_irg(node));
irg_walk_core(node, pre, post, env);
ir_free_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
}
/*
* walk over a graph
*/
......@@ -323,7 +329,7 @@ static unsigned irg_walk_in_or_dep_2_pre(ir_node *node, irg_walk_func *pre, void
{
int i;
unsigned cnt = 1;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -351,7 +357,7 @@ static unsigned irg_walk_in_or_dep_2_post(ir_node *node, irg_walk_func *post, vo
{
int i;
unsigned cnt = 1;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -380,7 +386,7 @@ static unsigned irg_walk_in_or_dep_2_both(ir_node *node, irg_walk_func *pre, irg
{
int i;
unsigned cnt = 1;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -409,12 +415,12 @@ static unsigned irg_walk_in_or_dep_2_both(ir_node *node, irg_walk_func *pre, irg
*/
static unsigned irg_walk_in_or_dep_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
if (node->visited < current_ir_graph->visited) {
if (! post) return irg_walk_in_or_dep_2_pre (node, pre, env);
else if (! pre) return irg_walk_in_or_dep_2_post(node, post, env);
else return irg_walk_in_or_dep_2_both(node, pre, post, env);
}
return 0;
if (irn_visited(node))
return 0;
if (! post) return irg_walk_in_or_dep_2_pre (node, pre, env);
else if (! pre) return irg_walk_in_or_dep_2_post(node, post, env);
else return irg_walk_in_or_dep_2_both(node, pre, post, env);
}
/*
......@@ -573,30 +579,32 @@ static ir_node *get_cf_op(ir_node *n)
return n;
}
static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
static void irg_block_walk_2(ir_node *node, irg_walk_func *pre,
irg_walk_func *post, void *env)
{
int i;
if (!Block_block_visited(node)) {
mark_Block_block_visited(node);
if (Block_block_visited(node))
return;
mark_Block_block_visited(node);
if (pre) pre(node, env);
if (pre)
pre(node, env);
for (i = get_Block_n_cfgpreds(node) - 1; i >= 0; --i) {
/* find the corresponding predecessor block. */
ir_node *pred = get_cf_op(get_Block_cfgpred(node, i));
pred = get_nodes_block(pred);
if (get_irn_opcode(pred) == iro_Block) {
/* recursion */
irg_block_walk_2(pred, pre, post, env);
}
else {
assert(get_irn_opcode(pred) == iro_Bad);
}
for (i = get_Block_n_cfgpreds(node) - 1; i >= 0; --i) {
/* find the corresponding predecessor block. */
ir_node *pred = get_cf_op(get_Block_cfgpred(node, i));
pred = get_nodes_block(pred);
if (get_irn_opcode(pred) == iro_Block) {
/* recursion */
irg_block_walk_2(pred, pre, post, env);
} else {
assert(get_irn_opcode(pred) == iro_Bad);
}
if (post) post(node, env);
}
if (post)
post(node, env);
}
......@@ -604,7 +612,7 @@ static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *p
flag, so that it can be interleaved with the other walker. */
void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(node);
ir_node *block, *pred;
int i;
......
......@@ -2682,18 +2682,9 @@ ident **get_ASM_clobbers(const ir_node *node)
}
/* returns the graph of a node */
ir_graph *get_irn_irg(const ir_node *node)
ir_graph *(get_irn_irg)(const ir_node *node)
{
/*
* Do not use get_nodes_Block() here, because this
* will check the pinned state.
* However even a 'wrong' block is always in the proper
* irg.
*/
if (! is_Block(node))
node = get_irn_n(node, -1);
/* note that get_Block_irg() can handle Bad nodes */
return get_Block_irg(node);
return _get_irn_irg(node);
}
......@@ -2931,9 +2922,9 @@ int (is_irn_forking)(const ir_node *node)
return _is_irn_forking(node);
}
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)
{
_copy_node_attr(old_node, new_node);
_copy_node_attr(irg, old_node, new_node);
}
/* Return the type associated with the value produced by n
......
......@@ -137,12 +137,13 @@ static inline void _set_irn_op(ir_node *node, ir_op *op)
/** Copies all attributes stored in the old node to the new node.
Assumes both have the same opcode and sufficient size. */
static inline void _copy_node_attr(const ir_node *old_node, ir_node *new_node)
static inline void _copy_node_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
ir_op *op = _get_irn_op(old_node);
/* must always exist */
op->ops.copy_attr(old_node, new_node);
op->ops.copy_attr(irg, old_node, new_node);
}
/**
......@@ -308,6 +309,20 @@ static inline void _set_irn_mode(ir_node *node, ir_mode *mode)
node->mode = mode;
}
static inline ir_graph *_get_irn_irg(const ir_node *node)
{
/*
* Do not use get_nodes_Block() here, because this
* will check the pinned state.
* However even a 'wrong' block is always in the proper
* irg.
*/
if (! is_Block(node))
node = get_irn_n(node, -1);
/* note that get_Block_irg() can handle Bad nodes */
return get_Block_irg(node);
}
/**
* Gets the visited counter of a node.
* Intern version for libFirm.
......@@ -334,8 +349,7 @@ static inline void _set_irn_visited(ir_node *node, ir_visited_t visited)
*/
static inline void _mark_irn_visited(ir_node *node)
{
assert(node);
node->visited = current_ir_graph->visited;
node->visited = get_irn_irg(node)->visited;
}
/**
......@@ -344,8 +358,8 @@ static inline void _mark_irn_visited(ir_node *node)
*/
static inline int _irn_visited(const ir_node *node)
{
assert(node);
return (node->visited >= current_ir_graph->visited);
ir_graph *irg = get_irn_irg(node);
return node->visited >= irg->visited;
}
static inline int _irn_visited_else_mark(ir_node *node)
......@@ -503,14 +517,14 @@ static inline void _set_Block_block_visited(ir_node *node, ir_visited_t visit)
/* For this current_ir_graph must be set. */
static inline void _mark_Block_block_visited(ir_node *node)
{
assert(node->op == op_Block);
node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
ir_graph *irg = get_Block_irg(node);
node->attr.block.block_visited = get_irg_block_visited(irg);
}
static inline int _Block_block_visited(const ir_node *node)
{
assert(node->op == op_Block);
return (node->attr.block.block_visited >= get_irg_block_visited(current_ir_graph));
ir_graph *irg = get_Block_irg(node);
return node->attr.block.block_visited >= get_irg_block_visited(irg);
}
static inline ir_node *_set_Block_dead(ir_node *block)
......@@ -716,6 +730,7 @@ static inline int _is_arg_Proj(const ir_node *node)
#define get_irn_n(node, n) _get_irn_n(node, n)
#define get_irn_mode(node) _get_irn_mode(node)
#define set_irn_mode(node, mode) _set_irn_mode(node, mode)
#define get_irn_irg(node) _get_irn_irg(node)
#define get_irn_op(node) _get_irn_op(node)
#define set_irn_op(node, op) _set_irn_op(node, op)
#define get_irn_opcode(node) _get_irn_opcode(node)
......@@ -750,7 +765,7 @@ static inline int _is_arg_Proj(const ir_node *node)
#define is_Const_one(node) _is_Const_one(node)
#define is_Const_all_one(node) _is_Const_all_one(node)
#define is_irn_forking(node) _is_irn_forking(node)
#define copy_node_attr(oldn,newn) _copy_node_attr(oldn,newn)
#define copy_node_attr(irg,oldn,newn) _copy_node_attr(irg,oldn,newn)
#define get_irn_type(node) _get_irn_type(node)
#define get_irn_type_attr(node) _get_irn_type_attr(node)
#define get_irn_entity_attr(node) _get_irn_entity_attr(node)
......
......@@ -47,9 +47,11 @@ static unsigned next_iro = iro_MaxOpcode;
* Copies all attributes stored in the old node to the new node.
* Assumes both have the same opcode and sufficient size.
*/
void default_copy_attr(const ir_node *old_node, ir_node *new_node)
void default_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
unsigned size = firm_add_node_size;
(void) irg;
assert(get_irn_op(old_node) == get_irn_op(new_node));
memcpy(&new_node->attr, &old_node->attr, get_op_attr_size(get_irn_op(old_node)));
......@@ -58,39 +60,46 @@ void default_copy_attr(const ir_node *old_node, ir_node *new_node)
/* copy additional node data */
memcpy(get_irn_data(new_node, void, size), get_irn_data(old_node, void, size), size);
}
} /* default_copy_attr */
}
/**
* Copies all Call attributes stored in the old node to the new node.
*/
static void call_copy_attr(const ir_node *old_node, ir_node *new_node)
static void call_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
default_copy_attr(old_node, new_node);
default_copy_attr(irg, old_node, new_node);
remove_Call_callee_arr(new_node);
} /* call_copy_attr */
}
/**
* Copies all Block attributes stored in the old node to the new node.
*/
static void block_copy_attr(const ir_node *old_node, ir_node *new_node)
static void block_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
ir_graph *irg = current_ir_graph;
default_copy_attr(old_node, new_node);
new_node->attr.block.phis = NULL;
new_node->attr.block.cg_backedge = NULL;
new_node->attr.block.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node));
default_copy_attr(irg, old_node, new_node);
new_node->attr.block.irg.irg = irg;
new_node->attr.block.phis = NULL;
new_node->attr.block.cg_backedge = NULL;
new_node->attr.block.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node));
new_node->attr.block.block_visited = 0;
memset(&new_node->attr.block.dom, 0, sizeof(new_node->attr.block.dom));
memset(&new_node->attr.block.pdom, 0, sizeof(new_node->attr.block.pdom));
/* TODO: we should probably create a new entity. But we somehow have to
* patch the stuff at the same time */
new_node->attr.block.entity = NULL;
new_node->attr.block.phis = NULL;
INIT_LIST_HEAD(&new_node->attr.block.succ_head);
} /* block_copy_attr */
}
/**
* Copies all phi attributes stored in old node to the new node
*/
static void phi_copy_attr(const ir_node *old_node, ir_node *new_node)
static void phi_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
ir_graph *irg = current_ir_graph;
default_copy_attr(old_node, new_node);
default_copy_attr(irg, old_node, new_node);
new_node->attr.phi.next = NULL;
new_node->attr.phi.u.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node));
}
......@@ -98,22 +107,20 @@ static void phi_copy_attr(const ir_node *old_node, ir_node *new_node)
/**
* Copies all filter attributes stored in old node to the new node
*/
static void filter_copy_attr(const ir_node *old_node, ir_node *new_node)
static void filter_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
ir_graph *irg = current_ir_graph;
default_copy_attr(old_node, new_node);
default_copy_attr(irg, old_node, new_node);
new_node->attr.filter.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node));
}
/**
* Copies all ASM attributes stored in old node to the new node
*/
static void ASM_copy_attr(const ir_node *old_node, ir_node *new_node)
static void ASM_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
ir_graph *irg = current_ir_graph;
default_copy_attr(old_node, new_node);
default_copy_attr(irg, old_node, new_node);
new_node->attr.assem.inputs = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.inputs);
new_node->attr.assem.outputs = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.outputs);
new_node->attr.assem.clobber = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.clobber);
......
......@@ -48,7 +48,8 @@ void finish_op(void);
* @param old_node the old node from which the attributes are read
* @param new_node the new node to which the attributes are written
*/
void default_copy_attr(const ir_node *old_node, ir_node *new_node);
void default_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node);
/**
* Returns the attribute size of nodes of this opcode.
......
......@@ -401,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) {
......@@ -660,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;
......@@ -673,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);
}
......
This diff is collapsed.
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