sparc_transform.c 30.1 KB
Newer Older
Hannes Rapp's avatar
Hannes Rapp committed
1
/*
2
 * Copyright (C) 1995-2010 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
 *
 * 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   code selection (transform FIRM into SPARC FIRM)
Michael Beck's avatar
Michael Beck committed
23
 * @version $Id$
Hannes Rapp's avatar
Hannes Rapp committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 */

#include "config.h"

#include "irnode_t.h"
#include "irgraph_t.h"
#include "irmode_t.h"
#include "irgmod.h"
#include "iredges.h"
#include "irvrfy.h"
#include "ircons.h"
#include "irprintf.h"
#include "dbginfo.h"
#include "iropt_t.h"
#include "debug.h"
#include "error.h"

#include "../benode.h"
#include "../beirg.h"
#include "../beutil.h"
#include "../betranshlp.h"
#include "bearch_sparc_t.h"

#include "sparc_nodes_attr.h"
#include "sparc_transform.h"
#include "sparc_new_nodes.h"
#include "gen_sparc_new_nodes.h"

#include "gen_sparc_regalloc_if.h"

#include <limits.h>

DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)

static sparc_code_gen_t *env_cg;

Hannes Rapp's avatar
Hannes Rapp committed
60
61
62
static ir_node *gen_SymConst(ir_node *node);


Hannes Rapp's avatar
Hannes Rapp committed
63
64
65
66
67
static inline int mode_needs_gp_reg(ir_mode *mode)
{
	return mode_is_int(mode) || mode_is_reference(mode);
}

68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
 * Create an And that will zero out upper bits.
 *
 * @param dbgi     debug info
 * @param block    the basic block
 * @param op       the original node
 * @param src_bits  number of lower bits that will remain
 */
static ir_node *gen_zero_extension(dbg_info *dbgi, ir_node *block, ir_node *op,
                                   int src_bits)
{
	if (src_bits == 8) {
		return new_bd_sparc_And_imm(dbgi, block, op, 0xFF);
	} else if (src_bits == 16) {
82
83
		ir_node *lshift = new_bd_sparc_Sll_imm(dbgi, block, op, 16);
		ir_node *rshift = new_bd_sparc_Slr_imm(dbgi, block, lshift, 16);
84
85
86
87
88
89
90
91
92
93
94
95
96
		return rshift;
	} else {
		panic("zero extension only supported for 8 and 16 bits");
	}
}

/**
 * Generate code for a sign extension.
 */
static ir_node *gen_sign_extension(dbg_info *dbgi, ir_node *block, ir_node *op,
                                   int src_bits)
{
	int shift_width = 32 - src_bits;
97
98
	ir_node *lshift_node = new_bd_sparc_Sll_imm(dbgi, block, op, shift_width);
	ir_node *rshift_node = new_bd_sparc_Sra_imm(dbgi, block, lshift_node, shift_width);
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
	return rshift_node;
}

/**
 * returns true if it is assured, that the upper bits of a node are "clean"
 * which means for a 16 or 8 bit value, that the upper bits in the register
 * are 0 for unsigned and a copy of the last significant bit for signed
 * numbers.
 */
static bool upper_bits_clean(ir_node *transformed_node, ir_mode *mode)
{
	(void) transformed_node;
	(void) mode;
	/* TODO */
	return false;
}

static ir_node *gen_extension(dbg_info *dbgi, ir_node *block, ir_node *op,
                              ir_mode *orig_mode)
{
	int bits = get_mode_size_bits(orig_mode);
	if (bits == 32)
		return op;

	if (mode_is_signed(orig_mode)) {
		return gen_sign_extension(dbgi, block, op, bits);
	} else {
		return gen_zero_extension(dbgi, block, op, bits);
	}
}


Hannes Rapp's avatar
Hannes Rapp committed
131
132
133
134
135
136
137
138
/**
 * Creates a possible DAG for a constant.
 */
static ir_node *create_const_graph_value(dbg_info *dbgi, ir_node *block,
				long value)
{
	ir_node *result;

139
	// we need to load hi & lo separately
140
	if (value < -4096 || value > 4095) {
141
142
143
144
145
146
		ir_node *hi = new_bd_sparc_HiImm(dbgi, block, (int) value);
		result = new_bd_sparc_LoImm(dbgi, block, hi, value);
		be_dep_on_frame(hi);
	} else {
		result = new_bd_sparc_Mov_imm(dbgi, block, (int) value);
		be_dep_on_frame(result);
Hannes Rapp's avatar
Hannes Rapp committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
	}

	return result;
}


/**
 * Create a DAG constructing a given Const.
 *
 * @param irn  a Firm const
 */
static ir_node *create_const_graph(ir_node *irn, ir_node *block)
{
	tarval  *tv = get_Const_tarval(irn);
	ir_mode *mode = get_tarval_mode(tv);
162
	dbg_info *dbgi = get_irn_dbg_info(irn);
Hannes Rapp's avatar
Hannes Rapp committed
163
164
	long value;

165

Hannes Rapp's avatar
Hannes Rapp committed
166
167
168
169
170
	if (mode_is_reference(mode)) {
		/* SPARC V8 is 32bit, so we can safely convert a reference tarval into Iu */
		assert(get_mode_size_bits(mode) == get_mode_size_bits(mode_Iu));
		tv = tarval_convert_to(tv, mode_Iu);
	}
171

Hannes Rapp's avatar
Hannes Rapp committed
172
	value = get_tarval_long(tv);
173
	return create_const_graph_value(dbgi, block, value);
Hannes Rapp's avatar
Hannes Rapp committed
174
175
}

Hannes Rapp's avatar
Hannes Rapp committed
176
177
178
179
180
181
/**
 * create a DAG to load fp constant. sparc only supports loading from global memory
 */
static ir_node *create_fp_const_graph(ir_node *irn, ir_node *block)
{
	(void) block;
Matthias Braun's avatar
Matthias Braun committed
182
	(void) irn;
Hannes Rapp's avatar
Hannes Rapp committed
183
184
185
	panic("FP constants not implemented");
}

