From e1d4778ef7c53519d9af64fa04a107ce4293437d Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 26 Oct 2006 13:15:06 +0000 Subject: [PATCH] output estimated cost statistics to statfile --- ir/be/bechordal_main.c | 8 ++++++++ ir/be/bemain.c | 11 +++++++++++ ir/be/bestat.c | 32 +++++++++++++++++++++++++++++++- ir/be/bestat.h | 6 ++++++ ir/be/ia32/bearch_ia32.c | 4 +++- 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/ir/be/bechordal_main.c b/ir/be/bechordal_main.c index 6868ff421..03236f647 100644 --- a/ir/be/bechordal_main.c +++ b/ir/be/bechordal_main.c @@ -573,6 +573,7 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi) /* Perform the following for each register class. */ for (j = 0, m = arch_isa_get_n_reg_class(isa); j < m; ++j) { node_stat_t node_stat; + double spillcosts = 0; chordal_env.cls = arch_isa_get_reg_class(isa, j); chordal_env.border_heads = pmap_create(); @@ -598,6 +599,10 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi) be_pre_spill_prepare_constr(&chordal_env); dump(BE_CH_DUMP_CONSTR, irg, chordal_env.cls, "-constr-pre", dump_ir_block_graph_sched); + if(be_stat_ev_is_active()) { + spillcosts = be_estimate_irg_costs(irg, main_env->arch_env, chordal_env.exec_freq); + } + BE_TIMER_PUSH(ra_timer.t_spill); /* spilling */ @@ -621,6 +626,9 @@ static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi) BE_TIMER_POP(ra_timer.t_spill); if(be_stat_ev_is_active()) { + spillcosts -= be_estimate_irg_costs(irg, main_env->arch_env, chordal_env.exec_freq); + be_stat_ev_l("spillcosts", (long) spillcosts); + node_stats(&chordal_env, &node_stat); be_stat_ev("phis_after_spill", node_stat.n_phis); be_stat_ev("mem_phis", node_stat.n_mem_phis); diff --git a/ir/be/bemain.c b/ir/be/bemain.c index 18ab7b39c..af35a3206 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -505,6 +505,7 @@ static void be_main_loop(FILE *file_handle, const char *cup_name) if(be_stat_ev_is_active()) { ir_snprintf(irg_name, sizeof(irg_name), "%F", irg); + be_stat_tags[STAT_TAG_CLS] = ""; be_stat_tags[STAT_TAG_IRG] = irg_name; be_stat_ev_push(be_stat_tags, STAT_TAG_LAST, be_stat_file); } @@ -642,11 +643,21 @@ static void be_main_loop(FILE *file_handle, const char *cup_name) arch_code_generator_before_ra(birg->cg); BE_TIMER_POP(t_codegen); + if(be_stat_ev_is_active()) { + be_stat_ev_l("costs_before_ra", + (long) be_estimate_irg_costs(irg, env.arch_env, birg->execfreqs)); + } + /* Do register allocation */ BE_TIMER_PUSH(t_regalloc); ra_timer = ra->allocate(birg); BE_TIMER_POP(t_regalloc); + if(be_stat_ev_is_active()) { + be_stat_ev_l("costs_after_ra", + (long) be_estimate_irg_costs(irg, env.arch_env, birg->execfreqs)); + } + dump(DUMP_RA, irg, "-ra", dump_ir_block_graph_sched); be_do_stat_nodes(irg, "06 Register Allocation"); diff --git a/ir/be/bestat.c b/ir/be/bestat.c index 996f8a66a..a1be208b8 100644 --- a/ir/be/bestat.c +++ b/ir/be/bestat.c @@ -303,8 +303,38 @@ void be_stat_init_irg(const arch_env_t *arch_env, ir_graph *irg) { } } -const char *be_stat_tags[STAT_TAG_LAST]; +typedef struct _estimate_irg_costs_env_t { + const arch_env_t *arch_env; + ir_exec_freq *execfreqs; + double costs; +} estimate_irg_costs_env_t; + +static void estimate_block_costs(ir_node *block, void *data) +{ + estimate_irg_costs_env_t *env = data; + ir_node *node; + double costs = 0; + + sched_foreach(block, node) { + costs += arch_get_op_estimated_cost(env->arch_env, node); + } + + env->costs += costs * get_block_execfreq(env->execfreqs, block); +} +double be_estimate_irg_costs(ir_graph *irg, const arch_env_t *arch_env, ir_exec_freq *execfreqs) +{ + estimate_irg_costs_env_t env; + env.arch_env = arch_env; + env.execfreqs = execfreqs; + env.costs = 0; + + irg_block_walk_graph(irg, estimate_block_costs, NULL, &env); + + return env.costs; +} + +const char *be_stat_tags[STAT_TAG_LAST]; FILE *be_stat_file = NULL; void be_init_stat_file(const char *stat_file_name, const char *sourcefilename) diff --git a/ir/be/bestat.h b/ir/be/bestat.h index 961ee2f4b..a3994e4ef 100644 --- a/ir/be/bestat.h +++ b/ir/be/bestat.h @@ -76,6 +76,12 @@ void be_do_stat_nodes(ir_graph *irg, const char *phase); */ void be_stat_init_irg(const arch_env_t *arch_env, ir_graph *irg); +/** + * Gives a cost estimate for the program (based on execution frequencies) + * and backend op_estimated_cost + */ +double be_estimate_irg_costs(ir_graph *irg, const arch_env_t *arch_env, ir_exec_freq *execfreqs); + void be_init_stat_file(const char *filename, const char *sourcefilename); void be_close_stat_file(void); diff --git a/ir/be/ia32/bearch_ia32.c b/ir/be/ia32/bearch_ia32.c index ecce61a9c..53324f2dc 100644 --- a/ir/be/ia32/bearch_ia32.c +++ b/ir/be/ia32/bearch_ia32.c @@ -550,7 +550,9 @@ static int ia32_get_op_estimated_cost(const void *self, const ir_node *irn) const ia32_irn_ops_t *ops = self; if (is_Proj(irn)) - return 0; + return 0; + if (!is_ia32_irn(irn)) + return 0; assert(is_ia32_irn(irn)); -- 2.20.1