TEMPLATE_new_nodes.c 11.8 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
 *
 * 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.
 */

20
/**
Matthias Braun's avatar
Matthias Braun committed
21
22
23
24
25
 * @file
 * @brief   This file implements the creation of the achitecture specific firm
 *          opcodes and the coresponding node constructors for the TEMPLATE
 *          assembler irg.
 * @version $Id$
26
27
 */
#ifdef HAVE_CONFIG_H
28
#include "config.h"
29
30
31
32
33
34
35
36
37
38
39
40
41
#endif

#include <stdlib.h>

#include "irprog_t.h"
#include "irgraph_t.h"
#include "irnode_t.h"
#include "irmode_t.h"
#include "ircons_t.h"
#include "iropt_t.h"
#include "irop.h"
#include "firm_common_t.h"
#include "irvrfy_t.h"
Christian Würdig's avatar
Christian Würdig committed
42
#include "irprintf.h"
43
#include "xmalloc.h"
44

45
#include "../bearch_t.h"
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

#include "TEMPLATE_nodes_attr.h"
#include "TEMPLATE_new_nodes.h"
#include "gen_TEMPLATE_regalloc_if.h"



/***********************************************************************************
 *      _                                   _       _             __
 *     | |                                 (_)     | |           / _|
 *   __| |_   _ _ __ ___  _ __   ___ _ __   _ _ __ | |_ ___ _ __| |_ __ _  ___ ___
 *  / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__|  _/ _` |/ __/ _ \
 * | (_| | |_| | | | | | | |_) |  __/ |    | | | | | ||  __/ |  | || (_| | (_|  __/
 *  \__,_|\__,_|_| |_| |_| .__/ \___|_|    |_|_| |_|\__\___|_|  |_| \__,_|\___\___|
 *                       | |
 *                       |_|
 ***********************************************************************************/

Christian Würdig's avatar
Christian Würdig committed
64
65
66
/**
 * Dumps the register requirements for either in or out.
 */
Matthias Braun's avatar
Matthias Braun committed
67
68
static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
                         int inout) {
Christian Würdig's avatar
Christian Würdig committed
69
70
	char *dir = inout ? "out" : "in";
	int   max = inout ? get_TEMPLATE_n_res(n) : get_irn_arity(n);
Matthias Braun's avatar
Matthias Braun committed
71
	char  buf[1024];
Christian Würdig's avatar
Christian Würdig committed
72
73
	int   i;

Matthias Braun's avatar
Matthias Braun committed
74
	memset(buf, 0, sizeof(buf));
Christian Würdig's avatar
Christian Würdig committed
75
76
77
78
79

	if (reqs) {
		for (i = 0; i < max; i++) {
			fprintf(F, "%sreq #%d =", dir, i);

Matthias Braun's avatar
Matthias Braun committed
80
			if (reqs[i]->type == arch_register_req_type_none) {
Christian Würdig's avatar
Christian Würdig committed
81
82
83
				fprintf(F, " n/a");
			}

Matthias Braun's avatar
Matthias Braun committed
84
85
			if (reqs[i]->type & arch_register_req_type_normal) {
				fprintf(F, " %s", reqs[i]->cls->name);
Christian Würdig's avatar
Christian Würdig committed
86
87
			}

Matthias Braun's avatar
Matthias Braun committed
88
89
90
			if (reqs[i]->type & arch_register_req_type_limited) {
				fprintf(F, " %s",
						arch_register_req_format(buf, sizeof(buf), reqs[i], n));
Christian Würdig's avatar
Christian Würdig committed
91
92
			}

Matthias Braun's avatar
Matthias Braun committed
93
94
			if (reqs[i]->type & arch_register_req_type_should_be_same) {
				ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
Christian Würdig's avatar
Christian Würdig committed
95
96
			}

Matthias Braun's avatar
Matthias Braun committed
97
98
			if (reqs[i]->type & arch_register_req_type_should_be_different) {
				ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
Christian Würdig's avatar
Christian Würdig committed
99
100
101
102
103
104
			}

			fprintf(F, "\n");
		}

		fprintf(F, "\n");
Matthias Braun's avatar
Matthias Braun committed
105
	} else {
Christian Würdig's avatar
Christian Würdig committed
106
107
108
109
110
		fprintf(F, "%sreq = N/A\n", dir);
	}
}


111
112
113
114
115
116
117
/**
 * Dumper interface for dumping TEMPLATE nodes in vcg.
 * @param n        the node to dump
 * @param F        the output file
 * @param reason   indicates which kind of information should be dumped
 * @return 0 on success or != 0 on failure
 */
118
static int TEMPLATE_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
Christian Würdig's avatar
Christian Würdig committed
119
120
121
  	ir_mode     *mode = NULL;
	int          bad  = 0;
	int          i;
122
	const TEMPLATE_attr_t *attr;
Matthias Braun's avatar
Matthias Braun committed
123
	const arch_register_req_t **reqs;
Christian Würdig's avatar
Christian Würdig committed
124
	const arch_register_t     **slots;
