#include <stdbool.h>
+#include "be_t.h"
#include "irtools.h"
#include "irprintf.h"
-#include "bestatevent.h"
-#include "beirg.h"
+#include "statev_t.h"
#include "bemodule.h"
#include "error.h"
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 *const allocatable_cols = rbitset_alloca(n_regs);
+ be_set_allocatable_regs(irg, sr->co->cls, allocatable_cols);
+
+ unsigned *const possible_cols = rbitset_alloca(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));
+ const arch_register_req_t *cur_req;
+ unsigned cur_col;
+
+ /* only inspect nodes which are in graph right now */
+ if (sr_is_removed(sr, other))
+ continue;
+
+ cur_req = arch_get_irn_register_req(other);
+ cur_col = get_irn_col(other);
+
+ /* Invalidate all single size register when it is a large one */
+ do {
+ rbitset_clear(possible_cols, cur_col);
+ ++cur_col;
+ } while ((cur_col % cur_req->width) != 0);
}
/* 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.");
- set_irn_col(sr->co, irn, free_col);
+ /* take one that matches the alignment constraint */
+ free_col = 0;
+ assert(!rbitset_is_empty(possible_cols, n_regs) && "No free color found. This can not be.");
+ while (true) {
+ free_col = (unsigned)rbitset_next(possible_cols, free_col, true);
+ if (free_col % arch_get_irn_register_req(irn)->width == 0)
+ break;
+ ++free_col;
+ assert(free_col < n_regs);
+ }
+ set_irn_col(sr->co->cls, irn, free_col);
pset_remove_ptr(sr->all_removed, irn); /* irn is back in graph again */
}
}
lpp_sol_state_t ilp_go(ilp_env_t *ienv)
{
- ir_graph *irg = ienv->co->irg;
- be_options_t *options = be_get_irg_options(irg);
+ ir_graph *irg = ienv->co->irg;
sr_remove(ienv->sr);
if (solve_log)
lpp_set_log(ienv->lp, stdout);
- lpp_solve(ienv->lp, options->ilp_server, options->ilp_solver);
+ lpp_solve(ienv->lp, be_options.ilp_server, be_options.ilp_solver);
- //be_stat_ev_dbl("co_ilp_objval", ienv->lp->objval);
- //be_stat_ev_dbl("co_ilp_best_bound", ienv->lp->best_bound);
- be_stat_ev ("co_ilp_iter", lpp_get_iter_cnt(ienv->lp));
- be_stat_ev_dbl("co_ilp_sol_time", lpp_get_sol_time(ienv->lp));
+ //stat_ev_dbl("co_ilp_objval", ienv->lp->objval);
+ //stat_ev_dbl("co_ilp_best_bound", ienv->lp->best_bound);
+ stat_ev_int("co_ilp_iter", lpp_get_iter_cnt(ienv->lp));
+ stat_ev_dbl("co_ilp_sol_time", lpp_get_sol_time(ienv->lp));
ienv->apply(ienv);