Merge branch 'opt_manage'
[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  * @brief
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 #include "begin.h"
47
48 /**
49  * A container type to load/restore all optimizations
50  */
51 typedef unsigned optimization_state_t;
52
53 /**
54  * This function enables/disables optimizations globally.
55  *
56  * If optimize == 0 no optimizations are performed at all.
57  * Default: optimize == 1.
58  */
59 FIRM_API void set_optimize(int value);
60 FIRM_API int get_optimize(void);
61
62 /** Enables/Disables constant folding optimization.
63  *
64  *  If opt_constant_folding == 1 perform
65  *  constant expression evaluation (2 + 5 ==> 7, 3 < 2 ==> false)
66  * Default: opt_constant_folding == 1.
67  */
68 FIRM_API void set_opt_constant_folding(int value);
69
70 /** Enables/Disables algebraic simplifications.
71  *
72  *  If opt_algebraic_simplification == 1 perform
73  *  - algebraic simplification  (a * 0 ==> 0, a or a ==> a)
74  *  - simplification of tests   ( !(a < b) ==> (a >= b))
75  * Default: opt_algebraic_simplification == 1.
76  */
77 FIRM_API void set_opt_algebraic_simplification(int value);
78
79 /** Enables/Disables common subexpression elimination.
80  *
81  * If opt_cse == 1 perform common subexpression elimination.
82  * Default: opt_cse == 1.
83  */
84 FIRM_API void set_opt_cse(int value);
85
86 /** Returns constant folding optimization setting. */
87 FIRM_API int get_opt_cse(void);
88
89 /** Enables/Disables global constant subexpression elimination.
90  *
91  * If opt_global_cse == 1 and opt_cse == 1 perform intra procedure
92  * constant subexpression elimination for floating nodes.  Intra
93  * procedure cse gets the graph into state "floating".  It is necessary
94  * to run pre/code motion to get the graph back into state "op_pin_state_pinned".
95  * right after a call to local_optimize with global cse turned on.
96  * Default: opt_global_cse == 0.
97  */
98 FIRM_API void set_opt_global_cse(int value);
99
100 /** Enables/Disables unreachable code elimination.
101  *
102  * If set, evaluate conditions of conditional branch and replace the
103  * branch with a Jmp/Bad Tuple.
104  *
105  * If opt_unreachable_code == 1 replace nodes (except Block,
106  * Phi and Tuple) with a Bad predecessor by the Bad node.
107  * Default: opt_unreachable_code == 1.
108  */
109 FIRM_API void set_opt_unreachable_code(int value);
110
111 /** Enable/Disable optimization of dynamic method dispatch.
112  *
113  * This flag enables/disables the optimization of dynamic method dispatch.
114  * If the flag is turned on Sel nodes can be replaced by Const nodes representing
115  * the address of a function.
116  */
117 FIRM_API void set_opt_dyn_meth_dispatch(int value);
118 FIRM_API int get_opt_dyn_meth_dispatch(void);
119
120 /** Restricts the behavior of cast optimization.
121  *
122  *  If set, downcast are not optimized if they might be
123  *  illegal as in (Super)(Sub) (new Super()).  Default:
124  *  0 == not suppressed.
125  */
126 FIRM_API void set_opt_suppress_downcast_optimization(int value);
127 FIRM_API int get_opt_suppress_downcast_optimization(void);
128
129 /**
130  * Enable/Disable Null exception in Load and Store nodes only.
131  *
132  * If enabled, only Null pointer exception can occur at Load and
133  * store nodes. If it can be proved that the address input of these
134  * nodes is non-null, the exception edge can safely be removed.
135  * If disabled, other exceptions (like unaligned access, read-only memory,
136  * etc.) can occur.
137  *
138  * This flag is enabled by default.
139  */
140 FIRM_API void set_opt_ldst_only_null_ptr_exceptions(int value);
141
142 /**
143  * Enable/Disable Selection based Null pointer check elimination.
144  *
145  * In languages, where all addresses are always Sel nodes, Null
146  * pointers can only occur as input to Sel nodes.
147  * If Null pointers are the only source for exceptions in Load and
148  * Store nodes (as typical in high level languages), we can eliminate
149  * exception edges from Load and Store when can prove that the Sel
150  * nodes representing the Load/Store address have non-null inputs.
151  * Enabling this flag enables this elimination.
152  *
153  * Enabling this flag is meaningless if ldst_non_null_exceptions is
154  * enabled.
155  *
156  * This flag should be set for Java style languages.
157  */
158 FIRM_API void set_opt_sel_based_null_check_elim(int value);
159
160 /**
161  * Enable/Disable Global Null Pointer Test Elimination.
162  *
163  * In languages where it is illegal to dereference NULL pointer, doing
164  * so makes the pointer "valid non-null", else the program will stop
165  * anyway by a fault.
166  *
167  * This flag should be set for C style languages.
168  */
169 FIRM_API void set_opt_global_null_ptr_elimination(int value);
170
171 /**
172  * Enable/Disable Automatic construction of Sync nodes during
173  * Firm construction.
174  *
175  * If this flags is set, sequential non-volatile Loads are automatically
176  * rearranged so that they can be executed in parallel by creating Sync nodes.
177  *
178  * This flag should be set for Java style languages.
179  */
180 FIRM_API void set_opt_auto_create_sync(int value);
181
182 /** Enable/Disable Alias analysis.
183  *
184  * If enabled, memory disambiguation by alias analysis is used.
185  */
186 FIRM_API void set_opt_alias_analysis(int value);
187
188 /** Enable/Disable closed world assumption.
189  *
190  * If enabled, optimizations expect to know the "whole world", i.e. no
191  * external types or callers exist.
192  * This enables some powerful optimizations.
193  */
194 FIRM_API void set_opt_closed_world(int value);
195
196 /**
197  * Save the current optimization state.
198  */
199 FIRM_API void save_optimization_state(optimization_state_t *state);
200
201 /**
202  * Restore the current optimization state.
203  */
204 FIRM_API void restore_optimization_state(const optimization_state_t *state);
205
206 /**
207  * Switches ALL optimizations off.
208  */
209 FIRM_API void all_optimizations_off(void);
210
211 /**
212  * Possible verification modes.
213  */
214 typedef enum firm_verification_t {
215   FIRM_VERIFICATION_OFF        = 0, /**< do not verify nodes at all */
216   FIRM_VERIFICATION_ON         = 1, /**< do node verification and assert on error in debug version */
217   FIRM_VERIFICATION_REPORT     = 2, /**< do node verification, but report to stderr only */
218   FIRM_VERIFICATION_ERROR_ONLY = 3  /**< do node verification, but NEVER do assert nor report */
219 } firm_verification_t;
220
221 /** Select verification of IR nodes and types.
222  *
223  *  Per default the  verification is in mode NODE_VERIFICATION_ASSERT.
224  *  Turn the verification off during development to check partial implementations.
225  */
226 FIRM_API void do_node_verification(firm_verification_t mode);
227
228 #include "end.h"
229
230 #endif