benode.c 49.5 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.
 */

Sebastian Hack's avatar
Sebastian Hack committed
20
/**
Christian Würdig's avatar
Christian Würdig committed
21
22
23
24
25
 * @file
 * @brief       Backend node support for generic backend nodes.
 * @author      Sebastian Hack
 * @date        17.05.2005
 * @version     $Id$
Sebastian Hack's avatar
Sebastian Hack committed
26
 *
27
 * Backend node support for generic backend nodes.
Michael Beck's avatar
Michael Beck committed
28
 * This file provides Perm, Copy, Spill and Reload nodes.
Sebastian Hack's avatar
Sebastian Hack committed
29
 */
Michael Beck's avatar
Michael Beck committed
30
#ifdef HAVE_CONFIG_H
31
#include "config.h"
Michael Beck's avatar
Michael Beck committed
32
#endif
Sebastian Hack's avatar
Sebastian Hack committed
33
34
35
36
37
38

#include <stdlib.h>

#include "obst.h"
#include "set.h"
#include "pmap.h"
39
#include "util.h"
Sebastian Hack's avatar
Sebastian Hack committed
40
#include "debug.h"
41
#include "fourcc.h"
Sebastian Hack's avatar
Sebastian Hack committed
42
#include "offset.h"
Sebastian Hack's avatar
Sebastian Hack committed
43
#include "bitfiddle.h"
Matthias Braun's avatar
Matthias Braun committed
44
#include "raw_bitset.h"
Sebastian Hack's avatar
Sebastian Hack committed
45
46
47
48

#include "irop_t.h"
#include "irmode_t.h"
#include "irnode_t.h"
49
#include "ircons_t.h"
50
#include "irprintf.h"
Sebastian Hack's avatar
Sebastian Hack committed
51
#include "irgwalk.h"
Michael Beck's avatar
Michael Beck committed
52
#include "iropt_t.h"
Sebastian Hack's avatar
Sebastian Hack committed
53

54
55
56
#include "be_t.h"
#include "belive_t.h"
#include "besched_t.h"
Sebastian Hack's avatar
Sebastian Hack committed
57
#include "benode_t.h"
58
#include "bearch_t.h"
Sebastian Hack's avatar
Sebastian Hack committed
59

60
61
#include "beirgmod.h"

Sebastian Hack's avatar
Sebastian Hack committed
62
63
#define OUT_POS(x) (-((x) + 1))

Matthias Braun's avatar
Matthias Braun committed
64
65
#define get_irn_attr(irn) get_irn_generic_attr(irn)
#define get_irn_attr_const(irn) get_irn_generic_attr_const(irn)
Daniel Grund's avatar
Daniel Grund committed
66

Sebastian Hack's avatar
Sebastian Hack committed
67
static unsigned be_node_tag = FOURCC('B', 'E', 'N', 'O');
68

Sebastian Hack's avatar
Sebastian Hack committed
69
70
typedef struct {
	arch_register_req_t req;
Sebastian Hack's avatar
Sebastian Hack committed
71
	arch_irn_flags_t    flags;
Sebastian Hack's avatar
Sebastian Hack committed
72
73
} be_req_t;

74
typedef struct {
75
	const arch_register_t *reg;
76
77
	be_req_t               req;
	be_req_t               in_req;
78
79
} be_reg_data_t;

80
/** The generic be nodes attribute type. */
81
typedef struct {
Michael Beck's avatar
Michael Beck committed
82
	be_reg_data_t *reg_data;
83
84
} be_node_attr_t;

85
86
/** The be_Return nodes attribute type. */
typedef struct {
Michael Beck's avatar
Michael Beck committed
87
	be_node_attr_t node_attr;     /**< base attributes of every be node. */
88
	int            num_ret_vals;  /**< number of return values */
89
	unsigned       pop;           /**< number of bytes that should be popped */
90
91
} be_return_attr_t;

Michael Beck's avatar
Michael Beck committed
92
/** The be_IncSP attribute type. */
Sebastian Hack's avatar
Sebastian Hack committed
93
typedef struct {
Michael Beck's avatar
Michael Beck committed
94
	be_node_attr_t node_attr;   /**< base attributes of every be node. */
95
96
97
	int            offset;      /**< The offset by which the stack shall be expanded/shrinked. */
	int            align;       /**< wether stack should be aligned after the
								     IncSP */
Michael Beck's avatar
Michael Beck committed
98
} be_incsp_attr_t;
Sebastian Hack's avatar
Sebastian Hack committed
99

100
/** The be_Frame attribute type. */
101
typedef struct {
102
103
104
	be_node_attr_t  node_attr;   /**< base attributes of every be node. */
	ir_entity      *ent;
	int             offset;
105
106
} be_frame_attr_t;

107
/** The be_Call attribute type. */
108
typedef struct {
109
110
111
112
	be_node_attr_t  node_attr;  /**< base attributes of every be node. */
	ir_entity      *ent;            /**< The called entity if this is a static call. */
	unsigned        pop;
	ir_type        *call_tp;          /**< The call type, copied from the original Call node. */
113
114
} be_call_attr_t;

115
typedef struct {
116
117
118
	be_node_attr_t   node_attr;  /**< base attributes of every be node. */
	ir_entity      **in_entities;
	ir_entity      **out_entities;
Matthias Braun's avatar
Matthias Braun committed
119
} be_memperm_attr_t;
120

