arm_transform.c 37.1 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
21
/**
 * @file
Michael Beck's avatar
Michael Beck committed
22
23
 * @brief   The codegenerator (transform FIRM into arm FIRM)
 * @author  Oliver Richter, Tobias Gneist, Michael Beck
24
25
 * @version $Id$
 */
26
27
28
29
30
31
32
33
34
35
36
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "irnode_t.h"
#include "irgraph_t.h"
#include "irmode_t.h"
#include "irgmod.h"
#include "iredges.h"
#include "irvrfy.h"
#include "ircons.h"
Michael Beck's avatar
Michael Beck committed
37
#include "irprintf.h"
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "dbginfo.h"
#include "iropt_t.h"
#include "debug.h"

#include "../benode_t.h"
#include "bearch_arm_t.h"

#include "arm_nodes_attr.h"
#include "../arch/archop.h"     /* we need this for Min and Max nodes */
#include "arm_transform.h"
#include "arm_new_nodes.h"
#include "arm_map_regs.h"

#include "gen_arm_regalloc_if.h"

#include <limits.h>

Michael Beck's avatar
Michael Beck committed
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
extern ir_op *get_op_Mulh(void);



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

typedef struct vals_ {
Michael Beck's avatar
Michael Beck committed
71
72
73
	int ops;
	unsigned char values[4];
	unsigned char shifts[4];
74
75
} vals;

76
77
78
79
80
81
82
83
/** Execute ROL. */
static unsigned do_rol(unsigned v, unsigned rol) {
	return (v << rol) | (v >> (32 - rol));
}

/**
 * construct 8bit values und rot amounts for a value
 */
Michael Beck's avatar
Michael Beck committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
static void gen_vals_from_word(unsigned int value, vals *result)
{
	int initial = 0;

	memset(result, 0, sizeof(*result));

	/* special case: we prefer shift amount 0 */
	if (value < 0x100) {
		result->values[0] = value;
		result->ops       = 1;
		return;
	}

	while (value != 0) {
		if (value & 0xFF) {
			unsigned v = do_rol(value, 8) & 0xFFFFFF;
			int shf = 0;
			for (;;) {
				if ((v & 3) != 0)
					break;
				shf += 2;
				v >>= 2;
			}
			v  &= 0xFF;
			shf = (initial + shf - 8) & 0x1F;
			result->values[result->ops] = v;
			result->shifts[result->ops] = shf;
			++result->ops;

			value ^= do_rol(v, shf) >> initial;
		}
		else {
			value >>= 8;
			initial += 8;
		}
	}
120
121
}

Michael Beck's avatar
Michael Beck committed
122
123
124
/**
 * Creates a arm_Const node.
 */
125
126
127
128
static ir_node *create_const_node(ir_node *irn, ir_node *block, long value) {
	tarval *tv = new_tarval_from_long(value, mode_Iu);
	dbg_info *dbg = get_irn_dbg_info(irn);
	return new_rd_arm_Mov_i(dbg, current_ir_graph, block, get_irn_mode(irn), tv);
129
130
}

Michael Beck's avatar
Michael Beck committed
131
132
133
/**
 * Creates a arm_Const_Neg node.
 */
134
135
136
137
static ir_node *create_const_neg_node(ir_node *irn, ir_node *block, long value) {
	tarval *tv = new_tarval_from_long(value, mode_Iu);
	dbg_info *dbg = get_irn_dbg_info(irn);
	return new_rd_arm_Mvn_i(dbg, current_ir_graph, block, get_irn_mode(irn), tv);
138
139
}

140
#define NEW_BINOP_NODE(opname, env, op1, op2) new_rd_arm_##opname(env->dbg, current_ir_graph, env->block, op1, op2, env->mode)
141

Michael Beck's avatar
Michael Beck committed
142
143
144
145
/**
 * Encodes an immediate with shifter operand
 */
static unsigned int arm_encode_imm_w_shift(unsigned int shift, unsigned int immediate) {
146
147
148
	return immediate | ((shift>>1)<<8);
}

Michael Beck's avatar
Michael Beck committed
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
 * Decode an immediate with shifter operand
 */
unsigned int arm_decode_imm_w_shift(tarval *tv) {
	unsigned l = get_tarval_long(tv);
	unsigned rol = (l & ~0xFF) >> 7;

	return do_rol(l & 0xFF, rol);
}

/**
 * Creates a possible DAG for an constant.
 */
162
static ir_node *create_const_graph_value(ir_node *irn, ir_node *block, unsigned int value) {
163
	ir_node *result;
Michael Beck's avatar
Michael Beck committed
164
165
	vals v, vn;
	int cnt;
166
167
	ir_mode *mode = get_irn_mode(irn);
	dbg_info *dbg = get_irn_dbg_info(irn);
168

Michael Beck's avatar
Michael Beck committed
169
170
171
172
173
	gen_vals_from_word(value, &v);
	gen_vals_from_word(~value, &vn);

	if (vn.ops < v.ops) {
		/* remove bits */
174
		result = create_const_neg_node(irn, block, arm_encode_imm_w_shift(vn.shifts[0], vn.values[0]));
Michael Beck's avatar
Michael Beck committed
175
176
177

		for (cnt = 1; cnt < vn.ops; ++cnt) {
			tarval *tv = new_tarval_from_long(arm_encode_imm_w_shift(vn.shifts[cnt], vn.values[cnt]), mode_Iu);
178
			ir_node *bic_i_node = new_rd_arm_Bic_i(dbg, current_ir_graph, block, result, mode, tv);
Michael Beck's avatar
Michael Beck committed
179
			result = bic_i_node;
180
181
		}
	}
Michael Beck's avatar
Michael Beck committed
182
183
	else {
		/* add bits */
184
		result = create_const_node(irn, block, arm_encode_imm_w_shift(v.shifts[0], v.values[0]));
Michael Beck's avatar
Michael Beck committed
185
186
187

		for (cnt = 1; cnt < v.ops; ++cnt) {
			tarval *tv = new_tarval_from_long(arm_encode_imm_w_shift(v.shifts[cnt], v.values[cnt]), mode_Iu);
188
			ir_node *orr_i_node = new_rd_arm_Or_i(dbg, current_ir_graph, block, result, mode, tv);
Michael Beck's avatar
Michael Beck committed
189
190
			result = orr_i_node;
		}
191
192
193
194
	}
	return result;
}

195
196
197
198
199
200
201
202
/**
 * Create a DAG constructing a given Const.
 *
 * @param irn  a Firm const
 */
static ir_node *create_const_graph(ir_node *irn, ir_node *block) {
	int value = get_tarval_long(get_Const_tarval(irn));
	return create_const_graph_value(irn, block, value);
203
204
205
}


Michael Beck's avatar
Michael Beck committed
206
207
208
/**
 * Creates code for a Firm Const node.
 */
