struct _be_uses_t {
set *uses;
ir_graph *irg;
- firm_dbg_module_t *dbg;
const arch_env_t *arch_env;
+ DEBUG_ONLY(firm_dbg_module_t *dbg;)
};
-
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-
static INLINE unsigned sadd(unsigned a, unsigned b)
{
return a + b;
be_use_t *u;
u = get_or_set_use(uses, bl, def, 0);
- if(!u->is_set) {
+ if (! u->is_set) {
u->is_set = 1;
u->next_use = USES_INFINITY;
u->next_use = be_get_next_use(uses, sched_first(bl), 0, def, 0);
return u->next_use;
}
-unsigned be_get_next_use(be_uses_t *uses,
- const ir_node *from, unsigned from_step, const ir_node *def,
- int skip_from_uses)
+static unsigned get_next_use(be_uses_t *uses, const ir_node *from, unsigned from_step, const ir_node *def, int skip_from_uses, unsigned long visited_nr)
{
- unsigned next_use = USES_INFINITY;
- unsigned step = from_step;
- unsigned n = 0;
- const ir_node *irn;
- const ir_node *bl = get_block(from);
- const ir_edge_t *succ_edge;
-
- sched_foreach_from(from, irn) {
- int i, n;
-
- if(!skip_from_uses) {
- for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
- ir_node *operand = get_irn_n(irn, i);
-
- if(operand == def) {
- DBG((uses->dbg, LEVEL_3, "found use of %+F at %+F\n", operand, irn));
- return step;
- }
- }
+ unsigned next_use = USES_INFINITY;
+ unsigned step = from_step;
+ unsigned n = 0;
+ ir_node *bl = get_nodes_block(from);
+ const ir_node *irn;
+ const ir_edge_t *succ_edge;
+
+ set_irn_visited(bl, visited_nr);
+
+ sched_foreach_from(from, irn) {
+ int i, n;
+
+ if (! skip_from_uses) {
+ for (i = 0, n = get_irn_arity(irn); i < n; ++i) {
+ ir_node *operand = get_irn_n(irn, i);
+
+ if (operand == def) {
+ DBG((uses->dbg, LEVEL_3, "found use of %+F at %+F\n", operand, irn));
+ return step;
+ }
+ }
+ }
+
+ skip_from_uses = 0;
+ step++;
}
- skip_from_uses = 0;
- step++;
- }
+ /* FIXME: quick and dirty hack to prevent ignore nodes (like stack pointer) from being spilled */
+ return is_live_end(bl, def) ? step : USES_INFINITY;
next_use = USES_INFINITY;
foreach_block_succ(bl, succ_edge) {
- const ir_node *succ_bl = succ_edge->src;
- if(is_live_in(succ_bl, def) || (get_irn_arity(succ_bl) > 1 && is_live_end(bl, def))) {
+ const ir_node *succ_bl = succ_edge->src;
+ if(get_irn_visited(succ_bl) < visited_nr && (is_live_in(succ_bl, def) || (get_irn_arity(succ_bl) > 1 && is_live_end(bl, def)))) {
unsigned next = get_next_use_bl(uses, succ_bl, def);
DBG((uses->dbg, LEVEL_2, "\t\tnext use in succ %+F: %d\n", succ_bl, next));
next_use = MIN(next_use, next);
n++;
- }
+ }
}
return next_use + step;
}
-be_uses_t *be_begin_uses(
- ir_graph *irg,
- const arch_env_t *arch_env,
- const arch_register_class_t *cls)
+unsigned be_get_next_use(be_uses_t *uses, const ir_node *from, unsigned from_step, const ir_node *def, int skip_from_uses)
+{
+ unsigned long visited_nr = get_irg_visited(uses->irg) + 1;
+
+ set_irg_visited(uses->irg, visited_nr);
+ return get_next_use(uses, from, from_step, def, skip_from_uses, visited_nr);
+}
+
+
+be_uses_t *be_begin_uses(ir_graph *irg, const arch_env_t *arch_env, const arch_register_class_t *cls)
{
- be_uses_t *uses = malloc(sizeof(uses[0]));
+ be_uses_t *uses = xmalloc(sizeof(uses[0]));
edges_assure(irg);
uses->arch_env = arch_env;
uses->uses = new_set(cmp_use, 512);
- uses->dbg = firm_dbg_register("be.uses");
- firm_dbg_set_mask(uses->dbg, DBG_LEVEL);
+ uses->irg = irg;
+ FIRM_DBG_REGISTER(uses->dbg, "firm.be.uses");
return uses;
}