updated doxygen docu
[libfirm] / ir / stat / firmstat.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/firmstat.c
4  * Purpose:     Statistics for Firm.
5  * Author:      Michael Beck
6  * Created:
7  * CVS-ID:      $Id$
8  * Copyright:   (c) 2004 Universität Karlsruhe
9  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
10  */
11
12 #ifdef HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15
16 #ifdef FIRM_STATISTICS
17
18 #include <stdio.h>
19
20 #ifdef HAVE_STDLIB_H
21 # include <stdlib.h>
22 #endif
23 #ifdef HAVE_STRING_H
24 # include <string.h>
25 #endif
26
27 #include "irouts.h"
28 #include "irdump.h"
29 #include "hashptr.h"
30 #include "firmstat_t.h"
31 #include "pattern.h"
32 #include "dags.h"
33 #include "stat_dmp.h"
34 #include "xmalloc.h"
35 #include "irhooks.h"
36
37 /*
38  * need this to be static:
39  * Special pseudo Opcodes that we need to count some interesting cases
40  */
41
42 /**
43  * The Phi0, a node that is created during SSA construction
44  */
45 static ir_op _op_Phi0;
46
47 /** The PhiM, just to count memory Phi's. */
48 static ir_op _op_PhiM;
49
50 /** The Mul by Const node. */
51 static ir_op _op_MulC;
52
53 /** The Div by Const node. */
54 static ir_op _op_DivC;
55
56 /** The Div by Const node. */
57 static ir_op _op_ModC;
58
59 /** The Div by Const node. */
60 static ir_op _op_DivModC;
61
62 /** The memory Proj node. */
63 static ir_op _op_ProjM;
64
65 /** A Sel of a Sel */
66 static ir_op _op_SelSel;
67
68 /** A Sel of a Sel of a Sel */
69 static ir_op _op_SelSelSel;
70
71 /* ---------------------------------------------------------------------------------- */
72
73 /** Marks the begin of a statistic (hook) function. */
74 #define STAT_ENTER              ++status->recursive
75
76 /** Marks the end of a statistic (hook) functions. */
77 #define STAT_LEAVE              --status->recursive
78
79 /** Allows to enter a statistic function only when we are not already in a hook. */
80 #define STAT_ENTER_SINGLE       do { if (status->recursive > 0) return; ++status->recursive; } while (0)
81
82 /**
83  * global status
84  */
85 static const int status_disable = 0;
86 static stat_info_t *status = (stat_info_t *)&status_disable;
87
88 /**
89  * Compare two elements of the opcode hash.
90  */
91 static int opcode_cmp(const void *elt, const void *key)
92 {
93         const node_entry_t *e1 = elt;
94         const node_entry_t *e2 = key;
95
96         return e1->op->code - e2->op->code;
97 } /* opcode_cmp */
98
99 /**
100  * Compare two elements of the graph hash.
101  */
102 static int graph_cmp(const void *elt, const void *key)
103 {
104         const graph_entry_t *e1 = elt;
105         const graph_entry_t *e2 = key;
106
107         return e1->irg != e2->irg;
108 } /* graph_cmp */
109
110 /**
111  * Compare two elements of the optimization hash.
112  */
113 static int opt_cmp(const void *elt, const void *key)
114 {
115         const opt_entry_t *e1 = elt;
116         const opt_entry_t *e2 = key;
117
118         return e1->op->code != e2->op->code;
119 } /* opt_cmp */
120
121 /**
122  * Compare two elements of the block/extbb hash.
123  */
124 static int block_cmp(const void *elt, const void *key)
125 {
126         const block_entry_t *e1 = elt;
127         const block_entry_t *e2 = key;
128
129         return e1->block_nr != e2->block_nr;
130 } /* block_cmp */
131
132 /**
133  * Compare two elements of the be_block hash.
134  */
135 static int be_block_cmp(const void *elt, const void *key)
136 {
137         const be_block_entry_t *e1 = elt;
138         const be_block_entry_t *e2 = key;
139
140         return e1->block_nr != e2->block_nr;
141 } /* be_block_cmp */
142
143 /**
144  * Compare two elements of reg pressure hash.
145  */
146 static int reg_pressure_cmp(const void *elt, const void *key)
147 {
148         const reg_pressure_entry_t *e1 = elt;
149         const reg_pressure_entry_t *e2 = key;
150
151         return e1->class_name != e2->class_name;
152 } /* reg_pressure_cmp */
153
154 /**
155  * Compare two elements of the perm_stat hash.
156  */
157 static int perm_stat_cmp(const void *elt, const void *key)
158 {
159         const perm_stat_entry_t *e1 = elt;
160         const perm_stat_entry_t *e2 = key;
161
162         return e1->perm != e2->perm;
163 } /* perm_stat_cmp */
164
165 /**
166  * Compare two elements of the perm_class hash.
167  */
168 static int perm_class_cmp(const void *elt, const void *key)
169 {
170         const perm_class_entry_t *e1 = elt;
171         const perm_class_entry_t *e2 = key;
172
173         return e1->class_name != e2->class_name;
174 } /* perm_class_cmp */
175
176 /**
177  * Compare two elements of the ir_op hash.
178  */
179 static int opcode_cmp_2(const void *elt, const void *key)
180 {
181         const ir_op *e1 = elt;
182         const ir_op *e2 = key;
183
184         return e1->code != e2->code;
185 } /* opcode_cmp_2 */
186
187 /**
188  * Compare two elements of the address_mark set.
189  */
190 static int address_mark_cmp(const void *elt, const void *key, size_t size)
191 {
192         const address_mark_entry_t *e1 = elt;
193         const address_mark_entry_t *e2 = key;
194
195         /* compare only the nodes, the rest is used as data container */
196         return e1->node != e2->node;
197 } /* address_mark_cmp */
198
199 /**
200  * Clear all counter in a node_entry_t.
201  */
202 static void opcode_clear_entry(node_entry_t *elem)
203 {
204         cnt_clr(&elem->cnt_alive);
205         cnt_clr(&elem->new_node);
206         cnt_clr(&elem->into_Id);
207 } /* opcode_clear_entry */
208
209 /**
210  * Returns the associates node_entry_t for an ir_op
211  *
212  * @param op    the IR operation
213  * @param hmap  a hash map containing ir_op* -> node_entry_t*
214  */
215 static node_entry_t *opcode_get_entry(const ir_op *op, hmap_node_entry_t *hmap)
216 {
217         node_entry_t key;
218         node_entry_t *elem;
219
220         key.op = op;
221
222         elem = pset_find(hmap, &key, op->code);
223         if (elem)
224                 return elem;
225
226         elem = obstack_alloc(&status->cnts, sizeof(*elem));
227         memset(elem, 0, sizeof(*elem));
228
229         /* clear counter */
230         opcode_clear_entry(elem);
231
232         elem->op = op;
233
234         return pset_insert(hmap, elem, op->code);
235 } /* opcode_get_entry */
236
237 /**
238  * Returns the associates ir_op for an opcode
239  *
240  * @param code  the IR opcode
241  * @param hmap  the hash map containing opcode -> ir_op*
242  */
243 static ir_op *opcode_find_entry(opcode code, hmap_ir_op *hmap)
244 {
245         ir_op key;
246
247         key.code = code;
248         return pset_find(hmap, &key, code);
249 } /* opcode_find_entry */
250
251 /**
252  * clears all counter in a graph_entry_t
253  */
254 static void graph_clear_entry(graph_entry_t *elem, int all)
255 {
256         if (all) {
257                 cnt_clr(&elem->cnt_walked);
258                 cnt_clr(&elem->cnt_walked_blocks);
259                 cnt_clr(&elem->cnt_was_inlined);
260                 cnt_clr(&elem->cnt_got_inlined);
261                 cnt_clr(&elem->cnt_strength_red);
262                 cnt_clr(&elem->cnt_real_func_call);
263         }  /* if */
264         cnt_clr(&elem->cnt_edges);
265         cnt_clr(&elem->cnt_all_calls);
266         cnt_clr(&elem->cnt_call_with_cnst_arg);
267         cnt_clr(&elem->cnt_indirect_calls);
268
269         if (elem->block_hash) {
270                 del_pset(elem->block_hash);
271                 elem->block_hash = NULL;
272         }  /* if */
273
274         if (elem->extbb_hash) {
275                 del_pset(elem->extbb_hash);
276                 elem->extbb_hash = NULL;
277         }  /* if */
278
279         obstack_free(&elem->recalc_cnts, NULL);
280         obstack_init(&elem->recalc_cnts);
281 } /* graph_clear_entry */
282
283 /**
284  * Returns the associated graph_entry_t for an IR graph.
285  *
286  * @param irg   the IR graph
287  * @param hmap  the hash map containing ir_graph* -> graph_entry_t*
288  */
289 static graph_entry_t *graph_get_entry(ir_graph *irg, hmap_graph_entry_t *hmap)
290 {
291         graph_entry_t key;
292         graph_entry_t *elem;
293         int i;
294
295         key.irg = irg;
296
297         elem = pset_find(hmap, &key, HASH_PTR(irg));
298
299         if (elem) {
300                 /* create hash map backend block information */
301                 if (! elem->be_block_hash)
302                         elem->be_block_hash = new_pset(be_block_cmp, 5);
303
304                 return elem;
305         }  /* if */
306
307         /* allocate a new one */
308         elem = obstack_alloc(&status->cnts, sizeof(*elem));
309         memset(elem, 0, sizeof(*elem));
310         obstack_init(&elem->recalc_cnts);
311
312         /* clear counter */
313         graph_clear_entry(elem, 1);
314
315         /* new hash table for opcodes here  */
316         elem->opcode_hash   = new_pset(opcode_cmp, 5);
317         elem->address_mark  = new_set(address_mark_cmp, 5);
318         elem->irg           = irg;
319
320         /* these hash tables are created on demand */
321         elem->block_hash = NULL;
322         elem->extbb_hash = NULL;
323
324         for (i = 0; i < sizeof(elem->opt_hash)/sizeof(elem->opt_hash[0]); ++i)
325                 elem->opt_hash[i] = new_pset(opt_cmp, 4);
326
327         return pset_insert(hmap, elem, HASH_PTR(irg));
328 } /* graph_get_entry */
329
330 /**
331  * Clear all counter in an opt_entry_t.
332  */
333 static void opt_clear_entry(opt_entry_t *elem)
334 {
335         cnt_clr(&elem->count);
336 } /* opt_clear_entry */
337
338 /**
339  * Returns the associated opt_entry_t for an IR operation.
340  *
341  * @param op    the IR operation
342  * @param hmap  the hash map containing ir_op* -> opt_entry_t*
343  */
344 static opt_entry_t *opt_get_entry(const ir_op *op, hmap_opt_entry_t *hmap)
345 {
346         opt_entry_t key;
347         opt_entry_t *elem;
348
349         key.op = op;
350
351         elem = pset_find(hmap, &key, op->code);
352         if (elem)
353                 return elem;
354
355         elem = obstack_alloc(&status->cnts, sizeof(*elem));
356         memset(elem, 0, sizeof(*elem));
357
358         /* clear new counter */
359         opt_clear_entry(elem);
360
361         elem->op = op;
362
363         return pset_insert(hmap, elem, op->code);
364 } /* opt_get_entry */
365
366 /**
367  * clears all counter in a block_entry_t
368  */
369 static void block_clear_entry(block_entry_t *elem)
370 {
371         cnt_clr(&elem->cnt_nodes);
372         cnt_clr(&elem->cnt_edges);
373         cnt_clr(&elem->cnt_in_edges);
374         cnt_clr(&elem->cnt_out_edges);
375         cnt_clr(&elem->cnt_phi_data);
376 }
377
378 /**
379  * Returns the associated block_entry_t for an block.
380  *
381  * @param block_nr  an IR  block number
382  * @param hmap      a hash map containing long -> block_entry_t
383  */
384 static block_entry_t *block_get_entry(struct obstack *obst, long block_nr, hmap_block_entry_t *hmap)
385 {
386         block_entry_t key;
387         block_entry_t *elem;
388
389         key.block_nr = block_nr;
390
391         elem = pset_find(hmap, &key, block_nr);
392         if (elem)
393                 return elem;
394
395         elem = obstack_alloc(obst, sizeof(*elem));
396         memset(elem, 0, sizeof(*elem));
397
398         /* clear new counter */
399         block_clear_entry(elem);
400
401         elem->block_nr = block_nr;
402
403         return pset_insert(hmap, elem, block_nr);
404 } /* block_get_entry */
405
406 /**
407  * Clear all sets in be_block_entry_t.
408  */
409 static void be_block_clear_entry(be_block_entry_t *elem)
410 {
411         if (elem->reg_pressure)
412                 del_pset(elem->reg_pressure);
413
414         if (elem->sched_ready)
415                 stat_delete_distrib_tbl(elem->sched_ready);
416
417         if (elem->perm_class_stat)
418                 del_pset(elem->perm_class_stat);
419
420         elem->reg_pressure    = new_pset(reg_pressure_cmp, 5);
421         elem->sched_ready     = stat_new_int_distrib_tbl();
422         elem->perm_class_stat = new_pset(perm_class_cmp, 5);
423 } /* be_block_clear_entry */
424
425 /**
426  * Returns the associated be_block_entry_t for an block.
427  *
428  * @param block_nr  an IR  block number
429  * @param hmap      a hash map containing long -> be_block_entry_t
430  */
431 static be_block_entry_t *be_block_get_entry(struct obstack *obst, long block_nr, hmap_be_block_entry_t *hmap)
432 {
433         be_block_entry_t key;
434         be_block_entry_t *elem;
435
436         key.block_nr = block_nr;
437
438         elem = pset_find(hmap, &key, block_nr);
439         if (elem)
440                 return elem;
441
442         elem = obstack_alloc(obst, sizeof(*elem));
443         memset(elem, 0, sizeof(*elem));
444
445         /* clear new counter */
446         be_block_clear_entry(elem);
447
448         elem->block_nr = block_nr;
449
450         return pset_insert(hmap, elem, block_nr);
451 } /* be_block_get_entry */
452
453 /**
454  * clears all sets in perm_class_entry_t
455  */
456 static void perm_class_clear_entry(perm_class_entry_t *elem) {
457         if (elem->perm_stat)
458                 del_pset(elem->perm_stat);
459
460         elem->perm_stat = new_pset(perm_stat_cmp, 5);
461 }
462
463 /**
464  * Returns the associated perm_class entry for a register class.
465  *
466  * @param class_name  the register class name
467  * @param hmap        a hash map containing class_name -> perm_class_entry_t
468  */
469 static perm_class_entry_t *perm_class_get_entry(struct obstack *obst, const char *class_name,
470                                                 hmap_perm_class_entry_t *hmap)
471 {
472         perm_class_entry_t key;
473         perm_class_entry_t *elem;
474
475         key.class_name = class_name;
476
477         elem = pset_find(hmap, &key, HASH_PTR(class_name));
478         if (elem)
479                 return elem;
480
481         elem = obstack_alloc(obst, sizeof(*elem));
482         memset(elem, 0, sizeof(*elem));
483
484         /* clear new counter */
485         perm_class_clear_entry(elem);
486
487         elem->class_name = class_name;
488
489         return pset_insert(hmap, elem, HASH_PTR(class_name));
490 } /* perm_class_get_entry */
491
492 /**
493  * clears all sets in perm_stat_entry_t
494  */
495 static void perm_stat_clear_entry(perm_stat_entry_t *elem) {
496         if (elem->chains)
497                 stat_delete_distrib_tbl(elem->chains);
498
499         if (elem->cycles)
500                 stat_delete_distrib_tbl(elem->cycles);
501
502         elem->chains = stat_new_int_distrib_tbl();
503         elem->cycles = stat_new_int_distrib_tbl();
504 } /* perm_stat_clear_entry */
505
506 /**
507  * Returns the associated perm_stat entry for a perm.
508  *
509  * @param perm      the perm node
510  * @param hmap      a hash map containing perm -> perm_stat_entry_t
511  */
512 static perm_stat_entry_t *perm_stat_get_entry(struct obstack *obst, ir_node *perm, hmap_perm_stat_entry_t *hmap)
513 {
514         perm_stat_entry_t key;
515         perm_stat_entry_t *elem;
516
517         key.perm = perm;
518
519         elem = pset_find(hmap, &key, HASH_PTR(perm));
520         if (elem)
521                 return elem;
522
523         elem = obstack_alloc(obst, sizeof(*elem));
524         memset(elem, 0, sizeof(*elem));
525
526         /* clear new counter */
527         perm_stat_clear_entry(elem);
528
529         elem->perm = perm;
530
531         return pset_insert(hmap, elem, HASH_PTR(perm));
532 } /* perm_stat_get_entry */
533
534 /**
535  * Returns the ir_op for an IR-node,
536  * handles special cases and return pseudo op codes.
537  *
538  * @param none  an IR node
539  */
540 static ir_op *stat_get_irn_op(ir_node *node)
541 {
542         ir_op *op = get_irn_op(node);
543
544         if (op == op_Phi && get_irn_arity(node) == 0) {
545                 /* special case, a Phi0 node, count on extra counter */
546                 op = status->op_Phi0 ? status->op_Phi0 : op;
547         } else if (op == op_Phi && get_irn_mode(node) == mode_M) {
548                 /* special case, a Memory Phi node, count on extra counter */
549                 op = status->op_PhiM ? status->op_PhiM : op;
550         } else if (op == op_Proj && get_irn_mode(node) == mode_M) {
551                 /* special case, a Memory Proj node, count on extra counter */
552                 op = status->op_ProjM ? status->op_ProjM : op;
553         } else if (op == op_Mul &&
554                 (get_irn_op(get_Mul_left(node)) == op_Const || get_irn_op(get_Mul_right(node)) == op_Const)) {
555                 /* special case, a Multiply by a const, count on extra counter */
556                 op = status->op_MulC ? status->op_MulC : op;
557         } else if (op == op_Div && get_irn_op(get_Div_right(node)) == op_Const) {
558                 /* special case, a division by a const, count on extra counter */
559                 op = status->op_DivC ? status->op_DivC : op;
560         } else if (op == op_Mod && get_irn_op(get_Mod_right(node)) == op_Const) {
561                 /* special case, a module by a const, count on extra counter */
562                 op = status->op_ModC ? status->op_ModC : op;
563         } else if (op == op_DivMod && get_irn_op(get_DivMod_right(node)) == op_Const) {
564                 /* special case, a division/modulo by a const, count on extra counter */
565                 op = status->op_DivModC ? status->op_DivModC : op;
566         } else if (op == op_Sel && get_irn_op(get_Sel_ptr(node)) == op_Sel) {
567                 /* special case, a Sel of a Sel, count on extra counter */
568                 op = status->op_SelSel ? status->op_SelSel : op;
569
570                 if (get_irn_op(get_Sel_ptr(get_Sel_ptr(node))) == op_Sel) {
571                         /* special case, a Sel of a Sel of a Sel, count on extra counter */
572                         op = status->op_SelSelSel ? status->op_SelSelSel : op;
573                 }  /* if */
574         }  /* if */
575
576         return op;
577 } /* stat_get_irn_op */
578
579 /**
580  * update the block counter
581  */
582 static void undate_block_info(ir_node *node, graph_entry_t *graph)
583 {
584         ir_op *op = get_irn_op(node);
585         ir_node *block;
586         block_entry_t *b_entry;
587         int i, arity;
588
589         /* check for block */
590         if (op == op_Block) {
591                 arity = get_irn_arity(node);
592                 b_entry = block_get_entry(&graph->recalc_cnts, get_irn_node_nr(node), graph->block_hash);
593
594                 /* count all incoming edges */
595                 for (i = 0; i < arity; ++i) {
596                         ir_node *pred = get_irn_n(node, i);
597                         ir_node *other_block = get_nodes_block(pred);
598                         block_entry_t *b_entry_other = block_get_entry(&graph->recalc_cnts, get_irn_node_nr(other_block), graph->block_hash);
599
600                         cnt_inc(&b_entry->cnt_in_edges);        /* an edge coming from another block */
601                         cnt_inc(&b_entry_other->cnt_out_edges);
602                 }  /* for */
603                 return;
604         }  /* if */
605
606         block   = get_nodes_block(node);
607         b_entry = block_get_entry(&graph->recalc_cnts, get_irn_node_nr(block), graph->block_hash);
608
609         if (op == op_Phi && mode_is_datab(get_irn_mode(node))) {
610                 /* count data Phi per block */
611                 cnt_inc(&b_entry->cnt_phi_data);
612         }  /* if */
613
614         /* we have a new node in our block */
615         cnt_inc(&b_entry->cnt_nodes);
616
617         /* don't count keep-alive edges */
618         if (get_irn_op(node) == op_End)
619                 return;
620
621         arity = get_irn_arity(node);
622
623         for (i = 0; i < arity; ++i) {
624                 ir_node *pred = get_irn_n(node, i);
625                 ir_node *other_block;
626
627                 other_block = get_nodes_block(pred);
628
629                 if (other_block == block)
630                         cnt_inc(&b_entry->cnt_edges);   /* a in block edge */
631                 else {
632                         block_entry_t *b_entry_other = block_get_entry(&graph->recalc_cnts, get_irn_node_nr(other_block), graph->block_hash);
633
634                         cnt_inc(&b_entry->cnt_in_edges);        /* an edge coming from another block */
635                         cnt_inc(&b_entry_other->cnt_out_edges);
636                 }  /* if */
637         }  /* for */
638 } /* undate_block_info */
639
640 /**
641  * Update the extended block counter.
642  */
643 static void update_extbb_info(ir_node *node, graph_entry_t *graph)
644 {
645         ir_op *op = get_irn_op(node);
646         ir_extblk *extbb;
647         extbb_entry_t *eb_entry;
648         int i, arity;
649
650         /* check for block */
651         if (op == op_Block) {
652                 extbb = get_nodes_extbb(node);
653                 arity = get_irn_arity(node);
654                 eb_entry = block_get_entry(&graph->recalc_cnts, get_extbb_node_nr(extbb), graph->extbb_hash);
655
656                 /* count all incoming edges */
657                 for (i = 0; i < arity; ++i) {
658                         ir_node *pred = get_irn_n(node, i);
659                         ir_extblk *other_extbb = get_nodes_extbb(pred);
660
661                         if (extbb != other_extbb) {
662                                 extbb_entry_t *eb_entry_other = block_get_entry(&graph->recalc_cnts, get_extbb_node_nr(other_extbb), graph->extbb_hash);
663
664                                 cnt_inc(&eb_entry->cnt_in_edges);       /* an edge coming from another extbb */
665                                 cnt_inc(&eb_entry_other->cnt_out_edges);
666                         }  /* if */
667                 }  /* for */
668                 return;
669         }  /* if */
670
671         extbb    = get_nodes_extbb(node);
672         eb_entry = block_get_entry(&graph->recalc_cnts, get_extbb_node_nr(extbb), graph->extbb_hash);
673
674         if (op == op_Phi && mode_is_datab(get_irn_mode(node))) {
675                 /* count data Phi per extbb */
676                 cnt_inc(&eb_entry->cnt_phi_data);
677         }  /* if */
678
679         /* we have a new node in our block */
680         cnt_inc(&eb_entry->cnt_nodes);
681
682         /* don't count keep-alive edges */
683         if (get_irn_op(node) == op_End)
684                 return;
685
686         arity = get_irn_arity(node);
687
688         for (i = 0; i < arity; ++i) {
689                 ir_node *pred = get_irn_n(node, i);
690                 ir_extblk *other_extbb = get_nodes_extbb(pred);
691
692                 if (other_extbb == extbb)
693                         cnt_inc(&eb_entry->cnt_edges);  /* a in extbb edge */
694                 else {
695                         extbb_entry_t *eb_entry_other = block_get_entry(&graph->recalc_cnts, get_extbb_node_nr(other_extbb), graph->extbb_hash);
696
697                         cnt_inc(&eb_entry->cnt_in_edges);       /* an edge coming from another extbb */
698                         cnt_inc(&eb_entry_other->cnt_out_edges);
699                 }  /* if */
700         }  /* for */
701 } /* update_extbb_info */
702
703 /** Calculates how many arguments of the call are const. */
704 static int cnt_const_args(ir_node *call)
705 {
706         int i, res = 0;
707         int n = get_Call_n_params(call);
708
709         for (i = 0; i < n; ++i) {
710                 ir_node *param = get_Call_param(call, i);
711                 ir_op   *op = get_irn_op(param);
712
713                 if (op == op_Const || op == op_SymConst)
714                         ++res;
715         }  /* for */
716         return res;
717 } /* cnt_const_args */
718
719 /**
720  * Update info on calls.
721  *
722  * @param call   The call
723  * @param graph  The graph entry containing the call
724  */
725 static void stat_update_call(ir_node *call, graph_entry_t *graph)
726 {
727         ir_node  *block = get_nodes_block(call);
728         ir_node  *ptr = get_Call_ptr(call);
729         entity   *ent = NULL;
730         ir_graph *callee = NULL;
731         int      num_const_args;
732
733         /*
734          * If the block is bad, the whole subgraph will collapse later
735          * so do not count this call.
736          * This happens in dead code.
737          */
738         if (is_Bad(block))
739                 return;
740
741         cnt_inc(&graph->cnt_all_calls);
742
743         /* found a call, this function is not a leaf */
744         graph->is_leaf = 0;
745
746         if (get_irn_op(ptr) == op_SymConst) {
747                 if (get_SymConst_kind(ptr) == symconst_addr_ent) {
748                         /* ok, we seems to know the entity */
749                         ent = get_SymConst_entity(ptr);
750                         callee = get_entity_irg(ent);
751
752                         /* it is recursive, if it calls at least once */
753                         if (callee == graph->irg)
754                                 graph->is_recursive = 1;
755                 }  /* if */
756         } else {
757                 /* indirect call, be could not predict */
758                 cnt_inc(&graph->cnt_indirect_calls);
759
760                 /* NOT a leaf call */
761                 graph->is_leaf_call = LCS_NON_LEAF_CALL;
762         }  /* if */
763
764         /* check, if it's a chain-call: Then, the call-block
765         * must dominate the end block. */
766         {
767                 ir_node *curr = get_irg_end_block(graph->irg);
768                 int depth = get_Block_dom_depth(block);
769
770                 for (; curr != block && get_Block_dom_depth(curr) > depth;) {
771                         curr = get_Block_idom(curr);
772
773                         if (! curr || is_no_Block(curr))
774                                 break;
775                 }  /* for */
776
777                 if (curr != block)
778                         graph->is_chain_call = 0;
779         }
780
781         /* check, if the callee is a leaf */
782         if (callee) {
783                 graph_entry_t *called = graph_get_entry(callee, status->irg_hash);
784
785                 if (called->is_analyzed) {
786                         if (! called->is_leaf)
787                                 graph->is_leaf_call = LCS_NON_LEAF_CALL;
788                 }  /* if */
789         }  /* if */
790
791         /* check, if arguments of the call are const */
792         num_const_args = cnt_const_args(call);
793
794         if (num_const_args > 0)
795                 cnt_inc(&graph->cnt_call_with_cnst_arg);
796 } /* stat_update_call */
797
798 /**
799  * Update info on calls for graphs on the wait queue.
800  */
801 static void stat_update_call_2(ir_node *call, graph_entry_t *graph)
802 {
803         ir_node  *block = get_nodes_block(call);
804         ir_node  *ptr = get_Call_ptr(call);
805         entity   *ent = NULL;
806         ir_graph *callee = NULL;
807
808         /*
809          * If the block is bad, the whole subgraph will collapse later
810          * so do not count this call.
811          * This happens in dead code.
812          */
813         if (is_Bad(block))
814                 return;
815
816         if (get_irn_op(ptr) == op_SymConst) {
817                 if (get_SymConst_kind(ptr) == symconst_addr_ent) {
818                         /* ok, we seems to know the entity */
819                         ent = get_SymConst_entity(ptr);
820                         callee = get_entity_irg(ent);
821                 }  /* if */
822         }  /* if */
823
824         /* check, if the callee is a leaf */
825         if (callee) {
826                 graph_entry_t *called = graph_get_entry(callee, status->irg_hash);
827
828                 assert(called->is_analyzed);
829
830                 if (! called->is_leaf)
831                         graph->is_leaf_call = LCS_NON_LEAF_CALL;
832         } else
833                 graph->is_leaf_call = LCS_NON_LEAF_CALL;
834 } /* stat_update_call_2 */
835
836 /**
837  * Walker for reachable nodes count.
838  */
839 static void update_node_stat(ir_node *node, void *env)
840 {
841         graph_entry_t *graph = env;
842         node_entry_t *entry;
843
844         ir_op *op = stat_get_irn_op(node);
845         int arity = get_irn_arity(node);
846
847         entry = opcode_get_entry(op, graph->opcode_hash);
848
849         cnt_inc(&entry->cnt_alive);
850         cnt_add_i(&graph->cnt_edges, arity);
851
852         /* count block edges */
853         undate_block_info(node, graph);
854
855         /* count extended block edges */
856         if (status->stat_options & FIRMSTAT_COUNT_EXTBB) {
857                 if (graph->irg != get_const_code_irg())
858                         update_extbb_info(node, graph);
859         }  /* if */
860
861         /* handle statistics for special node types */
862
863         if (op == op_Const) {
864                 if (status->stat_options & FIRMSTAT_COUNT_CONSTS) {
865                         /* check properties of constants */
866                         stat_update_const(status, node, graph);
867                 }  /* if */
868         } else if (op == op_Call) {
869                 /* check for properties that depends on calls like recursion/leaf/indirect call */
870                 stat_update_call(node, graph);
871         }  /* if */
872 } /* update_node_stat */
873
874 /**
875  * Walker for reachable nodes count for graphs on the wait_q.
876  */
877 static void update_node_stat_2(ir_node *node, void *env)
878 {
879         graph_entry_t *graph = env;
880
881         /* check for properties that depends on calls like recursion/leaf/indirect call */
882         if (is_Call(node))
883                 stat_update_call_2(node, graph);
884 } /* update_node_stat_2 */
885
886 /**
887  * Get the current address mark.
888  */
889 static unsigned get_adr_mark(graph_entry_t *graph, ir_node *node)
890 {
891         address_mark_entry_t *value = set_find(graph->address_mark, &node, sizeof(*value), HASH_PTR(node));
892
893         return value ? value->mark : 0;
894 } /* get_adr_mark */
895
896 /**
897  * Set the current address mark.
898  */
899 static void set_adr_mark(graph_entry_t *graph, ir_node *node, unsigned val)
900 {
901         address_mark_entry_t *value = set_insert(graph->address_mark, &node, sizeof(*value), HASH_PTR(node));
902
903         value->mark = val;
904 } /* set_adr_mark */
905
906 #if 0
907 /**
908  * a vcg attribute hook: Color a node with a different color if
909  * it's identified as a part of an address expression or at least referenced
910  * by an address expression.
911  */
912 static int stat_adr_mark_hook(FILE *F, ir_node *node, ir_node *local)
913 {
914         ir_node *n           = local ? local : node;
915         ir_graph *irg        = get_irn_irg(n);
916         graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
917         unsigned mark        = get_adr_mark(graph, n);
918
919         if (mark & MARK_ADDRESS_CALC)
920                 fprintf(F, "color: purple");
921         else if ((mark & (MARK_REF_ADR | MARK_REF_NON_ADR)) == MARK_REF_ADR)
922                 fprintf(F, "color: pink");
923         else if ((mark & (MARK_REF_ADR | MARK_REF_NON_ADR)) == (MARK_REF_ADR|MARK_REF_NON_ADR))
924                 fprintf(F, "color: lightblue");
925         else
926                 return 0;
927
928         /* I know the color! */
929         return 1;
930 } /* stat_adr_mark_hook */
931 #endif
932
933 /**
934  * walker that marks every node that is an address calculation
935  *
936  * predecessor nodes must be visited first. We ensure this by
937  * calling in in the post of an outs walk. This should work even in cycles,
938  * while the pre in a normal walk will not.
939  */
940 static void mark_address_calc(ir_node *node, void *env)
941 {
942         graph_entry_t *graph = env;
943         ir_mode *mode = get_irn_mode(node);
944         int i, n;
945         unsigned mark_preds = MARK_REF_NON_ADR;
946
947         if (! mode_is_numP(mode))
948                 return;
949
950         if (mode_is_reference(mode)) {
951                 /* a reference is calculated here, we are sure */
952                 set_adr_mark(graph, node, MARK_ADDRESS_CALC);
953
954                 mark_preds = MARK_REF_ADR;
955         } else {
956                 unsigned mark = get_adr_mark(graph, node);
957
958                 if ((mark & (MARK_REF_ADR | MARK_REF_NON_ADR)) == MARK_REF_ADR) {
959                 /*
960                 * this node has not an reference mode, but is only
961                 * referenced by address calculations
962                         */
963                         mark_preds = MARK_REF_ADR;
964                 }  /* if */
965         }  /* if */
966
967         /* mark all predecessors */
968         for (i = 0, n = get_irn_arity(node); i < n; ++i) {
969                 ir_node *pred = get_irn_n(node, i);
970
971                 set_adr_mark(graph, pred, get_adr_mark(graph, pred) | mark_preds);
972         }  /* for */
973 } /* mark_address_calc */
974
975 /**
976  * Called for every graph when the graph is either deleted or stat_dump_snapshot()
977  * is called, must recalculate all statistic info.
978  *
979  * @param global    The global entry
980  * @param graph     The current entry
981  */
982 static void update_graph_stat(graph_entry_t *global, graph_entry_t *graph)
983 {
984         node_entry_t *entry;
985
986         /* clear first the alive counter in the graph */
987         for (entry = pset_first(graph->opcode_hash); entry; entry = pset_next(graph->opcode_hash)) {
988                 cnt_clr(&entry->cnt_alive);
989         }  /* for */
990
991         /* set pessimistic values */
992         graph->is_leaf       = 1;
993         graph->is_leaf_call  = LCS_UNKNOWN;
994         graph->is_recursive  = 0;
995         graph->is_chain_call = 1;
996
997         /* create new block counter */
998         graph->block_hash = new_pset(block_cmp, 5);
999
1000         /* we need dominator info */
1001         if (graph->irg != get_const_code_irg()) {
1002                 assure_doms(graph->irg);
1003
1004                 if (status->stat_options & FIRMSTAT_COUNT_EXTBB) {
1005                         /* we need extended basic blocks */
1006                         compute_extbb(graph->irg);
1007
1008                         /* create new extbb counter */
1009                         graph->extbb_hash = new_pset(block_cmp, 5);
1010                 }  /* if */
1011         }  /* if */
1012
1013         /* count the nodes in the graph */
1014         irg_walk_graph(graph->irg, update_node_stat, NULL, graph);
1015
1016 #if 0
1017         /* Uncomment this code if chain-call means call exact one */
1018         entry = opcode_get_entry(op_Call, graph->opcode_hash);
1019
1020         /* check if we have more than 1 call */
1021         if (cnt_gt(entry->cnt_alive, 1))
1022                 graph->is_chain_call = 0;
1023 #endif
1024
1025         /* recursive functions are never chain calls, leafs don't have calls */
1026         if (graph->is_recursive || graph->is_leaf)
1027                 graph->is_chain_call = 0;
1028
1029         /* assume we walk every graph only ONCE, we could sum here the global count */
1030         for (entry = pset_first(graph->opcode_hash); entry; entry = pset_next(graph->opcode_hash)) {
1031                 node_entry_t *g_entry = opcode_get_entry(entry->op, global->opcode_hash);
1032
1033                 /* update the node counter */
1034                 cnt_add(&g_entry->cnt_alive, &entry->cnt_alive);
1035         }  /* for */
1036
1037         /* update the edge counter */
1038         cnt_add(&global->cnt_edges, &graph->cnt_edges);
1039
1040         /* count the number of address calculation */
1041         if (graph->irg != get_const_code_irg()) {
1042                 ir_graph *rem = current_ir_graph;
1043
1044                 if (get_irg_outs_state(graph->irg) != outs_consistent)
1045                         compute_irg_outs(graph->irg);
1046
1047                 /* Must be done an the outs graph */
1048                 current_ir_graph = graph->irg;
1049                 irg_out_walk(get_irg_start(graph->irg), NULL, mark_address_calc, graph);
1050                 current_ir_graph = rem;
1051
1052 #if 0
1053                 /* register the vcg hook and dump the graph for test */
1054                 set_dump_node_vcgattr_hook(stat_adr_mark_hook);
1055                 dump_ir_block_graph(graph->irg, "-adr");
1056                 set_dump_node_vcgattr_hook(NULL);
1057 #endif
1058         }  /* if */
1059
1060         /* count the DAG's */
1061         if (status->stat_options & FIRMSTAT_COUNT_DAG)
1062                 count_dags_in_graph(global, graph);
1063
1064         /* calculate the patterns of this graph */
1065         stat_calc_pattern_history(graph->irg);
1066
1067         /* leaf function did not call others */
1068         if (graph->is_leaf)
1069                 graph->is_leaf_call = LCS_NON_LEAF_CALL;
1070         else if (graph->is_leaf_call == LCS_UNKNOWN) {
1071                 /* we still don't know if this graph calls leaf-functions, so enqueue */
1072                 pdeq_putl(status->wait_q, graph);
1073         }  /* if */
1074
1075         /* we have analyzed this graph */
1076         graph->is_analyzed = 1;
1077 } /* update_graph_stat */
1078
1079 /**
1080  * Called for every graph that was on the wait_q in stat_dump_snapshot()
1081  * must finish all statistic info calculations.
1082  *
1083  * @param global    The global entry
1084  * @param graph     The current entry
1085  */
1086 static void update_graph_stat_2(graph_entry_t *global, graph_entry_t *graph)
1087 {
1088         if (graph->is_deleted) {
1089                 /* deleted, ignore */
1090                 return;
1091         }
1092
1093         if (graph->irg) {
1094                 /* count the nodes in the graph */
1095                 irg_walk_graph(graph->irg, update_node_stat_2, NULL, graph);
1096
1097                 if (graph->is_leaf_call == LCS_UNKNOWN)
1098                         graph->is_leaf_call = LCS_LEAF_CALL;
1099         }  /* if */
1100 } /* update_graph_stat_2 */
1101
1102 /**
1103  * Register a dumper.
1104  */
1105 static void stat_register_dumper(const dumper_t *dumper)
1106 {
1107         dumper_t *p = xmalloc(sizeof(*p));
1108
1109         if (p) {
1110                 memcpy(p, dumper, sizeof(*p));
1111
1112                 p->next        = status->dumper;
1113                 p->status      = status;
1114                 status->dumper = p;
1115         }
1116
1117         /* FIXME: memory leak */
1118 } /* stat_register_dumper */
1119
1120 /**
1121  * Dumps the statistics of an IR graph.
1122  */
1123 static void stat_dump_graph(graph_entry_t *entry)
1124 {
1125         dumper_t *dumper;
1126
1127         for (dumper = status->dumper; dumper; dumper = dumper->next) {
1128                 if (dumper->dump_graph)
1129                         dumper->dump_graph(dumper, entry);
1130         }  /* for */
1131 } /* stat_dump_graph */
1132
1133 /**
1134  * Calls all registered dumper functions.
1135  */
1136 static void stat_dump_registered(graph_entry_t *entry)
1137 {
1138         dumper_t *dumper;
1139
1140         for (dumper = status->dumper; dumper; dumper = dumper->next) {
1141                 if (dumper->func_map) {
1142                         dump_graph_FUNC func;
1143
1144                         foreach_pset(dumper->func_map, func)
1145                                 func(dumper, entry);
1146                 }  /* if */
1147         }  /* for */
1148 } /* stat_dump_registered */
1149
1150 /**
1151  * Dumps a constant table.
1152  */
1153 static void stat_dump_consts(const constant_info_t *tbl)
1154 {
1155         dumper_t *dumper;
1156
1157         for (dumper = status->dumper; dumper; dumper = dumper->next) {
1158                 if (dumper->dump_const_tbl)
1159                         dumper->dump_const_tbl(dumper, tbl);
1160         }  /* for */
1161 } /* stat_dump_consts */
1162
1163 /**
1164  * Initialize the dumper.
1165  */
1166 static void stat_dump_init(const char *name)
1167 {
1168         dumper_t *dumper;
1169
1170         for (dumper = status->dumper; dumper; dumper = dumper->next) {
1171                 if (dumper->init)
1172                         dumper->init(dumper, name);
1173         }  /* for */
1174 } /* stat_dump_init */
1175
1176 /**
1177  * Finish the dumper.
1178  */
1179 static void stat_dump_finish(void)
1180 {
1181         dumper_t *dumper;
1182
1183         for (dumper = status->dumper; dumper; dumper = dumper->next) {
1184                 if (dumper->finish)
1185                         dumper->finish(dumper);
1186         }  /* for */
1187 } /* stat_dump_finish */
1188
1189 /**
1190  * Register an additional function for all dumper.
1191  */
1192 void stat_register_dumper_func(dump_graph_FUNC func) {
1193         dumper_t *dumper;
1194
1195         for (dumper = status->dumper; dumper; dumper = dumper->next) {
1196                 if (! dumper->func_map)
1197                         dumper->func_map = pset_new_ptr(3);
1198                 pset_insert_ptr(dumper->func_map, func);
1199         }  /* for */
1200 } /* stat_register_dumper_func */
1201
1202 /* ---------------------------------------------------------------------- */
1203
1204 /*
1205  * Helper: get an ir_op from an opcode.
1206  */
1207 ir_op *stat_get_op_from_opcode(opcode code)
1208 {
1209         return opcode_find_entry(code, status->ir_op_hash);
1210 } /* stat_get_op_from_opcode */
1211
1212 /**
1213  * Hook: A new IR op is registered.
1214  *
1215  * @param ctx  the hook context
1216  * @param op   the new IR opcode that was created.
1217  */
1218 static void stat_new_ir_op(void *ctx, ir_op *op)
1219 {
1220         if (! status->stat_options)
1221                 return;
1222
1223         STAT_ENTER;
1224         {
1225                 graph_entry_t *graph = graph_get_entry(NULL, status->irg_hash);
1226
1227                 /* execute for side effect :-) */
1228                 (void)opcode_get_entry(op, graph->opcode_hash);
1229
1230                 pset_insert(status->ir_op_hash, op, op->code);
1231         }
1232         STAT_LEAVE;
1233 } /* stat_new_ir_op */
1234
1235 /**
1236  * Hook: An IR op is freed.
1237  *
1238  * @param ctx  the hook context
1239  * @param op   the IR opcode that is freed
1240  */
1241 static void stat_free_ir_op(void *ctx, ir_op *op)
1242 {
1243         if (! status->stat_options)
1244                 return;
1245
1246         STAT_ENTER;
1247         {
1248         }
1249         STAT_LEAVE;
1250 } /* stat_free_ir_op */
1251
1252 /**
1253  * Hook: A new node is created.
1254  *
1255  * @param ctx   the hook context
1256  * @param irg   the IR graph on which the node is created
1257  * @param node  the new IR node that was created
1258  */
1259 static void stat_new_node(void *ctx, ir_graph *irg, ir_node *node)
1260 {
1261         if (! status->stat_options)
1262                 return;
1263
1264         /* do NOT count during dead node elimination */
1265         if (status->in_dead_node_elim > 0)
1266                 return;
1267
1268         STAT_ENTER;
1269         {
1270                 node_entry_t *entry;
1271                 graph_entry_t *graph;
1272                 ir_op *op = stat_get_irn_op(node);
1273
1274                 /* increase global value */
1275                 graph = graph_get_entry(NULL, status->irg_hash);
1276                 entry = opcode_get_entry(op, graph->opcode_hash);
1277                 cnt_inc(&entry->new_node);
1278
1279                 /* increase local value */
1280                 graph = graph_get_entry(current_ir_graph, status->irg_hash);
1281                 entry = opcode_get_entry(op, graph->opcode_hash);
1282                 cnt_inc(&entry->new_node);
1283         }
1284         STAT_LEAVE;
1285 } /* stat_new_node */
1286
1287 /**
1288  * Hook: A node is changed into a Id node
1289  *
1290  * @param ctx   the hook context
1291  * @param node  the IR node that will be turned into an ID
1292  */
1293 static void stat_turn_into_id(void *ctx, ir_node *node)
1294 {
1295         if (! status->stat_options)
1296                 return;
1297
1298         STAT_ENTER;
1299         {
1300                 node_entry_t *entry;
1301                 graph_entry_t *graph;
1302                 ir_op *op = stat_get_irn_op(node);
1303
1304                 /* increase global value */
1305                 graph = graph_get_entry(NULL, status->irg_hash);
1306                 entry = opcode_get_entry(op, graph->opcode_hash);
1307                 cnt_inc(&entry->into_Id);
1308
1309                 /* increase local value */
1310                 graph = graph_get_entry(current_ir_graph, status->irg_hash);
1311                 entry = opcode_get_entry(op, graph->opcode_hash);
1312                 cnt_inc(&entry->into_Id);
1313         }
1314         STAT_LEAVE;
1315 } /* stat_turn_into_id */
1316
1317 /**
1318  * Hook: A new graph was created
1319  *
1320  * @param ctx  the hook context
1321  * @param irg  the new IR graph that was created
1322  * @param ent  the entity of this graph
1323  */
1324 static void stat_new_graph(void *ctx, ir_graph *irg, entity *ent)
1325 {
1326         if (! status->stat_options)
1327                 return;
1328
1329         STAT_ENTER;
1330         {
1331                 /* execute for side effect :-) */
1332                 graph_entry_t * graph = graph_get_entry(irg, status->irg_hash);
1333
1334                 graph->ent           = ent;
1335                 graph->is_deleted    = 0;
1336                 graph->is_leaf       = 0;
1337                 graph->is_leaf_call  = 0;
1338                 graph->is_recursive  = 0;
1339                 graph->is_chain_call = 0;
1340                 graph->is_analyzed   = 0;
1341         }
1342         STAT_LEAVE;
1343 } /* stat_new_graph */
1344
1345 /**
1346  * Hook: A graph will be deleted
1347  *
1348  * @param ctx  the hook context
1349  * @param irg  the IR graph that will be deleted
1350  *
1351  * Note that we still hold the information for this graph
1352  * in our hash maps, only a flag is set which prevents this
1353  * information from being changed, it's "frozen" from now.
1354  */
1355 static void stat_free_graph(void *ctx, ir_graph *irg)
1356 {
1357         if (! status->stat_options)
1358                 return;
1359
1360         STAT_ENTER;
1361         {
1362                 graph_entry_t *graph  = graph_get_entry(irg, status->irg_hash);
1363                 graph_entry_t *global = graph_get_entry(NULL, status->irg_hash);
1364
1365                 graph->is_deleted = 1;
1366
1367                 if (status->stat_options & FIRMSTAT_COUNT_DELETED) {
1368                         /* count the nodes of the graph yet, it will be destroyed later */
1369                         update_graph_stat(global, graph);
1370                 }  /* if */
1371         }
1372         STAT_LEAVE;
1373 } /* stat_free_graph */
1374
1375 /**
1376  * Hook: A walk over a graph is initiated. Do not count walks from statistic code.
1377  *
1378  * @param ctx  the hook context
1379  * @param irg  the IR graph that will be walked
1380  * @param pre  the pre walker
1381  * @param post the post walker
1382  */
1383 static void stat_irg_walk(void *ctx, ir_graph *irg, generic_func *pre, generic_func *post)
1384 {
1385         if (! status->stat_options)
1386                 return;
1387
1388         STAT_ENTER_SINGLE;
1389         {
1390                 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1391
1392                 cnt_inc(&graph->cnt_walked);
1393         }
1394         STAT_LEAVE;
1395 } /* stat_irg_walk */
1396
1397 /**
1398  * Hook: A walk over a graph in block-wise order is initiated. Do not count walks from statistic code.
1399  *
1400  * @param ctx  the hook context
1401  * @param irg  the IR graph that will be walked
1402  * @param pre  the pre walker
1403  * @param post the post walker
1404  */
1405 static void stat_irg_walk_blkwise(void *ctx, ir_graph *irg, generic_func *pre, generic_func *post)
1406 {
1407         /* for now, do NOT differentiate between blockwise and normal */
1408         stat_irg_walk(ctx, irg, pre, post);
1409 } /* stat_irg_walk_blkwise */
1410
1411 /**
1412  * Hook: A walk over the graph's blocks is initiated. Do not count walks from statistic code.
1413  *
1414  * @param ctx  the hook context
1415  * @param irg  the IR graph that will be walked
1416  * @param node the IR node
1417  * @param pre  the pre walker
1418  * @param post the post walker
1419  */
1420 static void stat_irg_block_walk(void *ctx, ir_graph *irg, ir_node *node, generic_func *pre, generic_func *post)
1421 {
1422         if (! status->stat_options)
1423                 return;
1424
1425         STAT_ENTER_SINGLE;
1426         {
1427                 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1428
1429                 cnt_inc(&graph->cnt_walked_blocks);
1430         }
1431         STAT_LEAVE;
1432 } /* stat_irg_block_walk */
1433
1434 /**
1435  * Called for every node that is removed due to an optimization.
1436  *
1437  * @param n     the IR node that will be removed
1438  * @param hmap  the hash map containing ir_op* -> opt_entry_t*
1439  */
1440 static void removed_due_opt(ir_node *n, hmap_opt_entry_t *hmap)
1441 {
1442         ir_op *op          = stat_get_irn_op(n);
1443         opt_entry_t *entry = opt_get_entry(op, hmap);
1444
1445         /* increase global value */
1446         cnt_inc(&entry->count);
1447 } /* removed_due_opt */
1448
1449 /**
1450  * Hook: Some nodes were optimized into some others due to an optimization.
1451  *
1452  * @param ctx  the hook context
1453  */
1454 static void stat_merge_nodes(
1455     void *ctx,
1456     ir_node **new_node_array, int new_num_entries,
1457     ir_node **old_node_array, int old_num_entries,
1458     hook_opt_kind opt)
1459 {
1460         if (! status->stat_options)
1461                 return;
1462
1463         STAT_ENTER;
1464         {
1465                 int i, j;
1466                 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1467
1468                 if (status->reassoc_run)
1469                         opt = HOOK_OPT_REASSOC;
1470
1471                 for (i = 0; i < old_num_entries; ++i) {
1472                         for (j = 0; j < new_num_entries; ++j) {
1473                                 if (old_node_array[i] == new_node_array[j])
1474                                         break;
1475
1476                                 /* nodes might be in new and old, these are NOT removed */
1477                                 if (j >= new_num_entries) {
1478                                         int xopt = opt;
1479
1480                                         /* sometimes we did not detect, that it is replaced by a Const */
1481                                         if (opt == HOOK_OPT_CONFIRM && new_num_entries == 1) {
1482                                                 ir_op *op = get_irn_op(new_node_array[0]);
1483
1484                                                 if (op == op_Const || op == op_SymConst)
1485                                                         xopt = HOOK_OPT_CONFIRM_C;
1486                                         }  /* if */
1487
1488                                         removed_due_opt(old_node_array[i], graph->opt_hash[xopt]);
1489                                 }  /* if */
1490                         }  /* for */
1491                 }  /* for */
1492         }
1493         STAT_LEAVE;
1494 } /* stat_merge_nodes */
1495
1496 /**
1497  * Hook: Reassociation is started/stopped.
1498  *
1499  * @param ctx   the hook context
1500  * @param flag  if non-zero, reassociation is started else stopped
1501  */
1502 static void stat_reassociate(void *ctx, int flag)
1503 {
1504         if (! status->stat_options)
1505                 return;
1506
1507         STAT_ENTER;
1508         {
1509                 status->reassoc_run = flag;
1510         }
1511         STAT_LEAVE;
1512 } /* stat_reassociate */
1513
1514 /**
1515  * Hook: A node was lowered into other nodes
1516  *
1517  * @param ctx  the hook context
1518  * @param node the IR node that will be lowered
1519  */
1520 static void stat_lower(void *ctx, ir_node *node)
1521 {
1522         if (! status->stat_options)
1523                 return;
1524
1525         STAT_ENTER;
1526         {
1527                 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1528
1529                 removed_due_opt(node, graph->opt_hash[HOOK_LOWERED]);
1530         }
1531         STAT_LEAVE;
1532 } /* stat_lower */
1533
1534 /**
1535  * Hook: A graph was inlined.
1536  *
1537  * @param ctx  the hook context
1538  * @param call the IR call that will re changed into the body of
1539  *             the called IR graph
1540  * @param called_irg  the IR graph representing the called routine
1541  */
1542 static void stat_inline(void *ctx, ir_node *call, ir_graph *called_irg)
1543 {
1544         if (! status->stat_options)
1545                 return;
1546
1547         STAT_ENTER;
1548         {
1549                 ir_graph *irg = get_irn_irg(call);
1550                 graph_entry_t *i_graph = graph_get_entry(called_irg, status->irg_hash);
1551                 graph_entry_t *graph   = graph_get_entry(irg, status->irg_hash);
1552
1553                 cnt_inc(&graph->cnt_got_inlined);
1554                 cnt_inc(&i_graph->cnt_was_inlined);
1555         }
1556         STAT_LEAVE;
1557 } /* stat_inline */
1558
1559 /**
1560  * Hook: A graph with tail-recursions was optimized.
1561  *
1562  * @param ctx  the hook context
1563  */
1564 static void stat_tail_rec(void *ctx, ir_graph *irg, int n_calls)
1565 {
1566         if (! status->stat_options)
1567                 return;
1568
1569         STAT_ENTER;
1570         {
1571                 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1572
1573                 graph->num_tail_recursion += n_calls;
1574         }
1575         STAT_LEAVE;
1576 } /* stat_tail_rec */
1577
1578 /**
1579  * Strength reduction was performed on an iteration variable.
1580  *
1581  * @param ctx  the hook context
1582  */
1583 static void stat_strength_red(void *ctx, ir_graph *irg, ir_node *strong)
1584 {
1585         if (! status->stat_options)
1586                 return;
1587
1588         STAT_ENTER;
1589         {
1590                 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1591                 cnt_inc(&graph->cnt_strength_red);
1592
1593                 removed_due_opt(strong, graph->opt_hash[HOOK_OPT_STRENGTH_RED]);
1594         }
1595         STAT_LEAVE;
1596 } /* stat_strength_red */
1597
1598 /**
1599  * Hook: Start/Stop the dead node elimination.
1600  *
1601  * @param ctx  the hook context
1602  */
1603 static void stat_dead_node_elim(void *ctx, ir_graph *irg, int start)
1604 {
1605         if (! status->stat_options)
1606                 return;
1607
1608         if (start)
1609                 ++status->in_dead_node_elim;
1610         else
1611                 --status->in_dead_node_elim;
1612 } /* stat_dead_node_elim */
1613
1614 /**
1615  * Hook: if-conversion was tried.
1616  */
1617 static void stat_if_conversion(void *context, ir_graph *irg, ir_node *phi,
1618                                int pos, ir_node *mux, if_result_t reason)
1619 {
1620         if (! status->stat_options)
1621                 return;
1622
1623         STAT_ENTER;
1624         {
1625                 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1626
1627                 cnt_inc(&graph->cnt_if_conv[reason]);
1628         }
1629         STAT_LEAVE;
1630 } /* stat_if_conversion */
1631
1632 /**
1633  * Hook: real function call was optimized.
1634  */
1635 static void stat_func_call(void *context, ir_graph *irg, ir_node *call)
1636 {
1637         if (! status->stat_options)
1638                 return;
1639
1640         STAT_ENTER;
1641         {
1642                 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1643
1644                 cnt_inc(&graph->cnt_real_func_call);
1645         }
1646         STAT_LEAVE;
1647 } /* stat_func_call */
1648
1649 /**
1650  * Hook: A multiply was replaced by a series of Shifts/Adds/Subs.
1651  *
1652  * @param ctx  the hook context
1653  */
1654 static void stat_arch_dep_replace_mul_with_shifts(void *ctx, ir_node *mul)
1655 {
1656         if (! status->stat_options)
1657                 return;
1658
1659         STAT_ENTER;
1660         {
1661                 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1662                 removed_due_opt(mul, graph->opt_hash[HOOK_OPT_ARCH_DEP]);
1663         }
1664         STAT_LEAVE;
1665 } /* stat_arch_dep_replace_mul_with_shifts */
1666
1667 /**
1668  * Hook: A division by const was replaced.
1669  *
1670  * @param ctx   the hook context
1671  * @param node  the division node that will be optimized
1672  */
1673 static void stat_arch_dep_replace_division_by_const(void *ctx, ir_node *node)
1674 {
1675         if (! status->stat_options)
1676                 return;
1677
1678         STAT_ENTER;
1679         {
1680                 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1681                 removed_due_opt(node, graph->opt_hash[HOOK_OPT_ARCH_DEP]);
1682         }
1683         STAT_LEAVE;
1684 } /* stat_arch_dep_replace_division_by_const */
1685
1686 /*
1687  * Update the register pressure of a block.
1688  *
1689  * @param irg        the irg containing the block
1690  * @param block      the block for which the reg pressure should be set
1691  * @param pressure   the pressure
1692  * @param class_name the name of the register class
1693  */
1694 void stat_be_block_regpressure(ir_graph *irg, ir_node *block, int pressure, const char *class_name)
1695 {
1696         if (! status->stat_options)
1697                 return;
1698
1699         STAT_ENTER;
1700         {
1701                 graph_entry_t        *graph = graph_get_entry(irg, status->irg_hash);
1702                 be_block_entry_t     *block_ent;
1703                 reg_pressure_entry_t *rp_ent;
1704
1705                 block_ent = be_block_get_entry(&status->be_data, get_irn_node_nr(block), graph->be_block_hash);
1706                 rp_ent    = obstack_alloc(&status->be_data, sizeof(*rp_ent));
1707                 memset(rp_ent, 0, sizeof(*rp_ent));
1708
1709                 rp_ent->class_name = class_name;
1710                 rp_ent->pressure   = pressure;
1711
1712                 pset_insert(block_ent->reg_pressure, rp_ent, HASH_PTR(class_name));
1713         }
1714         STAT_LEAVE;
1715 } /* stat_be_block_regpressure */
1716
1717 /**
1718  * Update the distribution of ready nodes of a block
1719  *
1720  * @param irg        the irg containing the block
1721  * @param block      the block for which the reg pressure should be set
1722  * @param num_ready  the number of ready nodes
1723  */
1724 void stat_be_block_sched_ready(ir_graph *irg, ir_node *block, int num_ready)
1725 {
1726         if (! status->stat_options)
1727                 return;
1728
1729         STAT_ENTER;
1730         {
1731                 graph_entry_t    *graph = graph_get_entry(irg, status->irg_hash);
1732                 be_block_entry_t *block_ent;
1733
1734                 block_ent = be_block_get_entry(&status->be_data, get_irn_node_nr(block), graph->be_block_hash);
1735
1736                 /* increase the counter of corresponding number of ready nodes */
1737                 stat_inc_int_distrib_tbl(block_ent->sched_ready, num_ready);
1738         }
1739         STAT_LEAVE;
1740 } /* stat_be_block_sched_ready */
1741
1742 /**
1743  * Update the permutation statistic of a block.
1744  *
1745  * @param class_name the name of the register class
1746  * @param n_regs     number of registers in the register class
1747  * @param perm       the perm node
1748  * @param block      the block containing the perm
1749  * @param size       the size of the perm
1750  * @param real_size  number of pairs with different registers
1751  */
1752 void stat_be_block_stat_perm(const char *class_name, int n_regs, ir_node *perm, ir_node *block,
1753                              int size, int real_size)
1754 {
1755         if (! status->stat_options)
1756                 return;
1757
1758         STAT_ENTER;
1759         {
1760                 graph_entry_t      *graph = graph_get_entry(get_irn_irg(block), status->irg_hash);
1761                 be_block_entry_t   *block_ent;
1762                 perm_class_entry_t *pc_ent;
1763                 perm_stat_entry_t  *ps_ent;
1764
1765                 block_ent = be_block_get_entry(&status->be_data, get_irn_node_nr(block), graph->be_block_hash);
1766                 pc_ent    = perm_class_get_entry(&status->be_data, class_name, block_ent->perm_class_stat);
1767                 ps_ent    = perm_stat_get_entry(&status->be_data, perm, pc_ent->perm_stat);
1768
1769                 pc_ent->n_regs = n_regs;
1770
1771                 /* update information */
1772                 ps_ent->size      = size;
1773                 ps_ent->real_size = real_size;
1774         }
1775         STAT_LEAVE;
1776 } /* stat_be_block_stat_perm */
1777
1778 /**
1779  * Update the permutation statistic of a single perm.
1780  *
1781  * @param class_name the name of the register class
1782  * @param perm       the perm node
1783  * @param block      the block containing the perm
1784  * @param is_chain   1 if chain, 0 if cycle
1785  * @param size       length of the cycle/chain
1786  * @param n_ops      the number of ops representing this cycle/chain after lowering
1787  */
1788 void stat_be_block_stat_permcycle(const char *class_name, ir_node *perm, ir_node *block,
1789                                   int is_chain, int size, int n_ops)
1790 {
1791         if (! status->stat_options)
1792                 return;
1793
1794         STAT_ENTER;
1795         {
1796                 graph_entry_t      *graph = graph_get_entry(get_irn_irg(block), status->irg_hash);
1797                 be_block_entry_t   *block_ent;
1798                 perm_class_entry_t *pc_ent;
1799                 perm_stat_entry_t  *ps_ent;
1800
1801                 block_ent = be_block_get_entry(&status->be_data, get_irn_node_nr(block), graph->be_block_hash);
1802                 pc_ent    = perm_class_get_entry(&status->be_data, class_name, block_ent->perm_class_stat);
1803                 ps_ent    = perm_stat_get_entry(&status->be_data, perm, pc_ent->perm_stat);
1804
1805                 if (is_chain) {
1806                         ps_ent->n_copies += n_ops;
1807                         stat_inc_int_distrib_tbl(ps_ent->chains, size);
1808                 } else {
1809                         ps_ent->n_exchg += n_ops;
1810                         stat_inc_int_distrib_tbl(ps_ent->cycles, size);
1811                 }  /* if */
1812         }
1813         STAT_LEAVE;
1814 } /* stat_be_block_stat_permcycle */
1815
1816 /* Dumps a statistics snapshot. */
1817 void stat_dump_snapshot(const char *name, const char *phase)
1818 {
1819         char fname[2048];
1820         const char *p;
1821         int l;
1822
1823         if (! status->stat_options)
1824                 return;
1825
1826         STAT_ENTER;
1827         {
1828                 graph_entry_t *entry;
1829                 graph_entry_t *global = graph_get_entry(NULL, status->irg_hash);
1830
1831                 /*
1832                  * The constant counter is only global, so we clear it here.
1833                  * Note that it does NOT contain the constants in DELETED
1834                  * graphs due to this.
1835                  */
1836                 if (status->stat_options & FIRMSTAT_COUNT_CONSTS)
1837                         stat_const_clear(status);
1838
1839                 /* build the name */
1840                 p = strrchr(name, '/');
1841 #ifdef _WIN32
1842                 {
1843                         const char *q;
1844
1845                         q = strrchr(name, '\\');
1846
1847                         /* NULL might be not the smallest pointer */
1848                         if (q && (!p || q > p))
1849                                 p = q;
1850                 }
1851 #endif /* _WIN32 */
1852                 if (p) {
1853                         ++p;
1854                         l = p - name;
1855
1856                         if (l > sizeof(fname) - 1)
1857                                 l = sizeof(fname) - 1;
1858
1859                         memcpy(fname, name, l);
1860                         fname[l] = '\0';
1861                 } else {
1862                         fname[0] = '\0';
1863                         p = name;
1864                 }  /* if */
1865                 strncat(fname, "firmstat-", sizeof(fname));
1866                 strncat(fname, phase, sizeof(fname));
1867                 strncat(fname, "-", sizeof(fname));
1868                 strncat(fname, p, sizeof(fname));
1869
1870                 stat_dump_init(fname);
1871
1872                 /* calculate the graph statistics */
1873                 for (entry = pset_first(status->irg_hash); entry; entry = pset_next(status->irg_hash)) {
1874                         if (entry->irg == NULL) {
1875                                 /* special entry for the global count */
1876                                 continue;
1877                         }  /* if */
1878                         if (! entry->is_deleted) {
1879                                 /* the graph is still alive, count the nodes on it */
1880                                 update_graph_stat(global, entry);
1881                         }  /* if */
1882                 }  /* for */
1883
1884                 /* some calculations are dependent, we pushed them on the wait_q */
1885                 while (! pdeq_empty(status->wait_q)) {
1886                         entry = pdeq_getr(status->wait_q);
1887
1888                         update_graph_stat_2(global, entry);
1889                 }  /* while */
1890
1891                 /* dump per graph */
1892                 for (entry = pset_first(status->irg_hash); entry; entry = pset_next(status->irg_hash)) {
1893                         if (entry->irg == NULL) {
1894                                 /* special entry for the global count */
1895                                 continue;
1896                         }  /* if */
1897
1898                         if (! entry->is_deleted || status->stat_options & FIRMSTAT_COUNT_DELETED) {
1899                                 stat_dump_graph(entry);
1900                                 stat_dump_registered(entry);
1901                         }  /* if */
1902
1903                         if (! entry->is_deleted) {
1904                                 /* clear the counter that are not accumulated */
1905                                 graph_clear_entry(entry, 0);
1906                         }  /* if */
1907                 }  /* for */
1908
1909                 /* dump global */
1910                 stat_dump_graph(global);
1911
1912                 /* dump the const info */
1913                 if (status->stat_options & FIRMSTAT_COUNT_CONSTS)
1914                         stat_dump_consts(&status->const_info);
1915
1916                 stat_dump_finish();
1917
1918                 stat_finish_pattern_history();
1919
1920                 /* clear the global counter here */
1921                 {
1922                         node_entry_t *entry;
1923
1924                         for (entry = pset_first(global->opcode_hash); entry; entry = pset_next(global->opcode_hash)) {
1925                                 opcode_clear_entry(entry);
1926                         }  /* for */
1927                         /* clear all global counter */
1928                         graph_clear_entry(global, 1);
1929                 }
1930         }
1931         STAT_LEAVE;
1932 } /* stat_dump_snapshot */
1933
1934 /** the hook entries for the Firm statistics module */
1935 static hook_entry_t stat_hooks[hook_last];
1936
1937 /* initialize the statistics module. */
1938 void firm_init_stat(unsigned enable_options)
1939 {
1940 #define X(a)  a, sizeof(a)-1
1941 #define HOOK(h, fkt) \
1942         stat_hooks[h].hook._##h = fkt; register_hook(h, &stat_hooks[h])
1943         unsigned num = 0;
1944
1945         if (! (enable_options & FIRMSTAT_ENABLED))
1946                 return;
1947
1948         status = xmalloc(sizeof(*status));
1949         memset(status, 0, sizeof(*status));
1950
1951         /* enable statistics */
1952         status->stat_options = enable_options & FIRMSTAT_ENABLED ? enable_options : 0;
1953
1954         /* register all hooks */
1955         HOOK(hook_new_ir_op,                          stat_new_ir_op);
1956         HOOK(hook_free_ir_op,                         stat_free_ir_op);
1957         HOOK(hook_new_node,                           stat_new_node);
1958         HOOK(hook_turn_into_id,                       stat_turn_into_id);
1959         HOOK(hook_new_graph,                          stat_new_graph);
1960         HOOK(hook_free_graph,                         stat_free_graph);
1961         HOOK(hook_irg_walk,                           stat_irg_walk);
1962         HOOK(hook_irg_walk_blkwise,                   stat_irg_walk_blkwise);
1963         HOOK(hook_irg_block_walk,                     stat_irg_block_walk);
1964         HOOK(hook_merge_nodes,                        stat_merge_nodes);
1965         HOOK(hook_reassociate,                        stat_reassociate);
1966         HOOK(hook_lower,                              stat_lower);
1967         HOOK(hook_inline,                             stat_inline);
1968         HOOK(hook_tail_rec,                           stat_tail_rec);
1969         HOOK(hook_strength_red,                       stat_strength_red);
1970         HOOK(hook_dead_node_elim,                     stat_dead_node_elim);
1971         HOOK(hook_if_conversion,                      stat_if_conversion);
1972         HOOK(hook_func_call,                          stat_func_call);
1973         HOOK(hook_arch_dep_replace_mul_with_shifts,   stat_arch_dep_replace_mul_with_shifts);
1974         HOOK(hook_arch_dep_replace_division_by_const, stat_arch_dep_replace_division_by_const);
1975
1976         obstack_init(&status->cnts);
1977         obstack_init(&status->be_data);
1978
1979         /* create the hash-tables */
1980         status->irg_hash   = new_pset(graph_cmp, 8);
1981         status->ir_op_hash = new_pset(opcode_cmp_2, 1);
1982
1983         /* create the wait queue */
1984         status->wait_q     = new_pdeq();
1985
1986         if (enable_options & FIRMSTAT_COUNT_STRONG_OP) {
1987                 /* build the pseudo-ops */
1988
1989                 _op_Phi0.code    = --num;
1990                 _op_Phi0.name    = new_id_from_chars(X("Phi0"));
1991
1992                 _op_PhiM.code    = --num;
1993                 _op_PhiM.name    = new_id_from_chars(X("PhiM"));
1994
1995                 _op_ProjM.code   = --num;
1996                 _op_ProjM.name   = new_id_from_chars(X("ProjM"));
1997
1998                 _op_MulC.code    = --num;
1999                 _op_MulC.name    = new_id_from_chars(X("MulC"));
2000
2001                 _op_DivC.code    = --num;
2002                 _op_DivC.name    = new_id_from_chars(X("DivC"));
2003
2004                 _op_ModC.code    = --num;
2005                 _op_ModC.name    = new_id_from_chars(X("ModC"));
2006
2007                 _op_DivModC.code = --num;
2008                 _op_DivModC.name = new_id_from_chars(X("DivModC"));
2009
2010                 status->op_Phi0    = &_op_Phi0;
2011                 status->op_PhiM    = &_op_PhiM;
2012                 status->op_ProjM   = &_op_ProjM;
2013                 status->op_MulC    = &_op_MulC;
2014                 status->op_DivC    = &_op_DivC;
2015                 status->op_ModC    = &_op_ModC;
2016                 status->op_DivModC = &_op_DivModC;
2017         } else {
2018                 status->op_Phi0    = NULL;
2019                 status->op_PhiM    = NULL;
2020                 status->op_ProjM   = NULL;
2021                 status->op_MulC    = NULL;
2022                 status->op_DivC    = NULL;
2023                 status->op_ModC    = NULL;
2024                 status->op_DivModC = NULL;
2025         }  /* if */
2026
2027         /* for Florian: count the Sel depth */
2028         if (enable_options & FIRMSTAT_COUNT_SELS) {
2029                 _op_SelSel.code    = --num;
2030                 _op_SelSel.name    = new_id_from_chars(X("Sel(Sel)"));
2031
2032                 _op_SelSelSel.code = --num;
2033                 _op_SelSelSel.name = new_id_from_chars(X("Sel(Sel(Sel))"));
2034
2035                 status->op_SelSel    = &_op_SelSel;
2036                 status->op_SelSelSel = &_op_SelSelSel;
2037         } else {
2038                 status->op_SelSel    = NULL;
2039                 status->op_SelSelSel = NULL;
2040         }  /* if */
2041
2042         /* register the dumper */
2043         stat_register_dumper(&simple_dumper);
2044
2045         if (enable_options & FIRMSTAT_CSV_OUTPUT)
2046                 stat_register_dumper(&csv_dumper);
2047
2048         /* initialize the pattern hash */
2049         stat_init_pattern_history(enable_options & FIRMSTAT_PATTERN_ENABLED);
2050
2051         /* initialize the Const options */
2052         if (enable_options & FIRMSTAT_COUNT_CONSTS)
2053                 stat_init_const_cnt(status);
2054
2055 #undef HOOK
2056 #undef X
2057 } /* firm_init_stat */
2058
2059 /**
2060  * Frees all dumper structures.
2061  */
2062 static void stat_term_dumper(void) {
2063         dumper_t *dumper, *next_dumper;
2064
2065         for (dumper = status->dumper; dumper; /* iteration done in loop body */ ) {
2066                 if (dumper->func_map)
2067                         del_pset(dumper->func_map);
2068
2069                 next_dumper = dumper->next;
2070                 free(dumper);
2071                 dumper = next_dumper;
2072         }  /* for */
2073 } /* stat_term_dumper */
2074
2075
2076 /* Terminates the statistics module, frees all memory. */
2077 void stat_term(void) {
2078         if (status != (stat_info_t *)&status_disable) {
2079                 obstack_free(&status->be_data, NULL);
2080                 obstack_free(&status->cnts, NULL);
2081
2082                 stat_term_dumper();
2083
2084                 xfree(status);
2085                 status = (stat_info_t *)&status_disable;
2086         }
2087 } /* stat_term */
2088
2089 /* returns 1 if statistics were initialized, 0 otherwise */
2090 int stat_is_active(void) {
2091         return status != (stat_info_t *)&status_disable;
2092 } /* stat_is_active */
2093
2094 #else
2095
2096 /* initialize the statistics module. */
2097 void firm_init_stat(unsigned enable_options) {}
2098
2099 /* Dumps a statistics snapshot */
2100 void stat_dump_snapshot(const char *name, const char *phase) {}
2101
2102 /* terminates the statistics module, frees all memory */
2103 void stat_term(void);
2104
2105 #endif /* FIRM_STATISTICS */