Remove the unused parameter const arch_env_t *env from arch_set_irn_register().
[libfirm] / ir / be / belive.c
index 62e9d91..200b118 100644 (file)
@@ -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.
  *
@@ -28,6 +28,9 @@
 #include "config.h"
 #endif
 
+/* statev is expensive here, only enable when needed */
+#define DISABLE_STATEV
+
 #include "impl.h"
 #include "iredges_t.h"
 #include "irgwalk.h"
@@ -63,6 +66,7 @@ static INLINE int is_liveness_node(const ir_node *irn)
        case iro_Bad:
        case iro_End:
        case iro_Anchor:
+       case iro_NoMem:
                return 0;
        default:;
        }
@@ -250,7 +254,8 @@ static struct _be_lv_info_node_t *be_lv_get_or_set(struct _be_lv_t *li, ir_node
  * 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(struct _be_lv_t *li, ir_node *bl, ir_node *irn)
+static int be_lv_remove(struct _be_lv_t *li, const ir_node *bl,
+                        const ir_node *irn)
 {
        struct _be_lv_info_t *irn_live = phase_get_irn_data(&li->ph, bl);
 
@@ -366,6 +371,12 @@ struct _lv_walker_t {
        void *data;
 };
 
+typedef struct lv_remove_walker_t {
+       be_lv_t       *lv;
+       const ir_node *irn;
+} lv_remove_walker_t;
+
+
 /**
  * Liveness analysis for a value.
  * This functions is meant to be called by a firm walker, to compute the
@@ -435,10 +446,8 @@ static void liveness_for_node(ir_node *irn, void *data)
 
 static void lv_remove_irn_walker(ir_node *bl, void *data)
 {
-       struct _lv_walker_t *w = data;
-       be_lv_t *lv  = w->lv;
-       ir_node *irn = w->data;
-       be_lv_remove(lv, bl, irn);
+       lv_remove_walker_t *w = data;
+       be_lv_remove(w->lv, bl, w->irn);
 }
 
 static const char *lv_flags_to_str(unsigned flags)
@@ -476,7 +485,7 @@ static void lv_dump_block(void *context, FILE *f, const ir_node *bl)
        }
 }
 
-static void *lv_phase_data_init(ir_phase *phase, ir_node *irn, void *old)
+static void *lv_phase_data_init(ir_phase *phase, const ir_node *irn, void *old)
 {
        struct _be_lv_info_t *info = phase_alloc(phase, LV_STD_SIZE * sizeof(info[0]));
        (void) irn;
@@ -519,7 +528,7 @@ static void compute_liveness(be_lv_t *lv)
        /*
         * inserting the variables sorted by their ID is probably
         * more efficient since the binary sorted set insertion
-        * will not need to move arounf the data.
+        * will not need to move around the data.
         * However, if sorting the variables a priori pays off
         * needs to be checked, hence the define.
         */
@@ -541,17 +550,23 @@ static void compute_liveness(be_lv_t *lv)
 void be_liveness_assure_sets(be_lv_t *lv)
 {
        if (!lv->nodes) {
+               BE_TIMER_PUSH(t_live);
+
                lv->nodes = bitset_malloc(2 * get_irg_last_idx(lv->irg));
                phase_init(&lv->ph, "liveness", lv->irg, PHASE_DEFAULT_GROWTH, lv_phase_data_init, NULL);
                compute_liveness(lv);
                /* be_live_chk_compare(lv, lv->lvc); */
+
+               BE_TIMER_POP(t_live);
        }
 }
 
 void be_liveness_assure_chk(be_lv_t *lv)
 {
 #ifndef USE_LIVE_CHK
+       BE_TIMER_PUSH(t_verify);
        be_liveness_assure_sets(lv);
+       BE_TIMER_POP(t_verify);
 #else
        (void) lv;
 #endif
@@ -570,9 +585,8 @@ void be_liveness_invalidate(be_lv_t *lv)
 /* Compute the inter block liveness for a graph. */
 be_lv_t *be_liveness(const be_irg_t *birg)
 {
-       be_lv_t *lv = xmalloc(sizeof(lv[0]));
+       be_lv_t *lv = XMALLOCZ(be_lv_t);
 
-       memset(lv, 0, sizeof(lv[0]));
        lv->irg  = be_get_birg_irg(birg);
        lv->birg = birg;
 #ifdef USE_LIVE_CHK
@@ -587,40 +601,47 @@ be_lv_t *be_liveness(const be_irg_t *birg)
 
 void be_liveness_recompute(be_lv_t *lv)
 {
-       unsigned last_idx = get_irg_last_idx(lv->irg);
+       unsigned last_idx;
+
+       BE_TIMER_PUSH(t_live);
+       last_idx = get_irg_last_idx(lv->irg);
        if(last_idx >= bitset_size(lv->nodes)) {
                bitset_free(lv->nodes);
                lv->nodes = bitset_malloc(last_idx * 2);
-       }
-
-       else
+       } else
                bitset_clear_all(lv->nodes);
 
        phase_free(&lv->ph);
        phase_init(&lv->ph, "liveness", lv->irg, PHASE_DEFAULT_GROWTH, lv_phase_data_init, NULL);
        compute_liveness(lv);
+
+       BE_TIMER_POP(t_live);
 }
 
 
 void be_liveness_free(be_lv_t *lv)
 {
        be_liveness_invalidate(lv);
-       free(lv);
+#ifdef USE_LIVE_CHK
+       lv_chk_free(lv->lvc);
+       dfs_free(lv->dfs);
+#endif
+       xfree(lv);
 }
 
-void be_liveness_remove(be_lv_t *lv, ir_node *irn)
+void be_liveness_remove(be_lv_t *lv, const ir_node *irn)
 {
        if (lv->nodes) {
                unsigned idx = get_irn_idx(irn);
-               struct _lv_walker_t w;
+               lv_remove_walker_t w;
 
                /*
                 * Removes a single irn from the liveness information.
                 * Since an irn can only be live at blocks dominated by the block of its
                 * definition, we only have to process that dominance subtree.
                 */
-               w.lv   = lv;
-               w.data = irn;
+               w.lv  = lv;
+               w.irn = irn;
                dom_tree_walk(get_nodes_block(irn), lv_remove_irn_walker, NULL, &w);
                if(idx < bitset_size(lv->nodes))
                        bitset_clear(lv->nodes, idx);
@@ -789,9 +810,7 @@ void be_liveness_transfer(const arch_env_t *arch_env,
                                ir_nodeset_remove(nodeset, proj);
                        }
                }
-       }
-
-       if (arch_irn_consider_in_reg_alloc(arch_env, cls, node)) {
+       } else if (arch_irn_consider_in_reg_alloc(arch_env, cls, node)) {
                ir_nodeset_remove(nodeset, node);
        }