#include "bechordal_t.h"
#include "bechordal_draw.h"
-#define DBG_LEVEL 0
+#define DBG_LEVEL SET_LEVEL_0
#define NO_COLOR (-1)
#undef DUMP_INTERVALS
#ifdef BUILD_GRAPH
-#define IF_EDGE_HASH(e) ((e)->src)
+#define IF_EDGE_HASH(e) ((e)->src ^ (e)->tgt)
#define IF_NODE_HASH(n) ((n)->nnr)
static int if_edge_cmp(const void *p1, const void *p2, size_t size)
b->is_real = is_real;
b->irn = irn;
b->step = step;
- check_heads(env);
list_add_tail(&b->list, head);
- check_heads(env);
DBG((dbg, LEVEL_5, "\t\t%s adding %+F, step: %d\n",
is_def ? "def" : "use", irn, step));
static INLINE int has_reg_class(const be_chordal_env_t *env, const ir_node *irn)
{
- return arch_irn_has_reg_class(env->arch_env, irn, arch_pos_make_out(0), env->cls);
+ return arch_irn_has_reg_class(env->session_env->main_env->arch_env,
+ irn, arch_pos_make_out(0), env->cls);
}
/**
struct list_head *head;
pset *live_in = put_live_in(block, pset_new_ptr_default());
pset *live_end = put_live_end(block, pset_new_ptr_default());
- const arch_register_class_t *cls = env->cls;
DBG((dbg, LEVEL_1, "Computing pressure in block %+F\n", block));
bitset_clear_all(live);
* They are necessary to build up real intervals.
*/
for(irn = pset_first(live_end); irn; irn = pset_next(live_end)) {
- DBG((dbg, LEVEL_3, "\tMaking live: %+F/%d\n", irn, get_irn_graph_nr(irn)));
- bitset_set(live, get_irn_graph_nr(irn));
- if(has_reg_class(env, irn))
+ if(has_reg_class(env, irn)) {
+ DBG((dbg, LEVEL_3, "\tMaking live: %+F/%d\n", irn, get_irn_graph_nr(irn)));
+ bitset_set(live, get_irn_graph_nr(irn));
border_use(irn, step, 0);
+ }
}
++step;
}
}
- check_heads(env);
del_pset(live_in);
del_pset(live_end);
static void assign(ir_node *block, void *env_ptr)
{
be_chordal_env_t *env = env_ptr;
- struct obstack *obst = &env->obst;
bitset_t *live = env->live;
bitset_t *colors = env->colors;
bitset_t *in_colors = env->in_colors;
- const arch_register_class_t *cls = env->cls;
-
- /* Mark the obstack level and allocate the temporary tmp_colors */
- void *obstack_level = obstack_base(obst);
- /*bitset_t *tmp_colors = bitset_obstack_alloc(obst, env->colors_n);*/
+ const arch_env_t *arch_env = env->session_env->main_env->arch_env;
const ir_node *irn;
border_t *b;
struct list_head *head = get_block_border_head(env, block);
pset *live_in = put_live_in(block, pset_new_ptr_default());
- check_heads(env);
-
-
bitset_clear_all(live);
bitset_clear_all(colors);
bitset_clear_all(in_colors);
*/
for(irn = pset_first(live_in); irn; irn = pset_next(live_in)) {
if(has_reg_class(env, irn)) {
- const arch_register_t *reg = arch_get_irn_register(env->arch_env, irn, 0);
- int col;
+ const arch_register_t *reg = arch_get_irn_register(arch_env, irn, 0);
+ int col;
- assert(reg && "Node must have been assigned a register");
+ assert(reg && "Node must have been assigned a register");
col = arch_register_get_index(reg);
/* Mark the color of the live in value as used. */
* color.
*/
if(b->is_def && !is_live_in(block, irn)) {
- const arch_register_t *reg;
+ const arch_register_t *reg;
int col = NO_COLOR;
DBG((dbg, LEVEL_4, "\tcolors in use: %b\n", colors));
- col = bitset_next_clear(colors, 0);
- reg = arch_register_for_index(env->cls, col);
+ col = bitset_next_clear(colors, 0);
+ reg = arch_register_for_index(env->cls, col);
- assert(arch_get_irn_register(env->arch_env, irn, 0) == NULL
- && "This node must not have been assigned a register yet");
+ assert(arch_get_irn_register(arch_env, irn, 0) == NULL && "This node must not have been assigned a register yet");
assert(!bitset_is_set(live, nr) && "Value's definition must not have been encountered");
bitset_set(colors, col);
bitset_set(live, nr);
- arch_set_irn_register(env->arch_env, irn, 0, reg);
+ arch_set_irn_register(arch_env, irn, 0, reg);
DBG((dbg, LEVEL_1, "\tassigning register %s(%d) to %+F\n",
arch_register_get_name(reg), col, irn));
}
/* Clear the color upon a use. */
else if(!b->is_def) {
- const arch_register_t *reg = arch_get_irn_register(env->arch_env, irn, 0);
+ const arch_register_t *reg = arch_get_irn_register(arch_env, irn, 0);
int col;
- assert(reg && "Register must have been assigned");
+ assert(reg && "Register must have been assigned");
- col = arch_register_get_index(reg);
+ col = arch_register_get_index(reg);
assert(bitset_is_set(live, nr) && "Cannot have a non live use");
bitset_clear(colors, col);
}
}
- /* Free the auxillary data on the obstack. */
- obstack_free(obst, obstack_level);
-
- del_pset(live_in);
+ del_pset(live_in);
}
void be_ra_chordal_init(void)
firm_dbg_set_mask(dbg, DBG_LEVEL);
}
-be_chordal_env_t *be_ra_chordal(ir_graph *irg,
- const arch_env_t *arch_env,
+be_chordal_env_t *be_ra_chordal(
+ const be_main_session_env_t *session,
const arch_register_class_t *cls)
{
+ ir_graph *irg = session->irg;
int node_count = get_graph_node_count(irg);
int colors_n = arch_register_class_n_regs(cls);
be_chordal_env_t *env = malloc(sizeof(*env));
env->nodes = new_set(if_node_cmp, node_count);
#endif
+ env->session_env = session;
env->live = bitset_obstack_alloc(&env->obst, node_count);
env->colors = bitset_obstack_alloc(&env->obst, colors_n);
env->in_colors = bitset_obstack_alloc(&env->obst, colors_n);
env->colors_n = colors_n;
env->cls = cls;
- env->arch_env = arch_env;
- env->irg = irg;
env->border_heads = pmap_create();
/* First, determine the pressure */
ir_snprintf(buf, sizeof(buf), "ifg_%s_%F.eps", cls->name, irg);
plotter = new_plotter_ps(buf);
- draw_interval_tree(&draw_chordal_def_opts, env, plotter, arch_env, cls);
+ draw_interval_tree(&draw_chordal_def_opts, env, plotter, env->session_env->main_env->arch_env, cls);
plotter_free(plotter);
}
#endif
}
void be_ra_chordal_check(be_chordal_env_t *chordal_env) {
- const arch_env_t *arch_env;
+ const arch_env_t *arch_env = chordal_env->session_env->main_env->arch_env;
struct obstack ob;
pmap_entry *pme;
ir_node **nodes, *n1, *n2;
int i, o;
- arch_env = chordal_env->arch_env;
-
/* Collect all irns */
obstack_init(&ob);
pmap_foreach(chordal_env->border_heads, pme) {
for (o = i+1, n2 = nodes[o]; n2; n2 = nodes[++o]) {
n2_reg = arch_get_irn_register(arch_env, n2, 0);
if (nodes_interfere(chordal_env, n1, n2) && n1_reg == n2_reg) {
- DBG((dbg, 0, "Values %+F and %+F interfere and have the same regiseter assigned\n", n1, n2));
+ DBG((dbg, 0, "Values %+F and %+F interfere and have the same register assigned\n", n1, n2));
assert(0 && "Interfering values have the same color!");
}
}
}
#endif
+
+typedef struct {
+ const be_main_session_env_t *env;
+ const arch_register_class_t *cls;
+} check_pressure_info_t;
+
+
+static int check_pressure_has_class(const check_pressure_info_t *i, const ir_node *irn)
+{
+ return arch_irn_has_reg_class(i->env->main_env->arch_env,
+ irn, arch_pos_make_out(0), i->cls);
+}
+
+static void check_pressure_walker(ir_node *bl, void *data)
+{
+ check_pressure_info_t *info = data;
+ int n_regs = arch_register_class_n_regs(info->cls);
+
+ pset *live = pset_new_ptr_default();
+ int step = 0;
+ ir_node *irn;
+ irn_live_t *li;
+
+ live_foreach(bl, li) {
+ if(live_is_end(li) && check_pressure_has_class(info, li->irn)) {
+ ir_node *irn = (ir_node *) li->irn;
+ pset_insert_ptr(live, irn);
+ }
+ }
+
+ sched_foreach_reverse(bl, irn) {
+ int i, n;
+ int pressure = pset_count(live);
+
+ if(pressure > n_regs) {
+ ir_node *x;
+ ir_printf("%+10F@%+10F: pressure to high: %d\n", bl, irn, pressure);
+ for(x = pset_first(live); x; x = pset_next(live))
+ ir_printf("\t%+10F\n", x);
+ }
+
+ if(check_pressure_has_class(info, irn))
+ pset_remove_ptr(live, irn);
+
+ for(i = 0, n = get_irn_arity(irn); i < n; i++) {
+ ir_node *op = get_irn_n(irn, i);
+ if(check_pressure_has_class(info, op) && !is_Phi(irn))
+ pset_insert_ptr(live, op);
+ }
+ step++;
+ }
+}
+
+void be_check_pressure(const be_main_session_env_t *env, const arch_register_class_t *cls)
+{
+ check_pressure_info_t i;
+ i.env = env;
+ i.cls = cls;
+ irg_block_walk_graph(env->irg, check_pressure_walker, NULL, &i);
+}