209
210
211
212
213
214
static ir_node *gen_Const(ir_node *irn, arm_code_gen_t *cg) {
	ir_graph *irg = current_ir_graph;
	ir_node *block = get_nodes_block(irn);
	ir_mode *mode = get_irn_mode(irn);
	dbg_info *dbg = get_irn_dbg_info(irn);

Michael Beck's avatar
Michael Beck committed
215
216
217
218
219
220
221
222
	if (mode_is_float(mode)) {
		if (USE_FPA(cg->isa))
			return new_rd_arm_fpaConst(dbg, irg, block, mode, get_Const_tarval(irn));
		else if (USE_VFP(cg->isa))
			assert(mode != mode_E && "IEEE Extended FP not supported");
		assert(0 && "NYI");
	}
	else if (mode_is_reference(mode))
223
		return irn;
Michael Beck's avatar
Michael Beck committed
224
	return create_const_graph(irn, block);
225
226
}

227
228
static ir_node *gen_mask(ir_node *irn, ir_node *op, int result_bits) {
	ir_node *block = get_nodes_block(irn);
229
	unsigned mask_bits = (1 << result_bits) - 1;
230
231
232
	ir_node *mask_node = create_const_graph_value(irn, block, mask_bits);
	dbg_info *dbg = get_irn_dbg_info(irn);
	return new_rd_arm_And(dbg, current_ir_graph, block, op, mask_node, get_irn_mode(irn), ARM_SHF_NONE, NULL);
233
234
}

235
236
static ir_node *gen_sign_extension(ir_node *irn, ir_node *op, int result_bits) {
	ir_node *block = get_nodes_block(irn);
237
	int shift_width = 32 - result_bits;
238
239
240
241
242
	ir_graph *irg = current_ir_graph;
	ir_node *shift_const_node = create_const_graph_value(irn, block, shift_width);
	dbg_info *dbg = get_irn_dbg_info(irn);
	ir_node *lshift_node = new_rd_arm_Shl(dbg, irg, block, op, shift_const_node, get_irn_mode(op));
	ir_node *rshift_node = new_rd_arm_Shrs(dbg, irg, block, lshift_node, shift_const_node, get_irn_mode(irn));
243
244
245
	return rshift_node;
}

Michael Beck's avatar
Michael Beck committed
246
247
248
249
250
251
/**
 * Transforms a Conv node.
 *
 * @param env   The transformation environment
 * @return the created arm Conv node
 */
252
253
254
255
static ir_node *gen_Conv(ir_node *irn, arm_code_gen_t *cg) {
	ir_graph *irg = current_ir_graph;
	ir_node *block   = get_nodes_block(irn);
	ir_node *op      = get_Conv_op(irn);
256
	ir_mode *in_mode = get_irn_mode(op);
257
258
	ir_mode *out_mode = get_irn_mode(irn);
	dbg_info *dbg    = get_irn_dbg_info(irn);
259
260
261
262

	if (in_mode == out_mode)
		return op;

Michael Beck's avatar
Michael Beck committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
	if (mode_is_float(in_mode) || mode_is_float(out_mode)) {
		cg->have_fp = 1;

		if (USE_FPA(cg->isa)) {
			if (mode_is_float(in_mode)) {
				if (mode_is_float(out_mode)) {
					/* from float to float */
					return new_rd_arm_fpaMov(dbg, irg, block, op, out_mode);
				}
				else {
					/* from float to int */
					return new_rd_arm_fpaFix(dbg, irg, block, op, out_mode);
				}
			}
			else {
				/* from int to float */
				return new_rd_arm_fpaFlt(dbg, irg, block, op, out_mode);
			}
		}
		assert(0 && "NYI");
	}
	else { /* complete in gp registers */
		int in_bits  = get_mode_size_bits(in_mode);
286
		int out_bits = get_mode_size_bits(out_mode);
Michael Beck's avatar
Michael Beck committed
287
		int in_sign  = get_mode_sign(in_mode);
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
		int out_sign = get_mode_sign(out_mode);

		// 32 -> 32
			// NOPpen
		if (in_bits == out_bits && in_bits == 32)
			return op;

		// 16 -> 16
			// unsigned -> unsigned
				// NOP
			// unsigned -> signed
				// sign extension (31:16)=(15)
			// signed -> unsigned
				// maskieren (31:16)=0
			// signed -> signed
				// NOP
		if (in_bits == out_bits && out_bits < 32) {
			if (in_sign && !out_sign) {
306
				return gen_mask(irn, op, out_bits);
307
			} else {
308
				return gen_sign_extension(irn, op, out_bits);
309
310
311
312
313
314
315
316
317
318
319
320
321
322
			}
		}

		// 16 -> 32
			// unsigned -> unsigned
				// NOP
			// unsigned -> signed
				// NOP
			// signed -> unsigned
				// sign extension (31:16)=(15)
			// signed -> signed
				// sign extension (31:16)=(15)
		if (in_bits < out_bits) {
			if (in_sign) {
323
				return gen_sign_extension(irn, op, out_bits);
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
			} else {
				return op;
			}
		}

		// 32 -> 16
			// unsigned -> unsigned
				// maskieren (31:16)=0
			// unsigned -> signed
				// maskieren (31:16)=0
			// signed -> unsigned
				// maskieren (31:16)=0
			// signed -> signed
				// sign extension (erledigt auch maskieren) (31:16)=(15)
		if (in_bits > out_bits) {
			if (in_sign && out_sign) {
340
				return gen_sign_extension(irn, op, out_bits);
341
			} else {
342
				return gen_mask(irn, op, out_bits);
343
344
345
			}
		}
		assert(0 && "recheck integer conversion logic!");
346
		return irn;
347
	}
Michael Beck's avatar
Michael Beck committed
348
	return NULL;
349
350
}

Michael Beck's avatar
Michael Beck committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/**
 * Return true if an operand is a shifter operand
 */
static int is_shifter_operand(ir_node *n, arm_shift_modifier *pmod) {
	arm_shift_modifier mod = ARM_SHF_NONE;

	if (is_arm_Mov(n))
		mod = get_arm_shift_modifier(n);

	*pmod = mod;
	if (mod != ARM_SHF_NONE) {
		long v = get_tarval_long(get_arm_value(n));
		if (v < 32)
			return (int)v;
	}
	return 0;
}
368
369
370
371
372
373
374

/**
 * Creates an arm Add.
 *
 * @param env   The transformation environment
 * @return the created arm Add node
 */
