/*
- * Author: Matthias Braun
- * Date: 26.7.06
- * Copyright: (c) Universitaet Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2007 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.
+ */
+
+/**
+ * @file
+ * @brief Spillslot coalescer.
+ * @author Matthias Braun
+ * @date 26.07.2006
+ * @version $Id$
*/
#ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
#endif
#include <stdlib.h>
#include "set.h"
-
+#include "array.h"
#include "irgwalk.h"
#include "ircons.h"
#include "irprintf.h"
#include "execfreq.h"
#include "unionfind.h"
-#include "type.h"
#include "irdump_t.h"
#include "benode_t.h"
#include "benodesets.h"
#include "bestatevent.h"
#include "bespilloptions.h"
+#include "bemodule.h"
+#include "beintlive_t.h"
+#include "beirg_t.h"
+#include "bearch_t.h"
#define DBG_COALESCING 1
#define DBG_INTERFERENCES 2
{
const spill_t* s1 = d1;
const spill_t* s2 = d2;
+ (void) size;
+
return s1->spill != s2->spill;
}
return res;
}
-#if 0
-static void dump_interference_graph(be_fec_env_t *env, bitset_t **interferences, const char* suffix) {
- char name[256];
- int i;
- int spillcount;
- spill_t *spill;
- FILE *f;
- static int cnt = 0;
-
- snprintf(name, sizeof(name), "%d-%s-spillslots-%s.vcg", cnt++, get_irg_dump_name(env->chordal_env->birg->irg), suffix);
-
- f = fopen(name, "w");
- assert(f != NULL);
-
- fprintf(f, "graph: {\n");
-
- spillcount = set_count(env->spills);
- for(spill = set_first(env->spills), i = 0; spill != NULL; spill = set_next(env->spills), ++i) {
- int slotid = spill->spillslot;
- fprintf(f, "\tnode: { title: \"n%d\" label: \"%d\" }\n", i, slotid);
- }
-
- for(i = 0; i < ARR_LEN(env->affinity_edges); ++i) {
- affinity_edge_t *edge = env->affinity_edges[i];
- fprintf(f, "\tedge: { sourcename: \"n%d\" targetname: \"n%d\" color: green }\n", edge->slot1, edge->slot2);
- }
-
- for(i = 0; i < spillcount; ++i) {
- int i2;
- for(i2 = 0; i2 < spillcount; ++i2) {
- if(bitset_is_set(interferences[i], i2)) {
- fprintf(f, "\tedge: { sourcename: \"n%d\" targetname: \"n%d\" color: red }\n", i, i2);
- }
- }
- }
-
- fprintf(f, "}\n");
- fclose(f);
-}
-#endif
-
/**
* A greedy coalescing algorithm for spillslots:
* 1. Sort the list of affinity edges
int affinity_edge_count;
bitset_t **interferences;
int* spillslot_unionfind;
- const be_lv_t *lv = be_get_birg_liveness(env->birg);
spillcount = set_count(env->spills);
if(spillcount == 0)
interferences[i] = bitset_alloca(spillcount);
}
- // construct interferences
- for(i = 0; i < spillcount; ++i) {
+ /* construct interferences */
+ for (i = 0; i < spillcount; ++i) {
+ ir_node *spill1 = spilllist[i]->spill;
+
+ if (is_NoMem(spill1))
+ continue;
+
for(i2 = i+1; i2 < spillcount; ++i2) {
- if(values_interfere(lv, spilllist[i]->spill, spilllist[i2]->spill)) {
+ ir_node *spill2 = spilllist[i2]->spill;
+
+ if (is_NoMem(spill2))
+ continue;
+
+ if (values_interfere(env->birg, spill1, spill2)) {
DBG((dbg, DBG_INTERFERENCES, "Slot %d and %d interfere\n", i, i2));
bitset_set(interferences[i], i2);
bitset_set(interferences[i2], i);
}
}
- // sort affinity edges
+ /* sort affinity edges */
affinity_edge_count = ARR_LEN(env->affinity_edges);
qsort(env->affinity_edges, affinity_edge_count, sizeof(env->affinity_edges[0]), cmp_affinity);
//dump_interference_graph(env, interferences, "before");
- // try to merge affine nodes
+ /* try to merge affine nodes */
for(i = 0; i < affinity_edge_count; ++i) {
const affinity_edge_t *edge = env->affinity_edges[i];
int s1 = uf_find(spillslot_unionfind, edge->slot1);
int s2 = uf_find(spillslot_unionfind, edge->slot2);
/* test if values interfere */
- if(bitset_is_set(interferences[s1], s2)) {
+ if (bitset_is_set(interferences[s1], s2)) {
assert(bitset_is_set(interferences[s2], s1));
continue;
}
{
const memperm_t* e1 = d1;
const memperm_t* e2 = d2;
+ (void) size;
+
return e1->block != e2->block;
}
ir_type *frame = get_irg_frame_type(irg);
ir_entity *res = frame_alloc_area(frame, slot->size, slot->align, 0);
- // adjust size of the entity type...
+ /* adjust size of the entity type... */
ir_type *enttype = get_entity_type(res);
set_type_size_bytes(enttype, slot->size);
}
}
} else {
- arch_set_frame_entity(arch_env, node, slot->entity);
+ if(!is_NoMem(node))
+ arch_set_frame_entity(arch_env, node, slot->entity);
}
}
// 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);
+ stat_ev_dbl("mem_perm", memperm->entrycount);
i = 0;
for(entry = memperm->entries; entry != NULL; entry = entry->next, ++i) {
be_set_MemPerm_out_entity(mempermnode, i, entry->out);
set_irg_current_block(irg, memperm->block);
proj = new_Proj(mempermnode, get_irn_mode(arg), i);
- sched_add_before(blockend, proj);
set_irn_n(entry->node, entry->pos, proj);
}
be_fec_env_t *be_new_frame_entity_coalescer(be_irg_t *birg)
{
const arch_env_t *arch_env = birg->main_env->arch_env;
+ be_fec_env_t *env = xmalloc(sizeof(env[0]));
- be_fec_env_t *env = xmalloc(sizeof(env[0]));
-
- be_assure_liveness(birg);
+ be_liveness_assure_chk(be_assure_liveness(birg));
obstack_init(&env->obst);
- env->arch_env = arch_env;
- env->birg = birg;
- env->spills = new_set(cmp_spill, 10);
- env->reloads = NEW_ARR_F(ir_node*, 0);
+ env->arch_env = arch_env;
+ env->birg = birg;
+ env->spills = new_set(cmp_spill, 10);
+ env->reloads = NEW_ARR_F(ir_node*, 0);
env->affinity_edges = NEW_ARR_F(affinity_edge_t*, 0);
- env->memperms = new_set(cmp_memperm, 10);
- FIRM_DBG_REGISTER(dbg, "firm.be.spillslots");
+ env->memperms = new_set(cmp_memperm, 10);
return env;
}
void be_assign_entities(be_fec_env_t *env)
{
- if(be_stat_ev_is_active()) {
- int count = set_count(env->spills);
- be_stat_ev("spillslots", count);
- }
+ stat_ev_dbl("spillslots", set_count(env->spills));
if(be_coalesce_spill_slots) {
do_greedy_coalescing(env);
}
- if(be_stat_ev_is_active()) {
- int count = count_spillslots(env);
- be_stat_ev("spillslots_after_coalescing", count);
- }
+ stat_ev_dbl("spillslots_after_coalescing", count_spillslots(env));
assign_spillslots(env);
if (!arch_irn_class_is(arch_env, node, reload))
return;
- mode = get_irn_mode(node);
- cls = arch_get_irn_reg_class(arch_env, node, -1);
+ mode = get_irn_mode(node);
+ cls = arch_get_irn_reg_class(arch_env, node, -1);
align = arch_isa_get_reg_class_alignment(arch_env_get_isa(arch_env), cls);
be_node_needs_frame_entity(env, node, mode, align);
}
-void be_coalesce_spillslots(const be_chordal_env_t *chordal_env)
+void be_coalesce_spillslots(be_irg_t *birg)
{
- be_fec_env_t *env = be_new_frame_entity_coalescer(chordal_env->birg);
+ be_fec_env_t *env = be_new_frame_entity_coalescer(birg);
/* collect reloads */
- irg_walk_graph(chordal_env->irg, NULL, collect_spills_walker, env);
+ irg_walk_graph(birg->irg, NULL, collect_spills_walker, env);
be_assign_entities(env);
be_free_frame_entity_coalescer(env);
}
+
+void be_init_spillslots(void)
+{
+ FIRM_DBG_REGISTER(dbg, "firm.be.spillslots");
+}
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillslots);