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;
80 be_lv_foreach(ra->chordal_env->lv, bb, be_lv_state_end, i) {
81 ir_node *value = be_lv_get_irn(ra->chordal_env->lv, bb, i);
82 if (has_reg_class(ra, value)) {
83 pset_insert_ptr(live, value);
86 stat[regpressure(live)]++;
88 sched_foreach_reverse(bb, irn) {
90 if(is_Phi(irn)) break;
92 if(has_reg_class(ra, irn)) {
93 pset_remove_ptr(live, irn);
96 for(i=get_irn_arity(irn)-1; i>=0; --i) {
97 ir_node *arg = get_irn_n(irn, i);
99 if(has_reg_class(ra, arg)) {
100 pset_insert_ptr(live, arg);
104 if(!is_Proj(irn)) stat[regpressure(live)]++;
109 be_analyze_regpressure(const be_chordal_env_t * chordal_env, const char * suffix)
111 regpressure_ana_t ra;
112 unsigned int stat[MAXPRESSURE+1];
117 ir_snprintf(fname, sizeof(fname), "%F_%s%s_pressure.stat", chordal_env->irg, chordal_env->cls->name, suffix);
118 f = fopen(fname, "w");
121 FIRM_DBG_REGISTER(ra.dbg, "firm.be.regpressureana");
123 ra.chordal_env = chordal_env;
124 ra.cls = chordal_env->cls;
127 memset(stat, 0, sizeof(stat));
129 irg_block_walk_graph(chordal_env->irg, regpressureanawalker, NULL, &ra);
131 for(i=0; i<=MAXPRESSURE; ++i) {
132 fprintf(f,"%d\n",stat[i]);