X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fstat%2Ffirmstat.c;h=e05961f07708983aad7f56613e3a3121e912297f;hb=2af4a97900b435e35d7c20350604e3863aff2b4c;hp=7c9a7c4859c519c54ffeeaca0e554ad7387864f4;hpb=48b0fa8564962b17e136a0f925eff458ca16abef;p=libfirm diff --git a/ir/stat/firmstat.c b/ir/stat/firmstat.c index 7c9a7c485..e05961f07 100644 --- a/ir/stat/firmstat.c +++ b/ir/stat/firmstat.c @@ -35,6 +35,7 @@ #include "irdump.h" #include "hashptr.h" #include "firmstat_t.h" +#include "irpass_t.h" #include "pattern.h" #include "dags.h" #include "stat_dmp.h" @@ -225,8 +226,7 @@ static node_entry_t *opcode_get_entry(const ir_op *op, hmap_node_entry_t *hmap) if (elem) return elem; - elem = obstack_alloc(&status->cnts, sizeof(*elem)); - memset(elem, 0, sizeof(*elem)); + elem = OALLOCZ(&status->cnts, node_entry_t); /* clear counter */ opcode_clear_entry(elem); @@ -302,8 +302,7 @@ static graph_entry_t *graph_get_entry(ir_graph *irg, hmap_graph_entry_t *hmap) } /* if */ /* allocate a new one */ - elem = obstack_alloc(&status->cnts, sizeof(*elem)); - memset(elem, 0, sizeof(*elem)); + elem = OALLOCZ(&status->cnts, graph_entry_t); obstack_init(&elem->recalc_cnts); /* clear counter */ @@ -348,8 +347,7 @@ static opt_entry_t *opt_get_entry(const ir_op *op, hmap_opt_entry_t *hmap) if (elem) return elem; - elem = obstack_alloc(&status->cnts, sizeof(*elem)); - memset(elem, 0, sizeof(*elem)); + elem = OALLOCZ(&status->cnts, opt_entry_t); /* clear new counter */ opt_clear_entry(elem); @@ -386,8 +384,7 @@ static block_entry_t *block_get_entry(struct obstack *obst, long block_nr, hmap_ if (elem) return elem; - elem = obstack_alloc(obst, sizeof(*elem)); - memset(elem, 0, sizeof(*elem)); + elem = OALLOCZ(obst, block_entry_t); /* clear new counter */ block_clear_entry(elem); @@ -433,8 +430,7 @@ static be_block_entry_t *be_block_get_entry(struct obstack *obst, long block_nr, if (elem) return elem; - elem = obstack_alloc(obst, sizeof(*elem)); - memset(elem, 0, sizeof(*elem)); + elem = OALLOCZ(obst, be_block_entry_t); /* clear new counter */ be_block_clear_entry(elem); @@ -472,8 +468,7 @@ static perm_class_entry_t *perm_class_get_entry(struct obstack *obst, const char if (elem) return elem; - elem = obstack_alloc(obst, sizeof(*elem)); - memset(elem, 0, sizeof(*elem)); + elem = OALLOCZ(obst, perm_class_entry_t); /* clear new counter */ perm_class_clear_entry(elem); @@ -514,8 +509,7 @@ static perm_stat_entry_t *perm_stat_get_entry(struct obstack *obst, ir_node *per if (elem) return elem; - elem = obstack_alloc(obst, sizeof(*elem)); - memset(elem, 0, sizeof(*elem)); + elem = OALLOCZ(obst, perm_stat_entry_t); /* clear new counter */ perm_stat_clear_entry(elem); @@ -1972,8 +1966,7 @@ void stat_be_block_regpressure(ir_graph *irg, ir_node *block, int pressure, cons reg_pressure_entry_t *rp_ent; block_ent = be_block_get_entry(&status->be_data, get_irn_node_nr(block), graph->be_block_hash); - rp_ent = obstack_alloc(&status->be_data, sizeof(*rp_ent)); - memset(rp_ent, 0, sizeof(*rp_ent)); + rp_ent = OALLOCZ(&status->be_data, reg_pressure_entry_t); rp_ent->class_name = class_name; rp_ent->pressure = pressure; @@ -2131,10 +2124,10 @@ void stat_dump_snapshot(const char *name, const char *phase) fname[0] = '\0'; p = name; } /* if */ - strncat(fname, "firmstat-", sizeof(fname)); - strncat(fname, phase, sizeof(fname)); - strncat(fname, "-", sizeof(fname)); - strncat(fname, p, sizeof(fname)); + strncat(fname, "firmstat-", sizeof(fname)-1); + strncat(fname, phase, sizeof(fname)-1); + strncat(fname, "-", sizeof(fname)-1); + strncat(fname, p, sizeof(fname)-1); stat_dump_init(fname); @@ -2207,6 +2200,60 @@ void stat_dump_snapshot(const char *name, const char *phase) STAT_LEAVE; } /* stat_dump_snapshot */ +struct pass_t { + ir_prog_pass_t pass; + const char *fname; + const char *phase; +}; + +/** + * Wrapper to run stat_dump_snapshot() as a ir_prog wrapper. + */ +static int stat_dump_snapshot_wrapper(ir_prog *irp, void *context) { + struct pass_t *pass = context; + + (void)irp; + stat_dump_snapshot(pass->fname, pass->phase); + return 0; +} /* stat_dump_snapshot_wrapper */ + +/** + * Ensure that no verifier is run from the wrapper. + */ +static int no_verify(ir_prog *prog, void *ctx) +{ + (void)prog; + (void)ctx; + return 0; +} + +/** + * Ensure that no dumper is run from the wrapper. + */ +static void no_dump(ir_prog *prog, void *ctx, unsigned idx) +{ + (void)prog; + (void)ctx; + (void)idx; +} + +/* create an ir_pog pass */ +ir_prog_pass_t *stat_dump_snapshot_pass( + const char *name, const char *fname, const char *phase) { + struct pass_t *pass = XMALLOCZ(struct pass_t); + + def_prog_pass_constructor( + &pass->pass, name ? name : "stat_snapshot", stat_dump_snapshot_wrapper); + pass->fname = fname; + pass->phase = phase; + + /* no dump/verify */ + pass->pass.dump_irprog = no_dump; + pass->pass.verify_irprog = no_verify; + + return &pass->pass; +} /* stat_dump_snapshot_pass */ + /** the hook entries for the Firm statistics module */ static hook_entry_t stat_hooks[hook_last];