X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana%2Firdom.c;h=ff572d8de4e40c5ebe8045d8baa87db802545de9;hb=ceefa5a3e6ff610b4b7d92033b8c2443cbc07938;hp=daf3b82a8e421d57a5942ebcc4ed683278c8d887;hpb=32ea6ea0320f551448bb66e534e3351977464d42;p=libfirm diff --git a/ir/ana/irdom.c b/ir/ana/irdom.c index daf3b82a8..ff572d8de 100644 --- a/ir/ana/irdom.c +++ b/ir/ana/irdom.c @@ -52,7 +52,8 @@ ir_node *get_Block_idom(const ir_node *bl) assert(is_Block(bl)); if (get_Block_dom_depth(bl) == -1) { /* This block is not reachable from Start */ - return new_Bad(); + ir_graph *irg = get_irn_irg(bl); + return new_r_Bad(irg); } return get_dom_info(bl)->idom; } @@ -70,7 +71,7 @@ void set_Block_idom(ir_node *bl, ir_node *n) * If we don't set the root of the dominator tree * Append bl to the dominates queue of n. */ - if(n != NULL) { + if (n != NULL) { ir_dom_info *ni = get_dom_info(n); bli->next = ni->first; @@ -83,7 +84,8 @@ ir_node *get_Block_ipostdom(const ir_node *bl) assert(is_Block(bl)); if (get_Block_postdom_depth(bl) == -1) { /* This block is not reachable from Start */ - return new_Bad(); + ir_graph *irg = get_irn_irg(bl); + return new_r_Bad(irg); } return get_pdom_info(bl)->idom; } @@ -101,7 +103,7 @@ void set_Block_ipostdom(ir_node *bl, ir_node *n) * If we don't set the root of the post dominator tree * Append bl to the post dominates queue of n. */ - if(n != NULL) { + if (n != NULL) { ir_dom_info *ni = get_pdom_info(n); bli->next = ni->first; @@ -347,14 +349,14 @@ void dom_tree_walk(ir_node *bl, irg_walk_func *pre, { ir_node *p; - if(pre) + if (pre) pre(bl, env); dominates_for_each(bl, p) { dom_tree_walk(p, pre, post, env); } - if(post) + if (post) post(bl, env); } @@ -364,14 +366,14 @@ void postdom_tree_walk(ir_node *bl, irg_walk_func *pre, { ir_node *p; - if(pre) + if (pre) pre(bl, env); postdominates_for_each(bl, p) { postdom_tree_walk(p, pre, post, env); } - if(post) + if (post) post(bl, env); } @@ -408,7 +410,7 @@ void postdom_tree_walk_irg(ir_graph *irg, irg_walk_func *pre, static void assign_tree_dom_pre_order(ir_node *bl, void *data) { - unsigned *num = data; + unsigned *num = (unsigned*) data; ir_dom_info *bi = get_dom_info(bl); bi->tree_pre_num = (*num)++; @@ -422,7 +424,7 @@ static void assign_tree_dom_pre_order_max(ir_node *bl, void *data) unsigned children = 0; (void) data; - for(p = bi->first; p; p = get_dom_info(p)->next) { + 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++; @@ -434,7 +436,7 @@ static void assign_tree_dom_pre_order_max(ir_node *bl, void *data) static void assign_tree_postdom_pre_order(ir_node *bl, void *data) { - unsigned *num = data; + unsigned *num = (unsigned*) data; ir_dom_info *bi = get_pdom_info(bl); bi->tree_pre_num = (*num)++; @@ -448,7 +450,7 @@ static void assign_tree_postdom_pre_order_max(ir_node *bl, void *data) unsigned children = 0; (void) data; - for(p = bi->first; p; p = get_pdom_info(p)->next) { + for (p = bi->first; p; p = get_pdom_info(p)->next) { unsigned max_p = get_pdom_info(p)->max_subtree_pre_num; max = max > max_p ? max : max_p; children++; @@ -468,6 +470,10 @@ static void assign_tree_postdom_pre_order_max(ir_node *bl, void *data) static void count_and_init_blocks_pdom(ir_node *bl, void *env) { int *n_blocks = (int *) env; + + if (is_Block_dead(bl)) + return; + (*n_blocks) ++; memset(get_pdom_info(bl), 0, sizeof(ir_dom_info)); @@ -506,12 +512,16 @@ typedef struct { * Start block misses control dead blocks. */ static void init_tmp_dom_info(ir_node *bl, tmp_dom_info *parent, - tmp_dom_info *tdi_list, int *used, int n_blocks) { + tmp_dom_info *tdi_list, int *used, int n_blocks) +{ tmp_dom_info *tdi; int i; + if (is_Block_dead(bl)) + return; + assert(is_Block(bl)); - if (get_irg_block_visited(current_ir_graph) == get_Block_block_visited(bl)) + if (Block_block_visited(bl)) return; mark_Block_block_visited(bl); set_Block_dom_pre_num(bl, *used); @@ -544,10 +554,14 @@ static void init_tmp_dom_info(ir_node *bl, tmp_dom_info *parent, * End block misses blocks in endless loops. */ static void init_tmp_pdom_info(ir_node *bl, tmp_dom_info *parent, - tmp_dom_info *tdi_list, int* used, int n_blocks) { + tmp_dom_info *tdi_list, int* used, int n_blocks) +{ tmp_dom_info *tdi; int i; + if (is_Block_dead(bl)) + return; + assert(is_Block(bl)); if (get_irg_block_visited(current_ir_graph) == get_Block_block_visited(bl)) return; @@ -626,6 +640,9 @@ inline static void dom_link(tmp_dom_info *v, tmp_dom_info *w) static void count_and_init_blocks_dom(ir_node *bl, void *env) { int *n_blocks = (int *) env; + if (is_Block_dead(bl)) + return; + (*n_blocks) ++; memset(get_dom_info(bl), 0, sizeof(ir_dom_info)); @@ -634,63 +651,6 @@ static void count_and_init_blocks_dom(ir_node *bl, void *env) set_Block_dom_depth(bl, -1); } -/** - * Initialize the dominance/postdominance construction: - * - * - count the number of blocks - * - clear the dominance info - * - remove Block-keepalives of live blocks to reduce - * the number of "phantom" block edges - * - * @param irg the graph - * @param pre a walker function that will be called for every block in the graph - */ -static int init_construction(ir_graph *irg, irg_walk_func *pre) -{ - ir_graph *rem = current_ir_graph; - ir_node *end; - int arity; - int n_blocks = 0; - - current_ir_graph = irg; - - /* this visits only the reachable blocks */ - irg_block_walk(get_irg_end_block(irg), pre, NULL, &n_blocks); - - /* now visit the unreachable (from End) Blocks and remove unnecessary keep-alives */ - end = get_irg_end(irg); - arity = get_End_n_keepalives(end); - if (arity) { /* we have keep-alives */ - ir_node **in; - int i, j; - - NEW_ARR_A(ir_node *, in, arity); - for (i = j = 0; i < arity; i++) { - ir_node *pred = get_End_keepalive(end, i); - - if (!is_Block(pred)) { - pred = get_nodes_block(pred); - if (!is_Block(pred)) { - /* a node which has a bad block input: kill it */ - continue; - } - } - dec_irg_block_visited(irg); - irg_block_walk(pred, pre, NULL, &n_blocks); - in[j++] = pred; - } - if (j != arity) { - /* we kill some keep-alives */ - set_End_keepalives(end, j, in); - set_irg_outs_inconsistent(irg); - } - } - - current_ir_graph = rem; - return n_blocks; -} - - /* Computes the dominator trees. Sets a flag in irg to "dom_consistent". If the control flow of the graph is changed this flag must be set to "dom_inconsistent". */ @@ -707,7 +667,8 @@ void compute_doms(ir_graph *irg) irg->dom_state = dom_consistent; /* Count the number of blocks in the graph. */ - n_blocks = init_construction(irg, count_and_init_blocks_dom); + n_blocks = 0; + irg_block_walk_graph(irg, count_and_init_blocks_dom, NULL, &n_blocks); /* Memory for temporary information. */ tdi_list = XMALLOCNZ(tmp_dom_info, n_blocks); @@ -739,7 +700,7 @@ void compute_doms(ir_graph *irg) tmp_dom_info *u; if (is_Bad(pred) || (get_Block_dom_pre_num (pred) == -1)) - continue; /* control-dead */ + continue; /* control-dead */ u = dom_eval (&tdi_list[get_Block_dom_pre_num(pred)]); if (u->semi < w->semi) w->semi = u->semi; @@ -754,8 +715,8 @@ void compute_doms(ir_graph *irg) ir_node *pred = get_irn_n(end, j); tmp_dom_info *u; - if (is_no_Block(pred) || get_Block_dom_pre_num(pred) == -1) - continue; /* control-dead */ + if (!is_Block(pred) || get_Block_dom_pre_num(pred) == -1) + continue; /* control-dead */ u = dom_eval (&tdi_list[get_Block_dom_pre_num(pred)]); if (u->semi < w->semi) w->semi = u->semi; @@ -849,7 +810,8 @@ void compute_postdoms(ir_graph *irg) irg->pdom_state = dom_consistent; /* Count the number of blocks in the graph. */ - n_blocks = init_construction(irg, count_and_init_blocks_pdom); + n_blocks = 0; + irg_block_walk_graph(irg, count_and_init_blocks_pdom, NULL, &n_blocks); /* Memory for temporary information. */ tdi_list = XMALLOCNZ(tmp_dom_info, n_blocks); @@ -880,7 +842,7 @@ void compute_postdoms(ir_graph *irg) tmp_dom_info *u; if (get_Block_postdom_pre_num (succ) == -1) - continue; /* endless-loop */ + continue; /* endless-loop */ u = dom_eval (&tdi_list[get_Block_postdom_pre_num(succ)]); if (u->semi < w->semi) w->semi = u->semi;