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"
29 /* some useful macro. */
30 #define ARR_SIZE(a) (sizeof(a)/sizeof((a)[0]))
33 * just be make some things clear :-), the
36 #define HASH_MAP(type) hmap_##type
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_be_block_entry_t;
43 typedef pset hmap_reg_pressure_entry_t;
44 typedef pset hmap_perm_stat_entry_t;
45 typedef pset hmap_perm_class_entry_t;
46 typedef pset hmap_ir_op;
47 typedef pset hmap_distrib_entry_t;
50 * An entry in a distribution table
52 typedef struct _distrib_entry_t {
53 counter_t cnt; /**< the current count */
54 const void *object; /**< the object which is counted */
57 /** The type of the hash function for objects in distribution tables. */
58 typedef unsigned (*distrib_hash_fun)(const void *object);
61 * The distribution table.
63 typedef struct _distrib_tbl_t {
64 struct obstack cnts; /**< obstack containing the distrib_entry_t entries */
65 HASH_MAP(distrib_entry_t) *hash_map; /**< the hash map containing the distribution */
66 distrib_hash_fun hash_func; /**< the hash function for object in this distribution */
67 unsigned int_dist; /**< non-zero, if it's a integer distribution */
71 * possible address marker values
74 MARK_ADDRESS_CALC = 1, /**< the node is an address expression */
75 MARK_REF_ADR = 2, /**< the node is referenced by an address expression */
76 MARK_REF_NON_ADR = 4, /**< the node is referenced by a non-address expression */
80 * An entry in the address_mark set
82 typedef struct _address_mark_entry_t {
83 ir_node *node; /**< the node which this entry belongs to, needed for compare */
84 unsigned mark; /**< the mark, a bitmask of enum adr_marker_t */
85 } address_mark_entry_t;
88 * An entry for ir_nodes, used in ir_graph statistics.
90 typedef struct _node_entry_t {
91 counter_t cnt_alive; /**< amount of nodes in this entry */
92 counter_t new_node; /**< amount of new nodes for this entry */
93 counter_t into_Id; /**< amount of nodes that turned into Id's for this entry */
94 const ir_op *op; /**< the op for this entry */
97 enum leaf_call_state_t {
98 LCS_UNKNOWN = 0, /**< state is unknown yet */
99 LCS_LEAF_CALL = 1, /**< only leaf functions will be called */
100 LCS_NON_LEAF_CALL = 2, /**< at least one non-leaf function will be called or indetermined */
104 * An entry for ir_graphs. These numbers are calculated for every IR graph.
106 typedef struct _graph_entry_t {
107 struct obstack recalc_cnts; /**< obstack containing the counters that are recalculated */
108 HASH_MAP(node_entry_t) *opcode_hash; /**< hash map containing the opcode counter */
109 HASH_MAP(block_entry_t) *block_hash; /**< hash map containing the block counter */
110 HASH_MAP(block_entry_t) *extbb_hash; /**< hash map containing the extended block counter */
111 HASH_MAP(be_block_entry_t) *be_block_hash; /**< hash map containing backend block information */
112 counter_t cnt_walked; /**< walker walked over the graph */
113 counter_t cnt_walked_blocks; /**< walker walked over the graph blocks */
114 counter_t cnt_was_inlined; /**< number of times other graph were inlined */
115 counter_t cnt_got_inlined; /**< number of times this graph was inlined */
116 counter_t cnt_strength_red; /**< number of times strength reduction was successful on this graph */
117 counter_t cnt_edges; /**< number of DF edges in this graph */
118 counter_t cnt_all_calls; /**< number of all calls */
119 counter_t cnt_call_with_cnst_arg; /**< number of calls with const args */
120 counter_t cnt_indirect_calls; /**< number of indirect calls */
121 counter_t cnt_if_conv[IF_RESULT_LAST]; /**< number of if conversions */
122 counter_t cnt_real_func_call; /**< number real function call optimization */
123 counter_t cnt_pure_adr_ops; /**< number of pure address operation */
124 counter_t cnt_all_adr_ops; /**< number of all address operation */
125 unsigned num_tail_recursion; /**< number of tail recursion optimizations */
126 HASH_MAP(opt_entry_t) *opt_hash[FS_OPT_MAX]; /**< hash maps containing opcode counter for optimizations */
127 ir_graph *irg; /**< the graph of this object */
128 entity *ent; /**< the entity of this graph if one exists */
129 set *address_mark; /**< a set containing the address marks of the nodes */
130 unsigned is_deleted:1; /**< set if this irg was deleted */
131 unsigned is_leaf:1; /**< set, if this irg is a leaf function */
132 unsigned is_leaf_call:2; /**< set, if this irg calls only leaf functions */
133 unsigned is_recursive:1; /**< set, if this irg has recursive calls */
134 unsigned is_chain_call:1; /**< set, if this irg is a chain call */
135 unsigned is_analyzed:1; /**< helper: set, if this irg was already analysed */
139 * An entry for optimized ir_nodes
141 typedef struct _opt_entry_t {
142 counter_t count; /**< optimization counter */
143 const ir_op *op; /**< the op for this entry */
147 * An entry for register pressure.
149 typedef struct _reg_pressure_entry_t {
150 const char *class_name; /**< name of the register class */
151 int pressure; /**< the register pressure for this class */
152 } reg_pressure_entry_t;
155 * An entry for permutation statistics.
157 typedef struct _perm_stat_entry_t {
158 ir_node *perm; /**< the perm node */
159 int size; /**< complete size */
160 int real_size; /**< number of pairs with different registers */
161 int n_copies; /**< number of copies created for lowering */
162 int n_exchg; /**< number of exchanges created for lowering */
163 distrib_tbl_t *cycles; /**< distribution of cycle lengths */
164 distrib_tbl_t *chains; /**< distribution of chain lengths */
168 * An entry for permutation statistics per class.
170 typedef struct _perm_class_entry_t {
171 const char *class_name; /**< name of the register class */
172 int n_regs; /**< number of register in this class */
173 HASH_MAP(perm_stat_entry_t) *perm_stat; /**< statistics about all perm nodes of this class */
174 } perm_class_entry_t;
177 * An entry for a block or extended block in a ir-graph
179 typedef struct _be_block_entry_t {
180 long block_nr; /**< block nr */
181 distrib_tbl_t *sched_ready; /**< distribution of ready nodes per block */
182 /**< the highest register pressures for this block for each register class */
183 HASH_MAP(reg_pressure_entry_t) *reg_pressure;
184 HASH_MAP(perm_class_entry_t) *perm_class_stat; /**< statistics about perm nodes for each register class */
188 * An entry for a block or extended block in a ir-graph
190 typedef struct _block_entry_t {
191 counter_t cnt_nodes; /**< the counter of nodes in this block */
192 counter_t cnt_edges; /**< the counter of edges in this block */
193 counter_t cnt_in_edges; /**< the counter of edges incoming from other blocks to this block */
194 counter_t cnt_out_edges; /**< the counter of edges outgoing from this block to other blocks */
195 counter_t cnt_phi_data; /**< the counter of data Phi nodes in this block */
196 long block_nr; /**< block nr */
199 /** An entry for an extended block in a ir-graph */
200 typedef block_entry_t extbb_entry_t;
203 * Some potential interesting float values
205 typedef enum _float_classify_t {
206 STAT_FC_0, /**< the float value 0.0 */
207 STAT_FC_1, /**< the float value 1.0 */
208 STAT_FC_2, /**< the float value 2.0 */
209 STAT_FC_0_5, /**< the float value 0.5 */
210 STAT_FC_EXACT, /**< an exact value */
211 STAT_FC_OTHER, /**< all other values */
212 STAT_FC_MAX /**< last value */
218 typedef struct _constant_info_t {
219 counter_t int_bits_count[32]; /**< distribution of bit sizes of integer constants */
220 counter_t floats[STAT_FC_MAX]; /**< floating point constants */
221 counter_t others; /**< all other constants */
225 typedef struct _dumper_t dumper_t;
228 * handler for dumping an IRG
230 * @param dmp the dumper
231 * @param entry the IR-graph hash map entry
233 typedef void (*dump_graph_FUNC)(dumper_t *dmp, graph_entry_t *entry);
236 * handler for dumper init
238 * @param dmp the dumper
239 * @param name name of the file to dump to
241 typedef void (*dump_init_FUNC)(dumper_t *dmp, const char *name);
244 * handler for dumper a constant info table
246 * @param dmp the dumper
248 typedef void (*dump_const_table_FUNC)(dumper_t *dmp, const constant_info_t *tbl);
251 * handler for dumper finish
253 * @param dmp the dumper
255 typedef void (*dump_finish_FUNC)(dumper_t *dmp);
260 typedef struct _statistic_info_t {
261 unsigned stat_options; /**< statistic options: field must be first */
262 struct obstack cnts; /**< obstack containing the counters that are incremented */
263 struct obstack be_data; /**< obstack containing backend statistics data */
264 HASH_MAP(graph_entry_t) *irg_hash; /**< hash map containing the counter for irgs */
265 HASH_MAP(ir_op) *ir_op_hash; /**< hash map containing all ir_ops (accessible by op_codes) */
266 pdeq *wait_q; /**< wait queue for leaf call decision */
267 int recursive; /**< flag for detecting recursive hook calls */
268 int in_dead_node_elim; /**< set, if dead node elimination runs */
269 ir_op *op_Phi0; /**< pseudo op for Phi0 */
270 ir_op *op_PhiM; /**< pseudo op for memory Phi */
271 ir_op *op_ProjM; /**< pseudo op for memory Proj */
272 ir_op *op_MulC; /**< pseudo op for multiplication by const */
273 ir_op *op_DivC; /**< pseudo op for division by const */
274 ir_op *op_ModC; /**< pseudo op for modulo by const */
275 ir_op *op_DivModC; /**< pseudo op for DivMod by const */
276 ir_op *op_SelSel; /**< pseudo op for Sel(Sel) */
277 ir_op *op_SelSelSel; /**< pseudo op for Sel(Sel(Sel)) */
278 dumper_t *dumper; /**< list of dumper */
279 int reassoc_run; /**< if set, reassociation is running */
280 constant_info_t const_info; /**< statistic info for constants */
284 * a dumper description
287 dump_graph_FUNC dump_graph; /**< handler for dumping an irg */
288 dump_const_table_FUNC dump_const_tbl; /**< handler for dumping a const table */
289 dump_init_FUNC init; /**< handler for init */
290 dump_finish_FUNC finish; /**< handler for finish */
291 FILE *f; /**< the file to dump to */
292 stat_info_t *status; /**< access to the global status */
293 dumper_t *next; /**< link to the next dumper */
294 pset *func_map; /**< pset containing all registered functions */
295 unsigned tag; /**< the id tag of the dumper */
299 * helper: get an ir_op from an opcode
301 ir_op *stat_get_op_from_opcode(opcode code);
303 /* API for distribution tables */
306 * creates a new distribution table.
308 * @param cmp_func Compare function for objects in the distribution
309 * @param hash_func Hash function for objects in the distribution
311 distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func);
314 * creates a new distribution table for an integer distribution.
316 distrib_tbl_t *stat_new_int_distrib_tbl(void);
319 * destroys a distribution table.
321 void stat_delete_distrib_tbl(distrib_tbl_t *tbl);
324 * adds a new object count into the distribution table.
326 void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_t *cnt);
329 * adds a new key count into the integer distribution table.
331 void stat_add_int_distrib_tbl(distrib_tbl_t *tbl, int key, const counter_t *cnt);
334 * increases object count by one
336 void stat_inc_distrib_tbl(distrib_tbl_t *tbl, const void *object);
339 * increases key count by one
341 void stat_inc_int_distrib_tbl(distrib_tbl_t *tbl, int key);
344 * inserts a new object with count 0 into the distribution table
345 * if object is already present, nothing happens
347 void stat_insert_distrib_tbl(distrib_tbl_t *tbl, const void *object);
350 * inserts a new key with count 0 into the integer distribution table
351 * if key is already present, nothing happens
353 void stat_insert_int_distrib_tbl(distrib_tbl_t *tbl, int key);
356 * returns the sum over all counters in a distribution table
358 int stat_get_count_distrib_tbl(distrib_tbl_t *tbl);
361 * calculates the mean value of a distribution.
363 double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl);
366 * calculates the average value of a distribution
368 double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl);
370 /** evaluates each entry of a distribution table. */
371 typedef void (*eval_distrib_entry_fun)(const distrib_entry_t *entry, void *env);
374 * iterates over all entries in a distribution table
376 void stat_iterate_distrib_tbl(distrib_tbl_t *tbl, eval_distrib_entry_fun eval, void *env);
379 * update info on Consts.
381 * @param node The Const node
382 * @param graph The graph entry containing the call
384 void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph);
387 * clears the const statistics for a new snapshot.
389 void stat_const_clear(stat_info_t *status);
392 * initialize the Const statistic.
394 void stat_init_const_cnt(stat_info_t *status);
397 * return a human readable name for an float classification
399 const char *stat_fc_name(float_classify_t classification);
402 * Update the register pressure of a block
404 * @param irg the irg containing the block
405 * @param block the block for which the reg pressure should be set
406 * @param pressure the pressure
407 * @param class_name the name of the register class
409 void stat_be_block_regpressure(ir_graph *irg, ir_node *block, int pressure, const char *class_name);
412 * Update the distribution of ready nodes of a block
414 * @param irg the irg containing the block
415 * @param block the block for which the reg pressure should be set
416 * @param num_ready the number of ready nodes
418 void stat_be_block_sched_ready(ir_graph *irg, ir_node *block, int num_ready);
421 * Update the permutation statistic of a block
423 * @param class_name the name of the register class
424 * @param perm the perm node
425 * @param block the block containing the perm
426 * @param size the size of the perm
427 * @param real_size number of pairs with different registers
429 void stat_be_block_stat_perm(const char *class_name, int n_regs, ir_node *perm, ir_node *block,
430 int size, int real_size);
433 * Update the permutation statistic of a single perm
435 * @param class_name the name of the register class
436 * @param perm the perm node
437 * @param block the block containing the perm
438 * @param is_chain 1 if chain, 0 if cycle
439 * @param size length of the cycle/chain
440 * @param n_ops the number of ops representing this cycle/chain after lowering
442 void stat_be_block_stat_permcycle(const char *class_name, ir_node *perm, ir_node *block,
443 int is_chain, int size, int n_ops);
446 * Register an additional function for all dumper. This function
447 * is called in dump_snapshot once for each graph_entry and dumper.
449 * @param func the dump function to register
451 void stat_register_dumper_func(dump_graph_FUNC func);
453 #endif /* _FIRMSTAT_T_H_ */