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