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];
62 void phi_stat_reset(void) {
65 for (i = 0; i < ASIZE; ++i)
67 curr_vals[I_SPACE1] = -1;
68 curr_vals[I_SPACE2] = -1;
69 curr_vals[I_SPACE3] = -1;
74 * Collect general data
76 static void stat_walker(ir_node *node, void *env) {
78 curr_vals[I_ALL_NODES]++;
80 /* count all block nodes */
82 curr_vals[I_BLOCKS]++;
87 * Collect phi node data
89 static void phi_node_stat(ir_node *node) {
92 /* count all phi nodes */
96 arity = get_irn_arity(node);
97 curr_vals[I_ARG] += arity;
98 if (arity > MAX_ARITY)
99 curr_vals[I_ARITY_E]++;
101 curr_vals[I_ARITY_S + arity]++;
103 /* type of argument {const, pred, glob} */
104 for (i = 0; i < arity; i++) {
105 ir_node *block_of_arg, *block_ith_pred;
106 ir_node *arg = get_irn_n(node, i);
108 if (iro_Const == get_irn_opcode(arg)) {
109 curr_vals[I_CONST]++;
113 block_of_arg = get_nodes_block(arg);
114 block_ith_pred = get_nodes_block(get_irn_n(get_nodes_block(node), i));
116 if (block_of_arg == block_ith_pred) {
127 * Collect phi class data
129 static void phi_class_stat(pset *pc) {
130 int i, o, size, doit, sth_interfered;
131 ir_node **members, *p;
133 /* phi class count */
134 curr_vals[I_PHICLS]++;
137 size = pset_count(pc);
138 if (size > MAX_CLS_SIZE)
139 curr_vals[I_CLS_SIZE_E]++;
141 curr_vals[I_CLS_SIZE_S + size]++;
143 /* get an array of all members for double iterating */
144 members = malloc(size * sizeof(*members));
145 for (i = 0, p = pset_first(pc); p; p = pset_next(pc))
149 /* determine interference of phi class members */
150 curr_vals[I_VALUES] += size;
152 for (i = 0; i < size-1; ++i) {
154 for (o = i+1; o < size; ++o) {
155 curr_vals[I_PAIRS]++;
156 if (values_interfere(members[i], members[o])) {
158 curr_vals[I_PAIRSI]++;
160 curr_vals[I_VALUESI]++;
167 /* Does this phi class have an inner interference? */
168 curr_vals[I_PHICLSI] += sth_interfered;
174 void phi_stat_collect(ir_graph *irg, pset *all_phi_nodes, pset *all_phi_classes) {
178 irg_walk_graph(irg, stat_walker, NULL, NULL);
179 curr_vals[I_BLOCKS] -= 2;
181 for (n = pset_first(all_phi_nodes); n; n = pset_next(all_phi_nodes))
184 for (pc = pset_first(all_phi_classes); pc; pc = pset_next(all_phi_classes))
190 * Dump statistic values in raw format
192 static void dump_file(char *filename, int stat[ASIZE]) {
196 if (! (file = fopen(filename, "wt"))) {
197 fprintf(stderr, "Cannot open file for writing: %s\n", filename);
201 for (i = 0; i < ASIZE; i++) {
202 if (i >= I_ARITY_S && i <= I_ARITY_E)
203 fprintf(file, "%i %i\n", stat[i], stat[I_PHIS]);
204 else if (i >= I_CLS_SIZE_S && i <= I_CLS_SIZE_E)
205 fprintf(file, "%i %i\n", stat[i], stat[I_PHICLS]);
207 fprintf(file, "%i\n", stat[i]);
214 void phi_stat_update(char *filename) {
223 all = fopen(filename, "rt");
226 for (i = 0; i < ASIZE; i++) {
227 if (i >= I_ARITY_S && i <= I_ARITY_E)
228 fscanf(all, "%i %i\n", &vals[i], &vals[I_PHIS]);
229 else if (i >= I_CLS_SIZE_S && i <= I_CLS_SIZE_E)
230 fscanf(all, "%i %i\n", &vals[i], &vals[I_PHICLS]);
232 fscanf(all, "%i\n", &vals[i]);
236 for (i = 0; i < ASIZE; i++)
240 /* add current values */
241 for (i = 0; i < ASIZE; i++)
242 vals[i] += curr_vals[i];
245 dump_file(filename, vals);
249 void phi_stat_dump(char *filename) {
251 dump_file(filename, curr_vals);
255 void phi_stat_dump_pretty(char *filename) {
259 if (! (out = fopen(filename, "wt"))) {
260 fprintf(stderr, "Cannot open file for writing: %s\n", filename);
264 fprintf(out, "\nPhi argument types\n");
265 fprintf(out, "Total %4d\n", curr_vals[I_ARG]);
266 fprintf(out, "Constants %4d\n", curr_vals[I_CONST]);
267 fprintf(out, "CF-Pred %4d\n", curr_vals[I_PRED]);
268 fprintf(out, "Others %4d\n", curr_vals[I_GLOB]);
270 fprintf(out, "\nPhi class interference\n");
271 fprintf(out, "Blocks %4d\n", curr_vals[I_BLOCKS]);
272 fprintf(out, "Phis %4d\n", curr_vals[I_PHIS]);
273 fprintf(out, "Interf classes %4d of %4d\n", curr_vals[I_PHICLSI], curr_vals[I_PHICLS]);
274 fprintf(out, "Interf pairs %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_PAIRS]);
275 fprintf(out, "Interf values %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_VALUES]);
277 fprintf(out, "\nPhi arity\n");
278 for (i = I_ARITY_S; i<=I_ARITY_E; i++)
279 fprintf(out, "%2i %4d\n", i-I_ARITY_S, curr_vals[i]);
281 fprintf(out, "\nPhi class sizes\n");
282 for (i = I_CLS_SIZE_S; i<=I_CLS_SIZE_E; i++)
283 fprintf(out, "%2i %4d\n", i-I_CLS_SIZE_S, curr_vals[i]);
285 fprintf(out, "\n\nTotal nodes: %4d\n", curr_vals[I_ALL_NODES]);