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 * just be make some things clear :-), the
32 #define HASH_MAP(type) hmap_##type
34 typedef pset hmap_node_entry_t;
35 typedef pset hmap_graph_entry_t;
36 typedef pset hmap_opt_entry_t;
37 typedef pset hmap_block_entry_t;
38 typedef pset hmap_ir_op;
39 typedef pset hmap_distrib_entry_t;
42 * possible address marker values
45 MARK_ADDRESS_CALC = 1, /**< the node is an address expression */
46 MARK_REF_ADR = 2, /**< the node is referenced by an address expression */
47 MARK_REF_NON_ADR = 4, /**< the node is referenced by a non-address expression */
51 * An entry in the address_mark set
53 typedef struct _address_mark_entry_t {
54 ir_node *node; /**< the node which this entry belongs to, needed for compare */
55 unsigned mark; /**< the mark, a bitmask of enum adr_marker_t */
56 } address_mark_entry_t;
59 * An entry for ir_nodes, used in ir_graph statistics.
61 typedef struct _node_entry_t {
62 counter_t cnt_alive; /**< amount of nodes in this entry */
63 counter_t new_node; /**< amount of new nodes for this entry */
64 counter_t into_Id; /**< amount of nodes that turned into Id's for this entry */
65 const ir_op *op; /**< the op for this entry */
68 enum leaf_call_state_t {
69 LCS_UNKNOWN = 0, /**< state is unknown yet */
70 LCS_LEAF_CALL = 1, /**< only leaf functions will be called */
71 LCS_NON_LEAF_CALL = 2, /**< at least one non-leaf function will be called or indetermined */
75 * An entry for ir_graphs
77 typedef struct _graph_entry_t {
78 HASH_MAP(node_entry_t) *opcode_hash; /**< hash map containing the opcode counter */
79 HASH_MAP(block_entry_t) *block_hash; /**< hash map countaining the block counter */
80 counter_t cnt_walked; /**< walker walked over the graph */
81 counter_t cnt_walked_blocks; /**< walker walked over the graph blocks */
82 counter_t cnt_was_inlined; /**< number of times other graph were inlined */
83 counter_t cnt_got_inlined; /**< number of times this graph was inlined */
84 counter_t cnt_strength_red; /**< number of times strength reduction was successful on this graph */
85 counter_t cnt_edges; /**< number of DF edges in this graph */
86 counter_t cnt_all_calls; /**< number of all calls */
87 counter_t cnt_indirect_calls; /**< number of indirect calls */
88 HASH_MAP(opt_entry_t) *opt_hash[STAT_OPT_MAX]; /**< hash maps containing opcode counter for optimizations */
89 ir_graph *irg; /**< the graph of this object */
90 entity *ent; /**< the entity of this graph if one exists */
91 set *address_mark; /**< a set containing the address marks of the nodes */
92 unsigned is_deleted:1; /**< set if this irg was deleted */
93 unsigned is_leaf:1; /**< set, if this irg is a leaf function */
94 unsigned is_leaf_call:2; /**< set, if this irg calls only leaf functions */
95 unsigned is_recursive:1; /**< set, if this irg has recursive calls */
96 unsigned is_chain_call:1; /**< set, if this irg is a chain call */
97 unsigned is_analyzed:1; /**< helper: set, if this irg was already analysed */
101 * An entry for optimized ir_nodes
103 typedef struct _opt_entry_t {
104 counter_t count; /**< optimization counter */
105 const ir_op *op; /**< the op for this entry */
109 * An entry for a block in a ir-graph
111 typedef struct _block_entry_t {
112 counter_t cnt_nodes; /**< the counter of nodes in this block */
113 counter_t cnt_edges; /**< the counter of edges in this block */
114 counter_t cnt_in_edges; /**< the counter of edges incoming from other blocks to this block */
115 counter_t cnt_out_edges; /**< the counter of edges outgoing from this block to other blocks */
116 long block_nr; /**< block nr */
120 typedef struct _dumper_t dumper_t;
123 * handler for dumping an IRG
125 * @param dmp the dumper
126 * @param entry the IR-graph hash map entry
128 typedef void (*dump_graph_FUNC)(dumper_t *dmp, graph_entry_t *entry);
131 * handler for dumper init
133 * @param dmp the dumper
134 * @param name name of the file to dump to
136 typedef void (*dump_init_FUNC)(dumper_t *dmp, const char *name);
139 * handler for dumper finish
141 * @param dmp the dumper
143 typedef void (*dump_finish_FUNC)(dumper_t *dmp);
149 typedef struct _statistic_info_t {
150 struct obstack cnts; /**< obstack containing the counters */
151 HASH_MAP(graph_entry_t) *irg_hash; /**< hash map containing the counter for irgs */
152 HASH_MAP(ir_op) *ir_op_hash; /**< hash map containing all ir_ops (accessible by op_codes) */
153 pdeq *wait_q; /**< wait queue for leaf call decision */
154 int recursive; /**< flag for detecting recursive hook calls */
155 int in_dead_node_elim; /**< set, if dead node elimination runs */
156 ir_op *op_Phi0; /**< pseudo op for Phi0 */
157 ir_op *op_PhiM; /**< pseudo op for memory Phi */
158 ir_op *op_ProjM; /**< pseudo op for memory Proj */
159 ir_op *op_MulC; /**< pseudo op for multiplication by const */
160 ir_op *op_DivC; /**< pseudo op for division by const */
161 ir_op *op_ModC; /**< pseudo op for modulo by const */
162 ir_op *op_DivModC; /**< pseudo op for DivMod by const */
163 dumper_t *dumper; /**< list of dumper */
164 int reassoc_run; /**< if set, reassociation is running */
165 int stat_options; /**< statistic options */
169 * a dumper description
172 dump_graph_FUNC dump_graph; /**< handler for dumping an irg */
173 dump_init_FUNC init; /**< handler for init */
174 dump_finish_FUNC finish; /**< handler for finish */
175 FILE *f; /**< the file to dump to */
176 stat_info_t *status; /**< access to the global status */
177 dumper_t *next; /**< link to the next dumper */
182 * An entry in a distribution table
184 typedef struct _distrib_entry_t {
185 counter_t cnt; /**< the current count */
186 const void *object; /**< the object which is counted */
189 /** The type of the hash function for objects in distribution tables. */
190 typedef unsigned (*distrib_hash_fun)(const void *object);
193 * The distribution table.
195 typedef struct _distrib_tbl_t {
196 struct obstack cnts; /**< obstack containing the distrib_entry_t entries */
197 HASH_MAP(distrib_entry_t) *hash_map; /**< the hash map containing the distribution */
198 distrib_hash_fun hash_func; /**< the hash function for object in this distribution */
199 unsigned int_dist; /**< non-zero, if it's a integer distribution */
202 /* API for distribution tables */
205 * creates a new distribution table
207 * @param cmp_func Compare function for objects in the distribution
208 * @param hash_func Hash function for objects in the distribution
210 distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func);
213 * creates a new distribution table for an integer distribution
215 distrib_tbl_t *stat_new_int_distrib_tbl(void);
218 * destroys a distribution table
220 void stat_delete_distrib_tbl(distrib_tbl_t *tbl);
223 * adds a new object count into the distribution table
225 void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_t *cnt);
228 * adds a new key count into the integer distribution table
230 void stat_add_int_distrib_tbl(distrib_tbl_t *tbl, int key, const counter_t *cnt);
233 * calculates the mean value of a distribution
235 double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl);
237 /** evaluates each entry of a distribution table */
238 typedef void (*eval_distrib_entry_fun)(const distrib_entry_t *entry);
241 * iterates over all entries in a distribution table
243 void stat_iterate_distrib_tbl(distrib_tbl_t *tbl, eval_distrib_entry_fun eval);
245 #endif /* _FIRMSTAT_T_H_ */