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