added data for post-dominance
[libfirm] / ir / ir / irflag.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irflag.h
4  * Purpose:     Flags to control optimizations.
5  * Author:      Christian Schaefer, Goetz Lindenmaier
6  * Modified by: Michael Beck
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1999-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  * @file irflag.h
15  *
16  * Flags to customize the behavior of libfirm.
17  *
18  * @author Christian Schaefer
19  *
20  * There are the following groups of flags:
21  * 1. Optimization flags.
22  *    a)  There is a flag, 'optimize' to turn on/off all optimizations.
23  *    b)  There are flags for each individual optimization.  Some flags turns
24  *        transformations in several algorithms on/off.
25  * 2. Normalization flags.
26  *    These flags steer transformations of the ir that improve it, as removing
27  *    dump Phi nodes (one predecessor, all preds are equal ...), Ids, Tuples ...
28  * 3. Verbosity flags.
29  *    a) Flags to steer the level of the information.
30  *    b) Flags to steer in which phase information should be dumped.
31  * 4. Verification flag
32  *    This one controls the behavior of node and type verifications
33  */
34 #ifndef _IRFLAG_H_
35 #define _IRFLAG_H_
36
37 #include "firm_types.h"
38
39 /**
40  * A container type to load/restore all optimizations
41  */
42 typedef unsigned optimization_state_t;
43
44 /**
45  * This function enables/disables optimizations globally.
46  *
47  * If optimize == 0 no optimizations are performed at all.
48  * Default: optimize == 1.
49  */
50 void set_optimize (int value);
51 int  get_optimize(void);
52
53 /** This function enables/disables output of information about phases and
54  *  controls the verbosity level.
55  *
56  *  0: no output at all.
57  *  1: very short output
58  *  >>1: very verbose output.
59  */
60 void set_firm_verbosity (int value);
61 int  get_firm_verbosity (void);
62
63 /** Enables/Disables constant folding optimization.
64  *
65  *  If opt_constant_folding == 1 perform
66  *  - constant expression evaluation (2 + 5 ==> 7, 3 < 2 ==> false)
67  *  - algebraic simplification  (a * 0 ==> 0, a or a ==> a)
68  *  - simplification of tests   ( !(a < b) ==> (a >= b))
69  *  - refining the memory representation
70  *  - remove store after load
71  * Default: opt_constant_folding == 1.
72  */
73 void set_opt_constant_folding (int value);
74
75 /** Enables/Disables loop unrolling.
76  *
77  * If opt_loop_unrolling == 1 perform loop_unrolling.
78  * See loop_unrolling.h.
79  *
80  * Default: opt_loop_unrolling = 1;
81  */
82 void set_opt_loop_unrolling (int value);
83
84 /** Enables/Disables output of information about loop unrolling.
85  */
86 void set_opt_loop_unrolling_verbose (int value);
87
88 /** Enables/Disables removal of redundant Loads and Stores.
89  *
90  *  - Remove Store that overwrites a just stored value (WAW).
91  *  - Remove Store if it stores a value just loaded (WAR with the same value).
92  *  - Remove Load that loads a value just saved (RAW with the same value).
93  *  - remove Load that loads a value already loaded (RAR)
94  *  - replace Load of constant values with constants (RC)
95  */
96 void set_opt_redundant_loadstore(int value);
97
98 /** Enables/Disables constant subexpression elimination.
99  *
100  * If opt_cse == 1 perform constant subexpression elimination.
101  * Default: opt_cse == 1.
102  */
103 void set_opt_cse (int value);
104
105 /** Returns constant folding optimization setting. */
106 int get_opt_cse(void);
107
108 /** Enables/Disables global constant subexpression elimination.
109  *
110  * If opt_global_cse == 1 and opt_cse == 1 perform intra procedure
111  * constant subexpression elimination for floating nodes.  Intra
112  * procedure cse gets the graph into state "floating".  It is necessary
113  * to run pre/code motion to get the graph back into state "op_pin_state_pinned".
114  * right after a call to local_optimize with global cse turned on.
115  * Default: opt_global_cse == 0.
116  */
117 void set_opt_global_cse (int value);
118
119 /** Enables/Disables strength reduction.
120  *
121  * If opt_strength_red == 1 perform strength reduction.
122  * See strenth_red.h.
123  *
124  * Default: opt_strength_red = 1;
125  */
126 void set_opt_strength_red (int value);
127
128 /** Enables/Disables output of information about strength reduction.
129  */
130 void set_opt_strength_red_verbose (int value);
131
132 /** Enables/Disables unreachable code elimination.
133  *
134  * If set, evaluate conditions of conditional branch and replace the
135  * branch with a Jmp/Bad Tuple.
136  *
137  * If opt_unreachable_code == 1 replace nodes (except Block,
138  * Phi and Tuple) with a Bad predecessor by the Bad node.
139  * Default: opt_unreachable_code == 1.
140  */
141 void set_opt_unreachable_code(int value);
142
143 /** Enables/Disables control flow optimizations.
144  *
145  * Performs Straightening, if simplifications and loop simplifications.
146  * Sets all separate control flow flags (control_flow_straightening,
147  * weak_simplification, strong_simplification and critical_edges).
148  */
149 void set_opt_control_flow(int value);
150
151 /** Enables/Disables Straightening. */
152 void set_opt_control_flow_straightening(int value);
153
154 /** Enables/Disables if simplifications in local optimizations. */
155 void set_opt_control_flow_weak_simplification(int value);
156
157 /** Enables/Disables strong if and loop simplification (in optimize_cf). */
158 void set_opt_control_flow_strong_simplification(int value);
159
160 /** Enables/Disables removal of critical control flow edges. */
161 void set_opt_critical_edges(int value);
162
163 /** Enables/Disables reassociation.
164  *
165  * If opt_reassociation == 1 reassociation is performed.
166  * Default: opt_reassociation == 1.
167  */
168 void set_opt_reassociation(int value);
169
170 /** Enables/Disables dead node elimination.
171  *
172  * If opt_dead_node_elimination == 1 deallocate all dead nodes
173  * by copying the firm graph.
174  * Default: opt_dead_node_elimination == 1. */
175 void set_opt_dead_node_elimination (int value);
176
177 /** Enables/Disables dead method elimination.
178  *
179  * If opt_dead_method_elimination == 1 methods never called are
180  * removed.
181  * Default: opt_dead_method_elimination == 1. */
182 void set_opt_dead_method_elimination (int value);
183 void set_opt_dead_method_elimination_verbose (int value);
184
185 /** Enable/Disables inlining.
186  *
187  * If opt_inline == 1 the inlining transformation is performed.
188  */
189 void set_opt_inline (int value);
190
191 /** Enable/Disable optimization of dynamic method dispatch.
192  *
193  * This flag enables/disables the optimization of dynamic method dispatch.
194  * If the flag is turned on Sel nodes can be replaced by Const nodes representing
195  * the address of a function.
196  */
197 void set_opt_dyn_meth_dispatch (int value);
198 int  get_opt_dyn_meth_dispatch (void);
199
200 /** Enable/Disable type optimization of cast nodes.
201  *
202  * Controls the optimizations in tropt.h.  Default: on.
203  */
204 void set_opt_optimize_class_casts (int value);
205 void set_opt_optimize_class_casts_verbose (int value);
206
207 /** Restricts the behavior of cast optimization.
208  *
209  *  If set, downcast are not optimized if they might be
210  *  illegal as in (Super)(Sub) (new Super()).  Default:
211  *  0 == not suppressed.
212  */
213 void set_opt_suppress_downcast_optimization(int value);
214 int  get_opt_suppress_downcast_optimization(void);
215
216 /** Enable/Disable optimization of tail-recursion calls.
217  *
218  * This flag enables/disables the optimization tail-recursion call.
219  * If the flag is turned on tail-recursion calls are optimized into loops.
220  */
221 void set_opt_tail_recursion(int value);
222 void set_opt_tail_recursion_verbose(int value);
223
224 /** Enable/Disable floating of fragile ops.
225  *
226  * This flags enables/disables the floating of fragile operations.
227  * If this flag is on, fragile operations which are known to NOT raise
228  * an exception can be place to other basic blocks.
229  * Otherwise they remain in the block they were created.
230  */
231 void set_opt_fragile_ops(int value);
232
233 /**
234  * Enable/Disable if conversion.
235  *
236  * If conversion tries to turn Conds into Mux nodes to eliminate
237  * control flow.
238  */
239 void set_opt_if_conversion(int value);
240
241 /**
242  * Enable/Disable real function call optimization.
243  *
244  * Real function call optimization detects "real functions" and
245  * allows the floating of Call nodes.
246  */
247 void set_opt_real_function_call(int value);
248
249 /**
250  * Enable/Disable Confirm node removal during local optimization.
251  */
252 void set_opt_remove_confirm(int value);
253
254 /**
255  * Enable/Disable scalar replacement optimization.
256  */
257 void set_opt_scalar_replacement(int value);
258 void set_opt_scalar_replacement_verbose(int value);
259
260 /** Enable/Disable normalizations of the firm representation.
261  *
262  *  This flag guards transformations that normalize the firm representation
263  *  as removing Ids and Tuples, useless Phis, replacing SymConst(id) by
264  *  Const(entity) and others.
265  *  The transformations guarded by this flag are not guarded by flag
266  *  "optimize".
267  *  Many algorithms operating on firm can not deal with constructs in
268  *  the non-normalized representation.
269  *  default: 1
270  *  @@@ ATTENTION: not all such transformations are guarded by a flag.
271  */
272 void set_opt_normalize (int value);
273
274
275 /** Enable/Disable precise exception context. */
276 void set_opt_precise_exc_context(int value);
277
278 /**
279  * Save the current optimization state.
280  */
281 void save_optimization_state(optimization_state_t *state);
282
283 /**
284  * Restore the current optimization state.
285  */
286 void restore_optimization_state(const optimization_state_t *state);
287
288 /**
289  * Switches ALL optimizations off.
290  */
291 void all_optimizations_off(void);
292
293 /**
294  * Possible verification modes.
295  */
296 typedef enum _firm_verification_t {
297   FIRM_VERIFICATION_OFF        = 0,     /**< do not verify nodes at all */
298   FIRM_VERIFICATION_ON         = 1,     /**< do node verification and assert on error in debug version */
299   FIRM_VERIFICATION_REPORT     = 2,     /**< do node verification, but report to stderr only */
300   FIRM_VERIFICATION_ERROR_ONLY = 3      /**< do node verification, but NEVER do assert nor report */
301 } firm_verification_t;
302
303 /** Select verification of nodes.
304  *
305  *  Per default the  verification is in mode NODE_VERIFICATION_ASSERT.
306  *  Turn the verification off during development to check partial implementations.
307  */
308 void do_node_verification(firm_verification_t mode);
309
310 #endif /* _IRFLAG_H_ */