-static INLINE int pi_get_first_pos(problem_instance_t *pi, int num) {
- num2pos_t find, *found;
- find.num = num;
- found = set_find(pi->num2pos, &find, sizeof(find), HASH_NUM(num));
- if (found) {
- assert(pi->x[found->pos].n == num && (found->pos == 0 || pi->x[found->pos-1].n != num) && "pi->num2pos is broken!");
- return found->pos;
- } else
- return -1;
-}
-
-/**
- * Get position by number and color.
- * returns -1 if not found.
- */
-static INLINE int pi_get_pos(problem_instance_t *pi, int num, int col) {
- num2pos_t find, *found;
- int pos;
-
- find.num = num;
- found = set_find(pi->num2pos, &find, sizeof(find), HASH_NUM(num));
- if (!found)
- return -1;
- pos = found->pos;
- while (pos < pi->x_dim && pi->x[pos].n == num && pi->x[pos].c < col)
- pos++;
-
- if (pi->x[pos].n == num && pi->x[pos].c == col)
- return pos;
- else
- return -1;
-}
-
-/**
- * Collects all irns in currently processed register class
- */
-static void pi_collect_x_names(ir_node *block, void *env) {
- problem_instance_t *pi = env;
- struct list_head *head = get_block_border_head(pi->co->chordal_env, block);
- border_t *curr;
- bitset_t *pos_regs = bitset_alloca(pi->co->cls->n_regs);
-
- list_for_each_entry_reverse(border_t, curr, head, list)
- if (curr->is_def && curr->is_real && !is_removed(curr->irn)) {
- x_name_t xx;
- pi->A_dim++; /* one knapsack constraint for each node */
-
- xx.n = get_irn_graph_nr(curr->irn);
- pi_set_first_pos(pi, xx.n, pi->x_dim);
-
- // iterate over all possible colors in order
- bitset_clear_all(pos_regs);
- arch_get_allocatable_regs(pi->co->env, curr->irn, arch_pos_make_out(0), pi->co->cls, pos_regs);
- bitset_foreach(pos_regs, xx.c) {
- DBG((dbg, LEVEL_2, "Adding %n %d\n", curr->irn, xx.c));
- obstack_grow(&pi->ob, &xx, sizeof(xx));
- pi->x_dim++; /* one x variable for each node and color */
- }
- }
-}
-
-/**
- * Checks if all nodes in living are live_out in block block.
- */
-static INLINE int all_live_in(ir_node *block, pset *living) {
- ir_node *n;
- for (n = pset_first(living); n; n = pset_next(living))
- if (!is_live_in(block, n)) {
- pset_break(living);
- return 0;
- }
- return 1;
-}
-
-/**
- * Finds cliques in the interference graph, considering only nodes
- * for which the color pi->curr_color is possible. Finds only 'maximal-cliques',
- * viz cliques which are not conatained in another one.
- * This is used for the matrix B.
- */
-static void pi_clique_finder(ir_node *block, void *env) {
- problem_instance_t *pi = env;
- enum phase_t {growing, shrinking} phase = growing;
- struct list_head *head = get_block_border_head(pi->co->chordal_env, block);
- border_t *b;
- pset *living = pset_new_ptr(SLOTS_LIVING);
-
- list_for_each_entry_reverse(border_t, b, head, list) {
- const ir_node *irn = b->irn;
- if (is_removed(irn))
- continue;
-
- if (b->is_def) {
- DBG((dbg, LEVEL_2, "Def %n\n", irn));
- pset_insert_ptr(living, irn);
- phase = growing;
- } else { /* is_use */
- DBG((dbg, LEVEL_2, "Use %n\n", irn));
-
- /* before shrinking the set, store the current 'maximum' clique;
- * do NOT if clique is a single node
- * do NOT if all values are live_in (in this case they were contained in a live-out clique elsewhere) */
- if (phase == growing && pset_count(living) >= 2 && !all_live_in(block, living)) {
- ir_node *n;
- for (n = pset_first(living); n; n = pset_next(living)) {
- int pos = pi_get_pos(pi, get_irn_graph_nr(n), pi->curr_color);
- matrix_set(pi->B, pi->curr_row, pos, 1);
- DBG((dbg, LEVEL_2, "B[%d, %d] := %d\n", pi->curr_row, pos, 1));
- }
- pi->curr_row++;
- }
- pset_remove_ptr(living, irn);
- phase = shrinking;
- }
- }
-
- del_pset(living);
-}
-
-static INLINE int pi_is_simplicial(problem_instance_t *pi, const if_node_t *ifn) {