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
25 #ifndef FIRM_IR_IRFLAG_H
26 #define FIRM_IR_IRFLAG_H
28 #include "firm_types.h"
33 * @defgroup Optimization Flags
34 * Flags to customize the behavior of libfirm.
36 * There are the following groups of flags:
37 * -# Optimization flags.
38 * -# There is a flag, 'optimize' to turn on/off all optimizations.
39 * -# There are flags for each individual optimization. Some flags turns
40 * transformations in several algorithms on/off.
41 * -# Normalization flags.
42 * These flags steer transformations of the ir that improve it, as removing
43 * dump Phi nodes (one predecessor, all predecessors are equal ...), Ids, Tuples ...
45 * -# Flags to steer the level of the information.
46 * -# Flags to steer in which phase information should be dumped.
51 * A container type to load/restore all optimizations
53 typedef unsigned optimization_state_t;
56 * This function enables/disables optimizations globally.
58 * If optimize == 0 no optimizations are performed at all.
59 * Default: optimize == 1.
61 FIRM_API void set_optimize(int value);
62 /** Returns global optimizations flag.
63 * @see set_optimize() */
64 FIRM_API int get_optimize(void);
66 /** Enables/Disables constant folding optimization.
68 * If opt_constant_folding == 1 perform
69 * constant expression evaluation (2 + 5 ==> 7, 3 < 2 ==> false)
70 * Default: opt_constant_folding == 1.
72 FIRM_API void set_opt_constant_folding(int value);
74 /** Enables/Disables algebraic simplifications.
76 * If opt_algebraic_simplification == 1 perform
77 * - algebraic simplification (a * 0 ==> 0, a or a ==> a)
78 * - simplification of tests ( !(a < b) ==> (a >= b))
79 * Default: opt_algebraic_simplification == 1.
81 FIRM_API void set_opt_algebraic_simplification(int value);
83 /** Enables/Disables common subexpression elimination.
85 * If opt_cse == 1 perform common subexpression elimination.
86 * Default: opt_cse == 1.
88 FIRM_API void set_opt_cse(int value);
90 /** Returns constant folding optimization setting. */
91 FIRM_API int get_opt_cse(void);
93 /** Enables/Disables global constant subexpression elimination.
95 * If opt_global_cse == 1 and opt_cse == 1 perform intra procedure
96 * constant subexpression elimination for floating nodes. Intra
97 * procedure cse gets the graph into state "floating". It is necessary
98 * to run pre/code motion to get the graph back into state "op_pin_state_pinned".
99 * right after a call to local_optimize with global cse turned on.
100 * Default: opt_global_cse == 0.
102 FIRM_API void set_opt_global_cse(int value);
104 /** Restricts the behavior of cast optimization.
106 * If set, downcast are not optimized if they might be
107 * illegal as in (Super)(Sub) (new Super()). Default:
108 * 0 == not suppressed.
110 FIRM_API void set_opt_suppress_downcast_optimization(int value);
111 /** Returns suppred_downcast flag.
112 * @see set_opt_suppress_downcast_optimization() */
113 FIRM_API int get_opt_suppress_downcast_optimization(void);
116 * Enable/Disable Global Null Pointer Test Elimination.
118 * In languages where it is illegal to dereference NULL pointer, doing
119 * so makes the pointer "valid non-null", else the program will stop
122 * This flag should be set for C style languages.
124 FIRM_API void set_opt_global_null_ptr_elimination(int value);
127 * Enable/Disable Automatic construction of Sync nodes during
130 * If this flags is set, sequential non-volatile Loads are automatically
131 * rearranged so that they can be executed in parallel by creating Sync nodes.
133 * This flag should be set for Java style languages.
135 FIRM_API void set_opt_auto_create_sync(int value);
137 /** Enable/Disable Alias analysis.
139 * If enabled, memory disambiguation by alias analysis is used.
141 FIRM_API void set_opt_alias_analysis(int value);
143 /** Enable/Disable closed world assumption.
145 * If enabled, optimizations expect to know the "whole world", i.e. no
146 * external types or callers exist.
147 * This enables some powerful optimizations.
149 FIRM_API void set_opt_closed_world(int value);
152 * Save the current optimization state.
154 FIRM_API void save_optimization_state(optimization_state_t *state);
157 * Restore the current optimization state.
159 FIRM_API void restore_optimization_state(const optimization_state_t *state);
162 * Switches ALL optimizations off.
164 FIRM_API void all_optimizations_off(void);
168 /** @ingroup irverify
169 * @defgroup irverify_flags Flags
170 * Enable/Disable automatic correctness tests
175 * Possible verification modes.
177 typedef enum firm_verification_t {
178 FIRM_VERIFICATION_OFF = 0, /**< do not verify nodes at all */
179 FIRM_VERIFICATION_ON = 1, /**< do node verification and assert on error in debug version */
180 FIRM_VERIFICATION_REPORT = 2, /**< do node verification, but report to stderr only */
181 FIRM_VERIFICATION_ERROR_ONLY = 3 /**< do node verification, but NEVER do assert nor report */
182 } firm_verification_t;
185 * Select verification of IR nodes and types.
187 * Per default the verification is in mode NODE_VERIFICATION_ASSERT.
188 * Turn the verification off during development to check partial
191 FIRM_API void do_node_verification(firm_verification_t mode);