375
376
static ir_node *gen_Add(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
Michael Beck's avatar
Michael Beck committed
377
378
	ir_node *op1 = get_Add_left(irn);
	ir_node *op2 = get_Add_right(irn);
379
380
	ir_mode *mode = get_irn_mode(irn);
	ir_graph *irg = current_ir_graph;
Michael Beck's avatar
Michael Beck committed
381
382
383
	ir_node *op3;
	int v;
	arm_shift_modifier mod;
384
	dbg_info *dbg = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
385

386
387
	if (mode_is_float(mode)) {
		cg->have_fp = 1;
Michael Beck's avatar
Michael Beck committed
388
389
390
391
392
393
		if (USE_FPA(cg->isa))
			return new_rd_arm_fpaAdd(dbg, irg, block, op1, op2, mode);
		else if (USE_VFP(cg->isa)) {
			assert(mode != mode_E && "IEEE Extended FP not supported");
		}
		assert(0 && "NYI");
394
	}
395
	if (mode_is_numP(mode)) {
Michael Beck's avatar
Michael Beck committed
396
		if (is_arm_Mov_i(op1))
397
			return new_rd_arm_Add_i(dbg, irg, block, op2, mode, get_arm_value(op1));
Michael Beck's avatar
Michael Beck committed
398
		if (is_arm_Mov_i(op2))
399
			return new_rd_arm_Add_i(dbg, irg, block, op1, mode, get_arm_value(op2));
Michael Beck's avatar
Michael Beck committed
400
401
402
403
404
405
406

		/* check for MLA */
		if (is_arm_Mul(op1) && get_irn_n_edges(op1) == 1) {
			op3 = op2;
			op2 = get_irn_n(op1, 1);
			op1 = get_irn_n(op1, 0);

407
			return new_rd_arm_Mla(dbg, irg, block, op1, op2, op3, mode);
Michael Beck's avatar
Michael Beck committed
408
409
410
411
412
413
		}
		if (is_arm_Mul(op2) && get_irn_n_edges(op2) == 1) {
			op3 = op1;
			op1 = get_irn_n(op2, 0);
			op2 = get_irn_n(op2, 1);

414
			return new_rd_arm_Mla(dbg, irg, block, op1, op2, op3, mode);
Michael Beck's avatar
Michael Beck committed
415
		}
416

Michael Beck's avatar
Michael Beck committed
417
418
419
420
		/* is the first a shifter */
		v = is_shifter_operand(op1, &mod);
		if (v) {
			op1 = get_irn_n(op1, 0);
421
			return new_rd_arm_Add(dbg, irg, block, op2, op1, mode, mod, new_tarval_from_long(v, mode_Iu));
Michael Beck's avatar
Michael Beck committed
422
423
424
425
426
		}
		/* is the second a shifter */
		v = is_shifter_operand(op2, &mod);
		if (v) {
			op2 = get_irn_n(op2, 0);
427
			return new_rd_arm_Add(dbg, irg, block, op1, op2, mode, mod, new_tarval_from_long(v, mode_Iu));
Michael Beck's avatar
Michael Beck committed
428
		}
429

Michael Beck's avatar
Michael Beck committed
430
		/* normal ADD */
431
		return new_rd_arm_Add(dbg, irg, block, op1, op2, mode, ARM_SHF_NONE, NULL);
Michael Beck's avatar
Michael Beck committed
432
433
434
435
436
	}

	assert(0 && "unknown mode for add");
	return NULL;
}
437
438
439
440

/**
 * Creates an arm Mul.
 *
Michael Beck's avatar
Michael Beck committed
441
 * @param env   The transformation environment
442
443
 * @return the created arm Mul node
 */
444
445
static ir_node *gen_Mul(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
Michael Beck's avatar
Michael Beck committed
446
447
	ir_node *op1 = get_Mul_left(irn);
	ir_node *op2 = get_Mul_right(irn);
448
449
450
	ir_mode *mode = get_irn_mode(irn);
	ir_graph *irg = current_ir_graph;
	dbg_info *dbg = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
451

452
453
	if (mode_is_float(mode)) {
		cg->have_fp = 1;
Michael Beck's avatar
Michael Beck committed
454
455
456
457
458
459
		if (USE_FPA(cg->isa))
			return new_rd_arm_fpaMul(dbg, irg, block, op1, op2, mode);
		else if (USE_VFP(cg->isa)) {
			assert(mode != mode_E && "IEEE Extended FP not supported");
		}
		assert(0 && "NYI");
460
	}
461
	return new_rd_arm_Mul(dbg, irg, block, op1, op2, mode);
462
463
464
}

/**
Michael Beck's avatar
Michael Beck committed
465
 * Creates an arm floating point Div.
466
 *
Michael Beck's avatar
Michael Beck committed
467
 * @param env   The transformation environment
468
469
 * @return the created arm fDiv node
 */
470
471
static ir_node *gen_Quot(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
Michael Beck's avatar
Michael Beck committed
472
473
	ir_node *op1 = get_Quot_left(irn);
	ir_node *op2 = get_Quot_right(irn);
474
475
	ir_mode *mode = get_irn_mode(irn);
	dbg_info *dbg = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
476

477
	assert(mode != mode_E && "IEEE Extended FP not supported");
478

Michael Beck's avatar
Michael Beck committed
479
480
481
482
483
484
485
486
487
	cg->have_fp = 1;
	if (USE_FPA(cg->isa))
		return new_rd_arm_fpaDiv(dbg, current_ir_graph, block, op1, op2, mode);
	else if (USE_VFP(cg->isa)) {
		assert(mode != mode_E && "IEEE Extended FP not supported");
	}
	assert(0 && "NYI");

	return NULL;
Michael Beck's avatar
Michael Beck committed
488
489
490
}

#define GEN_INT_OP(op) \
491
492
493
static ir_node *gen_ ## op(ir_node *irn, arm_code_gen_t *cg) { \
	ir_graph *irg = current_ir_graph; \
	ir_node *block = get_nodes_block(irn); \
Michael Beck's avatar
Michael Beck committed
494
495
496
497
	ir_node *op1 = get_ ## op ## _left(irn); \
	ir_node *op2 = get_ ## op ## _right(irn); \
	int v; \
	arm_shift_modifier mod; \
498
499
	ir_mode *mode = get_irn_mode(irn); \
	dbg_info *dbg = get_irn_dbg_info(irn); \
Michael Beck's avatar
Michael Beck committed
500
501
 \
	if (is_arm_Mov_i(op1)) \
502
		return new_rd_arm_ ## op ## _i(dbg, irg, block, op2, mode, get_arm_value(op1)); \
Michael Beck's avatar
Michael Beck committed
503
	if (is_arm_Mov_i(op2)) \
504
		return new_rd_arm_ ## op ## _i(dbg, irg, block, op1, mode, get_arm_value(op2)); \
Michael Beck's avatar
Michael Beck committed
505
506
507
508
	/* is the first a shifter */ \
	v = is_shifter_operand(op1, &mod); \
	if (v) { \
		op1 = get_irn_n(op1, 0); \
509
		return new_rd_arm_ ## op(dbg, irg, block, op2, op1, mode, mod, new_tarval_from_long(v, mode_Iu)); \
Michael Beck's avatar
Michael Beck committed
510
511
512
513
514
	} \
	/* is the second a shifter */ \
	v = is_shifter_operand(op2, &mod); \
	if (v) { \
		op2 = get_irn_n(op2, 0); \
515
		return new_rd_arm_ ## op(dbg, irg, block, op1, op2, mode, mod, new_tarval_from_long(v, mode_Iu)); \
Michael Beck's avatar
Michael Beck committed
516
517
	} \
	/* Normal op */ \
