3 * File name: ir/ir/stat_dmp.c
4 * Purpose: Statistics for Firm.
8 * Copyright: (c) 2004 Universität Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
18 * names of the optimizations
20 static const char *opt_names[] = {
21 "straightening optimization",
23 "constant evaluation",
24 "algebraic simplification",
26 "Write-After-Write optimization",
27 "Write-After-Read optimization",
28 "Read-After-Write optimization",
29 "Read-After-Read optimization",
30 "Read-a-Const optimization",
33 "Common subexpression elimination",
35 "Architecture dependant optimization",
36 "Reassociation optimization",
37 "Polymorphic call optimization",
38 "an if conversion was tried",
42 static const char *if_conv_names[] = {
44 "if conv side effect :",
45 "if conv Phi node found :",
46 "if conv to deep DAG's :",
47 "if conv bad control flow :",
51 * dumps a opcode hash into human readable form
53 static void simple_dump_opcode_hash(dumper_t *dmp, pset *set)
64 fprintf(dmp->f, "%-16s %-8s %-8s %-8s\n", "Opcode", "alive", "created", "->Id");
65 for (entry = pset_first(set); entry; entry = pset_next(set)) {
66 fprintf(dmp->f, "%-16s %8d %8d %8d\n",
67 get_id_str(entry->op->name), entry->cnt_alive.cnt[0], entry->new_node.cnt[0], entry->into_Id.cnt[0]);
69 cnt_add(&f_alive, &entry->cnt_alive);
70 cnt_add(&f_new_node, &entry->new_node);
71 cnt_add(&f_Id, &entry->into_Id);
73 fprintf(dmp->f, "-------------------------------------------\n");
74 fprintf(dmp->f, "%-16s %8d %8d %8d\n", "Sum",
81 * dumps a optimization hash into human readable form
83 static void simple_dump_opt_hash(dumper_t *dmp, pset *set, int index)
85 opt_entry_t *entry = pset_first(set);
88 fprintf(dmp->f, "\n%s:\n", opt_names[index]);
89 fprintf(dmp->f, "%-16s %-8s\n", "Opcode", "deref");
91 for (; entry; entry = pset_next(set)) {
92 fprintf(dmp->f, "%-16s %8d\n",
93 get_id_str(entry->op->name), entry->count.cnt[0]);
99 * dumps the edges count
101 static void simple_dump_edges(dumper_t *dmp, counter_t *cnt)
103 fprintf(dmp->f, "%-16s %8d\n", "Edges", cnt->cnt[0]);
109 static void simple_dump_graph(dumper_t *dmp, graph_entry_t *entry)
111 int i, dump_opts = 1;
112 block_entry_t *b_entry;
115 ir_graph *const_irg = get_const_code_irg();
117 if (entry->irg == const_irg) {
118 fprintf(dmp->f, "\nConst code Irg %p", (void *)entry->irg);
122 fprintf(dmp->f, "\nEntity %s, Irg %p", get_entity_name(entry->ent), (void *)entry->irg);
124 fprintf(dmp->f, "\nIrg %p", (void *)entry->irg);
127 fprintf(dmp->f, " %swalked %u over blocks %u:\n"
128 " was inlined : %u\n"
129 " got inlined : %u\n"
130 " strength red : %u\n"
131 " leaf function : %s\n"
132 " calls only leaf functions : %s\n"
136 " indirect calls : %u\n",
137 entry->is_deleted ? "DELETED " : "",
138 entry->cnt_walked.cnt[0], entry->cnt_walked_blocks.cnt[0],
139 entry->cnt_was_inlined.cnt[0],
140 entry->cnt_got_inlined.cnt[0],
141 entry->cnt_strength_red.cnt[0],
142 entry->is_leaf ? "YES" : "NO",
143 entry->is_leaf_call == LCS_NON_LEAF_CALL ? "NO" : (entry->is_leaf_call == LCS_LEAF_CALL ? "Yes" : "Maybe"),
144 entry->is_recursive ? "YES" : "NO",
145 entry->is_chain_call ? "YES" : "NO",
146 entry->cnt_all_calls.cnt[0],
147 entry->cnt_indirect_calls.cnt[0]
150 for (i = 0; i < sizeof(entry->cnt_if_conv)/sizeof(entry->cnt_if_conv[0]); ++i) {
151 fprintf(dmp->f, " %s : %u\n", if_conv_names[i], entry->cnt_if_conv[i].cnt[0]);
156 fprintf(dmp->f, "\nGlobals counts:\n");
157 fprintf(dmp->f, "--------------\n");
161 simple_dump_opcode_hash(dmp, entry->opcode_hash);
162 simple_dump_edges(dmp, &entry->cnt_edges);
164 /* effects of optimizations */
168 for (i = 0; i < sizeof(entry->opt_hash)/sizeof(entry->opt_hash[0]); ++i) {
169 simple_dump_opt_hash(dmp, entry->opt_hash[i], i);
172 /* dump block info */
173 fprintf(dmp->f, "\n%12s %12s %12s %12s %12s %12s\n", "Block Nr", "Nodes", "intern E", "incoming E", "outgoing E", "quot");
174 for (b_entry = pset_first(entry->block_hash);
176 b_entry = pset_next(entry->block_hash)) {
177 fprintf(dmp->f, "BLK %12ld %12u %12u %12u %12u %4.8f\n",
179 b_entry->cnt_nodes.cnt[0],
180 b_entry->cnt_edges.cnt[0],
181 b_entry->cnt_in_edges.cnt[0],
182 b_entry->cnt_out_edges.cnt[0],
183 (double)b_entry->cnt_edges.cnt[0] / (double)b_entry->cnt_nodes.cnt[0]
190 * initialize the simple dumper
192 static void simple_init(dumper_t *dmp, const char *name)
196 snprintf(fname, sizeof(fname), "%s.txt", name);
197 dmp->f = fopen(fname, "w");
201 * finishes the simple dumper
203 static void simple_finish(dumper_t *dmp)
210 * the simple human readable dumper
212 const dumper_t simple_dumper = {
221 /* ---------------------------------------------------------------------- */
224 * count the nodes as needed:
226 * 1 normal (data) Phi's
231 static void csv_count_nodes(dumper_t *dmp, graph_entry_t *graph, counter_t cnt[])
236 for (i = 0; i < 4; ++i)
239 for (entry = pset_first(graph->opcode_hash); entry; entry = pset_next(graph->opcode_hash)) {
240 if (entry->op == op_Phi) {
242 cnt_add(&cnt[1], &entry->cnt_alive);
244 else if (entry->op == dmp->status->op_PhiM) {
246 cnt_add(&cnt[2], &entry->cnt_alive);
248 else if (entry->op == op_Proj) {
250 cnt_add(&cnt[3], &entry->cnt_alive);
253 /* all other nodes */
254 cnt_add(&cnt[0], &entry->cnt_alive);
262 static void csv_dump_graph(dumper_t *dmp, graph_entry_t *entry)
268 if (entry->irg && !entry->is_deleted) {
269 ir_graph *const_irg = get_const_code_irg();
271 if (entry->irg == const_irg) {
272 name = "<Const code Irg>";
277 name = get_entity_name(entry->ent);
279 name = "<UNKNOWN IRG>";
282 csv_count_nodes(dmp, entry, cnt);
284 fprintf(dmp->f, "%-40s, %p, %d, %d, %d, %d\n",
296 * initialize the simple dumper
298 static void csv_init(dumper_t *dmp, const char *name)
302 snprintf(fname, sizeof(fname), "%s.csv", name);
303 dmp->f = fopen(fname, "a");
307 * finishes the simple dumper
309 static void csv_finish(dumper_t *dmp)
316 * the simple human readable dumper
318 const dumper_t csv_dumper = {