Hannes Rapp's avatar
Hannes Rapp committed
186
187
188
189
190
191
192
193

typedef enum {
	MATCH_NONE         = 0,
	MATCH_COMMUTATIVE  = 1 << 0,
	MATCH_SIZE_NEUTRAL = 1 << 1,
} match_flags_t;

typedef ir_node* (*new_binop_reg_func) (dbg_info *dbgi, ir_node *block, ir_node *op1, ir_node *op2);
Hannes Rapp's avatar
Hannes Rapp committed
194
typedef ir_node* (*new_binop_fp_func) (dbg_info *dbgi, ir_node *block, ir_node *op1, ir_node *op2, ir_mode *mode);
Hannes Rapp's avatar
Hannes Rapp committed
195
196
197
typedef ir_node* (*new_binop_imm_func) (dbg_info *dbgi, ir_node *block, ir_node *op1, int simm13);

/**
198
 * checks if a node's value can be encoded as a immediate
Hannes Rapp's avatar
Hannes Rapp committed
199
200
201
202
203
204
 *
 */
static bool is_imm_encodeable(const ir_node *node)
{
	long val;

Hannes Rapp's avatar
Hannes Rapp committed
205
206
	//assert(mode_is_float_vector(get_irn_mode(node)));

Hannes Rapp's avatar
Hannes Rapp committed
207
208
209
210
211
	if (!is_Const(node))
		return false;

	val = get_tarval_long(get_Const_tarval(node));

212
	return !(val < -4096 || val > 4095);
Hannes Rapp's avatar
Hannes Rapp committed
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
}

/**
 * helper function for binop operations
 *
 * @param new_binop_reg_func register generation function ptr
 * @param new_binop_imm_func immediate generation function ptr
 */
static ir_node *gen_helper_binop(ir_node *node, match_flags_t flags,
				new_binop_reg_func new_reg, new_binop_imm_func new_imm)
{
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	ir_node  *op1     = get_binop_left(node);
	ir_node  *new_op1;
	ir_node  *op2     = get_binop_right(node);
	ir_node  *new_op2;
	dbg_info *dbgi    = get_irn_dbg_info(node);

	if (is_imm_encodeable(op2)) {
		ir_node *new_op1 = be_transform_node(op1);
Hannes Rapp's avatar
Hannes Rapp committed
233
		return new_imm(dbgi, block, new_op1, get_tarval_long(get_Const_tarval(op2)));
Hannes Rapp's avatar
Hannes Rapp committed
234
235
236
237
238
239
240
241
242
243
244
245
246
	}

	new_op2 = be_transform_node(op2);

	if ((flags & MATCH_COMMUTATIVE) && is_imm_encodeable(op1)) {
		return new_imm(dbgi, block, new_op2, get_tarval_long(get_Const_tarval(op1)) );
	}

	new_op1 = be_transform_node(op1);

	return new_reg(dbgi, block, new_op1, new_op2);
}

Hannes Rapp's avatar
Hannes Rapp committed
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/**
 * helper function for FP binop operations
 */
static ir_node *gen_helper_binfpop(ir_node *node, new_binop_fp_func new_reg)
{
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	ir_node  *op1     = get_binop_left(node);
	ir_node  *new_op1;
	ir_node  *op2     = get_binop_right(node);
	ir_node  *new_op2;
	dbg_info *dbgi    = get_irn_dbg_info(node);

	new_op2 = be_transform_node(op2);
	new_op1 = be_transform_node(op1);
	return new_reg(dbgi, block, new_op1, new_op2, get_irn_mode(node));
}

Hannes Rapp's avatar
Hannes Rapp committed
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/**
 * Creates an sparc Add.
 *
 * @param node   FIRM node
 * @return the created sparc Add node
 */
static ir_node *gen_Add(ir_node *node)
{
	ir_mode  *mode    = get_irn_mode(node);
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	dbg_info *dbgi    = get_irn_dbg_info(node);

	(void) block;
	(void) dbgi;

	if (mode_is_float(mode))
		panic("FP not implemented yet");

	return gen_helper_binop(node, MATCH_COMMUTATIVE | MATCH_SIZE_NEUTRAL, new_bd_sparc_Add_reg, new_bd_sparc_Add_imm);
}


/**
 * Creates an sparc Sub.
 *
 * @param node       FIRM node
 * @return the created sparc Sub node
 */
static ir_node *gen_Sub(ir_node *node)
{
	ir_mode  *mode    = get_irn_mode(node);
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	dbg_info *dbgi    = get_irn_dbg_info(node);

298
299
	(void) block;
	(void) dbgi;
Hannes Rapp's avatar
Hannes Rapp committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

	if (mode_is_float(mode))
		panic("FP not implemented yet");

	return gen_helper_binop(node, MATCH_SIZE_NEUTRAL, new_bd_sparc_Sub_reg, new_bd_sparc_Sub_imm);
}


/**
 * Transforms a Load.
 *
 * @param node    the ir Load node
 * @return the created sparc Load node
 */
static ir_node *gen_Load(ir_node *node)
{
	ir_mode  *mode     = get_Load_mode(node);
	ir_node  *block    = be_transform_node(get_nodes_block(node));
	ir_node  *ptr      = get_Load_ptr(node);
	ir_node  *new_ptr  = be_transform_node(ptr);
	ir_node  *mem      = get_Load_mem(node);
	ir_node  *new_mem  = be_transform_node(mem);
	dbg_info *dbgi      = get_irn_dbg_info(node);
	ir_node  *new_load = NULL;

325
326
327
	if (mode_is_float(mode))
		panic("SPARC: no fp implementation yet");

328
	new_load = new_bd_sparc_Ld(dbgi, block, new_ptr, new_mem, mode, NULL, 0, 0, false);
Hannes Rapp's avatar
Hannes Rapp committed
329
330
	set_irn_pinned(new_load, get_irn_pinned(node));

Hannes Rapp's avatar
Hannes Rapp committed
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
	return new_load;
}



