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",
42 * dumps a opcode hash into human readable form
44 static void simple_dump_opcode_hash(dumper_t *dmp, pset *set)
55 fprintf(dmp->f, "%-16s %-8s %-8s %-8s\n", "Opcode", "alive", "created", "->Id");
56 for (entry = pset_first(set); entry; entry = pset_next(set)) {
57 fprintf(dmp->f, "%-16s %8d %8d %8d\n",
58 get_id_str(entry->op->name), entry->cnt_alive.cnt[0], entry->new_node.cnt[0], entry->into_Id.cnt[0]);
60 cnt_add(&f_alive, &entry->cnt_alive);
61 cnt_add(&f_new_node, &entry->new_node);
62 cnt_add(&f_Id, &entry->into_Id);
64 fprintf(dmp->f, "-------------------------------------------\n");
65 fprintf(dmp->f, "%-16s %8d %8d %8d\n", "Sum",
72 * dumps a optimization hash into human readable form
74 static void simple_dump_opt_hash(dumper_t *dmp, pset *set, int index)
76 opt_entry_t *entry = pset_first(set);
79 fprintf(dmp->f, "\n%s:\n", opt_names[index]);
80 fprintf(dmp->f, "%-16s %-8s\n", "Opcode", "deref");
82 for (; entry; entry = pset_next(set)) {
83 fprintf(dmp->f, "%-16s %8d\n",
84 get_id_str(entry->op->name), entry->count.cnt[0]);
90 * dumps the endges count
92 static void simple_dump_edges(dumper_t *dmp, counter_t *cnt)
94 fprintf(dmp->f, "%-16s %8d\n", "Edges", cnt->cnt[0]);
100 static void simple_dump_graph(dumper_t *dmp, graph_entry_t *entry)
103 block_entry_t *b_entry;
106 ir_graph *const_irg = get_const_code_irg();
108 if (entry->irg == const_irg) {
109 fprintf(dmp->f, "\nConst code Irg %p", (void *)entry->irg);
113 fprintf(dmp->f, "\nEntity %s, Irg %p", get_entity_name(entry->ent), (void *)entry->irg);
115 fprintf(dmp->f, "\nIrg %p", (void *)entry->irg);
118 fprintf(dmp->f, " %swalked %u over blocks %u:\n"
119 " was inlined : %u\n"
120 " got inlined : %u\n"
121 " strength red : %u\n"
122 " leaf function : %s\n"
123 " calls only leaf functions : %s\n"
127 " indirect calls : %u\n",
128 entry->is_deleted ? "DELETED " : "",
129 entry->cnt_walked.cnt[0], entry->cnt_walked_blocks.cnt[0],
130 entry->cnt_was_inlined.cnt[0],
131 entry->cnt_got_inlined.cnt[0],
132 entry->cnt_strength_red.cnt[0],
133 entry->is_leaf ? "YES" : "NO",
134 entry->is_leaf_call == LCS_NON_LEAF_CALL ? "NO" : (entry->is_leaf_call == LCS_LEAF_CALL ? "Yes" : "Maybe"),
135 entry->is_recursive ? "YES" : "NO",
136 entry->is_chain_call ? "YES" : "NO",
137 entry->cnt_all_calls.cnt[0],
138 entry->cnt_indirect_calls.cnt[0]
142 fprintf(dmp->f, "\nGlobals counts:\n");
143 fprintf(dmp->f, "--------------\n");
147 simple_dump_opcode_hash(dmp, entry->opcode_hash);
148 simple_dump_edges(dmp, &entry->cnt_edges);
150 /* effects of optimizations */
154 for (i = 0; i < sizeof(entry->opt_hash)/sizeof(entry->opt_hash[0]); ++i) {
155 simple_dump_opt_hash(dmp, entry->opt_hash[i], i);
158 /* dump block info */
159 fprintf(dmp->f, "\n%12s %12s %12s %12s %12s %12s\n", "Block Nr", "Nodes", "intern E", "incoming E", "outgoing E", "quot");
160 for (b_entry = pset_first(entry->block_hash);
162 b_entry = pset_next(entry->block_hash)) {
163 fprintf(dmp->f, "BLK %12ld %12u %12u %12u %12u %4.8f\n",
165 b_entry->cnt_nodes.cnt[0],
166 b_entry->cnt_edges.cnt[0],
167 b_entry->cnt_in_edges.cnt[0],
168 b_entry->cnt_out_edges.cnt[0],
169 (double)b_entry->cnt_edges.cnt[0] / (double)b_entry->cnt_nodes.cnt[0]
176 * initialise the simple dumper
178 static void simple_init(dumper_t *dmp, const char *name)
182 snprintf(fname, sizeof(fname), "%s.txt", name);
183 dmp->f = fopen(fname, "w");
187 * finishes the simple dumper
189 static void simple_finish(dumper_t *dmp)
196 * the simple human readable dumper
198 const dumper_t simple_dumper = {
207 /* ---------------------------------------------------------------------- */
210 * count the nodes as needed:
212 * 1 normal (data) Phi's
217 static void csv_count_nodes(dumper_t *dmp, graph_entry_t *graph, counter_t cnt[])
222 for (i = 0; i < 4; ++i)
225 for (entry = pset_first(graph->opcode_hash); entry; entry = pset_next(graph->opcode_hash)) {
226 if (entry->op == op_Phi) {
228 cnt_add(&cnt[1], &entry->cnt_alive);
230 else if (entry->op == dmp->status->op_PhiM) {
232 cnt_add(&cnt[2], &entry->cnt_alive);
234 else if (entry->op == op_Proj) {
236 cnt_add(&cnt[3], &entry->cnt_alive);
239 /* all other nodes */
240 cnt_add(&cnt[0], &entry->cnt_alive);
248 static void csv_dump_graph(dumper_t *dmp, graph_entry_t *entry)
254 if (entry->irg && !entry->is_deleted) {
255 ir_graph *const_irg = get_const_code_irg();
257 if (entry->irg == const_irg) {
258 name = "<Const code Irg>";
263 name = get_entity_name(entry->ent);
265 name = "<UNKNOWN IRG>";
268 csv_count_nodes(dmp, entry, cnt);
270 fprintf(dmp->f, "%-40s, %p, %d, %d, %d, %d\n",
282 * initialise the simple dumper
284 static void csv_init(dumper_t *dmp, const char *name)
288 snprintf(fname, sizeof(fname), "%s.csv", name);
289 dmp->f = fopen(fname, "a");
293 * finishes the simple dumper
295 static void csv_finish(dumper_t *dmp)
302 * the simple human readable dumper
304 const dumper_t csv_dumper = {