cleanup driver interface a bit
authorMatthias Braun <matze@braunis.de>
Fri, 18 Nov 2011 16:16:29 +0000 (17:16 +0100)
committerMatthias Braun <matze@braunis.de>
Fri, 18 Nov 2011 17:11:41 +0000 (18:11 +0100)
driver/firm_opt.c
driver/firm_opt.h
libfirm
main.c

index 08ec2c8..2ea1dec 100644 (file)
@@ -35,7 +35,6 @@ struct a_firm_opt {
        int      clone_threshold; /**< The threshold value for procedure cloning. */
        unsigned inline_maxsize;  /**< Maximum function size for inlining. */
        unsigned inline_threshold;/**< Inlining benefice threshold. */
-       bool     verify_edges;    /**< verify edges */
 };
 
 /** statistic options */
@@ -52,8 +51,6 @@ typedef enum a_firmstat_selection_tag {
 struct a_firm_dump {
        bool debug_print;   /**< enable debug print */
        bool all_types;     /**< dump the All_types graph */
-       bool no_blocks;     /**< dump non-blocked graph */
-       bool extbb;         /**< dumps extended basic blocks */
        bool ir_graph;      /**< dump all graphs */
        bool all_phases;    /**< dump the IR graph after all phases */
        bool statistic;     /**< Firm statistic setting */
@@ -82,15 +79,12 @@ static struct a_firm_opt firm_opt = {
        .clone_threshold  =  DEFAULT_CLONE_THRESHOLD,
        .inline_maxsize   =  750,
        .inline_threshold =  0,
-       .verify_edges     =  false,
 };
 
 /* dumping options */
 static struct a_firm_dump firm_dump = {
        .debug_print  = false,
        .all_types    = false,
-       .no_blocks    = false,
-       .extbb        = false,
        .ir_graph     = false,
        .all_phases   = false,
        .statistic    = STAT_NONE,
@@ -138,14 +132,10 @@ static const struct params {
   { X("verify-report"),          &firm_opt.verify,           FIRM_VERIFICATION_REPORT, "node verification, report only" },
   { X("check-all"),              &firm_opt.check_all,        1, "enable checking all Firm phases" },
   { X("no-check-all"),           &firm_opt.check_all,        0, "disable checking all Firm phases" },
-  { X("verify-edges-on"),        &firm_opt.verify_edges,     1, "enable out edge verification" },
-  { X("verify-edges-off"),       &firm_opt.verify_edges,     0, "disable out edge verification" },
 
   /* dumping */
   { X("dump-ir"),                &firm_dump.ir_graph,        1, "dump IR graph" },
   { X("dump-all-types"),         &firm_dump.all_types,       1, "dump graph of all types" },
-  { X("dump-no-blocks"),         &firm_dump.no_blocks,       1, "dump non-blocked graph" },
-  { X("dump-extbb"),             &firm_dump.extbb,           1, "dump extended basic blocks" },
   { X("dump-all-phases"),        &firm_dump.all_phases,      1, "dump graphs for all optimization phases" },
   { X("dump-filter=<string>"),   NULL,                       0, "set dumper filter" },
 
@@ -164,6 +154,7 @@ static const struct params {
 static ir_timer_t *t_vcg_dump;
 static ir_timer_t *t_verify;
 static ir_timer_t *t_all_opt;
+static ir_timer_t *t_backend;
 static bool do_irg_opt(ir_graph *irg, const char *name);
 
 /** dump all the graphs depending on cond */
@@ -722,7 +713,8 @@ static void do_firm_lowering(const char *input_filename)
  */
 void gen_firm_init(void)
 {
-       unsigned pattern = 0;
+       ir_init();
+       enable_safe_defaults();
 
        FOR_EACH_OPT(i) {
                i->timer = ir_timer_new();
@@ -734,6 +726,13 @@ void gen_firm_init(void)
        timer_register(t_vcg_dump, "Firm: vcg dumping");
        t_all_opt = ir_timer_new();
        timer_register(t_all_opt, "Firm: all optimizations");
+       t_backend = ir_timer_new();
+       timer_register(t_backend, "Firm: backend");
+}
+
+static void init_statistics(void)
+{
+       unsigned pattern = 0;
 
        if (firm_dump.stat_pattern)
                pattern |= FIRMSTAT_PATTERN_ENABLED;
@@ -744,29 +743,6 @@ void gen_firm_init(void)
        firm_init_stat(firm_dump.statistic == STAT_NONE ?
                        0 : FIRMSTAT_ENABLED | FIRMSTAT_COUNT_STRONG_OP
                        | FIRMSTAT_COUNT_CONSTS | pattern);
-
-       edges_init_dbg(firm_opt.verify_edges);
-
-       /* Sel node cannot produce NULL pointers */
-       set_opt_sel_based_null_check_elim(1);
-
-       /* dynamic dispatch works currently only if whole world scenarios */
-       set_opt_dyn_meth_dispatch(0);
-
-       /* do not run architecture dependent optimizations in building phase */
-       arch_dep_set_opts(arch_dep_none);
-
-       do_node_verification((firm_verification_t) firm_opt.verify);
-       if (firm_dump.extbb)
-               ir_add_dump_flags(ir_dump_flag_group_extbb);
-       if (firm_dump.no_blocks)
-               ir_remove_dump_flags(ir_dump_flag_blocks_as_subgraphs);
-
-       set_optimize(1);
-       set_opt_constant_folding(firm_opt.const_folding);
-       set_opt_algebraic_simplification(firm_opt.const_folding);
-       set_opt_cse(firm_opt.cse);
-       set_opt_global_cse(0);
 }
 
 /**
@@ -775,15 +751,23 @@ void gen_firm_init(void)
  *
  * @param out                a file handle for the output, may be NULL
  * @param input_filename     the name of the (main) source file
- * @param c_mode             non-zero if "C" was compiled
  */
-void gen_firm_finish(FILE *out, const char *input_filename)
+void generate_code(FILE *out, const char *input_filename)
 {
        int i;
 
+       set_optimize(1);
+       set_opt_constant_folding(firm_opt.const_folding);
+       set_opt_algebraic_simplification(firm_opt.const_folding);
+       set_opt_cse(firm_opt.cse);
+       set_opt_global_cse(0);
+
+       init_statistics();
+
+       do_node_verification((firm_verification_t) firm_opt.verify);
+
        /* the general for dumping option must be set, or the others will not work*/
-       firm_dump.ir_graph
-               = (bool) (firm_dump.ir_graph | firm_dump.all_phases | firm_dump.extbb);
+       firm_dump.ir_graph = (bool) (firm_dump.ir_graph | firm_dump.all_phases);
 
        ir_add_dump_flags(ir_dump_flag_keepalive_edges
                        | ir_dump_flag_consts_local | ir_dump_flag_dominance);
@@ -796,11 +780,6 @@ void gen_firm_finish(FILE *out, const char *input_filename)
                dump_ir_prog_ext(dump_typegraph, "types.vcg");
        }
 
-       /* finalize all graphs */
-       for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
-               ir_graph *irg = get_irp_irg(i);
-               irg_finalize_cons(irg);
-       }
        dump_all("");
 
        timer_push(t_verify);
@@ -831,16 +810,19 @@ void gen_firm_finish(FILE *out, const char *input_filename)
                stat_dump_snapshot(input_filename, "final-ir");
 
        /* run the code generator */
-       ir_timer_t *timer = ir_timer_new();
-       timer_register(timer, "Firm: backend");
-       timer_start(timer);
+       timer_start(t_backend);
        be_main(out, input_filename);
-       timer_stop(timer);
+       timer_stop(t_backend);
 
        if (firm_dump.statistic & STAT_FINAL)
                stat_dump_snapshot(input_filename, "final");
 }
 
+void gen_firm_finish(void)
+{
+       ir_finish();
+}
+
 static void disable_all_opts(void)
 {
        firm_opt.cse             = false;
@@ -985,14 +967,3 @@ void choose_optimization_pack(int level)
                break;
        }
 }
-
-/**
- * Do very early initializations
- */
-void firm_early_init(void)
-{
-       /* arg: need this here for command line options */
-       ir_init();
-
-       enable_safe_defaults();
-}
index 9f3516f..6b5f05f 100644 (file)
@@ -96,11 +96,16 @@ extern ir_entity_ptr rts_entities[rts_max];
 /** Initialize for the Firm-generating back end. */
 void gen_firm_init(void);
 
-/** called, after the Firm generation is completed. */
-void gen_firm_finish(FILE *out, const char *input_filename);
-
-/** early initialization. */
-void firm_early_init(void);
+/** free resources hold by firm-generating back end */
+void gen_firm_finish(void);
+
+/**
+ * Transform, optimize and generate code
+ *
+ * @param out                a file handle for the output, may be NULL
+ * @param input_filename     the name of the (main) source file
+ */
+void generate_code(FILE *out, const char *input_filename);
 
 /** process optimization commandline option */
 int firm_option(const char *opt);
diff --git a/libfirm b/libfirm
index bd092bd..a390c5a 160000 (submodule)
--- a/libfirm
+++ b/libfirm
@@ -1 +1 @@
-Subproject commit bd092bd1f52df17d8317a2e16b9e9e2dc9b8bed6
+Subproject commit a390c5a73dd626c0f6456ab665c418c5949f3eb0
diff --git a/main.c b/main.c
index 369e5e6..1de0dba 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1045,8 +1045,6 @@ static void init_types_and_adjust(void)
 
 int main(int argc, char **argv)
 {
-       firm_early_init();
-
        const char        *dumpfunction         = NULL;
        const char        *print_file_name_file = NULL;
        compile_mode_t     mode                 = CompileAssembleLink;
@@ -1095,6 +1093,9 @@ int main(int argc, char **argv)
 
 #define SINGLE_OPTION(ch) (option[0] == (ch) && option[1] == '\0')
 
+       /* initialize this early because it has to parse options */
+       gen_firm_init();
+
        /* early options parsing (find out optimization level and OS) */
        for (int i = 1; i < argc; ++i) {
                const char *arg = argv[i];
@@ -1659,7 +1660,6 @@ int main(int argc, char **argv)
                set_be_option("profileuse");
        }
 
-       gen_firm_init();
        init_symbol_table();
        init_types_and_adjust();
        init_typehash();
@@ -1951,7 +1951,7 @@ graph_built:
                                return EXIT_SUCCESS;
                        }
 
-                       gen_firm_finish(asm_out, filename);
+                       generate_code(asm_out, filename);
                        if (asm_out != out) {
                                fclose(asm_out);
                        }
@@ -2065,6 +2065,7 @@ graph_built:
        obstack_free(&asflags_obst, NULL);
        obstack_free(&file_obst, NULL);
 
+       gen_firm_finish();
        exit_mangle();
        exit_ast2firm();
        exit_parser();