4 * Copyright: (c) Universitaet Karlsruhe
5 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
12 #include "phiclass_t.h"
14 #include "becopyopt.h"
15 #include "becopystat.h"
20 static pset *all_phi_nodes;
21 static pset *all_phi_classes;
22 static pset *all_copy_nodes;
24 void copystat_init(void) {
25 all_phi_nodes = pset_new_ptr_default();
26 all_phi_classes = pset_new_ptr_default();
27 all_copy_nodes = pset_new_ptr_default();
32 void copystat_reset(void) {
34 for (i = 0; i < ASIZE; ++i)
39 * Collect general data
41 static void stat_walker(ir_node *node, void *env) {
42 curr_vals[I_ALL_NODES]++; /* count all nodes */
44 if (is_Block(node)) /* count all blocks */
45 curr_vals[I_BLOCKS]++;
47 if (is_Phi(node)) /* collect phis */
48 pset_insert_ptr(all_phi_nodes, node);
51 pset_insert_ptr(all_copy_nodes, node);
55 * Collect phi node data
57 static void stat_phi_node(be_chordal_env_t *chordal_env, ir_node *phi) {
61 /* count all phi phis */
62 curr_vals[I_PHI_CNT]++;
65 arity = get_irn_arity(phi);
66 curr_vals[I_PHI_ARG_CNT] += arity;
67 if (arity > MAX_ARITY)
68 curr_vals[I_PHI_ARITY_E]++;
70 curr_vals[I_PHI_ARITY_S + arity]++;
72 /* type of argument {self, const, pred, glob} */
73 for (i = 0; i < arity; i++) {
74 ir_node *block_of_arg, *block_ith_pred;
75 ir_node *arg = get_irn_n(phi, i);
78 curr_vals[I_COPIES_MAX]++; /* if arg!=phi this is a possible copy */
79 if (nodes_interfere(chordal_env, phi, arg))
80 curr_vals[I_COPIES_IF]++;
84 curr_vals[I_PHI_ARG_SELF]++;
88 if (iro_Const == get_irn_opcode(arg)) {
89 curr_vals[I_PHI_ARG_CONST]++;
93 block_of_arg = get_nodes_block(arg);
94 block_ith_pred = get_nodes_block(get_irn_n(get_nodes_block(phi), i));
95 if (block_of_arg == block_ith_pred) {
96 curr_vals[I_PHI_ARG_PRED]++;
100 curr_vals[I_PHI_ARG_GLOB]++;
105 * Collect register-constrained node data
107 static void stat_copy_node(be_chordal_env_t *chordal_env, ir_node *root) {
108 curr_vals[I_CPY_CNT]++;
109 curr_vals[I_COPIES_MAX]++;
110 if (nodes_interfere(chordal_env, root, get_Copy_src(root))) {
111 curr_vals[I_COPIES_IF]++;
112 assert(0 && "A Perm pair (in/out) should never interfere!");
117 * Collect phi class data
119 static void stat_phi_class(be_chordal_env_t *chordal_env, pset *pc) {
120 int i, o, size, if_free;
121 ir_node **members, *p;
123 /* phi class count */
124 curr_vals[I_CLS_CNT]++;
127 size = pset_count(pc);
128 if (size > MAX_CLS_SIZE)
129 curr_vals[I_CLS_SIZE_E]++;
131 curr_vals[I_CLS_SIZE_S + size]++;
133 /* get an array of all members for double iterating */
134 members = xmalloc(size * sizeof(*members));
135 for (i = 0, p = pset_first(pc); p; p = pset_next(pc))
139 /* determine interference of phi class members */
140 curr_vals[I_CLS_IF_MAX] += size*(size-1)/2;
142 for (i = 0; i < size-1; ++i)
143 for (o = i+1; o < size; ++o)
144 if (nodes_interfere(chordal_env, members[i], members[o])) {
146 curr_vals[I_CLS_IF_CNT]++;
149 /* Does this phi class have an inner interference? */
150 curr_vals[I_CLS_IF_FREE] += if_free;
155 void copystat_collect_irg(ir_graph *irg) {
156 irg_walk_graph(irg, stat_walker, NULL, NULL);
157 curr_vals[I_BLOCKS] -= 2; /* substract 2 for start and end block */
158 all_phi_classes = phi_class_compute_by_phis(all_phi_nodes);
161 #define is_curr_reg_class(irn) (arch_get_irn_reg_class(chordal_env->arch_env, irn, arch_pos_make_out(0)) == chordal_env->cls)
163 void copystat_collect_cls(be_chordal_env_t *chordal_env) {
167 for (n = pset_first(all_phi_nodes); n; n = pset_next(all_phi_nodes))
168 if (is_curr_reg_class(n))
169 stat_phi_node(chordal_env, n);
171 for (n = pset_first(all_copy_nodes); n; n = pset_next(all_copy_nodes))
172 if (is_curr_reg_class(n))
173 stat_copy_node(chordal_env, n);
175 for (pc = pset_first(all_phi_classes); pc; pc = pset_next(all_phi_classes)) {
176 ir_node *member = pset_first(pc);
178 if (is_curr_reg_class(member))
179 stat_phi_class(chordal_env, pc);
183 void copystat_dump(ir_graph *irg) {
187 snprintf(buf, sizeof(buf), "%s__%s", get_irp_prog_name(), get_entity_name(get_irg_entity(irg)));
188 FILE *out = ffopen(buf, "stat", "wt");
190 fprintf(out, "%s\n", get_irp_prog_name());
191 for (i = 0; i < ASIZE; i++) {
192 if (i >= I_PHI_ARITY_S && i <= I_PHI_ARITY_E)
193 fprintf(out, "%i %i\n", curr_vals[i], curr_vals[I_PHI_CNT]);
194 else if (i >= I_CLS_SIZE_S && i <= I_CLS_SIZE_E)
195 fprintf(out, "%i %i\n", curr_vals[i], curr_vals[I_CLS_CNT]);
197 fprintf(out, "%i\n", curr_vals[i]);
203 void copystat_dump_pretty(ir_graph *irg) {
207 snprintf(buf, sizeof(buf), "%s__%s", get_irp_prog_name(), get_entity_name(get_irg_entity(irg)));
208 FILE *out = ffopen(buf, "pstat", "wt");
210 fprintf(out, "Nodes %4d\n", curr_vals[I_ALL_NODES]);
211 fprintf(out, "Blocks %4d\n", curr_vals[I_BLOCKS]);
212 fprintf(out, "CopyIrn %4d\n", curr_vals[I_CPY_CNT]);
214 fprintf(out, "\nPhis %4d\n", curr_vals[I_PHI_CNT]);
215 fprintf(out, "... argument types\n");
216 fprintf(out, " Total %4d\n", curr_vals[I_PHI_ARG_CNT]);
217 fprintf(out, " Self %4d\n", curr_vals[I_PHI_ARG_SELF]);
218 fprintf(out, " Constants %4d\n", curr_vals[I_PHI_ARG_CONST]);
219 fprintf(out, " CF-Pred %4d\n", curr_vals[I_PHI_ARG_PRED]);
220 fprintf(out, " Others %4d\n", curr_vals[I_PHI_ARG_GLOB]);
221 fprintf(out, "... arities\n");
222 for (i = I_PHI_ARITY_S; i<=I_PHI_ARITY_E; i++)
223 fprintf(out, " %2i %4d\n", i-I_PHI_ARITY_S, curr_vals[i]);
225 fprintf(out, "\nPhi classes %4d\n", curr_vals[I_CLS_CNT]);
226 fprintf(out, " compl. free %4d\n", curr_vals[I_CLS_IF_FREE]);
227 fprintf(out, " inner intf. %4d / %4d\n", curr_vals[I_CLS_IF_CNT], curr_vals[I_CLS_IF_MAX]);
228 fprintf(out, "... sizes\n");
229 for (i = I_CLS_SIZE_S; i<=I_CLS_SIZE_E; i++)
230 fprintf(out, " %2i %4d\n", i-I_CLS_SIZE_S, curr_vals[i]);
232 fprintf(out, "\nILP stat\n");
233 fprintf(out, " Time %8d\n", curr_vals[I_ILP_TIME]);
234 fprintf(out, " Iter %8d\n", curr_vals[I_ILP_ITER]);
236 fprintf(out, "\nCopy stat\n");
237 fprintf(out, " Max %4d\n", curr_vals[I_COPIES_MAX]);
238 fprintf(out, " Init %4d\n", curr_vals[I_COPIES_INIT]);
239 fprintf(out, " Heur %4d\n", curr_vals[I_COPIES_HEUR]);
240 fprintf(out, " Opt %4d\n", curr_vals[I_COPIES_OPT]);
241 fprintf(out, " Intf %4d\n", curr_vals[I_COPIES_IF]);