121
122
123
ir_op *op_be_Spill;
ir_op *op_be_Reload;
ir_op *op_be_Perm;
Matthias Braun's avatar
Matthias Braun committed
124
ir_op *op_be_MemPerm;
125
126
ir_op *op_be_Copy;
ir_op *op_be_Keep;
Sebastian Hack's avatar
Sebastian Hack committed
127
ir_op *op_be_CopyKeep;
128
129
130
ir_op *op_be_Call;
ir_op *op_be_Return;
ir_op *op_be_IncSP;
Sebastian Hack's avatar
Sebastian Hack committed
131
ir_op *op_be_AddSP;
Michael Beck's avatar
Michael Beck committed
132
ir_op *op_be_SubSP;
133
134
ir_op *op_be_RegParams;
ir_op *op_be_FrameAddr;
135
ir_op *op_be_Barrier;
Michael Beck's avatar
Michael Beck committed
136
ir_op *op_be_Unwind;
Sebastian Hack's avatar
Sebastian Hack committed
137

Sebastian Hack's avatar
Sebastian Hack committed
138
static int beo_base = -1;
Sebastian Hack's avatar
Sebastian Hack committed
139

Sebastian Hack's avatar
Sebastian Hack committed
140
static const ir_op_ops be_node_op_ops;
Sebastian Hack's avatar
Sebastian Hack committed
141

142
143
144
145
146
147
148
149
150
151
#define N   irop_flag_none
#define L   irop_flag_labeled
#define C   irop_flag_commutative
#define X   irop_flag_cfopcode
#define I   irop_flag_ip_cfopcode
#define F   irop_flag_fragile
#define Y   irop_flag_forking
#define H   irop_flag_highlevel
#define c   irop_flag_constlike
#define K   irop_flag_keep
152
#define M   irop_flag_uses_memory
153

154

Michael Beck's avatar
Michael Beck committed
155
/**
Michael Beck's avatar
Michael Beck committed
156
 * Compare two be node attributes.
Michael Beck's avatar
Michael Beck committed
157
158
159
 *
 * @return zero if both attributes are identically
 */
Michael Beck's avatar
Michael Beck committed
160
static int _node_cmp_attr(const be_node_attr_t *a, const be_node_attr_t *b) {
161
162
	int i, len;

Michael Beck's avatar
Michael Beck committed
163
	if (ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
164
		return 1;
Michael Beck's avatar
Michael Beck committed
165

166
167
168
169
	len = ARR_LEN(a->reg_data);
	for (i = 0; i < len; ++i) {
		if (a->reg_data[i].reg != b->reg_data[i].reg ||
				memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
Michael Beck's avatar
Michael Beck committed
170
			    memcmp(&a->reg_data[i].req,    &b->reg_data[i].req,    sizeof(a->reg_data[i].req)))
171
			return 1;
Michael Beck's avatar
Michael Beck committed
172
	}
173
174

	return 0;
Michael Beck's avatar
Michael Beck committed
175
176
}

Michael Beck's avatar
Michael Beck committed
177
178
179
180
181
/**
 * Compare the node attributes of two be_node's.
 *
 * @return zero if both nodes have identically attributes
 */
182
static int node_cmp_attr(ir_node *a, ir_node *b) {
Michael Beck's avatar
Michael Beck committed
183
184
	const be_node_attr_t *a_attr = get_irn_attr_const(a);
	const be_node_attr_t *b_attr = get_irn_attr_const(b);
185
186
187
188

	return _node_cmp_attr(a_attr, b_attr);
}

Michael Beck's avatar
Michael Beck committed
189
/**
Michael Beck's avatar
Michael Beck committed
190
 * Compare the attributes of two be_FrameAddr nodes.
Michael Beck's avatar
Michael Beck committed
191
 *
Michael Beck's avatar
Michael Beck committed
192
 * @return zero if both nodes have identically attributes
Michael Beck's avatar
Michael Beck committed
193
 */
194
static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
Michael Beck's avatar
Michael Beck committed
195
196
	const be_frame_attr_t *a_attr = get_irn_attr_const(a);
	const be_frame_attr_t *b_attr = get_irn_attr_const(b);
Michael Beck's avatar
Michael Beck committed
197

198
199
200
	if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
		return 1;

Michael Beck's avatar
Michael Beck committed
201
	return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
202
203
}

Michael Beck's avatar
Michael Beck committed
204
205
206
207
208
/**
 * Compare the attributes of two be_Return nodes.
 *
 * @return zero if both nodes have identically attributes
 */
209
static int Return_cmp_attr(ir_node *a, ir_node *b) {
Michael Beck's avatar
Michael Beck committed
210
211
	const be_return_attr_t *a_attr = get_irn_attr_const(a);
	const be_return_attr_t *b_attr = get_irn_attr_const(b);
212
213
214

	if (a_attr->num_ret_vals != b_attr->num_ret_vals)
		return 1;
215
216
	if (a_attr->pop != b_attr->pop)
		return 1;
217

Michael Beck's avatar
Michael Beck committed
218
	return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
219
220
}

Michael Beck's avatar
Michael Beck committed
221
222
223
224
225
/**
 * Compare the attributes of two be_IncSP nodes.
 *
 * @return zero if both nodes have identically attributes
 */
226
static int IncSP_cmp_attr(ir_node *a, ir_node *b) {
Michael Beck's avatar
Michael Beck committed
227
228
	const be_incsp_attr_t *a_attr = get_irn_attr_const(a);
	const be_incsp_attr_t *b_attr = get_irn_attr_const(b);
229
230
231
232

	if (a_attr->offset != b_attr->offset)
		return 1;

Michael Beck's avatar
Michael Beck committed
233
	return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
234
235
}

