- Don't use morgan spiller as default until it is as stable as belady spiller
[libfirm] / ir / be / beuses.c
index e8d5b70..f79400f 100644 (file)
@@ -39,19 +39,15 @@ typedef struct _be_use_t {
        const ir_node *bl;
        const ir_node *irn;
        unsigned next_use;
-       int is_set;
 } be_use_t;
 
 struct _be_uses_t {
   set *uses;
   ir_graph *irg;
-  firm_dbg_module_t *dbg;
   const arch_env_t *arch_env;
+  DEBUG_ONLY(firm_dbg_module_t *dbg;)
 };
 
-
-#define MIN(a, b)                ((a) < (b) ? (a) : (b))
-
 static INLINE unsigned sadd(unsigned a, unsigned b)
 {
   return a + b;
@@ -70,16 +66,18 @@ static int cmp_use(const void *a, const void *b, size_t n)
 }
 
 static INLINE be_use_t *get_or_set_use(be_uses_t *uses,
-    const ir_node *bl, const ir_node *irn, unsigned next_use)
+    const ir_node *bl, const ir_node *def, unsigned next_use)
 {
-  unsigned hash = HASH_COMBINE(HASH_PTR(bl), HASH_PTR(irn));
+  unsigned hash = HASH_COMBINE(HASH_PTR(bl), HASH_PTR(def));
   be_use_t templ;
+  be_use_t* result;
 
   templ.bl = bl;
-  templ.irn = irn;
-  templ.next_use = next_use;
-  templ.is_set = 0;
-  return set_insert(uses->uses, &templ, sizeof(templ), hash);
+  templ.irn = def;
+  templ.next_use = be_get_next_use(uses, sched_first(bl), 0, def, 0);
+  result = set_insert(uses->uses, &templ, sizeof(templ), hash);
+
+  return result;
 }
 
 unsigned be_get_next_use(be_uses_t *uses, const ir_node *from,
@@ -88,14 +86,8 @@ unsigned be_get_next_use(be_uses_t *uses, const ir_node *from,
 static unsigned get_next_use_bl(be_uses_t *uses, const ir_node *bl,
     const ir_node *def)
 {
-  be_use_t *u;
-
-  u = get_or_set_use(uses, bl, def, 0);
-  if(!u->is_set) {
-       u->is_set = 1;
-       u->next_use = USES_INFINITY;
-       u->next_use = be_get_next_use(uses, sched_first(bl), 0, def, 0);
-  }
+  be_use_t *u = get_or_set_use(uses, bl, def, 0);
+
   return u->next_use;
 }
 
@@ -113,11 +105,11 @@ static unsigned get_next_use(be_uses_t *uses, const ir_node *from, unsigned from
        sched_foreach_from(from, irn) {
                int i, n;
 
-               if(!skip_from_uses) {
-                       for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
+               if (! skip_from_uses) {
+                       for (i = 0, n = get_irn_arity(irn); i < n; ++i) {
                                ir_node *operand = get_irn_n(irn, i);
 
-                               if(operand == def) {
+                               if (operand == def) {
                                        DBG((uses->dbg, LEVEL_3, "found use of %+F at %+F\n", operand, irn));
                                        return step;
                                }
@@ -128,6 +120,9 @@ static unsigned get_next_use(be_uses_t *uses, const ir_node *from, unsigned from
                step++;
        }
 
+       /* FIXME: quick and dirty hack to prevent ignore nodes (like stack pointer) from being spilled */
+       return is_live_end(bl, def) ? step : USES_INFINITY;
+
        next_use = USES_INFINITY;
        foreach_block_succ(bl, succ_edge) {
                const ir_node *succ_bl = succ_edge->src;
@@ -160,9 +155,8 @@ be_uses_t *be_begin_uses(ir_graph *irg, const arch_env_t *arch_env, const arch_r
 
   uses->arch_env = arch_env;
   uses->uses     = new_set(cmp_use, 512);
-  uses->dbg      = firm_dbg_register("be.uses");
   uses->irg      = irg;
-  firm_dbg_set_mask(uses->dbg, DBG_LEVEL);
+  FIRM_DBG_REGISTER(uses->dbg, "firm.be.uses");
 
   return uses;
 }