3 * File name: ir/stat/firmstat_t.h
4 * Purpose: Statistics for Firm. Internal data structures.
8 * Copyright: (c) 2004 Universität Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
11 #ifndef _FIRMSTAT_T_H_
12 #define _FIRMSTAT_T_H_
21 #include "irgraph_t.h"
30 /* some useful macro. */
31 #define ARR_SIZE(a) (sizeof(a)/sizeof((a)[0]))
34 * just be make some things clear :-), the
37 #define HASH_MAP(type) hmap_##type
39 typedef pset hmap_node_entry_t;
40 typedef pset hmap_graph_entry_t;
41 typedef pset hmap_opt_entry_t;
42 typedef pset hmap_block_entry_t;
43 typedef pset hmap_reg_pressure_entry_t;
44 typedef pset hmap_ir_op;
45 typedef pset hmap_distrib_entry_t;
48 * possible address marker values
51 MARK_ADDRESS_CALC = 1, /**< the node is an address expression */
52 MARK_REF_ADR = 2, /**< the node is referenced by an address expression */
53 MARK_REF_NON_ADR = 4, /**< the node is referenced by a non-address expression */
57 * An entry in the address_mark set
59 typedef struct _address_mark_entry_t {
60 ir_node *node; /**< the node which this entry belongs to, needed for compare */
61 unsigned mark; /**< the mark, a bitmask of enum adr_marker_t */
62 } address_mark_entry_t;
65 * An entry for ir_nodes, used in ir_graph statistics.
67 typedef struct _node_entry_t {
68 counter_t cnt_alive; /**< amount of nodes in this entry */
69 counter_t new_node; /**< amount of new nodes for this entry */
70 counter_t into_Id; /**< amount of nodes that turned into Id's for this entry */
71 const ir_op *op; /**< the op for this entry */
74 enum leaf_call_state_t {
75 LCS_UNKNOWN = 0, /**< state is unknown yet */
76 LCS_LEAF_CALL = 1, /**< only leaf functions will be called */
77 LCS_NON_LEAF_CALL = 2, /**< at least one non-leaf function will be called or indetermined */
81 * An entry for ir_graphs. These numbers are calculated for every IR graph.
83 typedef struct _graph_entry_t {
84 struct obstack recalc_cnts; /**< obstack containing the counters that are recalculated */
85 HASH_MAP(node_entry_t) *opcode_hash; /**< hash map containing the opcode counter */
86 HASH_MAP(block_entry_t) *block_hash; /**< hash map containing the block counter */
87 HASH_MAP(block_entry_t) *extbb_hash; /**< hash map containing the extended block counter */
88 HASH_MAP(block_entry_t) *rp_block_hash; /**< hash map containing the block reg pressure information */
89 counter_t cnt_walked; /**< walker walked over the graph */
90 counter_t cnt_walked_blocks; /**< walker walked over the graph blocks */
91 counter_t cnt_was_inlined; /**< number of times other graph were inlined */
92 counter_t cnt_got_inlined; /**< number of times this graph was inlined */
93 counter_t cnt_strength_red; /**< number of times strength reduction was successful on this graph */
94 counter_t cnt_edges; /**< number of DF edges in this graph */
95 counter_t cnt_all_calls; /**< number of all calls */
96 counter_t cnt_call_with_cnst_arg; /**< number of calls with const args */
97 counter_t cnt_indirect_calls; /**< number of indirect calls */
98 counter_t cnt_if_conv[IF_RESULT_LAST]; /**< number of if conversions */
99 counter_t cnt_real_func_call; /**< number real function call optimization */
100 unsigned num_tail_recursion; /**< number of tail recursion optimizations */
101 HASH_MAP(opt_entry_t) *opt_hash[FS_OPT_MAX]; /**< hash maps containing opcode counter for optimizations */
102 ir_graph *irg; /**< the graph of this object */
103 entity *ent; /**< the entity of this graph if one exists */
104 set *address_mark; /**< a set containing the address marks of the nodes */
105 unsigned is_deleted:1; /**< set if this irg was deleted */
106 unsigned is_leaf:1; /**< set, if this irg is a leaf function */
107 unsigned is_leaf_call:2; /**< set, if this irg calls only leaf functions */
108 unsigned is_recursive:1; /**< set, if this irg has recursive calls */
109 unsigned is_chain_call:1; /**< set, if this irg is a chain call */
110 unsigned is_analyzed:1; /**< helper: set, if this irg was already analysed */
114 * An entry for optimized ir_nodes
116 typedef struct _opt_entry_t {
117 counter_t count; /**< optimization counter */
118 const ir_op *op; /**< the op for this entry */
122 * An entry for register pressure.
124 typedef struct _reg_pressure_entry_t {
125 ident *id_name; /**< name of the register class */
126 int pressure; /**< the register pressure for this class */
127 } reg_pressure_entry_t;
130 * An entry for a block or extended block in a ir-graph
132 typedef struct _block_entry_t {
133 counter_t cnt_nodes; /**< the counter of nodes in this block */
134 counter_t cnt_edges; /**< the counter of edges in this block */
135 counter_t cnt_in_edges; /**< the counter of edges incoming from other blocks to this block */
136 counter_t cnt_out_edges; /**< the counter of edges outgoing from this block to other blocks */
137 counter_t cnt_phi_data; /**< the counter of data Phi nodes in this block */
138 long block_nr; /**< block nr */
139 /**< the highest register pressures for this block for each register class */
140 HASH_MAP(reg_pressure_entry_t) *reg_pressure;
143 /** An entry for an extended block in a ir-graph */
144 typedef block_entry_t extbb_entry_t;
147 * Some potential interesting float values
149 typedef enum _float_classify_t {
150 STAT_FC_0, /**< the float value 0.0 */
151 STAT_FC_1, /**< the float value 1.0 */
152 STAT_FC_2, /**< the float value 2.0 */
153 STAT_FC_0_5, /**< the float value 0.5 */
154 STAT_FC_EXACT, /**< an exact value */
155 STAT_FC_OTHER, /**< all other values */
156 STAT_FC_MAX /**< last value */
162 typedef struct _constant_info_t {
163 counter_t int_bits_count[32]; /**< distribution of bit sizes of integer constants */
164 counter_t floats[STAT_FC_MAX]; /**< floating point constants */
165 counter_t others; /**< all other constants */
169 typedef struct _dumper_t dumper_t;
172 * handler for dumping an IRG
174 * @param dmp the dumper
175 * @param entry the IR-graph hash map entry
177 typedef void (*dump_graph_FUNC)(dumper_t *dmp, graph_entry_t *entry);
180 * handler for dumper init
182 * @param dmp the dumper
183 * @param name name of the file to dump to
185 typedef void (*dump_init_FUNC)(dumper_t *dmp, const char *name);
188 * handler for dumper a constant info table
190 * @param dmp the dumper
192 typedef void (*dump_const_table_FUNC)(dumper_t *dmp, const constant_info_t *tbl);
195 * handler for dumper finish
197 * @param dmp the dumper
199 typedef void (*dump_finish_FUNC)(dumper_t *dmp);
204 typedef struct _statistic_info_t {
205 unsigned stat_options; /**< statistic options: field must be first */
206 struct obstack cnts; /**< obstack containing the counters that are incremented */
207 HASH_MAP(graph_entry_t) *irg_hash; /**< hash map containing the counter for irgs */
208 HASH_MAP(ir_op) *ir_op_hash; /**< hash map containing all ir_ops (accessible by op_codes) */
209 pdeq *wait_q; /**< wait queue for leaf call decision */
210 int recursive; /**< flag for detecting recursive hook calls */
211 int in_dead_node_elim; /**< set, if dead node elimination runs */
212 ir_op *op_Phi0; /**< pseudo op for Phi0 */
213 ir_op *op_PhiM; /**< pseudo op for memory Phi */
214 ir_op *op_ProjM; /**< pseudo op for memory Proj */
215 ir_op *op_MulC; /**< pseudo op for multiplication by const */
216 ir_op *op_DivC; /**< pseudo op for division by const */
217 ir_op *op_ModC; /**< pseudo op for modulo by const */
218 ir_op *op_DivModC; /**< pseudo op for DivMod by const */
219 ir_op *op_SelSel; /**< pseudo op for Sel(Sel) */
220 ir_op *op_SelSelSel; /**< pseudo op for Sel(Sel(Sel)) */
221 dumper_t *dumper; /**< list of dumper */
222 int reassoc_run; /**< if set, reassociation is running */
223 constant_info_t const_info; /**< statistic info for constants */
227 * a dumper description
230 dump_graph_FUNC dump_graph; /**< handler for dumping an irg */
231 dump_const_table_FUNC dump_const_tbl; /**< handler for dumping a const table */
232 dump_init_FUNC init; /**< handler for init */
233 dump_finish_FUNC finish; /**< handler for finish */
234 FILE *f; /**< the file to dump to */
235 stat_info_t *status; /**< access to the global status */
236 dumper_t *next; /**< link to the next dumper */
240 * helper: get an ir_op from an opcode
242 ir_op *stat_get_op_from_opcode(opcode code);
245 * An entry in a distribution table
247 typedef struct _distrib_entry_t {
248 counter_t cnt; /**< the current count */
249 const void *object; /**< the object which is counted */
252 /** The type of the hash function for objects in distribution tables. */
253 typedef unsigned (*distrib_hash_fun)(const void *object);
256 * The distribution table.
258 typedef struct _distrib_tbl_t {
259 struct obstack cnts; /**< obstack containing the distrib_entry_t entries */
260 HASH_MAP(distrib_entry_t) *hash_map; /**< the hash map containing the distribution */
261 distrib_hash_fun hash_func; /**< the hash function for object in this distribution */
262 unsigned int_dist; /**< non-zero, if it's a integer distribution */
265 /* API for distribution tables */
268 * creates a new distribution table.
270 * @param cmp_func Compare function for objects in the distribution
271 * @param hash_func Hash function for objects in the distribution
273 distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func);
276 * creates a new distribution table for an integer distribution.
278 distrib_tbl_t *stat_new_int_distrib_tbl(void);
281 * destroys a distribution table.
283 void stat_delete_distrib_tbl(distrib_tbl_t *tbl);
286 * adds a new object count into the distribution table.
288 void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_t *cnt);
291 * adds a new key count into the integer distribution table.
293 void stat_add_int_distrib_tbl(distrib_tbl_t *tbl, int key, const counter_t *cnt);
296 * calculates the mean value of a distribution.
298 double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl);
300 /** evaluates each entry of a distribution table. */
301 typedef void (*eval_distrib_entry_fun)(const distrib_entry_t *entry);
304 * iterates over all entries in a distribution table
306 void stat_iterate_distrib_tbl(distrib_tbl_t *tbl, eval_distrib_entry_fun eval);
309 * update info on Consts.
311 * @param node The Const node
312 * @param graph The graph entry containing the call
314 void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph);
317 * clears the const statistics for a new snapshot.
319 void stat_const_clear(stat_info_t *status);
322 * initialize the Const statistic.
324 void stat_init_const_cnt(stat_info_t *status);
327 * return a human readable name for an float classification
329 const char *stat_fc_name(float_classify_t classification);
331 #endif /* _FIRMSTAT_T_H_ */