bemodule.c 6.48 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
/*
Michael Beck's avatar
Michael Beck committed
2
 * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
Christian Würdig's avatar
Christian Würdig committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

Christian Würdig's avatar
Christian Würdig committed
20
21
22
23
24
25
/**
 * @file
 * @brief       Backend module interface.
 * @author      Matthias Braun
 * @date        29.09.2005
 * @version     $Id$
Matthias Braun's avatar
Matthias Braun committed
26
 */
27
#include "config.h"
Matthias Braun's avatar
Matthias Braun committed
28
29
30
31
32
33
34
35
36

#include <stdlib.h>

#include "bemodule_t.h"
#include "xmalloc.h"

void be_init_sched(void);
void be_init_blocksched(void);
void be_init_spill(void);
37
void be_init_spilloptions(void);
Matthias Braun's avatar
Matthias Braun committed
38
39
40
void be_init_listsched(void);
void be_init_schedrss(void);
void be_init_chordal(void);
41
void be_init_chordal_main(void);
yb9976's avatar
yb9976 committed
42
void be_init_copyopt(void);
43
void be_init_copyheur(void);
Matthias Braun's avatar
Matthias Braun committed
44
void be_init_copyheur2(void);
45
void be_init_copyheur4(void);
46
47
void be_init_copyilp2(void);
void be_init_copypbqp(void);
Matthias Braun's avatar
Matthias Braun committed
48
void be_init_copystat(void);
49
void be_init_daemelspill(void);
50
void be_init_dbgout(void);
Matthias Braun's avatar
Matthias Braun committed
51
52
53
54
void be_init_arch_ia32(void);
void be_init_arch_ppc32(void);
void be_init_arch_mips(void);
void be_init_arch_arm(void);
55
void be_init_arch_sta(void);
56
void be_init_arch_TEMPLATE(void);
Matthias Braun's avatar
Matthias Braun committed
57
58
void be_init_ilpsched(void);
void be_init_copyilp(void);
59
void be_init_peephole(void);
Matthias Braun's avatar
Matthias Braun committed
60
void be_init_ra(void);
61
void be_init_spillbelady(void);
62
void be_init_spillbelady2(void);
63
void be_init_spillbelady3(void);
64
void be_init_ssaconstr(void);
65
void be_init_stabs(void);
Matthias Braun's avatar
Matthias Braun committed
66
void be_init_straight_alloc(void);
Matthias Braun's avatar
Matthias Braun committed
67
void be_init_ifg(void);
Matthias Braun's avatar
Matthias Braun committed
68
69
70
71
void be_init_irgmod(void);
void be_init_loopana(void);
void be_init_spillslots(void);
void be_init_live(void);
72
void be_init_state(void);
73
void be_init_pbqp(void);
Matthias Braun's avatar
Matthias Braun committed
74
75

void be_quit_copystat(void);
76
void be_quit_pbqp(void);
Matthias Braun's avatar
Matthias Braun committed
77

Christian Würdig's avatar
Christian Würdig committed
78
/**
Michael Beck's avatar
Michael Beck committed
79
 * Driver for module initialization.
Christian Würdig's avatar
Christian Würdig committed
80
81
 * Call your module initialization function here.
 */
