Remove obsolete outs invalidation
[libfirm] / ir / be / bespilldaemel.c
index 6454b1f..ef36c8f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
@@ -57,7 +57,7 @@
 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
 
 static spill_env_t                 *spill_env;
-static int                          n_regs;
+static unsigned                     n_regs;
 static const arch_register_class_t *cls;
 static const be_lv_t               *lv;
 static bitset_t                    *spilled_nodes;
@@ -70,8 +70,8 @@ struct spill_candidate_t {
 
 static int compare_spill_candidates_desc(const void *d1, const void *d2)
 {
-       const spill_candidate_t *c1 = d1;
-       const spill_candidate_t *c2 = d2;
+       const spill_candidate_t *c1 = (const spill_candidate_t*)d1;
+       const spill_candidate_t *c2 = (const spill_candidate_t*)d2;
 
        return (int) (c1->costs - c2->costs);
 }
@@ -133,6 +133,12 @@ static void spill_node(ir_node *node)
        bitset_set(spilled_nodes, get_irn_idx(node));
 }
 
+static unsigned get_value_width(const ir_node *node)
+{
+       const arch_register_req_t *req = arch_get_register_req_out(node);
+       return req->width;
+}
+
 /**
  * spill @p n nodes from a nodeset. Removes the nodes from the nodeset and
  * sets the spilled bits in spilled_nodes.
@@ -144,15 +150,16 @@ static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node)
        size_t                 free_regs_needed = 0;
        spill_candidate_t     *candidates;
        ir_nodeset_iterator_t  iter;
-       size_t                 i, arity;
+       int                    i, arity;
+       size_t                 c;
        int                    spills_needed;
        size_t                 cand_idx;
        ir_node               *n;
        ir_node               *value;
 
        be_foreach_definition(node, cls, value,
-               assert(req_->width == 1); /* no support for wide-values yet */
-               ++values_defined;
+               assert(req_->width >= 1);
+               values_defined += req_->width;
        );
 
        /* we need registers for the non-live argument values */
@@ -161,7 +168,7 @@ static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node)
                ir_node *pred = get_irn_n(node, i);
                if (arch_irn_consider_in_reg_alloc(cls, pred)
                                && !ir_nodeset_contains(live_nodes, pred)) {
-                       ++free_regs_needed;
+                       free_regs_needed += get_value_width(pred);
                }
        }
 
@@ -178,17 +185,17 @@ static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node)
        candidates = ALLOCAN(spill_candidate_t, n_live_nodes);
 
        /* construct array with spill candidates and calculate their costs */
-       i = 0;
+       c = 0;
        foreach_ir_nodeset(live_nodes, n, iter) {
-               spill_candidate_t *candidate = & candidates[i];
+               spill_candidate_t *candidate = & candidates[c];
 
                assert(!bitset_is_set(spilled_nodes, get_irn_idx(n)));
 
                candidate->node  = n;
                candidate->costs = get_spill_costs(n);
-               ++i;
+               ++c;
        }
-       assert(i == n_live_nodes);
+       assert(c == n_live_nodes);
 
        /* sort spill candidates */
        qsort(candidates, n_live_nodes, sizeof(candidates[0]),
@@ -197,9 +204,9 @@ static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node)
        /* spill cheapest ones */
        cand_idx = 0;
        while (spills_needed > 0) {
-               bool               is_use = false;
-               spill_candidate_t *candidate;
-               ir_node           *cand_node;
+               bool                       is_use = false;
+               spill_candidate_t         *candidate;
+               ir_node                   *cand_node;
 
                if (cand_idx >= n_live_nodes) {
                        panic("can't spill enough values for node %+F", node);
@@ -220,13 +227,12 @@ static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node)
                                break;
                        }
                }
-               if (is_use) {
+               if (is_use)
                        continue;
-               }
 
                spill_node(cand_node);
                ir_nodeset_remove(live_nodes, cand_node);
-               --spills_needed;
+               spills_needed -= get_value_width(cand_node);
        }
 }
 
@@ -282,6 +288,7 @@ static void spill_block(ir_node *block, void *data)
        ir_node               *node;
        int                    n_phi_values_spilled;
        int                    regpressure;
+       int                    live_nodes_pressure;
        int                    phi_spills_needed;
        (void) data;
 
@@ -322,12 +329,17 @@ static void spill_block(ir_node *block, void *data)
                        break;
 
                if (bitset_is_set(spilled_nodes, get_irn_idx(node))) {
-                       ++n_phi_values_spilled;
+                       n_phi_values_spilled += get_value_width(node);
                }
        }
 
+       live_nodes_pressure = 0;
+       foreach_ir_nodeset(&live_nodes, node, iter) {
+               live_nodes_pressure += get_value_width(node);
+       }
+
        /* calculate how many of the phis need to be spilled */
-       regpressure       = ir_nodeset_size(&live_nodes) + n_phi_values_spilled;
+       regpressure       = live_nodes_pressure + n_phi_values_spilled;
        phi_spills_needed = regpressure - n_regs;
        DBG((dbg, LEVEL_3, "Regpressure before phis: %d phispills: %d\n",
             regpressure, phi_spills_needed));
@@ -341,10 +353,11 @@ static void spill_block(ir_node *block, void *data)
                if (phi_spills_needed <= 0)
                        break;
 
-               if (bitset_is_set(spilled_nodes, get_irn_idx(node))) {
-                       be_spill_phi(spill_env, node);
-                       --phi_spills_needed;
-               }
+               if (!bitset_is_set(spilled_nodes, get_irn_idx(node)))
+                       continue;
+
+               be_spill_phi(spill_env, node);
+               phi_spills_needed -= get_value_width(node);
        }
        assert(phi_spills_needed <= 0);
 
@@ -353,7 +366,7 @@ static void spill_block(ir_node *block, void *data)
 
 static void be_spill_daemel(ir_graph *irg, const arch_register_class_t *new_cls)
 {
-       n_regs = new_cls->n_regs - be_put_ignore_regs(irg, new_cls, NULL);
+       n_regs = be_get_n_allocatable_regs(irg, new_cls);
        if (n_regs == 0)
                return;
 
@@ -374,7 +387,7 @@ static void be_spill_daemel(ir_graph *irg, const arch_register_class_t *new_cls)
        be_delete_spill_env(spill_env);
 }
 
-BE_REGISTER_MODULE_CONSTRUCTOR(be_init_daemelspill);
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_daemelspill)
 void be_init_daemelspill(void)
 {
        static be_spiller_t daemel_spiller = {