/**
 * Transforms a Store.
 *
 * @param node    the ir Store node
 * @return the created sparc Store node
 */
static ir_node *gen_Store(ir_node *node)
{
	ir_node  *block    = be_transform_node(get_nodes_block(node));
	ir_node  *ptr      = get_Store_ptr(node);
	ir_node  *new_ptr  = be_transform_node(ptr);
	ir_node  *mem      = get_Store_mem(node);
	ir_node  *new_mem  = be_transform_node(mem);
	ir_node  *val      = get_Store_value(node);
	ir_node  *new_val  = be_transform_node(val);
	ir_mode  *mode     = get_irn_mode(val);
	dbg_info *dbgi     = get_irn_dbg_info(node);
	ir_node *new_store = NULL;

355
356
357
	if (mode_is_float(mode))
		panic("SPARC: no fp implementation yet");

358
	new_store = new_bd_sparc_St(dbgi, block, new_ptr, new_val, new_mem, mode, NULL, 0, 0, false);
Hannes Rapp's avatar
Hannes Rapp committed
359
360
361
362

	return new_store;
}

363
364
/**
 * Creates an sparc Mul.
365
 * returns the lower 32bits of the 64bit multiply result
366
367
368
 *
 * @return the created sparc Mul node
 */
369
static ir_node *gen_Mul(ir_node *node) {
370
371
372
373
374
375
	ir_mode  *mode    = get_irn_mode(node);
	dbg_info *dbgi     = get_irn_dbg_info(node);

	ir_node *mul;
	ir_node *proj_res_low;

Hannes Rapp's avatar
Hannes Rapp committed
376
377
378
379
	if (mode_is_float(mode)) {
		mul = gen_helper_binfpop(node, new_bd_sparc_fMul);
		return mul;
	}
380
381

	assert(mode_is_data(mode));
Hannes Rapp's avatar
Hannes Rapp committed
382
	mul = gen_helper_binop(node, MATCH_COMMUTATIVE | MATCH_SIZE_NEUTRAL, new_bd_sparc_Mul_reg, new_bd_sparc_Mul_imm);
383
	arch_irn_add_flags(mul, arch_irn_flags_modify_flags);
384

Hannes Rapp's avatar
Hannes Rapp committed
385
	proj_res_low = new_rd_Proj(dbgi, mul, mode_Iu, pn_sparc_Mul_low);
386
	return proj_res_low;
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
}

/**
 * Creates an sparc Mulh.
 * Mulh returns the upper 32bits of a mul instruction
 *
 * @return the created sparc Mulh node
 */
static ir_node *gen_Mulh(ir_node *node) {
	ir_mode  *mode    = get_irn_mode(node);
	dbg_info *dbgi     = get_irn_dbg_info(node);

	ir_node *mul;
	ir_node *proj_res_hi;

	if (mode_is_float(mode))
		panic("FP not supported yet");


	assert(mode_is_data(mode));
Hannes Rapp's avatar
Hannes Rapp committed
407
408
409
	mul = gen_helper_binop(node, MATCH_COMMUTATIVE | MATCH_SIZE_NEUTRAL, new_bd_sparc_Mulh_reg, new_bd_sparc_Mulh_imm);
	//arch_irn_add_flags(mul, arch_irn_flags_modify_flags);
	proj_res_hi = new_rd_Proj(dbgi, mul, mode_Iu, pn_sparc_Mulh_low);
410
	return proj_res_hi;
411
}
Hannes Rapp's avatar
Hannes Rapp committed
412

413
414
415
416
417
/**
 * Creates an sparc Div.
 *
 * @return the created sparc Div node
 */
418
419
static ir_node *gen_Div(ir_node *node) {

420
421
	ir_mode  *mode    = get_irn_mode(node);

422
	ir_node *div;
423
424
425
426

	if (mode_is_float(mode))
		panic("FP not supported yet");

427
	//assert(mode_is_data(mode));
Hannes Rapp's avatar
Hannes Rapp committed
428
	div = gen_helper_binop(node, MATCH_SIZE_NEUTRAL, new_bd_sparc_Div_reg, new_bd_sparc_Div_imm);
429
	return div;
430
431
}

432

433
434
435
436
437
438
439
440
441
/**
 * transform abs node:
 * mov a, b
 * sra b, 31, b
 * xor a, b
 * sub a, b
 *
 * @return
 */
442
static ir_node *gen_Abs(ir_node *node) {
443
444
445
446
447
448
449
450
451
452
453
454
455
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	ir_mode  *mode    = get_irn_mode(node);
	dbg_info *dbgi    = get_irn_dbg_info(node);
	ir_node   *op     = get_Abs_op(node);

	ir_node *mov, *sra, *xor, *sub, *new_op;

	if (mode_is_float(mode))
		panic("FP not supported yet");

	new_op = be_transform_node(op);

	mov = new_bd_sparc_Mov_reg(dbgi, block, new_op);
456
	sra = new_bd_sparc_Sra_imm(dbgi, block, mov, 31);
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
	xor = new_bd_sparc_Xor_reg(dbgi, block, new_op, sra);
	sub = new_bd_sparc_Sub_reg(dbgi, block, sra, xor);

	return sub;
}

/**
 * Transforms a Not node.
 *
 * @return the created ARM Not node
 */
static ir_node *gen_Not(ir_node *node)
{
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	ir_node  *op      = get_Not_op(node);
	ir_node  *new_op  = be_transform_node(op);
	dbg_info *dbgi    = get_irn_dbg_info(node);

	return new_bd_sparc_Not(dbgi, block, new_op);
}

