2356b25a2bf71f3cb4c96a782b87832271104df7
[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  * @brief
25  * Flags to customize the behavior of libfirm.
26  *
27  * There are the following groups of flags:
28  * 1. Optimization flags.
29  *    a)  There is a flag, 'optimize' to turn on/off all optimizations.
30  *    b)  There are flags for each individual optimization.  Some flags turns
31  *        transformations in several algorithms on/off.
32  * 2. Normalization flags.
33  *    These flags steer transformations of the ir that improve it, as removing
34  *    dump Phi nodes (one predecessor, all predecessors are equal ...), Ids, Tuples ...
35  * 3. Verbosity flags.
36  *    a) Flags to steer the level of the information.
37  *    b) Flags to steer in which phase information should be dumped.
38  * 4. Verification flag
39  *    This one controls the behavior of node and type verifications
40  */
41 #ifndef FIRM_IR_IRFLAG_H
42 #define FIRM_IR_IRFLAG_H
43
44 #include "firm_types.h"
45 #include "begin.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 FIRM_API void set_optimize(int value);
59 FIRM_API 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 FIRM_API 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 FIRM_API 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 FIRM_API void set_opt_cse(int value);
84
85 /** Returns constant folding optimization setting. */
86 FIRM_API 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 FIRM_API void set_opt_global_cse(int value);
98
99 /** Enable/Disable optimization of dynamic method dispatch.
100  *
101  * This flag enables/disables the optimization of dynamic method dispatch.
102  * If the flag is turned on Sel nodes can be replaced by Const nodes representing
103  * the address of a function.
104  */
105 FIRM_API void set_opt_dyn_meth_dispatch(int value);
106 FIRM_API int get_opt_dyn_meth_dispatch(void);
107
108 /** Restricts the behavior of cast optimization.
109  *
110  *  If set, downcast are not optimized if they might be
111  *  illegal as in (Super)(Sub) (new Super()).  Default:
112  *  0 == not suppressed.
113  */
114 FIRM_API void set_opt_suppress_downcast_optimization(int value);
115 FIRM_API int get_opt_suppress_downcast_optimization(void);
116
117 /**
118  * Enable/Disable Null exception in Load and Store nodes only.
119  *
120  * If enabled, only Null pointer exception can occur at Load and
121  * store nodes. If it can be proved that the address input of these
122  * nodes is non-null, the exception edge can safely be removed.
123  * If disabled, other exceptions (like unaligned access, read-only memory,
124  * etc.) can occur.
125  *
126  * This flag is enabled by default.
127  */
128 FIRM_API void set_opt_ldst_only_null_ptr_exceptions(int value);
129
130 /**
131  * Enable/Disable Selection based Null pointer check elimination.
132  *
133  * In languages, where all addresses are always Sel nodes, Null
134  * pointers can only occur as input to Sel nodes.
135  * If Null pointers are the only source for exceptions in Load and
136  * Store nodes (as typical in high level languages), we can eliminate
137  * exception edges from Load and Store when can prove that the Sel
138  * nodes representing the Load/Store address have non-null inputs.
139  * Enabling this flag enables this elimination.
140  *
141  * Enabling this flag is meaningless if ldst_non_null_exceptions is
142  * enabled.
143  *
144  * This flag should be set for Java style languages.
145  */
146 FIRM_API void set_opt_sel_based_null_check_elim(int value);
147
148 /**
149  * Enable/Disable Global Null Pointer Test Elimination.
150  *
151  * In languages where it is illegal to dereference NULL pointer, doing
152  * so makes the pointer "valid non-null", else the program will stop
153  * anyway by a fault.
154  *
155  * This flag should be set for C style languages.
156  */
157 FIRM_API void set_opt_global_null_ptr_elimination(int value);
158
159 /**
160  * Enable/Disable Automatic construction of Sync nodes during
161  * Firm construction.
162  *
163  * If this flags is set, sequential non-volatile Loads are automatically
164  * rearranged so that they can be executed in parallel by creating Sync nodes.
165  *
166  * This flag should be set for Java style languages.
167  */
168 FIRM_API void set_opt_auto_create_sync(int value);
169
170 /** Enable/Disable Alias analysis.
171  *
172  * If enabled, memory disambiguation by alias analysis is used.
173  */
174 FIRM_API void set_opt_alias_analysis(int value);
175
176 /** Enable/Disable closed world assumption.
177  *
178  * If enabled, optimizations expect to know the "whole world", i.e. no
179  * external types or callers exist.
180  * This enables some powerful optimizations.
181  */
182 FIRM_API void set_opt_closed_world(int value);
183
184 /**
185  * Save the current optimization state.
186  */
187 FIRM_API void save_optimization_state(optimization_state_t *state);
188
189 /**
190  * Restore the current optimization state.
191  */
192 FIRM_API void restore_optimization_state(const optimization_state_t *state);
193
194 /**
195  * Switches ALL optimizations off.
196  */
197 FIRM_API void all_optimizations_off(void);
198
199 /**
200  * Possible verification modes.
201  */
202 typedef enum firm_verification_t {
203   FIRM_VERIFICATION_OFF        = 0, /**< do not verify nodes at all */
204   FIRM_VERIFICATION_ON         = 1, /**< do node verification and assert on error in debug version */
205   FIRM_VERIFICATION_REPORT     = 2, /**< do node verification, but report to stderr only */
206   FIRM_VERIFICATION_ERROR_ONLY = 3  /**< do node verification, but NEVER do assert nor report */
207 } firm_verification_t;
208
209 /**
210  * Select verification of IR nodes and types.
211  *
212  * Per default the  verification is in mode NODE_VERIFICATION_ASSERT.
213  * Turn the verification off during development to check partial
214  * implementations.
215  */
216 FIRM_API void do_node_verification(firm_verification_t mode);
217
218 #include "end.h"
219
220 #endif