/*
- * 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.
*/
/**
#include "bemodule.h"
-#define COL_COST_INFEASIBLE DBL_MAX
-#define AFF_NEIGHBOUR_FIX_BENEFIT 128.0
-#define NEIGHBOUR_CONSTR_COSTS 64.0
-
-
#ifdef DEBUG_libfirm
#define DBG_AFF_CHUNK(env, level, chunk) do { if (firm_dbg_get_mask(dbg) & (level)) dbg_aff_chunk((env), (chunk)); } while (0)
/* main coalescing environment */
typedef struct co_mst_env_t {
int n_regs; /**< number of regs in class */
- int k; /**< number of non-ignore registers 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 */
const arch_register_req_t *req;
neighbours_iter_t nodes_it;
- ir_node *neigh;
unsigned len;
res->irn = irn;
req = arch_get_irn_register_req(irn);
if (arch_register_req_is(req, limited)) {
rbitset_copy_to_bitset(req->limited, res->adm_colors);
+ /* exclude global ignore registers as well */
+ bitset_and(res->adm_colors, env->allocatable_regs);
} else {
- bitset_set_all(res->adm_colors);
+ bitset_copy(res->adm_colors, env->allocatable_regs);
}
- /* exclude global ignore registers as well */
- bitset_and(res->adm_colors, env->allocatable_regs);
-
/* compute the constraint factor */
res->constr_factor = (real_t) (1 + env->n_regs - bitset_popcount(res->adm_colors)) / env->n_regs;
*/
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;
}
/* 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);
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;
* TODO Sebastian: Perhaps we should at all nodes and figure out
* a suitable color using costs as done above (determine_color_costs).
*/
- for (i = 0; i < env->k; ++i) {
+ for (i = 0; i < env->n_regs; ++i) {
int col = order[i].col;
waitq *good_starts;
aff_chunk_t *local_best;
*/
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 k;
- 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);
- k = bitset_popcount(allocatable_regs);
+ unsigned const n_regs = co->cls->n_regs;
mst_env.n_regs = n_regs;
- mst_env.k = k;
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);
}
}
/* 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;