From de25f93b0e1223e11e0ff6c5425ee277e563119c Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 1 Dec 2011 20:14:25 +0100 Subject: [PATCH] becopyilp: fix size_reduction code Fix the size reduction stuff which happily assigned non-allocatable registers. It worked by chance on x86 as all non-allocatable registers come last. --- ir/be/becopyilp.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/ir/be/becopyilp.c b/ir/be/becopyilp.c index 646b6c98d..6ec78b5a5 100644 --- a/ir/be/becopyilp.c +++ b/ir/be/becopyilp.c @@ -165,27 +165,37 @@ void sr_remove(size_red_t *sr) void sr_reinsert(size_red_t *sr) { coloring_suffix_t *cs; + ir_graph *irg = sr->co->irg; be_ifg_t *ifg = sr->co->cenv->ifg; - bitset_t *used_cols = bitset_alloca(arch_register_class_n_regs(sr->co->cls)); + unsigned n_regs = arch_register_class_n_regs(sr->co->cls); + unsigned *possible_cols; + unsigned *allocatable_cols; + + rbitset_alloca(allocatable_cols, n_regs); + be_set_allocatable_regs(irg, sr->co->cls, allocatable_cols); + + rbitset_alloca(possible_cols, n_regs); neighbours_iter_t iter; /* color the removed nodes in right order */ for (cs = sr->col_suff; cs; cs = cs->next) { - int free_col; - ir_node *other, *irn; + unsigned free_col; + ir_node *other; + ir_node *irn = cs->irn; - /* get free color by inspecting all neighbors */ - irn = cs->irn; - bitset_clear_all(used_cols); + rbitset_copy(possible_cols, allocatable_cols, n_regs); + /* get free color by inspecting all neighbors */ be_ifg_foreach_neighbour(ifg, &iter, irn, other) { - if (!sr_is_removed(sr, other)) /* only inspect nodes which are in graph right now */ - bitset_set(used_cols, get_irn_col(other)); + /* only inspect nodes which are in graph right now */ + if (sr_is_removed(sr, other)) + continue; + rbitset_clear(possible_cols, get_irn_col(other)); } /* now all bits not set are possible colors */ - free_col = bitset_next_clear(used_cols, 0); - assert(free_col != -1 && "No free color found. This can not be."); + free_col = (unsigned)rbitset_next(possible_cols, 0, true); + assert(!rbitset_is_empty(possible_cols, n_regs) && "No free color found. This can not be."); set_irn_col(sr->co, irn, free_col); pset_remove_ptr(sr->all_removed, irn); /* irn is back in graph again */ } -- 2.20.1