518
	return new_rd_arm_ ## op(dbg, irg, block, op1, op2, mode, ARM_SHF_NONE, NULL); \
519
520
521
522
523
524
}


/**
 * Creates an arm And.
 *
Michael Beck's avatar
Michael Beck committed
525
 * @param env   The transformation environment
526
527
 * @return the created arm And node
 */
528
static ir_node *gen_And(ir_node *irn, arm_code_gen_t *cg);
Michael Beck's avatar
Michael Beck committed
529
GEN_INT_OP(And)
530
531

/**
Michael Beck's avatar
Michael Beck committed
532
 * Creates an arm Orr.
533
 *
Michael Beck's avatar
Michael Beck committed
534
 * @param env   The transformation environment
535
536
 * @return the created arm Or node
 */
537
static ir_node *gen_Or(ir_node *irn, arm_code_gen_t *cg);
Michael Beck's avatar
Michael Beck committed
538
GEN_INT_OP(Or)
539
540
541
542

/**
 * Creates an arm Eor.
 *
Michael Beck's avatar
Michael Beck committed
543
 * @param env   The transformation environment
544
545
 * @return the created arm Eor node
 */
546
static ir_node *gen_Eor(ir_node *irn, arm_code_gen_t *cg);
Michael Beck's avatar
Michael Beck committed
547
GEN_INT_OP(Eor)
548
549
550
551

/**
 * Creates an arm Sub.
 *
Michael Beck's avatar
Michael Beck committed
552
 * @param env   The transformation environment
553
554
 * @return the created arm Sub node
 */
555
556
static ir_node *gen_Sub(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
Michael Beck's avatar
Michael Beck committed
557
558
559
560
	ir_node *op1 = get_Sub_left(irn);
	ir_node *op2 = get_Sub_right(irn);
	int v;
	arm_shift_modifier mod;
561
562
563
	ir_mode *mode = get_irn_mode(irn);
	ir_graph *irg = current_ir_graph;
	dbg_info *dbg = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
564

565
566
	if (mode_is_float(mode)) {
		cg->have_fp = 1;
Michael Beck's avatar
Michael Beck committed
567
568
569
570
571
572
		if (USE_FPA(cg->isa))
			return new_rd_arm_fpaSub(dbg, irg, block, op1, op2, mode);
		else if (USE_VFP(cg->isa)) {
			assert(mode != mode_E && "IEEE Extended FP not supported");
		}
		assert(0 && "NYI");
Michael Beck's avatar
Michael Beck committed
573
	}
574
	if (mode_is_numP(mode)) {
Michael Beck's avatar
Michael Beck committed
575
		if (is_arm_Mov_i(op1))
576
			return new_rd_arm_Rsb_i(dbg, irg, block, op2, mode, get_arm_value(op1));
Michael Beck's avatar
Michael Beck committed
577
		if (is_arm_Mov_i(op2))
578
			return new_rd_arm_Sub_i(dbg, irg, block, op1, mode, get_arm_value(op2));
Michael Beck's avatar
Michael Beck committed
579
580
581
582
583

		/* is the first a shifter */
		v = is_shifter_operand(op1, &mod);
		if (v) {
			op1 = get_irn_n(op1, 0);
584
			return new_rd_arm_Rsb(dbg, irg, block, op2, op1, mode, mod, new_tarval_from_long(v, mode_Iu));
585
		}
Michael Beck's avatar
Michael Beck committed
586
587
588
589
		/* is the second a shifter */
		v = is_shifter_operand(op2, &mod);
		if (v) {
			op2 = get_irn_n(op2, 0);
590
			return new_rd_arm_Sub(dbg, irg, block, op1, op2, mode, mod, new_tarval_from_long(v, mode_Iu));
Michael Beck's avatar
Michael Beck committed
591
592
		}
		/* normal sub */
593
		return new_rd_arm_Sub(dbg, irg, block, op1, op2, mode, ARM_SHF_NONE, NULL);
594
	}
Michael Beck's avatar
Michael Beck committed
595
596
	assert(0 && "unknown mode for sub");
	return NULL;
597
598
599
600
601
}

/**
 * Creates an arm Shl.
 *
Michael Beck's avatar
Michael Beck committed
602
 * @param env   The transformation environment
603
604
 * @return the created arm Shl node
 */
605
static ir_node *gen_Shl(ir_node *irn, arm_code_gen_t *cg) {
606
	ir_node *result;
607
	ir_node *block = get_nodes_block(irn);
Michael Beck's avatar
Michael Beck committed
608
609
	ir_node *op1 = get_Shl_left(irn);
	ir_node *op2 = get_Shl_right(irn);
610
611
612
	ir_mode *mode = get_irn_mode(irn);
	ir_graph *irg = current_ir_graph;
	dbg_info *dbg = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
613
614

	if (is_arm_Mov_i(op2)) {
615
		result = new_rd_arm_Mov(dbg, irg, block, op1, mode, ARM_SHF_LSL, get_arm_value(op2));
616
	} else {
617
		result = new_rd_arm_Shl(dbg, irg, block, op1, op2, mode);
618
619
620
621
622
623
624
	}
	return result;
}

/**
 * Creates an arm Shr.
 *
Michael Beck's avatar
Michael Beck committed
625
 * @param env   The transformation environment
626
627
 * @return the created arm Shr node
 */
628
static ir_node *gen_Shr(ir_node *irn, arm_code_gen_t *cg) {
629
	ir_node *result;
630
	ir_node *block = get_nodes_block(irn);
Michael Beck's avatar
Michael Beck committed
631
632
	ir_node *op1 = get_Shr_left(irn);
	ir_node *op2 = get_Shr_right(irn);
633
634
635
	ir_mode *mode = get_irn_mode(irn);
	ir_graph *irg = current_ir_graph;
	dbg_info *dbg = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
636
637

	if (is_arm_Mov_i(op2)) {
638
		result = new_rd_arm_Mov(dbg, irg, block, op1, mode, ARM_SHF_LSR, get_arm_value(op2));
639
	} else {
640
		result = new_rd_arm_Shr(dbg, irg, block, op1, op2, mode);
641
642
643
644
645
646
647
	}
	return result;
}

/**
 * Creates an arm Shrs.
 *
Michael Beck's avatar
Michael Beck committed
648
 * @param env   The transformation environment
649
650
 * @return the created arm Shrs node
 */
