From: Matthias Braun Date: Sun, 25 Mar 2007 16:55:14 +0000 (+0000) Subject: generalize the inside_walk flags: we have using_visited, using_block_visited and... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=28026a9f6aee143c644be2be98d16f2fa66b34f4;p=libfirm generalize the inside_walk flags: we have using_visited, using_block_visited and using_irn_link now [r8729] --- diff --git a/ir/ir/ircgcons.c b/ir/ir/ircgcons.c index dc5dc87b2..d1181f74e 100644 --- a/ir/ir/ircgcons.c +++ b/ir/ir/ircgcons.c @@ -150,12 +150,16 @@ static void link(ir_node * head, ir_node * node) { * ... -> Proj -> NULL. */ static void collect_phicallproj(void) { int i; + for (i = get_irp_n_irgs() - 1; i >= 0; --i) { ir_graph * irg = get_irp_irg(i); ir_node * start = get_irg_start(irg); ir_node * end = get_irg_end(irg); current_ir_graph = irg; assert(irg && start); + + set_using_irn_link(irg); + /* Die speziellen Parameter der Start-Operation extra verlinken, * auch wenn sie nicht im intraprozeduralen Graphen erreichbar * sind. */ @@ -163,6 +167,8 @@ static void collect_phicallproj(void) { link(start, get_irg_globals(irg)); /* walk */ irg_walk_graph(irg, firm_clear_link, (irg_walk_func *) collect_phicallproj_walker, &end); + + clear_using_irn_link(irg); } } diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index 9d36c01f2..4c7601c7d 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -580,12 +580,13 @@ static void collect_node(ir_node * node, void *env) { static ir_node **construct_block_lists(ir_graph *irg) { int i; int rem_view = get_interprocedural_view(); - int walk_flag = inside_irg_walk(irg); + int walk_flag = using_visited(irg); ir_graph *rem = current_ir_graph; current_ir_graph = irg; - clear_inside_irg_walk(current_ir_graph); + if(walk_flag) + clear_using_visited(current_ir_graph); for (i = get_irp_n_irgs() - 1; i >= 0; --i) ird_set_irg_link(get_irp_irg(i), NULL); @@ -602,8 +603,8 @@ static ir_node **construct_block_lists(ir_graph *irg) { set_interprocedural_view(rem_view); - if (walk_flag) - set_inside_irg_walk(current_ir_graph); + if(walk_flag) + set_using_visited(current_ir_graph); current_ir_graph = rem; return ird_get_irg_link(irg); diff --git a/ir/ir/irgopt.c b/ir/ir/irgopt.c index 5cca95599..8e18d55fd 100644 --- a/ir/ir/irgopt.c +++ b/ir/ir/irgopt.c @@ -185,6 +185,8 @@ void optimize_graph_df(ir_graph *irg) { set_irg_doms_inconsistent(irg); set_irg_loopinfo_inconsistent(irg); + set_using_irn_link(irg); + /* walk over the graph */ irg_walk_graph(irg, NULL, opt_walker, waitq); @@ -197,6 +199,8 @@ void optimize_graph_df(ir_graph *irg) { del_pdeq(waitq); + clear_using_irn_link(irg); + if (! state) edges_deactivate(irg); diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index 157a5823c..5c668252b 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -873,36 +873,52 @@ void *get_irg_loc_description(ir_graph *irg, int n) { return irg->loc_descriptions ? irg->loc_descriptions[n] : NULL; } -/* Sets the inside block walk flag */ -void (set_inside_block_walk)(ir_graph *irg) { - _set_inside_block_walk(irg); +#ifndef NDEBUG +void set_using_block_visited(ir_graph *irg) { + assert(irg->using_block_visited == 0); + irg->using_block_visited = 1; } -/* Clears the inside block walk flag */ -void (clear_inside_block_walk)(ir_graph *irg) { - _clear_inside_block_walk(irg); +void clear_using_block_visited(ir_graph *irg) { + assert(irg->using_block_visited == 1); + irg->using_block_visited = 0; } -/* Returns the inside block walk flag */ -unsigned (inside_block_walk)(const ir_graph *irg) { - return _inside_block_walk(irg); +int using_block_visited(const ir_graph *irg) { + return irg->using_block_visited; } -/* Sets the inside irg walk flag */ -void (set_inside_irg_walk)(ir_graph *irg) { - _clear_inside_irg_walk(irg); + +void set_using_visited(ir_graph *irg) { + assert(irg->using_visited == 0); + irg->using_visited = 1; } -/* Clears the inside irg walk flag */ -void (clear_inside_irg_walk)(ir_graph *irg) { - _clear_inside_irg_walk(irg); +void clear_using_visited(ir_graph *irg) { + assert(irg->using_visited == 1); + irg->using_visited = 0; } -/* Returns the inside irg walk flag */ -unsigned (inside_irg_walk)(const ir_graph *irg) { - return _inside_irg_walk(irg); +int using_visited(const ir_graph *irg) { + return irg->using_visited; } + +void set_using_irn_link(ir_graph *irg) { + assert(irg->using_irn_link == 0); + irg->using_irn_link = 1; +} + +void clear_using_irn_link(ir_graph *irg) { + assert(irg->using_irn_link == 1); + irg->using_irn_link = 0; +} + +int using_irn_link(const ir_graph *irg) { + return irg->using_irn_link; +} +#endif + /* Returns a estimated node count of the irg. */ unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg) { return _get_irg_estimated_node_cnt(irg); diff --git a/ir/ir/irgraph.h b/ir/ir/irgraph.h index 3b2f52acf..8655b060b 100644 --- a/ir/ir/irgraph.h +++ b/ir/ir/irgraph.h @@ -478,13 +478,32 @@ void inc_irg_block_visited (ir_graph *irg); unsigned long get_irg_block_visited (const ir_graph *irg); void set_irg_block_visited (ir_graph *irg, unsigned long i); -/** Flags indicating whether or not we are inside an irg/block walk. */ -void set_inside_block_walk(ir_graph *irg); -void clear_inside_block_walk(ir_graph *irg); -unsigned inside_block_walk(const ir_graph *irg); -void set_inside_irg_walk(ir_graph *irg); -void clear_inside_irg_walk(ir_graph *irg); -unsigned inside_irg_walk(const ir_graph *irg); +/** + * Debug helpers: You can indicate wether you are currently using visited or + * block_visited flags. If NDEBUG is not defined, then the compiler will abort + * if 2 parties try to use the flags. + */ +#ifndef NDEBUG +void set_using_block_visited(ir_graph *irg); +void clear_using_block_visited(ir_graph *irg); +int using_block_visited(const ir_graph *irg); +void set_using_visited(ir_graph *irg); +void clear_using_visited(ir_graph *irg); +int using_visited(const ir_graph *irg); +void set_using_irn_link(ir_graph *irg); +void clear_using_irn_link(ir_graph *irg); +int using_irn_link(const ir_graph *irg); +#else +static INLINE void set_using_block_visited(ir_graph *irg) { (void) irg; } +static INLINE void clear_using_block_visited(ir_graph *irg) { (void) irg; } +static int using_block_visited(const ir_graph *irg) { (void) irg; return 0; } +static INLINE void set_using_visited(ir_graph *irg) { (void) irg; } +static INLINE void clear_using_visited(ir_graph *irg) { (void) irg; } +static int using_visited(const ir_graph *irg) { (void) irg; return 0; } +static INLINE void set_using_irn_link(ir_graph *irg) { (void) irg; } +static INLINE void clear_using_irn_link(ir_graph *irg) { (void) irg; } +static int using_irn_link(const ir_graph *irg) { (void) irg; return 0; } +#endif /** move Proj nodes into the same block as its predecessors */ void normalize_proj_nodes(ir_graph *irg); diff --git a/ir/ir/irgraph_t.h b/ir/ir/irgraph_t.h index 1a5bbd0f7..ef1f544ee 100644 --- a/ir/ir/irgraph_t.h +++ b/ir/ir/irgraph_t.h @@ -155,8 +155,13 @@ struct ir_graph { every time someone walks through the graph */ unsigned long block_visited; /**< same as visited, for a complete block */ - unsigned inside_irg_walk : 1; /**< set to 1 if we are currently in an irg walk */ - unsigned inside_block_walk : 1; /**< set to 1 if we are currently in a block walk */ + +#ifndef NDEBUG + unsigned using_visited : 1; /**< set to 1 if we are currently using the visited flag */ + unsigned using_block_visited : 1; /**< set to 1 if we are currently using the block_visited flag */ + unsigned using_irn_link : 1; /**< set to 1 if we are currently using the irn_link fields */ +#endif + unsigned estimated_node_count; /**< estimated number of nodes in this graph, updated after every walk */ irg_edges_info_t edge_info; /**< edge info for automatic outs */ @@ -557,36 +562,6 @@ _dec_irg_block_visited(ir_graph *irg) { --irg->block_visited; } -static INLINE void -_set_inside_block_walk(ir_graph *irg) { - irg->inside_block_walk = 1; -} - -static INLINE void -_clear_inside_block_walk(ir_graph *irg) { - irg->inside_block_walk = 0; -} - -static INLINE unsigned -_inside_block_walk(const ir_graph *irg) { - return irg->inside_block_walk; -} - -static INLINE void -_set_inside_irg_walk(ir_graph *irg) { - irg->inside_irg_walk = 1; -} - -static INLINE void -_clear_inside_irg_walk(ir_graph *irg) { - irg->inside_irg_walk = 0; -} - -static INLINE unsigned -_inside_irg_walk(const ir_graph *irg) { - return irg->inside_irg_walk; -} - static INLINE unsigned _get_irg_estimated_node_cnt(const ir_graph *irg) { return irg->estimated_node_count; @@ -704,12 +679,6 @@ get_idx_irn(ir_graph *irg, unsigned idx) { #define set_irg_block_visited(irg, v) _set_irg_block_visited(irg, v) #define inc_irg_block_visited(irg) _inc_irg_block_visited(irg) #define dec_irg_block_visited(irg) _dec_irg_block_visited(irg) -#define set_inside_block_walk(irg) _set_inside_block_walk(irg) -#define clear_inside_block_walk(irg) _clear_inside_block_walk(irg) -#define inside_block_walk(irg) _inside_block_walk(irg) -#define set_inside_irg_walk(irg) _set_inside_irg_walk(irg) -#define clear_inside_irg_walk(irg) _clear_inside_irg_walk(irg) -#define inside_irg_walk(irg) _inside_irg_walk(irg) #define get_irg_estimated_node_cnt(irg) _get_irg_estimated_node_cnt(irg) #define get_irg_fp_model(irg) _get_irg_fp_model(irg) diff --git a/ir/ir/irgwalk.c b/ir/ir/irgwalk.c index 56a53c56b..446d5b8c8 100644 --- a/ir/ir/irgwalk.c +++ b/ir/ir/irgwalk.c @@ -260,11 +260,10 @@ void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env) irg_walk_cg(node, visited, irg_set, pre, post, env); eset_destroy(irg_set); } else { - assert(! inside_irg_walk(current_ir_graph)); /* we must not already be inside an irg walk */ - set_inside_irg_walk(current_ir_graph); + set_using_visited(current_ir_graph); inc_irg_visited(current_ir_graph); nodes_touched = irg_walk_2(node, pre, post, env); - clear_inside_irg_walk(current_ir_graph); + clear_using_visited(current_ir_graph); } return; } @@ -415,11 +414,10 @@ void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, if (get_interprocedural_view()) { assert(0 && "This is not yet implemented."); } else { - assert(! inside_irg_walk(current_ir_graph)); /* we must not already be inside an irg walk */ - set_inside_irg_walk(current_ir_graph); + set_using_visited(current_ir_graph); inc_irg_visited(current_ir_graph); nodes_touched = irg_walk_in_or_dep_2(node, pre, post, env); - clear_inside_irg_walk(current_ir_graph); + clear_using_visited(current_ir_graph); } return; } @@ -604,9 +602,8 @@ 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 */ - assert(! inside_irg_walk(current_ir_graph)); /* we must not already be in a block walk */ + set_using_block_visited(current_ir_graph); inc_irg_block_visited(current_ir_graph); - set_inside_block_walk(current_ir_graph); block = is_Block(node) ? node : get_nodes_block(node); assert(get_irn_op(block) == op_Block); irg_block_walk_2(block, pre, post, env); @@ -632,8 +629,7 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void } } - clear_inside_block_walk(current_ir_graph); - return; + clear_using_block_visited(current_ir_graph); } /* diff --git a/ir/ir/irgwalk_blk.c b/ir/ir/irgwalk_blk.c index 0de8e9613..c0a2c3390 100644 --- a/ir/ir/irgwalk_blk.c +++ b/ir/ir/irgwalk_blk.c @@ -346,9 +346,6 @@ do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *en int old_view = get_interprocedural_view(); block_entry_t *entry; - assert(! inside_irg_walk(irg)); /* we must not already be inside an irg walk */ - set_inside_irg_walk(irg); - /* switch off interprocedural view */ set_interprocedural_view(0); @@ -358,6 +355,7 @@ do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *en blks.follow_deps = follow_deps != 0; /* first step: traverse the graph and fill the lists */ + set_using_visited(irg); inc_irg_visited(irg); collect_walk(end_node, &blks); @@ -378,7 +376,7 @@ do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *en obstack_free(&blks.obst, NULL); set_interprocedural_view(old_view); - clear_inside_irg_walk(irg); + clear_using_visited(irg); } void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) diff --git a/ir/opt/condeval.c b/ir/opt/condeval.c index 1e18533c4..be50c2b45 100644 --- a/ir/opt/condeval.c +++ b/ir/opt/condeval.c @@ -25,6 +25,7 @@ #include "iredges.h" #include "iredges_t.h" #include "irtools.h" +#include "irgraph.h" #include "tv.h" DEBUG_ONLY(static firm_dbg_module_t *dbg); @@ -482,7 +483,6 @@ void opt_cond_eval(ir_graph* irg) int changed; FIRM_DBG_REGISTER(dbg, "firm.opt.condeval"); - //firm_dbg_set_mask(dbg, SET_LEVEL_5); DB((dbg, LEVEL_1, "===> Performing condition evaluation on %+F\n", irg)); @@ -491,8 +491,14 @@ void opt_cond_eval(ir_graph* irg) normalize_proj_nodes(irg); + set_using_irn_link(irg); + set_using_visited(irg); + do { changed = 0; irg_block_walk_graph(irg, cond_eval, NULL, &changed); } while(changed); + + clear_using_visited(irg); + clear_using_irn_link(irg); }