-static void pi_add_constr_E(problem_instance_t *pi) {
- unit_t *curr;
- bitset_t *root_regs, *arg_regs;
- root_regs = bitset_alloca(pi->co->cls->n_regs);
- arg_regs = bitset_alloca(pi->co->cls->n_regs);
-
- /* for all roots of optimization units */
- list_for_each_entry(unit_t, curr, &pi->co->units, units) {
- const ir_node *root, *arg;
- int rootnr, argnr, color;
- int y_idx, i, cst_counter = 0;
- char buf[32];
-
- root = curr->nodes[0];
- rootnr = get_irn_graph_nr(root);
- bitset_clear_all(root_regs);
- arch_get_allocatable_regs(pi->co->env, root, arch_pos_make_out(0), pi->co->cls, root_regs);
-
- /* for all arguments of root */
- for (i = 1; i < curr->node_count; ++i) {
- arg = curr->nodes[i];
- argnr = get_irn_graph_nr(arg);
- bitset_clear_all(arg_regs);
- arch_get_allocatable_regs(pi->co->env, arg, arch_pos_make_out(0), pi->co->cls, arg_regs);
-
- /* Introduce new variable and set factor in objective function */
- y_idx = lpp_add_var(pi->curr_lp, NULL, real, get_weight(root, arg));
-
- /* For all colors root and arg have in common, add 2 constraints to E */
- bitset_and(arg_regs, root_regs);
- bitset_foreach(arg_regs, color) {
- int root_idx, arg_idx, cst_idx;
- mangle_var(buf, 'x', rootnr, color);
- root_idx = lpp_get_var_idx(pi->curr_lp, buf);
- mangle_var(buf, 'x', argnr, color);
- arg_idx = lpp_get_var_idx(pi->curr_lp, buf);
-
- /* add root-arg+y <= 1 */
- mangle_cst(buf, 'E', cst_counter++);
- cst_idx = lpp_add_cst(pi->curr_lp, buf, less, 0);
- lpp_set_factor_fast(pi->curr_lp, cst_idx, root_idx, 1);
- lpp_set_factor_fast(pi->curr_lp, cst_idx, arg_idx, -1);
- lpp_set_factor_fast(pi->curr_lp, cst_idx, y_idx, -1);
-
- /* add arg-root+y <= 1 */
- mangle_cst(buf, 'E', cst_counter++);
- cst_idx = lpp_add_cst(pi->curr_lp, buf, less, 0);
- lpp_set_factor_fast(pi->curr_lp, cst_idx, root_idx, -1);
- lpp_set_factor_fast(pi->curr_lp, cst_idx, arg_idx, 1);
- lpp_set_factor_fast(pi->curr_lp, cst_idx, y_idx, -1);
- }
+ rbitset_copy(possible_cols, allocatable_cols, n_regs);
+
+ /* get free color by inspecting all neighbors */
+ be_ifg_foreach_neighbour(ifg, &iter, irn, 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 */
+ /* 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);