651
static ir_node *gen_Shrs(ir_node *irn, arm_code_gen_t *cg) {
652
	ir_node *result;
653
	ir_node *block = get_nodes_block(irn);
Michael Beck's avatar
Michael Beck committed
654
655
	ir_node *op1 = get_Shrs_left(irn);
	ir_node *op2 = get_Shrs_right(irn);
656
657
	ir_mode *mode = get_irn_mode(irn);
	dbg_info *dbg = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
658
659

	if (is_arm_Mov_i(op2)) {
660
		result = new_rd_arm_Mov(dbg, current_ir_graph, block, op1, mode, ARM_SHF_ASR, get_arm_value(op2));
661
	} else {
662
		result = new_rd_arm_Shrs(dbg, current_ir_graph, block, op1, op2, mode);
663
664
665
666
667
668
669
	}
	return result;
}

/**
 * Transforms a Not node.
 *
Michael Beck's avatar
Michael Beck committed
670
 * @param env   The transformation environment
671
672
 * @return the created arm Not node
 */
673
674
675
static ir_node *gen_Not(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
	ir_node *op = get_Not_op(irn);
Michael Beck's avatar
Michael Beck committed
676
677
678
	int v;
	arm_shift_modifier mod = ARM_SHF_NONE;
	tarval  *tv = NULL;
679
	dbg_info *dbg = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
680
681
682
683
684
685

	v = is_shifter_operand(op, &mod);
	if (v) {
		op = get_irn_n(op, 0);
		tv = new_tarval_from_long(v, mode_Iu);
	}
686
	return new_rd_arm_Mvn(dbg, current_ir_graph, block, op, get_irn_mode(irn), mod, tv);
687
688
}

Michael Beck's avatar
Michael Beck committed
689
690
691
692
693
694
/**
 * Transforms an Abs node.
 *
 * @param env   The transformation environment
 * @return the created arm Abs node
 */
695
696
697
698
699
static ir_node *gen_Abs(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
	ir_node *op = get_Abs_op(irn);
	ir_mode *mode = get_irn_mode(irn);
	dbg_info *dbg = get_irn_dbg_info(irn);
700

701
702
	if (mode_is_float(mode)) {
		cg->have_fp = 1;
Michael Beck's avatar
Michael Beck committed
703
704
705
706
707
708
		if (USE_FPA(cg->isa))
			return new_rd_arm_fpaAbs(dbg, current_ir_graph, block, op, mode);
		else if (USE_VFP(cg->isa)) {
			assert(mode != mode_E && "IEEE Extended FP not supported");
		}
		assert(0 && "NYI");
709
	}
710
	return new_rd_arm_Abs(dbg, current_ir_graph, block, op, mode);
711
712
713
714
715
}

/**
 * Transforms a Minus node.
 *
Michael Beck's avatar
Michael Beck committed
716
 * @param env   The transformation environment
717
718
 * @return the created arm Minus node
 */
719
720
721
722
723
724
static ir_node *gen_Minus(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
	ir_node *op = get_Minus_op(irn);
	ir_mode *mode = get_irn_mode(irn);
	ir_graph *irg = current_ir_graph;
	dbg_info *dbg = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
725

726
	if (mode_is_float(mode)) {
Michael Beck's avatar
Michael Beck committed
727
728
729
730
731
732
733
		cg->have_fp = 1;
		if (USE_FPA(cg->isa))
			return new_rd_arm_fpaMnv(dbg, irg, block, op, mode);
		else if (USE_VFP(cg->isa)) {
			assert(mode != mode_E && "IEEE Extended FP not supported");
		}
		assert(0 && "NYI");
734
	}
735
	return new_rd_arm_Rsb_i(dbg, irg, block, op, mode, get_mode_null(mode));
736
737
738
739
740
741
742
743
744
745
746
}

/**
 * Transforms a Load.
 *
 * @param mod     the debug module
 * @param block   the block the new node should belong to
 * @param node    the ir Load node
 * @param mode    node mode
 * @return the created arm Load node
 */
747
748
749
750
751
static ir_node *gen_Load(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
	ir_mode *mode = get_Load_mode(irn);
	ir_graph *irg = current_ir_graph;
	dbg_info *dbg = get_irn_dbg_info(irn);
752

Michael Beck's avatar
Michael Beck committed
753
	if (mode_is_float(mode)) {
754
		cg->have_fp = 1;
Michael Beck's avatar
Michael Beck committed
755
756
757
758
759
760
761
		if (USE_FPA(cg->isa))
			return new_rd_arm_fpaLdf(dbg, irg, block, get_Load_ptr(irn), get_Load_mem(irn),
				get_Load_mode(irn));
		else if (USE_VFP(cg->isa)) {
			assert(mode != mode_E && "IEEE Extended FP not supported");
		}
		assert(0 && "NYI");
762
763
	}
	if (mode == mode_Bu) {
Michael Beck's avatar
Michael Beck committed
764
		return new_rd_arm_Loadb(dbg, irg, block, get_Load_ptr(irn), get_Load_mem(irn));
765
766
	}
	if (mode == mode_Bs) {
Michael Beck's avatar
Michael Beck committed
767
		return new_rd_arm_Loadbs(dbg, irg, block, get_Load_ptr(irn), get_Load_mem(irn));
768
769
	}
	if (mode == mode_Hu) {
Michael Beck's avatar
Michael Beck committed
770
		return new_rd_arm_Loadh(dbg, irg, block, get_Load_ptr(irn), get_Load_mem(irn));
771
772
	}
	if (mode == mode_Hs) {
Michael Beck's avatar
Michael Beck committed
773
		return new_rd_arm_Loadhs(dbg, irg, block, get_Load_ptr(irn), get_Load_mem(irn));
774
775
	}
	if (mode_is_reference(mode)) {
Michael Beck's avatar
Michael Beck committed
776
		return new_rd_arm_Load(dbg, irg, block, get_Load_ptr(irn), get_Load_mem(irn));
777
	}
Michael Beck's avatar
Michael Beck committed
778
	return new_rd_arm_Load(dbg, irg, block, get_Load_ptr(irn), get_Load_mem(irn));
779
780
781
782
783
784
785
786
787
788
789
}

/**
 * Transforms a Store.
 *
 * @param mod     the debug module
 * @param block   the block the new node should belong to
 * @param node    the ir Store node
 * @param mode    node mode
 * @return the created arm Store node
 */
