fixed precedence constraint
[libfirm] / ir / be / belistsched.c
index ffd9668..57f6699 100644 (file)
 #include "bearch.h"
 #include "bestat.h"
 
-#ifdef WITH_LIBCORE
 #include <libcore/lc_opts.h>
 #include <libcore/lc_opts_enum.h>
-#endif /* WITH_LIBCORE */
 
 #define BE_SCHED_NODE(irn) (be_is_Keep(irn) || be_is_CopyKeep(irn) || be_is_RegParams(irn))
 
@@ -74,7 +72,6 @@ static list_sched_options_t list_sched_options = {
        BE_SCHED_PREP_NONE,       /* no scheduling preparation */
 };
 
-#ifdef WITH_LIBCORE
 /* schedule selector options. */
 static const lc_opt_enum_int_items_t sched_select_items[] = {
        { "trivial",  BE_SCHED_SELECT_TRIVIAL  },
@@ -107,7 +104,6 @@ static const lc_opt_table_entry_t list_sched_option_table[] = {
        LC_OPT_ENT_ENUM_PTR("select", "node selector",          &sched_select_var),
        { NULL }
 };
-#endif /* WITH_LIBCORE */
 
 /**
  * All scheduling info needed per node.
@@ -175,31 +171,31 @@ static INLINE int make_ready(block_sched_env_t *env, ir_node *pred, ir_node *irn
 {
        int i, n;
 
-    /* Blocks cannot be scheduled. */
-    if (is_Block(irn) || get_irn_n_edges(irn) == 0)
-        return 0;
+       /* Blocks cannot be scheduled. */
+       if (is_Block(irn) || get_irn_n_edges(irn) == 0)
+               return 0;
 
-    /*
-     * Check, if the given ir node is in a different block as the
-     * currently scheduled one. If that is so, don't make the node ready.
-     */
-    if (env->block != get_nodes_block(irn))
-        return 0;
+       /*
+        * Check, if the given ir node is in a different block as the
+        * currently scheduled one. If that is so, don't make the node ready.
+        */
+       if (env->block != get_nodes_block(irn))
+               return 0;
 
        for (i = 0, n = get_irn_ins_or_deps(irn); i < n; ++i) {
-        ir_node *op = get_irn_in_or_dep(irn, i);
-
-        /* if irn is an End we have keep-alives and op might be a block, skip that */
-        if (is_Block(op)) {
-          assert(get_irn_op(irn) == op_End);
-          continue;
-        }
-
-        /* If the operand is local to the scheduled block and not yet
-         * scheduled, this nodes cannot be made ready, so exit. */
-        if (! is_already_scheduled(env, op) && get_nodes_block(op) == env->block)
-            return 0;
-    }
+               ir_node *op = get_irn_in_or_dep(irn, i);
+
+               /* if irn is an End we have keep-alives and op might be a block, skip that */
+               if (is_Block(op)) {
+                       assert(get_irn_op(irn) == op_End);
+                       continue;
+               }
+
+               /* If the operand is local to the scheduled block and not yet
+                * scheduled, this nodes cannot be made ready, so exit. */
+               if (! is_already_scheduled(env, op) && get_nodes_block(op) == env->block)
+                       return 0;
+       }
 
        nodeset_insert(env->cands, irn);
 
@@ -215,7 +211,7 @@ static INLINE int make_ready(block_sched_env_t *env, ir_node *pred, ir_node *irn
 /**
  * Try, to make all users of a node ready.
  * In fact, a usage node can only be made ready, if all its operands
- * have already been scheduled yet. This is checked my make_ready().
+ * have already been scheduled yet. This is checked by make_ready().
  * @param env The block schedule environment.
  * @param irn The node, which usages (successors) are to be made ready.
  */
@@ -517,7 +513,7 @@ static void list_sched_block(ir_node *block, void *env_ptr)
 
                /* Keeps must be scheduled immediatly */
                foreach_nodeset(be.cands, irn) {
-                       if (be_is_Keep(irn) || be_is_CopyKeep(irn) || get_irn_mode(irn) == mode_M) {
+                       if (be_is_Keep(irn) || be_is_CopyKeep(irn) || is_Sync(irn)) {
                                nodeset_break(be.cands);
                                break;
                        }
@@ -624,7 +620,65 @@ void list_sched(const be_irg_t *birg, be_options_t *be_opts)
        DEL_ARR_F(env.sched_info);
 }
 
-#ifdef WITH_LIBCORE
+/* List schedule a block. */
+void list_sched_single_block(const be_irg_t *birg, ir_node *block, be_options_t *be_opts)
+{
+       const arch_env_t *arch_env = birg->main_env->arch_env;
+       ir_graph         *irg      = birg->irg;
+
+       int num_nodes;
+       sched_env_t env;
+       list_sched_selector_t sel;
+
+       /* Select a scheduler based on backend options */
+       switch (list_sched_options.select) {
+               case BE_SCHED_SELECT_TRIVIAL:
+                       memcpy(&sel, trivial_selector, sizeof(sel));
+                       break;
+               case BE_SCHED_SELECT_RANDOM:
+                       memcpy(&sel, random_selector, sizeof(sel));
+                       break;
+               case BE_SCHED_SELECT_REGPRESS:
+                       memcpy(&sel, reg_pressure_selector, sizeof(sel));
+                       break;
+               case BE_SCHED_SELECT_MUCHNIK:
+                       memcpy(&sel, muchnik_selector, sizeof(sel));
+                       break;
+               case BE_SCHED_SELECT_HEUR:
+                       memcpy(&sel, heuristic_selector, sizeof(sel));
+                       break;
+               case BE_SCHED_SELECT_HMUCHNIK:
+               default:
+                       memcpy(&sel, trivial_selector, sizeof(sel));
+       }
+
+       /* Assure, that the out edges are computed */
+       edges_deactivate(birg->irg);
+       edges_activate(birg->irg);
+
+       num_nodes = get_irg_last_idx(irg);
+
+       /* initialize environment for list scheduler */
+       memset(&env, 0, sizeof(env));
+       env.selector   = arch_env->isa->impl->get_list_sched_selector(arch_env->isa, &sel);
+       env.arch_env   = arch_env;
+       env.irg        = irg;
+       env.sched_info = NEW_ARR_F(sched_irn_t, num_nodes);
+
+       memset(env.sched_info, 0, num_nodes * sizeof(env.sched_info[0]));
+
+       if (env.selector->init_graph)
+               env.selector_env = env.selector->init_graph(env.selector, arch_env, irg);
+
+       /* Schedule block. */
+       list_sched_block(block, &env);
+
+       if (env.selector->finish_graph)
+               env.selector->finish_graph(env.selector_env);
+
+       DEL_ARR_F(env.sched_info);
+}
+
 /**
  * Register list scheduler options.
  */
@@ -636,4 +690,3 @@ void be_init_listsched(void) {
 }
 
 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_listsched);
-#endif /* WITH_LIBCORE */