flag for strength reduction verbosity
[libfirm] / ir / stat / firmstat_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/stat/firmstat_t.h
4  * Purpose:     Statistics for Firm. Internal data structures.
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 #ifndef _FIRMSTAT_T_H_
12 #define _FIRMSTAT_T_H_
13
14 /**
15  * @file firmstat_t.h
16  */
17 #include "firmstat.h"
18
19 #include "irop_t.h"
20 #include "irnode_t.h"
21 #include "irgraph_t.h"
22 #include "pset.h"
23 #include "irprog.h"
24 #include "irgwalk.h"
25 #include "counter.h"
26
27 /*
28  * just be make some things clear :-), the
29  * poor man "generics"
30  */
31 #define HASH_MAP(type) hmap_##type
32
33 typedef pset hmap_node_entry_t;
34 typedef pset hmap_graph_entry_t;
35 typedef pset hmap_opt_entry_t;
36 typedef pset hmap_block_entry_t;
37 typedef pset hmap_ir_op;
38 typedef pset hmap_distrib_entry_t;
39
40
41 /**
42  * An entry for ir_nodes, used in ir_graph statistics.
43  */
44 typedef struct _node_entry_t {
45   counter_t   cnt_alive;                /**< amount of nodes in this entry */
46   counter_t   new_node;                 /**< amount of new nodes for this entry */
47   counter_t   into_Id;                  /**< amount of nodes that turned into Id's for this entry */
48   const ir_op *op;                      /**< the op for this entry */
49 } node_entry_t;
50
51 /**
52  * An entry for ir_graphs
53  */
54 typedef struct _graph_entry_t {
55   HASH_MAP(node_entry_t)  *opcode_hash;                 /**< hash map containing the opcode counter */
56   HASH_MAP(block_entry_t) *block_hash;                  /**< hash map countaining the block counter */
57   counter_t               cnt_walked;                   /**< walker walked over the graph */
58   counter_t               cnt_walked_blocks;            /**< walker walked over the graph blocks */
59   counter_t               cnt_was_inlined;              /**< number of times other graph were inlined */
60   counter_t               cnt_got_inlined;              /**< number of times this graph was inlined */
61   counter_t               cnt_edges;                    /**< number of DF edges in this graph */
62   HASH_MAP(opt_entry_t)   *opt_hash[STAT_OPT_MAX];      /**< hash maps containing opcode counter for optimizations */
63   ir_graph                *irg;                         /**< the graph of this object */
64   entity                  *ent;                         /**< the entity of this graph if one exists */
65   int                     deleted;                      /**< set if this irg was deleted */
66 } graph_entry_t;
67
68 /**
69  * An entry for optimized ir_nodes
70  */
71 typedef struct _opt_entry_t {
72   counter_t   count;                    /**< optimization counter */
73   const ir_op *op;                      /**< the op for this entry */
74 } opt_entry_t;
75
76 /**
77  * An entry for a block in a ir-graph
78  */
79 typedef struct _block_entry_t {
80   counter_t  cnt_nodes;                 /**< the counter of nodes in this block */
81   counter_t  cnt_edges;                 /**< the counter of edges in this block */
82   counter_t  cnt_in_edges;              /**< the counter of edges incoming from other blocks to this block */
83   counter_t  cnt_out_edges;             /**< the counter of edges outgoing from this block to other blocks */
84   long       block_nr;                  /**< block nr */
85 } block_entry_t;
86
87 /** forward */
88 typedef struct _dumper_t dumper_t;
89
90 /**
91  * handler for dumping an IRG
92  *
93  * @param dmp   the dumper
94  * @param entry the IR-graph hash map entry
95  */
96 typedef void (*dump_graph_FUNC)(dumper_t *dmp, graph_entry_t *entry);
97
98 /**
99  * handler for dumper init
100  *
101  * @param dmp   the dumper
102  * @param name  name of the file to dump to
103  */
104 typedef void (*dump_init_FUNC)(dumper_t *dmp, const char *name);
105
106 /**
107  * handler for dumper finish
108  *
109  * @param dmp   the dumper
110  */
111 typedef void (*dump_finish_FUNC)(dumper_t *dmp);
112
113
114 /**
115  * a dumper description
116  */
117 struct _dumper_t {
118   dump_graph_FUNC         dump_graph;           /**< handler for dumping an irg */
119   dump_init_FUNC          init;                 /**< handler for init */
120   dump_finish_FUNC        finish;               /**< handler for finish */
121   FILE                    *f;                   /**< the file to dump to */
122   dumper_t                *next;                /**< link to the next dumper */
123 };
124
125 /**
126  * statistics info
127  */
128 typedef struct _statistic_info_t {
129   struct obstack          cnts;                 /**< obstack containing the counters */
130   HASH_MAP(graph_entry_t) *irg_hash;            /**< hash map containing the counter for irgs */
131   HASH_MAP(ir_op)         *ir_op_hash;          /**< hash map containing all ir_ops (accessible by op_codes) */
132   int                     recursive;            /**< flag for detecting recursive hook calls */
133   int                     in_dead_node_elim;    /**< set, if dead node elimination runs */
134   ir_op                   *op_Phi0;             /**< needed pseudo op */
135   ir_op                   *op_PhiM;             /**< needed pseudo op */
136   dumper_t                *dumper;              /**< list of dumper */
137   int                     enable;               /**< if set, statistic is enabled */
138 } stat_info_t;
139
140 /**
141  * An entry in a distribution table
142  */
143 typedef struct _distrib_entry_t {
144   counter_t     cnt;            /**< the current count */
145   const void    *object;        /**< the object which is counted */
146 } distrib_entry_t;
147
148 /** The type of the hash function for objects in distribution tables. */
149 typedef unsigned (*distrib_hash_fun)(const void *object);
150
151 /**
152  * The distribution table.
153  */
154 typedef struct _distrib_tbl_t {
155   struct obstack                cnts;           /**< obstack containing the distrib_entry_t entries */
156   HASH_MAP(distrib_entry_t)     *hash_map;      /**< the hash map containing the distribution */
157   distrib_hash_fun              hash_func;      /**< the hash function for object in this distribution */
158   unsigned                      int_dist;       /**< non-zero, if it's a integer distribution */
159 } distrib_tbl_t;
160
161 /* API for distribution tables */
162
163 /**
164  * creates a new distribution table
165  *
166  * @param cmp_func   Compare function for objects in the distribution
167  * @param hash_func  Hash function for objects in the distribution
168  */
169 distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func);
170
171 /**
172  * creates a new distribution table for an integer distribution
173  */
174 distrib_tbl_t *stat_new_int_distrib_tbl(void);
175
176 /**
177  * destroys a distribution table
178  */
179 void stat_delete_distrib_tbl(distrib_tbl_t *tbl);
180
181 /**
182  * adds a new object count into the distribution table
183  */
184 void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_t *cnt);
185
186 /**
187  * adds a new key count into the integer distribution table
188  */
189 void stat_add_int_distrib_tbl(distrib_tbl_t *tbl, int key, const counter_t *cnt);
190
191 /**
192  * calculates the mean value of a distribution
193  */
194 double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl);
195
196 /** evaluates each entry of a distribution table */
197 typedef void (*eval_distrib_entry_fun)(const distrib_entry_t *entry);
198
199 /**
200  * iterates over all entries in a distribution table
201  */
202 void stat_iterate_distrib_tbl(distrib_tbl_t *tbl, eval_distrib_entry_fun eval);
203
204 #endif /* _FIRMSTAT_T_H_ */