125
126
127

	switch (reason) {
		case dump_node_opcode_txt:
Christian Würdig's avatar
Christian Würdig committed
128
			fprintf(F, "%s", get_irn_opname(n));
129
130
131
132
133
134
135
136
			break;

		case dump_node_mode_txt:
			mode = get_irn_mode(n);

			if (mode) {
				fprintf(F, "[%s]", get_mode_name(mode));
			}
Christian Würdig's avatar
Christian Würdig committed
137
138
139
			else {
				fprintf(F, "[?NOMODE?]");
			}
140
141
142
143
			break;

		case dump_node_nodeattr_txt:

Christian Würdig's avatar
Christian Würdig committed
144
145
			/* TODO: dump some attributes which should show up */
			/* in node name in dump (e.g. consts or the like)  */
146
147
148
149

			break;

		case dump_node_info_txt:
150
			attr = get_TEMPLATE_attr_const(n);
Christian Würdig's avatar
Christian Würdig committed
151
			fprintf(F, "=== TEMPLATE attr begin ===\n");
152
153
154
155

			/* dump IN requirements */
			if (get_irn_arity(n) > 0) {
				reqs = get_TEMPLATE_in_req_all(n);
Christian Würdig's avatar
Christian Würdig committed
156
				dump_reg_req(F, n, reqs, 0);
157
158
159
160
161
			}

			/* dump OUT requirements */
			if (attr->n_res > 0) {
				reqs = get_TEMPLATE_out_req_all(n);
Christian Würdig's avatar
Christian Würdig committed
162
				dump_reg_req(F, n, reqs, 1);
163
164
165
166
167
168
169
170
171
172
173
174
175
176
			}

			/* dump assigned registers */
			slots = get_TEMPLATE_slots(n);
			if (slots && attr->n_res > 0) {
				for (i = 0; i < attr->n_res; i++) {
					if (slots[i]) {
						fprintf(F, "reg #%d = %s\n", i, slots[i]->name);
					}
					else {
						fprintf(F, "reg #%d = n/a\n", i);
					}
				}
			}
Christian Würdig's avatar
Christian Würdig committed
177
			fprintf(F, "\n");
178

Christian Würdig's avatar
Christian Würdig committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
			/* dump n_res */
			fprintf(F, "n_res = %d\n", get_TEMPLATE_n_res(n));

			/* dump flags */
			fprintf(F, "flags =");
			if (attr->flags == arch_irn_flags_none) {
				fprintf(F, " none");
			}
			else {
				if (attr->flags & arch_irn_flags_dont_spill) {
					fprintf(F, " unspillable");
				}
				if (attr->flags & arch_irn_flags_rematerializable) {
					fprintf(F, " remat");
				}
				if (attr->flags & arch_irn_flags_ignore) {
					fprintf(F, " ignore");
				}
			}
			fprintf(F, " (%d)\n", attr->flags);

			/* TODO: dump all additional attributes */

			fprintf(F, "=== TEMPLATE attr end ===\n");
			/* end of: case dump_node_info_txt */
204
205
206
			break;
	}

Christian Würdig's avatar
Christian Würdig committed
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
	return bad;
}



/***************************************************************************************************
 *        _   _                   _       __        _                    _   _               _
 *       | | | |                 | |     / /       | |                  | | | |             | |
 *   __ _| |_| |_ _ __   ___  ___| |_   / /_ _  ___| |_   _ __ ___   ___| |_| |__   ___   __| |___
 *  / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
 * | (_| | |_| |_| |    \__ \  __/ |_ / / (_| |  __/ |_  | | | | | |  __/ |_| | | | (_) | (_| \__ \
 *  \__,_|\__|\__|_|    |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
 *                                        __/ |
 *                                       |___/
 ***************************************************************************************************/

224
225
const TEMPLATE_attr_t *get_TEMPLATE_attr_const(const ir_node *node) {
	assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
Matthias Braun's avatar
Matthias Braun committed
226
	return (const TEMPLATE_attr_t *)get_irn_generic_attr_const(node);
227
228
229
}

TEMPLATE_attr_t *get_TEMPLATE_attr(ir_node *node) {
230
	assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
231
	return (TEMPLATE_attr_t *)get_irn_generic_attr(node);
232
233
234
235
236
}

/**
 * Returns the argument register requirements of a TEMPLATE node.
 */
Matthias Braun's avatar
Matthias Braun committed
237
const arch_register_req_t **get_TEMPLATE_in_req_all(const ir_node *node) {
238
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
239
240
241
242
243
244
	return attr->in_req;
}

/**
 * Returns the result register requirements of an TEMPLATE node.
 */
Matthias Braun's avatar
Matthias Braun committed
245
const arch_register_req_t **get_TEMPLATE_out_req_all(const ir_node *node) {
246
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
247
248
249
250
251
252
	return attr->out_req;
}

/**
 * Returns the argument register requirement at position pos of an TEMPLATE node.
 */
Matthias Braun's avatar
Matthias Braun committed
253
const arch_register_req_t *get_TEMPLATE_in_req(const ir_node *node, int pos) {
254
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
255
256
257
258
259
260
	return attr->in_req[pos];
}

