6a656d39625ace2c463cbe9bb9934ad221eb6cef
[libfirm] / ir / ir / irflag.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irflag.c
4  * Purpose:     Flags to control optimizations.
5  * Author:      Christian Schaefer, Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1999-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
16
17 #ifdef WITH_LIBCORE
18 #include <libcore/lc_opts.h>
19 #endif
20
21 #include "firm_common.h"
22 #include "irtools.h"
23 #include "irflag_t.h"
24
25 /* DISABLE - don't do this optimization
26    ENABLE  - lets see, if there is a better graph */
27 #define ON      (-1)
28 #define OFF  (0)
29
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)
33
34 optimization_state_t libFIRM_opt =
35 #include "irflag_t.def"
36   0;
37
38 #undef FLAG
39 #undef E_FLAG
40 #undef I_FLAG
41
42
43 /* verbose is always off on default */
44 optimization_state_t libFIRM_verb = 0;
45
46 /** The Firm verbosity level */
47 int firm_verbosity_level;
48
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;    \
54 }                                          \
55 void set_opt_##name##_verbose(int flag) {  \
56   if (flag) libFIRM_verb |= irf_##name;    \
57   else      libFIRM_verb &= ~irf_##name;   \
58 }                                          \
59 int (get_opt_##name)(void) {               \
60   return _get_opt_##name();                \
61 }
62
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;   \
68 }                                         \
69 void set_opt_##name##_verbose(int flag) { \
70   if (flag) libFIRM_verb |= irf_##name;   \
71   else      libFIRM_verb &= ~irf_##name;  \
72 }
73
74 /* generate them */
75 #include "irflag_t.def"
76
77 #undef I_FLAG
78 #undef E_FLAG
79
80 /* for compatibility reasons */
81 void set_optimize(int value) {
82   if (value) libFIRM_opt |= irf_optimize;
83   else       libFIRM_opt &= ~irf_optimize;
84 }
85
86 int (get_optimize)(void) {
87   return get_opt_optimize();
88 }
89
90 void set_opt_control_flow(int value)
91 {
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);
96 }
97
98 void set_firm_verbosity (int value) {
99   firm_verbosity_level = value;
100 }
101
102 int  (get_firm_verbosity) (void) {
103   return _get_firm_verbosity();
104 }
105
106 /* Save the current optimization state. */
107 void save_optimization_state(optimization_state_t *state)
108 {
109   *state = libFIRM_opt;
110 }
111
112 /* Restore the current optimization state. */
113 void restore_optimization_state(const optimization_state_t *state)
114 {
115   libFIRM_opt = *state;
116 }
117
118 #ifdef _DEBUG
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"
123 }
124 #endif
125
126 #ifdef WITH_LIBCORE
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"
131 #undef I_FLAG
132 #undef E_FLAG
133         { NULL }
134 };
135 #endif
136
137 void firm_init_flags(void)
138 {
139 #ifdef WITH_LIBCORE
140         lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
141         lc_opt_add_table(grp, firm_flags);
142 #endif
143 }