18 #include "bephicongr_t.h"
19 #include "bechordal.h"
22 #define SUMMARY_FILE_NAME "all.phistat"
25 #define MAX_CLS_SIZE 10
45 I_ARITY_E = I_ARITY_S+MAX_ARITY,
49 I_CLS_SIZE_E = I_CLS_SIZE_S+MAX_CLS_SIZE,
54 static int curr_vals[ASIZE];
58 * Dump statistic values and some annotations for current irp
60 static void dump_file(void) {
65 next = sprintf(buf, get_irp_prog_name());
66 sprintf(buf+next, ".phistat");
67 out = fopen(buf, "wt");
69 fprintf(out, "\nPhi argument types\n");
70 fprintf(out, "Total %4d\n", curr_vals[I_ARG]);
71 fprintf(out, "Constants %4d\n", curr_vals[I_CONST]);
72 fprintf(out, "CF-Pred %4d\n", curr_vals[I_PRED]);
73 fprintf(out, "Others %4d\n", curr_vals[I_GLOB]);
75 fprintf(out, "\nPhi class interference\n");
76 fprintf(out, "Blocks %4d\n", curr_vals[I_BLOCKS]);
77 fprintf(out, "Phis %4d\n", curr_vals[I_PHIS]);
78 fprintf(out, "Interf classes %4d of %4d\n", curr_vals[I_PHICLSI], curr_vals[I_PHICLS]);
79 fprintf(out, "Interf pairs %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_PAIRS]);
80 fprintf(out, "Interf values %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_VALUES]);
82 fprintf(out, "\nPhi arity\n");
83 for (i = I_ARITY_S; i<=I_ARITY_E; i++)
84 fprintf(out, "%2i %4d\n", i-I_ARITY_S, curr_vals[i]);
86 fprintf(out, "\nPhi class sizes\n");
87 for (i = I_CLS_SIZE_S; i<=I_CLS_SIZE_E; i++)
88 fprintf(out, "%2i %4d\n", i-I_CLS_SIZE_S, curr_vals[i]);
90 fprintf(out, "\n\nTotal nodes: %4d\n", curr_vals[I_ALL_NODES]);
97 * Updates the summary file with cumulated values
99 static void update_all_file(void) {
105 all = fopen(SUMMARY_FILE_NAME, "rt");
107 for (i = 0; i<ASIZE; i++) {
108 if (i >= I_ARITY_S && i <= I_ARITY_E)
109 fscanf(all, "%i %i\n", &vals[i], &vals[I_ALL_NODES]);
111 fscanf(all, "%i\n", &vals[i]);
115 for (i = 0; i<ASIZE; i++)
120 all = fopen(SUMMARY_FILE_NAME, "wt");
121 for (i = 0; i<ASIZE; i++) {
122 if (i >= I_ARITY_S && i <= I_ARITY_E)
123 fprintf(all, "%i %i\n", vals[i]+curr_vals[i], vals[I_ALL_NODES]+curr_vals[I_ALL_NODES]);
125 fprintf(all, "%i\n", vals[i]+curr_vals[i]);
131 * Collect the statistical data
133 static void phi_stat_walker(ir_node *node, void *env) {
136 /* count all nodes */
137 curr_vals[I_ALL_NODES]++;
139 /* count all block nodes */
141 curr_vals[I_BLOCKS]++;
143 if (!(is_Phi(node) && mode_is_datab(get_irn_mode(node)))) return;
145 /* count all phi nodes */
149 arity = get_irn_arity(node);
150 curr_vals[I_ARG] += arity;
151 if (arity > MAX_ARITY)
152 curr_vals[I_ARITY_E]++;
154 curr_vals[I_ARITY_S + arity]++;
156 /* type of argument */
157 for (i = 0; i < arity; i++) {
158 ir_node *block_of_arg, *block_ith_pred;
159 ir_node *arg = get_irn_n(node, i);
161 if (iro_Const == get_irn_opcode(arg)) {
162 curr_vals[I_CONST]++;
166 block_of_arg = get_nodes_block(arg);
167 block_ith_pred = get_nodes_block(get_irn_n(get_nodes_block(node), i));
169 if (block_of_arg == block_ith_pred) {
179 static void phi_class_stat_walker(ir_node *node, void *env) {
180 int i, o, size, doit, sth_interfered;
181 ir_node **members, *p;
184 pc = get_phi_class(node);
187 /* phi class count */
188 curr_vals[I_PHICLS]++;
191 size = pset_count(pc);
192 if (size > MAX_CLS_SIZE)
193 curr_vals[I_CLS_SIZE_E]++;
195 curr_vals[I_CLS_SIZE_S + size]++;
197 /* count interfering pairs / values */
198 members = (ir_node **) malloc(size * sizeof(ir_node*));
200 for (i=0, p = (ir_node *)pset_first(pc); p; p = (ir_node *)pset_next(pc))
204 /* determine interference of phi args */
205 curr_vals[I_VALUES] += size;
207 for (i = 0; i < size-1; ++i) {
209 for (o = i+1; o < size; ++o) {
210 curr_vals[I_PAIRS]++;
211 if (phi_ops_interfere(members[i], members[o])) {
213 curr_vals[I_PAIRSI]++;
215 curr_vals[I_VALUESI]++;
222 /* has this phi class an interference? */
223 curr_vals[I_PHICLSI] += sth_interfered;
229 void do_phi_statistics(void) {
231 curr_vals[I_SPACE1] = -1;
232 curr_vals[I_SPACE2] = -1;
233 curr_vals[I_SPACE3] = -1;
235 for (i = 0, n = get_irp_n_irgs(); i < n; i++) {
236 ir_graph *irg = get_irp_irg(i);
237 irg_walk_graph(irg, phi_stat_walker, NULL, NULL);
238 irg_walk_graph(irg, phi_class_stat_walker, NULL, NULL);
239 curr_vals[I_BLOCKS] -= 2;