fixed phi spilling
[libfirm] / ir / be / bemodule.c
1 /*
2  * Author:      Matthias Braun
3  * Date:        29.09.2005
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  * CVS-Id:      $Id$
7  */
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif /* HAVE_CONFIG_H */
11
12 #include <stdlib.h>
13
14 #include "bemodule_t.h"
15 #include "xmalloc.h"
16
17 void be_init_sched(void);
18 void be_init_blocksched(void);
19 void be_init_spill(void);
20 void be_init_listsched(void);
21 void be_init_schedrss(void);
22 void be_init_chordal(void);
23 void be_init_copycoal(void);
24 void be_init_copyheur2(void);
25 void be_init_raextern(void);
26 void be_init_copystat(void);
27 void be_init_arch_ia32(void);
28 void be_init_arch_ppc32(void);
29 void be_init_arch_mips(void);
30 void be_init_arch_arm(void);
31 void be_init_arch_sta(void);
32 void be_init_ilpsched(void);
33 void be_init_copyilp(void);
34 void be_init_javacoal(void);
35 void be_init_ra(void);
36 void be_init_spillbelady(void);
37 void be_init_spillmorgan(void);
38 void be_init_spillremat(void);
39 void be_init_ifg(void);
40 void be_init_irgmod(void);
41 void be_init_loopana(void);
42 void be_init_spillslots(void);
43 void be_init_live(void);
44 void be_init_state(void);
45
46 void be_quit_copystat(void);
47
48 /**
49  * Driver for module intialization.
50  * Call your module initialization function here.
51  */
52 void be_init_modules(void)
53 {
54         static int run_once = 0;
55
56         if (run_once)
57                 return;
58         run_once = 1;
59
60         be_init_irgmod();
61         be_init_loopana();
62         be_init_live();
63         be_init_spillslots();
64         be_init_sched();
65         be_init_blocksched();
66         be_init_spill();
67         be_init_listsched();
68         be_init_schedrss();
69         be_init_chordal();
70         be_init_copycoal();
71         be_init_copyheur2();
72         be_init_raextern();
73         be_init_copystat();
74         be_init_ra();
75         be_init_spillbelady();
76         be_init_spillmorgan();
77         be_init_state();
78         be_init_ifg();
79
80         be_init_arch_ia32();
81         be_init_arch_ppc32();
82         be_init_arch_mips();
83         be_init_arch_arm();
84
85 #ifdef WITH_ILP
86         be_init_ilpsched();
87         be_init_copyilp();
88         be_init_spillremat();
89 #endif /* WITH_ILP */
90
91 #ifdef WITH_JVM
92         be_init_javacoal();
93 #endif /* WITH_JVM */
94
95 #if PLUGIN_IR_BE_STA
96         be_init_arch_sta();
97 #endif /* PLUGIN_IR_BE_STA */
98 }
99
100 void be_quit_modules(void)
101 {
102         be_quit_copystat();
103 }
104
105 //---------------------------------------------------------------------------
106
107 typedef struct module_opt_data_t {
108         void **var;
109         be_module_list_entry_t * const *list_head;
110 } module_opt_data_t;
111
112 /**
113  * Searches in list for module option. If found, set option to given value and return true.
114  * Beware: return value of 0 means error.
115  */
116 static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
117                           size_t length, ...)
118 {
119         module_opt_data_t            *moddata = data;
120         int                          res      = 0;
121         va_list                      args;
122         const char                   *opt;
123         const be_module_list_entry_t *module;
124
125         va_start(args, length);
126         opt = va_arg(args, const char*);
127
128         for (module = *(moddata->list_head); module != NULL; module = module->next) {
129                 if (strcmp(module->name, opt) == 0) {
130                         *(moddata->var) = module->data;
131                         res = 1;
132                         break;
133                 }
134         }
135         va_end(args);
136
137         return res;
138 }
139
140 /**
141  * Dump the names of all registered module options.
142  */
143 int dump_opt_module(char *buf, size_t buflen, const char *name,
144                     lc_opt_type_t type, void *data, size_t length)
145 {
146         module_opt_data_t            *moddata = data;
147         const be_module_list_entry_t *module;
148
149         for (module = *(moddata->list_head); module != NULL; module = module->next) {
150                 if (module->data == *(moddata->var)) {
151                         snprintf(buf, buflen, "%s", module->name);
152                         return strlen(buf);
153                 }
154         }
155
156         snprintf(buf, buflen, "none");
157         return strlen(buf);
158 }
159
160 /**
161  * Dump the values of all register module options.
162  */
163 int dump_opt_module_vals(char *buf, size_t buflen, const char *name,
164                          lc_opt_type_t type, void *data, size_t len)
165 {
166         module_opt_data_t            *moddata = data;
167         char                         *p       = buf;
168         const be_module_list_entry_t *module;
169
170         for (module = *(moddata->list_head); module != NULL; module = module->next) {
171                 size_t len = strlen(module->name);
172
173                 if (module != *(moddata->list_head)) {
174                         p       = strncat(p, ", ", buflen - 1);
175                         buflen -= 2;
176                 }
177
178                 p = strncat(p, module->name, buflen - 1);
179
180                 if (len >= buflen)
181                         break;
182
183                 buflen -= len;
184         }
185
186         return strlen(buf);
187 }
188
189 /**
190  * Add a new module to list.
191  */
192 void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
193                            void *module)
194 {
195         be_module_list_entry_t *entry;
196
197     entry       = xmalloc(sizeof(entry[0]));
198         entry->name = name;
199         entry->data = module;
200         entry->next = *list_head;
201         *list_head  = entry;
202 }
203
204 /**
205  * Add an option for a module.
206  */
207 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
208                             const char *description,
209                             be_module_list_entry_t * const * list_head,
210                             void **var)
211 {
212         module_opt_data_t *moddata;
213
214         moddata            = xmalloc(sizeof(moddata[0]));
215         moddata->var       = var;
216         moddata->list_head = list_head;
217
218         lc_opt_add_opt(grp, name, description, lc_opt_type_enum,
219                        moddata, sizeof(moddata[0]),
220                        set_opt_module, dump_opt_module, dump_opt_module_vals,
221                                    NULL);
222 }