478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
static ir_node *gen_And(ir_node *node)
{
	ir_mode  *mode    = get_irn_mode(node);
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	dbg_info *dbgi    = get_irn_dbg_info(node);

	(void) block;
	(void) dbgi;

	if (mode_is_float(mode))
		panic("FP not implemented yet");

	return gen_helper_binop(node, MATCH_COMMUTATIVE, new_bd_sparc_And_reg, new_bd_sparc_And_imm);
}

static ir_node *gen_Or(ir_node *node)
{
	ir_mode  *mode    = get_irn_mode(node);
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	dbg_info *dbgi    = get_irn_dbg_info(node);

	(void) block;
	(void) dbgi;

	if (mode_is_float(mode))
		panic("FP not implemented yet");

	return gen_helper_binop(node, MATCH_COMMUTATIVE, new_bd_sparc_Or_reg, new_bd_sparc_Or_imm);
}

508
static ir_node *gen_Eor(ir_node *node)
Hannes Rapp's avatar
Hannes Rapp committed
509
510
511
512
513
514
515
516
517
518
519
520
521
522
{
	ir_mode  *mode    = get_irn_mode(node);
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	dbg_info *dbgi    = get_irn_dbg_info(node);

	(void) block;
	(void) dbgi;

	if (mode_is_float(mode))
		panic("FP not implemented yet");

	return gen_helper_binop(node, MATCH_COMMUTATIVE, new_bd_sparc_Xor_reg, new_bd_sparc_Xor_imm);
}

523
524
static ir_node *gen_Shl(ir_node *node)
{
525
	return gen_helper_binop(node, MATCH_SIZE_NEUTRAL, new_bd_sparc_Sll_reg, new_bd_sparc_Sll_imm);
526
527
528
529
}

static ir_node *gen_Shr(ir_node *node)
{
530
	return gen_helper_binop(node, MATCH_SIZE_NEUTRAL, new_bd_sparc_Slr_reg, new_bd_sparc_Slr_imm);
531
}
Hannes Rapp's avatar
Hannes Rapp committed
532

533
static ir_node *gen_Shrs(ir_node *node)
534
{
535
	return gen_helper_binop(node, MATCH_SIZE_NEUTRAL, new_bd_sparc_Sra_reg, new_bd_sparc_Sra_imm);
536
537
}

Hannes Rapp's avatar
Hannes Rapp committed
538
539
/****** TRANSFORM GENERAL BACKEND NODES ********/

540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
/**
 * Transforms a Minus node.
 *
 */
static ir_node *gen_Minus(ir_node *node)
{
	ir_node  *block   = be_transform_node(get_nodes_block(node));
	ir_node  *op      = get_Minus_op(node);
	ir_node  *new_op  = be_transform_node(op);
	dbg_info *dbgi    = get_irn_dbg_info(node);
	ir_mode  *mode    = get_irn_mode(node);

	if (mode_is_float(mode)) {
		panic("FP not implemented yet");
	}

	assert(mode_is_data(mode));
	return new_bd_sparc_Minus(dbgi, block, new_op);
}

Hannes Rapp's avatar
Hannes Rapp committed
560
561
562
/**
 * Transforms a Const node.
 *
Hannes Rapp's avatar
Hannes Rapp committed
563
 * @param node    the ir Const node
Hannes Rapp's avatar
Hannes Rapp committed
564
565
 * @return The transformed sparc node.
 */
566
567
static ir_node *gen_Const(ir_node *node)
{
Hannes Rapp's avatar
Hannes Rapp committed
568
569
570
571
572
573
574
	ir_node  *block = be_transform_node(get_nodes_block(node));
	ir_mode *mode = get_irn_mode(node);
	dbg_info *dbg = get_irn_dbg_info(node);

	(void) dbg;

	if (mode_is_float(mode)) {
Hannes Rapp's avatar
Hannes Rapp committed
575
		return create_fp_const_graph(node, block);
Hannes Rapp's avatar
Hannes Rapp committed
576
	}
Hannes Rapp's avatar
Hannes Rapp committed
577

Hannes Rapp's avatar
Hannes Rapp committed
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
	return create_const_graph(node, block);
}

/**
 * AddSP
 * @param node the ir AddSP node
 * @return transformed sparc SAVE node
 */
static ir_node *gen_be_AddSP(ir_node *node)
{
	ir_node  *block  = be_transform_node(get_nodes_block(node));
	ir_node  *sz     = get_irn_n(node, be_pos_AddSP_size);
	ir_node  *new_sz = be_transform_node(sz);
	ir_node  *sp     = get_irn_n(node, be_pos_AddSP_old_sp);
	ir_node  *new_sp = be_transform_node(sp);
	dbg_info *dbgi   = get_irn_dbg_info(node);
	ir_node  *nomem  = new_NoMem();
	ir_node  *new_op;

	/* SPARC stack grows in reverse direction */
598
	new_op = new_bd_sparc_SubSP(dbgi, block, new_sp, new_sz, nomem);
Hannes Rapp's avatar
Hannes Rapp committed
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620

	return new_op;
}


/**
 * SubSP
 * @param node the ir SubSP node
 * @return transformed sparc SAVE node
 */
static ir_node *gen_be_SubSP(ir_node *node)
{
	ir_node  *block  = be_transform_node(get_nodes_block(node));
	ir_node  *sz     = get_irn_n(node, be_pos_SubSP_size);
	ir_node  *new_sz = be_transform_node(sz);
	ir_node  *sp     = get_irn_n(node, be_pos_SubSP_old_sp);
	ir_node  *new_sp = be_transform_node(sp);
	dbg_info *dbgi   = get_irn_dbg_info(node);
	ir_node  *nomem  = new_NoMem();
	ir_node  *new_op;

	/* SPARC stack grows in reverse direction */
621
	new_op = new_bd_sparc_AddSP(dbgi, block, new_sp, new_sz, nomem);
Hannes Rapp's avatar
Hannes Rapp committed
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
	return new_op;
}

/**
 * transform FrameAddr
 */
