Implement binary emitter for LdTls.
[libfirm] / ir / be / bechordal_main.c
index ca525a0..a367495 100644 (file)
@@ -24,9 +24,7 @@
  * @date        29.11.2005
  * @version     $Id$
  */
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include <stdlib.h>
 #include <time.h>
 #include "beabi.h"
 #include "beutil.h"
 #include "besched.h"
-#include "besched_t.h"
+#include "besched.h"
 #include "belive_t.h"
-#include "bearch_t.h"
+#include "bearch.h"
 #include "beifg_t.h"
 #include "beifg_impl.h"
-#include "benode_t.h"
+#include "benode.h"
 #include "bestatevent.h"
 #include "bestat.h"
 #include "bemodule.h"
 #include "be_t.h"
 #include "bera.h"
-#include "beirg_t.h"
+#include "beirg.h"
 
 #include "bespillslots.h"
-#include "bespilloptions.h"
+#include "bespill.h"
 #include "belower.h"
 
 #include "becopystat.h"
 #include "becopyopt.h"
 #include "bessadestr.h"
 #include "beverify.h"
-#include "benode_t.h"
+#include "benode.h"
 
 static be_ra_chordal_opts_t options = {
        BE_CH_DUMP_NONE,
@@ -98,8 +96,6 @@ typedef struct _post_spill_env_t {
        double                      pre_spill_cost;
 } post_spill_env_t;
 
-static be_options_t  *main_opts;
-
 static const lc_opt_enum_int_items_t lower_perm_items[] = {
        { "copy", BE_CH_LOWER_PERM_COPY },
        { "swap", BE_CH_LOWER_PERM_SWAP },
@@ -148,7 +144,7 @@ static lc_opt_enum_int_var_t be_ch_vrfy_var = {
 static const lc_opt_table_entry_t be_chordal_options[] = {
        LC_OPT_ENT_ENUM_PTR ("perm",          "perm lowering options", &lower_perm_var),
        LC_OPT_ENT_ENUM_MASK("dump",          "select dump phases", &dump_var),
-       LC_OPT_ENT_ENUM_PTR ("vrfy",          "verify options", &be_ch_vrfy_var),
+       LC_OPT_ENT_ENUM_PTR ("verify",        "verify options", &be_ch_vrfy_var),
        LC_OPT_LAST
 };
 
@@ -211,7 +207,7 @@ static void memory_operand_walker(ir_node *irn, void *env)
 /**
  * Starts a walk for memory operands if supported by the backend.
  */
-static INLINE void check_for_memory_operands(ir_graph *irg)
+void check_for_memory_operands(ir_graph *irg)
 {
        irg_walk_graph(irg, NULL, memory_operand_walker, NULL);
 }
@@ -227,7 +223,6 @@ static void pre_spill(post_spill_env_t *pse, const arch_register_class_t *cls)
        be_chordal_env_t    *chordal_env = &pse->cenv;
        be_irg_t            *birg        = pse->birg;
        ir_graph            *irg         = be_get_birg_irg(birg);
-       const be_main_env_t *main_env    = birg->main_env;
 
        pse->cls                   = cls;
        chordal_env->cls           = cls;
@@ -237,13 +232,13 @@ static void pre_spill(post_spill_env_t *pse, const arch_register_class_t *cls)
        be_assure_liveness(birg);
        be_liveness_assure_chk(be_get_birg_liveness(birg));
 
-       stat_ev_do(pse->pre_spill_cost = be_estimate_irg_costs(irg, main_env->arch_env, birg->exec_freq));
+       stat_ev_do(pse->pre_spill_cost = be_estimate_irg_costs(irg, birg->exec_freq));
 
        /* put all ignore registers into the ignore register set. */
        be_put_ignore_regs(birg, pse->cls, chordal_env->ignore_colors);
 
        BE_TIMER_PUSH(t_ra_constr);
-       be_pre_spill_prepare_constr(chordal_env);
+       be_pre_spill_prepare_constr(chordal_env->birg, chordal_env->cls);
        BE_TIMER_POP(t_ra_constr);
 
        dump(BE_CH_DUMP_CONSTR, birg->irg, pse->cls, "-constr-pre", dump_ir_block_graph_sched);
@@ -256,13 +251,12 @@ static void post_spill(post_spill_env_t *pse, int iteration) {
        be_chordal_env_t    *chordal_env = &pse->cenv;
        be_irg_t            *birg        = pse->birg;
        ir_graph            *irg         = birg->irg;
-       const be_main_env_t *main_env    = birg->main_env;
-       int                  colors_n     = arch_register_class_n_regs(chordal_env->cls);
+       int                  colors_n    = arch_register_class_n_regs(chordal_env->cls);
        int             allocatable_regs = colors_n - be_put_ignore_regs(birg, chordal_env->cls, NULL);
 
        /* some special classes contain only ignore regs, no work to be done */
        if (allocatable_regs > 0) {
-               stat_ev_dbl("bechordal_spillcosts", be_estimate_irg_costs(irg, main_env->arch_env, birg->exec_freq) - pse->pre_spill_cost);
+               stat_ev_dbl("bechordal_spillcosts", be_estimate_irg_costs(irg, birg->exec_freq) - pse->pre_spill_cost);
 
                /*
                        If we have a backend provided spiller, post spill is
@@ -276,9 +270,9 @@ static void post_spill(post_spill_env_t *pse, int iteration) {
                }
                BE_TIMER_POP(t_ra_spill_apply);
 
-               BE_TIMER_PUSH(t_verify);
 
                /* verify schedule and register pressure */
+               BE_TIMER_PUSH(t_verify);
                if (chordal_env->opts->vrfy_option == BE_CH_VRFY_WARN) {
                        be_verify_schedule(birg);
                        be_verify_register_pressure(birg, pse->cls, irg);
@@ -357,14 +351,12 @@ static void post_spill(post_spill_env_t *pse, int iteration) {
  */
 static void be_ra_chordal_main(be_irg_t *birg)
 {
-       const be_main_env_t *main_env = birg->main_env;
-       const arch_env_t    *arch_env = main_env->arch_env;
-       ir_graph            *irg      = birg->irg;
-       int                 j, m;
-       be_chordal_env_t    chordal_env;
-       struct obstack      obst;
-
-       main_opts = main_env->options;
+       const arch_env_t *arch_env = birg->main_env->arch_env;
+       ir_graph         *irg      = birg->irg;
+       int               j;
+       int               m;
+       be_chordal_env_t  chordal_env;
+       struct obstack    obst;
 
        BE_TIMER_PUSH(t_ra_other);
 
@@ -437,7 +429,7 @@ static void be_ra_chordal_main(be_irg_t *birg)
                /* the backend has its own spiller */
                m = arch_env_get_n_reg_class(arch_env);
 
-               pse = alloca(m * sizeof(pse[0]));
+               pse = ALLOCAN(post_spill_env_t, m);
 
                for (j = 0; j < m; ++j) {
                        memcpy(&pse[j].cenv, &chordal_env, sizeof(chordal_env));
@@ -456,7 +448,12 @@ static void be_ra_chordal_main(be_irg_t *birg)
        }
 
        BE_TIMER_PUSH(t_verify);
-       be_verify_register_allocation(birg);
+       if (chordal_env.opts->vrfy_option == BE_CH_VRFY_WARN) {
+               be_verify_register_allocation(birg);
+       } else if(chordal_env.opts->vrfy_option == BE_CH_VRFY_ASSERT) {
+               assert(be_verify_register_allocation(birg)
+                               && "Register allocation invalid");
+       }
        BE_TIMER_POP(t_verify);
 
        BE_TIMER_PUSH(t_ra_epilog);
@@ -470,12 +467,12 @@ static void be_ra_chordal_main(be_irg_t *birg)
        BE_TIMER_POP(t_ra_other);
 }
 
-static be_ra_t be_ra_chordal_allocator = {
-       be_ra_chordal_main,
-};
-
 void be_init_chordal_main(void)
 {
+       static be_ra_t be_ra_chordal_allocator = {
+               be_ra_chordal_main,
+       };
+
        lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
        lc_opt_entry_t *ra_grp = lc_opt_get_grp(be_grp, "ra");
        lc_opt_entry_t *chordal_grp = lc_opt_get_grp(ra_grp, "chordal");