From d71a3bd2c4a9535b8d983952f9d3951db2ff205a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20W=C3=BCrdig?= Date: Fri, 19 May 2006 15:11:08 +0000 Subject: [PATCH] added ability to register additional dumper functions for each dumper added identifier for dumper [r7785] --- ir/stat/firmstat.c | 59 +++++++++++++++++++++++++++++++++++++++++--- ir/stat/firmstat_t.h | 9 +++++++ ir/stat/stat_dmp.c | 4 +++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/ir/stat/firmstat.c b/ir/stat/firmstat.c index f764d2dc6..42dc88706 100644 --- a/ir/stat/firmstat.c +++ b/ir/stat/firmstat.c @@ -313,9 +313,9 @@ static graph_entry_t *graph_get_entry(ir_graph *irg, hmap_graph_entry_t *hmap) graph_clear_entry(elem, 1); /* new hash table for opcodes here */ - elem->opcode_hash = new_pset(opcode_cmp, 5); - elem->address_mark = new_set(address_mark_cmp, 5); - elem->irg = irg; + elem->opcode_hash = new_pset(opcode_cmp, 5); + elem->address_mark = new_set(address_mark_cmp, 5); + elem->irg = irg; /* these hash tables are created on demand */ elem->block_hash = NULL; @@ -1115,7 +1115,7 @@ static void stat_register_dumper(const dumper_t *dumper) dumper_t *p = xmalloc(sizeof(*p)); if (p) { - *p = *dumper; + memcpy(p, dumper, sizeof(*p)); p->next = status->dumper; p->status = status; @@ -1138,6 +1138,23 @@ static void stat_dump_graph(graph_entry_t *entry) } } +/** + * calls all registered functions. + */ +static void stat_dump_registered(graph_entry_t *entry) +{ + dumper_t *dumper; + + for (dumper = status->dumper; dumper; dumper = dumper->next) { + if (dumper->func_map) { + dump_graph_FUNC func; + + foreach_pset(dumper->func_map, func) + func(dumper, entry); + } + } +} + /** * dumps a constant table */ @@ -1177,6 +1194,19 @@ static void stat_dump_finish(void) } } +/** + * register an additional function for all dumper + */ +void stat_register_dumper_func(dump_graph_FUNC func) { + dumper_t *dumper; + + for (dumper = status->dumper; dumper; dumper = dumper->next) { + if (! dumper->func_map) + dumper->func_map = pset_new_ptr(3); + pset_insert_ptr(dumper->func_map, func); + } +} + /* ---------------------------------------------------------------------- */ /* @@ -1880,6 +1910,7 @@ void stat_dump_snapshot(const char *name, const char *phase) if (! entry->is_deleted || status->stat_options & FIRMSTAT_COUNT_DELETED) { stat_dump_graph(entry); + stat_dump_registered(entry); } if (! entry->is_deleted) { @@ -2039,11 +2070,31 @@ void firm_init_stat(unsigned enable_options) #undef X } +/** + * Frees all dumper structures; + */ +static void stat_term_dumper() { + dumper_t *dumper, *next_dumper; + + for (dumper = status->dumper; dumper; /* iteration done in loop body */ ) { + if (dumper->func_map) + del_pset(dumper->func_map); + + next_dumper = dumper->next; + free(dumper); + dumper = next_dumper; + } +} + + /* terminates the statistics module, frees all memory */ void stat_term(void) { if (status != (stat_info_t *)&status_disable) { obstack_free(&status->be_data, NULL); obstack_free(&status->cnts, NULL); + + stat_term_dumper(); + xfree(status); status = (stat_info_t *)&status_disable; } diff --git a/ir/stat/firmstat_t.h b/ir/stat/firmstat_t.h index 6954e037b..ac51b8d98 100644 --- a/ir/stat/firmstat_t.h +++ b/ir/stat/firmstat_t.h @@ -289,6 +289,8 @@ struct _dumper_t { FILE *f; /**< the file to dump to */ stat_info_t *status; /**< access to the global status */ dumper_t *next; /**< link to the next dumper */ + pset *func_map; /**< pset containing all registered functions */ + unsigned tag; /**< the id tag of the dumper */ }; /** @@ -438,5 +440,12 @@ void stat_be_block_stat_perm(const char *class_name, int n_regs, ir_node *perm, void stat_be_block_stat_permcycle(const char *class_name, ir_node *perm, ir_node *block, int is_chain, int size, int n_ops); +/** + * Register an additional function for all dumper. This function + * is called in dump_snapshot once for each graph_entry and dumper. + * + * @param func the dump function to register + */ +void stat_register_dumper_func(dump_graph_FUNC func); #endif /* _FIRMSTAT_T_H_ */ diff --git a/ir/stat/stat_dmp.c b/ir/stat/stat_dmp.c index 70b72b135..9f70d5b28 100644 --- a/ir/stat/stat_dmp.c +++ b/ir/stat/stat_dmp.c @@ -548,6 +548,8 @@ const dumper_t simple_dumper = { NULL, NULL, NULL, + NULL, + FOURCC('S', 'M', 'P', 'L'), }; /* ---------------------------------------------------------------------- */ @@ -668,4 +670,6 @@ const dumper_t csv_dumper = { NULL, NULL, NULL, + NULL, + FOURCC('C', 'S', 'V', '\0') }; -- 2.20.1