Matthias Braun's avatar
Matthias Braun committed
82
83
84
85
void be_init_modules(void)
{
	static int run_once = 0;

Christian Würdig's avatar
Christian Würdig committed
86
	if (run_once)
Matthias Braun's avatar
Matthias Braun committed
87
88
89
		return;
	run_once = 1;

Matthias Braun's avatar
Matthias Braun committed
90
91
92
93
	be_init_irgmod();
	be_init_loopana();
	be_init_live();
	be_init_spillslots();
Matthias Braun's avatar
Matthias Braun committed
94
95
96
	be_init_sched();
	be_init_blocksched();
	be_init_spill();
97
	be_init_spilloptions();
98
	be_init_dbgout();
Matthias Braun's avatar
Matthias Braun committed
99
100
	be_init_listsched();
	be_init_schedrss();
101
	be_init_chordal_main();
Matthias Braun's avatar
Matthias Braun committed
102
	be_init_chordal();
yb9976's avatar
yb9976 committed
103
	be_init_copyopt();
104
	be_init_copyheur4();
105
106
107
108
109
110
111
112
113
	be_init_copyheur();
	be_init_copyheur2();
#ifdef WITH_ILP
	be_init_copyilp2();
#endif
#ifdef FIRM_KAPS
	be_init_copypbqp();
#endif
	be_init_copynone();
Matthias Braun's avatar
Matthias Braun committed
114
	be_init_copystat();
115
	be_init_peephole();
Matthias Braun's avatar
Matthias Braun committed
116
	be_init_ra();
117
	be_init_spillbelady();
118
	be_init_spillbelady2();
119
	be_init_spillbelady3();
120
	be_init_daemelspill();
121
	be_init_ssaconstr();
Matthias Braun's avatar
Matthias Braun committed
122
	be_init_straight_alloc();
123
	be_init_state();
Matthias Braun's avatar
Matthias Braun committed
124
	be_init_ifg();
125
	be_init_stabs();
Matthias Braun's avatar
Matthias Braun committed
126
127
128
129
130

	be_init_arch_ia32();
	be_init_arch_ppc32();
	be_init_arch_mips();
	be_init_arch_arm();
Matthias Braun's avatar
Matthias Braun committed
131
	be_init_arch_TEMPLATE();
Matthias Braun's avatar
Matthias Braun committed
132
133
134
135

#ifdef WITH_ILP
	be_init_ilpsched();
	be_init_copyilp();
Christian Würdig's avatar
Christian Würdig committed
136
#endif /* WITH_ILP */
Matthias Braun's avatar
Matthias Braun committed
137

Michael Beck's avatar
Michael Beck committed
138
#if PLUGIN_IR_BE_STA
Matthias Braun's avatar
Matthias Braun committed
139
	be_init_arch_sta();
Christian Würdig's avatar
Christian Würdig committed
140
#endif /* PLUGIN_IR_BE_STA */
141
142
143
144

#ifdef FIRM_GRGEN_BE
	be_init_pbqp();
#endif
Matthias Braun's avatar
Matthias Braun committed
145
146
147
148
149
}

void be_quit_modules(void)
{
	be_quit_copystat();
150
151
152
#ifdef FIRM_GRGEN_BE
	be_quit_pbqp();
#endif
Matthias Braun's avatar
Matthias Braun committed
153
154
155
156
157
}

//---------------------------------------------------------------------------

typedef struct module_opt_data_t {
158
	void **var;
159
	be_module_list_entry_t * const *list_head;
Matthias Braun's avatar
Matthias Braun committed
160
161
} module_opt_data_t;

162
/**
Christian Würdig's avatar
Christian Würdig committed
163
 * Searches in list for module option. If found, set option to given value and return true.
164
165
 * Beware: return value of 0 means error.
 */
166
167
static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
                          size_t length, ...)
Matthias Braun's avatar
Matthias Braun committed
168
{
Christian Würdig's avatar
Christian Würdig committed
169
170
171
172
	module_opt_data_t            *moddata = data;
	int                          res      = 0;
	va_list                      args;
	const char                   *opt;
Matthias Braun's avatar
Matthias Braun committed
173
	const be_module_list_entry_t *module;
Matthias Braun's avatar
Matthias Braun committed
174
175
	(void) type;
	(void) name;
Matthias Braun's avatar
Matthias Braun committed
176
177
178
179

	va_start(args, length);
	opt = va_arg(args, const char*);

Christian Würdig's avatar
Christian Würdig committed
180
181
	for (module = *(moddata->list_head); module != NULL; module = module->next) {
		if (strcmp(module->name, opt) == 0) {
Matthias Braun's avatar
Matthias Braun committed
182
			*(moddata->var) = module->data;
183
			res = 1;
Matthias Braun's avatar
Matthias Braun committed
184
185
186
187
188
			break;
		}
	}
	va_end(args);

189
	return res;
Matthias Braun's avatar
Matthias Braun committed
190
191
}

Christian Würdig's avatar
Christian Würdig committed
192
193
194
/**
 * Dump the names of all registered module options.
 */
