adapted to new callback
[libfirm] / ir / be / bechordal_main.c
index 4afa70c..e8ae60d 100644 (file)
@@ -4,7 +4,7 @@
  * @author Sebastian Hack
  * @cvs-id $Id$
  *
- * Copyright (C) 2005 Universitaet Karlsruhe
+ * Copyright (C) 2005-2006 Universitaet Karlsruhe
  * Released under the GPL
  *
  * Driver for the chordal register allocator.
@@ -26,6 +26,7 @@
 #include <libcore/lc_timing.h>
 #endif /* WITH_LIBCORE */
 
+#include "ircons_t.h"
 #include "irmode_t.h"
 #include "irgraph_t.h"
 #include "irprintf_t.h"
@@ -129,6 +130,13 @@ static be_ra_chordal_opts_t options = {
        BE_CH_VRFY_WARN,
 };
 
+/** Enable extreme live range splitting. */
+static int be_elr_split = 0;
+
+/** Assumed loop iteration count for execution frequency estimation. */
+static int be_loop_weight = 9;
+
+#ifdef WITH_LIBCORE
 static be_ra_timer_t ra_timer = {
        NULL,
        NULL,
@@ -143,7 +151,6 @@ static be_ra_timer_t ra_timer = {
        NULL,
 };
 
-#ifdef WITH_LIBCORE
 static const lc_opt_enum_int_items_t spill_items[] = {
        { "morgan", BE_CH_SPILL_MORGAN },
        { "belady", BE_CH_SPILL_BELADY },
@@ -215,12 +222,6 @@ static lc_opt_enum_int_var_t be_ch_vrfy_var = {
        &options.vrfy_option, be_ch_vrfy_items
 };
 
-/** Enable extreme live range splitting. */
-static int be_elr_split = 0;
-
-/** Assumed loop iteration count for execution frequency estimation. */
-static int be_loop_weight = 9;
-
 static const lc_opt_table_entry_t be_chordal_options[] = {
        LC_OPT_ENT_ENUM_INT ("spill",         "spill method (belady, morgan or remat)", &spill_var),
        LC_OPT_ENT_ENUM_PTR ("ifg",           "interference graph flavour (std, fast, clique, pointer, list, check)", &ifg_flavor_var),
@@ -232,6 +233,9 @@ static const lc_opt_table_entry_t be_chordal_options[] = {
        { NULL }
 };
 
+extern void be_spill_remat_register_options(lc_opt_entry_t *ent);
+
+
 static void be_ra_chordal_register_options(lc_opt_entry_t *grp)
 {
        static int run_once = 0;
@@ -242,10 +246,13 @@ static void be_ra_chordal_register_options(lc_opt_entry_t *grp)
                chordal_grp = lc_opt_get_grp(grp, "chordal");
 
                lc_opt_add_table(chordal_grp, be_chordal_options);
-       }
 
-       co_register_options(chordal_grp);
-       be_java_coal_register_options(chordal_grp);
+               co_register_options(chordal_grp);
+               be_java_coal_register_options(chordal_grp);
+#ifdef WITH_ILP
+               be_spill_remat_register_options(chordal_grp);
+#endif
+       }
 }
 #endif /* WITH_LIBCORE */
 
@@ -323,10 +330,16 @@ static void memory_operand_walker(ir_node *irn, void *env) {
        const arch_env_t *aenv = cenv->birg->main_env->arch_env;
        const ir_edge_t  *edge, *ne;
        ir_node          *block;
+       ir_node          *spill;
 
        if (! be_is_Reload(irn))
                return;
 
+       // only use memory operands, if the reload is only used by 1 node
+       if(get_irn_n_edges(irn) > 1)
+               return;
+
+       spill = be_get_Reload_mem(irn);
        block = get_nodes_block(irn);
 
        foreach_out_edge_safe(irn, edge, ne) {
@@ -338,7 +351,7 @@ static void memory_operand_walker(ir_node *irn, void *env) {
 
                if (get_nodes_block(src) == block && arch_possible_memory_operand(aenv, src, pos)) {
                        DBG((cenv->dbg, LEVEL_3, "performing memory operand %+F at %+F\n", irn, src));
-                       arch_perform_memory_operand(aenv, src, irn, pos);
+                       arch_perform_memory_operand(aenv, src, spill, pos);
                }
        }
 
@@ -357,23 +370,12 @@ static INLINE void check_for_memory_operands(be_chordal_env_t *chordal_env) {
        irg_walk_graph(chordal_env->irg, NULL, memory_operand_walker, chordal_env);
 }
 
+#ifdef WITH_LIBCORE
 /**
- * Performs chordal register allocation for each register class on given irg.
- *
- * @param bi  Backend irg object
- * @return Structure containing timer for the single phases or NULL if no timing requested.
+ * Initialize all timers.
  */
-static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
+static void be_init_timer(be_options_t *main_opts)
 {
-       const be_main_env_t *main_env  = bi->main_env;
-       const arch_isa_t    *isa       = arch_env_get_isa(main_env->arch_env);
-       ir_graph            *irg       = bi->irg;
-       be_options_t        *main_opts = main_env->options;
-       int                  splitted  = 0;
-
-       int j, m;
-       be_chordal_env_t chordal_env;
-
        if (main_opts->timing == BE_TIME_ON) {
                ra_timer.t_prolog  = lc_timer_register("ra_prolog",   "regalloc prolog");
                ra_timer.t_epilog  = lc_timer_register("ra_epilog",   "regalloc epilog");
@@ -399,15 +401,19 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
                LC_STOP_AND_RESET_TIMER(ra_timer.t_verify);
                LC_STOP_AND_RESET_TIMER(ra_timer.t_other);
        }
+}
 
-#define BE_TIMER_PUSH(timer)                                                        \
-       if (main_opts->timing == BE_TIME_ON) {                                          \
-               int res = lc_timer_push(timer);                                             \
-               if (options.vrfy_option == BE_CH_VRFY_ASSERT)                               \
-                       assert(res && "Timer already on stack, cannot be pushed twice.");       \
-               else if (options.vrfy_option == BE_CH_VRFY_WARN && ! res)                   \
-                       fprintf(stderr, "Timer %s already on stack, cannot be pushed twice.\n", \
-                               lc_timer_get_name(timer));                                          \
+#define BE_TIMER_INIT(main_opts)       be_init_timer(main_opts)
+
+#define BE_TIMER_PUSH(timer)                                                            \
+       if (main_opts->timing == BE_TIME_ON) {                                              \
+               if (! lc_timer_push(timer)) {                                                   \
+                       if (options.vrfy_option == BE_CH_VRFY_ASSERT)                               \
+                               assert(!"Timer already on stack, cannot be pushed twice.");             \
+                       else if (options.vrfy_option == BE_CH_VRFY_WARN)                            \
+                               fprintf(stderr, "Timer %s already on stack, cannot be pushed twice.\n", \
+                                       lc_timer_get_name(timer));                                          \
+               }                                                                               \
        }
 #define BE_TIMER_POP(timer)                                                                    \
        if (main_opts->timing == BE_TIME_ON) {                                                     \
@@ -419,7 +425,32 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
                                lc_timer_get_name(tmp), lc_timer_get_name(timer));                             \
                timer = tmp;                                                                           \
        }
+#else
 
+#define BE_TIMER_INIT(main_opts)
+#define BE_TIMER_PUSH(timer)
+#define BE_TIMER_POP(timer)
+
+#endif /* WITH_LIBCORE */
+
+/**
+ * Performs chordal register allocation for each register class on given irg.
+ *
+ * @param bi  Backend irg object
+ * @return Structure containing timer for the single phases or NULL if no timing requested.
+ */
+static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
+{
+       const be_main_env_t *main_env  = bi->main_env;
+       const arch_isa_t    *isa       = arch_env_get_isa(main_env->arch_env);
+       ir_graph            *irg       = bi->irg;
+       be_options_t        *main_opts = main_env->options;
+       int                  splitted  = 0;
+
+       int j, m;
+       be_chordal_env_t chordal_env;
+
+       BE_TIMER_INIT(main_opts);
        BE_TIMER_PUSH(ra_timer.t_other);
        BE_TIMER_PUSH(ra_timer.t_prolog);
 
@@ -483,7 +514,9 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
                    );
 
                dump(BE_CH_DUMP_SPILL, irg, chordal_env.cls, "-spill", dump_ir_block_graph_sched);
+
                check_for_memory_operands(&chordal_env);
+
                be_abi_fix_stack_nodes(bi->abi, chordal_env.lv);
 
                BE_TIMER_PUSH(ra_timer.t_verify);
@@ -491,11 +524,11 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
                /* verify schedule and register pressure */
                if (options.vrfy_option == BE_CH_VRFY_WARN) {
                        be_verify_schedule(irg);
-                       be_verify_register_pressure(chordal_env.birg->main_env->arch_env, chordal_env.cls, irg);
+                       be_verify_register_pressure(chordal_env.birg, chordal_env.cls, irg);
                }
                else if (options.vrfy_option == BE_CH_VRFY_ASSERT) {
                        assert(be_verify_schedule(irg) && "Schedule verification failed");
-                       assert(be_verify_register_pressure(chordal_env.birg->main_env->arch_env, chordal_env.cls, irg)
+                       assert(be_verify_register_pressure(chordal_env.birg, chordal_env.cls, irg)
                                && "Register pressure verification failed");
                }
                BE_TIMER_POP(ra_timer.t_verify);
@@ -589,10 +622,10 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
 
        /* verify spillslots */
        if (options.vrfy_option == BE_CH_VRFY_WARN) {
-               be_verify_spillslots(irg);
+               be_verify_spillslots(main_env->arch_env, irg);
        }
        else if (options.vrfy_option == BE_CH_VRFY_ASSERT) {
-               assert(be_verify_spillslots(irg) && "Spillslot verification failed");
+               assert(be_verify_spillslots(main_env->arch_env, irg) && "Spillslot verification failed");
        }
        BE_TIMER_POP(ra_timer.t_verify);
 
@@ -609,29 +642,19 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
        free_execfreq(chordal_env.exec_freq);
 
        BE_TIMER_POP(ra_timer.t_epilog);
-
-       BE_TIMER_PUSH(ra_timer.t_verify);
-
-       /* verify spillslots */
-       if (options.vrfy_option == BE_CH_VRFY_WARN) {
-               be_verify_schedule(irg);
-       }
-       else if (options.vrfy_option == BE_CH_VRFY_ASSERT) {
-               assert(be_verify_schedule(irg) && "Schedule verification failed");
-       }
-       BE_TIMER_POP(ra_timer.t_verify);
-
        BE_TIMER_POP(ra_timer.t_other);
 
-#undef BE_TIMER_PUSH
-#undef BE_TIMER_POP
-
+#ifdef WITH_LIBCORE
        return main_opts->timing == BE_TIME_ON ? &ra_timer : NULL;
+#endif /* WITH_LIBCORE */
+       return NULL;
 }
 
 const be_ra_t be_ra_chordal_allocator = {
 #ifdef WITH_LIBCORE
        be_ra_chordal_register_options,
-#endif
        be_ra_chordal_main
+#else
+       0
+#endif
 };