static ir_node *gen_be_FrameAddr(ir_node *node)
{
	ir_node   *block  = be_transform_node(get_nodes_block(node));
	ir_entity *ent    = be_get_frame_entity(node);
	ir_node   *fp     = be_get_FrameAddr_frame(node);
	ir_node   *new_fp = be_transform_node(fp);
	dbg_info  *dbgi   = get_irn_dbg_info(node);
	ir_node   *new_node;
	new_node = new_bd_sparc_FrameAddr(dbgi, block, new_fp, ent);
	return new_node;
}

/**
 * Transform a be_Copy.
 */
643
644
static ir_node *gen_be_Copy(ir_node *node)
{
Hannes Rapp's avatar
Hannes Rapp committed
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
	ir_node *result = be_duplicate_node(node);
	ir_mode *mode   = get_irn_mode(result);

	if (mode_needs_gp_reg(mode)) {
		set_irn_mode(node, mode_Iu);
	}

	return result;
}

/**
 * Transform a Call
 */
static ir_node *gen_be_Call(ir_node *node)
{
	ir_node *res = be_duplicate_node(node);
	arch_irn_add_flags(res, arch_irn_flags_modify_flags);
	return res;
}

Hannes Rapp's avatar
Hannes Rapp committed
665
666
667
668
/**
 * Transforms a Switch.
 *
 */
Hannes Rapp's avatar
Hannes Rapp committed
669
670
static ir_node *gen_SwitchJmp(ir_node *node)
{
Hannes Rapp's avatar
Hannes Rapp committed
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
	ir_node  *block    = be_transform_node(get_nodes_block(node));
	ir_node  *selector = get_Cond_selector(node);
	dbg_info *dbgi     = get_irn_dbg_info(node);
	ir_node *new_op = be_transform_node(selector);
	ir_node *const_graph;
	ir_node *sub;

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

	foreach_out_edge(node, 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;
	n_projs = max - translation + 1;

	foreach_out_edge(node, 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);
	}

	const_graph = create_const_graph_value(dbgi, block, translation);
	sub = new_bd_sparc_Sub_reg(dbgi, block, new_op, const_graph);
	return new_bd_sparc_SwitchJmp(dbgi, block, sub, n_projs, get_Cond_default_proj(node) - translation);
Hannes Rapp's avatar
Hannes Rapp committed
710
711
}

712
713
714
715
716
717
718
719
720
721
722
723
724
725
static bool is_cmp_unsigned(ir_node *b_value)
{
	ir_node *pred;
	ir_node *op;

	if (!is_Proj(b_value))
		panic("can't determine cond signednes");
	pred = get_Proj_pred(b_value);
	if (!is_Cmp(pred))
		panic("can't determine cond signednes (no cmp)");
	op = get_Cmp_left(pred);
	return !mode_is_signed(get_irn_mode(op));
}

Hannes Rapp's avatar
Hannes Rapp committed
726
727
728
729
730
731
732
733
734
/**
 * Transform Cond nodes
 */
static ir_node *gen_Cond(ir_node *node)
{
	ir_node  *selector = get_Cond_selector(node);
	ir_mode  *mode     = get_irn_mode(selector);
	ir_node  *block;
	ir_node  *flag_node;
735
736
	bool      is_unsigned;
	pn_Cmp    pnc;
Hannes Rapp's avatar
Hannes Rapp committed
737
738
739
740
	dbg_info *dbgi;

	// switch/case jumps
	if (mode != mode_b) {
Hannes Rapp's avatar
Hannes Rapp committed
741
		return gen_SwitchJmp(node);
Hannes Rapp's avatar
Hannes Rapp committed
742
743
744
745
	}

	// regular if/else jumps
	assert(is_Proj(selector));
746
	assert(is_Cmp(get_Proj_pred(selector)));
Hannes Rapp's avatar
Hannes Rapp committed
747

748
749
750
751
752
753
	block       = be_transform_node(get_nodes_block(node));
	dbgi        = get_irn_dbg_info(node);
	flag_node   = be_transform_node(get_Proj_pred(selector));
	pnc         = get_Proj_proj(selector);
	is_unsigned = is_cmp_unsigned(selector);
	return new_bd_sparc_BXX(dbgi, block, flag_node, pnc, is_unsigned);
Hannes Rapp's avatar
Hannes Rapp committed
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
}

/**
 * transform Cmp
 */
static ir_node *gen_Cmp(ir_node *node)
{
	ir_node  *block    = be_transform_node(get_nodes_block(node));
	ir_node  *op1      = get_Cmp_left(node);
	ir_node  *op2      = get_Cmp_right(node);
	ir_mode  *cmp_mode = get_irn_mode(op1);
	dbg_info *dbgi     = get_irn_dbg_info(node);
	ir_node  *new_op1;
	ir_node  *new_op2;

	if (mode_is_float(cmp_mode)) {
		panic("FloatCmp not implemented");
	}

773
	/*
Hannes Rapp's avatar
Hannes Rapp committed
774
775
776
	if (get_mode_size_bits(cmp_mode) != 32) {
		panic("CmpMode != 32bit not supported yet");
	}
777
	*/
Hannes Rapp's avatar
Hannes Rapp committed
778
779
780
781

	assert(get_irn_mode(op2) == cmp_mode);

	/* compare with 0 can be done with Tst */
782
	/*
Hannes Rapp's avatar
Hannes Rapp committed
783
784
785
786
787
788
789
790
791
792
793
	if (is_Const(op2) && tarval_is_null(get_Const_tarval(op2))) {
		new_op1 = be_transform_node(op1);
		return new_bd_sparc_Tst(dbgi, block, new_op1, false,
		                          is_unsigned);
	}

	if (is_Const(op1) && tarval_is_null(get_Const_tarval(op1))) {
		new_op2 = be_transform_node(op2);
		return new_bd_sparc_Tst(dbgi, block, new_op2, true,
		                          is_unsigned);
	}
794
	*/
Hannes Rapp's avatar
Hannes Rapp committed
795
796
797

	/* integer compare */
	new_op1 = be_transform_node(op1);
798
	new_op1 = gen_extension(dbgi, block, new_op1, cmp_mode);
Hannes Rapp's avatar
Hannes Rapp committed
799
	new_op2 = be_transform_node(op2);
800
	new_op2 = gen_extension(dbgi, block, new_op2, cmp_mode);
801
	return new_bd_sparc_Cmp_reg(dbgi, block, new_op1, new_op2);
Hannes Rapp's avatar
Hannes Rapp committed
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
}

