2 * Copyright (C) 1995-2008 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
22 * @brief Register Pressure Statistics.
23 * @author Adam M. Szalkowski
53 #include "besched_t.h"
61 #define MAXPRESSURE 128
63 typedef struct _regpressure_ana_t {
65 const arch_register_class_t *cls;
68 DEBUG_ONLY(firm_dbg_module_t *dbg);
71 static INLINE int has_reg_class(const regpressure_ana_t *ra, const ir_node *irn)
73 return arch_irn_consider_in_reg_alloc(ra->cls, irn);
76 static INLINE int regpressure(pset *live) {
77 int pressure = pset_count(live);
78 return MIN(pressure, MAXPRESSURE);
82 regpressureanawalker(ir_node *bb, void *data)
84 regpressure_ana_t *ra = data;
85 pset *live = pset_new_ptr_default();
87 unsigned int *stat = ra->stat;
89 const be_lv_t *lv = ra->lv;
91 be_lv_foreach(lv, bb, be_lv_state_end, i) {
92 ir_node *value = be_lv_get_irn(lv, bb, i);
93 if (has_reg_class(ra, value)) {
94 pset_insert_ptr(live, value);
97 stat[regpressure(live)]++;
99 sched_foreach_reverse(bb, irn) {
101 if (is_Phi(irn)) break;
103 if (has_reg_class(ra, irn)) {
104 pset_remove_ptr(live, irn);
107 for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
108 ir_node *arg = get_irn_n(irn, i);
110 if (has_reg_class(ra, arg)) {
111 pset_insert_ptr(live, arg);
116 stat[regpressure(live)]++;
120 void be_analyze_regpressure(be_irg_t *birg, const arch_register_class_t *cls, const char *suffix)
122 regpressure_ana_t ra;
123 unsigned int stat[MAXPRESSURE+1];
127 ir_graph *irg = be_get_birg_irg(birg);
129 ir_snprintf(fname, sizeof(fname), "%F_%s%s_pressure.stat", irg, cls->name, suffix);
130 f = fopen(fname, "w");
133 be_liveness_assure_sets(be_assure_liveness(birg));
135 FIRM_DBG_REGISTER(ra.dbg, "firm.be.regpressureana");
137 ra.arch_env = birg->main_env->arch_env;
138 ra.lv = be_get_birg_liveness(birg);
142 memset(stat, 0, sizeof(stat));
144 irg_block_walk_graph(irg, regpressureanawalker, NULL, &ra);
146 for (i = 0; i <= MAXPRESSURE; ++i) {
147 fprintf(f, "%d\n", stat[i]);