sparc_new_nodes.c 11 KB
Newer Older
Hannes Rapp's avatar
Hannes Rapp committed
1
/*
Michael Beck's avatar
Michael Beck committed
2
 * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
Hannes Rapp's avatar
Hannes Rapp committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * 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.
 */

/**
 * @file
 * @brief   This file implements the creation of the achitecture specific firm
 *          opcodes and the coresponding node constructors for the sparc
 *          assembler irg.
Michael Beck's avatar
Michael Beck committed
25
 * @version $Id$
Hannes Rapp's avatar
Hannes Rapp committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 */
#include "config.h"

#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 "irprintf.h"
#include "xmalloc.h"

#include "../bearch.h"

#include "sparc_nodes_attr.h"
#include "sparc_new_nodes.h"
#include "gen_sparc_regalloc_if.h"

47
bool sparc_has_load_store_attr(const ir_node *node)
48
{
Matthias Braun's avatar
Matthias Braun committed
49
50
	return is_sparc_Ld(node) || is_sparc_St(node) || is_sparc_Ldf(node)
	    || is_sparc_Stf(node);
51
52
53
54
}

static bool has_jmp_cond_attr(const ir_node *node)
{
55
	return is_sparc_Bicc(node) || is_sparc_fbfcc(node);
56
57
}

58
static bool has_switch_jmp_attr(const ir_node *node)
59
60
61
62
{
	return is_sparc_SwitchJmp(node);
}

63
64
65
66
67
static bool has_fp_attr(const ir_node *node)
{
	return is_sparc_fadd(node) || is_sparc_fsub(node)
	    || is_sparc_fmul(node) || is_sparc_fdiv(node)
	    || is_sparc_fftoi(node) || is_sparc_fitof(node)
68
	    || is_sparc_fneg(node) || is_sparc_fcmp(node);
69
70
71
72
73
74
75
}

static bool has_fp_conv_attr(const ir_node *node)
{
	return is_sparc_fftof(node);
}

Hannes Rapp's avatar
Hannes Rapp committed
76
77
78
/**
 * Dumper interface for dumping sparc nodes in vcg.
 * @param F        the output file
79
 * @param n        the node to dump
Hannes Rapp's avatar
Hannes Rapp committed
80
81
 * @param reason   indicates which kind of information should be dumped
 */
82
static void sparc_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
Hannes Rapp's avatar
Hannes Rapp committed
83
{
84
85
	const sparc_attr_t *attr;

Hannes Rapp's avatar
Hannes Rapp committed
86
	switch (reason) {
87
88
	case dump_node_opcode_txt:
		fprintf(F, "%s", get_irn_opname(n));
Hannes Rapp's avatar
Hannes Rapp committed
89
90
		break;

91
	case dump_node_mode_txt:
Hannes Rapp's avatar
Hannes Rapp committed
92
93
		break;

94
95
	case dump_node_info_txt:
		arch_dump_reqs_and_registers(F, n);
96
97
98
99
100
101
102
		attr = get_sparc_attr_const(n);
		if (attr->immediate_value_entity) {
			ir_fprintf(F, "entity: %+F (offset %d)\n",
			           attr->immediate_value_entity, attr->immediate_value);
		} else {
			ir_fprintf(F, "immediate value: %d\n", attr->immediate_value);
		}
103
		if (sparc_has_load_store_attr(n)) {
104
			const sparc_load_store_attr_t *attr = get_sparc_load_store_attr_const(n);
105
106
107
108
109
110
111
			ir_fprintf(F, "load store mode: %+F\n", attr->load_store_mode);
			fprintf(F, "is frame entity: %s\n",
			        attr->is_frame_entity ? "true" : "false");
		}
		if (has_jmp_cond_attr(n)) {
			const sparc_jmp_cond_attr_t *attr
				= get_sparc_jmp_cond_attr_const(n);
112
113
			fprintf(F, "relation: %d (%s)\n", attr->relation,
			        get_relation_string(attr->relation));
114
			fprintf(F, "unsigned: %s\n", attr->is_unsigned ? "true" : "false");
115
		}
116
117
118
		if (has_switch_jmp_attr(n)) {
			const sparc_switch_jmp_attr_t *attr
				= get_sparc_switch_jmp_attr_const(n);
119
120
			fprintf(F, "default proj: %ld\n", attr->default_proj_num);
		}
121
122
123
124
125
126
127
128
129
		if (has_fp_attr(n)) {
			const sparc_fp_attr_t *attr = get_sparc_fp_attr_const(n);
			ir_fprintf(F, "fp_mode: %+F\n", attr->fp_mode);
		}
		if (has_fp_conv_attr(n)) {
			const sparc_fp_conv_attr_t *attr = get_sparc_fp_conv_attr_const(n);
			ir_fprintf(F, "conv from: %+F\n", attr->src_mode);
			ir_fprintf(F, "conv to: %+F\n", attr->dest_mode);
		}
130
131
132
		break;

	case dump_node_nodeattr_txt:
Hannes Rapp's avatar
Hannes Rapp committed
133
134
135
136
		break;
	}
}