Michael Beck's avatar
Michael Beck committed
236
237
238
239
240
/**
 * Compare the attributes of two be_Call nodes.
 *
 * @return zero if both nodes have identically attributes
 */
241
static int Call_cmp_attr(ir_node *a, ir_node *b) {
Michael Beck's avatar
Michael Beck committed
242
243
	const be_call_attr_t *a_attr = get_irn_attr_const(a);
	const be_call_attr_t *b_attr = get_irn_attr_const(b);
244
245
246
247
248

	if (a_attr->ent != b_attr->ent ||
			a_attr->call_tp != b_attr->call_tp)
		return 1;

Michael Beck's avatar
Michael Beck committed
249
	return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
Michael Beck's avatar
Michael Beck committed
250
251
}

Matthias Braun's avatar
Matthias Braun committed
252
253
254
static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
{
	int idx;
Matthias Braun's avatar
Matthias Braun committed
255
	const be_node_attr_t *attr;
Matthias Braun's avatar
Matthias Braun committed
256
257
258
	be_reg_data_t *rd;

	assert(is_be_node(node));
Matthias Braun's avatar
Matthias Braun committed
259
	attr = get_irn_attr_const(node);
Matthias Braun's avatar
Matthias Braun committed
260
261
262
263
264
265
266
267
268
269
270
271
272

	if(pos < 0) {
		idx = -(pos + 1);
	} else {
		idx = pos;
		assert(idx < get_irn_arity(node));
	}
	assert(idx < ARR_LEN(attr->reg_data));
	rd = &attr->reg_data[idx];

	return pos < 0 ? &rd->req : &rd->in_req;
}

273
static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
Matthias Braun's avatar
Matthias Braun committed
274
275
276
277
278
{
	be_req_t *bereq = get_be_req(node, pos);
	return &bereq->req;
}

Sebastian Hack's avatar
Sebastian Hack committed
279
280
void be_node_init(void) {
	static int inited = 0;
Sebastian Hack's avatar
Sebastian Hack committed
281

Sebastian Hack's avatar
Sebastian Hack committed
282
283
	if(inited)
		return;
Sebastian Hack's avatar
Sebastian Hack committed
284

Sebastian Hack's avatar
Sebastian Hack committed
285
	inited = 1;
Sebastian Hack's avatar
Sebastian Hack committed
286

287
	/* Acquire all needed opcodes. */
288
	beo_base = get_next_ir_opcodes(beo_Last);
Sebastian Hack's avatar
Sebastian Hack committed
289

290
291
292
293
294
295
296
297
298
299
300
	op_be_Spill      = new_ir_op(beo_base + beo_Spill,     "be_Spill",     op_pin_state_pinned, N,   oparity_unary,    0, sizeof(be_frame_attr_t),   &be_node_op_ops);
	op_be_Reload     = new_ir_op(beo_base + beo_Reload,    "be_Reload",    op_pin_state_pinned, N,   oparity_zero,     0, sizeof(be_frame_attr_t),   &be_node_op_ops);
	op_be_Perm       = new_ir_op(beo_base + beo_Perm,      "be_Perm",      op_pin_state_pinned, N,   oparity_variable, 0, sizeof(be_node_attr_t),    &be_node_op_ops);
	op_be_MemPerm    = new_ir_op(beo_base + beo_MemPerm,   "be_MemPerm",   op_pin_state_pinned, N,   oparity_variable, 0, sizeof(be_memperm_attr_t), &be_node_op_ops);
	op_be_Copy       = new_ir_op(beo_base + beo_Copy,      "be_Copy",      op_pin_state_floats, N,   oparity_unary,    0, sizeof(be_node_attr_t),    &be_node_op_ops);
	op_be_Keep       = new_ir_op(beo_base + beo_Keep,      "be_Keep",      op_pin_state_pinned, K,   oparity_dynamic,  0, sizeof(be_node_attr_t),    &be_node_op_ops);
	op_be_CopyKeep   = new_ir_op(beo_base + beo_CopyKeep,  "be_CopyKeep",  op_pin_state_pinned, K,   oparity_variable, 0, sizeof(be_node_attr_t),    &be_node_op_ops);
	op_be_Call       = new_ir_op(beo_base + beo_Call,      "be_Call",      op_pin_state_pinned, F|M, oparity_variable, 0, sizeof(be_call_attr_t),    &be_node_op_ops);
	op_be_Return     = new_ir_op(beo_base + beo_Return,    "be_Return",    op_pin_state_pinned, X,   oparity_dynamic,  0, sizeof(be_return_attr_t),  &be_node_op_ops);
	op_be_AddSP      = new_ir_op(beo_base + beo_AddSP,     "be_AddSP",     op_pin_state_pinned, N,   oparity_unary,    0, sizeof(be_node_attr_t),    &be_node_op_ops);
	op_be_SubSP      = new_ir_op(beo_base + beo_SubSP,     "be_SubSP",     op_pin_state_pinned, N,   oparity_unary,    0, sizeof(be_node_attr_t),    &be_node_op_ops);
Michael Beck's avatar
Michael Beck committed
301
	op_be_IncSP      = new_ir_op(beo_base + beo_IncSP,     "be_IncSP",     op_pin_state_pinned, N,   oparity_unary,    0, sizeof(be_incsp_attr_t),   &be_node_op_ops);
302
303
304
	op_be_RegParams  = new_ir_op(beo_base + beo_RegParams, "be_RegParams", op_pin_state_pinned, N,   oparity_zero,     0, sizeof(be_node_attr_t),    &be_node_op_ops);
	op_be_FrameAddr  = new_ir_op(beo_base + beo_FrameAddr, "be_FrameAddr", op_pin_state_floats, N,   oparity_unary,    0, sizeof(be_frame_attr_t),   &be_node_op_ops);
	op_be_Barrier    = new_ir_op(beo_base + beo_Barrier,   "be_Barrier",   op_pin_state_pinned, N,   oparity_dynamic,  0, sizeof(be_node_attr_t),    &be_node_op_ops);
Michael Beck's avatar
Michael Beck committed
305
	op_be_Unwind     = new_ir_op(beo_base + beo_Unwind,    "be_Unwind",    op_pin_state_pinned, X,   oparity_zero,     0, sizeof(be_node_attr_t),    &be_node_op_ops);
306
307

	set_op_tag(op_be_Spill,      &be_node_tag);
308
	op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
309
	set_op_tag(op_be_Reload,     &be_node_tag);
310
	op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
311
	set_op_tag(op_be_Perm,       &be_node_tag);
312
	op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
Matthias Braun's avatar
Matthias Braun committed
313
	set_op_tag(op_be_MemPerm,    &be_node_tag);
314
	op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
315
	set_op_tag(op_be_Copy,       &be_node_tag);
316
	op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
317
	set_op_tag(op_be_Keep,       &be_node_tag);
318
	op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
Sebastian Hack's avatar
Sebastian Hack committed
319
	set_op_tag(op_be_CopyKeep,   &be_node_tag);
320
	op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
321
	set_op_tag(op_be_Call,       &be_node_tag);
322
	op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
323
	set_op_tag(op_be_Return,     &be_node_tag);
324
	op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
Sebastian Hack's avatar
Sebastian Hack committed
325
	set_op_tag(op_be_AddSP,      &be_node_tag);
326
	op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
Michael Beck's avatar
Michael Beck committed
327
	set_op_tag(op_be_SubSP,      &be_node_tag);
328
	op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
329
	set_op_tag(op_be_IncSP,      &be_node_tag);
Michael Beck's avatar
Michael Beck committed
330
	op_be_IncSP->ops.node_cmp_attr = IncSP_cmp_attr;
331
	set_op_tag(op_be_RegParams,  &be_node_tag);
332
	op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
333
	set_op_tag(op_be_FrameAddr,  &be_node_tag);
Michael Beck's avatar
Michael Beck committed
334
	op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
335
336
	set_op_tag(op_be_Barrier,    &be_node_tag);
	op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
Michael Beck's avatar
Michael Beck committed
337
338
	set_op_tag(op_be_Unwind,     &be_node_tag);
	op_be_Unwind->ops.node_cmp_attr = node_cmp_attr;
Sebastian Hack's avatar
Sebastian Hack committed
339
}
340

