From 8624e724f0873fe99349c327f9bb0a618910106e Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 10 Jan 2007 15:58:32 +0000 Subject: [PATCH] isas and spillers register themselfes in the module constructors now --- ir/be/TEMPLATE/bearch_TEMPLATE.c | 12 +++++----- ir/be/arm/bearch_arm.c | 29 ++++++++++-------------- ir/be/bearch.h | 5 +++++ ir/be/bechordal_main.c | 33 +-------------------------- ir/be/bechordal_t.h | 6 ----- ir/be/bemain.c | 32 ++++++++++++--------------- ir/be/bemodule.c | 6 ++++- ir/be/bespillbelady.c | 12 ++++++++++ ir/be/bespillmorgan.c | 14 +++++++++++- ir/be/bespillmorgan.h | 2 +- ir/be/bespilloptions.c | 20 +++++++++++++++++ ir/be/bespilloptions.h | 9 ++++++++ ir/be/bespillremat.c | 28 ++++++++++++++--------- ir/be/ia32/bearch_ia32.c | 38 ++++++++++---------------------- ir/be/ia32/bearch_ia32.h | 8 ------- ir/be/ia32/bearch_ia32_t.h | 1 - ir/be/mips/bearch_mips.c | 14 ++++++------ ir/be/ppc32/bearch_ppc32.c | 12 +++++----- 18 files changed, 142 insertions(+), 139 deletions(-) delete mode 100644 ir/be/ia32/bearch_ia32.h diff --git a/ir/be/TEMPLATE/bearch_TEMPLATE.c b/ir/be/TEMPLATE/bearch_TEMPLATE.c index 08f77cb00..8e0ca63d8 100644 --- a/ir/be/TEMPLATE/bearch_TEMPLATE.c +++ b/ir/be/TEMPLATE/bearch_TEMPLATE.c @@ -586,11 +586,6 @@ static const backend_params *TEMPLATE_get_libfirm_params(void) { return &p; } -void be_init_arch_TEMPLATE() -{ -} -BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_TEMPLATE); - const arch_isa_if_t TEMPLATE_isa_if = { TEMPLATE_init, TEMPLATE_done, @@ -604,3 +599,10 @@ const arch_isa_if_t TEMPLATE_isa_if = { TEMPLATE_get_reg_class_alignment, TEMPLATE_get_libfirm_params, }; + +void be_init_arch_TEMPLATE(void) +{ + be_register_isa_if("TEMPLATE", &TEMPLATE_isa_if); +} + +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_TEMPLATE); diff --git a/ir/be/arm/bearch_arm.c b/ir/be/arm/bearch_arm.c index 824a18821..527a64e21 100644 --- a/ir/be/arm/bearch_arm.c +++ b/ir/be/arm/bearch_arm.c @@ -1140,23 +1140,6 @@ static const lc_opt_table_entry_t arm_options[] = { LC_OPT_ENT_BOOL("gen_reg_names", "use generic register names", &arm_isa_template.gen_reg_names), { NULL } }; - -/** - * Register command line options for the ARM backend. - * - * Options so far: - * - * arm-fpuunit=unit select the floating point unit - * arm-gen_reg_names use generic register names instead of SP, LR, PC - */ -void be_init_arch_arm(void) -{ - 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 = { @@ -1175,3 +1158,15 @@ const arch_isa_if_t arm_isa_if = { arm_get_allowed_execution_units, arm_get_machine, }; + +void be_init_arch_arm(void) +{ + 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_isa_if("arm", &arm_isa_if); +} + +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_arm); diff --git a/ir/be/bearch.h b/ir/be/bearch.h index c1387fc5b..af3c634c8 100644 --- a/ir/be/bearch.h +++ b/ir/be/bearch.h @@ -795,4 +795,9 @@ extern arch_env_t *arch_env_push_irn_handler(arch_env_t *env, const arch_irn_han */ extern const arch_irn_handler_t *arch_env_pop_irn_handler(arch_env_t *env); +/** + * Register an instruction set architecture + */ +void be_register_isa_if(const char *name, const arch_isa_if_t *isa); + #endif /* _FIRM_BEARCH_H */ diff --git a/ir/be/bechordal_main.c b/ir/be/bechordal_main.c index 39755ed7c..17cd724f7 100644 --- a/ir/be/bechordal_main.c +++ b/ir/be/bechordal_main.c @@ -78,7 +78,6 @@ static be_ra_chordal_opts_t options = { BE_CH_DUMP_NONE, - BE_CH_SPILL_BELADY, BE_CH_IFG_STD, BE_CH_LOWER_PERM_SWAP, BE_CH_VRFY_WARN, @@ -109,15 +108,6 @@ static be_ra_timer_t ra_timer = { NULL, }; -static const lc_opt_enum_int_items_t spill_items[] = { - { "belady", BE_CH_SPILL_BELADY }, - { "morgan", BE_CH_SPILL_MORGAN }, -#ifdef WITH_ILP - { "remat", BE_CH_SPILL_REMAT }, -#endif /* WITH_ILP */ - { NULL, 0 } -}; - static const lc_opt_enum_int_items_t ifg_flavor_items[] = { { "std", BE_CH_IFG_STD }, { "fast", BE_CH_IFG_FAST }, @@ -160,10 +150,6 @@ static const lc_opt_enum_int_items_t be_ch_vrfy_items[] = { { NULL, 0 } }; -static lc_opt_enum_int_var_t spill_var = { - &options.spill_method, spill_items -}; - static lc_opt_enum_int_var_t ifg_flavor_var = { &options.ifg_flavor, ifg_flavor_items }; @@ -181,7 +167,6 @@ 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_INT ("spill", "spill method", &spill_var), LC_OPT_ENT_ENUM_PTR ("ifg", "interference graph flavour", &ifg_flavor_var), LC_OPT_ENT_ENUM_PTR ("perm", "perm lowering options", &lower_perm_var), LC_OPT_ENT_ENUM_MASK("dump", "select dump phases", &dump_var), @@ -720,23 +705,7 @@ static void be_ra_chordal_main(be_irg_t *birg) pre_spill(isa, j, &pse); BE_TIMER_PUSH(ra_timer.t_spill); - /* spilling */ - switch(options.spill_method) { - case BE_CH_SPILL_MORGAN: - be_spill_morgan(&pse.cenv); - break; - case BE_CH_SPILL_BELADY: - be_spill_belady(&pse.cenv); - break; - #ifdef WITH_ILP - case BE_CH_SPILL_REMAT: - be_spill_remat(&pse.cenv); - break; - #endif /* WITH_ILP */ - default: - fprintf(stderr, "no valid spiller selected. falling back to belady\n"); - be_spill_belady(&pse.cenv); - } + be_do_spill(&pse.cenv); BE_TIMER_POP(ra_timer.t_spill); dump(BE_CH_DUMP_SPILL, irg, pse.cenv.cls, "-spill", dump_ir_block_graph_sched); diff --git a/ir/be/bechordal_t.h b/ir/be/bechordal_t.h index bafedce7f..f0754aaac 100644 --- a/ir/be/bechordal_t.h +++ b/ir/be/bechordal_t.h @@ -92,11 +92,6 @@ void be_ra_chordal_color(be_chordal_env_t *chordal_env); void be_ra_chordal_check(be_chordal_env_t *chordal_env); enum { - /* spill method */ - BE_CH_SPILL_BELADY = 1, - BE_CH_SPILL_MORGAN = 2, - BE_CH_SPILL_REMAT = 3, - /* Dump flags */ BE_CH_DUMP_NONE = (1 << 0), BE_CH_DUMP_SPILL = (1 << 1), @@ -131,7 +126,6 @@ enum { struct _be_ra_chordal_opts_t { int dump_flags; - int spill_method; int ifg_flavor; int lower_perm_opt; int vrfy_option; diff --git a/ir/be/bemain.c b/ir/be/bemain.c index 1cd2c1a9e..79167cd8a 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -90,7 +90,7 @@ static be_options_t be_options = { static char config_file[256] = { 0 }; /* back end instruction set architecture to use */ -static const arch_isa_if_t *isa_if = &ia32_isa_if; +static const arch_isa_if_t *isa_if = NULL; #ifdef WITH_LIBCORE @@ -108,18 +108,6 @@ static const lc_opt_enum_mask_items_t dump_items[] = { { NULL, 0 } }; -/* instruction set architectures. */ -static const lc_opt_enum_const_ptr_items_t isa_items[] = { - { "ia32", &ia32_isa_if }, -#if 0 - { "sta", &sta_isa_if }, - { "arm", &arm_isa_if }, - { "ppc32", &ppc32_isa_if }, - { "mips", &mips_isa_if }, -#endif - { NULL, NULL } -}; - /* verify options. */ static const lc_opt_enum_int_items_t vrfy_items[] = { { "off", BE_VRFY_OFF }, @@ -141,10 +129,6 @@ static lc_opt_enum_mask_var_t dump_var = { &be_options.dump_flags, dump_items }; -static lc_opt_enum_const_ptr_var_t isa_var = { - (const void **) &isa_if, isa_items -}; - static lc_opt_enum_int_var_t vrfy_var = { &be_options.vrfy_option, vrfy_items }; @@ -156,7 +140,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 ("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), LC_OPT_ENT_ENUM_PTR ("vrfy", "verify the backend irg", &vrfy_var), @@ -174,6 +157,16 @@ static const lc_opt_table_entry_t be_main_options[] = { #endif /* WITH_LIBCORE */ +static be_module_list_entry_t *isa_ifs = NULL; + +void be_register_isa_if(const char *name, const arch_isa_if_t *isa) +{ + if(isa_if == NULL) + isa_if = isa; + + be_add_module_to_list(&isa_ifs, name, (void*) isa); +} + void be_opt_register(void) { #ifdef WITH_LIBCORE @@ -189,6 +182,9 @@ void be_opt_register(void) be_grp = lc_opt_get_grp(firm_opt_get_root(), "be"); lc_opt_add_table(be_grp, be_main_options); + + be_add_module_list_opt(be_grp, "isa", "the instruction set architecture", + &isa_ifs, (void**) &isa_if); #endif /* WITH_LIBCORE */ } diff --git a/ir/be/bemodule.c b/ir/be/bemodule.c index 57d05bca5..2716892ac 100644 --- a/ir/be/bemodule.c +++ b/ir/be/bemodule.c @@ -29,9 +29,11 @@ void be_init_arch_mips(void); void be_init_arch_arm(void); void be_init_ilpsched(void); void be_init_copyilp(void); -void be_init_spillremat(void); void be_init_javacoal(void); void be_init_ra(void); +void be_init_spillbelady(void); +void be_init_spillmorgan(void); +void be_init_spillremat(void); void be_quit_copystat(void); @@ -54,6 +56,8 @@ void be_init_modules(void) be_init_raextern(); be_init_copystat(); be_init_ra(); + be_init_spillbelady(); + be_init_spillmorgan(); be_init_arch_ia32(); be_init_arch_ppc32(); diff --git a/ir/be/bespillbelady.c b/ir/be/bespillbelady.c index fde941c53..dfac1e865 100644 --- a/ir/be/bespillbelady.c +++ b/ir/be/bespillbelady.c @@ -39,6 +39,7 @@ #include "belive_t.h" #include "benode_t.h" #include "bechordal_t.h" +#include "bespilloptions.h" #define DBG_SPILL 1 #define DBG_WSETS 2 @@ -730,3 +731,14 @@ void be_spill_belady_spill_env(const be_chordal_env_t *chordal_env, spill_env_t be_end_uses(env.uses); obstack_free(&env.ob, NULL); } + +void be_init_spillbelady(void) +{ + static be_spiller_t belady_spiller = { + be_spill_belady + }; + + be_register_spiller("belady", &belady_spiller); +} + +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillbelady); diff --git a/ir/be/bespillmorgan.c b/ir/be/bespillmorgan.c index 16f9e6080..f889bccdc 100644 --- a/ir/be/bespillmorgan.c +++ b/ir/be/bespillmorgan.c @@ -26,6 +26,7 @@ #include "bespillbelady.h" #include "beverify.h" #include "benodesets.h" +#include "bespilloptions.h" #define DBG_LIVE 1 #define DBG_LOOPANA 2 @@ -539,7 +540,7 @@ static int reduce_register_pressure_in_loop(morgan_env_t *env, const ir_loop *lo return outer_spills_needed; } -void be_spill_morgan(be_chordal_env_t *chordal_env) { +void be_spill_morgan(const be_chordal_env_t *chordal_env) { ir_graph *irg = chordal_env->irg; morgan_env_t env; @@ -604,3 +605,14 @@ void be_spill_morgan(be_chordal_env_t *chordal_env) { be_delete_spill_env(env.senv); obstack_free(&env.obst, NULL); } + +void be_init_spillmorgan(void) +{ + static be_spiller_t morgan_spiller = { + be_spill_morgan + }; + + be_register_spiller("morgan", &morgan_spiller); +} + +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillmorgan); diff --git a/ir/be/bespillmorgan.h b/ir/be/bespillmorgan.h index e400aacea..1299170c4 100644 --- a/ir/be/bespillmorgan.h +++ b/ir/be/bespillmorgan.h @@ -10,6 +10,6 @@ #include "be_t.h" #include "bechordal.h" -void be_spill_morgan(be_chordal_env_t *env); +void be_spill_morgan(const be_chordal_env_t *env); #endif diff --git a/ir/be/bespilloptions.c b/ir/be/bespilloptions.c index 581a8dfb6..8ce012acd 100644 --- a/ir/be/bespilloptions.c +++ b/ir/be/bespilloptions.c @@ -27,12 +27,32 @@ static const lc_opt_table_entry_t be_spill_options[] = { { NULL } }; +static be_module_list_entry_t *spillers = NULL; +static be_spiller_t *selected_spiller = NULL; + +void be_register_spiller(const char *name, be_spiller_t *spiller) +{ + if(selected_spiller == NULL) + selected_spiller = spiller; + be_add_module_to_list(&spillers, name, spiller); +} + +void be_do_spill(const be_chordal_env_t *env) +{ + assert(selected_spiller != NULL); + if(selected_spiller != NULL) { + selected_spiller->spill(env); + } +} + void be_init_spill(void) { 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); + be_add_module_list_opt(spill_grp, "spiller", "spill algorithm", + &spillers, (void**) &selected_spiller); } BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spill); diff --git a/ir/be/bespilloptions.h b/ir/be/bespilloptions.h index 53fbe9b84..0a2b06bfa 100644 --- a/ir/be/bespilloptions.h +++ b/ir/be/bespilloptions.h @@ -7,7 +7,16 @@ #ifndef BESPILL_OPTIONS_H_ #define BESPILL_OPTIONS_H_ +#include "bechordal.h" + extern int be_coalesce_spill_slots; extern int be_do_remats; +typedef struct be_spiller_t { + void (*spill) (const be_chordal_env_t *env); +} be_spiller_t; +void be_register_spiller(const char *name, be_spiller_t *spiller); + +void be_do_spill(const be_chordal_env_t *env); + #endif diff --git a/ir/be/bespillremat.c b/ir/be/bespillremat.c index f4216c36a..e3a284799 100644 --- a/ir/be/bespillremat.c +++ b/ir/be/bespillremat.c @@ -54,6 +54,7 @@ #include "bespill.h" #include "bepressurestat.h" #include "beprofile.h" +#include "bespilloptions.h" #include "bechordal_t.h" @@ -157,17 +158,6 @@ static const lc_opt_table_entry_t options[] = { { NULL } }; -void be_init_spillremat(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 *remat_grp = lc_opt_get_grp(chordal_grp, "remat"); - - lc_opt_add_table(remat_grp, options); -} - -BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillremat); #endif @@ -4540,6 +4530,22 @@ be_spill_remat(const be_chordal_env_t * chordal_env) DBG((si.dbg, LEVEL_1, "\tdone.\n")); } +void be_init_spillremat(void) +{ + static be_spiller_t remat_spiller = { + be_spill_remat + }; + 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"); + + be_register_spiller("remat", &remat_spiller); + lc_opt_add_table(remat_grp, options); +} + +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillremat); + #else /* WITH_ILP */ static void INLINE diff --git a/ir/be/ia32/bearch_ia32.c b/ir/be/ia32/bearch_ia32.c index b452dd0ad..d8af7e3db 100644 --- a/ir/be/ia32/bearch_ia32.c +++ b/ir/be/ia32/bearch_ia32.c @@ -1451,6 +1451,7 @@ static void set_tarval_output_modes(void) } } +const arch_isa_if_t ia32_isa_if; /** * The template that generates a new ISA object. @@ -1980,32 +1981,6 @@ static const lc_opt_table_entry_t ia32_options[] = { LC_OPT_ENT_ENUM_INT("gasmode", "set the GAS compatibility mode", &gas_var), { NULL } }; - -/** - * Register command line options for the ia32 backend. - * - * Options so far: - * - * ia32-arch=arch create instruction for arch - * ia32-opt=arch optimize for run on arch - * ia32-fpunit=unit select floating point unit (x87 or SSE2) - * ia32-incdec optimize for inc/dec - * ia32-noaddrmode do not use address mode - * ia32-nolea do not optimize for LEAs - * ia32-noplacecnst do not place constants, - * ia32-noimmop no operations with immediates - * ia32-noextbb do not use extended basic block scheduling - * ia32-nopushargs do not create pushs for function argument passing - * ia32-gasmode set the GAS compatibility mode - */ -void be_init_arch_ia32(void) -{ - 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 = { @@ -2024,3 +1999,14 @@ const arch_isa_if_t ia32_isa_if = { ia32_get_allowed_execution_units, ia32_get_machine, }; + +void be_init_arch_ia32(void) +{ + 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_isa_if("ia32", &ia32_isa_if); +} + +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_ia32); diff --git a/ir/be/ia32/bearch_ia32.h b/ir/be/ia32/bearch_ia32.h deleted file mode 100644 index 9293464e1..000000000 --- a/ir/be/ia32/bearch_ia32.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _BEARCH_IA32_H_ -#define _BEARCH_IA32_H_ - -#include "../bearch.h" - -extern const arch_isa_if_t ia32_isa_if; - -#endif /* _BEARCH_IA32_H_ */ diff --git a/ir/be/ia32/bearch_ia32_t.h b/ir/be/ia32/bearch_ia32_t.h index bfeeb287e..7b0291fcb 100644 --- a/ir/be/ia32/bearch_ia32_t.h +++ b/ir/be/ia32/bearch_ia32_t.h @@ -5,7 +5,6 @@ #include "pmap.h" #include "debug.h" -#include "bearch_ia32.h" #include "ia32_nodes_attr.h" #include "set.h" diff --git a/ir/be/mips/bearch_mips.c b/ir/be/mips/bearch_mips.c index f03afaa83..2ddc6a990 100644 --- a/ir/be/mips/bearch_mips.c +++ b/ir/be/mips/bearch_mips.c @@ -969,13 +969,6 @@ static const backend_params *mips_get_libfirm_params(void) { return &p; } -#ifdef WITH_LIBCORE -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 = { mips_init, mips_done, @@ -992,3 +985,10 @@ const arch_isa_if_t mips_isa_if = { mips_get_allowed_execution_units, mips_get_machine, }; + +void be_init_arch_mips(void) +{ + be_register_isa_if("mips", &mips_isa_if); +} + +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_mips); diff --git a/ir/be/ppc32/bearch_ppc32.c b/ir/be/ppc32/bearch_ppc32.c index 43f4f289f..8ff4c5e0c 100644 --- a/ir/be/ppc32/bearch_ppc32.c +++ b/ir/be/ppc32/bearch_ppc32.c @@ -908,11 +908,6 @@ static const backend_params *ppc32_get_libfirm_params(void) { return &p; } -void be_init_arch_ppc32(void) -{ -} -BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_ppc32); - const arch_isa_if_t ppc32_isa_if = { ppc32_init, ppc32_done, @@ -929,3 +924,10 @@ const arch_isa_if_t ppc32_isa_if = { ppc32_get_allowed_execution_units, ppc32_get_machine, }; + +void be_init_arch_ppc32(void) +{ + be_register_isa_if("ppc32", &ppc32_isa_if); +} + +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_ppc32); -- 2.20.1