790
791
792
793
794
static ir_node *gen_Store(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
	ir_mode *mode = get_irn_mode(get_Store_value(irn));
	ir_graph *irg = current_ir_graph;
	dbg_info *dbg = get_irn_dbg_info(irn);
795

796
	assert(mode != mode_E && "IEEE Extended FP not supported");
Michael Beck's avatar
Michael Beck committed
797
	if (mode_is_float(mode)) {
798
		cg->have_fp = 1;
Michael Beck's avatar
Michael Beck committed
799
800
801
802
803
804
805
		if (USE_FPA(cg->isa))
			return new_rd_arm_fpaStf(dbg, irg, block, get_Store_ptr(irn), get_Store_value(irn),
				get_Store_mem(irn), get_irn_mode(get_Store_value(irn)));
		else if (USE_VFP(cg->isa)) {
			assert(mode != mode_E && "IEEE Extended FP not supported");
		}
		assert(0 && "NYI");
806
807
	}
	if (mode == mode_Bu) {
Michael Beck's avatar
Michael Beck committed
808
		return new_rd_arm_Storeb(dbg, irg, block, get_Store_ptr(irn), get_Store_value(irn), get_Store_mem(irn));
809
810
	}
	if (mode == mode_Bs) {
Michael Beck's avatar
Michael Beck committed
811
		return new_rd_arm_Storebs(dbg, irg, block, get_Store_ptr(irn), get_Store_value(irn), get_Store_mem(irn));
812
813
	}
	if (mode == mode_Hu) {
Michael Beck's avatar
Michael Beck committed
814
		return new_rd_arm_Storeh(dbg, irg, block, get_Store_ptr(irn), get_Store_value(irn), get_Store_mem(irn));
815
816
	}
	if (mode == mode_Hs) {
Michael Beck's avatar
Michael Beck committed
817
		return new_rd_arm_Storehs(dbg, irg, block, get_Store_ptr(irn), get_Store_value(irn), get_Store_mem(irn));
818
	}
Michael Beck's avatar
Michael Beck committed
819
	return new_rd_arm_Store(dbg, irg, block, get_Store_ptr(irn), get_Store_value(irn), get_Store_mem(irn));
820
821
822
}


823
static ir_node *gen_Cond(ir_node *irn, arm_code_gen_t *cg) {
Christian Würdig's avatar
Christian Würdig committed
824
	ir_node *result   = NULL;
825
826
827
828
	ir_node *selector = get_Cond_selector(irn);
	ir_node *block    = get_nodes_block(irn);
	ir_graph *irg     = current_ir_graph;
	dbg_info *dbg     = get_irn_dbg_info(irn);
Christian Würdig's avatar
Christian Würdig committed
829

830
831
832
833
834
835
	if ( get_irn_mode(selector) == mode_b ) {
		//CondJmp
		ir_node *proj_node = get_Cond_selector(irn);
		ir_node *cmp_node = get_Proj_pred(proj_node);
		ir_node *op1 = get_Cmp_left(cmp_node);
		ir_node *op2 = get_Cmp_right(cmp_node);
836
		result = new_rd_arm_CondJmp(dbg, irg, block, op1, op2, mode_T);
837
838
839
		set_arm_proj_num(result, get_Proj_proj(proj_node));
	} else {
		//SwitchJmp
840
		ir_node *op = get_irn_n(irn, 0);
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
		ir_node *const_graph;
		ir_node *sub;
		ir_node *const_node;

		ir_node *proj;
		const ir_edge_t *edge;
		int min = INT_MAX;
		int max = INT_MIN;
		int translation;
		int norm_max;
		int norm_min;
		int pn;
		int n_projs;
		ir_node **projs;

		foreach_out_edge(irn, edge) {
			proj = get_edge_src_irn(edge);
			assert(is_Proj(proj) && "Only proj allowed at SwitchJmp");

			pn = get_Proj_proj(proj);

			min = pn<min ? pn : min;
			max = pn>max ? pn : max;
		}
		translation = min;
		norm_max = max - translation;
		norm_min = min - translation;

		n_projs = norm_max + 1;
		projs = xcalloc(n_projs , sizeof(ir_node*));


		foreach_out_edge(irn, edge) {
			proj = get_edge_src_irn(edge);
			assert(is_Proj(proj) && "Only proj allowed at SwitchJmp");

			pn = get_Proj_proj(proj) - translation;
			set_Proj_proj(proj, pn);
		}


882
883
884
885
		const_node = new_rd_Const(dbg, irg, block, mode_Iu, new_tarval_from_long(translation, mode_Iu));
		const_graph = gen_Const(const_node, cg);
		sub = new_rd_arm_Sub(dbg, irg, block, op, const_graph, get_irn_mode(op), ARM_SHF_NONE, NULL);
		result = new_rd_arm_SwitchJmp(dbg, irg, block, sub, mode_T);
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
		set_arm_n_projs(result, n_projs);
		set_arm_default_proj_num(result, get_Cond_defaultProj(irn)-translation);
	}
	return result;
}

/**
 * Returns the name of a SymConst.
 * @param symc  the SymConst
 * @return name of the SymConst
 */
const char *get_sc_name(ir_node *symc) {
	if (get_irn_opcode(symc) != iro_SymConst)
		return "NONE";

	switch (get_SymConst_kind(symc)) {
		case symconst_addr_name:
			return get_id_str(get_SymConst_name(symc));

		case symconst_addr_ent:
			return get_entity_ld_name(get_SymConst_entity(symc));

		default:
			assert(0 && "Unsupported SymConst");
	}

	return NULL;
}

915
916
917
918
919
static ir_node *gen_SymConst(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block = get_nodes_block(irn);
	ir_mode *mode = get_irn_mode(irn);
	dbg_info *dbg = get_irn_dbg_info(irn);
	return new_rd_arm_SymConst(dbg, current_ir_graph, block, mode, get_sc_name(irn));
920
921
922
923
924
925
926
927
928
929
}



/**
 * Transforms a CopyB node.
 *
 * @param env   The transformation environment
 * @return The transformed node.
 */
930
static ir_node *gen_CopyB(ir_node *irn, arm_code_gen_t *cg) {
931
	ir_node  *res   = NULL;
932
933
934
935
936
937
938
939
	dbg_info *dbg   = get_irn_dbg_info(irn);
	ir_mode  *mode  = get_irn_mode(irn);
	ir_node  *src   = get_CopyB_src(irn);
	ir_node  *dst   = get_CopyB_dst(irn);
	ir_node  *mem   = get_CopyB_mem(irn);
	ir_node  *block = get_nodes_block(irn);
	int       size  = get_type_size_bytes(get_CopyB_type(irn));
	ir_graph *irg   = current_ir_graph;
940
941
942
	ir_node *src_copy;
	ir_node *dst_copy;

Michael Beck's avatar
Michael Beck committed
943
944
	src_copy = be_new_Copy(&arm_reg_classes[CLASS_arm_gp], irg, block, src);
	dst_copy = be_new_Copy(&arm_reg_classes[CLASS_arm_gp], irg, block, dst);
945
946
947
948
949
950
951
952
953
954
955

 	res = new_rd_arm_CopyB( dbg, irg, block, dst_copy, src_copy, new_rd_arm_EmptyReg(dbg, irg, block, mode_Iu), new_rd_arm_EmptyReg(dbg, irg, block, mode_Iu), new_rd_arm_EmptyReg(dbg, irg, block, mode_Iu), mem, mode);
	set_arm_value(res, new_tarval_from_long(size, mode_Iu));

	return res;
}