/**
 * Returns the result register requirement at position pos of an TEMPLATE node.
 */
Matthias Braun's avatar
Matthias Braun committed
261
const arch_register_req_t *get_TEMPLATE_out_req(const ir_node *node, int pos) {
262
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
263
264
265
266
267
268
	return attr->out_req[pos];
}

/**
 * Sets the OUT register requirements at position pos.
 */
Matthias Braun's avatar
Matthias Braun committed
269
void set_TEMPLATE_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
270
271
272
273
274
275
276
	TEMPLATE_attr_t *attr   = get_TEMPLATE_attr(node);
	attr->out_req[pos] = req;
}

/**
 * Sets the IN register requirements at position pos.
 */
Matthias Braun's avatar
Matthias Braun committed
277
void set_TEMPLATE_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
278
279
280
281
282
283
284
285
	TEMPLATE_attr_t *attr  = get_TEMPLATE_attr(node);
	attr->in_req[pos] = req;
}

/**
 * Returns the register flag of an TEMPLATE node.
 */
arch_irn_flags_t get_TEMPLATE_flags(const ir_node *node) {
286
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
287
288
289
290
291
292
	return attr->flags;
}

/**
 * Sets the register flag of an TEMPLATE node.
 */
Matthias Braun's avatar
Matthias Braun committed
293
void set_TEMPLATE_flags(ir_node *node, arch_irn_flags_t flags) {
294
295
296
297
298
299
300
	TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
	attr->flags      = flags;
}

/**
 * Returns the result register slots of an TEMPLATE node.
 */
Matthias Braun's avatar
Matthias Braun committed
301
const arch_register_t **get_TEMPLATE_slots(ir_node *node) {
Christoph Mallon's avatar
Christoph Mallon committed
302
	TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
Matthias Braun's avatar
Matthias Braun committed
303
304
305
306
307
308
309
	return attr->slots;
}

/**
 * Returns the result register slots of an TEMPLATE node.
 */
const arch_register_t * const *get_TEMPLATE_slots_const(const ir_node *node) {
Christoph Mallon's avatar
Christoph Mallon committed
310
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
311
312
313
314
315
316
317
	return attr->slots;
}

/**
 * Returns the name of the OUT register at position pos.
 */
const char *get_TEMPLATE_out_reg_name(const ir_node *node, int pos) {
318
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
319
320
321
322
323
324
325
326
327
328
329
330

	assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
	assert(pos < attr->n_res && "Invalid OUT position.");
	assert(attr->slots[pos]  && "No register assigned");

	return arch_register_get_name(attr->slots[pos]);
}

/**
 * Returns the index of the OUT register at position pos within its register class.
 */
int get_TEMPLATE_out_regnr(const ir_node *node, int pos) {
331
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
332
333
334
335
336
337
338
339
340
341
342
343

	assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
	assert(pos < attr->n_res && "Invalid OUT position.");
	assert(attr->slots[pos]  && "No register assigned");

	return arch_register_get_index(attr->slots[pos]);
}

/**
 * Returns the OUT register at position pos.
 */
const arch_register_t *get_TEMPLATE_out_reg(const ir_node *node, int pos) {
344
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364

	assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
	assert(pos < attr->n_res && "Invalid OUT position.");
	assert(attr->slots[pos]  && "No register assigned");

	return attr->slots[pos];
}

/**
 * Sets the number of results.
 */
void set_TEMPLATE_n_res(ir_node *node, int n_res) {
	TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
	attr->n_res      = n_res;
}

/**
 * Returns the number of results.
 */
int get_TEMPLATE_n_res(const ir_node *node) {
365
	const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
366
367
368
	return attr->n_res;
}

Matthias Braun's avatar
Matthias Braun committed
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/**
 * Initializes the nodes attributes.
 */
void init_TEMPLATE_attributes(ir_node *node, arch_irn_flags_t flags,
                              const arch_register_req_t **in_reqs,
                              const arch_register_req_t **out_reqs,
                              const be_execution_unit_t ***execution_units,
                              int n_res, unsigned latency)
{
	TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);

	attr->flags = flags;
	attr->out_req = out_reqs;
	attr->in_req = in_reqs;
	attr->n_res = n_res;
384

Matthias Braun's avatar
Matthias Braun committed
385
386
	memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
}
387
388
389
390
391
392
393
394
395
396
397
398
399

/***************************************************************************************
 *                  _                            _                   _
 *                 | |                          | |                 | |
 *  _ __   ___   __| | ___    ___ ___  _ __  ___| |_ _ __ _   _  ___| |_ ___  _ __ ___
 * | '_ \ / _ \ / _` |/ _ \  / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
 * | | | | (_) | (_| |  __/ | (_| (_) | | | \__ \ |_| |  | |_| | (__| || (_) | |  \__ \
 * |_| |_|\___/ \__,_|\___|  \___\___/|_| |_|___/\__|_|   \__,_|\___|\__\___/|_|  |___/
 *
 ***************************************************************************************/

/* Include the generated constructor functions */
#include "gen_TEMPLATE_new_nodes.c.inl"