Matthias Braun's avatar
Matthias Braun committed
195
196
197
int dump_opt_module(char *buf, size_t buflen, const char *name,
                    lc_opt_type_t type, void *data, size_t length)
{
Christian Würdig's avatar
Christian Würdig committed
198
	module_opt_data_t            *moddata = data;
Matthias Braun's avatar
Matthias Braun committed
199
	const be_module_list_entry_t *module;
Matthias Braun's avatar
Matthias Braun committed
200
201
202
	(void) name;
	(void) type;
	(void) length;
Matthias Braun's avatar
Matthias Braun committed
203

Christian Würdig's avatar
Christian Würdig committed
204
205
	for (module = *(moddata->list_head); module != NULL; module = module->next) {
		if (module->data == *(moddata->var)) {
Matthias Braun's avatar
Matthias Braun committed
206
207
208
209
210
211
212
213
214
			snprintf(buf, buflen, "%s", module->name);
			return strlen(buf);
		}
	}

	snprintf(buf, buflen, "none");
	return strlen(buf);
}

Christian Würdig's avatar
Christian Würdig committed
215
216
217
/**
 * Dump the values of all register module options.
 */
Matthias Braun's avatar
Matthias Braun committed
218
219
220
int dump_opt_module_vals(char *buf, size_t buflen, const char *name,
                         lc_opt_type_t type, void *data, size_t len)
{
Christian Würdig's avatar
Christian Würdig committed
221
222
	module_opt_data_t            *moddata = data;
	char                         *p       = buf;
Matthias Braun's avatar
Matthias Braun committed
223
	const be_module_list_entry_t *module;
Matthias Braun's avatar
Matthias Braun committed
224
225
226
	(void) name;
	(void) type;
	(void) len;
Matthias Braun's avatar
Matthias Braun committed
227

Christian Würdig's avatar
Christian Würdig committed
228
	for (module = *(moddata->list_head); module != NULL; module = module->next) {
Matthias Braun's avatar
Matthias Braun committed
229
230
		size_t len = strlen(module->name);

Christian Würdig's avatar
Christian Würdig committed
231
232
		if (module != *(moddata->list_head)) {
			p       = strncat(p, ", ", buflen - 1);
Matthias Braun's avatar
Matthias Braun committed
233
234
235
236
			buflen -= 2;
		}

		p = strncat(p, module->name, buflen - 1);
Christian Würdig's avatar
Christian Würdig committed
237
238

		if (len >= buflen)
Matthias Braun's avatar
Matthias Braun committed
239
			break;
Christian Würdig's avatar
Christian Würdig committed
240

Matthias Braun's avatar
Matthias Braun committed
241
242
243
244
245
246
		buflen -= len;
	}

	return strlen(buf);
}

Christian Würdig's avatar
Christian Würdig committed
247
248
249
/**
 * Add a new module to list.
 */
Matthias Braun's avatar
Matthias Braun committed
250
void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
251
                           void *module)
Matthias Braun's avatar
Matthias Braun committed
252
{
253
	be_module_list_entry_t *entry = XMALLOC(be_module_list_entry_t);
Matthias Braun's avatar
Matthias Braun committed
254
255
256
	entry->name = name;
	entry->data = module;
	entry->next = *list_head;
Christian Würdig's avatar
Christian Würdig committed
257
	*list_head  = entry;
Matthias Braun's avatar
Matthias Braun committed
258
259
}

Christian Würdig's avatar
Christian Würdig committed
260
261
262
/**
 * Add an option for a module.
 */
Matthias Braun's avatar
Matthias Braun committed
263
264
void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
                            const char *description,
265
                            be_module_list_entry_t * const * list_head,
Matthias Braun's avatar
Matthias Braun committed
266
267
                            void **var)
{
268
	module_opt_data_t *moddata = XMALLOC(module_opt_data_t);
Christian Würdig's avatar
Christian Würdig committed
269
	moddata->var       = var;
Matthias Braun's avatar
Matthias Braun committed
270
271
272
273
274
275
276
	moddata->list_head = list_head;

	lc_opt_add_opt(grp, name, description, lc_opt_type_enum,
	               moddata, sizeof(moddata[0]),
	               set_opt_module, dump_opt_module, dump_opt_module_vals,
				   NULL);
}