-/**
- * 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 contained in another one.
- * This is used for the matrix B.
- * TODO check color
- */
-static void pi_add_constr_B(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)) {
- int cst_idx;
- ir_node *n;
- mangle_cst(pi->buf, 'B', pi->cst_counter);
- cst_idx = lpp_add_cst(pi->curr_lp, pi->buf, less, 1);
- for (n = pset_first(living); n; n = pset_next(living)) {
- int var_idx;
- mangle_var_irn(pi->buf, 'x', n, pi->curr_color);
- var_idx = lpp_get_var_idx(pi->curr_lp, pi->buf);
- assert(var_idx>=1);
- lpp_set_factor_fast(pi->curr_lp, cst_idx, var_idx, 1);
- }
- pi->cst_counter++;
- }
- pset_remove_ptr(living, irn);
- phase = shrinking;
- }
- }
-
- del_pset(living);
-}
-
-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);