From e1c59206a1d08078fb36e930101eb4b47f959eab Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 9 Aug 2006 12:43:11 +0000 Subject: [PATCH] - add new finish call to architecture calls. This call is meant to be the last place where the arch code should modify the irg before emitting assembler code. This allows to gather statistics, verify the graph at the last possible moment before it is emitted --- ir/be/TEMPLATE/bearch_TEMPLATE.c | 12 ++++++------ ir/be/arm/bearch_arm.c | 4 ++-- ir/be/bearch.h | 10 +++++++++- ir/be/bechordal_main.c | 12 ------------ ir/be/bemain.c | 4 ++++ ir/be/ia32/bearch_ia32.c | 16 ++++++++++++---- ir/be/mips/bearch_mips.c | 12 ++++++------ ir/be/ppc32/bearch_ppc32.c | 4 ++-- 8 files changed, 41 insertions(+), 33 deletions(-) diff --git a/ir/be/TEMPLATE/bearch_TEMPLATE.c b/ir/be/TEMPLATE/bearch_TEMPLATE.c index 1cd6a88a5..d7fa82cde 100644 --- a/ir/be/TEMPLATE/bearch_TEMPLATE.c +++ b/ir/be/TEMPLATE/bearch_TEMPLATE.c @@ -263,10 +263,11 @@ static void TEMPLATE_prepare_graph(void *self) { /** * Called immediatly before emit phase. */ -static void TEMPLATE_finish_irg(ir_graph *irg, TEMPLATE_code_gen_t *cg) { - /* TODO: - fix offsets for nodes accessing stack - - ... - */ +static void TEMPLATE_finish_irg(void *self) { + TEMPLATE_code_gen_t *cg = self; + ir_graph *irg = cg->irg; + + dump_ir_block_graph_sched(irg, "-TEMPLATE-finished"); } @@ -301,8 +302,6 @@ static void TEMPLATE_emit_and_done(void *self) { cg->emit_decls = 0; } - TEMPLATE_finish_irg(irg, cg); - dump_ir_block_graph_sched(irg, "-TEMPLATE-finished"); TEMPLATE_gen_routine(out, irg, cg); cur_reg_set = NULL; @@ -320,6 +319,7 @@ static const arch_code_generator_if_t TEMPLATE_code_gen_if = { TEMPLATE_before_sched, /* before scheduling hook */ TEMPLATE_before_ra, /* before register allocation hook */ TEMPLATE_after_ra, /* after register allocation hook */ + TEMPLATE_finish_irg, TEMPLATE_emit_and_done }; diff --git a/ir/be/arm/bearch_arm.c b/ir/be/arm/bearch_arm.c index 3914f4a8e..e2c18892a 100644 --- a/ir/be/arm/bearch_arm.c +++ b/ir/be/arm/bearch_arm.c @@ -286,7 +286,7 @@ static void arm_prepare_graph(void *self) { /** * Called immediately before emit phase. */ -static void arm_finish_irg(ir_graph *irg, arm_code_gen_t *cg) { +static void arm_finish_irg(void *self) { /* TODO: - fix offsets for nodes accessing stack - ... */ @@ -319,7 +319,6 @@ static void arm_emit_and_done(void *self) { cg->emit_decls = 0; } - arm_finish_irg(irg, cg); dump_ir_block_graph_sched(irg, "-arm-finished"); arm_gen_routine(out, irg, cg); @@ -532,6 +531,7 @@ static const arch_code_generator_if_t arm_code_gen_if = { arm_before_sched, /* before scheduling hook */ arm_before_ra, /* before register allocation hook */ NULL, /* after register allocation */ + arm_finish_irg, arm_emit_and_done, }; diff --git a/ir/be/bearch.h b/ir/be/bearch.h index 6da6382cc..70f9a9a09 100644 --- a/ir/be/bearch.h +++ b/ir/be/bearch.h @@ -524,7 +524,14 @@ struct _arch_code_generator_if_t { void (*after_ra)(void *self); /** - * Called after everything happened. + * Called directly before done is called. This should be the last place + * where the irg is modified. + */ + void (*finish)(void *self); + + /** + * Called after everything happened. This call should emit the final + * assembly code but avoid changing the irg. * The code generator must also be de-allocated here. */ void (*done)(void *self); @@ -545,6 +552,7 @@ do { \ #define arch_code_generator_before_sched(cg) _arch_cg_call(cg, before_sched) #define arch_code_generator_before_ra(cg) _arch_cg_call(cg, before_ra) #define arch_code_generator_after_ra(cg) _arch_cg_call(cg, after_ra) +#define arch_code_generator_finish(cg) _arch_cg_call(cg, finish) #define arch_code_generator_done(cg) _arch_cg_call(cg, done) /** diff --git a/ir/be/bechordal_main.c b/ir/be/bechordal_main.c index 4afa70c0a..19feacea5 100644 --- a/ir/be/bechordal_main.c +++ b/ir/be/bechordal_main.c @@ -609,18 +609,6 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi) free_execfreq(chordal_env.exec_freq); BE_TIMER_POP(ra_timer.t_epilog); - - BE_TIMER_PUSH(ra_timer.t_verify); - - /* verify spillslots */ - if (options.vrfy_option == BE_CH_VRFY_WARN) { - be_verify_schedule(irg); - } - else if (options.vrfy_option == BE_CH_VRFY_ASSERT) { - assert(be_verify_schedule(irg) && "Schedule verification failed"); - } - BE_TIMER_POP(ra_timer.t_verify); - BE_TIMER_POP(ra_timer.t_other); #undef BE_TIMER_PUSH diff --git a/ir/be/bemain.c b/ir/be/bemain.c index d3ec2a7c9..4ee7aa4d7 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -539,6 +539,10 @@ static void be_main_loop(FILE *file_handle) be_abi_fix_stack_bias(birg.abi); BE_TIMER_POP(t_abi); + BE_TIMER_PUSH(t_finish); + arch_code_generator_finish(birg.cg); + BE_TIMER_POP(t_finish); + /* check schedule */ BE_TIMER_PUSH(t_verify); be_sched_vrfy(birg.irg, vrfy_option); diff --git a/ir/be/ia32/bearch_ia32.c b/ir/be/ia32/bearch_ia32.c index 269901cf7..c65aa1361 100644 --- a/ir/be/ia32/bearch_ia32.c +++ b/ir/be/ia32/bearch_ia32.c @@ -1039,6 +1039,17 @@ static void ia32_after_ra(void *self) { } } +/** + * Last touchups for the graph before emit + */ +static void ia32_finish(void *self) { + ia32_code_gen_t *cg = self; + ir_graph *irg = cg->irg; + + ia32_finish_irg(irg, cg); + if (cg->dump) + be_dump(irg, "-finished", dump_ir_block_graph_sched); +} /** * Emits the code, closes the output file and frees @@ -1048,9 +1059,6 @@ static void ia32_codegen(void *self) { ia32_code_gen_t *cg = self; ir_graph *irg = cg->irg; - ia32_finish_irg(irg, cg); - if (cg->dump) - be_dump(irg, "-finished", dump_ir_block_graph_sched); ia32_gen_routine(cg->isa->out, irg, cg); cur_reg_set = NULL; @@ -1061,7 +1069,6 @@ static void ia32_codegen(void *self) { /* de-allocate code generator */ del_set(cg->reg_set); free(self); - } static void *ia32_cg_init(const be_irg_t *birg); @@ -1073,6 +1080,7 @@ static const arch_code_generator_if_t ia32_code_gen_if = { ia32_before_sched, /* before scheduling hook */ ia32_before_ra, /* before register allocation hook */ ia32_after_ra, /* after register allocation hook */ + ia32_finish, /* called before codegen */ ia32_codegen /* emit && done */ }; diff --git a/ir/be/mips/bearch_mips.c b/ir/be/mips/bearch_mips.c index b41aa3190..78196241f 100644 --- a/ir/be/mips/bearch_mips.c +++ b/ir/be/mips/bearch_mips.c @@ -448,10 +448,11 @@ static void mips_prepare_graph(void *self) { /** * Called immediately before emit phase. */ -static void mips_finish_irg(ir_graph *irg, mips_code_gen_t *cg) { - /* TODO: - fix offsets for nodes accessing stack - - ... - */ +static void mips_finish_irg(void *self) { + mips_code_gen_t *cg = self; + ir_graph *irg = cg->irg; + + dump_ir_block_graph_sched(irg, "-mips-finished"); } @@ -487,8 +488,6 @@ static void mips_emit_and_done(void *self) { cg->emit_decls = 0; } - mips_finish_irg(irg, cg); - dump_ir_block_graph_sched(irg, "-mips-finished"); mips_gen_routine(out, irg, cg); cur_reg_set = NULL; @@ -511,6 +510,7 @@ static const arch_code_generator_if_t mips_code_gen_if = { mips_before_sched, /* before scheduling hook */ mips_before_ra, /* before register allocation hook */ mips_after_ra, + mips_finish_irg, mips_emit_and_done }; diff --git a/ir/be/ppc32/bearch_ppc32.c b/ir/be/ppc32/bearch_ppc32.c index 09b527635..c1222d6e1 100644 --- a/ir/be/ppc32/bearch_ppc32.c +++ b/ir/be/ppc32/bearch_ppc32.c @@ -434,7 +434,7 @@ static void ppc32_prepare_graph(void *self) { /** * Called immediatly before emit phase. */ -static void ppc32_finish_irg(ir_graph *irg, ppc32_code_gen_t *cg) { +static void ppc32_finish_irg(void *self) { /* TODO: - fix offsets for nodes accessing stack - ... */ @@ -557,7 +557,6 @@ static void ppc32_emit_and_done(void *self) { cg->emit_decls = 0; } - ppc32_finish_irg(irg, cg); dump_ir_block_graph_sched(irg, "-ppc-finished"); ppc32_gen_routine(out, irg, cg); @@ -600,6 +599,7 @@ static const arch_code_generator_if_t ppc32_code_gen_if = { ppc32_before_sched, /* before scheduling hook */ ppc32_before_ra, /* before register allocation hook */ ppc32_after_ra, + ppc32_finish_irg, ppc32_emit_and_done }; -- 2.20.1