X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgwalk.c;h=f879313ed295b5c8e49d287677beaa464f182c85;hb=169fd803ea2ed08171113c1fd7ab4e528e1ebc26;hp=180680b04c8950e03b7113a0d7d6d85da7f7ce52;hpb=92113524c53ef7b31e31b9ab4f4e2f7af69d46b8;p=libfirm diff --git a/ir/ir/irgwalk.c b/ir/ir/irgwalk.c index 180680b04..f879313ed 100644 --- a/ir/ir/irgwalk.c +++ b/ir/ir/irgwalk.c @@ -11,31 +11,38 @@ */ /** -* traverse an ir graph -* - execute the pre function before recursion -* - execute the post function after recursion -*/ + * @file irgwalk.c + * + * traverse an ir graph + * - execute the pre function before recursion + * - execute the post function after recursion + */ #ifdef HAVE_CONFIG_H -# include +# include "config.h" #endif -#include +#ifdef HAVE_STDLIB_H +# include +#endif #include "irnode_t.h" #include "irgraph_t.h" /* visited flag */ #include "irprog.h" #include "irgwalk.h" #include "typewalk.h" -#include "firmstat.h" +#include "irhooks.h" #include "ircgcons.h" #include "eset.h" #include "array.h" -/* walk over an interprocedural graph (callgraph). Visits only graphs in irg_set. */ -static void irg_walk_cg(ir_node * node, int visited, eset * irg_set, +/** + * Walk over an interprocedural graph (callgraph). + * Visits only graphs in irg_set. + */ +static void irg_walk_cg(ir_node * node, unsigned long visited, eset * irg_set, irg_walk_func *pre, irg_walk_func *post, void * env) { int i; ir_graph * rem = current_ir_graph; @@ -105,13 +112,15 @@ static void irg_walk_cg(ir_node * node, int visited, eset * irg_set, } -/* Insert all ir_graphs in irg_set, that are (transitive) reachable. */ +/** + * Insert all ir_graphs in irg_set, that are (transitive) reachable. + */ static void collect_irgs(ir_node * node, eset * irg_set) { if (get_irn_op(node) == op_Call) { int i; for (i = get_Call_n_callees(node) - 1; i >= 0; --i) { entity * ent = get_Call_callee(node, i); - ir_graph * irg = ent ? get_entity_irg(ent) : NULL; + ir_graph * irg = get_entity_irg(ent); if (irg && !eset_contains(irg_set, irg)) { eset_insert(irg_set, irg); irg_walk_graph(irg, (irg_walk_func *) collect_irgs, NULL, irg_set); @@ -208,16 +217,16 @@ void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env) { assert(node && node->kind==k_ir_node); - if (interprocedural_view) { + if (get_interprocedural_view()) { eset * irg_set = eset_create(); - int visited; + unsigned long visited; ir_graph * irg; assert(get_irp_ip_view_state() == ip_view_valid); - interprocedural_view = false; + set_interprocedural_view(false); eset_insert(irg_set, current_ir_graph); irg_walk(node, (irg_walk_func *) collect_irgs, NULL, irg_set); - interprocedural_view = true; + set_interprocedural_view(true); visited = get_max_irg_visited() + 1; for (irg = eset_first(irg_set); irg; irg = eset_next(irg_set)) { set_irg_visited(irg, visited); @@ -231,11 +240,13 @@ void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env) return; } - +/* + * walk over a graph + */ void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) { ir_graph * rem = current_ir_graph; - stat_irg_walk(irg, (void *)pre, (void *)post); + hook_irg_walk(irg, (generic_func *)pre, (generic_func *)post); current_ir_graph = irg; irg_walk(get_irg_end(irg), pre, post, env); current_ir_graph = rem; @@ -266,14 +277,14 @@ static INLINE ir_graph * switch_irg (ir_node *n, int index) { ir_graph *old_current = current_ir_graph; - if (interprocedural_view) { + if (get_interprocedural_view()) { /* Only Filter and Block nodes can have predecessors in other graphs. */ if (get_irn_op(n) == op_Filter) n = get_nodes_block(n); if (get_irn_op(n) == op_Block) { ir_node *cfop = skip_Proj(get_Block_cfgpred(n, index)); if (is_ip_cfop(cfop)) { - current_ir_graph = get_irn_irg(cfop); + current_ir_graph = get_irn_irg(cfop); } } } @@ -312,9 +323,9 @@ cg_walk_2(ir_node *node, 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 = interprocedural_view; + int rem_view = get_interprocedural_view(); - interprocedural_view = true; + set_interprocedural_view(true); inc_max_irg_visited(); /* Fix all irg_visited flags */ @@ -363,7 +374,7 @@ void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) { } } - interprocedural_view = rem_view; + set_interprocedural_view(rem_view); current_ir_graph = rem; } @@ -388,8 +399,8 @@ static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *p { int i; - if(get_Block_block_visited(node) < get_irg_block_visited(current_ir_graph)) { - set_Block_block_visited(node, get_irg_block_visited(current_ir_graph)); + if (Block_not_block_visited(node)) { + mark_Block_block_visited(node); if(pre) pre(node, env); @@ -398,11 +409,11 @@ static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *p 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); + /* recursion */ + irg_block_walk_2(pred, pre, post, env); } else { - assert(get_irn_opcode(pred) == iro_Bad); + assert(get_irn_opcode(pred) == iro_Bad); } } @@ -419,15 +430,16 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void ir_node *block, *pred; int i; - stat_irg_block_walk(current_ir_graph, node, (void *)pre, (void *)post); + hook_irg_block_walk(current_ir_graph, node, (generic_func *)pre, (generic_func *)post); assert(node); - assert(!interprocedural_view); /* interprocedural_view not implemented, because it + assert(!get_interprocedural_view()); /* interprocedural_view not implemented, because it * interleaves with irg_walk */ inc_irg_block_visited(current_ir_graph); if (is_no_Block(node)) block = get_nodes_block(node); else block = node; assert(get_irn_opcode(block) == iro_Block); irg_block_walk_2(block, pre, post, env); + /* keepalive: the endless loops ... */ if (get_irn_op(node) == op_End) { int arity = get_irn_arity(node); @@ -436,12 +448,25 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void if (get_irn_op(pred) == op_Block) 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); + } + } } return; } - +/* + * walk over a graph block wise + */ void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) { ir_graph * rem = current_ir_graph; @@ -458,7 +483,9 @@ typedef struct walk_env { void *env; } walk_env; -/* Walk to all constant expressions in this entity. */ +/** + * Walk to all constant expressions in this entity. + */ static void walk_entity(entity *ent, void *env) { walk_env *my_env = (walk_env *)env; @@ -468,9 +495,9 @@ static void walk_entity(entity *ent, void *env) irg_walk(get_atomic_ent_value(ent), my_env->pre, my_env->post, my_env->env); } else { - int i, n = get_compound_ent_n_values(ent); + int i, n_vals = get_compound_ent_n_values(ent); - for (i = 0; i < n; i++) + for (i = 0; i < n_vals; i++) irg_walk(get_compound_ent_value(ent, i), my_env->pre, my_env->post, my_env->env); } } @@ -499,13 +526,12 @@ void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) { /* Walk constant array bounds. */ for (i = 0; i < get_irp_n_types(); i++) { type *tp = get_irp_type(i); - if (is_array_type(tp)) { + if (is_Array_type(tp)) { for (j = 0; j < get_array_n_dimensions(tp); j++) { - ir_node *n; - n = get_array_lower_bound(tp, j); - if (n) irg_walk(n, pre, post, env); - n = get_array_upper_bound(tp, j); - if (n) irg_walk(n, pre, post, env); + ir_node *n = get_array_lower_bound(tp, j); + if (n) irg_walk(n, pre, post, env); + n = get_array_upper_bound(tp, j); + if (n) irg_walk(n, pre, post, env); } } }