/**
 * Transforms a SymConst node.
 */
static ir_node *gen_SymConst(ir_node *node)
{
	ir_node   *block  = be_transform_node(get_nodes_block(node));
	ir_entity *entity = get_SymConst_entity(node);
	dbg_info  *dbgi   = get_irn_dbg_info(node);
	ir_node   *new_node;

	new_node = new_bd_sparc_SymConst(dbgi, block, entity);
	be_dep_on_frame(new_node);
	return new_node;
}

Hannes Rapp's avatar
Hannes Rapp committed
819
820
821
822
/**
 * Transforms a Conv node.
 *
 */
823
824
static ir_node *gen_Conv(ir_node *node)
{
Hannes Rapp's avatar
Hannes Rapp committed
825
826
827
828
829
830
831
	ir_node  *block    = be_transform_node(get_nodes_block(node));
	ir_node  *op       = get_Conv_op(node);
	ir_node  *new_op   = be_transform_node(op);
	ir_mode  *src_mode = get_irn_mode(op);
	ir_mode  *dst_mode = get_irn_mode(node);
	dbg_info *dbg      = get_irn_dbg_info(node);

Hannes Rapp's avatar
Hannes Rapp committed
832
833
834
	int src_bits = get_mode_size_bits(src_mode);
	int dst_bits = get_mode_size_bits(dst_mode);

Hannes Rapp's avatar
Hannes Rapp committed
835
836
837
838
	if (src_mode == dst_mode)
		return new_op;

	if (mode_is_float(src_mode) || mode_is_float(dst_mode)) {
Hannes Rapp's avatar
Hannes Rapp committed
839
840
841
842
843
844
		assert((src_bits <= 64 && dst_bits <= 64) && "quad FP not implemented");

		if (mode_is_float(src_mode)) {
			if (mode_is_float(dst_mode)) {
				// float -> float conv
				if (src_bits > dst_bits) {
845
					return new_bd_sparc_FsTOd(dbg, block, new_op, dst_mode);
Hannes Rapp's avatar
Hannes Rapp committed
846
				} else {
847
					return new_bd_sparc_FdTOs(dbg, block, new_op, dst_mode);
Hannes Rapp's avatar
Hannes Rapp committed
848
849
850
851
852
				}
			} else {
				// float -> int conv
				switch (dst_bits) {
					case 32:
853
						return new_bd_sparc_FsTOi(dbg, block, new_op, dst_mode);
Hannes Rapp's avatar
Hannes Rapp committed
854
					case 64:
855
						return new_bd_sparc_FdTOi(dbg, block, new_op, dst_mode);
Hannes Rapp's avatar
Hannes Rapp committed
856
857
858
859
860
861
862
863
					default:
						panic("quad FP not implemented");
				}
			}
		} else {
			// int -> float conv
			switch (dst_bits) {
				case 32:
864
					return new_bd_sparc_FiTOs(dbg, block, new_op, src_mode);
Hannes Rapp's avatar
Hannes Rapp committed
865
				case 64:
866
					return new_bd_sparc_FiTOd(dbg, block, new_op, src_mode);
Hannes Rapp's avatar
Hannes Rapp committed
867
868
869
870
				default:
					panic("quad FP not implemented");
			}
		}
Hannes Rapp's avatar
Hannes Rapp committed
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
	} else { /* complete in gp registers */
		int min_bits;
		ir_mode *min_mode;

		if (src_bits == dst_bits) {
			/* kill unneccessary conv */
			return new_op;
		}

		if (src_bits < dst_bits) {
			min_bits = src_bits;
			min_mode = src_mode;
		} else {
			min_bits = dst_bits;
			min_mode = dst_mode;
		}

		if (upper_bits_clean(new_op, min_mode)) {
			return new_op;
		}

		if (mode_is_signed(min_mode)) {
			return gen_sign_extension(dbg, block, new_op, min_bits);
		} else {
			return gen_zero_extension(dbg, block, new_op, min_bits);
		}
	}
}

900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
static ir_node *gen_Unknown(ir_node *node)
{
	ir_node  *block     = get_nodes_block(node);
	ir_node  *new_block = be_transform_node(block);
	dbg_info *dbgi      = get_irn_dbg_info(node);

	/* just produce a 0 */
	ir_mode *mode = get_irn_mode(node);
	if (mode_is_float(mode)) {
		panic("FP not implemented");
		be_dep_on_frame(node);
		return node;
	} else if (mode_needs_gp_reg(mode)) {
		return create_const_graph_value(dbgi, new_block, 0);
	}

	panic("Unexpected Unknown mode");
}

Hannes Rapp's avatar
Hannes Rapp committed
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
/**
 * Transform some Phi nodes
 */
static ir_node *gen_Phi(ir_node *node)
{
	const arch_register_req_t *req;
	ir_node  *block = be_transform_node(get_nodes_block(node));
	ir_graph *irg   = current_ir_graph;
	dbg_info *dbgi  = get_irn_dbg_info(node);
	ir_mode  *mode  = get_irn_mode(node);
	ir_node  *phi;

	if (mode_needs_gp_reg(mode)) {
		/* we shouldn't have any 64bit stuff around anymore */
		assert(get_mode_size_bits(mode) <= 32);
		/* all integer operations are on 32bit registers now */
		mode = mode_Iu;
		req  = sparc_reg_classes[CLASS_sparc_gp].class_req;
	} else {
		req = arch_no_register_req;
	}

	/* phi nodes allow loops, so we use the old arguments for now
	 * and fix this later */
Hannes Rapp's avatar
Hannes Rapp committed
943
	phi = new_ir_node(dbgi, irg, block, op_Phi, mode, get_irn_arity(node), get_irn_in(node) + 1);
944
	copy_node_attr(irg, node, phi);
Hannes Rapp's avatar
Hannes Rapp committed
945
946
947
948
949
950
	be_duplicate_deps(node, phi);
	arch_set_out_register_req(phi, 0, req);
	be_enqueue_preds(node);
	return phi;
}

