From: Christian Würdig Date: Fri, 7 Apr 2006 14:04:51 +0000 (+0000) Subject: added reg pressure statitics X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=fc2d3435186c4624d0afe61bebf51b9af2c1573d;p=libfirm added reg pressure statitics --- diff --git a/ir/be/bemain.c b/ir/be/bemain.c index a07a214b3..5c6ffe191 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -55,6 +55,7 @@ #include "bessadestr.h" #include "beabi.h" #include "belower.h" +#include "bestat.h" #define DUMP_INITIAL (1 << 0) #define DUMP_ABI (1 << 1) @@ -338,6 +339,9 @@ static void be_main_loop(FILE *file_handle) /* Verify the schedule */ sched_verify_irg(irg); + /* do some statistics */ + be_do_stat_reg_pressure(&birg); + /* Do register allocation */ arch_code_generator_before_ra(birg.cg); ra->allocate(&birg); diff --git a/ir/be/bestat.c b/ir/be/bestat.c new file mode 100644 index 000000000..605eb0456 --- /dev/null +++ b/ir/be/bestat.c @@ -0,0 +1,58 @@ +#include "irnode_t.h" +#include "irprintf.h" +#include "irgwalk.h" +#include "irhooks.h" +#include "dbginfo_t.h" +#include "firmstat.h" +#include "ident.h" + +#include "bestat.h" +#include "belive_t.h" +#include "besched.h" + +/** + * Compare two live entries. + */ +static int cmp_irn_live(const void *a, const void *b) +{ + const irn_live_t *p = a; + const irn_live_t *q = b; + + return !(p->block == q->block && p->irn == q->irn); +} + +/** + * Collect reg pressure statistics per block and per class. + */ +static void stat_reg_pressure_block(ir_node *block, void *env) { + be_irg_t *birg = env; + const arch_env_t *aenv = birg->main_env->arch_env; + int i, n = arch_isa_get_n_reg_class(aenv->isa); + + for (i = 0; i < n; i++) { + const arch_register_class_t *cls = arch_isa_get_reg_class(aenv->isa, i); + ir_node *irn; + pset *live_nodes = new_pset(cmp_irn_live, 64); + int max_live; + + live_nodes = be_liveness_end_of_block(aenv, cls, block, live_nodes); + max_live = pset_count(live_nodes); + + sched_foreach_reverse(block, irn) { + int cnt; + + live_nodes = be_liveness_transfer(aenv, cls, irn, live_nodes); + cnt = pset_count(live_nodes); + + max_live = cnt < max_live ? max_live : cnt; + } + + hook_be_block_regpressure(block, birg->irg, max_live, new_id_from_str(cls->name)); + ir_printf("max regpressure %+F: %d\n", block, max_live); + } +} + +void be_do_stat_reg_pressure(be_irg_t *birg) { + /* Collect register pressure information for each block */ + irg_block_walk_graph(birg->irg, stat_reg_pressure_block, NULL, birg); +} diff --git a/ir/be/bestat.h b/ir/be/bestat.h new file mode 100644 index 000000000..2d7c9692f --- /dev/null +++ b/ir/be/bestat.h @@ -0,0 +1,12 @@ +#ifndef _BESTAT_H_ +#define _BESTAT_H_ + +#include "be_t.h" + +/** + * Collects statistics information about register pressure. + * @param birg The be irg object containing the irg + */ +void be_do_stat_reg_pressure(be_irg_t *birg); + +#endif /* _BESTAT_H_ */ \ No newline at end of file