cleaned up doxygen comments
[libfirm] / ir / ir / irflag.c
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Flags to control optimizations.
23  * @author  Christian Schaefer, Goetz Lindenmaier
24  * @version $Id$
25  */
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31
32 #ifdef WITH_LIBCORE
33 #include <libcore/lc_opts.h>
34 #endif
35
36 #include "firm_common.h"
37 #include "irtools.h"
38 #include "irflag_t.h"
39
40 /* DISABLE - don't do this optimization
41    ENABLE  - lets see, if there is a better graph */
42 #define ON      (-1)
43 #define OFF  (0)
44
45 #define FLAG(name, value, def)  (irf_##name & def) |
46 #define E_FLAG(name, value, def)        FLAG(name, value, def)
47 #define I_FLAG(name, value, def)        FLAG(name, value, def)
48
49 optimization_state_t libFIRM_opt =
50 #include "irflag_t.def"
51   0;
52
53 #undef FLAG
54 #undef E_FLAG
55 #undef I_FLAG
56
57
58 /* verbose is always off on default */
59 optimization_state_t libFIRM_verb = 0;
60
61 /** The Firm verbosity level */
62 int firm_verbosity_level;
63
64 /* an external flag can be set and get from outside */
65 #define E_FLAG(name, value, def)           \
66 void set_opt_##name(int flag) {            \
67   if (flag) libFIRM_opt |= irf_##name;     \
68   else      libFIRM_opt &= ~irf_##name;    \
69 }                                          \
70 void set_opt_##name##_verbose(int flag) {  \
71   if (flag) libFIRM_verb |= irf_##name;    \
72   else      libFIRM_verb &= ~irf_##name;   \
73 }                                          \
74 int (get_opt_##name)(void) {               \
75   return _get_opt_##name();                \
76 }
77
78 /* an internal flag can only be set from outside */
79 #define I_FLAG(name, value, def)          \
80 void set_opt_##name(int flag) {           \
81   if (flag) libFIRM_opt |= irf_##name;    \
82   else      libFIRM_opt &= ~irf_##name;   \
83 }                                         \
84 void set_opt_##name##_verbose(int flag) { \
85   if (flag) libFIRM_verb |= irf_##name;   \
86   else      libFIRM_verb &= ~irf_##name;  \
87 }
88
89 /* generate them */
90 #include "irflag_t.def"
91
92 #undef I_FLAG
93 #undef E_FLAG
94
95 /* for compatibility reasons */
96 void set_optimize(int value) {
97   if (value) libFIRM_opt |= irf_optimize;
98   else       libFIRM_opt &= ~irf_optimize;
99 }
100
101 int (get_optimize)(void) {
102   return get_opt_optimize();
103 }
104
105 void set_opt_control_flow(int value)
106 {
107   set_opt_control_flow_straightening(value);
108   set_opt_control_flow_weak_simplification(value);
109   set_opt_control_flow_strong_simplification(value);
110 }
111
112 void set_firm_verbosity (int value) {
113   firm_verbosity_level = value;
114 }
115
116 int  (get_firm_verbosity) (void) {
117   return _get_firm_verbosity();
118 }
119
120 /* Save the current optimization state. */
121 void save_optimization_state(optimization_state_t *state)
122 {
123   *state = libFIRM_opt;
124 }
125
126 /* Restore the current optimization state. */
127 void restore_optimization_state(const optimization_state_t *state)
128 {
129   libFIRM_opt = *state;
130 }
131
132 /* Switches ALL optimizations off */
133 void all_optimizations_off(void)
134 {
135   libFIRM_opt = 0;
136 }
137
138 #ifdef _DEBUG
139 /* only for debugging */
140 void firm_show_flags(FILE *f) {
141   if (! f)
142     f = stdout;
143   printf("Firm optimization state:\n");
144 #define E_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
145 #define I_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
146 #include "irflag_t.def"
147 #undef I_FLAG
148 #undef E_FLAG
149   printf("\n");
150 }
151 #endif
152
153 #ifdef WITH_LIBCORE
154 static const lc_opt_table_entry_t firm_flags[] = {
155 #define I_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
156 #define E_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
157 #include "irflag_t.def"
158 #undef I_FLAG
159 #undef E_FLAG
160         { NULL }
161 };
162 #endif
163
164 void firm_init_flags(void)
165 {
166 #ifdef WITH_LIBCORE
167         lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
168         lc_opt_add_table(grp, firm_flags);
169 #endif
170 }
171
172 firm_verification_t opt_do_node_verification = FIRM_VERIFICATION_ON;
173
174 void do_node_verification(firm_verification_t mode) {
175   opt_do_node_verification = mode;
176 }