341
342
343
/**
 * Initializes the generic attribute of all be nodes and return ir.
 */
344
static void *init_node_attr(ir_node *node, int max_reg_data)
Sebastian Hack's avatar
Sebastian Hack committed
345
{
346
	ir_graph *irg = get_irn_irg(node);
347
	struct obstack *obst = get_irg_obstack(irg);
348
	be_node_attr_t *a = get_irn_attr(node);
Sebastian Hack's avatar
Sebastian Hack committed
349

350
	memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
Sebastian Hack's avatar
Sebastian Hack committed
351

352
353
	if(max_reg_data >= 0) {
		a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
Sebastian Hack's avatar
Sebastian Hack committed
354
		memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
355
356
	} else {
		a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
Sebastian Hack's avatar
Sebastian Hack committed
357
358
359
360
	}

	return a;
}
361

362
363
364
365
366
367
368
369
static void add_register_req(ir_node *node)
{
	be_node_attr_t *a = get_irn_attr(node);
	be_reg_data_t regreq;
	memset(&regreq, 0, sizeof(regreq));
	ARR_APP1(be_reg_data_t, a->reg_data, regreq);
}

370
int is_be_node(const ir_node *irn)
371
{
Sebastian Hack's avatar
Sebastian Hack committed
372
	return get_op_tag(get_irn_op(irn)) == &be_node_tag;
373
374
}

Sebastian Hack's avatar
Sebastian Hack committed
375
be_opcode_t be_get_irn_opcode(const ir_node *irn)
376
{
377
	return is_be_node(irn) ? (be_opcode_t) get_irn_opcode(irn) - beo_base : beo_NoBeOp;
378
379
}

Michael Beck's avatar
Michael Beck committed
380
381
382
383
384
385
386
387
388
389
/**
 * Skip Proj nodes and return their Proj numbers.
 *
 * If *node is a Proj or Proj(Proj) node, skip it.
 *
 * @param node  points to the node to be skipped
 *
 * @return 0 if *node was no Proj node, its Proj number else.
 */
static int redir_proj(const ir_node **node)
Sebastian Hack's avatar
Sebastian Hack committed
390
391
392
393
{
	const ir_node *n = *node;

	if(is_Proj(n)) {
394
395
396
397
398
399
400
		ir_node *irn;

		*node = irn = get_Proj_pred(n);
		if(is_Proj(irn)) {
			assert(get_irn_mode(irn) == mode_T);
			*node = get_Proj_pred(irn);
		}
Sebastian Hack's avatar
Sebastian Hack committed
401
402
403
404
405
406
		return get_Proj_proj(n);
	}

	return 0;
}

