2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Flags to control optimizations.
23 * @author Christian Schaefer, Goetz Lindenmaier, Michael Beck
26 * Flags to customize the behavior of libfirm.
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 ...
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
42 #ifndef FIRM_IR_IRFLAG_H
43 #define FIRM_IR_IRFLAG_H
45 #include "firm_types.h"
48 * A container type to load/restore all optimizations
50 typedef unsigned optimization_state_t;
53 * This function enables/disables optimizations globally.
55 * If optimize == 0 no optimizations are performed at all.
56 * Default: optimize == 1.
58 void set_optimize (int value);
59 int get_optimize(void);
61 /** Enables/Disables constant folding optimization.
63 * If opt_constant_folding == 1 perform
64 * - constant expression evaluation (2 + 5 ==> 7, 3 < 2 ==> false)
65 * - algebraic simplification (a * 0 ==> 0, a or a ==> a)
66 * - simplification of tests ( !(a < b) ==> (a >= b))
67 * Default: opt_constant_folding == 1.
69 void set_opt_constant_folding (int value);
71 /** Enables/Disables output of information about loop unrolling.
73 void set_opt_loop_unrolling_verbose (int value);
75 /** Enables/Disables common subexpression elimination.
77 * If opt_cse == 1 perform common subexpression elimination.
78 * Default: opt_cse == 1.
80 void set_opt_cse (int value);
82 /** Returns constant folding optimization setting. */
83 int get_opt_cse(void);
85 /** Enables/Disables global constant subexpression elimination.
87 * If opt_global_cse == 1 and opt_cse == 1 perform intra procedure
88 * constant subexpression elimination for floating nodes. Intra
89 * procedure cse gets the graph into state "floating". It is necessary
90 * to run pre/code motion to get the graph back into state "op_pin_state_pinned".
91 * right after a call to local_optimize with global cse turned on.
92 * Default: opt_global_cse == 0.
94 void set_opt_global_cse (int value);
96 /** Enables/Disables strength reduction.
98 * If opt_strength_red == 1 perform strength reduction.
101 * Default: opt_strength_red = 1;
103 void set_opt_strength_red (int value);
105 /** Enables/Disables output of information about strength reduction.
107 void set_opt_strength_red_verbose (int value);
109 /** Enables/Disables unreachable code elimination.
111 * If set, evaluate conditions of conditional branch and replace the
112 * branch with a Jmp/Bad Tuple.
114 * If opt_unreachable_code == 1 replace nodes (except Block,
115 * Phi and Tuple) with a Bad predecessor by the Bad node.
116 * Default: opt_unreachable_code == 1.
118 void set_opt_unreachable_code(int value);
120 /** Enables/Disables control flow optimizations.
122 * Performs Straightening, if simplifications and loop simplifications.
123 * Sets all separate control flow flags (control_flow_straightening,
124 * weak_simplification, strong_simplification and critical_edges).
126 void set_opt_control_flow(int value);
128 /** Enables/Disables Straightening. */
129 void set_opt_control_flow_straightening(int value);
131 /** Enables/Disables if simplifications in local optimizations. */
132 void set_opt_control_flow_weak_simplification(int value);
134 /** Enables/Disables strong if and loop simplification (in optimize_cf). */
135 void set_opt_control_flow_strong_simplification(int value);
138 * Enables/Disable overflow unsafe transformations (default off).
139 * If enabled, SubIu(x, 1) might be transformed into AddIu(x, 0xFFFFFFFF).
140 * While enabling generates better code, it invalidates strength reduction
141 * of linear-function-test-replacement.
142 * So, if strength reduction is used, enable it AFTER strength reduction runs.
144 void set_opt_overflow_unsafe_transform(int value);
146 /** Enable/Disable optimization of dynamic method dispatch.
148 * This flag enables/disables the optimization of dynamic method dispatch.
149 * If the flag is turned on Sel nodes can be replaced by Const nodes representing
150 * the address of a function.
152 void set_opt_dyn_meth_dispatch (int value);
153 int get_opt_dyn_meth_dispatch (void);
155 /** Enable/Disable type optimization of cast nodes.
157 * Controls the optimizations in tropt.h. Default: on.
159 void set_opt_optimize_class_casts (int value);
160 void set_opt_optimize_class_casts_verbose (int value);
162 /** Restricts the behavior of cast optimization.
164 * If set, downcast are not optimized if they might be
165 * illegal as in (Super)(Sub) (new Super()). Default:
166 * 0 == not suppressed.
168 void set_opt_suppress_downcast_optimization(int value);
169 int get_opt_suppress_downcast_optimization(void);
171 /** Enable/Disable floating of fragile ops.
173 * This flags enables/disables the floating of fragile operations.
174 * If this flag is on, fragile operations which are known to NOT raise
175 * an exception can be place to other basic blocks.
176 * Otherwise they remain in the block they were created.
178 void set_opt_fragile_ops(int value);
181 * Enable/Disable Confirm node removal during local optimization.
183 void set_opt_remove_confirm(int value);
186 * Enable/Disable scalar replacement optimization.
188 void set_opt_scalar_replacement(int value);
189 void set_opt_scalar_replacement_verbose(int value);
192 * Enable/Disable Null exception in Load and Store nodes only.
194 * If enabled, only Null pointer exception can occur at Load and
195 * store nodes. If it can be proved that the address input of these
196 * nodes is non-null, the exception edge can safely be removed.
197 * If disabled, other exceptions (like unaligned access, read-only memory,
200 * This flag is enabled by default.
202 void set_opt_ldst_only_null_ptr_exceptions(int value);
205 * Enable/Disable Selection based Null pointer check elimination.
207 * In languages, where all addresses are always Sel nodes, Null
208 * pointers can only occur as input to Sel nodes.
209 * If Null pointers are the only source for exceptions in Load and
210 * Store nodes (as typical in high level languages), we can eliminate
211 * exception edges from Load and Store when can prove that the Sel
212 * nodes representing the Load/Store address have non-null inputs.
213 * Enabling this flag enables this elimination.
215 * Enabling this flag is meaningless if ldst_non_null_exceptions is
218 * This flags should be set for Java style languages.
220 void set_opt_sel_based_null_check_elim(int value);
223 * Enable/Disable Automatic construction of Sync nodes during
226 * If this flags is set, sequential non-volatile Loads are automatically
227 * rearranged so that they can be executed in parallel by creating Sync nodes.
229 * This flags should be set for Java style languages.
231 void set_opt_auto_create_sync(int value);
233 /** Enable/Disable normalizations of the firm representation.
235 * This flag guards transformations that normalize the Firm representation
236 * as removing Ids and Tuples, useless Phis, replacing SymConst(id) by
237 * Const(entity) and others.
238 * The transformations guarded by this flag are not guarded by flag
240 * Many algorithms operating on Firm can not deal with constructs in
241 * the non-normalized representation.
244 * @note ATTENTION: not all such transformations are guarded by a flag.
246 void set_opt_normalize (int value);
248 /** Enable/Disable precise exception context.
250 * If enabled, all exceptions form a barrier for values, as in the
259 * If precise exception handling is enabled, an exception handler see a == 1,
260 * else it might see a == 2.
261 * Enable this for languages with strict exception order like Java.
263 void set_opt_precise_exc_context(int value);
265 /** Enable/Disable Alias analysis.
267 * If enabled, memory disambiguation by alias analysis is used.
269 void set_opt_alias_analysis(int value);
271 /** Enable/Disable closed world assumption.
273 * If enabled, optimizations expect to know the "whole world", i.e. no
274 * external types or callers exist.
275 * This enables some powerful optimizations.
277 void set_opt_closed_world(int value);
280 * Save the current optimization state.
282 void save_optimization_state(optimization_state_t *state);
285 * Restore the current optimization state.
287 void restore_optimization_state(const optimization_state_t *state);
290 * Switches ALL optimizations off.
292 void all_optimizations_off(void);
295 * Possible verification modes.
297 typedef enum _firm_verification_t {
298 FIRM_VERIFICATION_OFF = 0, /**< do not verify nodes at all */
299 FIRM_VERIFICATION_ON = 1, /**< do node verification and assert on error in debug version */
300 FIRM_VERIFICATION_REPORT = 2, /**< do node verification, but report to stderr only */
301 FIRM_VERIFICATION_ERROR_ONLY = 3 /**< do node verification, but NEVER do assert nor report */
302 } firm_verification_t;
304 /** Select verification of IR nodes and types.
306 * Per default the verification is in mode NODE_VERIFICATION_ASSERT.
307 * Turn the verification off during development to check partial implementations.
309 void do_node_verification(firm_verification_t mode);