137
138
static void sparc_set_attr_imm(ir_node *res, ir_entity *entity,
                               int32_t immediate_value)
Hannes Rapp's avatar
Hannes Rapp committed
139
{
140
	sparc_attr_t *attr           = (sparc_attr_t*)get_irn_generic_attr(res);
141
142
	attr->immediate_value_entity = entity;
	attr->immediate_value        = immediate_value;
Hannes Rapp's avatar
Hannes Rapp committed
143
144
}

145
146
static void init_sparc_jmp_cond_attr(ir_node *node, ir_relation relation,
                                     bool is_unsigned)
Hannes Rapp's avatar
Hannes Rapp committed
147
148
{
	sparc_jmp_cond_attr_t *attr = get_sparc_jmp_cond_attr(node);
149
	attr->relation    = relation;
150
	attr->is_unsigned = is_unsigned;
Hannes Rapp's avatar
Hannes Rapp committed
151
152
153
154
}

sparc_attr_t *get_sparc_attr(ir_node *node)
{
155
156
	assert(is_sparc_irn(node));
	return (sparc_attr_t*) get_irn_generic_attr(node);
Hannes Rapp's avatar
Hannes Rapp committed
157
158
159
160
}

const sparc_attr_t *get_sparc_attr_const(const ir_node *node)
{
161
162
	assert(is_sparc_irn(node));
	return (const sparc_attr_t*) get_irn_generic_attr_const(node);
Hannes Rapp's avatar
Hannes Rapp committed
163
164
165
166
}

sparc_load_store_attr_t *get_sparc_load_store_attr(ir_node *node)
{
167
	assert(sparc_has_load_store_attr(node));
168
	return (sparc_load_store_attr_t*) get_irn_generic_attr_const(node);
Hannes Rapp's avatar
Hannes Rapp committed
169
170
171
172
}

const sparc_load_store_attr_t *get_sparc_load_store_attr_const(const ir_node *node)
{
173
	assert(sparc_has_load_store_attr(node));
174
	return (const sparc_load_store_attr_t*) get_irn_generic_attr_const(node);
Hannes Rapp's avatar
Hannes Rapp committed
175
176
177
178
}

sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr(ir_node *node)
{
179
180
	assert(has_jmp_cond_attr(node));
	return (sparc_jmp_cond_attr_t*) get_irn_generic_attr_const(node);
Hannes Rapp's avatar
Hannes Rapp committed
181
182
183
184
}

const sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr_const(const ir_node *node)
{
185
186
	assert(has_jmp_cond_attr(node));
	return (const sparc_jmp_cond_attr_t*) get_irn_generic_attr_const(node);
Hannes Rapp's avatar
Hannes Rapp committed
187
188
}

189
sparc_switch_jmp_attr_t *get_sparc_switch_jmp_attr(ir_node *node)
Hannes Rapp's avatar
Hannes Rapp committed
190
{
191
192
	assert(has_switch_jmp_attr(node));
	return (sparc_switch_jmp_attr_t*) get_irn_generic_attr_const(node);
Hannes Rapp's avatar
Hannes Rapp committed
193
194
}

195
const sparc_switch_jmp_attr_t *get_sparc_switch_jmp_attr_const(const ir_node *node)
Hannes Rapp's avatar
Hannes Rapp committed
196
{
197
198
	assert(has_switch_jmp_attr(node));
	return (const sparc_switch_jmp_attr_t*) get_irn_generic_attr_const(node);
Hannes Rapp's avatar
Hannes Rapp committed
199
200
}

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
sparc_fp_attr_t *get_sparc_fp_attr(ir_node *node)
{
	assert(has_fp_attr(node));
	return (sparc_fp_attr_t*) get_irn_generic_attr(node);
}

