X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana%2Firdom.c;h=789d8c336bdc83d2fcc94f0bead62865bc429ba4;hb=f6aeac6a547a52beb3cb663c5e63c05c9c3728ea;hp=af11ca9d1484811c64c056fbabc1e7420216ce0f;hpb=1b57293234c2f0c753f48c94e0ca0f127b15a27b;p=libfirm diff --git a/ir/ana/irdom.c b/ir/ana/irdom.c index af11ca9d1..789d8c336 100644 --- a/ir/ana/irdom.c +++ b/ir/ana/irdom.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -40,7 +40,7 @@ #include "irgraph_t.h" /* To access state field. */ #include "irnode_t.h" #include "ircons_t.h" -#include "array.h" +#include "array_t.h" #include "iredges.h" @@ -63,7 +63,7 @@ ir_node *get_Block_idom(const ir_node *bl) { void set_Block_idom(ir_node *bl, ir_node *n) { ir_dom_info *bli = get_dom_info(bl); - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); /* Set the immediate dominator of bl to n */ bli->idom = n; @@ -92,7 +92,7 @@ ir_node *get_Block_ipostdom(const ir_node *bl) { void set_Block_ipostdom(ir_node *bl, ir_node *n) { ir_dom_info *bli = get_pdom_info(bl); - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); /* Set the immediate post dominator of bl to n */ bli->idom = n; @@ -110,43 +110,43 @@ void set_Block_ipostdom(ir_node *bl, ir_node *n) { } int get_Block_dom_pre_num(const ir_node *bl) { - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); return get_dom_info(bl)->pre_num; } void set_Block_dom_pre_num(ir_node *bl, int num) { - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); get_dom_info(bl)->pre_num = num; } int get_Block_dom_depth(const ir_node *bl) { - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); return get_dom_info(bl)->dom_depth; } void set_Block_dom_depth(ir_node *bl, int depth) { - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); get_dom_info(bl)->dom_depth = depth; } int get_Block_postdom_pre_num(const ir_node *bl) { - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); return get_pdom_info(bl)->pre_num; } void set_Block_postdom_pre_num(ir_node *bl, int num) { - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); get_pdom_info(bl)->pre_num = num; } int get_Block_postdom_depth(const ir_node *bl) { - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); return get_pdom_info(bl)->dom_depth; } void set_Block_postdom_depth(ir_node *bl, int depth) { - assert(get_irn_op(bl) == op_Block); + assert(is_Block(bl)); get_pdom_info(bl)->dom_depth = depth; } @@ -444,13 +444,15 @@ static void assign_tree_postdom_pre_order_max(ir_node *bl, void *data) * count the number of blocks and clears the post dominance info */ static void count_and_init_blocks_pdom(ir_node *bl, void *env) { - int *n_blocks = (int *) env; - (*n_blocks) ++; - - memset(get_pdom_info(bl), 0, sizeof(ir_dom_info)); - set_Block_ipostdom(bl, NULL); - set_Block_postdom_pre_num(bl, -1); - set_Block_postdom_depth(bl, -1); + if (is_Block(bl)) { + int *n_blocks = (int *) env; + (*n_blocks) ++; + + memset(get_pdom_info(bl), 0, sizeof(ir_dom_info)); + set_Block_ipostdom(bl, NULL); + set_Block_postdom_pre_num(bl, -1); + set_Block_postdom_depth(bl, -1); + } } /** temporary type used while constructing the dominator / post dominator tree. */ @@ -594,13 +596,15 @@ INLINE static void dom_link(tmp_dom_info *v, tmp_dom_info *w) { * Walker: count the number of blocks and clears the dominance info */ static void count_and_init_blocks_dom(ir_node *bl, void *env) { - int *n_blocks = (int *) env; - (*n_blocks) ++; - - memset(get_dom_info(bl), 0, sizeof(ir_dom_info)); - set_Block_idom(bl, NULL); - set_Block_dom_pre_num(bl, -1); - set_Block_dom_depth(bl, -1); + if (is_Block(bl)) { + int *n_blocks = (int *) env; + (*n_blocks) ++; + + memset(get_dom_info(bl), 0, sizeof(ir_dom_info)); + set_Block_idom(bl, NULL); + set_Block_dom_pre_num(bl, -1); + set_Block_dom_depth(bl, -1); + } } /** @@ -608,53 +612,21 @@ static void count_and_init_blocks_dom(ir_node *bl, void *env) { * * - 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 (get_irn_op(pred) == op_Block) { - if (Block_not_block_visited(pred)) { - /* we found a endless loop */ - dec_irg_block_visited(irg); - irg_block_walk(pred, pre, NULL, &n_blocks); - } - else - continue; - } - in[j++] = pred; - } - if (j != arity) { - /* we kill some Block keep-alives */ - set_End_keepalives(end, j, in); - set_irg_outs_inconsistent(irg); - } - } - - current_ir_graph = rem; + /* + * Normally one would use irg_block_walk_graph() here, however, this does NOT + * guarantee that all UNREACHABLE blocks are visited. + * This could led to wrong dominance info in those blocks, causing + * the verifier to crash for instance. + * So, we visit EVERY node to ensure the info is updated. + */ + irg_walk_graph(irg, pre, NULL, &n_blocks); return n_blocks; } @@ -677,7 +649,7 @@ void compute_doms(ir_graph *irg) { n_blocks = init_construction(irg, count_and_init_blocks_dom); /* Memory for temporary information. */ - tdi_list = xcalloc(n_blocks, sizeof(tdi_list[0])); + tdi_list = XMALLOCNZ(tmp_dom_info, n_blocks); /* We need the out data structure. */ assure_irg_outs(irg); @@ -816,7 +788,7 @@ void compute_postdoms(ir_graph *irg) { n_blocks = init_construction(irg, count_and_init_blocks_pdom); /* Memory for temporary information. */ - tdi_list = xcalloc(n_blocks, sizeof(tdi_list[0])); + tdi_list = XMALLOCNZ(tmp_dom_info, n_blocks); /* We need the out data structure. */ assure_irg_outs(irg);