Matthias Braun's avatar
Matthias Braun committed
407
static be_reg_data_t *retrieve_reg_data(const ir_node *node)
Sebastian Hack's avatar
Sebastian Hack committed
408
{
Matthias Braun's avatar
Matthias Braun committed
409
	const be_node_attr_t *attr;
Matthias Braun's avatar
Matthias Braun committed
410
	int pos = 0;
Sebastian Hack's avatar
Sebastian Hack committed
411

Matthias Braun's avatar
Matthias Braun committed
412
413
414
	if(is_Proj(node)) {
		pos = get_Proj_proj(node);
		node = get_Proj_pred(node);
Sebastian Hack's avatar
Sebastian Hack committed
415
416
	}

Matthias Braun's avatar
Matthias Braun committed
417
	assert(is_be_node(node));
Matthias Braun's avatar
Matthias Braun committed
418
	attr = get_irn_attr_const(node);
Matthias Braun's avatar
Matthias Braun committed
419
	assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
Sebastian Hack's avatar
Sebastian Hack committed
420

Matthias Braun's avatar
Matthias Braun committed
421
	return &attr->reg_data[pos];
Sebastian Hack's avatar
Sebastian Hack committed
422
423
}

Sebastian Hack's avatar
Sebastian Hack committed
424
static void
425
be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
Sebastian Hack's avatar
Sebastian Hack committed
426
{
Sebastian Hack's avatar
Sebastian Hack committed
427
	be_reg_data_t *r = retrieve_reg_data(irn);
428
	(void) self;
Matthias Braun's avatar
Matthias Braun committed
429
	r->reg = reg;
Sebastian Hack's avatar
Sebastian Hack committed
430
431
}

432
433
ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
	ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
434
{
Matthias Braun's avatar
Matthias Braun committed
435
	be_frame_attr_t *a;
436
	ir_node         *in[2];
437
	ir_node         *res;
438

439
440
441
	in[0]     = frame;
	in[1]     = to_spill;
	res       = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
442
443
	a         = init_node_attr(res, 2);
	a->ent    = NULL;
Matthias Braun's avatar
Matthias Braun committed
444
	a->offset = 0;
Sebastian Hack's avatar
Sebastian Hack committed
445

446
	be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
447
	be_node_set_reg_class(res, be_pos_Spill_val, cls);
Sebastian Hack's avatar
Sebastian Hack committed
448
449
	return res;
}
450

451
452
ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
	ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
453
{
454
455
456
457
458
459
460
	ir_node *in[2];
	ir_node *res;

	in[0] = frame;
	in[1] = mem;
	res   = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);

Sebastian Hack's avatar
Sebastian Hack committed
461
462
	init_node_attr(res, 2);
	be_node_set_reg_class(res, -1, cls);
463
	be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
464
	be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
Sebastian Hack's avatar
Sebastian Hack committed
465
466
	return res;
}
467

468
ir_node *be_get_Reload_mem(const ir_node *irn)
Sebastian Hack's avatar
Sebastian Hack committed
469
470
{
	assert(be_is_Reload(irn));
Daniel Grund's avatar
Daniel Grund committed
471
	return get_irn_n(irn, be_pos_Reload_mem);
Sebastian Hack's avatar
Sebastian Hack committed
472
473
}

474
475
476
477
478
479
ir_node *be_get_Reload_frame(const ir_node *irn)
{
	assert(be_is_Reload(irn));
	return get_irn_n(irn, be_pos_Reload_frame);
}

480
481
482
483
484
ir_node *be_get_Spill_val(const ir_node *irn)
{
	assert(be_is_Spill(irn));
	return get_irn_n(irn, be_pos_Spill_val);
}
Matthias Braun's avatar
Matthias Braun committed
485

486
487
488
489
490
ir_node *be_get_Spill_frame(const ir_node *irn)
{
	assert(be_is_Spill(irn));
	return get_irn_n(irn, be_pos_Spill_frame);
}
491

Sebastian Hack's avatar
Sebastian Hack committed
492
493
ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
{
Sebastian Hack's avatar
Sebastian Hack committed
494
	int i;
495
	ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
Sebastian Hack's avatar
Sebastian Hack committed
496
497
498
499
500
501
	init_node_attr(irn, n);
	for(i = 0; i < n; ++i) {
		be_node_set_reg_class(irn, i, cls);
		be_node_set_reg_class(irn, OUT_POS(i), cls);
	}

Sebastian Hack's avatar
Sebastian Hack committed
502
503
	return irn;
}
504

505
506
507
void be_Perm_reduce(ir_node *perm, int new_size, int *map)
{
	ir_graph *irg           = get_irn_irg(perm);
508
509
	int            arity    = get_irn_arity(perm);
	be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0]));
510
	be_node_attr_t *attr    = get_irn_attr(perm);
511
	ir_node **new_in        = NEW_ARR_D(ir_node *, irg->obst, new_size);
512
513
514
515

	int i;

	assert(be_is_Perm(perm));
516
	assert(new_size <= arity);
517
518

	/* save the old register data */
519
	memcpy(old_data, attr->reg_data, arity * sizeof(old_data[0]));
520
521

	/* compose the new in array and set the new register data directly in place */
522
	for (i = 0; i < new_size; ++i) {
523
		int idx = map[i];
524
525
		new_in[i]         = get_irn_n(perm, idx);
		attr->reg_data[i] = old_data[idx];
526
527
528
529
530
	}

	set_irn_in(perm, new_size, new_in);
}

