X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbelive.c;h=41778139fdff487d6fa0942685a8bc75a1e0c55f;hb=b38e2c8fb2d6b9f713f0948a536a28b623b0732b;hp=bd407d997224af2066929d46d876301ffbceb330;hpb=7e447b3efcd7b0e79c6746da340416206331d18d;p=libfirm diff --git a/ir/be/belive.c b/ir/be/belive.c index bd407d997..41778139f 100644 --- a/ir/be/belive.c +++ b/ir/be/belive.c @@ -1,20 +1,6 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. - * * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. + * Copyright (C) 2012 University of Karlsruhe. */ /** @@ -204,41 +190,10 @@ static int be_lv_remove(be_lv_t *li, const ir_node *bl, return 0; } -/** - * Mark a node as live-in in a block. - */ -static inline void mark_live_in(be_lv_t *lv, ir_node *block, ir_node *irn) -{ - be_lv_info_node_t *n = be_lv_get_or_set(lv, block, irn); - DBG((dbg, LEVEL_2, "marking %+F live in at %+F\n", irn, block)); - n->flags |= be_lv_state_in; -} - -/** - * Mark a node as live-out in a block. - */ -static inline void mark_live_out(be_lv_t *lv, ir_node *block, ir_node *irn) -{ - be_lv_info_node_t *n = be_lv_get_or_set(lv, block, irn); - DBG((dbg, LEVEL_2, "marking %+F live out at %+F\n", irn, block)); - n->flags |= be_lv_state_out | be_lv_state_end; -} - -/** - * Mark a node as live-end in a block. - */ -static inline void mark_live_end(be_lv_t *lv, ir_node *block, ir_node *irn) -{ - be_lv_info_node_t *n = be_lv_get_or_set(lv, block, irn); - DBG((dbg, LEVEL_2, "marking %+F live end at %+F\n", irn, block)); - n->flags |= be_lv_state_end; -} - static struct { be_lv_t *lv; /**< The liveness object. */ ir_node *def; /**< The node (value). */ ir_node *def_block; /**< The block of def. */ - bitset_t *visited; /**< A set were all visited blocks are recorded. */ } re; /** @@ -246,35 +201,32 @@ static struct { * transitively, i.e. if the block is not the block of the value's * definition, all predecessors are also marked live. * @param block The block to mark the value live out of. - * @param is_true_out Is the node real out there or only live at the end - * of the block. + * @param state The liveness bits to set, either end or end+out. */ -static void live_end_at_block(ir_node *block, int is_true_out) +static void live_end_at_block(ir_node *const block, be_lv_state_t const state) { - be_lv_t *lv = re.lv; - ir_node *def = re.def; - bitset_t *visited; + be_lv_info_node_t *const n = be_lv_get_or_set(re.lv, block, re.def); + be_lv_state_t const before = n->flags; - mark_live_end(lv, block, def); - if (is_true_out) - mark_live_out(lv, block, def); + assert(state == be_lv_state_end || state == (be_lv_state_end | be_lv_state_out)); + DBG((dbg, LEVEL_2, "marking %+F live %s at %+F\n", re.def, state & be_lv_state_out ? "end+out" : "end", block)); + n->flags |= state; - visited = re.visited; - if (!bitset_is_set(visited, get_irn_idx(block))) { - bitset_set(visited, get_irn_idx(block)); + /* There is no need to recurse further, if we where here before (i.e., any + * live state bits were set before). */ + if (before != be_lv_state_none) + return; - /* - * If this block is not the definition block, we have to go up - * further. - */ - if (re.def_block != block) { - int i; + /* Stop going up further, if this is the block of the definition. */ + if (re.def_block == block) + return; - mark_live_in(lv, block, def); + DBG((dbg, LEVEL_2, "marking %+F live in at %+F\n", re.def, block)); + n->flags |= be_lv_state_in; - for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) - live_end_at_block(get_Block_cfgpred_block(block, i), 1); - } + for (int i = get_Block_n_cfgpreds(block); i-- != 0;) { + ir_node *const pred_block = get_Block_cfgpred_block(block, i); + live_end_at_block(pred_block, be_lv_state_end | be_lv_state_out); } } @@ -291,10 +243,7 @@ typedef struct lv_remove_walker_t { */ static void liveness_for_node(ir_node *irn) { - ir_node *def_block; - - bitset_clear_all(re.visited); - def_block = get_nodes_block(irn); + ir_node *const def_block = get_nodes_block(irn); re.def = irn; re.def_block = def_block; @@ -324,7 +273,7 @@ static void liveness_for_node(ir_node *irn) */ if (is_Phi(use)) { ir_node *pred_block = get_Block_cfgpred_block(use_block, edge->pos); - live_end_at_block(pred_block, 0); + live_end_at_block(pred_block, be_lv_state_end); } /* @@ -334,11 +283,13 @@ static void liveness_for_node(ir_node *irn) else if (def_block != use_block) { int i; - mark_live_in(re.lv, use_block, irn); + be_lv_info_node_t *const n = be_lv_get_or_set(re.lv, use_block, irn); + DBG((dbg, LEVEL_2, "marking %+F live in at %+F\n", irn, use_block)); + n->flags |= be_lv_state_in; for (i = get_Block_n_cfgpreds(use_block) - 1; i >= 0; --i) { ir_node *pred_block = get_Block_cfgpred_block(use_block, i); - live_end_at_block(pred_block, 1); + live_end_at_block(pred_block, be_lv_state_end | be_lv_state_out); } } } @@ -363,7 +314,6 @@ static void collect_liveness_nodes(ir_node *irn, void *data) void be_liveness_compute_sets(be_lv_t *lv) { - ir_node **nodes; int i; int n; @@ -375,16 +325,14 @@ void be_liveness_compute_sets(be_lv_t *lv) obstack_init(&lv->obst); n = get_irg_last_idx(lv->irg); - nodes = NEW_ARR_F(ir_node *, n); - memset(nodes, 0, sizeof(nodes[0]) * n); + ir_node **const nodes = NEW_ARR_FZ(ir_node*, n); /* inserting the variables sorted by their ID is probably * more efficient since the binary sorted set insertion * will not need to move around the data. */ irg_walk_graph(lv->irg, NULL, collect_liveness_nodes, nodes); - re.lv = lv; - re.visited = bitset_malloc(n); + re.lv = lv; for (i = 0; i < n; ++i) { if (nodes[i] != NULL) @@ -392,7 +340,6 @@ void be_liveness_compute_sets(be_lv_t *lv) } DEL_ARR_F(nodes); - free(re.visited); be_timer_pop(T_LIVE); @@ -462,10 +409,8 @@ void be_liveness_introduce(be_lv_t *lv, ir_node *irn) { /* Don't compute liveness information for non-data nodes. */ if (lv->sets_valid && is_liveness_node(irn)) { - re.lv = lv; - re.visited = bitset_malloc(get_irg_last_idx(lv->irg)); + re.lv = lv; liveness_for_node(irn); - bitset_free(re.visited); } } @@ -486,17 +431,9 @@ void be_liveness_transfer(const arch_register_class_t *cls, ir_nodeset_remove(nodeset, value); ); - int arity = get_irn_arity(node); - for (int i = 0; i < arity; ++i) { - const arch_register_req_t *in_req = arch_get_irn_register_req_in(node, i); - if (in_req->cls != cls) - continue; - ir_node *op = get_irn_n(node, i); - const arch_register_req_t *op_req = arch_get_irn_register_req(op); - if (arch_register_req_is(op_req, ignore)) - continue; + be_foreach_use(node, cls, in_req, op, op_req, ir_nodeset_insert(nodeset, op); - } + ); }