- All backend modules use module constructors for registering their options now
authorMatthias Braun <matze@braunis.de>
Thu, 21 Dec 2006 14:55:08 +0000 (14:55 +0000)
committerMatthias Braun <matze@braunis.de>
Thu, 21 Dec 2006 14:55:08 +0000 (14:55 +0000)
- New register allocator modules can register themselfes in a list now,
the same will be done for spillers, copy coalescers, architectures soon

38 files changed:
ir/be/TEMPLATE/bearch_TEMPLATE.c
ir/be/arm/arm_emitter.c
ir/be/arm/bearch_arm.c
ir/be/arm/bearch_arm_t.h
ir/be/be.h
ir/be/bearch.h
ir/be/beblocksched.c
ir/be/beblocksched.h
ir/be/bechordal.h
ir/be/bechordal_main.c
ir/be/becopyheur2.c
ir/be/becopyheur3.c
ir/be/becopyilp.c
ir/be/becopyopt.c
ir/be/becopyopt.h
ir/be/becopystat.c
ir/be/becopystat.h
ir/be/beilpsched.c
ir/be/bejavacoal.c
ir/be/belistsched.c
ir/be/bemain.c
ir/be/bemodule.c
ir/be/bemodule.h
ir/be/bera.c
ir/be/bera.h
ir/be/beraextern.c
ir/be/beraextern.h
ir/be/besched.c
ir/be/besched_t.h
ir/be/beschedrss.c
ir/be/bespillbelady.c
ir/be/bespilloptions.c
ir/be/bespilloptions.h
ir/be/bespillremat.c
ir/be/ia32/bearch_ia32.c
ir/be/ia32/ia32_optimize.c
ir/be/mips/bearch_mips.c
ir/be/ppc32/bearch_ppc32.c

index f8904bb..08f77cb 100644 (file)
@@ -21,6 +21,7 @@
 #include "../besched_t.h"
 #include "../be.h"
 #include "../beabi.h"
+#include "../bemodule.h"
 
 #include "bearch_TEMPLATE_t.h"
 
@@ -585,11 +586,10 @@ static const backend_params *TEMPLATE_get_libfirm_params(void) {
        return &p;
 }
 
-#ifdef WITH_LIBCORE
-static void TEMPLATE_register_options(lc_opt_entry_t *ent)
+void be_init_arch_TEMPLATE()
 {
 }
