4 * Copyright: (c) Universitaet Karlsruhe
5 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
14 #include "phiclass_t.h"
15 #include "becopyopt.h"
16 #include "becopystat.h"
21 #define DEBUG_LVL 0 //SET_LEVEL_1
22 static firm_dbg_module_t *dbg = NULL;
24 static pset *all_phi_nodes;
25 static pset *all_phi_classes;
26 static pset *all_copy_nodes;
28 void copystat_init(void) {
29 dbg = firm_dbg_register("ir.be.copystat");
30 firm_dbg_set_mask(dbg, DEBUG_LVL);
32 all_phi_nodes = pset_new_ptr_default();
33 all_phi_classes = pset_new_ptr_default();
34 all_copy_nodes = pset_new_ptr_default();
38 void copystat_reset(void) {
40 for (i = 0; i < ASIZE; ++i)
42 del_pset(all_phi_nodes);
43 del_pset(all_phi_classes);
44 del_pset(all_copy_nodes);
45 all_phi_nodes = pset_new_ptr_default();
46 all_phi_classes = pset_new_ptr_default();
47 all_copy_nodes = pset_new_ptr_default();
51 * Collect general data
53 static void stat_walker(ir_node *node, void *env) {
54 curr_vals[I_ALL_NODES]++; /* count all nodes */
56 if (is_Block(node)) /* count all blocks */
57 curr_vals[I_BLOCKS]++;
59 if (is_Phi(node)) /* collect phis */
60 pset_insert_ptr(all_phi_nodes, node);
63 pset_insert_ptr(all_copy_nodes, node);
67 * Collect phi node data
69 static void stat_phi_node(be_chordal_env_t *chordal_env, ir_node *phi) {
73 /* count all phi phis */
74 curr_vals[I_PHI_CNT]++;
77 arity = get_irn_arity(phi);
78 curr_vals[I_PHI_ARG_CNT] += arity;
79 if (arity > MAX_ARITY)
80 curr_vals[I_PHI_ARITY_E]++;
82 curr_vals[I_PHI_ARITY_S + arity]++;
84 /* type of argument {self, const, pred, glob} */
85 for (i = 0; i < arity; i++) {
86 ir_node *block_of_arg, *block_ith_pred;
87 ir_node *arg = get_irn_n(phi, i);
90 curr_vals[I_COPIES_MAX]++; /* if arg!=phi this is a possible copy */
91 if (nodes_interfere(chordal_env, phi, arg)) {
92 DBG((dbg, LEVEL_1, "%e -- In Block %N: %n %N %n %N\n", get_irg_entity(chordal_env->irg), get_nodes_block(phi), phi, phi, arg, arg));
93 curr_vals[I_COPIES_IF]++;
98 curr_vals[I_PHI_ARG_SELF]++;
102 if (iro_Const == get_irn_opcode(arg)) {
103 curr_vals[I_PHI_ARG_CONST]++;
107 block_of_arg = get_nodes_block(arg);
108 block_ith_pred = get_nodes_block(get_irn_n(get_nodes_block(phi), i));
109 if (block_of_arg == block_ith_pred) {
110 curr_vals[I_PHI_ARG_PRED]++;
114 curr_vals[I_PHI_ARG_GLOB]++;
119 * Collect register-constrained node data
121 static void stat_copy_node(be_chordal_env_t *chordal_env, ir_node *root) {
122 curr_vals[I_CPY_CNT]++;
123 curr_vals[I_COPIES_MAX]++;
124 if (nodes_interfere(chordal_env, root, get_Copy_src(root))) {
125 curr_vals[I_COPIES_IF]++;
126 assert(0 && "A Perm pair (in/out) should never interfere!");
131 * Collect phi class data
133 static void stat_phi_class(be_chordal_env_t *chordal_env, pset *pc) {
134 int i, o, size, if_free;
135 ir_node **members, *p;
137 /* phi class count */
138 curr_vals[I_CLS_CNT]++;
141 size = pset_count(pc);
142 if (size > MAX_CLS_SIZE)
143 curr_vals[I_CLS_SIZE_E]++;
145 curr_vals[I_CLS_SIZE_S + size]++;
147 /* get an array of all members for double iterating */
148 members = xmalloc(size * sizeof(*members));
149 for (i = 0, p = pset_first(pc); p; p = pset_next(pc))
153 /* determine interference of phi class members */
154 curr_vals[I_CLS_IF_MAX] += size*(size-1)/2;
156 for (i = 0; i < size-1; ++i)
157 for (o = i+1; o < size; ++o)
158 if (nodes_interfere(chordal_env, members[i], members[o])) {
160 curr_vals[I_CLS_IF_CNT]++;
163 /* Does this phi class have an inner interference? */
164 curr_vals[I_CLS_IF_FREE] += if_free;
169 void copystat_collect_irg(ir_graph *irg) {
170 irg_walk_graph(irg, stat_walker, NULL, NULL);
171 curr_vals[I_BLOCKS] -= 2; /* substract 2 for start and end block */
172 all_phi_classes = phi_class_compute_by_phis(all_phi_nodes);
175 #define is_curr_reg_class(irn) (arch_get_irn_reg_class(chordal_env->arch_env, irn, arch_pos_make_out(0)) == chordal_env->cls)
177 void copystat_collect_cls(be_chordal_env_t *chordal_env) {
181 for (n = pset_first(all_phi_nodes); n; n = pset_next(all_phi_nodes))
182 if (is_curr_reg_class(n))
183 stat_phi_node(chordal_env, n);
185 for (n = pset_first(all_copy_nodes); n; n = pset_next(all_copy_nodes))
186 if (is_curr_reg_class(n))
187 stat_copy_node(chordal_env, n);
189 for (pc = pset_first(all_phi_classes); pc; pc = pset_next(all_phi_classes)) {
190 ir_node *member = pset_first(pc);
192 if (is_curr_reg_class(member))
193 stat_phi_class(chordal_env, pc);
197 void copystat_dump(ir_graph *irg) {
202 snprintf(buf, sizeof(buf), "%s__%s", get_irp_prog_name(), get_entity_name(get_irg_entity(irg)));
203 out = ffopen(buf, "stat", "wt");
205 fprintf(out, "%s\n", get_irp_prog_name());
206 for (i = 0; i < ASIZE; i++) {
207 if (i >= I_PHI_ARITY_S && i <= I_PHI_ARITY_E)
208 fprintf(out, "%i %i\n", curr_vals[i], curr_vals[I_PHI_CNT]);
209 else if (i >= I_CLS_SIZE_S && i <= I_CLS_SIZE_E)
210 fprintf(out, "%i %i\n", curr_vals[i], curr_vals[I_CLS_CNT]);
212 fprintf(out, "%i\n", curr_vals[i]);
218 void copystat_dump_pretty(ir_graph *irg) {
223 snprintf(buf, sizeof(buf), "%s__%s", get_irp_prog_name(), get_entity_name(get_irg_entity(irg)));
224 out = ffopen(buf, "pstat", "wt");
226 fprintf(out, "Nodes %4d\n", curr_vals[I_ALL_NODES]);
227 fprintf(out, "Blocks %4d\n", curr_vals[I_BLOCKS]);
228 fprintf(out, "CopyIrn %4d\n", curr_vals[I_CPY_CNT]);
230 fprintf(out, "\nPhis %4d\n", curr_vals[I_PHI_CNT]);
231 fprintf(out, "... argument types\n");
232 fprintf(out, " Total %4d\n", curr_vals[I_PHI_ARG_CNT]);
233 fprintf(out, " Self %4d\n", curr_vals[I_PHI_ARG_SELF]);
234 fprintf(out, " Constants %4d\n", curr_vals[I_PHI_ARG_CONST]);
235 fprintf(out, " CF-Pred %4d\n", curr_vals[I_PHI_ARG_PRED]);
236 fprintf(out, " Others %4d\n", curr_vals[I_PHI_ARG_GLOB]);
237 fprintf(out, "... arities\n");
238 for (i = I_PHI_ARITY_S; i<=I_PHI_ARITY_E; i++)
239 fprintf(out, " %2i %4d\n", i-I_PHI_ARITY_S, curr_vals[i]);
241 fprintf(out, "\nPhi classes %4d\n", curr_vals[I_CLS_CNT]);
242 fprintf(out, " compl. free %4d\n", curr_vals[I_CLS_IF_FREE]);
243 fprintf(out, " inner intf. %4d / %4d\n", curr_vals[I_CLS_IF_CNT], curr_vals[I_CLS_IF_MAX]);
244 fprintf(out, "... sizes\n");
245 for (i = I_CLS_SIZE_S; i<=I_CLS_SIZE_E; i++)
246 fprintf(out, " %2i %4d\n", i-I_CLS_SIZE_S, curr_vals[i]);
248 fprintf(out, "\nILP stat\n");
249 fprintf(out, " Time %8d\n", curr_vals[I_ILP_TIME]);
250 fprintf(out, " Iter %8d\n", curr_vals[I_ILP_ITER]);
252 fprintf(out, "\nCopy stat\n");
253 fprintf(out, " Max %4d\n", curr_vals[I_COPIES_MAX]);
254 fprintf(out, " Init %4d\n", curr_vals[I_COPIES_INIT]);
255 fprintf(out, " Heur %4d\n", curr_vals[I_COPIES_HEUR]);
256 fprintf(out, " Opt %4d\n", curr_vals[I_COPIES_OPT]);
257 fprintf(out, " Intf %4d\n", curr_vals[I_COPIES_IF]);