get_opt_alias_analysis(), set_opt_alias_analysis() added
[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 predecessors 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 _FIRM_IR_IRFLAG_H_
35 #define _FIRM_IR_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  * Default: opt_constant_folding == 1.
70  */
71 void set_opt_constant_folding (int value);
72
73 /** Enables/Disables loop unrolling.
74  *
75  * If opt_loop_unrolling == 1 perform loop_unrolling.
76  * See loop_unrolling.h.
77  *
78  * Default: opt_loop_unrolling = 1;
79  */
80 void set_opt_loop_unrolling (int value);
81
82 /** Enables/Disables output of information about loop unrolling.
83  */
84 void set_opt_loop_unrolling_verbose (int value);
85
86 /** Enables/Disables removal of redundant Loads and Stores.
87  *
88  *  - Remove Store that overwrites a just stored value (WAW).
89  *  - Remove Store if it stores a value just loaded (WAR with the same value).
90  *  - Remove Load that loads a value just saved (RAW with the same value).
91  *  - remove Load that loads a value already loaded (RAR)
92  *  - replace Load of constant values with constants (RC)
93  */
94 void set_opt_redundant_loadstore(int value);
95
96 /** Enables/Disables common subexpression elimination.
97  *
98  * If opt_cse == 1 perform common subexpression elimination.
99  * Default: opt_cse == 1.
100  */
101 void set_opt_cse (int value);
102
103 /** Returns constant folding optimization setting. */
104 int get_opt_cse(void);
105
106 /** Enables/Disables global constant subexpression elimination.
107  *
108  * If opt_global_cse == 1 and opt_cse == 1 perform intra procedure
109  * constant subexpression elimination for floating nodes.  Intra
110  * procedure cse gets the graph into state "floating".  It is necessary
111  * to run pre/code motion to get the graph back into state "op_pin_state_pinned".
112  * right after a call to local_optimize with global cse turned on.
113  * Default: opt_global_cse == 0.
114  */
115 void set_opt_global_cse (int value);
116
117 /** Enables/Disables strength reduction.
118  *
119  * If opt_strength_red == 1 perform strength reduction.
120  * See strenth_red.h.
121  *
122  * Default: opt_strength_red = 1;
123  */
124 void set_opt_strength_red (int value);
125
126 /** Enables/Disables output of information about strength reduction.
127  */
128 void set_opt_strength_red_verbose (int value);
129
130 /** Enables/Disables unreachable code elimination.
131  *
132  * If set, evaluate conditions of conditional branch and replace the
133  * branch with a Jmp/Bad Tuple.
134  *
135  * If opt_unreachable_code == 1 replace nodes (except Block,
136  * Phi and Tuple) with a Bad predecessor by the Bad node.
137  * Default: opt_unreachable_code == 1.
138  */
139 void set_opt_unreachable_code(int value);
140
141 /** Enables/Disables control flow optimizations.
142  *
143  * Performs Straightening, if simplifications and loop simplifications.
144  * Sets all separate control flow flags (control_flow_straightening,
145  * weak_simplification, strong_simplification and critical_edges).
146  */
147 void set_opt_control_flow(int value);
148
149 /** Enables/Disables Straightening. */
150 void set_opt_control_flow_straightening(int value);
151
152 /** Enables/Disables if simplifications in local optimizations. */
153 void set_opt_control_flow_weak_simplification(int value);
154
155 /** Enables/Disables strong if and loop simplification (in optimize_cf). */
156 void set_opt_control_flow_strong_simplification(int value);
157
158 /** Enables/Disables reassociation.
159  *
160  * If opt_reassociation == 1 reassociation is performed.
161  * Default: opt_reassociation == 1.
162  */
163 void set_opt_reassociation(int value);
164
165 /** Enables/Disables dead node elimination.
166  *
167  * If opt_dead_node_elimination == 1 deallocate all dead nodes
168  * by copying the firm graph.
169  * Default: opt_dead_node_elimination == 1. */
170 void set_opt_dead_node_elimination (int value);
171
172 /** Enables/Disables dead method elimination.
173  *
174  * If opt_dead_method_elimination == 1 methods never called are
175  * removed.
176  * Default: opt_dead_method_elimination == 1.
177  */
178 void set_opt_dead_method_elimination (int value);
179 void set_opt_dead_method_elimination_verbose (int value);
180
181 /** Enable/Disables method inlining.
182  *
183  * If opt_inline == 1 the inlining transformation is performed.
184  */
185 void set_opt_inline (int value);
186
187 /** Enable/Disable optimization of dynamic method dispatch.
188  *
189  * This flag enables/disables the optimization of dynamic method dispatch.
190  * If the flag is turned on Sel nodes can be replaced by Const nodes representing
191  * the address of a function.
192  */
193 void set_opt_dyn_meth_dispatch (int value);
194 int  get_opt_dyn_meth_dispatch (void);
195
196 /** Enable/Disable type optimization of cast nodes.
197  *
198  * Controls the optimizations in tropt.h.  Default: on.
199  */
200 void set_opt_optimize_class_casts (int value);
201 void set_opt_optimize_class_casts_verbose (int value);
202
203 /** Restricts the behavior of cast optimization.
204  *
205  *  If set, downcast are not optimized if they might be
206  *  illegal as in (Super)(Sub) (new Super()).  Default:
207  *  0 == not suppressed.
208  */
209 void set_opt_suppress_downcast_optimization(int value);
210 int  get_opt_suppress_downcast_optimization(void);
211
212 /** Enable/Disable optimization of tail-recursion calls.
213  *
214  * This flag enables/disables the optimization tail-recursion call.
215  * If the flag is turned on tail-recursion calls are optimized into loops.
216  */
217 void set_opt_tail_recursion(int value);
218 void set_opt_tail_recursion_verbose(int value);
219
220 /** Enable/Disable floating of fragile ops.
221  *
222  * This flags enables/disables the floating of fragile operations.
223  * If this flag is on, fragile operations which are known to NOT raise
224  * an exception can be place to other basic blocks.
225  * Otherwise they remain in the block they were created.
226  */
227 void set_opt_fragile_ops(int value);
228
229 /**
230  * Enable/Disable if conversion.
231  *
232  * If conversion tries to turn Conds into Mux nodes to eliminate
233  * control flow.
234  */
235 void set_opt_if_conversion(int value);
236
237 /**
238  * Enable/Disable function call optimization.
239  *
240  * Function call optimization detects const and pure functions and
241  * allows the CSE of Call nodes. A const function is one that
242  * do only evaluate it's parameters and did not read or write memory
243  * to compute its results. Pure functions are allowed to read global memory.
244  */
245 void set_opt_function_call(int value);
246
247 /**
248  * Enable/Disable Confirm node removal during local optimization.
249  */
250 void set_opt_remove_confirm(int value);
251
252 /**
253  * Enable/Disable scalar replacement optimization.
254  */
255 void set_opt_scalar_replacement(int value);
256 void set_opt_scalar_replacement_verbose(int value);
257
258 /**
259  * Enable/Disable Null exception in Load and Store nodes only.
260  *
261  * If enabled, only Null pointer exception can occur at Load and
262  * store nodes. If it can be proved that the address input of these
263  * nodes is non-null, the exception edge can safely be removed.
264  * If disabled, other exceptions (like unaligned access, read-only memory,
265  * etc.) can occur.
266  *
267  * This flag is enabled by default.
268  */
269 void set_opt_ldst_only_null_ptr_exceptions(int value);
270
271 /**
272  * Enable/Disable Selection based Null pointer check elimination.
273  *
274  * In languages, where all addresses are always Sel nodes, Null
275  * pointers can only occur as input to Sel nodes.
276  * If Null pointers are the only source for exceptions in Load and
277  * Store nodes (as typical in high level languages), we can eliminate
278  * exception edges from Load and Store when can prove that the Sel
279  * nodes representing the Load/Store address have non-null inputs.
280  * Enabling this flag enables this elimination.
281  *
282  * Enabling this flag is meaningless if ldst_non_null_exceptions is
283  * enabled.
284  *
285  * This flags should be set for Java style languages.
286  */
287 void set_opt_sel_based_null_check_elim(int value);
288
289 /**
290  * Enable/Disable Automatic construction of Sync nodes during
291  * Firm construction.
292  *
293  * If this flags is set, sequential non-volatile Loads are automatically
294  * rearranged so that they can be executed in parallel by creating Sync nodes.
295  *
296  * This flags should be set for Java style languages.
297  */
298 void set_opt_auto_create_sync(int value);
299
300 /** Enable/Disable normalizations of the firm representation.
301  *
302  *  This flag guards transformations that normalize the Firm representation
303  *  as removing Ids and Tuples, useless Phis, replacing SymConst(id) by
304  *  Const(entity) and others.
305  *  The transformations guarded by this flag are not guarded by flag
306  *  "optimize".
307  *  Many algorithms operating on Firm can not deal with constructs in
308  *  the non-normalized representation.
309  *  default: ON
310  *
311  *  @note ATTENTION: not all such transformations are guarded by a flag.
312  */
313 void set_opt_normalize (int value);
314
315 /** Enable/Disable precise exception context.
316  *
317  * If enabled, all exceptions form a barrier for values, as in the
318  * following example:
319  *
320  * @code
321  * a = 1;
322  * b = 3 / 0;
323  * a = 2;
324  * @endcode
325  *
326  * If precise exception handling is enabled, an exception handler see a == 1,
327  * else it might see a == 2.
328  * Enable this for languages with strict exception order like Java.
329  */
330 void set_opt_precise_exc_context(int value);
331
332 /** Enable/Disable Alias analysis.
333  *
334  * If enabled, memory disambiguation by alias analysis is used.
335  */
336 void set_opt_alias_analysis(int value);
337
338 /** Enable/Disable closed world assumption.
339  *
340  * If enabled, optimizations expect to know the "whole world", i.e. no
341  * external types or callers exist.
342  * This enables some powerful optimizations.
343  */
344 void set_opt_closed_world(int value);
345
346 /**
347  * Save the current optimization state.
348  */
349 void save_optimization_state(optimization_state_t *state);
350
351 /**
352  * Restore the current optimization state.
353  */
354 void restore_optimization_state(const optimization_state_t *state);
355
356 /**
357  * Switches ALL optimizations off.
358  */
359 void all_optimizations_off(void);
360
361 /**
362  * Possible verification modes.
363  */
364 typedef enum _firm_verification_t {
365   FIRM_VERIFICATION_OFF        = 0,     /**< do not verify nodes at all */
366   FIRM_VERIFICATION_ON         = 1,     /**< do node verification and assert on error in debug version */
367   FIRM_VERIFICATION_REPORT     = 2,     /**< do node verification, but report to stderr only */
368   FIRM_VERIFICATION_ERROR_ONLY = 3      /**< do node verification, but NEVER do assert nor report */
369 } firm_verification_t;
370
371 /** Select verification of IR nodes and types.
372  *
373  *  Per default the  verification is in mode NODE_VERIFICATION_ASSERT.
374  *  Turn the verification off during development to check partial implementations.
375  */
376 void do_node_verification(firm_verification_t mode);
377
378 #endif /* _FIRM_IR_IRFLAG_H_ */