From: Matthias Braun Date: Thu, 21 Dec 2006 14:55:08 +0000 (+0000) Subject: - All backend modules use module constructors for registering their options now X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=da48a7f7266cfe6274fc4d159d63bba245724222;p=libfirm - All backend modules use module constructors for registering their options now - New register allocator modules can register themselfes in a list now, the same will be done for spillers, copy coalescers, architectures soon --- diff --git a/ir/be/TEMPLATE/bearch_TEMPLATE.c b/ir/be/TEMPLATE/bearch_TEMPLATE.c index f8904bb93..08f77cb00 100644 --- a/ir/be/TEMPLATE/bearch_TEMPLATE.c +++ b/ir/be/TEMPLATE/bearch_TEMPLATE.c @@ -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 }; diff --git a/ir/be/arm/arm_emitter.c b/ir/be/arm/arm_emitter.c index 770bef598..f346a30c9 100644 --- a/ir/be/arm/arm_emitter.c +++ b/ir/be/arm/arm_emitter.c @@ -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); diff --git a/ir/be/arm/bearch_arm.c b/ir/be/arm/bearch_arm.c index 943e7da70..824a18821 100644 --- a/ir/be/arm/bearch_arm.c +++ b/ir/be/arm/bearch_arm.c @@ -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 }; diff --git a/ir/be/arm/bearch_arm_t.h b/ir/be/arm/bearch_arm_t.h index 7091dea31..16e54fa6a 100644 --- a/ir/be/arm/bearch_arm_t.h +++ b/ir/be/arm/bearch_arm_t.h @@ -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 */ }; diff --git a/ir/be/be.h b/ir/be/be.h index efab423d1..3b6fecdac 100644 --- a/ir/be/be.h +++ b/ir/be/be.h @@ -8,6 +8,12 @@ #include "dbginfo.h" #include "ifconv.h" +#ifdef WITH_LIBCORE +#include +#include +#include +#endif /* WITH_LIBCORE */ + #define LC_STOP_AND_RESET_TIMER(timer) do { lc_timer_stop(timer); lc_timer_reset(timer); } while(0) /** diff --git a/ir/be/bearch.h b/ir/be/bearch.h index 08b660078..c1387fc5b 100644 --- a/ir/be/bearch.h +++ b/ir/be/bearch.h @@ -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)) diff --git a/ir/be/beblocksched.c b/ir/be/beblocksched.c index e97b183d9..704d33dab 100644 --- a/ir/be/beblocksched.c +++ b/ir/be/beblocksched.c @@ -25,6 +25,8 @@ #include "irtools.h" #include "debug.h" #include "beirgmod.h" +#include "bemodule.h" +#include "be.h" #ifdef WITH_LIBCORE #include @@ -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) { diff --git a/ir/be/beblocksched.h b/ir/be/beblocksched.h index 2ff69024c..1e7d9f665 100644 --- a/ir/be/beblocksched.h +++ b/ir/be/beblocksched.h @@ -15,9 +15,4 @@ ir_node **be_create_block_schedule(ir_graph *irg, ir_exec_freq *execfreqs); -#ifdef WITH_LIBCORE -#include -void be_block_schedule_register_options(lc_opt_entry_t *grp); -#endif /* WITH_LIBCORE */ - #endif /* _BEBLOCKSCHED_H */ diff --git a/ir/be/bechordal.h b/ir/be/bechordal.h index 4cb739680..a9c42960d 100644 --- a/ir/be/bechordal.h +++ b/ir/be/bechordal.h @@ -11,11 +11,6 @@ #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 diff --git a/ir/be/bechordal_main.c b/ir/be/bechordal_main.c index 451efff96..39755ed7c 100644 --- a/ir/be/bechordal_main.c +++ b/ir/be/bechordal_main.c @@ -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); diff --git a/ir/be/becopyheur2.c b/ir/be/becopyheur2.c index 3b9b3bcdc..1653a2d93 100644 --- a/ir/be/becopyheur2.c +++ b/ir/be/becopyheur2.c @@ -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 /* diff --git a/ir/be/becopyheur3.c b/ir/be/becopyheur3.c index 9ee2a9ce7..d8a452b26 100644 --- a/ir/be/becopyheur3.c +++ b/ir/be/becopyheur3.c @@ -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) { diff --git a/ir/be/becopyilp.c b/ir/be/becopyilp.c index 883ce50c0..fcd1dba45 100644 --- a/ir/be/becopyilp.c +++ b/ir/be/becopyilp.c @@ -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 */ diff --git a/ir/be/becopyopt.c b/ir/be/becopyopt.c index 476034228..80440cd76 100644 --- a/ir/be/becopyopt.c +++ b/ir/be/becopyopt.c @@ -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; diff --git a/ir/be/becopyopt.h b/ir/be/becopyopt.h index 7e11ba32d..0ef10ca88 100644 --- a/ir/be/becopyopt.h +++ b/ir/be/becopyopt.h @@ -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); diff --git a/ir/be/becopystat.c b/ir/be/becopystat.c index 4d59f2b10..fc1df4efd 100644 --- a/ir/be/becopystat.c +++ b/ir/be/becopystat.c @@ -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(); } /** diff --git a/ir/be/becopystat.h b/ir/be/becopystat.h index dd8438ecf..a71d81aff 100644 --- a/ir/be/becopystat.h +++ b/ir/be/becopystat.h @@ -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); diff --git a/ir/be/beilpsched.c b/ir/be/beilpsched.c index 730f4c229..4065e950e 100644 --- a/ir/be/beilpsched.c +++ b/ir/be/beilpsched.c @@ -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 */ diff --git a/ir/be/bejavacoal.c b/ir/be/bejavacoal.c index a8282f4c1..82a2e2488 100644 --- a/ir/be/bejavacoal.c +++ b/ir/be/bejavacoal.c @@ -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 @@ -463,5 +468,4 @@ void be_java_coal_start_jvm(void) { } - #endif /* WITH_JVM */ diff --git a/ir/be/belistsched.c b/ir/be/belistsched.c index 680fb1e4a..498cf28d4 100644 --- a/ir/be/belistsched.c +++ b/ir/be/belistsched.c @@ -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 */ diff --git a/ir/be/bemain.c b/ir/be/bemain.c index 81e731ea2..bfc6e0e67 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -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 diff --git a/ir/be/bemodule.c b/ir/be/bemodule.c index 64473f667..32c1f61a5 100644 --- a/ir/be/bemodule.c +++ b/ir/be/bemodule.c @@ -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 diff --git a/ir/be/bemodule.h b/ir/be/bemodule.h index 659e5f79f..dfa67c567 100644 --- a/ir/be/bemodule.h +++ b/ir/be/bemodule.h @@ -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 diff --git a/ir/be/bera.c b/ir/be/bera.c index 2178ec7e5..3525d7f51 100644 --- a/ir/be/bera.c +++ b/ir/be/bera.c @@ -7,6 +7,8 @@ #include "config.h" #endif +#include + #include "pset.h" #include "impl.h" @@ -14,9 +16,11 @@ #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(®ister_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", + ®ister_allocators, (void**) &selected_allocator); } +BE_REGISTER_MODULE_CONSTRUCTOR(init_be_ra); diff --git a/ir/be/bera.h b/ir/be/bera.h index 1b83e766c..1ca7f6460 100644 --- a/ir/be/bera.h +++ b/ir/be/bera.h @@ -10,7 +10,6 @@ #include "firm_config.h" #ifdef WITH_LIBCORE -#include #include #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. diff --git a/ir/be/beraextern.c b/ir/be/beraextern.c index fc6a5a1ff..09cc2908b 100644 --- a/ir/be/beraextern.c +++ b/ir/be/beraextern.c @@ -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 -}; diff --git a/ir/be/beraextern.h b/ir/be/beraextern.h index 84d8be38e..850678cc7 100644 --- a/ir/be/beraextern.h +++ b/ir/be/beraextern.h @@ -12,6 +12,4 @@ #include "bera.h" -extern const be_ra_t be_ra_external_allocator; - #endif diff --git a/ir/be/besched.c b/ir/be/besched.c index beb38858c..64a2cb7ed 100644 --- a/ir/be/besched.c +++ b/ir/be/besched.c @@ -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; diff --git a/ir/be/besched_t.h b/ir/be/besched_t.h index d23ce3a8d..f0d82b842 100644 --- a/ir/be/besched_t.h +++ b/ir/be/besched_t.h @@ -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. diff --git a/ir/be/beschedrss.c b/ir/be/beschedrss.c index 11f9d7ba9..f8d54ed3a 100644 --- a/ir/be/beschedrss.c +++ b/ir/be/beschedrss.c @@ -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 */ /** diff --git a/ir/be/bespillbelady.c b/ir/be/bespillbelady.c index 91ef2cd44..fde941c53 100644 --- a/ir/be/bespillbelady.c +++ b/ir/be/bespillbelady.c @@ -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; diff --git a/ir/be/bespilloptions.c b/ir/be/bespilloptions.c index 488323cc7..581a8dfb6 100644 --- a/ir/be/bespilloptions.c +++ b/ir/be/bespilloptions.c @@ -8,35 +8,31 @@ #include "config.h" #endif +#include "irtools.h" + #include "bespilloptions.h" +#include "bemodule.h" +#include "be.h" -#ifdef WITH_LIBCORE #include #include #include -#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); diff --git a/ir/be/bespilloptions.h b/ir/be/bespilloptions.h index 1f1e38341..53fbe9b84 100644 --- a/ir/be/bespilloptions.h +++ b/ir/be/bespilloptions.h @@ -10,9 +10,4 @@ extern int be_coalesce_spill_slots; extern int be_do_remats; -#ifdef WITH_LIBCORE -#include -void be_spill_register_options(lc_opt_entry_t *grp); -#endif - #endif diff --git a/ir/be/bespillremat.c b/ir/be/bespillremat.c index f4abb1961..f4216c36a 100644 --- a/ir/be/bespillremat.c +++ b/ir/be/bespillremat.c @@ -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 diff --git a/ir/be/ia32/bearch_ia32.c b/ir/be/ia32/bearch_ia32.c index 3148224d7..8c525e50e 100644 --- a/ir/be/ia32/bearch_ia32.c +++ b/ir/be/ia32/bearch_ia32.c @@ -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 }; diff --git a/ir/be/ia32/ia32_optimize.c b/ir/be/ia32/ia32_optimize.c index 0b3cfc6fa..5a9f97900 100644 --- a/ir/be/ia32/ia32_optimize.c +++ b/ir/be/ia32/ia32_optimize.c @@ -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. */ diff --git a/ir/be/mips/bearch_mips.c b/ir/be/mips/bearch_mips.c index cf90a8048..f03afaa83 100644 --- a/ir/be/mips/bearch_mips.c +++ b/ir/be/mips/bearch_mips.c @@ -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 }; diff --git a/ir/be/ppc32/bearch_ppc32.c b/ir/be/ppc32/bearch_ppc32.c index f4ae6f417..43f4f289f 100644 --- a/ir/be/ppc32/bearch_ppc32.c +++ b/ir/be/ppc32/bearch_ppc32.c @@ -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 };