removed debg output
[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 #include "firm_common.h"
18 #include "irflag_t.h"
19
20 /* DISABLE - don't do this optimization
21    ENABLE  - lets see, if there is a better graph */
22 #define ENABLE(a)   a
23 #define DISABLE(a)  0
24
25 optimization_state_t libFIRM_opt =
26   ENABLE(OPT_OPTIMIZED)                          |
27   ENABLE(OPT_CSE)                                |
28   DISABLE(OPT_GLOBAL_CSE)                        |
29   ENABLE(OPT_CONSTANT_FOLDING)                   |
30   ENABLE(OPT_UNREACHABLE_CODE)                   |
31   ENABLE(OPT_CONTROL_FLOW_STRAIGHTENING)         |
32   ENABLE(OPT_CONTROL_FLOW_WEAK_SIMPLIFICATION)   |
33   ENABLE(OPT_CONTROL_FLOW_STRONG_SIMPLIFICATION) |
34   ENABLE(OPT_CRITICAL_EDGES)                     |
35   ENABLE(OPT_DEAD_NODE_ELIMINATION)              |
36   ENABLE(OPT_REASSOCIATION)                      |
37   ENABLE(OPT_INLINE)                             |
38   ENABLE(OPT_DYN_METH_DISPATCH)                  |
39   ENABLE(OPT_NORMALIZE);
40
41 /* set the flags with set_flagname, get the flag with get_flagname */
42 void set_opt_cse (int value)
43 {
44   if (value)
45     libFIRM_opt |= OPT_CSE;
46   else
47     libFIRM_opt &= ~OPT_CSE;
48 }
49
50 void set_opt_global_cse(int value)
51 {
52   if (value)
53     libFIRM_opt |= OPT_GLOBAL_CSE;
54   else
55     libFIRM_opt &= ~OPT_GLOBAL_CSE;
56 }
57
58 void
59 set_opt_constant_folding(int value)
60 {
61   if (value)
62     libFIRM_opt |= OPT_CONSTANT_FOLDING;
63   else
64     libFIRM_opt &= ~OPT_CONSTANT_FOLDING;
65 }
66
67 void
68 set_opt_unreachable_code(int value)
69 {
70   if (value)
71     libFIRM_opt |= OPT_UNREACHABLE_CODE;
72   else
73     libFIRM_opt &= ~OPT_UNREACHABLE_CODE;
74 }
75
76 void set_opt_control_flow(int value)
77 {
78   set_opt_control_flow_straightening(value);
79   set_opt_control_flow_weak_simplification(value);
80   set_opt_control_flow_strong_simplification(value);
81   set_opt_critical_edges(value);
82 }
83
84 /* Performs Straightening */
85 void set_opt_control_flow_straightening(int value)
86 {
87   if (value)
88     libFIRM_opt |= OPT_CONTROL_FLOW_STRAIGHTENING;
89   else
90     libFIRM_opt &= ~OPT_CONTROL_FLOW_STRAIGHTENING;
91 }
92
93 /* Performs if simplifications in local optimizations. */
94 void set_opt_control_flow_weak_simplification(int value)
95 {
96   if (value)
97     libFIRM_opt |= OPT_CONTROL_FLOW_WEAK_SIMPLIFICATION;
98   else
99     libFIRM_opt &= ~OPT_CONTROL_FLOW_WEAK_SIMPLIFICATION;
100 }
101
102 /* Performs strong if and loop simplification (in optimize_cf). */
103 void set_opt_control_flow_strong_simplification(int value)
104 {
105   if (value)
106     libFIRM_opt |= OPT_CONTROL_FLOW_STRONG_SIMPLIFICATION;
107   else
108     libFIRM_opt &= ~OPT_CONTROL_FLOW_STRONG_SIMPLIFICATION;
109 }
110
111 void set_opt_critical_edges(int value)
112 {
113   if (value)
114     libFIRM_opt |= OPT_CRITICAL_EDGES;
115   else
116     libFIRM_opt &= ~OPT_CRITICAL_EDGES;
117 }
118
119 void set_opt_reassociation(int value)
120 {
121   if (value)
122     libFIRM_opt |= OPT_REASSOCIATION;
123   else
124     libFIRM_opt &= ~OPT_REASSOCIATION;
125 }
126
127 void set_opt_dead_node_elimination(int value)
128 {
129   if (value)
130     libFIRM_opt |= OPT_DEAD_NODE_ELIMINATION;
131   else
132     libFIRM_opt &= ~OPT_DEAD_NODE_ELIMINATION;
133 }
134
135 void set_optimize(int value)
136 {
137   if (value)
138     libFIRM_opt |= OPT_OPTIMIZED;
139   else
140     libFIRM_opt &= ~OPT_OPTIMIZED;
141 }
142
143 int get_optimize(void)
144 {
145   return get_opt_optimize();
146 }
147
148 void set_opt_inline(int value)
149 {
150   if (value)
151     libFIRM_opt |= OPT_INLINE;
152   else
153     libFIRM_opt &= ~OPT_INLINE;
154 }
155
156 /** Enable/Disable optimization of dynamic method dispatch
157  *
158  * This flag enables/disables the optimization of dynamic method dispatch.
159  * If the flag is turned on Sel nodes can be replaced by Const nodes representing
160  * the address of a function.
161  */
162 void set_opt_dyn_meth_dispatch (int value)
163 {
164   if (value)
165     libFIRM_opt |= OPT_DYN_METH_DISPATCH;
166   else
167     libFIRM_opt &= ~OPT_DYN_METH_DISPATCH;
168 }
169
170 void set_opt_normalize(int value)
171 {
172   if (value)
173     libFIRM_opt |= OPT_NORMALIZE;
174   else
175     libFIRM_opt &= ~OPT_NORMALIZE;
176 }
177
178 /* Save the current optimization state. */
179 void save_optimization_state(optimization_state_t *state)
180 {
181   *state = libFIRM_opt;
182 }
183
184 /* Restore the current optimization state. */
185 void restore_optimization_state(const optimization_state_t *state)
186 {
187   libFIRM_opt = *state;
188 }
189
190 /* repeat 'inline' methods here */
191
192 # ifndef USE_GCC_INLINE
193
194 /** Returns constant folding optimization setting. */
195 int get_opt_cse(void)           /* iropt.c */
196 {
197   return libFIRM_opt & OPT_CSE;
198 }
199
200 /** Returns constant subexpression elimination setting. */
201 int get_opt_global_cse(void)    /* irgopt.c iropt.c */
202 {
203   return libFIRM_opt & OPT_GLOBAL_CSE;
204 }
205
206 /** Returns global constant subexpression elimination setting. */
207 int get_opt_constant_folding(void) /* iropt.c */
208 {
209   return libFIRM_opt & OPT_CONSTANT_FOLDING;
210 }
211
212 /** Returns unreachable code elimination setting. */
213 int get_opt_unreachable_code(void) /* iropt.c */
214 {
215   return libFIRM_opt & OPT_UNREACHABLE_CODE;
216 }
217
218 /** Returns Straightening setting. */
219 int get_opt_control_flow_straightening(void) /* iropt.c, irgopt.c */
220 {
221   return libFIRM_opt & OPT_CONTROL_FLOW_STRAIGHTENING;
222 }
223
224 /** Returns if simplifications in local optimizations setting. */
225 int get_opt_control_flow_weak_simplification(void) /* iropt.c, irgopt.c */
226 {
227   return libFIRM_opt & OPT_CONTROL_FLOW_WEAK_SIMPLIFICATION;
228 }
229
230 /** Returns strong if and loop simplification setting */
231 int get_opt_control_flow_strong_simplification(void) /* irgopt.c */
232 {
233   return libFIRM_opt & OPT_CONTROL_FLOW_STRONG_SIMPLIFICATION;
234 }
235
236 /** Returns whether critical edges are removed */
237 int get_opt_critical_edges(void) /* irgopt.c */
238 {
239   return libFIRM_opt & OPT_CRITICAL_EDGES;
240 }
241
242 /** Returns reassociation setting. */
243 int get_opt_reassociation(void) /* iropt.c */
244 {
245   return libFIRM_opt & OPT_REASSOCIATION;
246 }
247
248 /** Returns dead node elimination setting. */
249 int get_opt_dead_node_elimination(void) /* irgopt.c */
250 {
251   return libFIRM_opt & OPT_DEAD_NODE_ELIMINATION;
252 }
253
254 /** Returns global optimization setting */
255 int get_opt_optimize(void)      /* iropt.c, irgopt.c */
256 {
257   return libFIRM_opt & OPT_OPTIMIZED;
258 }
259
260 /** Returns inlining setting. */ /* how appropriate */
261 int get_opt_inline(void)        /* irgopt.c */
262 {
263   return libFIRM_opt & OPT_INLINE;
264 }
265
266 int get_opt_dyn_meth_dispatch(void) /* cgana.c */
267 {
268   return libFIRM_opt & OPT_DYN_METH_DISPATCH;
269 }
270
271 int get_opt_normalize(void)     /* irgopt.c, irnode.c, iropt.c */
272 {
273   return libFIRM_opt & OPT_NORMALIZE;
274 }
275
276 # endif /* not defined USE_GCC_INLINE */