Hannes Rapp's avatar
Hannes Rapp committed
951
952
953
954

/**
 * Transform a Proj from a Load.
 */
955
956
static ir_node *gen_Proj_Load(ir_node *node)
{
Hannes Rapp's avatar
Hannes Rapp committed
957
958
959
960
961
962
963
	ir_node  *load     = get_Proj_pred(node);
	ir_node  *new_load = be_transform_node(load);
	dbg_info *dbgi     = get_irn_dbg_info(node);
	long     proj      = get_Proj_proj(node);

	/* renumber the proj */
	switch (get_sparc_irn_opcode(new_load)) {
964
		case iro_sparc_Ld:
Hannes Rapp's avatar
Hannes Rapp committed
965
966
			/* handle all gp loads equal: they have the same proj numbers. */
			if (proj == pn_Load_res) {
967
				return new_rd_Proj(dbgi, new_load, mode_Iu, pn_sparc_Ld_res);
Hannes Rapp's avatar
Hannes Rapp committed
968
			} else if (proj == pn_Load_M) {
969
				return new_rd_Proj(dbgi, new_load, mode_M, pn_sparc_Ld_M);
Hannes Rapp's avatar
Hannes Rapp committed
970
			}
971
			break;
Hannes Rapp's avatar
Hannes Rapp committed
972
973
974
975
		default:
			panic("Unsupported Proj from Load");
	}

976
	return be_duplicate_node(node);
Hannes Rapp's avatar
Hannes Rapp committed
977
978
979
980
981
}

/**
 * Transform the Projs of a be_AddSP.
 */
982
983
static ir_node *gen_Proj_be_AddSP(ir_node *node)
{
Hannes Rapp's avatar
Hannes Rapp committed
984
985
986
987
988
989
	ir_node  *pred     = get_Proj_pred(node);
	ir_node  *new_pred = be_transform_node(pred);
	dbg_info *dbgi     = get_irn_dbg_info(node);
	long     proj      = get_Proj_proj(node);

	if (proj == pn_be_AddSP_sp) {
990
		ir_node *res = new_rd_Proj(dbgi, new_pred, mode_Iu,
Hannes Rapp's avatar
Hannes Rapp committed
991
992
993
		                           pn_sparc_SubSP_stack);
		arch_set_irn_register(res, &sparc_gp_regs[REG_SP]);
		return res;
994
	} else if (proj == pn_be_AddSP_res) {
995
		return new_rd_Proj(dbgi, new_pred, mode_Iu, pn_sparc_SubSP_stack);
Hannes Rapp's avatar
Hannes Rapp committed
996
	} else if (proj == pn_be_AddSP_M) {
997
		return new_rd_Proj(dbgi, new_pred, mode_M, pn_sparc_SubSP_M);
Hannes Rapp's avatar
Hannes Rapp committed
998
999
1000
1001
1002
1003
1004
1005
	}

	panic("Unsupported Proj from AddSP");
}

/**
 * Transform the Projs of a be_SubSP.
 */
1006
1007
static ir_node *gen_Proj_be_SubSP(ir_node *node)
{
Hannes Rapp's avatar
Hannes Rapp committed
1008
1009
1010
1011
1012
1013
	ir_node  *pred     = get_Proj_pred(node);
	ir_node  *new_pred = be_transform_node(pred);
	dbg_info *dbgi     = get_irn_dbg_info(node);
	long     proj      = get_Proj_proj(node);

	if (proj == pn_be_SubSP_sp) {
1014
		ir_node *res = new_rd_Proj(dbgi, new_pred, mode_Iu,
Hannes Rapp's avatar
Hannes Rapp committed
1015
1016
1017
1018
		                           pn_sparc_AddSP_stack);
		arch_set_irn_register(res, &sparc_gp_regs[REG_SP]);
		return res;
	} else if (proj == pn_be_SubSP_M) {
1019
		return new_rd_Proj(dbgi,  new_pred, mode_M, pn_sparc_AddSP_M);
Hannes Rapp's avatar
Hannes Rapp committed
1020
1021
1022
1023
1024
1025
1026
1027
	}

	panic("Unsupported Proj from SubSP");
}

/**
 * Transform the Projs from a Cmp.
 */
1028
1029
static ir_node *gen_Proj_Cmp(ir_node *node)
{
Hannes Rapp's avatar
Hannes Rapp committed
1030
1031
1032
1033
	(void) node;
	panic("not implemented");
}

Hannes Rapp's avatar
Hannes Rapp committed
1034
1035
1036
/**
 * transform Projs from a Div
 */
1037
1038
1039
1040
1041
1042
1043
1044
static ir_node *gen_Proj_Div(ir_node *node)
{
	ir_node  *pred     = get_Proj_pred(node);
	ir_node  *new_pred = be_transform_node(pred);
	dbg_info *dbgi     = get_irn_dbg_info(node);
	long     proj      = get_Proj_proj(node);

	switch (proj) {
1045
1046
1047
1048
	case pn_Div_res:
		if (is_sparc_Div(new_pred)) {
			return new_rd_Proj(dbgi, new_pred, mode_Iu, pn_sparc_Div_res);
		}
1049
1050
1051
1052
1053
1054
1055
1056
		break;
	default:
		break;
	}
	panic("Unsupported Proj from Div");
}


Hannes Rapp's avatar
Hannes Rapp committed
1057
1058
1059
/**
 * Transform a Proj node.
 */
