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);
97 set_opt_critical_edges(value);
100 void set_firm_verbosity (int value) {
101 firm_verbosity_level = value;
104 int (get_firm_verbosity) (void) {
105 return _get_firm_verbosity();
108 /* Save the current optimization state. */
109 void save_optimization_state(optimization_state_t *state)
111 *state = libFIRM_opt;
114 /* Restore the current optimization state. */
115 void restore_optimization_state(const optimization_state_t *state)
117 libFIRM_opt = *state;
120 /* Switches ALL optimizations off */
121 void all_optimizations_off(void)
127 /* only for debugging */
128 void firm_show_flags(FILE *f) {
131 printf("Firm optimization state:\n");
132 #define E_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
133 #define I_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
134 #include "irflag_t.def"
142 static const lc_opt_table_entry_t firm_flags[] = {
143 #define I_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
144 #define E_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
145 #include "irflag_t.def"
152 void firm_init_flags(void)
155 lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
156 lc_opt_add_table(grp, firm_flags);
160 firm_verification_t opt_do_node_verification = FIRM_VERIFICATION_ON;
162 void do_node_verification(firm_verification_t mode) {
163 opt_do_node_verification = mode;