const sparc_fp_attr_t *get_sparc_fp_attr_const(const ir_node *node)
{
	assert(has_fp_attr(node));
	return (const sparc_fp_attr_t*) get_irn_generic_attr_const(node);
}

sparc_fp_conv_attr_t *get_sparc_fp_conv_attr(ir_node *node)
{
	assert(has_fp_conv_attr(node));
	return (sparc_fp_conv_attr_t*) get_irn_generic_attr(node);
}

const sparc_fp_conv_attr_t *get_sparc_fp_conv_attr_const(const ir_node *node)
{
	assert(has_fp_conv_attr(node));
	return (const sparc_fp_conv_attr_t*) get_irn_generic_attr_const(node);
}

Hannes Rapp's avatar
Hannes Rapp committed
225
226
227
/**
 * Initializes the nodes attributes.
 */
228
229
230
231
static void init_sparc_attributes(ir_node *node, arch_irn_flags_t flags,
                                  const arch_register_req_t **in_reqs,
                                  const be_execution_unit_t ***execution_units,
                                  int n_res)
Hannes Rapp's avatar
Hannes Rapp committed
232
233
234
235
236
237
238
{
	ir_graph        *irg  = get_irn_irg(node);
	struct obstack  *obst = get_irg_obstack(irg);
	backend_info_t  *info;
	(void) execution_units;

	arch_irn_set_flags(node, flags);
239
	arch_set_in_register_reqs(node, in_reqs);
Hannes Rapp's avatar
Hannes Rapp committed
240
241
242
243
244
245
246

	info            = be_get_info(node);
	info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
	memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
}

static void init_sparc_load_store_attributes(ir_node *res, ir_mode *ls_mode,
247
											ir_entity *entity, int32_t offset,
248
249
											bool is_frame_entity,
											bool is_reg_reg)
Hannes Rapp's avatar
Hannes Rapp committed
250
{
251
252
253
254
255
	sparc_load_store_attr_t *attr     = get_sparc_load_store_attr(res);
	attr->base.immediate_value_entity = entity;
	attr->base.immediate_value        = offset;
	attr->load_store_mode             = ls_mode;
	attr->is_frame_entity             = is_frame_entity;
256
	attr->is_reg_reg                  = is_reg_reg;
Hannes Rapp's avatar
Hannes Rapp committed
257
258
}

259
260
261
262
263
264
265
266
267
268
269
270
271
272
static void init_sparc_fp_attributes(ir_node *res, ir_mode *fp_mode)
{
	sparc_fp_attr_t *attr = get_sparc_fp_attr(res);
	attr->fp_mode = fp_mode;
}

static void init_sparc_fp_conv_attributes(ir_node *res, ir_mode *src_mode,
                                          ir_mode *dest_mode)
{
	sparc_fp_conv_attr_t *attr = get_sparc_fp_conv_attr(res);
	attr->src_mode = src_mode;
	attr->dest_mode = dest_mode;
}

273
274
275
276
277
278
279
280
static void init_sparc_switch_jmp_attributes(ir_node *res, long default_pn,
                                             ir_entity *jump_table)
{
	sparc_switch_jmp_attr_t *attr = get_sparc_switch_jmp_attr(res);
	attr->default_proj_num = default_pn;
	attr->jump_table       = jump_table;
}

Hannes Rapp's avatar
Hannes Rapp committed
281
282
283
/**
 * copies sparc attributes of  node
 */
284
285
static void sparc_copy_attr(ir_graph *irg, const ir_node *old_node,
                            ir_node *new_node)
286
{
287
288
	struct obstack     *obst    = get_irg_obstack(irg);
	const sparc_attr_t *attr_old = get_sparc_attr_const(old_node);
Hannes Rapp's avatar
Hannes Rapp committed
289
	sparc_attr_t       *attr_new = get_sparc_attr(new_node);
290
291
	backend_info_t     *old_info = be_get_info(old_node);
	backend_info_t     *new_info = be_get_info(new_node);
Hannes Rapp's avatar
Hannes Rapp committed
292
293
294
295

	/* copy the attributes */
	memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
	/* copy out flags */
296
	new_info->flags = old_info->flags;
Hannes Rapp's avatar
Hannes Rapp committed
297
298
	new_info->out_infos =
		DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
299
	new_info->in_reqs = old_info->in_reqs;
Hannes Rapp's avatar
Hannes Rapp committed
300
301
302
303
304
}

/**
 * compare some node's attributes
 */