-#endif /* WITH_LIBCORE */
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_TEMPLATE);
 
 const arch_isa_if_t TEMPLATE_isa_if = {
        TEMPLATE_init,
@@ -603,7 +603,4 @@ const arch_isa_if_t TEMPLATE_isa_if = {
        TEMPLATE_get_list_sched_selector,
        TEMPLATE_get_reg_class_alignment,
     TEMPLATE_get_libfirm_params,
-#ifdef WITH_LIBCORE
-       TEMPLATE_register_options
-#endif
 };
index 770bef5..f346a30 100644 (file)
@@ -19,6 +19,7 @@
 #include "irargs_t.h"
 
 #include "../besched.h"
+#include "../beblocksched.h"
 
 #include "arm_emitter.h"
 #include "gen_arm_emitter.h"
@@ -951,7 +952,7 @@ void arm_gen_routine(FILE *F, ir_graph *irg, const arm_code_gen_t *cg) {
        arm_register_emitters();
 
        /* create the block schedule. For now, we don't need it earlier. */
-       blk_sched = sched_create_block_schedule(cg->irg, cg->birg->exec_freq);
+       blk_sched = be_create_block_schedule(cg->irg, cg->birg->exec_freq);
 
        arm_emit_start(F, irg);
        irg_block_walk_graph(irg, arm_gen_labels, NULL, &emit_env);
index 943e7da..824a188 100644 (file)
@@ -29,6 +29,7 @@
 #include "../beabi.h"
 #include "../bemachine.h"
 #include "../beilpsched.h"
+#include "../bemodule.h"
 
 #include "bearch_arm_t.h"
 
@@ -1148,11 +1149,14 @@ static const lc_opt_table_entry_t arm_options[] = {
  * arm-fpuunit=unit     select the floating point unit
  * arm-gen_reg_names    use generic register names instead of SP, LR, PC
  */
-static void arm_register_options(lc_opt_entry_t *ent)
+void be_init_arch_arm(void)
 {
-       lc_opt_entry_t *be_grp_arm = lc_opt_get_grp(ent, "arm");
-       lc_opt_add_table(be_grp_arm, arm_options);
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *arm_grp = lc_opt_get_grp(be_grp, "arm");
+
+       lc_opt_add_table(arm_grp, arm_options);
 }
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_arm);
 #endif /* WITH_LIBCORE */
 
 const arch_isa_if_t arm_isa_if = {
@@ -1170,7 +1174,4 @@ const arch_isa_if_t arm_isa_if = {
        arm_get_libfirm_params,
        arm_get_allowed_execution_units,
        arm_get_machine,
-#ifdef WITH_LIBCORE
-       arm_register_options
-#endif
 };
index 7091dea..16e54fa 100644 (file)
@@ -132,7 +132,7 @@ struct _arm_isa_t {
        arm_code_gen_t        *cg;            /**< current code generator */
        FILE                  *out;           /**< output file */
 
-       unsigned               fpu_arch;      /**< FPU architecture */
+       int                   fpu_arch;      /**< FPU architecture */
 };
 
 
index efab423..3b6fecd 100644 (file)
@@ -8,6 +8,12 @@
 #include "dbginfo.h"
 #include "ifconv.h"
 
+#ifdef WITH_LIBCORE
+#include <libcore/lc_opts.h>
+#include <libcore/lc_opts_enum.h>
+#include <libcore/lc_timing.h>
+#endif /* WITH_LIBCORE */
+
 #define LC_STOP_AND_RESET_TIMER(timer) do { lc_timer_stop(timer); lc_timer_reset(timer); } while(0)
 
 /**
index 08b6600..c1387fc 100644 (file)
@@ -736,14 +736,6 @@ struct _arch_isa_if_t {
         * @param self  The isa object.
         */
        const be_machine_t *(*get_machine)(const void *self);
-
-#ifdef WITH_LIBCORE
-       /**
-        * Register command line options for this backend.
-        * @param grp  The root group.
-        */
-       void (*register_options)(lc_opt_entry_t *grp);
-#endif
 };
 
 #define arch_isa_get_n_reg_class(isa)                  ((isa)->impl->get_n_reg_class(isa))
index e97b183..704d33d 100644 (file)
@@ -25,6 +25,8 @@
 #include "irtools.h"
 #include "debug.h"
 #include "beirgmod.h"
+#include "bemodule.h"
+#include "be.h"
 
 #ifdef WITH_LIBCORE
 #include <libcore/lc_opts.h>
@@ -696,22 +698,15 @@ static ir_node **create_extbb_block_schedule(ir_graph *irg, ir_exec_freq *execfr
  * |_|  |_|\__,_|_|_| |_|
  *
  */
-
-#ifdef WITH_LIBCORE
-void be_block_schedule_register_options(lc_opt_entry_t *grp)
+void be_init_blocksched(void)
 {
-       static int     run_once = 0;
-       lc_opt_entry_t *blocksched_grp;
-
-       if (run_once)
-               return;
-
-       run_once       = 1;
-       blocksched_grp = lc_opt_get_grp(grp, "blocksched");
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *blocksched_grp = lc_opt_get_grp(be_grp, "blocksched");
 
        lc_opt_add_table(blocksched_grp, be_blocksched_options);
 }
-#endif /* WITH_LIBCORE */
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_blocksched);
 
 ir_node **be_create_block_schedule(ir_graph *irg, ir_exec_freq *execfreqs)
 {
index 2ff6902..1e7d9f6 100644 (file)
@@ -15,9 +15,4 @@
 
 ir_node **be_create_block_schedule(ir_graph *irg, ir_exec_freq *execfreqs);
 
-#ifdef WITH_LIBCORE
-#include <libcore/lc_opts.h>
-void be_block_schedule_register_options(lc_opt_entry_t *grp);
-#endif /* WITH_LIBCORE */
-
 #endif /* _BEBLOCKSCHED_H */
index 4cb7396..a9c4296 100644 (file)
 #include "bearch.h"
 #include "bera.h"
 
-/**
- * The register allocator structure.
- */
-extern const be_ra_t be_ra_chordal_allocator;
-
 typedef struct _be_chordal_env_t be_chordal_env_t;
 
 #endif
index 451efff..39755ed 100644 (file)
@@ -57,6 +57,7 @@
 #include "benode_t.h"
 #include "bestatevent.h"
 #include "bestat.h"
+#include "bemodule.h"
 
 #include "bespillbelady.h"
 #include "bespillmorgan.h"
@@ -94,7 +95,6 @@ typedef struct _post_spill_env_t {
        double           pre_spill_cost;
 } post_spill_env_t;
 
-#ifdef WITH_LIBCORE
 static be_ra_timer_t ra_timer = {
        NULL,
        NULL,
@@ -110,8 +110,8 @@ static be_ra_timer_t ra_timer = {
 };
 
 static const lc_opt_enum_int_items_t spill_items[] = {
-       { "morgan", BE_CH_SPILL_MORGAN },
        { "belady", BE_CH_SPILL_BELADY },
+       { "morgan", BE_CH_SPILL_MORGAN },
 #ifdef WITH_ILP
        { "remat",  BE_CH_SPILL_REMAT },
 #endif /* WITH_ILP */
@@ -191,8 +191,6 @@ static const lc_opt_table_entry_t be_chordal_options[] = {
        { NULL }
 };
 
-extern void be_spill_remat_register_options(lc_opt_entry_t *ent);
-
 void be_ra_chordal_check(be_chordal_env_t *chordal_env) {
        const arch_env_t *arch_env = chordal_env->birg->main_env->arch_env;
        struct obstack ob;
@@ -243,28 +241,6 @@ int nodes_interfere(const be_chordal_env_t *env, const ir_node *a, const ir_node
                return values_interfere(env->birg->lv, a, b);
 }
 
-static void be_ra_chordal_register_options(lc_opt_entry_t *grp)
-{
-       static int run_once = 0;
-       lc_opt_entry_t *chordal_grp;
-
-       if (! run_once) {
-               run_once    = 1;
-               chordal_grp = lc_opt_get_grp(grp, "chordal");
-
-               lc_opt_add_table(chordal_grp, be_chordal_options);
-
-               co_register_options(chordal_grp);
-#ifdef WITH_JVM
-               be_java_coal_register_options(chordal_grp);
-#endif
-#ifdef WITH_ILP
-               be_spill_remat_register_options(chordal_grp);
-#endif
-       }
-}
-#endif /* WITH_LIBCORE */
-
 static void dump(unsigned mask, ir_graph *irg,
                                 const arch_register_class_t *cls,
                                 const char *suffix,
@@ -706,7 +682,7 @@ static void post_spill(post_spill_env_t *pse) {
  * @param birg  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(be_irg_t *birg)
+static void be_ra_chordal_main(be_irg_t *birg)
 {
        const be_main_env_t *main_env  = birg->main_env;
        const arch_isa_t    *isa       = arch_env_get_isa(main_env->arch_env);
@@ -821,17 +797,22 @@ static be_ra_timer_t *be_ra_chordal_main(be_irg_t *birg)
 
        be_stat_ev("insns_after", count_insns(irg));
 
-#ifdef WITH_LIBCORE
-       return main_opts->timing == BE_TIME_ON ? &ra_timer : NULL;
-#endif /* WITH_LIBCORE */
-       return NULL;
+       return;
 }
 
-const be_ra_t be_ra_chordal_allocator = {
-#ifdef WITH_LIBCORE
-       be_ra_chordal_register_options,
-#else
-       NULL,
-#endif
+static be_ra_t be_ra_chordal_allocator = {
        be_ra_chordal_main,
 };
+
+void be_init_chordal(void)
+{
+       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");
+
+       lc_opt_add_table(chordal_grp, be_chordal_options);
+
+       be_register_allocator("chordal", &be_ra_chordal_allocator);
+}
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_chordal);
index 3b9b3bc..1653a2d 100644 (file)
@@ -30,6 +30,7 @@
 #include "irprintf.h"
 #include "irtools.h"
 
+#include "bemodule.h"
 #include "beabi.h"
 #include "benode_t.h"
 #include "becopyopt.h"
@@ -69,11 +70,17 @@ static const lc_opt_table_entry_t options[] = {
        { NULL }
 };
 
-void be_co2_register_options(lc_opt_entry_t *grp)
+void be_init_copyheur2(void)
 {
-       lc_opt_entry_t *co2_grp = lc_opt_get_grp(grp, "co2");
+       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");
+       lc_opt_entry_t *co2_grp = lc_opt_get_grp(chordal_grp, "co2");
+
        lc_opt_add_table(co2_grp, options);
 }
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copyheur2);
 #endif
 
 /*
index 9ee2a9c..d8a452b 100644 (file)
@@ -31,6 +31,7 @@
 #include "irprintf.h"
 #include "irtools.h"
 
+#include "bemodule.h"
 #include "beabi.h"
 #include "benode_t.h"
 #include "becopyopt.h"
@@ -66,13 +67,18 @@ static const lc_opt_table_entry_t options[] = {
        { NULL }
 };
 
-void be_co3_register_options(lc_opt_entry_t *grp)
+void be_init_copyheur3(void)
 {
-       lc_opt_entry_t *co3_grp = lc_opt_get_grp(grp, "co3");
+       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");
+       lc_opt_entry_t *co3_grp = lc_opt_get_grp(chordal_grp, "co3");
+
        lc_opt_add_table(co3_grp, options);
 }
-#endif
 
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copyheur3);
+#endif
 
 static void set_admissible_regs(be_java_coal_t *coal, copy_opt_t *co, ir_node *irn, int t_idx, int *col_map)
 {
index 883ce50..fcd1dba 100644 (file)
@@ -45,11 +45,18 @@ static const lc_opt_table_entry_t options[] = {
        { NULL }
 };
 
-void be_co_ilp_register_options(lc_opt_entry_t *grp)
+void be_init_copyilp(void)
 {
-       lc_opt_entry_t *ilp_grp = lc_opt_get_grp(grp, "ilp");
+       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");
+       lc_opt_entry_t *co_grp = lc_opt_get_grp(chordal_grp, "co");
+       lc_opt_entry_t *ilp_grp = lc_opt_get_grp(co_grp, "ilp");
+
        lc_opt_add_table(ilp_grp, options);
 }
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copyilp);
 #endif /* WITH_LIBCORE */
 
 
index 4760342..80440cd 100644 (file)
@@ -29,7 +29,7 @@
 #include "irphase_t.h"
 #include "irprintf_t.h"
 
-
+#include "bemodule.h"
 #include "bearch.h"
 #include "benode_t.h"
 #include "beutil.h"
@@ -136,17 +136,17 @@ extern void be_co_ilp_register_options(lc_opt_entry_t *grp);
 extern void be_co2_register_options(lc_opt_entry_t *grp);
 extern void be_co3_register_options(lc_opt_entry_t *grp);
 
-void co_register_options(lc_opt_entry_t *grp)
+void be_init_copycoal(void)
 {
-       lc_opt_entry_t *co_grp = lc_opt_get_grp(grp, "co");
-       lc_opt_add_table(co_grp, options);
+       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");
+       lc_opt_entry_t *co_grp = lc_opt_get_grp(chordal_grp, "co");
 
-       be_co2_register_options(co_grp);
-       be_co3_register_options(co_grp);
-#ifdef WITH_ILP
-       be_co_ilp_register_options(co_grp);
-#endif
+       lc_opt_add_table(co_grp, options);
 }
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copycoal);
 #endif
 
 
@@ -165,9 +165,6 @@ void co_register_options(lc_opt_entry_t *grp)
 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
 
 
-void be_copy_opt_init(void) {
-}
-
 copy_opt_t *new_copy_opt(be_chordal_env_t *chordal_env, cost_fct_t get_costs)
 {
        const char *s1, *s2, *s3;
index 7e11ba3..0ef10ca 100644 (file)
@@ -48,11 +48,6 @@ enum {
 /** The driver for copy minimization. */
 void co_driver(be_chordal_env_t *cenv);
 
-/**
- * Has to be called during the firm init phase
- */
-void be_copy_opt_init(void);
-
 typedef struct _copy_opt_t copy_opt_t;
 
 typedef int(*cost_fct_t)(const copy_opt_t *, ir_node*, ir_node*, int);
index 4d59f2b..fc1df4e 100644 (file)
@@ -22,6 +22,7 @@
 #include "becopyopt_t.h"
 #include "becopystat.h"
 #include "beirg_t.h"
+#include "bemodule.h"
 
 #define DEBUG_LVL SET_LEVEL_1
 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
@@ -94,24 +95,26 @@ static pset *all_phi_classes;
 static pset *all_copy_nodes;
 static ir_graph *last_irg;
 
-void copystat_init(void) {
+void be_init_copystat(void) {
        FIRM_DBG_REGISTER(dbg, "firm.be.copystat");
 
        all_phi_nodes   = pset_new_ptr_default();
        all_phi_classes = pset_new_ptr_default();
        all_copy_nodes  = pset_new_ptr_default();
+       memset(curr_vals, 0, sizeof(curr_vals));
 }
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copystat);
 
-void copystat_reset(void) {
-       int i;
-       for (i = 0; i < ASIZE; ++i)
-               curr_vals[i] = 0;
+void be_quit_copystat(void) {
        del_pset(all_phi_nodes);
        del_pset(all_phi_classes);
        del_pset(all_copy_nodes);
-       all_phi_nodes = pset_new_ptr_default();
-       all_phi_classes = pset_new_ptr_default();
-       all_copy_nodes = pset_new_ptr_default();
+}
+BE_REGISTER_MODULE_DESTRUCTOR(be_quit_copystat);
+
+void copystat_reset(void) {
+       be_quit_copystat();
+       be_init_copystat();
 }
 
 /**
index dd8438e..a71d81a 100644 (file)
@@ -13,8 +13,6 @@
 #include "bearch.h"
 #include "bechordal_t.h"
 
-void copystat_init(void);
-void copystat_reset(void);
 void copystat_collect_cls(be_chordal_env_t *chordal_env);
 void copystat_add_max_costs(int costs);
 void copystat_add_inevit_costs(int costs);
index 730f4c2..4065e95 100644 (file)
@@ -1891,16 +1891,12 @@ void be_ilp_sched(const be_irg_t *birg) {
 /**
  * Register ILP scheduler options.
  */
-void ilpsched_register_options(lc_opt_entry_t *grp) {
-       static int     run_once = 0;
-       lc_opt_entry_t *sched_grp;
-
-       if (! run_once) {
-               run_once  = 1;
-               sched_grp = lc_opt_get_grp(grp, "ilpsched");
+void be_init_ilpsched(void)
+{
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *sched_grp = lc_opt_get_grp(be_grp, "ilpsched");
 
-               lc_opt_add_table(sched_grp, ilpsched_option_table);
-       }
+       lc_opt_add_table(sched_grp, ilpsched_option_table);
 }
 #endif /* WITH_LIBCORE */
 
index a8282f4..82a2e24 100644 (file)
@@ -43,11 +43,16 @@ static const lc_opt_table_entry_t options[] = {
        { NULL }
 };
 
-void be_java_coal_register_options(lc_opt_entry_t *grp)
+void be_init_javacoal(void)
 {
+       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");
        lc_opt_entry_t *jc_grp = lc_opt_get_grp(grp, "jc");
        lc_opt_add_table(jc_grp, options);
 }
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_javacoal);
 #endif /* WITH_LIBCORE */
 
 #include <jni.h>
@@ -463,5 +468,4 @@ void be_java_coal_start_jvm(void)
 {
 }
 
-
 #endif /* WITH_JVM */
index 680fb1e..498cf28 100644 (file)
@@ -32,6 +32,7 @@
 #include "debug.h"
 #include "irtools.h"
 
+#include "bemodule.h"
 #include "besched_t.h"
 #include "beutil.h"
 #include "belive_t.h"
@@ -622,16 +623,12 @@ void list_sched(const be_irg_t *birg, be_options_t *be_opts)
 /**
  * Register list scheduler options.
  */
-void list_sched_register_options(lc_opt_entry_t *grp) {
-       static int     run_once = 0;
-       lc_opt_entry_t *sched_grp;
+void be_init_listsched(void) {
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *sched_grp = lc_opt_get_grp(be_grp, "listsched");
 
-       if (! run_once) {
-               run_once  = 1;
-               sched_grp = lc_opt_get_grp(grp, "listsched");
-
-               lc_opt_add_table(sched_grp, list_sched_option_table);
-               rss_register_options(sched_grp);
-       }
+       lc_opt_add_table(sched_grp, list_sched_option_table);
 }
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_listsched);
 #endif /* WITH_LIBCORE */
index 81e731e..bfc6e0e 100644 (file)
@@ -42,9 +42,9 @@
 #include "arm/bearch_arm.h"
 #include "ppc32/bearch_ppc32.h"
 #include "mips/bearch_mips.h"
-// #include "sta/bearch_sta.h"
 
 #include "be_t.h"
+#include "bemodule.h"
 #include "beutil.h"
 #include "benode_t.h"
 #include "beirgmod.h"
@@ -90,15 +90,13 @@ static be_options_t be_options = {
 static char config_file[256] = { 0 };
 
 /* register allocator to use. */
-static const be_ra_t *ra = &be_ra_chordal_allocator;
+//static const be_ra_t *ra = &be_ra_chordal_allocator;
 
 /* back end instruction set architecture to use */
 static const arch_isa_if_t *isa_if = &ia32_isa_if;
 
 #ifdef WITH_LIBCORE
 
-static lc_opt_entry_t *be_grp_root = NULL;
-
 /* possible dumping options */
 static const lc_opt_enum_mask_items_t dump_items[] = {
        { "none",       DUMP_NONE },
@@ -113,13 +111,6 @@ static const lc_opt_enum_mask_items_t dump_items[] = {
        { NULL,         0 }
 };
 
-/* register allocators */
-static const lc_opt_enum_const_ptr_items_t ra_items[] = {
-       { "chordal",  &be_ra_chordal_allocator },
-       { "external", &be_ra_external_allocator },
-       { NULL,      NULL }
-};
-
 /* instruction set architectures. */
 static const lc_opt_enum_const_ptr_items_t isa_items[] = {
        { "ia32",    &ia32_isa_if },
@@ -153,10 +144,6 @@ static lc_opt_enum_mask_var_t dump_var = {
        &be_options.dump_flags, dump_items
 };
 
-static lc_opt_enum_const_ptr_var_t ra_var = {
-       (const void **) &ra, ra_items
-};
-
 static lc_opt_enum_const_ptr_var_t isa_var = {
        (const void **) &isa_if, isa_items
 };
@@ -172,7 +159,6 @@ static lc_opt_enum_int_var_t sched_var = {
 static const lc_opt_table_entry_t be_main_options[] = {
        LC_OPT_ENT_STR      ("config",   "read another config file containing backend options", config_file, sizeof(config_file)),
        LC_OPT_ENT_ENUM_MASK("dump",     "dump irg on several occasions",                       &dump_var),
-       LC_OPT_ENT_ENUM_PTR ("ra",       "register allocator",                                  &ra_var),
        LC_OPT_ENT_ENUM_PTR ("isa",      "the instruction set architecture",                    &isa_var),
        LC_OPT_ENT_NEGBOOL  ("noomitfp", "do not omit frame pointer",                           &be_options.omit_fp),
        LC_OPT_ENT_BOOL     ("stabs",    "enable stabs debug support",                          &be_options.stabs_debug_support),
@@ -194,50 +180,30 @@ static const lc_opt_table_entry_t be_main_options[] = {
 void be_opt_register(void)
 {
 #ifdef WITH_LIBCORE
-       int i;
-       lc_opt_entry_t *be_grp_ra;
+       lc_opt_entry_t *be_grp;
        static int run_once = 0;
 
-       if (! run_once) {
-               run_once     = 1;
-               be_grp_root  = lc_opt_get_grp(firm_opt_get_root(), "be");
-               be_grp_ra    = lc_opt_get_grp(be_grp_root, "ra");
-
-               lc_opt_add_table(be_grp_root, be_main_options);
-
-               /* register allocator options */
-               for(i = 0; ra_items[i].name != NULL; ++i) {
-                       const be_ra_t *ra = ra_items[i].value;
-                       ra->register_options(be_grp_ra);
-               }
-
-               /* register isa options */
-               for(i = 0; isa_items[i].name != NULL; ++i) {
-                       const arch_isa_if_t *isa = isa_items[i].value;
-                       isa->register_options(be_grp_root);
-               }
+       if (run_once) {
+               return;
+       }
+       run_once     = 1;
 
-               /* list scheduler register options */
-               list_sched_register_options(be_grp_root);
+       be_init_modules();
 
-#ifdef WITH_ILP
-               /* ilp scheduler register options */
-               ilpsched_register_options(be_grp_root);
-#endif /* WITH_ILP */
-
-               be_block_schedule_register_options(be_grp_root);
-       }
+       be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_add_table(be_grp, be_main_options);
 #endif /* WITH_LIBCORE */
 }
 
 /* Parse one argument. */
 int be_parse_arg(const char *arg) {
 #ifdef WITH_LIBCORE
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
        if (strcmp(arg, "help") == 0 || (arg[0] == '?' && arg[1] == '\0')) {
-               lc_opt_print_help(be_grp_root, stdout);
+               lc_opt_print_help(be_grp, stdout);
                return -1;
        }
-       return lc_opt_from_single_arg(be_grp_root, NULL, arg, NULL);
+       return lc_opt_from_single_arg(be_grp, NULL, arg, NULL);
 #else
        return 0;
 #endif /* WITH_LIBCORE */
@@ -265,10 +231,7 @@ static void be_sched_vrfy(ir_graph *irg, int vrfy_opt) {
 const backend_params *be_init(void)
 {
        be_opt_register();
-
-       be_sched_init();
-       be_copy_opt_init();
-       copystat_init();
+       be_init_modules();
        phi_class_init();
 
        if (isa_if->get_params)
@@ -663,7 +626,7 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
 
                /* Do register allocation */
                BE_TIMER_PUSH(t_regalloc);
-               ra_timer = ra->allocate(birg);
+               //ra_timer = ra->allocate(birg);
                BE_TIMER_POP(t_regalloc);
 
 #ifdef FIRM_STATISTICS
index 64473f6..32c1f61 100644 (file)
@@ -78,12 +78,14 @@ void be_quit_modules(void)
 
 //---------------------------------------------------------------------------
 
+#ifdef WITH_LIBCORE
 typedef struct module_opt_data_t {
        void **var;
-       const be_module_list_entry_t * const *list_head;
+       be_module_list_entry_t * const *list_head;
 } module_opt_data_t;
 
-static int set_opt_module(const char *name, lc_opt_type_t type, void *data, size_t length, ...)
+static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
+                          size_t length, ...)
 {
        module_opt_data_t *moddata = data;
        va_list args;
@@ -159,7 +161,7 @@ void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
 
 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
                             const char *description,
-                            const be_module_list_entry_t * const * list_head,
+                            be_module_list_entry_t * const * list_head,
                             void **var)
 {
        module_opt_data_t *moddata = xmalloc(sizeof(moddata[0]));
@@ -171,3 +173,5 @@ void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
                       set_opt_module, dump_opt_module, dump_opt_module_vals,
                                   NULL);
 }
+
+#endif
index 659e5f7..dfa67c5 100644 (file)
@@ -43,7 +43,8 @@ void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
 
 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
                             const char *description,
-                            const be_module_list_entry_t * const * first, void **var);
+                            be_module_list_entry_t * const * first,
+                            void **var);
 
 #endif
 
index 2178ec7..3525d7f 100644 (file)
@@ -7,6 +7,8 @@
 #include "config.h"
 #endif
 
+#include <stdlib.h>
+
 #include "pset.h"
 #include "impl.h"
 
 #include "irmode.h"
 #include "irdom.h"
 
+#include "bera.h"
 #include "beutil.h"
 #include "besched_t.h"
 #include "belive_t.h"
+#include "bemodule.h"
 
 static sched_timestep_t get_time_step(const ir_node *irn)
 {
@@ -102,6 +106,27 @@ int values_interfere(const be_lv_t *lv, const ir_node *a, const ir_node *b)
                        if(get_nodes_block(user) == bb && !is_Phi(user) && b != user && value_dominates(b, user))
                                return 1;
                }
-  }
-  return 0;
+       }
+
+       return 0;
+}
+
+/** The list of register allocators */
+static be_module_list_entry_t *register_allocators = NULL;
+static be_ra_t *selected_allocator = NULL;
+
+void be_register_allocator(const char *name, be_ra_t *allocator)
+{
+       if(selected_allocator == NULL)
+               selected_allocator = allocator;
+       be_add_module_to_list(&register_allocators, name, allocator);
+}
+
+void be_init_ra(void)
+{
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+
+       be_add_module_list_opt(be_grp, "regalloc", "register allocator",
+                              &register_allocators, (void**) &selected_allocator);
 }
+BE_REGISTER_MODULE_CONSTRUCTOR(init_be_ra);
index 1b83e76..1ca7f64 100644 (file)
@@ -10,7 +10,6 @@
 #include "firm_config.h"
 
 #ifdef WITH_LIBCORE
-#include <libcore/lc_opts.h>
 #include <libcore/lc_timing.h>
 #endif
 
@@ -19,6 +18,7 @@
 #include "be.h"
 #include "belive.h"
 #include "beirg.h"
+#include "bemodule.h"
 
 #ifdef WITH_LIBCORE
 
@@ -40,11 +40,16 @@ typedef void *be_ra_timer_t;
 typedef void *lc_opt_entry_t;
 #endif  /* WITH_LIBCORE */
 
-typedef struct {
-       void (*register_options)(lc_opt_entry_t *grp);
-       be_ra_timer_t *(*allocate)(be_irg_t *bi);
+typedef struct be_ra_t {
+       void (*allocate)(be_irg_t *bi);   /**< allocate registers on a graph */
 } be_ra_t;
 
+void be_register_allocator(const char *name, be_ra_t *allocator);
+
+/**
+ * Do register allocation with currently selected register allocator
+ */
+void be_allocate_registers(be_irg_t *birg);
 
 /**
  * Check, if two values interfere.
index fc6a5a1..09cc290 100644 (file)
@@ -86,6 +86,7 @@ alloc         ::= node-nr reg-nr .
 #include "irdom_t.h"
 #include "phiclass.h"
 
+#include "bemodule.h"
 #include "beraextern.h"
 #include "beabi.h"
 #include "bearch.h"
@@ -704,7 +705,7 @@ static char callee[128] = "\"E:/user/kimohoff/public/register allocator\"";
  * Read in results and apply them
  *
  */
-static be_ra_timer_t *be_ra_extern_main(be_irg_t *birg) {
+static void be_ra_extern_main(be_irg_t *birg) {
        be_main_env_t *env = birg->main_env;
        ir_graph *irg = birg->irg;
 
@@ -770,8 +771,6 @@ static be_ra_timer_t *be_ra_extern_main(be_irg_t *birg) {
        free_ssa_destr_simple(raenv.vars);
 
        be_invalidate_liveness(birg);
-
-       return NULL;
 }
 
 /******************************************************************************
@@ -805,17 +804,19 @@ static const lc_opt_table_entry_t be_ra_extern_options[] = {
        { NULL }
 };
 
-static void be_ra_extern_register_options(lc_opt_entry_t *root) {
-       lc_opt_entry_t *grp = lc_opt_get_grp(root, "ext");
+static be_ra_t be_ra_external_allocator = {
+       be_ra_extern_main
+};
+
+void be_init_raextern(void) {
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *blocksched_grp = lc_opt_get_grp(be_grp, "ra");
+       lc_opt_entry_t *ext_grp = lc_opt_get_grp(blocksched_grp, "ext");
+
+       lc_opt_add_table(ext_grp, be_ra_extern_options);
 
-       lc_opt_add_table(grp, be_ra_extern_options);
+       be_register_allocator("ext", &be_ra_external_allocator);
 }
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_raextern);
 
 #endif /* WITH_LIBCORE */
-
-const be_ra_t be_ra_external_allocator = {
-#ifdef WITH_LIBCORE
-       be_ra_extern_register_options,
-#endif
-       be_ra_extern_main
-};
index 84d8be3..850678c 100644 (file)
@@ -12,6 +12,4 @@
 
 #include "bera.h"
 
-extern const be_ra_t be_ra_external_allocator;
-
 #endif
index beb3885..64a2cb7 100644 (file)
@@ -18,6 +18,7 @@
 #include "irextbb.h"
 #include "debug.h"
 
+#include "bemodule.h"
 #include "bearch.h"
 #include "besched_t.h"
 #include "beutil.h"
@@ -57,11 +58,13 @@ void be_sched_dump(FILE *f, ir_graph *irg)
 }
 
 /* Init the scheduling stuff. */
-void be_sched_init(void)
+void be_init_sched(void)
 {
        sched_irn_data_offset = register_additional_node_data(sizeof(sched_info_t));
 }
 
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched);
+
 void sched_renumber(const ir_node *block)
 {
        ir_node *irn;
index d23ce3a..f0d82b8 100644 (file)
@@ -34,12 +34,6 @@ typedef struct _sched_info_t {
 #define get_irn_sched_info(irn) get_irn_data(irn, sched_info_t, sched_irn_data_offset)
 #define get_sched_info_irn(sched_info) get_irn_data_base(sched_info, sched_irn_data_offset)
 
-/**
- * Init the scheduling stuff.
- * To be called from the central backend initialization routine.
- */
-void be_sched_init(void);
-
 /**
  * Check, if the node is scheduled.
  * @param irn The node.
index 11f9d7b..f8d54ed 100644 (file)
@@ -34,6 +34,7 @@
 #include "height.h"
 
 #include "beabi.h"
+#include "bemodule.h"
 #include "benode_t.h"
 #include "besched_t.h"
 
@@ -2075,17 +2076,15 @@ static void process_block(ir_node *block, void *env) {
 /**
  * Register the options.
  */
-void rss_register_options(lc_opt_entry_t *grp) {
-       static int     run_once = 0;
-       lc_opt_entry_t *rss_grp;
+void be_init_schedrss(void) {
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *sched_grp = lc_opt_get_grp(be_grp, "sched");
+       lc_opt_entry_t *rss_grp = lc_opt_get_grp(sched_grp, "rss");
 
-       if (! run_once) {
-               run_once = 1;
-               rss_grp  = lc_opt_get_grp(grp, "rss");
-
-               lc_opt_add_table(rss_grp, rss_option_table);
-       }
+       lc_opt_add_table(rss_grp, rss_option_table);
 }
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_schedrss);
 #endif /* WITH_LIBCORE */
 
 /**
index 91ef2cd..fde941c 100644 (file)
@@ -697,6 +697,8 @@ void be_spill_belady_spill_env(const be_chordal_env_t *chordal_env, spill_env_t
        FIRM_DBG_REGISTER(dbg, "firm.be.spill.belady");
        //firm_dbg_set_mask(dbg, DBG_SPILL);
 
+       be_assure_liveness(chordal_env->birg);
+
        /* init belady env */
        obstack_init(&env.ob);
        env.cenv      = chordal_env;
index 488323c..581a8df 100644 (file)
@@ -8,35 +8,31 @@
 #include "config.h"
 #endif
 
+#include "irtools.h"
+
 #include "bespilloptions.h"
+#include "bemodule.h"
+#include "be.h"
 
-#ifdef WITH_LIBCORE
 #include <libcore/lc_opts.h>
 #include <libcore/lc_opts_enum.h>
 #include <libcore/lc_timing.h>
-#endif /* WITH_LIBCORE */
 
 int be_coalesce_spill_slots = 1;
 int be_do_remats = 1;
 
-#ifdef WITH_LIBCORE
 static const lc_opt_table_entry_t be_spill_options[] = {
        LC_OPT_ENT_BOOL ("coalesce_slots", "coalesce the spill slots", &be_coalesce_spill_slots),
        LC_OPT_ENT_BOOL ("remat", "try to rematerialize values instead of reloading", &be_do_remats),
        { NULL }
 };
 
-void be_spill_register_options(lc_opt_entry_t *grp)
+void be_init_spill(void)
 {
-       static int     run_once = 0;
-       lc_opt_entry_t *spill_grp;
-
-       if (run_once)
-               return;
-
-       run_once       = 1;
-       spill_grp = lc_opt_get_grp(grp, "spill");
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *spill_grp = lc_opt_get_grp(be_grp, "spill");
 
        lc_opt_add_table(spill_grp, be_spill_options);
 }
-#endif /* WITH_LIBCORE */
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spill);
index 1f1e383..53fbe9b 100644 (file)
@@ -10,9 +10,4 @@
 extern int be_coalesce_spill_slots;
 extern int be_do_remats;
 
-#ifdef WITH_LIBCORE
-#include <libcore/lc_opts.h>
-void be_spill_register_options(lc_opt_entry_t *grp);
-#endif
-
 #endif
index f4abb19..f4216c3 100644 (file)
@@ -157,11 +157,17 @@ static const lc_opt_table_entry_t options[] = {
        { NULL }
 };
 
-void be_spill_remat_register_options(lc_opt_entry_t *grp)
+void be_init_spillremat(void)
 {
-       lc_opt_entry_t *my_grp = lc_opt_get_grp(grp, "remat");
-       lc_opt_add_table(my_grp, options);
+       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");
+       lc_opt_entry_t *remat_grp = lc_opt_get_grp(chordal_grp, "remat");
+
+       lc_opt_add_table(remat_grp, options);
 }
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillremat);
 #endif
 
 
index 3148224..8c525e5 100644 (file)
@@ -48,6 +48,7 @@
 #include "../bemachine.h"
 #include "../beilpsched.h"
 #include "../bespillslots.h"
+#include "../bemodule.h"
 
 #include "bearch_ia32_t.h"
 
@@ -1996,11 +1997,14 @@ static const lc_opt_table_entry_t ia32_options[] = {
  * ia32-nopushargs   do not create pushs for function argument passing
  * ia32-gasmode      set the GAS compatibility mode
  */
-static void ia32_register_options(lc_opt_entry_t *ent)
+void be_init_arch_ia32(void)
 {
-       lc_opt_entry_t *be_grp_ia32 = lc_opt_get_grp(ent, "ia32");
-       lc_opt_add_table(be_grp_ia32, ia32_options);
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *ia32_grp = lc_opt_get_grp(be_grp, "ia32");
+
+       lc_opt_add_table(ia32_grp, ia32_options);
 }
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_ia32);
 #endif /* WITH_LIBCORE */
 
 const arch_isa_if_t ia32_isa_if = {
@@ -2018,7 +2022,4 @@ const arch_isa_if_t ia32_isa_if = {
        ia32_get_libfirm_params,
        ia32_get_allowed_execution_units,
        ia32_get_machine,
-#ifdef WITH_LIBCORE
-       ia32_register_options
-#endif
 };
index 0b3cfc6..5a9f979 100644 (file)
@@ -4,7 +4,7 @@
  * Purpose:     Implements several optimizations for IA32
  * Author:      Christian Wuerdig
  * CVS-ID:      $Id$
- * Copyright:   (c) 2006 Universitรคt Karlsruhe
+ * Copyright:   (c) 2006 Universitaet Karlsruhe
  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
  */
 
index cf90a80..f03afaa 100644 (file)
@@ -27,6 +27,7 @@
 #include "../be.h"
 #include "../beabi.h"
 #include "../bemachine.h"
+#include "../bemodule.h"
 
 #include "bearch_mips_t.h"
 
@@ -969,9 +970,10 @@ static const backend_params *mips_get_libfirm_params(void) {
 }
 
 #ifdef WITH_LIBCORE
-static void mips_register_options(lc_opt_entry_t *ent)
+void be_init_arch_mips(void)
 {
 }
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_mips);
 #endif /* WITH_LIBCORE */
 
 const arch_isa_if_t mips_isa_if = {
@@ -989,7 +991,4 @@ const arch_isa_if_t mips_isa_if = {
        mips_get_libfirm_params,
        mips_get_allowed_execution_units,
        mips_get_machine,
-#ifdef WITH_LIBCORE
-       mips_register_options
-#endif
 };
index f4ae6f4..43f4f28 100644 (file)
@@ -23,6 +23,8 @@
 #include "../be.h"
 #include "../beabi.h"
 #include "../bemachine.h"
+#include "../bemodule.h"
+#include "../beblocksched.h"
 
 #include "pset.h"
 
@@ -471,7 +473,7 @@ static void ppc32_before_sched(void *self) {
  */
 static void ppc32_before_ra(void *self) {
        ppc32_code_gen_t *cg = self;
-       cg->blk_sched = sched_create_block_schedule(cg->irg, cg->birg->exec_freq);
+       cg->blk_sched = be_create_block_schedule(cg->irg, cg->birg->exec_freq);
 }
 
 static void ppc32_transform_spill(ir_node *node, void *env)
@@ -906,11 +908,10 @@ static const backend_params *ppc32_get_libfirm_params(void) {
        return &p;
 }
 
-#ifdef WITH_LIBCORE
-static void ppc32_register_options(lc_opt_entry_t *ent)
+void be_init_arch_ppc32(void)
 {
 }
-#endif /* WITH_LIBCORE */
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_ppc32);
 
 const arch_isa_if_t ppc32_isa_if = {
        ppc32_init,
@@ -927,7 +928,4 @@ const arch_isa_if_t ppc32_isa_if = {
        ppc32_get_libfirm_params,
        ppc32_get_allowed_execution_units,
        ppc32_get_machine,
-#ifdef WITH_LIBCORE
-       ppc32_register_options
-#endif
 };