use tv_t.h instead of tv.h
[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 "pdeq.h"
24 #include "irprog.h"
25 #include "irgwalk.h"
26 #include "counter.h"
27 #include "irhooks.h"
28
29 /* some useful macro. */
30 #define ARR_SIZE(a)   (sizeof(a)/sizeof((a)[0]))
31
32 /*
33  * just be make some things clear :-), the
34  * poor man "generics"
35  */
36 #define HASH_MAP(type) hmap_##type
37
38 typedef pset hmap_node_entry_t;
39 typedef pset hmap_graph_entry_t;
40 typedef pset hmap_opt_entry_t;
41 typedef pset hmap_block_entry_t;
42 typedef pset hmap_ir_op;
43 typedef pset hmap_distrib_entry_t;
44
45 /**
46  * possible address marker values
47  */
48 enum adr_marker_t {
49   MARK_ADDRESS_CALC     = 1,    /**< the node is an address expression */
50   MARK_REF_ADR          = 2,    /**< the node is referenced by an address expression */
51   MARK_REF_NON_ADR      = 4,    /**< the node is referenced by a non-address expression */
52 };
53
54 /**
55  * An entry in the address_mark set
56  */
57 typedef struct _address_mark_entry_t {
58   ir_node  *node;               /**< the node which this entry belongs to, needed for compare */
59   unsigned mark;                /**< the mark, a bitmask of enum adr_marker_t */
60 } address_mark_entry_t;
61
62 /**
63  * An entry for ir_nodes, used in ir_graph statistics.
64  */
65 typedef struct _node_entry_t {
66   counter_t   cnt_alive;    /**< amount of nodes in this entry */
67   counter_t   new_node;     /**< amount of new nodes for this entry */
68   counter_t   into_Id;      /**< amount of nodes that turned into Id's for this entry */
69   const ir_op *op;          /**< the op for this entry */
70 } node_entry_t;
71
72 enum leaf_call_state_t {
73   LCS_UNKNOWN       = 0,      /**< state is unknown yet */
74   LCS_LEAF_CALL     = 1,      /**< only leaf functions will be called */
75   LCS_NON_LEAF_CALL = 2,      /**< at least one non-leaf function will be called or indetermined */
76 };
77
78 /**
79  * An entry for ir_graphs. These numbers are calculated for every IR graph.
80  */
81 typedef struct _graph_entry_t {
82   HASH_MAP(node_entry_t)  *opcode_hash;                 /**< hash map containing the opcode counter */
83   HASH_MAP(block_entry_t) *block_hash;                  /**< hash map containing the block counter */
84   counter_t               cnt_walked;                     /**< walker walked over the graph */
85   counter_t               cnt_walked_blocks;            /**< walker walked over the graph blocks */
86   counter_t               cnt_was_inlined;              /**< number of times other graph were inlined */
87   counter_t               cnt_got_inlined;              /**< number of times this graph was inlined */
88   counter_t               cnt_strength_red;             /**< number of times strength reduction was successful on this graph */
89   counter_t               cnt_edges;                    /**< number of DF edges in this graph */
90   counter_t               cnt_all_calls;                /**< number of all calls */
91   counter_t               cnt_call_with_cnst_arg;       /**< number of calls with const args */
92   counter_t               cnt_indirect_calls;           /**< number of indirect calls */
93   counter_t               cnt_if_conv[IF_RESULT_LAST];  /**< number of if conversions */
94   counter_t               cnt_real_func_call;           /**< number real function call optimization */
95   unsigned                num_tail_recursion;           /**< number of tail recursion optimizations */
96   HASH_MAP(opt_entry_t)   *opt_hash[HOOK_OPT_LAST];     /**< hash maps containing opcode counter for optimizations */
97   ir_graph                *irg;                         /**< the graph of this object */
98   entity                  *ent;                         /**< the entity of this graph if one exists */
99   set                     *address_mark;                /**< a set containing the address marks of the nodes */
100   unsigned                is_deleted:1;                 /**< set if this irg was deleted */
101   unsigned                is_leaf:1;                    /**< set, if this irg is a leaf function */
102   unsigned                is_leaf_call:2;               /**< set, if this irg calls only leaf functions */
103   unsigned                is_recursive:1;               /**< set, if this irg has recursive calls */
104   unsigned                is_chain_call:1;              /**< set, if this irg is a chain call */
105   unsigned                is_analyzed:1;                /**< helper: set, if this irg was already analysed */
106 } graph_entry_t;
107
108 /**
109  * An entry for optimized ir_nodes
110  */
111 typedef struct _opt_entry_t {
112   counter_t   count;    /**< optimization counter */
113   const ir_op *op;      /**< the op for this entry */
114 } opt_entry_t;
115
116 /**
117  * An entry for a block in a ir-graph
118  */
119 typedef struct _block_entry_t {
120   counter_t  cnt_nodes;     /**< the counter of nodes in this block */
121   counter_t  cnt_edges;     /**< the counter of edges in this block */
122   counter_t  cnt_in_edges;  /**< the counter of edges incoming from other blocks to this block */
123   counter_t  cnt_out_edges; /**< the counter of edges outgoing from this block to other blocks */
124   counter_t  cnt_phi_data;  /**< the counter of data Phi nodes in this block */
125   long       block_nr;      /**< block nr */
126 } block_entry_t;
127
128 /**
129  * constant info
130  */
131 typedef struct _constant_info_t {
132   counter_t  bits_count[32];   /**< distribution of bit sizes of constants */
133   counter_t  others;           /**< number of other constants */
134 } constant_info_t;
135
136 /** forward */
137 typedef struct _dumper_t dumper_t;
138
139 /**
140  * handler for dumping an IRG
141  *
142  * @param dmp   the dumper
143  * @param entry the IR-graph hash map entry
144  */
145 typedef void (*dump_graph_FUNC)(dumper_t *dmp, graph_entry_t *entry);
146
147 /**
148  * handler for dumper init
149  *
150  * @param dmp   the dumper
151  * @param name  name of the file to dump to
152  */
153 typedef void (*dump_init_FUNC)(dumper_t *dmp, const char *name);
154
155 /**
156  * handler for dumper a constant info table
157  *
158  * @param dmp   the dumper
159  */
160 typedef void (*dump_const_table_FUNC)(dumper_t *dmp, const constant_info_t *tbl);
161
162 /**
163  * handler for dumper finish
164  *
165  * @param dmp   the dumper
166  */
167 typedef void (*dump_finish_FUNC)(dumper_t *dmp);
168
169 /**
170  * statistics info
171  */
172 typedef struct _statistic_info_t {
173   int                     stat_options;   /**< statistic options: must be first */
174   struct obstack          cnts;           /**< obstack containing the counters */
175   HASH_MAP(graph_entry_t) *irg_hash;      /**< hash map containing the counter for irgs */
176   HASH_MAP(ir_op)         *ir_op_hash;    /**< hash map containing all ir_ops (accessible by op_codes) */
177   pdeq                    *wait_q;        /**< wait queue for leaf call decision */
178   int                     recursive;      /**< flag for detecting recursive hook calls */
179   int                     in_dead_node_elim;    /**< set, if dead node elimination runs */
180   ir_op                   *op_Phi0;       /**< pseudo op for Phi0 */
181   ir_op                   *op_PhiM;       /**< pseudo op for memory Phi */
182   ir_op                   *op_ProjM;      /**< pseudo op for memory Proj */
183   ir_op                   *op_MulC;       /**< pseudo op for multiplication by const */
184   ir_op                   *op_DivC;       /**< pseudo op for division by const */
185   ir_op                   *op_ModC;       /**< pseudo op for modulo by const */
186   ir_op                   *op_DivModC;    /**< pseudo op for DivMod by const */
187   ir_op                   *op_SelSel;     /**< pseudo op for Sel(Sel) */
188   ir_op                   *op_SelSelSel;  /**< pseudo op for Sel(Sel(Sel)) */
189   dumper_t                *dumper;        /**< list of dumper */
190   int                     reassoc_run;    /**< if set, reassociation is running */
191   constant_info_t         const_info;     /**< statistic info for constants */
192 } stat_info_t;
193
194 /**
195  * a dumper description
196  */
197 struct _dumper_t {
198   dump_graph_FUNC         dump_graph;     /**< handler for dumping an irg */
199   dump_const_table_FUNC   dump_const_tbl; /**< handler for dumping a const table */
200   dump_init_FUNC          init;           /**< handler for init */
201   dump_finish_FUNC        finish;         /**< handler for finish */
202   FILE                    *f;             /**< the file to dump to */
203   stat_info_t             *status;        /**< access to the global status */
204   dumper_t                *next;          /**< link to the next dumper */
205 };
206
207 /**
208  * helper: get an ir_op from an opcode
209  */
210 ir_op *stat_get_op_from_opcode(opcode code);
211
212 /**
213  * An entry in a distribution table
214  */
215 typedef struct _distrib_entry_t {
216   counter_t     cnt;            /**< the current count */
217   const void    *object;        /**< the object which is counted */
218 } distrib_entry_t;
219
220 /** The type of the hash function for objects in distribution tables. */
221 typedef unsigned (*distrib_hash_fun)(const void *object);
222
223 /**
224  * The distribution table.
225  */
226 typedef struct _distrib_tbl_t {
227   struct obstack                cnts;           /**< obstack containing the distrib_entry_t entries */
228   HASH_MAP(distrib_entry_t)     *hash_map;      /**< the hash map containing the distribution */
229   distrib_hash_fun          hash_func;  /**< the hash function for object in this distribution */
230   unsigned                      int_dist;       /**< non-zero, if it's a integer distribution */
231 } distrib_tbl_t;
232
233 /* API for distribution tables */
234
235 /**
236  * creates a new distribution table.
237  *
238  * @param cmp_func   Compare function for objects in the distribution
239  * @param hash_func  Hash function for objects in the distribution
240  */
241 distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func);
242
243 /**
244  * creates a new distribution table for an integer distribution.
245  */
246 distrib_tbl_t *stat_new_int_distrib_tbl(void);
247
248 /**
249  * destroys a distribution table.
250  */
251 void stat_delete_distrib_tbl(distrib_tbl_t *tbl);
252
253 /**
254  * adds a new object count into the distribution table.
255  */
256 void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_t *cnt);
257
258 /**
259  * adds a new key count into the integer distribution table.
260  */
261 void stat_add_int_distrib_tbl(distrib_tbl_t *tbl, int key, const counter_t *cnt);
262
263 /**
264  * calculates the mean value of a distribution.
265  */
266 double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl);
267
268 /** evaluates each entry of a distribution table. */
269 typedef void (*eval_distrib_entry_fun)(const distrib_entry_t *entry);
270
271 /**
272  * iterates over all entries in a distribution table
273  */
274 void stat_iterate_distrib_tbl(distrib_tbl_t *tbl, eval_distrib_entry_fun eval);
275
276 /**
277  * update info on Consts.
278  *
279  * @param node   The Const node
280  * @param graph  The graph entry containing the call
281  */
282 void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph);
283
284 /**
285  * clears the const statistics for a new snapshot.
286  */
287 void stat_const_clear(stat_info_t *status);
288
289 /**
290  * initialize the Const statistic.
291  */
292 void stat_init_const_cnt(stat_info_t *status);
293
294 #endif /* _FIRMSTAT_T_H_ */