Michael Beck's avatar
Michael Beck committed
305
static int cmp_attr_sparc(const ir_node *a, const ir_node *b)
Hannes Rapp's avatar
Hannes Rapp committed
306
307
308
309
{
	const sparc_attr_t *attr_a = get_sparc_attr_const(a);
	const sparc_attr_t *attr_b = get_sparc_attr_const(b);

Hannes Rapp's avatar
Hannes Rapp committed
310
	return attr_a->immediate_value != attr_b->immediate_value
311
		|| attr_a->immediate_value_entity != attr_b->immediate_value_entity;
Hannes Rapp's avatar
Hannes Rapp committed
312
313
}

Michael Beck's avatar
Michael Beck committed
314
static int cmp_attr_sparc_load_store(const ir_node *a, const ir_node *b)
Hannes Rapp's avatar
Hannes Rapp committed
315
{
Hannes Rapp's avatar
Hannes Rapp committed
316
317
318
319
	const sparc_load_store_attr_t *attr_a = get_sparc_load_store_attr_const(a);
	const sparc_load_store_attr_t *attr_b = get_sparc_load_store_attr_const(b);

	if (cmp_attr_sparc(a, b))
320
		return 1;
Hannes Rapp's avatar
Hannes Rapp committed
321

322
323
	return attr_a->is_frame_entity != attr_b->is_frame_entity
			|| attr_a->load_store_mode != attr_b->load_store_mode;
Hannes Rapp's avatar
Hannes Rapp committed
324
325
}

Michael Beck's avatar
Michael Beck committed
326
static int cmp_attr_sparc_jmp_cond(const ir_node *a, const ir_node *b)
Hannes Rapp's avatar
Hannes Rapp committed
327
{
Hannes Rapp's avatar
Hannes Rapp committed
328
329
330
331
	const sparc_jmp_cond_attr_t *attr_a = get_sparc_jmp_cond_attr_const(a);
	const sparc_jmp_cond_attr_t *attr_b = get_sparc_jmp_cond_attr_const(b);

	if (cmp_attr_sparc(a, b))
332
		return 1;
Hannes Rapp's avatar
Hannes Rapp committed
333

334
	return attr_a->relation != attr_b->relation
335
	    || attr_a->is_unsigned != attr_b->is_unsigned;
Hannes Rapp's avatar
Hannes Rapp committed
336
337
}

Michael Beck's avatar
Michael Beck committed
338
static int cmp_attr_sparc_switch_jmp(const ir_node *a, const ir_node *b)
Hannes Rapp's avatar
Hannes Rapp committed
339
{
340
341
	const sparc_switch_jmp_attr_t *attr_a = get_sparc_switch_jmp_attr_const(a);
	const sparc_switch_jmp_attr_t *attr_b = get_sparc_switch_jmp_attr_const(b);
Hannes Rapp's avatar
Hannes Rapp committed
342
343

	if (cmp_attr_sparc(a, b))
344
		return 1;
Hannes Rapp's avatar
Hannes Rapp committed
345

346
	return attr_a->default_proj_num != attr_b->default_proj_num;
Hannes Rapp's avatar
Hannes Rapp committed
347
348
}

Michael Beck's avatar
Michael Beck committed
349
static int cmp_attr_sparc_fp(const ir_node *a, const ir_node *b)
350
351
352
353
354
355
356
357
358
359
{
	const sparc_fp_attr_t *attr_a = get_sparc_fp_attr_const(a);
	const sparc_fp_attr_t *attr_b = get_sparc_fp_attr_const(b);

	if (cmp_attr_sparc(a, b))
		return 1;

	return attr_a->fp_mode != attr_b->fp_mode;
}

Michael Beck's avatar
Michael Beck committed
360
static int cmp_attr_sparc_fp_conv(const ir_node *a, const ir_node *b)
361
362
363
364
365
366
367
368
369
370
371
{
	const sparc_fp_conv_attr_t *attr_a = get_sparc_fp_conv_attr_const(a);
	const sparc_fp_conv_attr_t *attr_b = get_sparc_fp_conv_attr_const(b);

	if (cmp_attr_sparc(a, b))
		return 1;

	return attr_a->src_mode != attr_b->src_mode
	    || attr_a->dest_mode != attr_b->dest_mode;;
}

Hannes Rapp's avatar
Hannes Rapp committed
372
373
/* Include the generated constructor functions */
#include "gen_sparc_new_nodes.c.inl"