Matthias Braun's avatar
Matthias Braun committed
531
532
533
534
535
ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
{
	int i;
	ir_node *frame = get_irg_frame(irg);
	const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
536
537
	ir_node *irn;
	const arch_register_t *sp = arch_env->isa->sp;
Matthias Braun's avatar
Matthias Braun committed
538
	be_memperm_attr_t *attr;
539
	ir_node **real_in;
Matthias Braun's avatar
Matthias Braun committed
540

541
542
543
544
545
546
547
548
	real_in = alloca((n+1) * sizeof(real_in[0]));
	real_in[0] = frame;
	memcpy(&real_in[1], in, n * sizeof(real_in[0]));

	irn =  new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);

	init_node_attr(irn, n + 1);
	be_node_set_reg_class(irn, 0, sp->reg_class);
Michael Beck's avatar
Michael Beck committed
549
	for (i = 0; i < n; ++i) {
550
		be_node_set_reg_class(irn, i + 1, cls_frame);
Matthias Braun's avatar
Matthias Braun committed
551
552
553
554
555
		be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
	}

	attr = get_irn_attr(irn);

556
557
	attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
	memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
Matthias Braun's avatar
Matthias Braun committed
558
559
560
561
562
563
564
	attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
	memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));

	return irn;
}


Sebastian Hack's avatar
Sebastian Hack committed
565
566
567
568
ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
{
	ir_node *in[1];
	ir_node *res;
Matthias Braun's avatar
Matthias Braun committed
569
	arch_register_req_t *req;
570

Sebastian Hack's avatar
Sebastian Hack committed
571
	in[0] = op;
572
	res   = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
Sebastian Hack's avatar
Sebastian Hack committed
573
574
575
	init_node_attr(res, 1);
	be_node_set_reg_class(res, 0, cls);
	be_node_set_reg_class(res, OUT_POS(0), cls);
Matthias Braun's avatar
Matthias Braun committed
576
577
578
579

	req = get_req(res, OUT_POS(0));
	req->cls = cls;
	req->type = arch_register_req_type_should_be_same;
580
	req->other_same = 1U << 0;
Matthias Braun's avatar
Matthias Braun committed
581

Sebastian Hack's avatar
Sebastian Hack committed
582
	return res;
583
584
}

585
586
587
588
ir_node *be_get_Copy_op(const ir_node *cpy) {
	return get_irn_n(cpy, be_pos_Copy_op);
}

589
590
591
592
void be_set_Copy_op(ir_node *cpy, ir_node *op) {
	set_irn_n(cpy, be_pos_Copy_op, op);
}

Sebastian Hack's avatar
Sebastian Hack committed
593
ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
Sebastian Hack's avatar
Sebastian Hack committed
594
{
Sebastian Hack's avatar
Sebastian Hack committed
595
	int i;
596
597
598
599
	ir_node *res;

	res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
	init_node_attr(res, -1);
Sebastian Hack's avatar
Sebastian Hack committed
600

Sebastian Hack's avatar
Sebastian Hack committed
601
	for(i = 0; i < n; ++i) {
602
603
604
		add_irn_n(res, in[i]);
		add_register_req(res);
		be_node_set_reg_class(res, i, cls);
Sebastian Hack's avatar
Sebastian Hack committed
605
	}
606
607
608
609
610
611
612
613
614
615
616
617
618
	keep_alive(res);

	return res;
}

void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
{
	int n;

	assert(be_is_Keep(keep));
	n = add_irn_n(keep, node);
	add_register_req(keep);
	be_node_set_reg_class(keep, n, cls);
Sebastian Hack's avatar
Sebastian Hack committed
619
620
}

Michael Beck's avatar
Michael Beck committed
621
/* creates a be_Call */
622
623
ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
                     int n_outs, int n, ir_node *in[], ir_type *call_tp)
Sebastian Hack's avatar
Sebastian Hack committed
624
{
625
626
	be_call_attr_t *a;
	int real_n = be_pos_Call_first_arg + n;
Sebastian Hack's avatar
Sebastian Hack committed
627
628
	ir_node *irn;
	ir_node **real_in;
Sebastian Hack's avatar
Sebastian Hack committed
629

630
631
632
633
634
	NEW_ARR_A(ir_node *, real_in, real_n);
	real_in[be_pos_Call_mem] = mem;
	real_in[be_pos_Call_sp]  = sp;
	real_in[be_pos_Call_ptr] = ptr;
	memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
Sebastian Hack's avatar
Sebastian Hack committed
635

636
	irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
637
638
639
	a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
	a->ent     = NULL;
	a->call_tp = call_tp;
Matthias Braun's avatar
Matthias Braun committed
640
	a->pop     = 0;
Sebastian Hack's avatar
Sebastian Hack committed
641
	return irn;
Sebastian Hack's avatar
Sebastian Hack committed
642
643
}

644
/* Gets the call entity or NULL if this is no static call. */
645
ir_entity *be_Call_get_entity(const ir_node *call) {
Matthias Braun's avatar
Matthias Braun committed
646
	const be_call_attr_t *a = get_irn_attr_const(call);
647
648
649
650
	assert(be_is_Call(call));
	return a->ent;
}

651
/* Sets the call entity. */
652
void be_Call_set_entity(ir_node *call, ir_entity *ent) {
653
654
655
656
657
	be_call_attr_t *a = get_irn_attr(call);
	assert(be_is_Call(call));
	a->ent = ent;
}

