#include "bespillslots.h"
#include "bechordal_t.h"
#include "bejavacoal.h"
+#include "benodesets.h"
+#include "bestatevent.h"
#define DBG_COALESCING 1
/** Compare 2 affinity edges (used in quicksort) */
static int cmp_affinity(const void *d1, const void *d2) {
- const affinity_edge_t *e1 = d1;
- const affinity_edge_t *e2 = d2;
+ const affinity_edge_t * const *e1 = d1;
+ const affinity_edge_t * const *e2 = d2;
- return e1->affinity < e2->affinity ? -1 : 1;
+ // sort in descending order
+ return (*e1)->affinity < (*e2)->affinity ? 1 : -1;
}
static int cmp_spill(const void* d1, const void* d2, size_t size) {
static spill_t *get_spill(ss_env_t *env, ir_node *node) {
spill_t spill, *res;
- int hash = HASH_PTR(node);
+ int hash = nodeset_hash(node);
spill.spill = node;
res = set_find(env->spills, &spill, sizeof(spill), hash);
const arch_env_t *arch_env = env->arch_env;
const arch_register_class_t *cls;
spill_t spill, *res;
- int hash = HASH_PTR(node);
+ int hash = nodeset_hash(node);
assert(arch_irn_class_is(arch_env, node, spill));
static spill_t *collect_memphi(ss_env_t *env, ir_node *node) {
int i, arity;
spill_t spill, *res;
- int hash = HASH_PTR(node);
+ int hash = nodeset_hash(node);
assert(is_Phi(node));
arg_spill = collect_memphi(env, arg);
}
- if(i == 0) {
+ if(res->cls == NULL) {
res->cls = arg_spill->cls;
} else {
- assert(res->cls == arg_spill->cls);
+ assert(arg_spill->cls == NULL || res->cls == arg_spill->cls);
}
// add an affinity edge
ss_env_t *env = data;
const arch_env_t *arch_env = env->arch_env;
- // @@@ ia32 classify returns classification of the irn the proj is attached
- // too, why oh why?...
+ // classify returns classification of the irn the proj is attached to
if(is_Proj(node))
return;
int hash;
entry.block = block;
- hash = HASH_PTR(block);
+ hash = nodeset_hash(block);
res = set_find(env->memperms, &entry, sizeof(entry), hash);
// insert node into schedule
blockend = get_end_of_block_insertion_point(memperm->block);
sched_add_before(blockend, mempermnode);
+ be_stat_ev("mem_perm", memperm->entrycount);
for(entry = memperm->entries, i = 0; entry != NULL; entry = entry->next, ++i) {
ir_node *proj;
}
}
-void be_coalesce_spillslots(const be_chordal_env_t *chordal_env) {
+static int count_spillslots(const ss_env_t *env) {
+ const spill_t *spill;
+ int spillcount = set_count(env->spills);
+ bitset_t *counted = bitset_alloca(spillcount);
+ int slotcount;
+
+ slotcount = 0;
+ for(spill = set_first(env->spills); spill != NULL;
+ spill = set_next(env->spills)) {
+ int spillslot = spill->spillslot;
+ if(!bitset_is_set(counted, spillslot)) {
+ slotcount++;
+ bitset_set(counted, spillslot);
+ }
+ }
+
+ return slotcount;
+}
+
+void be_coalesce_spillslots(const be_chordal_env_t *chordal_env, int coalesce_spillslots) {
ss_env_t env;
obstack_init(&env.obst);
/* Get initial spill slots */
irg_walk_graph(chordal_env->irg, NULL, collect_spills_walker, &env);
- do_greedy_coalescing(&env);
+ be_stat_ev("spillslots", set_count(env.spills));
+
+ if(coalesce_spillslots) {
+ do_greedy_coalescing(&env);
+ if(be_stat_ev_is_active()) {
+ be_stat_ev("spillslots_after_coalescing", count_spillslots(&env));
+ }
+ }
assign_spillslots(&env);