19 #include "bechordal.h"
23 #define MAX_CLS_SIZE 10
26 * For an explanation of these values see phi_stat_dump_pretty
46 I_ARITY_E = I_ARITY_S+MAX_ARITY,
50 I_CLS_SIZE_E = I_CLS_SIZE_S+MAX_CLS_SIZE,
56 * Holds current values. Values are added till next
59 static int curr_vals[ASIZE];
63 * Resets the array holding the data
65 void phi_stat_reset(void) {
68 for (i = 0; i < ASIZE; ++i)
70 curr_vals[I_SPACE1] = -1;
71 curr_vals[I_SPACE2] = -1;
72 curr_vals[I_SPACE3] = -1;
77 * Collect general data
79 static void stat_walker(ir_node *node, void *env) {
81 curr_vals[I_ALL_NODES]++;
83 /* count all block nodes */
85 curr_vals[I_BLOCKS]++;
90 * Collect phi node data
92 static void phi_node_stat(ir_node *node) {
95 /* count all phi nodes */
99 arity = get_irn_arity(node);
100 curr_vals[I_ARG] += arity;
101 if (arity > MAX_ARITY)
102 curr_vals[I_ARITY_E]++;
104 curr_vals[I_ARITY_S + arity]++;
106 /* type of argument {const, pred, glob} */
107 for (i = 0; i < arity; i++) {
108 ir_node *block_of_arg, *block_ith_pred;
109 ir_node *arg = get_irn_n(node, i);
111 if (iro_Const == get_irn_opcode(arg)) {
112 curr_vals[I_CONST]++;
116 block_of_arg = get_nodes_block(arg);
117 block_ith_pred = get_nodes_block(get_irn_n(get_nodes_block(node), i));
119 if (block_of_arg == block_ith_pred) {
130 * Collect phi class data
132 static void phi_class_stat(pset *pc) {
133 int i, o, size, doit, sth_interfered;
134 ir_node **members, *p;
136 /* phi class count */
137 curr_vals[I_PHICLS]++;
140 size = pset_count(pc);
141 if (size > MAX_CLS_SIZE)
142 curr_vals[I_CLS_SIZE_E]++;
144 curr_vals[I_CLS_SIZE_S + size]++;
146 /* get an array of all members for double iterating */
147 members = (ir_node **) malloc(size * sizeof(ir_node*));
148 for (i=0, p = (ir_node *)pset_first(pc); p; p = (ir_node *)pset_next(pc))
152 /* determine interference of phi class members */
153 curr_vals[I_VALUES] += size;
155 for (i = 0; i < size-1; ++i) {
157 for (o = i+1; o < size; ++o) {
158 curr_vals[I_PAIRS]++;
159 if (phi_ops_interfere(members[i], members[o])) {
161 curr_vals[I_PAIRSI]++;
163 curr_vals[I_VALUESI]++;
170 /* Does this phi class have an inner interference? */
171 curr_vals[I_PHICLSI] += sth_interfered;
178 * Collect all stat data
180 void phi_stat_collect(ir_graph *irg, pset *all_phi_nodes, pset *all_phi_classes) {
184 irg_walk_graph(irg, stat_walker, NULL, NULL);
185 curr_vals[I_BLOCKS] -= 2;
187 for (n = (ir_node *)pset_first(all_phi_nodes); n; n = (ir_node *)pset_next(all_phi_nodes))
190 for (pc = (pset *)pset_first(all_phi_classes); pc; pc = (pset *)pset_next(all_phi_classes))
196 * Dump statistic values in raw format
198 static void dump_file(char *filename, int stat[ASIZE]) {
202 if (! (file = fopen(filename, "wt"))) {
203 fprintf(stderr, "Cannot open file for writing: %s\n", filename);
207 for (i = 0; i < ASIZE; i++) {
208 if (i >= I_ARITY_S && i <= I_ARITY_E)
209 fprintf(file, "%i %i\n", stat[i], stat[I_PHIS]);
210 else if (i >= I_CLS_SIZE_S && i <= I_CLS_SIZE_E)
211 fprintf(file, "%i %i\n", stat[i], stat[I_PHICLS]);
213 fprintf(file, "%i\n", stat[i]);
221 * Updates a cumulative file with the current values.
223 void phi_stat_update(char *filename) {
232 all = fopen(filename, "rt");
235 for (i = 0; i < ASIZE; i++) {
236 if (i >= I_ARITY_S && i <= I_ARITY_E)
237 fscanf(all, "%i %i\n", &vals[i], &vals[I_PHIS]);
238 else if (i >= I_CLS_SIZE_S && i <= I_CLS_SIZE_E)
239 fscanf(all, "%i %i\n", &vals[i], &vals[I_PHICLS]);
241 fscanf(all, "%i\n", &vals[i]);
245 for (i = 0; i < ASIZE; i++)
249 /* add current values */
250 for (i = 0; i < ASIZE; i++)
251 vals[i] += curr_vals[i];
254 dump_file(filename, vals);
259 * Dumps the current contents of the values array to a file.
260 * Updates a cumulative file.
262 void phi_stat_dump(char *filename) {
264 dump_file(filename, curr_vals);
269 * Dumps the current contents of the values array
270 * and annotations to a file.
272 void phi_stat_dump_pretty(char *filename) {
276 if (! (out = fopen(filename, "wt"))) {
277 fprintf(stderr, "Cannot open file for writing: %s\n", filename);
281 fprintf(out, "\nPhi argument types\n");
282 fprintf(out, "Total %4d\n", curr_vals[I_ARG]);
283 fprintf(out, "Constants %4d\n", curr_vals[I_CONST]);
284 fprintf(out, "CF-Pred %4d\n", curr_vals[I_PRED]);
285 fprintf(out, "Others %4d\n", curr_vals[I_GLOB]);
287 fprintf(out, "\nPhi class interference\n");
288 fprintf(out, "Blocks %4d\n", curr_vals[I_BLOCKS]);
289 fprintf(out, "Phis %4d\n", curr_vals[I_PHIS]);
290 fprintf(out, "Interf classes %4d of %4d\n", curr_vals[I_PHICLSI], curr_vals[I_PHICLS]);
291 fprintf(out, "Interf pairs %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_PAIRS]);
292 fprintf(out, "Interf values %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_VALUES]);
294 fprintf(out, "\nPhi arity\n");
295 for (i = I_ARITY_S; i<=I_ARITY_E; i++)
296 fprintf(out, "%2i %4d\n", i-I_ARITY_S, curr_vals[i]);
298 fprintf(out, "\nPhi class sizes\n");
299 for (i = I_CLS_SIZE_S; i<=I_CLS_SIZE_E; i++)
300 fprintf(out, "%2i %4d\n", i-I_CLS_SIZE_S, curr_vals[i]);
302 fprintf(out, "\n\nTotal nodes: %4d\n", curr_vals[I_ALL_NODES]);