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.
18 #include <libcore/lc_opts.h>
21 #include "firm_common.h"
25 /* DISABLE - don't do this optimization
26 ENABLE - lets see, if there is a better graph */
30 #define FLAG(name, value, def) (irf_##name & def) |
31 #define E_FLAG(name, value, def) FLAG(name, value, def)
32 #define I_FLAG(name, value, def) FLAG(name, value, def)
34 optimization_state_t libFIRM_opt =
35 #include "irflag_t.def"
43 /* verbose is always off on default */
44 optimization_state_t libFIRM_verb = 0;
46 /** The Firm verbosity level */
47 int firm_verbosity_level;
49 /* an external flag can be set and get from outside */
50 #define E_FLAG(name, value, def) \
51 void set_opt_##name(int flag) { \
52 if (flag) libFIRM_opt |= irf_##name; \
53 else libFIRM_opt &= ~irf_##name; \
55 void set_opt_##name##_verbose(int flag) { \
56 if (flag) libFIRM_verb |= irf_##name; \
57 else libFIRM_verb &= ~irf_##name; \
59 int (get_opt_##name)(void) { \
60 return _get_opt_##name(); \
63 /* an internal flag can only be set from outside */
64 #define I_FLAG(name, value, def) \
65 void set_opt_##name(int flag) { \
66 if (flag) libFIRM_opt |= irf_##name; \
67 else libFIRM_opt &= ~irf_##name; \
69 void set_opt_##name##_verbose(int flag) { \
70 if (flag) libFIRM_verb |= irf_##name; \
71 else libFIRM_verb &= ~irf_##name; \
75 #include "irflag_t.def"
80 /* for compatibility reasons */
81 void set_optimize(int value) {
82 if (value) libFIRM_opt |= irf_optimize;
83 else libFIRM_opt &= ~irf_optimize;
86 int (get_optimize)(void) {
87 return get_opt_optimize();
90 void set_opt_control_flow(int value)
92 set_opt_control_flow_straightening(value);
93 set_opt_control_flow_weak_simplification(value);
94 set_opt_control_flow_strong_simplification(value);
95 set_opt_critical_edges(value);
98 void set_firm_verbosity (int value) {
99 firm_verbosity_level = value;
102 int (get_firm_verbosity) (void) {
103 return _get_firm_verbosity();
106 /* Save the current optimization state. */
107 void save_optimization_state(optimization_state_t *state)
109 *state = libFIRM_opt;
112 /* Restore the current optimization state. */
113 void restore_optimization_state(const optimization_state_t *state)
115 libFIRM_opt = *state;
119 void firm_show_flags(void) {
120 #define E_FLAG(name, value, def) printf(#name " = %s\n", get_opt_##name() ? "ON" : "OFF");
121 #define I_FLAG(name, value, def) printf(#name " = %s\n", get_opt_##name() ? "ON" : "OFF");
122 #include "irflag_t.def"
127 static const lc_opt_table_entry_t firm_flags[] = {
128 #define I_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
129 #define E_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
130 #include "irflag_t.def"
137 void firm_init_flags(void)
140 lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
141 lc_opt_add_table(grp, firm_flags);