Michael Beck's avatar
Michael Beck committed
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
/********************************************
 *  _                          _
 * | |                        | |
 * | |__   ___ _ __   ___   __| | ___  ___
 * | '_ \ / _ \ '_ \ / _ \ / _` |/ _ \/ __|
 * | |_) |  __/ | | | (_) | (_| |  __/\__ \
 * |_.__/ \___|_| |_|\___/ \__,_|\___||___/
 *
 ********************************************/

/**
 * Return an expanding stack offset.
 * Note that function is called in the transform phase
 * where the stack offsets are still relative regarding
 * the first (frame allocating) IncSP.
 * However this is exactly what we want because frame
 * access must be done relative the the fist IncSP ...
 */
static int get_sp_expand_offset(ir_node *inc_sp) {
975
	int offset = be_get_IncSP_offset(inc_sp);
Michael Beck's avatar
Michael Beck committed
976

977
	if (offset == BE_STACK_FRAME_SIZE_EXPAND)
Michael Beck's avatar
Michael Beck committed
978
		return 0;
979
980

	return offset;
Michael Beck's avatar
Michael Beck committed
981
982
983
}

#if 0
Matthias Braun's avatar
Matthias Braun committed
984
static ir_node *gen_StackParam(ir_node *irn, arm_code_gen_t *cg) {
985
986
987
988
989
990
991
	ir_node   *new_op = NULL;
	ir_node   *block  = get_nodes_block(irn);
	ir_node   *noreg  = ia32_new_NoReg_gp(env->cg);
	ir_node   *mem    = new_rd_NoMem(env->irg);
	ir_node   *ptr    = get_irn_n(irn, 0);
	ir_entity *ent    = be_get_frame_entity(irn);
	ir_mode   *mode   = env->mode;
Michael Beck's avatar
Michael Beck committed
992
993
994
995
996
997
998
999
1000

//	/* If the StackParam has only one user ->     */
//	/* put it in the Block where the user resides */
//	if (get_irn_n_edges(node) == 1) {
//		env->block = get_nodes_block(get_edge_src_irn(get_irn_out_edge_first(node)));
//	}

	if (mode_is_float(mode)) {
		if (USE_SSE2(env->cg))
1001
			new_op = new_rd_ia32_fLoad(env->dbg, env->irg, block, ptr, noreg, mem, mode_T);
Michael Beck's avatar
Michael Beck committed
1002
1003
		else {
			env->cg->used_x87 = 1;
1004
			new_op = new_rd_ia32_vfld(env->dbg, env->irg, block, ptr, noreg, mem, mode_T);
Michael Beck's avatar
Michael Beck committed
1005
1006
1007
		}
	}
	else {
1008
		new_op = new_rd_ia32_Load(env->dbg, env->irg, block, ptr, noreg, mem, mode_T);
Michael Beck's avatar
Michael Beck committed
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
	}

	set_ia32_frame_ent(new_op, ent);
	set_ia32_use_frame(new_op);

	set_ia32_am_support(new_op, ia32_am_Source);
	set_ia32_op_type(new_op, ia32_AddrModeS);
	set_ia32_am_flavour(new_op, ia32_B);
	set_ia32_ls_mode(new_op, mode);

	SET_IA32_ORIG_NODE(new_op, ia32_get_old_node_name(env->cg, env->irn));

1021
	return new_rd_Proj(env->dbg, env->irg, block, new_op, mode, 0);
Michael Beck's avatar
Michael Beck committed
1022
}
Matthias Braun's avatar
Matthias Braun committed
1023
#endif
Michael Beck's avatar
Michael Beck committed
1024
1025
1026
1027

/**
 * Transforms a FrameAddr into an ia32 Add.
 */
1028
1029
static ir_node *gen_be_FrameAddr(ir_node *irn, arm_code_gen_t *cg) {
	ir_node *block  = get_nodes_block(irn);
1030
	ir_entity *ent  = be_get_frame_entity(irn);
1031
	int     offset  = get_entity_offset(ent);
1032
	ir_node *op     = get_irn_n(irn, 0);
Michael Beck's avatar
Michael Beck committed
1033
	ir_node *cnst;
1034
1035
	ir_mode *mode   = get_irn_mode(irn);
	dbg_info *dbg   = get_irn_dbg_info(irn);
Michael Beck's avatar
Michael Beck committed
1036
1037
1038
1039
1040
1041

	if (be_is_IncSP(op)) {
		/* BEWARE: we get an offset which is absolute from an offset that
		   is relative. Both must be merged */
		offset += get_sp_expand_offset(op);
	}
1042
1043
1044
1045
	cnst = create_const_graph_value(irn, block, (unsigned)offset);
	if (is_arm_Mov_i(cnst))
		return new_rd_arm_Add_i(dbg, current_ir_graph, block, op, mode, get_arm_value(cnst));
	return new_rd_arm_Add(dbg, current_ir_graph, block, op, cnst, mode, ARM_SHF_NONE, NULL);
Michael Beck's avatar
Michael Beck committed
1046
1047
}

Matthias Braun's avatar
Matthias Braun committed
1048
#if 0
Michael Beck's avatar
Michael Beck committed
1049
1050
1051
/**
 * Transforms a FrameLoad into an ia32 Load.
 */
1052
static ir_node *gen_FrameLoad(ir_node *irn, arm_code_gen_t *cg) {
1053
1054
1055
1056
1057
1058
	ir_node   *new_op = NULL;
	ir_node   *noreg  = ia32_new_NoReg_gp(env->cg);
	ir_node   *mem    = get_irn_n(irn, 0);
	ir_node   *ptr    = get_irn_n(irn, 1);
	ir_entity *ent    = be_get_frame_entity(irn);
	ir_mode   *mode   = get_type_mode(get_entity_type(ent));
Michael Beck's avatar
Michael Beck committed
1059
1060
1061

	if (mode_is_float(mode)) {
		if (USE_SSE2(env->cg))
1062
			new_op = new_rd_ia32_fLoad(env->dbg, current_ir_graph, env->block, ptr, noreg, mem, mode_T);
Michael Beck's avatar
Michael Beck committed
1063
1064
		else {
			env->cg->used_x87 = 1;
1065
			new_op = new_rd_ia32_vfld(env->dbg, current_ir_graph, env->block, ptr, noreg, mem, mode_T);
Michael Beck's avatar
Michael Beck committed
1066
1067
1068
		}
	}
	else {
1069
		new_op = new_rd_ia32_Load(env->dbg, current_ir_graph, env->block, ptr, noreg, mem, mode_T);
Michael Beck's avatar
Michael Beck committed
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
	}

	set_ia32_frame_ent(new_op, ent);
	set_ia32_use_frame(new_op);

	set_ia32_am_support(new_op, ia32_am_Source);
	set_ia32_op_type(new_op, ia32_AddrModeS);
	set_ia32_am_flavour(new_op, ia32_B);
	set_ia32_ls_mode(new_op, mode);

	SET_IA32_ORIG_NODE(new_op, ia32_get_old_node_name(env->cg, env->irn));

	return new_op;
}
Matthias Braun's avatar
Matthias Braun committed
1084
#endif
Michael Beck's avatar
Michael Beck committed
1085

