2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Flags to control optimizations.
9 * @author Christian Schaefer, Goetz Lindenmaier, Michael Beck
11 #ifndef FIRM_IR_IRFLAG_H
12 #define FIRM_IR_IRFLAG_H
14 #include "firm_types.h"
19 * @defgroup Optimization Flags
20 * Flags to customize the behavior of libfirm.
22 * There are the following groups of flags:
23 * -# Optimization flags.
24 * -# There is a flag, 'optimize' to turn on/off all optimizations.
25 * -# There are flags for each individual optimization. Some flags turns
26 * transformations in several algorithms on/off.
27 * -# Normalization flags.
28 * These flags steer transformations of the ir that improve it, as removing
29 * dump Phi nodes (one predecessor, all predecessors are equal ...), Ids, Tuples ...
31 * -# Flags to steer the level of the information.
32 * -# Flags to steer in which phase information should be dumped.
37 * A container type to load/restore all optimizations
39 typedef unsigned optimization_state_t;
42 * This function enables/disables optimizations globally.
44 * If optimize == 0 no optimizations are performed at all.
45 * Default: optimize == 1.
47 FIRM_API void set_optimize(int value);
48 /** Returns global optimizations flag.
49 * @see set_optimize() */
50 FIRM_API int get_optimize(void);
52 /** Enables/Disables constant folding optimization.
54 * If opt_constant_folding == 1 perform
55 * constant expression evaluation (2 + 5 ==> 7, 3 < 2 ==> false)
56 * Default: opt_constant_folding == 1.
58 FIRM_API void set_opt_constant_folding(int value);
59 /** returns 0 if constant_folding is disabled, !=0 otherwise */
60 FIRM_API int get_opt_constant_folding(void);
62 /** Enables/Disables algebraic simplifications.
64 * If opt_algebraic_simplification == 1 perform
65 * - algebraic simplification (a * 0 ==> 0, a or a ==> a)
66 * - simplification of tests ( !(a < b) ==> (a >= b))
67 * Default: opt_algebraic_simplification == 1.
69 FIRM_API void set_opt_algebraic_simplification(int value);
71 /** Enables/Disables common subexpression elimination.
73 * If opt_cse == 1 perform common subexpression elimination.
74 * Default: opt_cse == 1.
76 FIRM_API void set_opt_cse(int value);
78 /** Returns constant folding optimization setting. */
79 FIRM_API int get_opt_cse(void);
81 /** Enables/Disables global constant subexpression elimination.
83 * If opt_global_cse == 1 and opt_cse == 1 perform intra procedure
84 * constant subexpression elimination for floating nodes. Intra
85 * procedure cse gets the graph into state "floating". It is necessary
86 * to run pre/code motion to get the graph back into state "op_pin_state_pinned".
87 * right after a call to local_optimize with global cse turned on.
88 * Default: opt_global_cse == 0.
90 FIRM_API void set_opt_global_cse(int value);
93 * Enable/Disable Global Null Pointer Test Elimination.
95 * In languages where it is illegal to dereference NULL pointer, doing
96 * so makes the pointer "valid non-null", else the program will stop
99 * This flag should be set for C style languages.
101 FIRM_API void set_opt_global_null_ptr_elimination(int value);
104 * Enable/Disable Automatic construction of Sync nodes during
107 * If this flags is set, sequential non-volatile Loads are automatically
108 * rearranged so that they can be executed in parallel by creating Sync nodes.
110 * This flag should be set for Java style languages.
112 FIRM_API void set_opt_auto_create_sync(int value);
114 /** Enable/Disable Alias analysis.
116 * If enabled, memory disambiguation by alias analysis is used.
118 FIRM_API void set_opt_alias_analysis(int value);
120 /** Enable/Disable closed world assumption.
122 * If enabled, optimizations expect to know the "whole world", i.e. no
123 * external types or callers exist.
124 * This enables some powerful optimizations.
126 FIRM_API void set_opt_closed_world(int value);
129 * Save the current optimization state.
131 FIRM_API void save_optimization_state(optimization_state_t *state);
134 * Restore the current optimization state.
136 FIRM_API void restore_optimization_state(const optimization_state_t *state);
139 * Switches ALL optimizations off.
141 FIRM_API void all_optimizations_off(void);
145 /** @ingroup irverify
146 * @defgroup irverify_flags Flags
147 * Enable/Disable automatic correctness tests
152 * Possible verification modes.
154 typedef enum firm_verification_t {
155 FIRM_VERIFICATION_OFF = 0, /**< do not verify nodes at all */
156 FIRM_VERIFICATION_ON = 1, /**< do node verification and assert on error in debug version */
157 FIRM_VERIFICATION_REPORT = 2, /**< do node verification, but report to stderr only */
158 FIRM_VERIFICATION_ERROR_ONLY = 3 /**< do node verification, but NEVER do assert nor report */
159 } firm_verification_t;
162 * Select verification of IR nodes and types.
164 * Per default the verification is in mode NODE_VERIFICATION_ASSERT.
165 * Turn the verification off during development to check partial
168 FIRM_API void do_node_verification(firm_verification_t mode);