X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbelive.c;h=bce02065983518c42fcc77c7712a5b40f78db8f7;hb=2822b67ee0e55acbdc420a9dc9a29d7e2b3f4723;hp=ae6940a3daf4577c0fe603cf74981e32e29adf86;hpb=5d001fc14a7d4ef4926012a9b5864341bac35066;p=libfirm diff --git a/ir/be/belive.c b/ir/be/belive.c index ae6940a3d..bce020659 100644 --- a/ir/be/belive.c +++ b/ir/be/belive.c @@ -73,7 +73,7 @@ static void live_end_at_block(ir_node *def, ir_node *block, mark_live_in(block, def); for(i = 0, n = get_irn_arity(block); i < n; ++i) - live_end_at_block(def, get_nodes_block(get_irn_n(block, i)), visited, 1); + live_end_at_block(def, get_Block_cfgpred_block(block, i), visited, 1); } } @@ -120,17 +120,8 @@ static void liveness_for_node(ir_node *irn, void *env) * value as live out of that block. */ if(is_Phi(use)) { - int i, n; - - /* Mark the node as a phi operand, since a use by a phi was found. */ - /* get_node_live_info(irn)->is_phi_op = 1; */ - - for(i = 0, n = get_irn_arity(use); i < n; ++i) { - if(get_irn_n(use, i) == irn) { - ir_node *pred_block = get_nodes_block(get_irn_n(use_block, i)); - live_end_at_block(irn, pred_block, visited, 0); - } - } + ir_node *pred_block = get_Block_cfgpred_block(use_block, edge->pos); + live_end_at_block(irn, pred_block, visited, 0); } /* @@ -166,6 +157,73 @@ void be_liveness(ir_graph *irg) if(live_info->live) del_set(live_info->live); + live_info->live = new_set(cmp_irn_live, 8192); irg_walk_graph(irg, liveness_for_node, NULL, NULL); } + +static void dump_liveness_walker(ir_node *bl, void *data) +{ + FILE *f = data; + const irn_live_t *li; + char buf[64]; + + ir_fprintf(f, "%+F\n", bl); + live_foreach(bl, li) { + strcpy(buf, ""); + + if(live_is_in(li)) + strcat(buf, "in "); + + if(live_is_end(li)) + strcat(buf, "end "); + + if(live_is_out(li)) + strcat(buf, "out "); + + ir_fprintf(f, "\t%+20F %s\n", li->irn, buf); + } +} + +void be_liveness_dump(ir_graph *irg, FILE *f) +{ + irg_block_walk_graph(irg, dump_liveness_walker, NULL, f); +} + +void be_liveness_dumpto(ir_graph *irg, const char *cls_name) +{ + FILE *f; + char buf[128]; + ir_snprintf(buf, sizeof(buf), "%F_%s-live.txt", irg, cls_name); + if((f = fopen(buf, "wt")) != NULL) { + be_liveness_dump(irg, f); + fclose(f); + } +} + +static void dom_check(ir_node *irn, void *data) +{ + if(!is_Block(irn) && irn != get_irg_end(get_irn_irg(irn))) { + int i, n; + ir_node *bl = get_nodes_block(irn); + + for(i = 0, n = get_irn_arity(irn); i < n; ++i) { + ir_node *op = get_irn_n(irn, i); + ir_node *def_bl = get_nodes_block(op); + ir_node *use_bl = bl; + + if(is_Phi(irn)) + use_bl = get_Block_cfgpred_block(bl, i); + + if(!block_dominates(def_bl, use_bl)) { + ir_fprintf(stderr, "%+F in %+F must dominate %+F for user %+F\n", op, def_bl, use_bl, irn); + assert(0); + } + } + } +} + +void be_check_dominance(ir_graph *irg) +{ + irg_walk_graph(irg, dom_check, NULL, NULL); +}