fixed precedence constraint
[libfirm] / ir / be / belistsched.c
index 8d911ad..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.
@@ -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 */