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