658
659
/* Gets the call type. */
ir_type *be_Call_get_type(ir_node *call) {
Matthias Braun's avatar
Matthias Braun committed
660
	const be_call_attr_t *a = get_irn_attr_const(call);
661
662
663
664
665
666
667
668
669
670
671
	assert(be_is_Call(call));
	return a->call_tp;
}

/* Sets the call type. */
void be_Call_set_type(ir_node *call, ir_type *call_tp) {
	be_call_attr_t *a = get_irn_attr(call);
	assert(be_is_Call(call));
	a->call_tp = call_tp;
}

Matthias Braun's avatar
Matthias Braun committed
672
673
674
675
676
677
678
679
680
681
void be_Call_set_pop(ir_node *call, unsigned pop) {
	be_call_attr_t *a = get_irn_attr(call);
	a->pop = pop;
}

unsigned be_Call_get_pop(const ir_node *call) {
	const be_call_attr_t *a = get_irn_attr_const(call);
	return a->pop;
}

682
/* Construct a new be_Return. */
683
ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
684
                       unsigned pop, int n, ir_node *in[])
Sebastian Hack's avatar
Sebastian Hack committed
685
{
686
	be_return_attr_t *a;
687
688
689
690
691
692
693
694
695
696
697
	ir_node *res;
	int i;

	res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
	init_node_attr(res, -1);
	for(i = 0; i < n; ++i) {
		add_irn_n(res, in[i]);
		add_register_req(res);
	}

	a = get_irn_attr(res);
698
	a->num_ret_vals = n_res;
699
	a->pop          = pop;
Sebastian Hack's avatar
Sebastian Hack committed
700

701
	return res;
Sebastian Hack's avatar
Sebastian Hack committed
702
703
}

704
/* Returns the number of real returns values */
705
int be_Return_get_n_rets(const ir_node *ret)
706
{
707
	const be_return_attr_t *a = get_irn_generic_attr_const(ret);
708
709
710
	return a->num_ret_vals;
}

711
712
713
714
715
716
unsigned be_Return_get_pop(const ir_node *ret)
{
	const be_return_attr_t *a = get_irn_generic_attr_const(ret);
	return a->pop;
}

717
718
719
720
721
722
723
724
725
726
int be_Return_append_node(ir_node *ret, ir_node *node)
{
	int pos;

	pos = add_irn_n(ret, node);
	add_register_req(ret);

	return pos;
}

727
728
ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl,
                      ir_node *old_sp, int offset, int align)
Sebastian Hack's avatar
Sebastian Hack committed
729
{
Michael Beck's avatar
Michael Beck committed
730
	be_incsp_attr_t *a;
Sebastian Hack's avatar
Sebastian Hack committed
731
	ir_node *irn;
Sebastian Hack's avatar
Sebastian Hack committed
732
	ir_node *in[1];
Sebastian Hack's avatar
Sebastian Hack committed
733
734

	in[0]     = old_sp;
735
736
	irn       = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode,
	                        sizeof(in) / sizeof(in[0]), in);
Sebastian Hack's avatar
Sebastian Hack committed
737
	a         = init_node_attr(irn, 1);
Sebastian Hack's avatar
Sebastian Hack committed
738
	a->offset = offset;
739
	a->align  = align;
Sebastian Hack's avatar
Sebastian Hack committed
740

741
	be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
Sebastian Hack's avatar
Sebastian Hack committed
742

Sebastian Hack's avatar
Sebastian Hack committed
743
	/* Set output constraint to stack register. */
Sebastian Hack's avatar
Sebastian Hack committed
744
	be_node_set_reg_class(irn, 0, sp->reg_class);
745
	be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
Sebastian Hack's avatar
Sebastian Hack committed
746
	be_node_set_irn_reg(NULL, irn, sp);
Sebastian Hack's avatar
Sebastian Hack committed
747
748

	return irn;
Sebastian Hack's avatar
Sebastian Hack committed
749
}
Sebastian Hack's avatar
Sebastian Hack committed
750

Sebastian Hack's avatar
Sebastian Hack committed
751
ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
Sebastian Hack's avatar
Sebastian Hack committed
752
{
Sebastian Hack's avatar
Sebastian Hack committed
753
	be_node_attr_t *a;
Sebastian Hack's avatar
Sebastian Hack committed
754
	ir_node *irn;
Sebastian Hack's avatar
Sebastian Hack committed
755
	ir_node *in[be_pos_AddSP_last];
756
	const arch_register_class_t *class;
Sebastian Hack's avatar
Sebastian Hack committed
757

Sebastian Hack's avatar
Sebastian Hack committed
758
759
	in[be_pos_AddSP_old_sp] = old_sp;
	in[be_pos_AddSP_size]   = sz;
Sebastian Hack's avatar
Sebastian Hack committed
760

761
762
	irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
	a   = init_node_attr(irn, be_pos_AddSP_last);
Sebastian Hack's avatar
Sebastian Hack committed
763

764
765
	be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
	                  arch_irn_flags_ignore | arch_irn_flags_modify_sp);
Sebastian Hack's avatar
Sebastian Hack committed
766
767

	/* Set output constraint to stack register. */
768
769
	be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
	be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
770
771
772
773
774
	be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
	a->reg_data[pn_be_AddSP_sp].reg = sp;

	class = arch_register_get_class(sp);
	be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
Sebastian Hack's avatar
Sebastian Hack committed
775
776
777
778

	return irn;
}

