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 Michael Beck, Sebastian Hack
32 #include "firm_common.h"
36 /* DISABLE - don't do this optimization
37 ENABLE - lets see, if there is a better graph */
41 #define FLAG(name, value, def) (irf_##name & def) |
42 #define E_FLAG(name, value, def) FLAG(name, value, def)
43 #define I_FLAG(name, value, def) FLAG(name, value, def)
44 #define R_FLAG(name, value)
46 optimization_state_t libFIRM_opt =
47 #include "irflag_t.def"
55 /** The bitset of currently running phases. */
56 optimization_state_t libFIRM_running = 0;
58 /* verbose is always off on default */
59 optimization_state_t libFIRM_verb = 0;
61 /* silence warnings */
62 void set_opt_optimize(int value);
63 int get_opt_optimize(void);
65 /* an external flag can be set and get from outside */
66 #define E_FLAG(name, value, def) \
67 void set_opt_##name(int flag) { \
68 if (flag) libFIRM_opt |= irf_##name; \
69 else libFIRM_opt &= ~irf_##name; \
71 int (get_opt_##name)(void) { \
72 return _get_opt_##name(); \
75 /* an internal flag can only be set from outside */
76 #define I_FLAG(name, value, def) \
77 void set_opt_##name(int flag) { \
78 if (flag) libFIRM_opt |= irf_##name; \
79 else libFIRM_opt &= ~irf_##name; \
82 #define R_FLAG(name, value)
85 #include "irflag_t.def"
91 /* for compatibility reasons */
92 void set_optimize(int value)
94 set_opt_optimize(value);
97 int (get_optimize)(void)
99 return get_opt_optimize();
102 void set_opt_control_flow(int value)
104 set_opt_control_flow_straightening(value);
105 set_opt_control_flow_weak_simplification(value);
106 set_opt_control_flow_strong_simplification(value);
109 /* Save the current optimization state. */
110 void save_optimization_state(optimization_state_t *state)
112 *state = libFIRM_opt;
115 /* Restore the current optimization state. */
116 void restore_optimization_state(const optimization_state_t *state)
118 libFIRM_opt = *state;
121 /* Switches ALL optimizations off */
122 void all_optimizations_off(void)
128 /* only for debugging */
129 void firm_show_flags(FILE *f)
133 printf("Firm optimization state:\n");
134 #define E_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
135 #define I_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
136 #define R_FLAG(name, value) printf(" %-20s = %s\n", #name, is_##name##_running() ? "is running" : "not running");
137 #include "irflag_t.def"
145 static const lc_opt_table_entry_t firm_flags[] = {
146 #define I_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
147 #define E_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
148 #define R_FLAG(name, val)
149 #include "irflag_t.def"
156 void firm_init_flags(void)
158 lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
159 lc_opt_add_table(grp, firm_flags);
162 firm_verification_t opt_do_node_verification = FIRM_VERIFICATION_ON;
164 void do_node_verification(firm_verification_t mode)
166 opt_do_node_verification = mode;