check constraints only for scheduled nodes
[libfirm] / ir / be / beilpsched.c
index 4065e95..04f22f0 100644 (file)
@@ -71,6 +71,7 @@ typedef struct _ilp_var_types_t {
 typedef struct _ilpsched_node_attr_t {
        unsigned asap;                     /**< The ASAP scheduling control step */
        unsigned alap;                     /**< The ALAP scheduling control step */
+       unsigned latency;                  /**< Latency of this node (needed for sorting) */
        unsigned sched_point;              /**< the step in which the node is finally scheduled */
        unsigned visit_idx;                /**< Index of the node having visited this node last */
        unsigned consumer_idx;             /**< Index of the node having counted this node as consumer last */
@@ -138,7 +139,7 @@ typedef struct {
                is_normal_Proj(isa, irn) ||  \
                is_Phi(irn)              ||  \
                is_NoMem(irn)            ||  \
-               is_Jmp(irn)              ||  \
+               is_Unknown(irn)          ||  \
                is_End(irn)                  \
                ))
 
@@ -235,7 +236,12 @@ static int cmp_ilpsched_irn(const void *a, const void *b) {
                        return 1;
                if (heights_reachable_in_block(glob_heights, irn_b, irn_a))
                        return -1;
-               return 0;
+
+               /*
+                       Ok, timestep is equal and the nodes are parallel,
+                       so check latency and schedule high latency first.
+               */
+               return QSORT_CMP(n2_a->latency, n1_a->latency);
        }
        else
                return QSORT_CMP(n1_a->sched_point, n2_a->sched_point);
@@ -471,8 +477,9 @@ static void calculate_irn_asap(ir_node *irn, void *walk_env) {
                        ilpsched_node_attr_t *pna       = get_ilpsched_node_attr(pred_node);
                        unsigned             lat;
 
-                       lat      = fixed_latency(env->sel, pred, env->block_env);
-                       na->asap = MAX(na->asap, pna->asap + lat);
+                       lat         = fixed_latency(env->sel, pred, env->block_env);
+                       na->latency = lat;
+                       na->asap    = MAX(na->asap, pna->asap + lat);
                }
        }
 
@@ -760,10 +767,9 @@ static void apply_solution(be_ilpsched_env_t *env, lpp_t *lpp, ir_node *block) {
                        }
                }
 
-               glob_heights = heights_new(env->irg);
+               glob_heights = env->height;
                /* sort nodes ascending by scheduling time step */
                qsort(sched_nodes, ARR_LEN(sched_nodes), sizeof(sched_nodes[0]), cmp_ilpsched_irn);
-               heights_free(glob_heights);
        }
 
        /* make all Phis ready and remember the single cf op */
@@ -779,6 +785,7 @@ static void apply_solution(be_ilpsched_env_t *env, lpp_t *lpp, ir_node *block) {
                        case iro_End:
                        case iro_Proj:
                        case iro_Bad:
+                       case iro_Unknown:
                                break;
                        default:
                                if (is_cfop(irn)) {
@@ -792,7 +799,8 @@ static void apply_solution(be_ilpsched_env_t *env, lpp_t *lpp, ir_node *block) {
        /* add all nodes from list */
        for (i = 0, l = ARR_LEN(sched_nodes); i < l; ++i) {
                ilpsched_node_attr_t *na = get_ilpsched_node_attr(sched_nodes[i]);
-               add_to_sched(env, block, sched_nodes[i]->irn, na->sched_point);
+               if (sched_nodes[i]->irn != cfop)
+                       add_to_sched(env, block, sched_nodes[i]->irn, na->sched_point);
        }
 
        /* schedule control flow node if not already done */
@@ -1603,6 +1611,7 @@ static void create_pressure_alive_constraint(be_ilpsched_env_t *env, lpp_t *lpp,
                num_cst, ilp_timer_elapsed_usec(t_cst) / 1000000.0));
 }
 
+#if 0
 static void create_proj_keep_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn_t *block_node) {
        char                  buf[1024];
        ir_node               *irn;
@@ -1676,6 +1685,7 @@ static void create_proj_keep_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_
        DBG((env->dbg, LEVEL_1, "\t%u Proj and Keep constraints (%g sec)\n",
                num_cst, ilp_timer_elapsed_usec(t_cst) / 1000000.0));
 }
+#endif
 
 /***************************************************
  *  _____ _      _____                    _
@@ -1697,6 +1707,7 @@ static void create_ilp(ir_node *block, void *walk_env) {
        FILE                  *logfile       = NULL;
        lpp_t                 *lpp           = NULL;
        struct obstack        var_obst;
+       char                  name[1024];
 
        DBG((env->dbg, 255, "\n\n\n=========================================\n"));
        DBG((env->dbg, 255, "  ILP Scheduling for %+F\n", block));
@@ -1720,8 +1731,10 @@ static void create_ilp(ir_node *block, void *walk_env) {
                        estimated_n_var, estimated_n_cst));
 
                /* set up the LPP object */
+               snprintf(name, sizeof(name), "ilp scheduling IRG %s", get_entity_ld_name(get_irg_entity(env->irg)));
+
                lpp = new_lpp_userdef(
-                       "be ilp scheduling",
+                       (const char *)name,
                        lpp_minimize,
                        estimated_n_cst + 1,  /* num vars */
                        estimated_n_cst + 20, /* num cst */
@@ -1737,6 +1750,7 @@ static void create_ilp(ir_node *block, void *walk_env) {
                create_ressource_constraints(env, lpp, block_node);
                create_bundle_constraints(env, lpp, block_node);
                //create_proj_keep_constraints(env, lpp, block_node);
+#if 0
                if (ba->n_interesting_nodes > env->opts->limit_dead) {
                        create_alive_nodes_constraint(env, lpp, block_node);
                        create_pressure_alive_constraint(env, lpp, block_node);
@@ -1744,6 +1758,7 @@ static void create_ilp(ir_node *block, void *walk_env) {
                        create_dying_nodes_constraint(env, lpp, block_node);
                        create_pressure_dead_constraint(env, lpp, block_node);
                }
+#endif
 
                DBG((env->dbg, LEVEL_1, "ILP to solve: %u variables, %u constraints\n", lpp->var_next, lpp->cst_next));
 
@@ -1865,9 +1880,6 @@ void be_ilp_sched(const be_irg_t *birg) {
        /* We refine the {ASAP(n), ALAP(n)} interval and fix the time steps for Projs and Keeps */
        irg_walk_in_or_dep_blkwise_graph(env.irg, NULL, refine_asap_alap_times, &env);
 
-       /* we don't need this information any longer */
-       heights_free(env.height);
-
        /* perform ILP scheduling */
        irg_block_walk_graph(env.irg, clear_unwanted_data, create_ilp, &env);
 
@@ -1882,6 +1894,7 @@ void be_ilp_sched(const be_irg_t *birg) {
 
        /* free all allocated object */
        phase_free(&env.ph);
+       heights_free(env.height);
 
        /* notify backend */
        be_ilp_sched_finish_irg_ilp_schedule(sel, birg->irg, env.irg_env);