inproved, commented
[libfirm] / ir / stat / firmstat.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/stat/firmstat.h
4  * Purpose:     Statistics for Firm.
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_H_
12 #define _FIRMSTAT_H_
13
14 /**
15  * @file firmstat.h
16  */
17 #include "irop.h"
18 #include "irnode.h"
19 #include "irgraph.h"
20
21 /**
22  * Statistic options, can be or'ed.
23  */
24 enum firmstat_options_t {
25   FIRMSTAT_ENABLED         = 0x00000001,        /**< enable statistics */
26   FIRMSTAT_PATTERN_ENABLED = 0x00000002,        /**< enable pattern calculation */
27   FIRMSTAT_COUNT_STRONG_OP = 0x00000004,        /**< if set, count Mul/Div/Mod/DivMod by constant */
28 };
29
30 /**
31  * Finish the statistics.
32  * Never called from libFirm should be called from user.
33  *
34  * @param name   basename of the statistic output file
35  */
36 void stat_finish(const char *name);
37
38 #ifdef FIRM_STATISTICS
39
40 typedef enum {
41   STAT_OPT_STG,                 /**< straightening optimization */
42   STAT_OPT_IFSIM,               /**< if simplification */
43   STAT_OPT_CONST_EVAL,          /**< constant evaluation */
44   STAT_OPT_ALGSIM,              /**< algebraic simplification */
45   STAT_OPT_PHI,                 /**< Phi optmization */
46   STAT_OPT_WAW,                 /**< Write-After-Write optimization */
47   STAT_OPT_WAR,                 /**< Write-After-Read optimization */
48   STAT_OPT_RAW,                 /**< Read-After-Write optimization */
49   STAT_OPT_RAR,                 /**< Read-After-Read optimization */
50   STAT_OPT_RC,                  /**< Read-a-Const optimization */
51   STAT_OPT_TUPLE,               /**< Tuple optimization */
52   STAT_OPT_ID,                  /**< ID optimization */
53   STAT_OPT_CSE,                 /**< common subexpression elimination */
54   STAT_OPT_STRENGTH_RED,        /**< strenght reduction */
55   STAT_OPT_ARCH_DEP,            /**< architecture dependant optimization */
56   STAT_OPT_REASSOC,             /**< reassociation */
57   STAT_OPT_POLY_CALL,           /**< polymorphic call optimization */
58   STAT_LOWERED,                 /**< lowered */
59
60   STAT_OPT_MAX
61 } stat_opt_kind;
62
63 /**
64  * initialize the statistics module.
65  *
66  * @param enable_options  Bitmask containing the statistic options
67  */
68 void init_stat(unsigned enable_options);
69
70 /**
71  * A new IR op is registered.
72  */
73 void stat_new_ir_op(const ir_op *op);
74
75 /**
76  * An IR op is freed.
77  */
78 void stat_free_ir_op(const ir_op *op);
79
80 /**
81  * A new node is created.
82  */
83 void stat_new_node(ir_node *node);
84
85 /**
86  * A node is changed into a Id node
87  */
88 void stat_turn_into_id(ir_node *node);
89
90 /**
91  * A new graph was created
92  */
93 void stat_new_graph(ir_graph *irg, entity *ent);
94
95 /**
96  * A graph was deleted
97  */
98 void stat_free_graph(ir_graph *irg);
99
100 /**
101  * A walk over a graph is initiated
102  */
103 void stat_irg_walk(ir_graph *irg, void *pre, void *post);
104
105 /**
106  * A walk over a graph in block-wise order is initiated
107  */
108 void stat_irg_walk_blkwise(ir_graph *irg, void *pre, void *post);
109
110 /**
111  * A walk over the graph's blocks is initiated
112  */
113 void stat_irg_block_walk(ir_graph *irg, const ir_node *node, void *pre, void *post);
114
115 /**
116  * Some nodes were optimized into some others due to an optimization
117  */
118 void stat_merge_nodes(
119     ir_node **new_node_array, int new_num_entries,
120     ir_node **old_node_array, int old_num_entries,
121     stat_opt_kind opt);
122
123 /**
124  * Reassociation of nodes started/stopped.
125  */
126 void stat_reassociate(int start);
127
128 /**
129  * A node was lowered into other nodes
130  */
131 void stat_lower(ir_node *node);
132
133 /**
134  * A graph was inlined
135  */
136 void stat_inline(ir_node *call, ir_graph *irg);
137
138 /**
139  * A graph with tail-recursions was optimized.
140  */
141 void stat_tail_rec(ir_graph *irg);
142
143 /**
144  * Strength reduction was performed on an iteration variable.
145  */
146 void stat_strength_red(ir_graph *irg, ir_node *strong, ir_node *cmp);
147
148 /**
149  * Start the dead node elimination.
150  */
151 void stat_dead_node_elim_start(ir_graph *irg);
152
153 /**
154  * Stops the dead node elimination.
155  */
156 void stat_dead_node_elim_stop(ir_graph *irg);
157
158 /**
159  * A multiply was replaced by a series of Shifts/Adds/Subs
160  */
161 void stat_arch_dep_replace_mul_with_shifts(ir_node *mul);
162
163 /**
164  * A division was replaced by a series of Shifts/Muls
165  */
166 void stat_arch_dep_replace_div_by_const(ir_node *div);
167
168 /**
169  * A modulo was replaced by a series of Shifts/Muls
170  */
171 void stat_arch_dep_replace_mod_by_const(ir_node *mod);
172
173 /**
174  * A Divod was replaced by a series of Shifts/Muls
175  */
176 void stat_arch_dep_replace_DivMod_by_const(ir_node *divmod);
177
178 /**
179  * helper: get an ir_op from an opcode
180  *
181  * @param code  the opcode
182  *
183  * @return  The associated ir_op or NULL if the opcode could not be found.
184  */
185 ir_op *stat_get_op_from_opcode(opcode code);
186
187 #else
188
189 #define init_stat(enable_options)
190 #define stat_finish(name)
191 #define stat_new_ir_op(op)
192 #define stat_free_ir_op(op)
193 #define stat_new_node(node)
194 #define stat_turn_into_id(node)
195 #define stat_new_graph(irg, ent)
196 #define stat_free_graph(irg)
197 #define stat_irg_walk(irg, pre, post)
198 #define stat_irg_walk_blkwise(irg, pre, post)
199 #define stat_irg_block_walk(irg, node, pre, post)
200 #define stat_merge_nodes(new_node_array, new_num_entries, old_node_array, old_num_entries, opt)
201 #define stat_reassociate(start)
202 #define stat_lower(node)
203 #define stat_inline(call, irg)
204 #define stat_tail_rec(irg)
205 #define stat_strength_red(irg, strong, cmp)
206 #define stat_dead_node_elim_start(irg)
207 #define stat_dead_node_elim_stop(irg)
208 #define stat_arch_dep_replace_mul_with_shifts(irn)
209 #define stat_arch_dep_replace_div_by_const(irn)
210 #define stat_arch_dep_replace_mod_by_const(irn)
211 #define stat_arch_dep_replace_DivMod_by_const(irn)
212
213 #endif
214
215 #endif /* _FIRMSTAT_H_ */