3 * File name: ir/ir/irflag.c
4 * Purpose: Flags to control optimizations.
5 * Author: Christian Schaefer, Goetz Lindenmaier
9 * Copyright: (c) 1999-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
20 #include <libcore/lc_opts.h>
23 #include "firm_common.h"
27 /* DISABLE - don't do this optimization
28 ENABLE - lets see, if there is a better graph */
32 #define FLAG(name, value, def) (irf_##name & def) |
33 #define E_FLAG(name, value, def) FLAG(name, value, def)
34 #define I_FLAG(name, value, def) FLAG(name, value, def)
36 optimization_state_t libFIRM_opt =
37 #include "irflag_t.def"
45 /* verbose is always off on default */
46 optimization_state_t libFIRM_verb = 0;
48 /** The Firm verbosity level */
49 int firm_verbosity_level;
51 /* an external flag can be set and get from outside */
52 #define E_FLAG(name, value, def) \
53 void set_opt_##name(int flag) { \
54 if (flag) libFIRM_opt |= irf_##name; \
55 else libFIRM_opt &= ~irf_##name; \
57 void set_opt_##name##_verbose(int flag) { \
58 if (flag) libFIRM_verb |= irf_##name; \
59 else libFIRM_verb &= ~irf_##name; \
61 int (get_opt_##name)(void) { \
62 return _get_opt_##name(); \
65 /* an internal flag can only be set from outside */
66 #define I_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 void set_opt_##name##_verbose(int flag) { \
72 if (flag) libFIRM_verb |= irf_##name; \
73 else libFIRM_verb &= ~irf_##name; \
77 #include "irflag_t.def"
82 /* for compatibility reasons */
83 void set_optimize(int value) {
84 if (value) libFIRM_opt |= irf_optimize;
85 else libFIRM_opt &= ~irf_optimize;
88 int (get_optimize)(void) {
89 return get_opt_optimize();
92 void set_opt_control_flow(int value)
94 set_opt_control_flow_straightening(value);
95 set_opt_control_flow_weak_simplification(value);
96 set_opt_control_flow_strong_simplification(value);
99 void set_firm_verbosity (int value) {
100 firm_verbosity_level = value;
103 int (get_firm_verbosity) (void) {
104 return _get_firm_verbosity();
107 /* Save the current optimization state. */
108 void save_optimization_state(optimization_state_t *state)
110 *state = libFIRM_opt;
113 /* Restore the current optimization state. */
114 void restore_optimization_state(const optimization_state_t *state)
116 libFIRM_opt = *state;
119 /* Switches ALL optimizations off */
120 void all_optimizations_off(void)
126 /* only for debugging */
127 void firm_show_flags(FILE *f) {
130 printf("Firm optimization state:\n");
131 #define E_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
132 #define I_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
133 #include "irflag_t.def"
141 static const lc_opt_table_entry_t firm_flags[] = {
142 #define I_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
143 #define E_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
144 #include "irflag_t.def"
151 void firm_init_flags(void)
154 lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
155 lc_opt_add_table(grp, firm_flags);
159 firm_verification_t opt_do_node_verification = FIRM_VERIFICATION_ON;
161 void do_node_verification(firm_verification_t mode) {
162 opt_do_node_verification = mode;