2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 /** vim: set sw=4 ts=4:
21 * @file bepressurestat.c
23 * @author Adam M. Szalkowski
25 * Register Pressure Statistics
27 * Copyright (C) 2006 Universitaet Karlsruhe
28 * Released under the GPL
53 #include <libcore/lc_bitset.h>
57 #include "besched_t.h"
62 #include "bespillremat.h"
65 #include "bechordal_t.h"
67 #define MAXPRESSURE 128
69 typedef struct _regpressure_ana_t {
71 const arch_register_class_t *cls;
74 DEBUG_ONLY(firm_dbg_module_t * dbg);
78 has_reg_class(const regpressure_ana_t * ra, const ir_node * irn)
80 return arch_irn_consider_in_reg_alloc(ra->arch_env, ra->cls, irn);
84 regpressure(pset * live)
86 int pressure = pset_count(live);
88 return (pressure>MAXPRESSURE)?MAXPRESSURE:pressure;
92 regpressureanawalker(ir_node * bb, void * data)
94 regpressure_ana_t *ra = data;
95 pset *live = pset_new_ptr_default();
97 unsigned int *stat = ra->stat;
99 const be_lv_t *lv = ra->lv;
101 be_lv_foreach(lv, bb, be_lv_state_end, i) {
102 ir_node *value = be_lv_get_irn(lv, bb, i);
103 if (has_reg_class(ra, value)) {
104 pset_insert_ptr(live, value);
107 stat[regpressure(live)]++;
109 sched_foreach_reverse(bb, irn) {
111 if(is_Phi(irn)) break;
113 if(has_reg_class(ra, irn)) {
114 pset_remove_ptr(live, irn);
117 for(i=get_irn_arity(irn)-1; i>=0; --i) {
118 ir_node *arg = get_irn_n(irn, i);
120 if(has_reg_class(ra, arg)) {
121 pset_insert_ptr(live, arg);
125 if(!is_Proj(irn)) stat[regpressure(live)]++;
130 be_analyze_regpressure(be_irg_t *birg, const arch_register_class_t *cls,
133 regpressure_ana_t ra;
134 unsigned int stat[MAXPRESSURE+1];
138 ir_graph *irg = be_get_birg_irg(birg);
140 ir_snprintf(fname, sizeof(fname), "%F_%s%s_pressure.stat", irg, cls->name, suffix);
141 f = fopen(fname, "w");
144 be_assure_liveness(birg);
146 FIRM_DBG_REGISTER(ra.dbg, "firm.be.regpressureana");
148 ra.arch_env = birg->main_env->arch_env;
149 ra.lv = be_get_birg_liveness(birg);
153 memset(stat, 0, sizeof(stat));
155 irg_block_walk_graph(irg, regpressureanawalker, NULL, &ra);
157 for(i=0; i<=MAXPRESSURE; ++i) {
158 fprintf(f,"%d\n",stat[i]);