Added call to eliminate_phi_interferences. Enabled phi-destruction.
[libfirm] / ir / be / becopyilp.c
index 63c9fba..111bef0 100644 (file)
 #include "becopyopt.h"
 #include "becopystat.h"
 
-#define DUMP_MPS
+#undef DUMP_MPS
 #define DEBUG_LVL SET_LEVEL_1
 static firm_dbg_module_t *dbg = NULL;
 
+#define EPSILON 0.00001
 #define SLOTS_LIVING 32
 
-/**
- * Represents the _costs_ if node n and m have different colors.
- * Must be >=0.
- **/
-#define get_weight(n,m) 1
-
 typedef struct _simpl_t {
        struct list_head chain;
        if_node_t *ifn;
@@ -115,14 +110,14 @@ static void pi_find_simplicials(problem_instance_t *pi) {
                redo = 0;
                for (ifn = set_first(if_nodes); ifn; ifn = set_next(if_nodes)) {
                        ir_node *irn = get_irn_for_graph_nr(pi->co->chordal_env->irg, ifn->nnr);
-                       if (!is_removed(irn) && !is_optimizable(irn) &&
+                       if (!is_removed(irn) && !is_optimizable(pi->co->chordal_env->arch_env, 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_2, " Removed %n\n", irn));
+                               DBG((dbg, LEVEL_2, " Removed %n %d\n", irn, get_irn_graph_nr(irn)));
                        }
                }
        }
@@ -252,7 +247,7 @@ static void pi_add_constr_E(problem_instance_t *pi) {
        DBG((dbg, LEVEL_2, "Add E constraints...\n"));
        /* for all roots of optimization units */
        list_for_each_entry(unit_t, curr, &pi->co->units, units) {
-               const ir_node *root, *arg;
+               ir_node *root, *arg;
                int rootnr, argnr, color;
                int y_idx, i;
                char buf[32];
@@ -271,7 +266,8 @@ static void pi_add_constr_E(problem_instance_t *pi) {
 
                        /* Introduce new variable and set factor in objective function */
                        mangle_var(buf, 'y', rootnr, argnr);
-                       y_idx = lpp_add_var(pi->curr_lp, buf, continous, get_weight(root, arg));
+                       y_idx = lpp_add_var(pi->curr_lp, buf, continous, curr->costs[i]);
+
                        /* set starting value */
                        //lpp_set_start_value(pi->curr_lp, y_idx, (get_irn_col(pi->co, root) != get_irn_col(pi->co, arg)));
 
@@ -319,13 +315,13 @@ static void pi_add_constr_M(problem_instance_t *pi) {
                int cst_idx, y_idx, i;
                char buf[32];
 
-               if (curr->ifg_mis_size == curr->node_count)
+               if (curr->minimal_costs == 0)
                        continue;
 
                root = curr->nodes[0];
                rootnr = get_irn_graph_nr(root);
                mangle_cst(buf, 'M', cst_counter++);
-               cst_idx = lpp_add_cst(pi->curr_lp, buf, greater, curr->node_count - curr->ifg_mis_size);
+               cst_idx = lpp_add_cst(pi->curr_lp, buf, greater, curr->minimal_costs);
 
                /* for all arguments */
                for (i = 1; i < curr->node_count; ++i) {
@@ -355,7 +351,7 @@ static problem_instance_t *new_pi(const copy_opt_t *co) {
 
        /* problem size reduction */
        pi_find_simplicials(pi);
-       //TODO dump_ifg_w/o_removed
+       //TODO If you wish to see it: dump_ifg_w/o_removed
        if (pi->all_simplicial)
                return pi;
 
@@ -415,7 +411,6 @@ static void pi_set_start_sol(problem_instance_t *pi) {
 static void pi_solve_ilp(problem_instance_t *pi, void (*lpp_solve)(lpp_t *)) {
        pi_set_start_sol(pi);
        lpp_solve(pi->curr_lp);
-       DBG((dbg, LEVEL_1, "Solution time: %f\n", lpp_get_sol_time(pi->curr_lp)));
 }
 
 /**
@@ -462,27 +457,30 @@ static void pi_apply_solution(problem_instance_t *pi) {
        DBG((dbg, LEVEL_2, "Applying solution...\n"));
 
 #ifdef DO_STAT
-       //TODO stat
+       curr_vals[I_ILP_ITER] += lpp_get_iter_cnt(pi->curr_lp);
+       curr_vals[I_ILP_TIME] += lpp_get_sol_time(pi->curr_lp);
 #endif
 
        sol = xmalloc((pi->last_x_var+1) * sizeof(*sol));
        state = lpp_get_solution(pi->curr_lp, sol, 1, pi->last_x_var);
        if (state != optimal) {
                printf("Solution state is not 'optimal': %d\n", state);
-               if (state < feasible)
-                       assert(0);
+               assert(state >= feasible && "The solution should at least be feasible!");
        }
-       for (i=0; i<pi->last_x_var; ++i)
-               if (sol[i] == 1.0) { /* split varibale name into components */
-                       int nnr, col;
-                       char var_name[64];
+       for (i=0; i<pi->last_x_var; ++i) {
+               int nnr, col;
+               char var_name[64];
+
+               if (sol[i] > 1-EPSILON) { /* split varibale name into components */
                        lpp_get_var_name(pi->curr_lp, 1+i, var_name, sizeof(var_name));
                        if (split_var(var_name, &nnr, &col) == 2) {
-                               DBG((dbg, LEVEL_2, " x%d = %d\n", nnr, col));
+                               DBG((dbg, LEVEL_2, "Irn %n  Idx %d  Var %s  Val %f\n", get_irn_for_graph_nr(pi->co->chordal_env->irg, nnr), i, var_name, sol[i]));
+                               DBG((dbg, LEVEL_2, "x%d = %d\n", nnr, col));
                                set_irn_col(pi->co, get_irn_for_graph_nr(pi->co->chordal_env->irg, nnr), col);
                        } else
                                assert(0 && "This should be a x-var");
                }
+       }
 }
 
 void co_ilp_opt(copy_opt_t *co) {
@@ -490,7 +488,7 @@ void co_ilp_opt(copy_opt_t *co) {
 
        dbg = firm_dbg_register("ir.be.copyoptilp");
        if (!strcmp(co->name, DEBUG_IRG))
-               firm_dbg_set_mask(dbg, -1);
+               firm_dbg_set_mask(dbg, DEBUG_LVL_ILP);
        else
                firm_dbg_set_mask(dbg, DEBUG_LVL);