- BugFix: kill partitions with 0 blocks either
[libfirm] / include / libfirm / irflag.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Flags to control optimizations.
23  * @author  Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  * @version $Id$
25  * @summary
26  * Flags to customize the behavior of libfirm.
27  *
28  * There are the following groups of flags:
29  * 1. Optimization flags.
30  *    a)  There is a flag, 'optimize' to turn on/off all optimizations.
31  *    b)  There are flags for each individual optimization.  Some flags turns
32  *        transformations in several algorithms on/off.
33  * 2. Normalization flags.
34  *    These flags steer transformations of the ir that improve it, as removing
35  *    dump Phi nodes (one predecessor, all predecessors are equal ...), Ids, Tuples ...
36  * 3. Verbosity flags.
37  *    a) Flags to steer the level of the information.
38  *    b) Flags to steer in which phase information should be dumped.
39  * 4. Verification flag
40  *    This one controls the behavior of node and type verifications
41  */
42 #ifndef FIRM_IR_IRFLAG_H
43 #define FIRM_IR_IRFLAG_H
44
45 #include "firm_types.h"
46
47 /**
48  * A container type to load/restore all optimizations
49  */
50 typedef unsigned optimization_state_t;
51
52 /**
53  * This function enables/disables optimizations globally.
54  *
55  * If optimize == 0 no optimizations are performed at all.
56  * Default: optimize == 1.
57  */
58 void set_optimize(int value);
59 int  get_optimize(void);
60
61 /** Enables/Disables constant folding optimization.
62  *
63  *  If opt_constant_folding == 1 perform
64  *  constant expression evaluation (2 + 5 ==> 7, 3 < 2 ==> false)
65  * Default: opt_constant_folding == 1.
66  */
67 void set_opt_constant_folding(int value);
68
69 /** Enables/Disables algebraic simplifications.
70  *
71  *  If opt_algebraic_simplification == 1 perform
72  *  - algebraic simplification  (a * 0 ==> 0, a or a ==> a)
73  *  - simplification of tests   ( !(a < b) ==> (a >= b))
74  * Default: opt_algebraic_simplification == 1.
75  */
76 void set_opt_algebraic_simplification(int value);
77
78 /** Enables/Disables common subexpression elimination.
79  *
80  * If opt_cse == 1 perform common subexpression elimination.
81  * Default: opt_cse == 1.
82  */
83 void set_opt_cse(int value);
84
85 /** Returns constant folding optimization setting. */
86 int get_opt_cse(void);
87
88 /** Enables/Disables global constant subexpression elimination.
89  *
90  * If opt_global_cse == 1 and opt_cse == 1 perform intra procedure
91  * constant subexpression elimination for floating nodes.  Intra
92  * procedure cse gets the graph into state "floating".  It is necessary
93  * to run pre/code motion to get the graph back into state "op_pin_state_pinned".
94  * right after a call to local_optimize with global cse turned on.
95  * Default: opt_global_cse == 0.
96  */
97 void set_opt_global_cse(int value);
98
99 /** Enables/Disables usage of combo algorithm.
100  *
101  *  If opt_combo == 1 perform combo optimization
102  *  instead of combinations of optimiza_graph_df()/
103  *  optimize_graph_cf()
104  * Default: opt_combo == 1.
105  */
106 void set_opt_combo(int value);
107
108 /** Enables/Disables strength reduction.
109  *
110  * If opt_strength_red == 1 perform strength reduction.
111  * See strenth_red.h.
112  *
113  * Default: opt_strength_red = 1;
114  */
115 void set_opt_strength_red(int value);
116
117 /** Enables/Disables unreachable code elimination.
118  *
119  * If set, evaluate conditions of conditional branch and replace the
120  * branch with a Jmp/Bad Tuple.
121  *
122  * If opt_unreachable_code == 1 replace nodes (except Block,
123  * Phi and Tuple) with a Bad predecessor by the Bad node.
124  * Default: opt_unreachable_code == 1.
125  */
126 void set_opt_unreachable_code(int value);
127
128 /** Enables/Disables control flow optimizations.
129  *
130  * Performs Straightening, if simplifications and loop simplifications.
131  * Sets all separate control flow flags (control_flow_straightening,
132  * weak_simplification, strong_simplification and critical_edges).
133  */
134 void set_opt_control_flow(int value);
135
136 /** Enables/Disables Straightening. */
137 void set_opt_control_flow_straightening(int value);
138
139 /** Enables/Disables if simplifications in local optimizations. */
140 void set_opt_control_flow_weak_simplification(int value);
141
142 /** Enables/Disables strong if and loop simplification (in optimize_cf). */
143 void set_opt_control_flow_strong_simplification(int value);
144
145 /** Enable/Disable optimization of dynamic method dispatch.
146  *
147  * This flag enables/disables the optimization of dynamic method dispatch.
148  * If the flag is turned on Sel nodes can be replaced by Const nodes representing
149  * the address of a function.
150  */
151 void set_opt_dyn_meth_dispatch(int value);
152 int  get_opt_dyn_meth_dispatch(void);
153
154 /** Enable/Disable type optimization of cast nodes.
155  *
156  * Controls the optimizations in tropt.h.  Default: on.
157  */
158 void set_opt_optimize_class_casts(int value);
159
160 /** Restricts the behavior of cast optimization.
161  *
162  *  If set, downcast are not optimized if they might be
163  *  illegal as in (Super)(Sub) (new Super()).  Default:
164  *  0 == not suppressed.
165  */
166 void set_opt_suppress_downcast_optimization(int value);
167 int  get_opt_suppress_downcast_optimization(void);
168
169 /** Enable/Disable floating of fragile ops.
170  *
171  * This flags enables/disables the floating of fragile operations.
172  * If this flag is on, fragile operations which are known to NOT raise
173  * an exception can be place to other basic blocks.
174  * Otherwise they remain in the block they were created.
175  */
176 void set_opt_fragile_ops(int value);
177
178 /**
179  * Enable/Disable Confirm node removal during local optimization.
180  */
181 void set_opt_remove_confirm(int value);
182
183 /**
184  * Enable/Disable scalar replacement optimization.
185  */
186 void set_opt_scalar_replacement(int value);
187
188 /**
189  * Enable/Disable Null exception in Load and Store nodes only.
190  *
191  * If enabled, only Null pointer exception can occur at Load and
192  * store nodes. If it can be proved that the address input of these
193  * nodes is non-null, the exception edge can safely be removed.
194  * If disabled, other exceptions (like unaligned access, read-only memory,
195  * etc.) can occur.
196  *
197  * This flag is enabled by default.
198  */
199 void set_opt_ldst_only_null_ptr_exceptions(int value);
200
201 /**
202  * Enable/Disable Selection based Null pointer check elimination.
203  *
204  * In languages, where all addresses are always Sel nodes, Null
205  * pointers can only occur as input to Sel nodes.
206  * If Null pointers are the only source for exceptions in Load and
207  * Store nodes (as typical in high level languages), we can eliminate
208  * exception edges from Load and Store when can prove that the Sel
209  * nodes representing the Load/Store address have non-null inputs.
210  * Enabling this flag enables this elimination.
211  *
212  * Enabling this flag is meaningless if ldst_non_null_exceptions is
213  * enabled.
214  *
215  * This flag should be set for Java style languages.
216  */
217 void set_opt_sel_based_null_check_elim(int value);
218
219 /**
220  * Enable/Disable Global Null Pointer Test Elimination.
221  *
222  * In languages where it is illegal to dereference NULL pointer, doing
223  * so makes the pointer "valid non-null", else the program will stop
224  * anyway by a fault.
225  *
226  * This flag should be set for C style languages.
227  */
228 void set_opt_global_null_ptr_elimination(int value);
229
230 /**
231  * Enable/Disable Automatic construction of Sync nodes during
232  * Firm construction.
233  *
234  * If this flags is set, sequential non-volatile Loads are automatically
235  * rearranged so that they can be executed in parallel by creating Sync nodes.
236  *
237  * This flag should be set for Java style languages.
238  */
239 void set_opt_auto_create_sync(int value);
240
241 /** Enable/Disable normalizations of the firm representation.
242  *
243  *  This flag guards transformations that normalize the Firm representation
244  *  as removing Ids and Tuples, useless Phis, replacing SymConst(id) by
245  *  Const(entity) and others.
246  *  The transformations guarded by this flag are not guarded by flag
247  *  "optimize".
248  *  Many algorithms operating on Firm can not deal with constructs in
249  *  the non-normalized representation.
250  *  default: ON
251  *
252  *  @note ATTENTION: not all such transformations are guarded by a flag.
253  */
254 void set_opt_normalize(int value);
255
256 /** Enable/Disable precise exception context.
257  *
258  * If enabled, all exceptions form a barrier for values, as in the
259  * following example:
260  *
261  * @code
262  * a = 1;
263  * b = 3 / 0;
264  * a = 2;
265  * @endcode
266  *
267  * If precise exception handling is enabled, an exception handler see a == 1,
268  * else it might see a == 2.
269  * Enable this for languages with strict exception order like Java.
270  */
271 void set_opt_precise_exc_context(int value);
272
273 /** Enable/Disable Alias analysis.
274  *
275  * If enabled, memory disambiguation by alias analysis is used.
276  */
277 void set_opt_alias_analysis(int value);
278
279 /** Enable/Disable closed world assumption.
280  *
281  * If enabled, optimizations expect to know the "whole world", i.e. no
282  * external types or callers exist.
283  * This enables some powerful optimizations.
284  */
285 void set_opt_closed_world(int value);
286
287 /**
288  * Save the current optimization state.
289  */
290 void save_optimization_state(optimization_state_t *state);
291
292 /**
293  * Restore the current optimization state.
294  */
295 void restore_optimization_state(const optimization_state_t *state);
296
297 /**
298  * Switches ALL optimizations off.
299  */
300 void all_optimizations_off(void);
301
302 /**
303  * Possible verification modes.
304  */
305 typedef enum _firm_verification_t {
306   FIRM_VERIFICATION_OFF        = 0,     /**< do not verify nodes at all */
307   FIRM_VERIFICATION_ON         = 1,     /**< do node verification and assert on error in debug version */
308   FIRM_VERIFICATION_REPORT     = 2,     /**< do node verification, but report to stderr only */
309   FIRM_VERIFICATION_ERROR_ONLY = 3      /**< do node verification, but NEVER do assert nor report */
310 } firm_verification_t;
311
312 /** Select verification of IR nodes and types.
313  *
314  *  Per default the  verification is in mode NODE_VERIFICATION_ASSERT.
315  *  Turn the verification off during development to check partial implementations.
316  */
317 void do_node_verification(firm_verification_t mode);
318
319 #endif