replace psets with arrays to make the compiler more predictable across runs (and...
[libfirm] / ir / be / becopyheur2.c
index c247865..46453c5 100644 (file)
@@ -180,12 +180,12 @@ typedef struct {
 #define get_co2_irn(co2, irn)         ((co2_irn_t *)       phase_get_or_set_irn_data(&co2->ph, irn))
 #define get_co2_cloud_irn(co2, irn)   ((co2_cloud_irn_t *) phase_get_or_set_irn_data(&co2->ph, irn))
 
-static void *co2_irn_init(ir_phase *ph, const ir_node *irn, void *data)
+static void *co2_irn_init(ir_phase *ph, const ir_node *irn)
 {
        co2_t *env         = (co2_t *) ph;
        affinity_node_t *a = get_affinity_info(env->co, irn);
        size_t size        = a ? sizeof(co2_cloud_irn_t) : sizeof(co2_irn_t);
-       co2_irn_t *ci      = data ? data : phase_alloc(ph, size);
+       co2_irn_t *ci      = phase_alloc(ph, size);
 
        memset(ci, 0, size);
        INIT_LIST_HEAD(&ci->changed_list);
@@ -228,7 +228,7 @@ static int col_cost_pair_lt(const void *a, const void *b)
        return QSORT_CMP(c, d);
 }
 
-int cmp_edges(const void *a, const void *b)
+static int cmp_edges(const void *a, const void *b)
 {
        const edge_t *p = a;
        const edge_t *q = b;
@@ -300,7 +300,7 @@ static void incur_constraint_costs(co2_t *env, const ir_node *irn, col_cost_pair
                unsigned n_constr = 0;
                unsigned i;
 
-               n_constr = rbitset_popcnt(req->limited, n_regs);
+               n_constr = rbitset_popcount(req->limited, n_regs);
                for (i = 0; i < n_regs; ++i) {
                        if (rbitset_is_set(req->limited, i)) {
                                col_costs[i].costs = add_saturated(col_costs[i].costs, costs / n_constr);
@@ -327,9 +327,9 @@ static void determine_color_costs(co2_t *env, co2_irn_t *ci, col_cost_pair_t *co
        bitset_t *forb     = bitset_alloca(n_regs);
        affinity_node_t *a = ci->aff;
 
-       bitset_pos_t elm;
+       unsigned elm;
        const ir_node *pos;
-       void *it;
+       neighbours_iter_t it;
        int i;
 
        /* Put all forbidden colors into the aux bitset. */
@@ -354,8 +354,7 @@ static void determine_color_costs(co2_t *env, co2_irn_t *ci, col_cost_pair_t *co
                }
        }
 
-       it = be_ifg_neighbours_iter_alloca(ifg);
-       be_ifg_foreach_neighbour(ifg, it, irn, pos) {
+       be_ifg_foreach_neighbour(ifg, &it, irn, pos) {
                col_t col = get_col(env, pos);
                if (color_is_fix(env, pos)) {
                        col_costs[col].costs  = INT_MAX;
@@ -365,7 +364,7 @@ static void determine_color_costs(co2_t *env, co2_irn_t *ci, col_cost_pair_t *co
                        col_costs[col].costs = add_saturated(col_costs[col].costs, 8 * be_ifg_degree(ifg, pos));
                }
        }
-       be_ifg_neighbours_break(ifg, it);
+       be_ifg_neighbours_break(&it);
 
        /* Set the costs to infinity for each color which is not allowed at this node. */
        bitset_foreach(forb, elm) {
@@ -430,7 +429,7 @@ static int recolor(co2_t *env, const ir_node *irn, col_cost_pair_t *col_list, st
 
                struct list_head changed;
                const ir_node *n;
-               void *it;
+               neighbours_iter_t it;
 
                DBG((env->dbg, LEVEL_3, "\t\t%2{firm:indent}trying color %d(%d) on %+F\n", depth, tgt_col, costs, irn));
 
@@ -452,8 +451,7 @@ static int recolor(co2_t *env, const ir_node *irn, col_cost_pair_t *col_list, st
                INIT_LIST_HEAD(&changed);
                list_add(&ci->changed_list, &changed);
 
-               it = be_ifg_neighbours_iter_alloca(ifg);
-               be_ifg_foreach_neighbour(ifg, it, irn, n) {
+               be_ifg_foreach_neighbour(ifg, &it, irn, n) {
 
                        /* try to re-color the neighbor if it has the target color. */
                        if (get_col(env, n) == tgt_col) {
@@ -472,7 +470,7 @@ static int recolor(co2_t *env, const ir_node *irn, col_cost_pair_t *col_list, st
                                        break;
                        }
                }
-               be_ifg_neighbours_break(ifg, it);
+               be_ifg_neighbours_break(&it);
 
                /*
                We managed to assign the target color to all neighbors, so from the perspective
@@ -614,9 +612,9 @@ static void node_color_badness(co2_cloud_irn_t *ci, int *badness)
        be_ifg_t *ifg  = env->co->cenv->ifg;
        bitset_t *bs   = bitset_alloca(n_regs);
 
-       bitset_pos_t elm;
+       unsigned elm;
        const ir_node *irn;
-       void *it;
+       neighbours_iter_t it;
 
        admissible_colors(env, &ci->inh, bs);
        bitset_flip_all(bs);
@@ -624,13 +622,12 @@ static void node_color_badness(co2_cloud_irn_t *ci, int *badness)
                badness[elm] = ci->costs;
 
        /* Use constrained/fixed interfering neighbors to influence the color badness */
-       it = be_ifg_neighbours_iter_alloca(ifg);
-       be_ifg_foreach_neighbour(ifg, it, ir->irn, irn) {
+       be_ifg_foreach_neighbour(ifg, &it, ir->irn, irn) {
                co2_irn_t *ni = get_co2_irn(env, irn);
 
                admissible_colors(env, ni, bs);
-               if (bitset_popcnt(bs) == 1) {
-                       bitset_pos_t c = bitset_next_set(bs, 0);
+               if (bitset_popcount(bs) == 1) {
+                       unsigned c = bitset_next_set(bs, 0);
                        badness[c] += ci->costs;
                }
 
@@ -639,7 +636,7 @@ static void node_color_badness(co2_cloud_irn_t *ci, int *badness)
                        badness[c] += ci->costs;
                }
        }
-       be_ifg_neighbours_break(ifg, it);
+       be_ifg_neighbours_break(&it);
 }
 
 /**
@@ -796,7 +793,7 @@ static void populate_cloud(co2_t *env, co2_cloud_t *cloud, affinity_node_t *a, i
        ci->costs          = costs;
        cloud->costs      += costs;
        cloud->n_constr   += is_constrained(env, &ci->inh);
-       cloud->freedom    += bitset_popcnt(get_adm(env, &ci->inh));
+       cloud->freedom    += bitset_popcount(get_adm(env, &ci->inh));
        cloud->max_degree  = MAX(cloud->max_degree, ci->inh.aff->degree);
        cloud->n_memb++;
 
@@ -1230,13 +1227,13 @@ int co_solve_heuristic_new(copy_opt_t *co)
        co2_t env;
        FILE  *f;
 
-       phase_init(&env.ph, "co2", co->cenv->birg->irg, PHASE_DEFAULT_GROWTH, co2_irn_init, NULL);
+       phase_init(&env.ph, co->cenv->irg, co2_irn_init);
        env.touched     = NULL;
        env.visited     = 0;
        env.co          = co;
        env.n_regs      = co->cls->n_regs;
        env.ignore_regs = bitset_alloca(co->cls->n_regs);
-       be_put_ignore_regs(co->cenv->birg, co->cls, env.ignore_regs);
+       be_put_ignore_regs(co->cenv->irg, co->cls, env.ignore_regs);
        FIRM_DBG_REGISTER(env.dbg, "firm.be.co2");
        INIT_LIST_HEAD(&env.cloud_head);
 
@@ -1261,10 +1258,11 @@ int co_solve_heuristic_new(copy_opt_t *co)
        }
 
        writeback_colors(&env);
-       phase_free(&env.ph);
+       phase_deinit(&env.ph);
        return 0;
 }
 
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copyheur2);
 void be_init_copyheur2(void)
 {
        lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
@@ -1279,5 +1277,3 @@ void be_init_copyheur2(void)
        lc_opt_add_table(co2_grp, options);
        be_register_copyopt("heur2", &copyheur);
 }
-
-BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copyheur2);