remove arch_irn_class_is macro as it hides usages of arch_irn_class_XXX from grep...
[libfirm] / ir / be / bechordal_main.c
index 80cebc1..6461dd5 100644 (file)
@@ -53,6 +53,7 @@
 #include "debug.h"
 #include "execfreq.h"
 #include "iredges_t.h"
+#include "error.h"
 
 #include "bechordal_t.h"
 #include "beabi.h"
@@ -70,6 +71,7 @@
 #include "be_t.h"
 #include "bera.h"
 #include "beirg.h"
+#include "bedump_minir.h"
 
 #include "bespillslots.h"
 #include "bespill.h"
@@ -143,10 +145,13 @@ static lc_opt_enum_int_var_t be_ch_vrfy_var = {
        &options.vrfy_option, be_ch_vrfy_items
 };
 
+static char minir_file[256] = "";
+
 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 ("verify",        "verify options", &be_ch_vrfy_var),
+       LC_OPT_ENT_STR      ("minirout",      "dump MinIR to file", minir_file, sizeof(minir_file)),
        LC_OPT_LAST
 };
 
@@ -161,21 +166,20 @@ void be_register_chordal_coloring(const char *name, be_ra_chordal_coloring_t *co
        be_add_module_to_list(&colorings, name, coloring);
 }
 
-void be_ra_chordal_coloring(be_chordal_env_t *env)
+static void be_ra_chordal_coloring(be_chordal_env_t *env)
 {
        assert(selected_coloring != NULL);
-       if(selected_coloring != NULL) {
+       if (selected_coloring != NULL) {
                selected_coloring->allocate(env);
        }
 }
 
-
 static void dump(unsigned mask, ir_graph *irg,
                                 const arch_register_class_t *cls,
                                 const char *suffix,
                                 void (*dump_func)(ir_graph *, const char *))
 {
-       if((options.dump_flags & mask) == mask) {
+       if ((options.dump_flags & mask) == mask) {
                if (cls) {
                        char buf[256];
                        snprintf(buf, sizeof(buf), "-%s%s", cls->name, suffix);
@@ -201,7 +205,7 @@ static void memory_operand_walker(ir_node *irn, void *env)
                return;
 
        /* only use memory operands, if the reload is only used by 1 node */
-       if(get_irn_n_edges(irn) > 1)
+       if (get_irn_n_edges(irn) > 1)
                return;
 
        spill = be_get_Reload_mem(irn);
@@ -269,7 +273,8 @@ static void pre_spill(post_spill_env_t *pse, const arch_register_class_t *cls)
 /**
  * Perform things which need to be done per register class after spilling.
  */
-static void post_spill(post_spill_env_t *pse, int iteration) {
+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;
@@ -336,6 +341,22 @@ static void post_spill(post_spill_env_t *pse, int iteration) {
                }
 
                be_timer_push(T_RA_COPYMIN);
+               if (minir_file[0] != '\0') {
+                       FILE *out;
+
+                       if (strcmp(minir_file, "-") == 0) {
+                               out = stdout;
+                       } else {
+                               out = fopen(minir_file, "w");
+                               if (out == NULL) {
+                                       panic("Cound't open minir output '%s'", minir_file);
+                               }
+                       }
+
+                       be_export_minir(chordal_env->birg->main_env->arch_env, out, irg);
+                       if (out != stdout)
+                               fclose(out);
+               }
                co_driver(chordal_env);
                be_timer_pop(T_RA_COPYMIN);
 
@@ -409,7 +430,7 @@ static void be_ra_chordal_main(be_irg_t *birg)
                        const arch_register_class_t *cls
                                = arch_env_get_reg_class(arch_env, j);
 
-                       if(arch_register_class_flags(cls) & arch_register_class_flag_manual_ra)
+                       if (arch_register_class_flags(cls) & arch_register_class_flag_manual_ra)
                                continue;
 
 
@@ -470,7 +491,7 @@ static void be_ra_chordal_main(be_irg_t *birg)
        be_timer_push(T_VERIFY);
        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) {
+       } else if (chordal_env.opts->vrfy_option == BE_CH_VRFY_ASSERT) {
                assert(be_verify_register_allocation(birg)
                                && "Register allocation invalid");
        }
@@ -487,6 +508,7 @@ static void be_ra_chordal_main(be_irg_t *birg)
        be_timer_pop(T_RA_OTHER);
 }
 
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_chordal_main);
 void be_init_chordal_main(void)
 {
        static be_ra_t be_ra_chordal_allocator = {
@@ -502,5 +524,3 @@ void be_init_chordal_main(void)
        lc_opt_add_table(chordal_grp, be_chordal_options);
        be_add_module_list_opt(chordal_grp, "coloring", "select coloring methode", &colorings, (void**) &selected_coloring);
 }
-
-BE_REGISTER_MODULE_CONSTRUCTOR(be_init_chordal_main);