X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana%2Firdom.c;h=ffb2c97b91c8bab517920251c73d233b62f84811;hb=4bad1346ff2abc3923beea23e5ac949acc7ca514;hp=b130f035893190756dc7b5bd6da405c3ccd6a737;hpb=12148ddd57ebc3de87a970b8e6a3f4084af57344;p=libfirm diff --git a/ir/ana/irdom.c b/ir/ana/irdom.c index b130f0358..ffb2c97b9 100644 --- a/ir/ana/irdom.c +++ b/ir/ana/irdom.c @@ -118,23 +118,20 @@ ir_node *get_Block_dominated_next(const ir_node *bl) return get_dom_info(bl)->next; } -void dom_tree_walk(ir_node *n, irg_walk_func *pre, +void dom_tree_walk(ir_node *bl, irg_walk_func *pre, irg_walk_func *post, void *env) { ir_node *p; - assert(get_irn_irg(n)->dom_state == dom_consistent - && "The dominators of the irg must be consistent"); - - for(p = get_dom_info(p)->first; p; p = get_dom_info(p)->next) { - if(pre) - pre(p, env); + if(pre) + pre(bl, env); + dominates_for_each(bl, p) { dom_tree_walk(p, pre, post, env); - - if(post) - post(p, env); } + + if(post) + post(bl, env); } void dom_tree_walk_irg(ir_graph *irg, irg_walk_func *pre, @@ -155,6 +152,7 @@ static void assign_tree_pre_order(ir_node *bl, void *data) { unsigned *num = data; dom_info *bi = get_dom_info(bl); + bi->tree_pre_num = (*num)++; } @@ -163,13 +161,16 @@ static void assign_tree_pre_order_max(ir_node *bl, void *data) dom_info *bi = get_dom_info(bl); ir_node *p; unsigned max = 0; + unsigned children = 0; for(p = bi->first; p; p = get_dom_info(p)->next) { unsigned max_p = get_dom_info(p)->max_subtree_pre_num; max = max > max_p ? max : max_p; + children++; } - bi->max_subtree_pre_num = max; + bi->max_subtree_pre_num = children > 0 ? max : bi->tree_pre_num; + assert(bi->max_subtree_pre_num >= bi->tree_pre_num); } /*--------------------------------------------------------------------*/ @@ -180,6 +181,7 @@ static void count_and_init_blocks(ir_node *bl, void *env) { int *n_blocks = (int *) env; (*n_blocks) ++; + memset(get_dom_info(bl), 0, sizeof(dom_info)); set_Block_idom(bl, NULL); set_Block_pre_num(bl, -1); set_Block_dom_depth(bl, -1); @@ -351,14 +353,12 @@ void compute_doms(ir_graph *irg) { } /* Step 4 */ tdi_list[0].dom = NULL; - memset(get_dom_info(tdi_list[0].block), 0, sizeof(dom_info)); set_Block_idom(tdi_list[0].block, NULL); set_Block_dom_depth(tdi_list[0].block, 1); for (i = 1; i < n_blocks; i++) { tmp_dom_info *w = &tdi_list[i]; if (w->dom != w->semi) w->dom = w->dom->dom; - memset(get_dom_info(tdi_list[i].block), 0, sizeof(dom_info)); set_Block_idom(w->block, w->dom->block); set_Block_dom_depth(w->block, get_Block_dom_depth(w->dom->block) + 1); }