X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgwalk.c;h=10484be99d1450f771d07ec131b1e2bc68e44c71;hb=a826556627270364ae3683c31e4b8cec4b5479c4;hp=9ae74d38b4f8e9d6ec97638c4f45a11156c91168;hpb=86e761ab84e9d929821dd977f6395cb21b89cde1;p=libfirm diff --git a/ir/ir/irgwalk.c b/ir/ir/irgwalk.c index 9ae74d38b..10484be99 100644 --- a/ir/ir/irgwalk.c +++ b/ir/ir/irgwalk.c @@ -22,18 +22,14 @@ * @brief Functions for traversing ir graphs * @author Boris Boesler, Goetz Lindenmaier, Michael Beck * @version $Id$ - * @summary + * @brief * traverse an ir graph * - execute the pre function before recursion * - execute the post function after recursion */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" -#ifdef HAVE_STDLIB_H -# include -#endif +#include #include "irnode_t.h" #include "irgraph_t.h" @@ -47,13 +43,15 @@ #include "pset_new.h" #include "array.h" +#ifdef INTERPROCEDURAL_VIEW /** * Walk over an interprocedural graph (callgraph). * Visits only graphs in irg_set. */ static void irg_walk_cg(ir_node * node, ir_visited_t visited, pset_new_t *irg_set, irg_walk_func *pre, - irg_walk_func *post, void * env) { + irg_walk_func *post, void * env) +{ int i; ir_graph * rem = current_ir_graph; ir_node * pred; @@ -122,11 +120,11 @@ static void irg_walk_cg(ir_node * node, ir_visited_t visited, current_ir_graph = rem; } - /** * Insert all ir_graphs in irg_set, that are (transitive) reachable. */ -static void collect_irgs(ir_node * node, pset_new_t *irg_set) { +static void collect_irgs(ir_node * node, pset_new_t *irg_set) +{ if (is_Call(node)) { int i; for (i = get_Call_n_callees(node) - 1; i >= 0; --i) { @@ -139,14 +137,15 @@ static void collect_irgs(ir_node * node, pset_new_t *irg_set) { } } } +#endif /** * specialized version of irg_walk_2, called if only pre callback exists * * @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; @@ -173,8 +172,8 @@ 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; @@ -202,8 +201,8 @@ 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; @@ -233,8 +232,8 @@ irg_walk_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * e * * @return number of visited nodes */ -static unsigned -irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) +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); @@ -288,7 +287,8 @@ void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env) /* * walk over a graph */ -void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) { +void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) +{ ir_graph * rem = current_ir_graph; hook_irg_walk(irg, (generic_func *)pre, (generic_func *)post); @@ -301,7 +301,8 @@ void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void /* Executes irg_walk(end, pre, post, env) for all irgraphs in irprog. Sets current_ir_graph properly for each walk. Conserves current current_ir_graph. */ -void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) { +void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) +{ int i, n; ir_graph *irg; @@ -318,8 +319,8 @@ void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) { * * @return number of visited nodes */ -static unsigned -irg_walk_in_or_dep_2_pre(ir_node *node, irg_walk_func *pre, void *env) { +static unsigned irg_walk_in_or_dep_2_pre(ir_node *node, irg_walk_func *pre, void *env) +{ int i; unsigned cnt = 1; ir_graph *irg = current_ir_graph; @@ -346,8 +347,8 @@ irg_walk_in_or_dep_2_pre(ir_node *node, irg_walk_func *pre, void *env) { * * @return number of visited nodes */ -static unsigned -irg_walk_in_or_dep_2_post(ir_node *node, irg_walk_func *post, void *env) { +static unsigned irg_walk_in_or_dep_2_post(ir_node *node, irg_walk_func *post, void *env) +{ int i; unsigned cnt = 1; ir_graph *irg = current_ir_graph; @@ -375,8 +376,8 @@ irg_walk_in_or_dep_2_post(ir_node *node, irg_walk_func *post, void *env) { * * @return number of visited nodes */ -static unsigned -irg_walk_in_or_dep_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env) { +static unsigned irg_walk_in_or_dep_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; @@ -406,8 +407,7 @@ irg_walk_in_or_dep_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post * * @return number of visited nodes */ -static unsigned -irg_walk_in_or_dep_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env) +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); @@ -437,7 +437,8 @@ void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, /* * Walk over a graph. Follow all edges (including dependencies) */ -void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) { +void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) +{ ir_graph * rem = current_ir_graph; hook_irg_walk(irg, (generic_func *)pre, (generic_func *)post); @@ -453,8 +454,8 @@ void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func * * Returns current_ir_graph and sets it to the irg of predecessor index * of node n. */ -static INLINE ir_graph * -switch_irg(ir_node *n, int index) { +static inline ir_graph * switch_irg(ir_node *n, int index) +{ ir_graph *old_current = current_ir_graph; if (get_interprocedural_view()) { @@ -472,8 +473,8 @@ switch_irg(ir_node *n, int index) { return old_current; } -static void -cg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) +#ifdef INTERPROCEDURAL_VIEW +static void cg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) { int i; ir_graph *rem = NULL; @@ -497,9 +498,9 @@ cg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) } } -#ifdef INTERPROCEDURAL_VIEW /* Walks all irgs in interprocedural view. Visits each node only once. */ -void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) { +void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) +{ int i; ir_graph *rem = current_ir_graph; int rem_view = get_interprocedural_view(); @@ -562,7 +563,8 @@ void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) { /***************************************************************************/ /* Walks back from n until it finds a real cf op. */ -static ir_node *get_cf_op(ir_node *n) { +static ir_node *get_cf_op(ir_node *n) +{ while (!is_cfop(n) && !is_fragile_op(n) && !is_Bad(n)) { n = skip_Id(n); n = skip_Tuple(n); @@ -578,13 +580,13 @@ static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *p if (!Block_block_visited(node)) { 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) { + 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) { + if (get_irn_opcode(pred) == iro_Block) { /* recursion */ irg_block_walk_2(pred, pre, post, env); } @@ -593,7 +595,7 @@ static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *p } } - if(post) post(node, env); + if (post) post(node, env); } } @@ -610,7 +612,7 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void assert(node); assert(!get_interprocedural_view()); /* interprocedural_view not implemented, because it - * interleaves with irg_walk */ + * interleaves with irg_walk */ ir_reserve_resources(irg, IR_RESOURCE_BLOCK_VISITED); inc_irg_block_visited(irg); block = is_Block(node) ? node : get_nodes_block(node); @@ -622,19 +624,16 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void int arity = get_irn_arity(node); for (i = 0; i < arity; i++) { pred = get_irn_n(node, i); - if (is_Block(pred)) - irg_block_walk_2(pred, pre, post, env); - } - /* Sometimes the blocks died, but are still reachable through Phis. - * Make sure the algorithms that try to remove these reach them. */ - for (i = 0; i < arity; i++) { - pred = get_irn_n(node, i); - if (get_irn_op(pred) == op_Phi) { - ir_node *block = get_nodes_block(pred); - - if (! is_Bad(block)) - irg_block_walk_2(block, pre, post, env); + if (!is_Block(pred)) { + pred = get_nodes_block(pred); + if (!is_Block(pred)) { + /* if rare cases a kept node might have a bad block input */ + continue; + } } + /* Sometimes the blocks died, but are still reachable through kept nodes. + * Make sure the algorithms that try to remove these reach them. */ + irg_block_walk_2(pred, pre, post, env); } } @@ -645,7 +644,8 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * walk over a graph block wise */ void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, - irg_walk_func *post, void *env) { + irg_walk_func *post, void *env) +{ ir_graph * rem = current_ir_graph; current_ir_graph = irg; irg_block_walk(get_irg_end(irg), pre, post, env); @@ -655,7 +655,8 @@ void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, /* * Additionally walk over all anchors. Do NOT increase the visit flag. */ -void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) { +void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) +{ ir_graph * rem = current_ir_graph; current_ir_graph = irg; @@ -675,7 +676,7 @@ typedef struct walk_env { static void walk_initializer(ir_initializer_t *initializer, walk_env *env) { - switch(initializer->kind) { + switch (initializer->kind) { case IR_INITIALIZER_CONST: irg_walk(initializer->consti.value, env->pre, env->post, env->env); return; @@ -685,7 +686,7 @@ static void walk_initializer(ir_initializer_t *initializer, walk_env *env) case IR_INITIALIZER_COMPOUND: { size_t i; - for(i = 0; i < initializer->compound.n_initializers; ++i) { + for (i = 0; i < initializer->compound.n_initializers; ++i) { ir_initializer_t *subinitializer = initializer->compound.initializers[i]; walk_initializer(subinitializer, env); @@ -703,24 +704,22 @@ static void walk_entity(ir_entity *ent, void *env) { walk_env *my_env = (walk_env *)env; - if (get_entity_variability(ent) != variability_uninitialized) { - if (ent->has_initializer) { - walk_initializer(ent->attr.initializer, my_env); - } else if (is_atomic_entity(ent)) { - irg_walk(get_atomic_ent_value(ent), my_env->pre, my_env->post, my_env->env); - } else { - int i, n_vals = get_compound_ent_n_values(ent); + if (ent->initializer != NULL) { + walk_initializer(ent->initializer, my_env); + } else if (entity_has_compound_ent_values(ent)) { + int i, n_vals = get_compound_ent_n_values(ent); - for (i = 0; i < n_vals; i++) - irg_walk(get_compound_ent_value(ent, i), my_env->pre, my_env->post, my_env->env); - } + for (i = 0; i < n_vals; i++) + irg_walk(get_compound_ent_value(ent, i), my_env->pre, my_env->post, my_env->env); } } /* Walks over all code in const_code_irg. */ -void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) { +void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) +{ int i, j, n_types; walk_env my_env; + ir_segment_t s; ir_graph *rem = current_ir_graph; current_ir_graph = get_const_code_irg(); @@ -731,7 +730,8 @@ void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) { my_env.env = env; /* Walk all types that can contain constant entities. */ - walk_types_entities(get_glob_type(), &walk_entity, &my_env); + for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; s++) + walk_types_entities(get_segment_type(s), &walk_entity, &my_env); n_types = get_irp_n_types(); for (i = 0; i < n_types; i++) walk_types_entities(get_irp_type(i), &walk_entity, &my_env);