Added insertion of duplicates for operands of phi nodes that interfere
[libfirm] / ir / be / becopyilp.c
index 63c9fba..462e802 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
 
 /**
@@ -115,14 +116,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)));
                        }
                }
        }
@@ -415,7 +416,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 +462,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 +493,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);