From 5995f50798657ea4237af8cb725e9a6995991e9c Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 10 Oct 2007 15:13:28 +0000 Subject: [PATCH] count executed optimization [r16145] --- ir/stat/firmstat.c | 32 +++++++++++++++++++++++++++++-- ir/stat/firmstat_t.h | 12 ++++++++++-- ir/stat/stat_dmp.c | 45 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/ir/stat/firmstat.c b/ir/stat/firmstat.c index eacad20d2..bd2fcbb56 100644 --- a/ir/stat/firmstat.c +++ b/ir/stat/firmstat.c @@ -526,6 +526,15 @@ static perm_stat_entry_t *perm_stat_get_entry(struct obstack *obst, ir_node *per return pset_insert(hmap, elem, HASH_PTR(perm)); } /* perm_stat_get_entry */ +/** + * Clear optimizations counter, + */ +static void clear_optimization_counter(void) { + int i; + for (i = 0; i < FS_OPT_MAX; ++i) + cnt_clr(&status->num_opts[i]); +} + /** * Returns the ir_op for an IR-node, * handles special cases and return pseudo op codes. @@ -1325,10 +1334,22 @@ static void stat_dump_param_tbl(const distrib_tbl_t *tbl, graph_entry_t *global) dumper_t *dumper; for (dumper = status->dumper; dumper; dumper = dumper->next) { - if (dumper->dump_const_tbl) + if (dumper->dump_param_tbl) dumper->dump_param_tbl(dumper, tbl, global); } /* for */ -} +} /* stat_dump_param_tbl */ + +/** + * Dumps the optimization counter + */ +static void stat_dump_opt_cnt(const counter_t *tbl, unsigned len) { + dumper_t *dumper; + + for (dumper = status->dumper; dumper; dumper = dumper->next) { + if (dumper->dump_opt_cnt) + dumper->dump_opt_cnt(dumper, tbl, len); + } /* for */ +} /* stat_dump_opt_cnt */ /** * Initialize the dumper. @@ -1641,6 +1662,7 @@ static void stat_merge_nodes( int i, j; graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash); + cnt_inc(&status->num_opts[opt]); if (status->reassoc_run) opt = HOOK_OPT_REASSOC; @@ -2097,6 +2119,10 @@ void stat_dump_snapshot(const char *name, const char *phase) /* dump the parameter distribution */ stat_dump_param_tbl(status->dist_param_cnt, global); + /* dump the optimization counter and clear them */ + stat_dump_opt_cnt(status->num_opts, ARR_SIZE(status->num_opts)); + clear_optimization_counter(); + stat_dump_finish(); stat_finish_pattern_history(fname); @@ -2239,6 +2265,8 @@ void firm_init_stat(unsigned enable_options) /* distribution table for parameter counts */ status->dist_param_cnt = stat_new_int_distrib_tbl(); + clear_optimization_counter(); + #undef HOOK #undef X } /* firm_init_stat */ diff --git a/ir/stat/firmstat_t.h b/ir/stat/firmstat_t.h index 8d48773cb..90ed0246a 100644 --- a/ir/stat/firmstat_t.h +++ b/ir/stat/firmstat_t.h @@ -289,6 +289,11 @@ typedef void (*dump_const_table_FUNC)(dumper_t *dmp, const constant_info_t *tbl) */ typedef void (*dump_param_tbl_FUNC)(dumper_t *dmp, const distrib_tbl_t *tbl, graph_entry_t *global); +/** + * dumps the optimizations counter + */ +typedef void (*dump_opt_cnt_FUNC)(dumper_t *dumper, const counter_t *tbl, unsigned len); + /** * handler for dumper init * @@ -328,7 +333,9 @@ typedef struct _statistic_info_t { dumper_t *dumper; /**< list of dumper */ int reassoc_run; /**< if set, reassociation is running */ constant_info_t const_info; /**< statistic info for constants */ - distrib_tbl_t *dist_param_cnt; /**< distributation table for call parameters */ + distrib_tbl_t *dist_param_cnt; /**< distribution table for call parameters */ + + counter_t num_opts[FS_OPT_MAX];/**< count optimizations */ } stat_info_t; /** @@ -337,7 +344,8 @@ typedef struct _statistic_info_t { struct _dumper_t { dump_graph_FUNC dump_graph; /**< handler for dumping an irg */ dump_const_table_FUNC dump_const_tbl; /**< handler for dumping a const table */ - dump_param_tbl_FUNC dump_param_tbl; /**< handler for dumper the Call parameter table */ + dump_param_tbl_FUNC dump_param_tbl; /**< handler for dumping the Call parameter table */ + dump_opt_cnt_FUNC dump_opt_cnt; /**< handler for dumping the optimization table. */ dump_init_FUNC init; /**< handler for init */ dump_finish_FUNC finish; /**< handler for finish */ FILE *f; /**< the file to dump to */ diff --git a/ir/stat/stat_dmp.c b/ir/stat/stat_dmp.c index aa4913bde..42fd8e0d9 100644 --- a/ir/stat/stat_dmp.c +++ b/ir/stat/stat_dmp.c @@ -179,17 +179,24 @@ static void simple_dump_opcode_hash(dumper_t *dmp, pset *set) } /* simple_dump_opcode_hash */ /** - * dumps an optimization hash into human readable form + * Return the name of an optimization. */ -static void simple_dump_opt_hash(dumper_t *dmp, pset *set, int index) -{ +static const char *get_opt_name(int index) { assert(index < (int) ARR_SIZE(opt_names) && "index out of range"); assert((int) opt_names[index].kind == index && "opt_names broken"); + return opt_names[index].name; +} /* get_opt_name */ +/** + * dumps an optimization hash into human readable form + */ +static void simple_dump_opt_hash(dumper_t *dmp, pset *set, int index) +{ if (pset_count(set) > 0) { opt_entry_t *entry; + const char *name = get_opt_name(index); - fprintf(dmp->f, "\n%s:\n", opt_names[index].name); + fprintf(dmp->f, "\n%s:\n", name); fprintf(dmp->f, "%-16s %-8s\n", "Opcode", "deref"); foreach_pset(set, entry) { @@ -604,6 +611,24 @@ static void simple_dump_param_tbl(dumper_t *dmp, const distrib_tbl_t *tbl, graph fprintf(dmp->f, "with local var adr params %12u\n", cnt_to_uint(&global->cnt[gcnt_call_with_local_adr])); } /* simple_dump_param_tbl */ +/** + * dumps the optimization counter table + */ +static void simple_dump_opt_cnt(dumper_t *dmp, const counter_t *tbl, unsigned len) { + unsigned i; + + fprintf(dmp->f, "\nOptimization counts:\n"); + fprintf(dmp->f, "---------------------\n"); + + for (i = 0; i < len; ++i) { + unsigned cnt = cnt_to_uint(&tbl[i]); + + if (cnt > 0) { + fprintf(dmp->f, "%8u %s\n", cnt, get_opt_name(i)); + } + } +} /* simple_dump_opt_cnt */ + /** * initialize the simple dumper */ @@ -633,6 +658,7 @@ const dumper_t simple_dumper = { simple_dump_graph, simple_dump_const_tbl, simple_dump_param_tbl, + simple_dump_opt_cnt, simple_init, simple_finish, NULL, @@ -734,6 +760,16 @@ static void csv_dump_param_tbl(dumper_t *dmp, const distrib_tbl_t *tbl, graph_en /* FIXME: NYI */ } /* csv_dump_param_tbl */ +/** + * dumps the optimization counter + */ +static void csv_dump_opt_cnt(dumper_t *dmp, const counter_t *tbl, unsigned len) { + (void) dmp; + (void) tbl; + (void) len; + /* FIXME: NYI */ +} /* csv_dump_opt_cnt */ + /** * initialize the simple dumper */ @@ -764,6 +800,7 @@ const dumper_t csv_dumper = { csv_dump_graph, csv_dump_const_tbl, csv_dump_param_tbl, + csv_dump_opt_cnt, csv_init, csv_finish, NULL, -- 2.20.1