- for (ifn = set_first(if_nodes); ifn; ifn = set_next(if_nodes)) {
- ir_node *irn = get_irn_for_graph_nr(pi->co->irg, ifn->nnr);
- if (!is_removed(irn) && !is_optimizable(irn) &&
- !is_optimizable_arg(pi->co, irn) && pi_is_simplicial(pi, ifn)) {
- simpl_t *s = xmalloc(sizeof(*s));
- s->ifn = ifn;
- list_add(&s->chain, &pi->simplicials);
- pset_insert_ptr(pi->removed, irn);
- redo = 1;
- DBG((dbg, LEVEL_1, " Removed %n\n", irn));
- }
- }
- }
-}
-
-/**
- * Generate the initial problem matrices and vectors.
- */
-static problem_instance_t *new_pi(const copy_opt_t *co) {
- DBG((dbg, LEVEL_1, "Generating new instance...\n"));
- problem_instance_t *pi = xcalloc(1, sizeof(*pi));
- pi->co = co;
- pi->num2pos = new_set(set_cmp_num2pos, SLOTS_NUM2POS);
- pi->bigM = 1;
- pi->removed = pset_new_ptr_default();
- INIT_LIST_HEAD(&pi->simplicials);
-
- /* problem size reduction */
- pi_find_simplicials(pi);
- //TODO dump_ifg_wo_removed
-
- /* Vector x
- * one entry per node and possible color */
- obstack_init(&pi->ob);
- dom_tree_walk_irg(co->irg, pi_collect_x_names, NULL, pi);
- pi->x = obstack_finish(&pi->ob);
-
- /* Matrix Q and E
- * weights for the 'same-color-optimization' target */
- {
- unit_t *curr;
- pi->Q = new_matrix(pi->x_dim, pi->x_dim);
- pi->E = new_matrix(pi->x_dim, pi->x_dim);
- pi->c = new_matrix(1, pi->x_dim);
-
- list_for_each_entry(unit_t, curr, &co->units, units) {
- const ir_node *root, *arg;
- int rootnr, argnr;
- unsigned save_rootpos, rootpos, argpos;
- int i;
-
- root = curr->nodes[0];
- rootnr = get_irn_graph_nr(root);
- save_rootpos = pi_get_first_pos(pi, rootnr);
- for (i = 1; i < curr->node_count; ++i) {
- int weight;
- rootpos = save_rootpos;
- arg = curr->nodes[i];
- argnr = get_irn_graph_nr(arg);
- argpos = pi_get_first_pos(pi, argnr);
- weight = -get_weight(root, arg);
-
- DBG((dbg, LEVEL_2, "Q[%n, %n] := %d\n", root, arg, weight));
- /* for all colors root and arg have in common, set the weight for
- * this pair in the objective function matrix Q */
- while (rootpos < pi->x_dim && argpos < pi->x_dim &&
- pi->x[rootpos].n == rootnr && pi->x[argpos].n == argnr) {
- if (pi->x[rootpos].c < pi->x[argpos].c)
- ++rootpos;
- else if (pi->x[rootpos].c > pi->x[argpos].c)
- ++argpos;
- else {
- /* E */
- matrix_set(pi->E, pi->E_dim, rootpos, +1);
- matrix_set(pi->E, pi->E_dim, argpos, -1);
- matrix_set(pi->E, pi->E_dim, pi->x_dim + pi->c_dim, 1);
- pi->E_dim++;
- matrix_set(pi->E, pi->E_dim, rootpos, -1);
- matrix_set(pi->E, pi->E_dim, argpos, +1);
- matrix_set(pi->E, pi->E_dim, pi->x_dim + pi->c_dim, 1);
- pi->E_dim++;
-
- /* Q */
- matrix_set(pi->Q, rootpos, argpos, weight + matrix_get(pi->Q, rootpos, argpos));
- rootpos++;
- argpos++;
- if (weight < pi->minQij) {
- DBG((dbg, LEVEL_2, "minQij = %d\n", weight));
- pi->minQij = weight;
- }
- if (weight > pi->maxQij) {
- DBG((dbg, LEVEL_2, "maxQij = %d\n", weight));
- pi->maxQij = weight;
- }
- }
- }
-
- /* E */
- matrix_set(pi->c, 1, pi->c_dim++, -weight);
- }
- }
- }
-
- /* Matrix A
- * knapsack constraint for each node */
- {
- int row = 0, col = 0;
- pi->A = new_matrix(pi->A_dim, pi->x_dim);
- while (col < pi->x_dim) {
- int curr_n = pi->x[col].n;
- while (col < pi->x_dim && pi->x[col].n == curr_n) {
- DBG((dbg, LEVEL_2, "A[%d, %d] := %d\n", row, col, 1));
- matrix_set(pi->A, row, col++, 1);
- }
- ++row;
- }
- assert(row == pi->A_dim);
- }