belive: Inline be_lv_remove() into its only caller.
[libfirm] / ir / be / belive.c
index 3680cc0..383df75 100644 (file)
@@ -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.
  */
 
 /**
@@ -170,15 +156,19 @@ static be_lv_info_node_t *be_lv_get_or_set(be_lv_t *li, ir_node *bl,
        return res;
 }
 
+typedef struct lv_remove_walker_t {
+       be_lv_t       *lv;
+       ir_node const *irn;
+} lv_remove_walker_t;
+
 /**
  * Removes a node from the list of live variables of a block.
- * @return 1 if the node was live at that block, 0 if not.
  */
-static int be_lv_remove(be_lv_t *li, const ir_node *bl,
-                        const ir_node *irn)
+static void lv_remove_irn_walker(ir_node *const bl, void *const data)
 {
-       be_lv_info_t *irn_live = ir_nodehashmap_get(be_lv_info_t, &li->map, bl);
-
+       lv_remove_walker_t *const w        = (lv_remove_walker_t*)data;
+       ir_node      const *const irn      = w->irn;
+       be_lv_info_t       *const irn_live = ir_nodehashmap_get(be_lv_info_t, &w->lv->map, bl);
        if (irn_live != NULL) {
                unsigned n   = irn_live[0].head.n_members;
                unsigned pos = _be_liveness_bsearch(irn_live, irn);
@@ -197,18 +187,14 @@ static int be_lv_remove(be_lv_t *li, const ir_node *bl,
 
                        --irn_live[0].head.n_members;
                        DBG((dbg, LEVEL_3, "\tdeleting %+F from %+F at pos %d\n", irn, bl, pos));
-                       return 1;
                }
        }
-
-       return 0;
 }
 
 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;
 
 /**
@@ -220,38 +206,31 @@ static struct {
  */
 static void live_end_at_block(ir_node *const block, be_lv_state_t const state)
 {
-       be_lv_info_node_t *const n = be_lv_get_or_set(re.lv, block, re.def);
+       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;
 
        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;
 
-       bitset_t *const 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;
 
-                       DBG((dbg, LEVEL_2, "marking %+F live in at %+F\n", re.def, block));
-                       n->flags |= be_lv_state_in;
+       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), be_lv_state_end | be_lv_state_out);
-               }
+       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);
        }
 }
 
-typedef struct lv_remove_walker_t {
-       be_lv_t       *lv;
-       const ir_node *irn;
-} lv_remove_walker_t;
-
-
 /**
  * Liveness analysis for a value.
  * Compute the set of all blocks a value is live in.
@@ -259,10 +238,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;
@@ -314,12 +290,6 @@ static void liveness_for_node(ir_node *irn)
        }
 }
 
-static void lv_remove_irn_walker(ir_node *bl, void *data)
-{
-       lv_remove_walker_t *w = (lv_remove_walker_t*)data;
-       be_lv_remove(w->lv, bl, w->irn);
-}
-
 /**
  * Walker, collect all nodes for which we want calculate liveness info
  * on an obstack.
@@ -351,8 +321,7 @@ void be_liveness_compute_sets(be_lv_t *lv)
         * 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)
@@ -360,7 +329,6 @@ void be_liveness_compute_sets(be_lv_t *lv)
        }
 
        DEL_ARR_F(nodes);
-       free(re.visited);
 
        be_timer_pop(T_LIVE);
 
@@ -430,10 +398,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);
        }
 }
 
@@ -475,7 +441,7 @@ void be_liveness_end_of_block(const be_lv_t *lv,
 
 void be_liveness_nodes_live_before(be_lv_t const *const lv, arch_register_class_t const *const cls, ir_node const *const pos, ir_nodeset_t *const live)
 {
-       ir_node const *const bl = get_nodes_block(pos);
+       ir_node *const bl = get_nodes_block(pos);
        be_liveness_end_of_block(lv, cls, bl, live);
        sched_foreach_reverse(bl, irn) {
                be_liveness_transfer(cls, irn, live);