Matthias Braun's avatar
Matthias Braun committed
1086
#if 0
Michael Beck's avatar
Michael Beck committed
1087
1088
1089
/**
 * Transforms a FrameStore into an ia32 Store.
 */
1090
static ir_node *gen_FrameStore(ir_node *irn, arm_code_gen_t *cg) {
1091
1092
1093
1094
1095
1096
1097
	ir_node   *new_op = NULL;
	ir_node   *noreg  = ia32_new_NoReg_gp(env->cg);
	ir_node   *mem    = get_irn_n(irn, 0);
	ir_node   *ptr    = get_irn_n(irn, 1);
	ir_node   *val    = get_irn_n(irn, 2);
	ir_entity *ent    = be_get_frame_entity(irn);
	ir_mode   *mode   = get_irn_mode(val);
Michael Beck's avatar
Michael Beck committed
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125

	if (mode_is_float(mode)) {
		if (USE_SSE2(env->cg))
			new_op = new_rd_ia32_fStore(env->dbg, env->irg, env->block, ptr, noreg, val, mem, mode_T);
		else {
			env->cg->used_x87 = 1;
			new_op = new_rd_ia32_vfst(env->dbg, env->irg, env->block, ptr, noreg, val, mem, mode_T);
		}
	}
	else if (get_mode_size_bits(mode) == 8) {
		new_op = new_rd_ia32_Store8Bit(env->dbg, env->irg, env->block, ptr, noreg, val, mem, mode_T);
	}
	else {
		new_op = new_rd_ia32_Store(env->dbg, env->irg, env->block, ptr, noreg, val, mem, mode_T);
	}

	set_ia32_frame_ent(new_op, ent);
	set_ia32_use_frame(new_op);

	set_ia32_am_support(new_op, ia32_am_Dest);
	set_ia32_op_type(new_op, ia32_AddrModeD);
	set_ia32_am_flavour(new_op, ia32_B);
	set_ia32_ls_mode(new_op, mode);

	SET_IA32_ORIG_NODE(new_op, ia32_get_old_node_name(env->cg, env->irn));

	return new_op;
}
Matthias Braun's avatar
Matthias Braun committed
1126
#endif
Michael Beck's avatar
Michael Beck committed
1127
1128


1129
// static ir_node *gen_be_Copy(ir_node *irn, arm_code_gen_t *cg) {
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
// 	return new_rd_arm_Copy(env->dbg, env->irg, env->block, op, env->mode);
// }

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

Michael Beck's avatar
Michael Beck committed
1143
1144
1145
/**
 * move constants out of the start block
 */
1146
1147
void arm_move_consts(ir_node *node, void *env) {
	int i;
Michael Beck's avatar
Michael Beck committed
1148

1149
1150
	if (is_Block(node))
		return;
Michael Beck's avatar
Michael Beck committed
1151

1152
	if (is_Phi(node)) {
Michael Beck's avatar
Michael Beck committed
1153
		for (i = get_irn_arity(node) - 1; i >= 0; --i) {
1154
			ir_node *pred = get_irn_n(node,i);
1155
			ir_opcode pred_code = get_irn_opcode(pred);
1156
1157
			if (pred_code == iro_Const) {
				ir_node *const_graph;
1158
				const_graph = create_const_graph(pred, get_nodes_block(get_irn_n(get_nodes_block(node),i)));
1159
				set_irn_n(node, i, const_graph);
Michael Beck's avatar
Michael Beck committed
1160
1161
1162
1163
1164
			}
			else if (pred_code == iro_SymConst) {
				/* FIXME: in general, SymConst always require a load, so it
				   might be better to place them into the first real block
				   and let the spiller rematerialize them. */
1165
1166
1167
				const char *str = get_sc_name(pred);
				ir_node *symconst_node;
				symconst_node = new_rd_arm_SymConst(get_irn_dbg_info(pred),
Michael Beck's avatar
Michael Beck committed
1168
1169
					current_ir_graph, get_nodes_block(get_irn_n(get_nodes_block(node),i)),
					get_irn_mode(pred), str);
1170
1171
1172
1173
1174
				set_irn_n(node, i, symconst_node);
			}
		}
		return;
	}
Michael Beck's avatar
Michael Beck committed
1175
	for (i = 0; i < get_irn_arity(node); i++) {
1176
		ir_node *pred = get_irn_n(node,i);
1177
		ir_opcode pred_code = get_irn_opcode(pred);
1178
1179
		if (pred_code == iro_Const) {
			ir_node *const_graph;
1180
			const_graph = create_const_graph(pred, get_nodes_block(node));
1181
1182
1183
1184
1185
			set_irn_n(node, i, const_graph);
		} else if (pred_code == iro_SymConst) {
			const char *str = get_sc_name(pred);
			ir_node *symconst_node;
			symconst_node = new_rd_arm_SymConst(get_irn_dbg_info(pred),
Michael Beck's avatar
Michael Beck committed
1186
1187
				current_ir_graph, get_nodes_block(node),
				get_irn_mode(pred), str);
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
			set_irn_n(node, i, symconst_node);
		}
	}
}


/************************************************************************/
/* move symbolic constants out of startblock                            */
/************************************************************************/
void arm_move_symconsts(ir_node *node, void *env) {
	int i;
Christian Würdig's avatar
Christian Würdig committed
1199

1200
1201
	if (is_Block(node))
		return;
Christian Würdig's avatar
Christian Würdig committed
1202

Michael Beck's avatar
Michael Beck committed
1203
	for (i = 0; i < get_irn_arity(node); i++) {
1204
1205
		ir_node *pred       = get_irn_n(node,i);
		ir_opcode pred_code = get_irn_opcode(pred);
Christian Würdig's avatar
Christian Würdig committed
1206

1207
1208
		if (pred_code == iro_SymConst) {
			const char *str = get_sc_name(pred);
Christian Würdig's avatar
Christian Würdig committed
1209
1210
			ir_node    *symconst_node;

1211
			symconst_node = new_rd_arm_SymConst(get_irn_dbg_info(pred),
Michael Beck's avatar
Michael Beck committed
1212
				current_ir_graph, get_nodes_block(node), get_irn_mode(pred), str);
1213
1214
1215
1216
1217
			set_irn_n(node, i, symconst_node);
		}
	}
}

Michael Beck's avatar
Michael Beck committed
1218
1219
1220
/**
 * the BAD transformer.
 */
1221
1222
static ir_node *bad_transform(ir_node *irn, arm_code_gen_t *cg) {
	ir_fprintf(stderr, "Not implemented: %+F\n", irn);
Michael Beck's avatar
Michael Beck committed
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304