don't extend load_mode when folding reloads
[libfirm] / ir / be / bemodule.c
1 /*
2  * Copyright (C) 1995-2008 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       Backend module interface.
23  * @author      Matthias Braun
24  * @date        29.09.2005
25  * @version     $Id$
26  */
27 #include <config.h>
28
29 #include "firm_config.h"
30
31 #include <stdlib.h>
32
33 #include "bemodule_t.h"
34 #include "xmalloc.h"
35
36 void be_init_sched(void);
37 void be_init_blocksched(void);
38 void be_init_spill(void);
39 void be_init_spilloptions(void);
40 void be_init_listsched(void);
41 void be_init_schedrss(void);
42 void be_init_chordal(void);
43 void be_init_chordal_main(void);
44 void be_init_copycoal(void);
45 void be_init_copyheur2(void);
46 void be_init_copyheur3(void);
47 void be_init_copyheur4(void);
48 void be_init_copyheur5(void);
49 void be_init_copystat(void);
50 void be_init_daemelspill(void);
51 void be_init_dbgout(void);
52 void be_init_arch_ia32(void);
53 void be_init_arch_ppc32(void);
54 void be_init_arch_mips(void);
55 void be_init_arch_arm(void);
56 void be_init_arch_sta(void);
57 void be_init_arch_TEMPLATE(void);
58 void be_init_ilpsched(void);
59 void be_init_copyilp(void);
60 void be_init_javacoal(void);
61 void be_init_peephole(void);
62 void be_init_ra(void);
63 void be_init_spillbelady(void);
64 void be_init_spillbelady2(void);
65 void be_init_spillbelady3(void);
66 //void be_init_spilllinearscan(void);
67 void be_init_ssaconstr(void);
68 void be_init_stabs(void);
69 void be_init_ifg(void);
70 void be_init_irgmod(void);
71 void be_init_loopana(void);
72 void be_init_spillslots(void);
73 void be_init_live(void);
74 void be_init_state(void);
75 void be_init_pbqp(void);
76
77 void be_quit_copystat(void);
78 void be_quit_pbqp(void);
79
80 /**
81  * Driver for module initialization.
82  * Call your module initialization function here.
83  */
84 void be_init_modules(void)
85 {
86         static int run_once = 0;
87
88         if (run_once)
89                 return;
90         run_once = 1;
91
92         be_init_irgmod();
93         be_init_loopana();
94         be_init_live();
95         be_init_spillslots();
96         be_init_sched();
97         be_init_blocksched();
98         be_init_spill();
99         be_init_spilloptions();
100         be_init_dbgout();
101         be_init_listsched();
102         be_init_schedrss();
103         be_init_chordal_main();
104         be_init_chordal();
105         be_init_copycoal();
106         be_init_copyheur2();
107         be_init_copyheur4();
108 //      be_init_copyheur5();
109         be_init_copystat();
110         be_init_peephole();
111         be_init_ra();
112         be_init_spillbelady();
113         be_init_spillbelady2();
114         be_init_spillbelady3();
115 //      be_init_spilllinearscan();
116         be_init_daemelspill();
117         be_init_ssaconstr();
118         be_init_state();
119         be_init_ifg();
120         be_init_stabs();
121
122         be_init_arch_ia32();
123         be_init_arch_ppc32();
124         be_init_arch_mips();
125         be_init_arch_arm();
126         be_init_arch_TEMPLATE();
127
128 #ifdef WITH_ILP
129         be_init_ilpsched();
130         be_init_copyilp();
131 #endif /* WITH_ILP */
132
133 #ifdef WITH_JVM
134         be_init_copyheur3();
135         be_init_javacoal();
136 #endif /* WITH_JVM */
137
138 #if PLUGIN_IR_BE_STA
139         be_init_arch_sta();
140 #endif /* PLUGIN_IR_BE_STA */
141
142 #ifdef FIRM_GRGEN_BE
143         be_init_pbqp();
144 #endif
145 }
146
147 void be_quit_modules(void)
148 {
149         be_quit_copystat();
150 #ifdef FIRM_GRGEN_BE
151         be_quit_pbqp();
152 #endif
153 }
154
155 //---------------------------------------------------------------------------
156
157 typedef struct module_opt_data_t {
158         void **var;
159         be_module_list_entry_t * const *list_head;
160 } module_opt_data_t;
161
162 /**
163  * Searches in list for module option. If found, set option to given value and return true.
164  * Beware: return value of 0 means error.
165  */
166 static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
167                           size_t length, ...)
168 {
169         module_opt_data_t            *moddata = data;
170         int                          res      = 0;
171         va_list                      args;
172         const char                   *opt;
173         const be_module_list_entry_t *module;
174         (void) type;
175         (void) name;
176
177         va_start(args, length);
178         opt = va_arg(args, const char*);
179
180         for (module = *(moddata->list_head); module != NULL; module = module->next) {
181                 if (strcmp(module->name, opt) == 0) {
182                         *(moddata->var) = module->data;
183                         res = 1;
184                         break;
185                 }
186         }
187         va_end(args);
188
189         return res;
190 }
191
192 /**
193  * Dump the names of all registered module options.
194  */
195 int dump_opt_module(char *buf, size_t buflen, const char *name,
196                     lc_opt_type_t type, void *data, size_t length)
197 {
198         module_opt_data_t            *moddata = data;
199         const be_module_list_entry_t *module;
200         (void) name;
201         (void) type;
202         (void) length;
203
204         for (module = *(moddata->list_head); module != NULL; module = module->next) {
205                 if (module->data == *(moddata->var)) {
206                         snprintf(buf, buflen, "%s", module->name);
207                         return strlen(buf);
208                 }
209         }
210
211         snprintf(buf, buflen, "none");
212         return strlen(buf);
213 }
214
215 /**
216  * Dump the values of all register module options.
217  */
218 int dump_opt_module_vals(char *buf, size_t buflen, const char *name,
219                          lc_opt_type_t type, void *data, size_t len)
220 {
221         module_opt_data_t            *moddata = data;
222         char                         *p       = buf;
223         const be_module_list_entry_t *module;
224         (void) name;
225         (void) type;
226         (void) len;
227
228         for (module = *(moddata->list_head); module != NULL; module = module->next) {
229                 size_t len = strlen(module->name);
230
231                 if (module != *(moddata->list_head)) {
232                         p       = strncat(p, ", ", buflen - 1);
233                         buflen -= 2;
234                 }
235
236                 p = strncat(p, module->name, buflen - 1);
237
238                 if (len >= buflen)
239                         break;
240
241                 buflen -= len;
242         }
243
244         return strlen(buf);
245 }
246
247 /**
248  * Add a new module to list.
249  */
250 void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
251                            void *module)
252 {
253         be_module_list_entry_t *entry;
254
255     entry       = xmalloc(sizeof(entry[0]));
256         entry->name = name;
257         entry->data = module;
258         entry->next = *list_head;
259         *list_head  = entry;
260 }
261
262 /**
263  * Add an option for a module.
264  */
265 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
266                             const char *description,
267                             be_module_list_entry_t * const * list_head,
268                             void **var)
269 {
270         module_opt_data_t *moddata;
271
272         moddata            = xmalloc(sizeof(moddata[0]));
273         moddata->var       = var;
274         moddata->list_head = list_head;
275
276         lc_opt_add_opt(grp, name, description, lc_opt_type_enum,
277                        moddata, sizeof(moddata[0]),
278                        set_opt_module, dump_opt_module, dump_opt_module_vals,
279                                    NULL);
280 }