1 /** vim: set sw=4 ts=4:
2 * @file bepressurestat.c
4 * @author Adam M. Szalkowski
6 * Register Pressure Statistics
8 * Copyright (C) 2006 Universitaet Karlsruhe
9 * Released under the GPL
34 #include <libcore/lc_bitset.h>
38 #include "besched_t.h"
43 #include "bespillremat.h"
46 #include "bechordal_t.h"
48 #define MAXPRESSURE 128
50 typedef struct _regpressure_ana_t {
51 const arch_register_class_t *cls;
52 const be_chordal_env_t *chordal_env;
54 DEBUG_ONLY(firm_dbg_module_t * dbg);
58 has_reg_class(const regpressure_ana_t * ra, const ir_node * irn)
60 return chordal_has_class(ra->chordal_env, irn);
64 regpressure(pset * live)
66 int pressure = pset_count(live);
68 return (pressure>MAXPRESSURE)?MAXPRESSURE:pressure;
72 regpressureanawalker(ir_node * bb, void * data)
74 regpressure_ana_t *ra = data;
75 pset *live = pset_new_ptr_default();
77 unsigned int *stat = ra->stat;
79 be_lv_t *lv = ra->chordal_env->birg->lv;
81 be_lv_foreach(lv, bb, be_lv_state_end, i) {
82 ir_node *value = be_lv_get_irn(lv, bb, i);
83 if (has_reg_class(ra, value)) {
84 pset_insert_ptr(live, value);
87 stat[regpressure(live)]++;
89 sched_foreach_reverse(bb, irn) {
91 if(is_Phi(irn)) break;
93 if(has_reg_class(ra, irn)) {
94 pset_remove_ptr(live, irn);
97 for(i=get_irn_arity(irn)-1; i>=0; --i) {
98 ir_node *arg = get_irn_n(irn, i);
100 if(has_reg_class(ra, arg)) {
101 pset_insert_ptr(live, arg);
105 if(!is_Proj(irn)) stat[regpressure(live)]++;
110 be_analyze_regpressure(const be_chordal_env_t * chordal_env, const char * suffix)
112 regpressure_ana_t ra;
113 unsigned int stat[MAXPRESSURE+1];
118 ir_snprintf(fname, sizeof(fname), "%F_%s%s_pressure.stat", chordal_env->irg, chordal_env->cls->name, suffix);
119 f = fopen(fname, "w");
122 FIRM_DBG_REGISTER(ra.dbg, "firm.be.regpressureana");
124 ra.chordal_env = chordal_env;
125 ra.cls = chordal_env->cls;
128 memset(stat, 0, sizeof(stat));
130 irg_block_walk_graph(chordal_env->irg, regpressureanawalker, NULL, &ra);
132 for(i=0; i<=MAXPRESSURE; ++i) {
133 fprintf(f,"%d\n",stat[i]);