1060
1061
static ir_node *gen_Proj(ir_node *node)
{
Hannes Rapp's avatar
Hannes Rapp committed
1062
1063
1064
1065
1066
1067
	ir_graph *irg  = current_ir_graph;
	dbg_info *dbgi = get_irn_dbg_info(node);
	ir_node  *pred = get_Proj_pred(node);
	long     proj  = get_Proj_proj(node);

	(void) irg;
1068
	(void) dbgi;
Hannes Rapp's avatar
Hannes Rapp committed
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086

	if (is_Store(pred)) {
		if (proj == pn_Store_M) {
			return be_transform_node(pred);
		} else {
			panic("Unsupported Proj from Store");
		}
	} else if (is_Load(pred)) {
		return gen_Proj_Load(node);
	} else if (be_is_SubSP(pred)) {
		//panic("gen_Proj not implemented for SubSP");
		return gen_Proj_be_SubSP(node);
	} else if (be_is_AddSP(pred)) {
		//panic("gen_Proj not implemented for AddSP");
		return gen_Proj_be_AddSP(node);
	} else if (is_Cmp(pred)) {
		//panic("gen_Proj not implemented for Cmp");
		return gen_Proj_Cmp(node);
1087
1088
	} else if (is_Div(pred)) {
		return gen_Proj_Div(node);
Hannes Rapp's avatar
Hannes Rapp committed
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
	} else if (is_Start(pred)) {
	/*
		if (proj == pn_Start_X_initial_exec) {
			ir_node *block = get_nodes_block(pred);
			ir_node *jump;

			// we exchange the ProjX with a jump
			block = be_transform_node(block);
			jump  = new_rd_Jmp(dbgi, block);
			return jump;
		}

		if (node == get_irg_anchor(irg, anchor_tls)) {
			return gen_Proj_tls(node);
		}
	*/
	} else {
		ir_node *new_pred = be_transform_node(pred);
		ir_mode *mode     = get_irn_mode(node);
		if (mode_needs_gp_reg(mode)) {
1109
			ir_node *new_proj = new_r_Proj(new_pred, mode_Iu, get_Proj_proj(node));
Hannes Rapp's avatar
Hannes Rapp committed
1110
1111
1112
1113
1114
			new_proj->node_nr = node->node_nr;
			return new_proj;
		}
	}

1115
	return be_duplicate_node(node);
Hannes Rapp's avatar
Hannes Rapp committed
1116
1117
}

1118

Hannes Rapp's avatar
Hannes Rapp committed
1119
1120
1121
1122
1123
1124
1125
1126
1127
/**
 * transform a Jmp
 */
static ir_node *gen_Jmp(ir_node *node)
{
	ir_node  *block     = get_nodes_block(node);
	ir_node  *new_block = be_transform_node(block);
	dbg_info *dbgi      = get_irn_dbg_info(node);

1128
	return new_bd_sparc_Ba(dbgi, new_block);
Hannes Rapp's avatar
Hannes Rapp committed
1129
1130
}

Hannes Rapp's avatar
Hannes Rapp committed
1131
1132
1133
1134
1135
/**
 * configure transformation callbacks
 */
void sparc_register_transformers(void)
{
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
	be_start_transform_setup();

	be_set_transform_function(op_Abs,          gen_Abs);
	be_set_transform_function(op_Add,          gen_Add);
	be_set_transform_function(op_And,          gen_And);
	be_set_transform_function(op_be_AddSP,     gen_be_AddSP);
	be_set_transform_function(op_be_Call,      gen_be_Call);
	be_set_transform_function(op_be_Copy,      gen_be_Copy);
	be_set_transform_function(op_be_FrameAddr, gen_be_FrameAddr);
	be_set_transform_function(op_be_SubSP,     gen_be_SubSP);
	be_set_transform_function(op_Cmp,          gen_Cmp);
	be_set_transform_function(op_Cond,         gen_Cond);
	be_set_transform_function(op_Const,        gen_Const);
	be_set_transform_function(op_Conv,         gen_Conv);
	be_set_transform_function(op_Div,          gen_Div);
1151
	be_set_transform_function(op_Eor,          gen_Eor);
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
	be_set_transform_function(op_Jmp,          gen_Jmp);
	be_set_transform_function(op_Load,         gen_Load);
	be_set_transform_function(op_Minus,        gen_Minus);
	be_set_transform_function(op_Mul,          gen_Mul);
	be_set_transform_function(op_Mulh,         gen_Mulh);
	be_set_transform_function(op_Not,          gen_Not);
	be_set_transform_function(op_Or,           gen_Or);
	be_set_transform_function(op_Phi,          gen_Phi);
	be_set_transform_function(op_Proj,         gen_Proj);
	be_set_transform_function(op_Shl,          gen_Shl);
	be_set_transform_function(op_Shr,          gen_Shr);
1163
	be_set_transform_function(op_Shrs,         gen_Shrs);
1164
1165
1166
1167
1168
1169
	be_set_transform_function(op_Store,        gen_Store);
	be_set_transform_function(op_Sub,          gen_Sub);
	be_set_transform_function(op_SymConst,     gen_SymConst);
	be_set_transform_function(op_Unknown,      gen_Unknown);

	be_set_transform_function(op_sparc_Save,   be_duplicate_node);
Hannes Rapp's avatar
Hannes Rapp committed
1170
1171
1172
1173
1174
1175
1176
1177
1178
}

/**
 * Transform a Firm graph into a SPARC graph.
 */
void sparc_transform_graph(sparc_code_gen_t *cg)
{
	sparc_register_transformers();
	env_cg = cg;
1179
	be_transform_graph(cg->irg, NULL);
Hannes Rapp's avatar
Hannes Rapp committed
1180
1181
1182
1183
1184
1185
}

void sparc_init_transform(void)
{
	FIRM_DBG_REGISTER(dbg, "firm.be.sparc.transform");
}