19 #include "bechordal.h"
23 #define MAX_CLS_SIZE 10
43 I_ARITY_E = I_ARITY_S+MAX_ARITY,
47 I_CLS_SIZE_E = I_CLS_SIZE_S+MAX_CLS_SIZE,
53 * Holds current values. Values are added till next
56 static int curr_vals[ASIZE];
60 * Resets the array holding the data
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 = (ir_node **) malloc(size * sizeof(ir_node*));
145 for (i=0, p = (ir_node *)pset_first(pc); p; p = (ir_node *)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 (phi_ops_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;
175 * Collect all stat data
177 void phi_stat_collect(ir_graph *irg, pset *all_phi_nodes, pset *all_phi_classes) {
181 irg_walk_graph(irg, stat_walker, NULL, NULL);
182 curr_vals[I_BLOCKS] -= 2;
184 for (n = (ir_node *)pset_first(all_phi_nodes); n; n = (ir_node *)pset_next(all_phi_nodes))
187 for (pc = (pset *)pset_first(all_phi_classes); pc; pc = (pset *)pset_next(all_phi_classes))
193 * Dump statistic values in raw format
195 static void dump_file(char *filename, int stat[ASIZE]) {
199 if (! (file = fopen(filename, "wt"))) {
200 //TODO DBG((dbgmod, 0, "Cannot open file for writing\n"));
204 for (i = 0; i < ASIZE; i++) {
205 if (i >= I_ARITY_S && i <= I_ARITY_E)
206 fprintf(file, "%i %i\n", stat[i], stat[I_ALL_NODES]);
208 fprintf(file, "%i\n", stat[i]);
216 * Updates a cumulative file with the current values.
218 static void update_file(char *filename) {
224 all = fopen(filename, "rt");
227 for (i = 0; i < ASIZE; i++) {
228 if (i >= I_ARITY_S && i <= I_ARITY_E)
229 fscanf(all, "%i %i\n", &vals[i], &vals[I_ALL_NODES]);
231 fscanf(all, "%i\n", &vals[i]);
235 for (i = 0; i < ASIZE; i++)
239 /* add current values */
240 for (i = 0; i < ASIZE; i++)
241 vals[i] += curr_vals[i];
244 dump_file(filename, vals);
249 * Dumps the current contents of the values array to a file.
250 * Updates a cumulative file.
252 void phi_stat_dump(char *filename, char *cum_filename) {
254 dump_file(filename, curr_vals);
256 update_file(cum_filename);
261 * Dumps the current contents of the values array
262 * and annotations to a file.
264 void phi_stat_dump_pretty(char *filename) {
268 if (! (out = fopen(filename, "wt"))) {
269 //TODO DBG((dbgmod, 0, "Cannot open file for writing\n"));
273 fprintf(out, "\nPhi argument types\n");
274 fprintf(out, "Total %4d\n", curr_vals[I_ARG]);
275 fprintf(out, "Constants %4d\n", curr_vals[I_CONST]);
276 fprintf(out, "CF-Pred %4d\n", curr_vals[I_PRED]);
277 fprintf(out, "Others %4d\n", curr_vals[I_GLOB]);
279 fprintf(out, "\nPhi class interference\n");
280 fprintf(out, "Blocks %4d\n", curr_vals[I_BLOCKS]);
281 fprintf(out, "Phis %4d\n", curr_vals[I_PHIS]);
282 fprintf(out, "Interf classes %4d of %4d\n", curr_vals[I_PHICLSI], curr_vals[I_PHICLS]);
283 fprintf(out, "Interf pairs %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_PAIRS]);
284 fprintf(out, "Interf values %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_VALUES]);
286 fprintf(out, "\nPhi arity\n");
287 for (i = I_ARITY_S; i<=I_ARITY_E; i++)
288 fprintf(out, "%2i %4d\n", i-I_ARITY_S, curr_vals[i]);
290 fprintf(out, "\nPhi class sizes\n");
291 for (i = I_CLS_SIZE_S; i<=I_CLS_SIZE_E; i++)
292 fprintf(out, "%2i %4d\n", i-I_CLS_SIZE_S, curr_vals[i]);
294 fprintf(out, "\n\nTotal nodes: %4d\n", curr_vals[I_ALL_NODES]);