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
34 #include "firm_common.h"
38 /* DISABLE - don't do this optimization
39 ENABLE - lets see, if there is a better graph */
43 #define FLAG(name, value, def) (irf_##name & def) |
44 #define E_FLAG(name, value, def) FLAG(name, value, def)
45 #define I_FLAG(name, value, def) FLAG(name, value, def)
46 #define R_FLAG(name, value)
48 optimization_state_t libFIRM_opt =
49 #include "irflag_t.def"
57 /** The bitset of currently running phases. */
58 optimization_state_t libFIRM_running = 0;
60 /* verbose is always off on default */
61 optimization_state_t libFIRM_verb = 0;
63 /** The Firm verbosity level */
64 int firm_verbosity_level;
66 /* an external flag can be set and get from outside */
67 #define E_FLAG(name, value, def) \
68 void set_opt_##name(int flag) { \
69 if (flag) libFIRM_opt |= irf_##name; \
70 else libFIRM_opt &= ~irf_##name; \
72 void set_opt_##name##_verbose(int flag) { \
73 if (flag) libFIRM_verb |= irf_##name; \
74 else libFIRM_verb &= ~irf_##name; \
76 int (get_opt_##name)(void) { \
77 return _get_opt_##name(); \
80 /* an internal flag can only be set from outside */
81 #define I_FLAG(name, value, def) \
82 void set_opt_##name(int flag) { \
83 if (flag) libFIRM_opt |= irf_##name; \
84 else libFIRM_opt &= ~irf_##name; \
86 void set_opt_##name##_verbose(int flag) { \
87 if (flag) libFIRM_verb |= irf_##name; \
88 else libFIRM_verb &= ~irf_##name; \
91 #define R_FLAG(name, value)
94 #include "irflag_t.def"
100 /* for compatibility reasons */
101 void set_optimize(int value) {
102 if (value) libFIRM_opt |= irf_optimize;
103 else libFIRM_opt &= ~irf_optimize;
106 int (get_optimize)(void) {
107 return get_opt_optimize();
110 void set_opt_control_flow(int value) {
111 set_opt_control_flow_straightening(value);
112 set_opt_control_flow_weak_simplification(value);
113 set_opt_control_flow_strong_simplification(value);
116 void set_firm_verbosity (int value) {
117 firm_verbosity_level = value;
120 int (get_firm_verbosity) (void) {
121 return _get_firm_verbosity();
124 /* Save the current optimization state. */
125 void save_optimization_state(optimization_state_t *state) {
126 *state = libFIRM_opt;
129 /* Restore the current optimization state. */
130 void restore_optimization_state(const optimization_state_t *state) {
131 libFIRM_opt = *state;
134 /* Switches ALL optimizations off */
135 void all_optimizations_off(void) {
140 /* only for debugging */
141 void firm_show_flags(FILE *f) {
144 printf("Firm optimization state:\n");
145 #define E_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
146 #define I_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
147 #define R_FLAG(name, value) printf(" %-20s = %s\n", #name, is_##name##_running() ? "is running" : "not running");
148 #include "irflag_t.def"
156 static const lc_opt_table_entry_t firm_flags[] = {
157 #define I_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
158 #define E_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
159 #define R_FLAG(name, val)
160 #include "irflag_t.def"
167 void firm_init_flags(void) {
168 lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
169 lc_opt_add_table(grp, firm_flags);
172 firm_verification_t opt_do_node_verification = FIRM_VERIFICATION_ON;
174 void do_node_verification(firm_verification_t mode) {
175 opt_do_node_verification = mode;