becopyopt: Use the set of admissible registers from bechordal.
[libfirm] / ir / be / becopyheur4.c
index a98ea3c..dbe5acc 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2011 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.
  */
 
 /**
@@ -109,7 +95,7 @@ typedef struct aff_edge_t {
 /* main coalescing environment */
 typedef struct co_mst_env_t {
        int              n_regs;         /**< number of regs in class */
-       bitset_t         *allocatable_regs; /**< set containing all global ignore registers */
+       bitset_t const   *allocatable_regs; /**< set containing all global ignore registers */
        ir_nodemap        map;           /**< phase object holding data for nodes */
        struct obstack    obst;
        pqueue_t         *chunks;        /**< priority queue for chunks */
@@ -636,14 +622,10 @@ static int count_interfering_aff_neighs(co_mst_env_t *env, const affinity_node_t
  */
 static void build_affinity_chunks(co_mst_env_t *env)
 {
-       nodes_iter_t nodes_it;
-       aff_edge_t  *edges    = NEW_ARR_F(aff_edge_t, 0);
-       ir_node     *n;
-       int         i, len;
-       size_t      pn;
+       aff_edge_t *edges = NEW_ARR_F(aff_edge_t, 0);
 
        /* at first we create the affinity edge objects */
-       be_ifg_foreach_node(env->ifg, &nodes_it, n) {
+       be_ifg_foreach_node(env->ifg, n) {
                int             n_idx = get_irn_idx(n);
                co_mst_irn_t    *n1;
                affinity_node_t *an;
@@ -692,9 +674,9 @@ static void build_affinity_chunks(co_mst_env_t *env)
        }
 
        /* now: sort edges and build the affinity chunks */
-       len = ARR_LEN(edges);
+       size_t const len = ARR_LEN(edges);
        qsort(edges, len, sizeof(edges[0]), cmp_aff_edge);
-       for (i = 0; i < len; ++i) {
+       for (size_t i = 0; i < len; ++i) {
                DBG((dbg, LEVEL_1, "edge (%u,%u) %f\n", edges[i].src->node_idx, edges[i].tgt->node_idx, edges[i].weight));
 
                (void)aff_chunk_absorb(env, edges[i].src, edges[i].tgt);
@@ -711,7 +693,7 @@ static void build_affinity_chunks(co_mst_env_t *env)
                pqueue_put(env->chunks, curr_chunk, curr_chunk->weight);
        }
 
-       for (pn = 0; pn < ARR_LEN(env->map.data); ++pn) {
+       for (size_t pn = 0; pn < ARR_LEN(env->map.data); ++pn) {
                co_mst_irn_t *mirn = (co_mst_irn_t*)env->map.data[pn];
                if (mirn == NULL)
                        continue;
@@ -1421,37 +1403,31 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c)
  */
 static int co_solve_heuristic_mst(copy_opt_t *co)
 {
-       unsigned     n_regs            = co->cls->n_regs;
-       bitset_t     *allocatable_regs = bitset_alloca(n_regs);
-       unsigned     i, j;
-       size_t       pn;
-       ir_node      *irn;
-       co_mst_env_t mst_env;
-
        last_chunk_id = 0;
 
        stat_ev_tim_push();
 
        /* init phase */
+       co_mst_env_t mst_env;
        ir_nodemap_init(&mst_env.map, co->irg);
        obstack_init(&mst_env.obst);
 
-       be_put_allocatable_regs(co->cenv->irg, co->cls, allocatable_regs);
+       unsigned const n_regs = co->cls->n_regs;
 
        mst_env.n_regs           = n_regs;
        mst_env.chunks           = new_pqueue();
        mst_env.co               = co;
-       mst_env.allocatable_regs = allocatable_regs;
+       mst_env.allocatable_regs = co->cenv->allocatable_regs;
        mst_env.ifg              = co->cenv->ifg;
        INIT_LIST_HEAD(&mst_env.chunklist);
        mst_env.chunk_visited    = 0;
        mst_env.single_cols      = OALLOCN(&mst_env.obst, col_cost_t*, n_regs);
 
-       for (i = 0; i < n_regs; ++i) {
+       for (unsigned i = 0; i < n_regs; ++i) {
                col_cost_t *vec = OALLOCN(&mst_env.obst, col_cost_t, n_regs);
 
                mst_env.single_cols[i] = vec;
-               for (j = 0; j < n_regs; ++j) {
+               for (unsigned j = 0; j < n_regs; ++j) {
                        vec[j].col  = j;
                        vec[j].cost = REAL(0.0);
                }
@@ -1477,12 +1453,12 @@ static int co_solve_heuristic_mst(copy_opt_t *co)
        }
 
        /* apply coloring */
-       for (pn = 0; pn < ARR_LEN(mst_env.map.data); ++pn) {
+       for (size_t pn = 0; pn < ARR_LEN(mst_env.map.data); ++pn) {
                co_mst_irn_t *mirn = (co_mst_irn_t*)mst_env.map.data[pn];
                const arch_register_t *reg;
                if (mirn == NULL)
                        continue;
-               irn = get_idx_irn(co->irg, pn);
+               ir_node *const irn = get_idx_irn(co->irg, pn);
                if (arch_irn_is_ignore(irn))
                        continue;