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