Michael Beck's avatar
Michael Beck committed
779
780
781
782
783
784
785
786
787
788
789
790
ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
{
	be_node_attr_t *a;
	ir_node *irn;
	ir_node *in[be_pos_SubSP_last];

	in[be_pos_SubSP_old_sp] = old_sp;
	in[be_pos_SubSP_size]   = sz;

	irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
	a   = init_node_attr(irn, be_pos_SubSP_last);

791
792
	be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
	                  arch_irn_flags_ignore | arch_irn_flags_modify_sp);
Michael Beck's avatar
Michael Beck committed
793
794
795
796

	/* Set output constraint to stack register. */
	be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
	be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
797
798
	be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
	a->reg_data[pn_be_SubSP_sp].reg = sp;
Michael Beck's avatar
Michael Beck committed
799
800
801
802

	return irn;
}

803
ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
Sebastian Hack's avatar
Sebastian Hack committed
804
{
805
806
	ir_node *res;
	int i;
Sebastian Hack's avatar
Sebastian Hack committed
807

808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
	res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
	init_node_attr(res, -1);
	for(i = 0; i < n_outs; ++i)
		add_register_req(res);

	return res;
}

ir_node *be_RegParams_append_out_reg(ir_node *regparams,
                                     const arch_env_t *arch_env,
                                     const arch_register_t *reg)
{
	ir_graph *irg = get_irn_irg(regparams);
	ir_node *block = get_nodes_block(regparams);
	be_node_attr_t *attr = get_irn_attr(regparams);
	const arch_register_class_t *cls = arch_register_get_class(reg);
	ir_mode *mode = arch_register_class_mode(cls);
	int n = ARR_LEN(attr->reg_data);
Michael Beck's avatar
Michael Beck committed
826
	ir_node *proj;
827
828

	assert(be_is_RegParams(regparams));
Michael Beck's avatar
Michael Beck committed
829
	proj = new_r_Proj(irg, block, regparams, mode, n);
830
	add_register_req(regparams);
831
	be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
832
833
	arch_set_irn_register(arch_env, proj, reg);

Michael Beck's avatar
Michael Beck committed
834
	/* TODO decide, whether we need to set ignore/modify sp flags here? */
835
836

	return proj;
Sebastian Hack's avatar
Sebastian Hack committed
837
838
}

839
ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
Sebastian Hack's avatar
Sebastian Hack committed
840
{
841
	be_frame_attr_t *a;
Sebastian Hack's avatar
Sebastian Hack committed
842
843
844
	ir_node *irn;
	ir_node *in[1];

845
	in[0]  = frame;
846
	irn    = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
Sebastian Hack's avatar
Sebastian Hack committed
847
	a      = init_node_attr(irn, 1);
848
849
850
	a->ent = ent;
	a->offset = 0;
	be_node_set_reg_class(irn, 0, cls_frame);
Sebastian Hack's avatar
Sebastian Hack committed
851
	be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
Michael Beck's avatar
Michael Beck committed
852
853

	return optimize_node(irn);
Sebastian Hack's avatar
Sebastian Hack committed
854
855
}

Matthias Braun's avatar
Matthias Braun committed
856
ir_node *be_get_FrameAddr_frame(const ir_node *node) {
Michael Beck's avatar
Michael Beck committed
857
858
859
860
	assert(be_is_FrameAddr(node));
	return get_irn_n(node, be_pos_FrameAddr_ptr);
}

Matthias Braun's avatar
Matthias Braun committed
861
862
863
864
865
866
ir_entity *be_get_FrameAddr_entity(const ir_node *node)
{
	const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
	return attr->ent;
}

Sebastian Hack's avatar
Sebastian Hack committed
867
868
869
870
871
872
873
874
ir_node *be_new_CopyKeep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *src, int n, ir_node *in_keep[], ir_mode *mode)
{
	ir_node *irn;
	ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));

	in[0] = src;
	memcpy(&in[1], in_keep, n * sizeof(in[0]));
	irn   = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
Sebastian Hack's avatar
Sebastian Hack committed
875
	init_node_attr(irn, n + 1);
Sebastian Hack's avatar
Sebastian Hack committed
876
877
878
879
880
881
882
883
	be_node_set_reg_class(irn, OUT_POS(0), cls);
	be_node_set_reg_class(irn, 0, cls);

	return irn;
}

ir_node *be_new_CopyKeep_single(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *src, ir_node *keep, ir_mode *mode)
{
Michael Beck's avatar
Michael Beck committed
884
	return be_new_CopyKeep(cls, irg, bl, src, 1, &keep, mode);
Sebastian Hack's avatar
Sebastian Hack committed
885
886
}

887
888
889
890
891
892
893
894
ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
	return get_irn_n(cpy, be_pos_CopyKeep_op);
}

void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
	set_irn_n(cpy, be_pos_CopyKeep_op, op);
}

895
ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
Sebastian Hack's avatar
Sebastian Hack committed
896
{
897
898
	ir_node *res;
	int i;
Sebastian Hack's avatar
Sebastian Hack committed
899

900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
	res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
	init_node_attr(res, -1);
	for(i = 0; i < n; ++i) {
		add_irn_n(res, in[i]);
		add_register_req(res);
	}

	return res;
}

ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
{
	ir_graph *irg = get_irn_irg(barrier);
	ir_node *block = get_nodes_block(barrier);
	ir_mode *mode = get_irn_mode(node);
	int n = add_irn_n(barrier, node);
916