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