Added index -> node map to irgs
[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 }
98
99 void set_firm_verbosity (int value) {
100   firm_verbosity_level = value;
101 }
102
103 int  (get_firm_verbosity) (void) {
104   return _get_firm_verbosity();
105 }
106
107 /* Save the current optimization state. */
108 void save_optimization_state(optimization_state_t *state)
109 {
110   *state = libFIRM_opt;
111 }
112
113 /* Restore the current optimization state. */
114 void restore_optimization_state(const optimization_state_t *state)
115 {
116   libFIRM_opt = *state;
117 }
118
119 /* Switches ALL optimizations off */
120 void all_optimizations_off(void)
121 {
122   libFIRM_opt = 0;
123 }
124
125 #ifdef _DEBUG
126 /* only for debugging */
127 void firm_show_flags(FILE *f) {
128   if (! f)
129     f = stdout;
130   printf("Firm optimization state:\n");
131 #define E_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
132 #define I_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
133 #include "irflag_t.def"
134 #undef I_FLAG
135 #undef E_FLAG
136   printf("\n");
137 }
138 #endif
139
140 #ifdef WITH_LIBCORE
141 static const lc_opt_table_entry_t firm_flags[] = {
142 #define I_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
143 #define E_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
144 #include "irflag_t.def"
145 #undef I_FLAG
146 #undef E_FLAG
147         { NULL }
148 };
149 #endif
150
151 void firm_init_flags(void)
152 {
153 #ifdef WITH_LIBCORE
154         lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
155         lc_opt_add_table(grp, firm_flags);
156 #endif
157 }
158
159 firm_verification_t opt_do_node_verification = FIRM_VERIFICATION_ON;
160
161 void do_node_verification(firm_verification_t mode) {
162   opt_do_node_verification = mode;
163 }