ppc32_transform.c 42.7 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.
 */

20
21
22
23
24
25
/**
 * @file
 * @brief   The codegenerator (transform FIRM into ppc FIRM)
 * @author  Moritz Kroll, Jens Mueller
 * @version $Id$
 */
26
27
28
29
30
31
32
33
34
35
36
#include "config.h"

#include "irnode_t.h"
#include "irgraph_t.h"
#include "irmode_t.h"
#include "irgmod.h"
#include "iredges.h"
#include "iredges_t.h"
#include "irvrfy.h"
#include "ircons.h"
#include "iropt_t.h"
37
#include "irprintf.h"
38
#include "debug.h"
39
#include "error.h"
40
41
42
43
44

#include "../benode_t.h"
#include "bearch_ppc32_t.h"

#include "ppc32_nodes_attr.h"
45
#include "archop.h"
46
47
48
49
50
51
52
53
#include "ppc32_transform.h"
#include "ppc32_new_nodes.h"
#include "ppc32_map_regs.h"

#include "gen_ppc32_regalloc_if.h"

extern ir_op *get_op_Mulh(void);

54
int is_direct_entity(ir_entity *ent);
55
56
57
58
59
60

ir_mode* ppc32_mode_Cond = NULL;

/**
 * Returns the proj of a given node with the given proj number
 */
61
static inline ir_node *get_succ_Proj(ir_node *node, long proj)
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
	const ir_edge_t *edge;
	foreach_out_edge(node, edge)
	{
		if (is_Proj(edge->src) && get_Proj_proj(edge->src) == proj)
			return edge->src;
	}
	return NULL;
}

/**
 * Returns a singleton condition mode
 */
ir_mode *get_ppc32_mode_Cond(void) {
	if (ppc32_mode_Cond)
		return ppc32_mode_Cond;
	else {
79
		ppc32_mode_Cond = new_ir_mode("mode_Cond", irms_int_number, 4, 0, irma_none, 0);
80
81
82
83
84
		return ppc32_mode_Cond;
	}
}

/**
85
 * Calculates the ir_modecode with size, sort and signed attributes
86
 */
87
ir_modecode get_nice_modecode(ir_mode *irmode)
88
{
89
	ir_modecode mode = irm_max;
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
	int sign = mode_is_signed(irmode);
	int bits = get_mode_size_bits(irmode);
	if(mode_is_int(irmode))
	{
		switch(bits)
		{
			case 8:
				mode = sign ? irm_Bs : irm_Bu;
				break;
			case 16:
				mode = sign ? irm_Hs : irm_Hu;
				break;
			case 32:
				mode = sign ? irm_Is : irm_Iu;
				break;
		}
	}
	else if(mode_is_float(irmode))
	{
		switch(bits)
		{
			case 32:
				mode = irm_F;
				break;
			case 64:
				mode = irm_D;
				break;
		}
	}
	else if(mode_is_reference(irmode))
	{
		switch(bits)
		{
			case 32:
				mode = irm_P;
				break;
		}
	}
	return mode;
}

/**
 * Returns true, if the given node is a Const node and it's value fits into
 * a signed 16-bit variable
 */
int is_16bit_signed_const(ir_node *node)
{
	tarval *tv_const;

	if(!is_ppc32_Const(node)) return 0;

	tv_const = get_ppc32_constant_tarval(node);

	switch(get_nice_modecode(get_irn_mode(node)))
	{
		case irm_Bu:
		case irm_Bs:
		case irm_Hs:
			return 1;
		case irm_Iu:
		case irm_P:
		{
			unsigned char val2 = get_tarval_sub_bits(tv_const, 2);
			unsigned char val3 = get_tarval_sub_bits(tv_const, 3);
			if(val2 || val3)
				return 0;

			// fall through
		}
		case irm_Hu:
		{
			unsigned char val1 = get_tarval_sub_bits(tv_const, 1);
			if(val1&0x80)
				return 0;
			return 1;
		}

		case irm_Is:
		{
			unsigned char val2 = get_tarval_sub_bits(tv_const, 2);
			unsigned char val3 = get_tarval_sub_bits(tv_const, 3);
			if(val2==0 && val3==0)
			{
				unsigned char val1 = get_tarval_sub_bits(tv_const, 1);
				if(val1&0x80)
					return 0;
				return 1;
			}
			if(!(val2==0xff && val3==0xff))
			{
				unsigned char val1 = get_tarval_sub_bits(tv_const, 1);
				if(!(val1&0x80))
					return 0;
				return 1;
			}
			return 0;
		}
		default:
188
			panic("is_16bit_signed_const(): Mode not supported: %F", get_irn_mode(node));
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
	}
}

/**
 * Returns true, if the given node is a Const node and it's value fits into
 * a unsigned 16-bit variable
 */
int is_16bit_unsigned_const(ir_node *node)
{
	tarval *tv_const;

	if(!is_ppc32_Const(node)) return 0;

	tv_const = get_ppc32_constant_tarval(node);
	switch(get_nice_modecode(get_irn_mode(node)))
	{
		case irm_Bu:
		case irm_Bs:
		case irm_Hs:
		case irm_Hu:
			return 1;
		case irm_Iu:
		case irm_P:
		case irm_Is:
		{
			unsigned char val2 = get_tarval_sub_bits(tv_const, 2);
			unsigned char val3 = get_tarval_sub_bits(tv_const, 3);
			if(val2 || val3)
				return 0;
			return 1;
		}
		default:
221
			panic("is_16bit_unsigned_const(): Mode not supported: %F", get_irn_mode(node));
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
	}
}


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

/**
 * Creates an ppc Add.
 *
 * @param env   The transformation environment
 * @return the created ppc Add node
 */
242
243
244
245
static ir_node *gen_Add(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Add_left(env->irn);
	ir_node *op2 = get_Add_right(env->irn);

246
247
	switch(get_nice_modecode(env->mode)){
		case irm_D:
248
			return new_bd_ppc32_fAdd(env->dbg, env->block, op1, op2, env->mode);
249
		case irm_F:
250
			return new_bd_ppc32_fAdds(env->dbg, env->block, op1, op2, env->mode);
251
252
253
254
255
256
257
258
259
		case irm_Is:
		case irm_Iu:
		case irm_Hs:
		case irm_Hu:
		case irm_Bs:
		case irm_Bu:
		case irm_P:
			if(is_16bit_signed_const(op1))
			{
260
				ir_node *addnode = new_bd_ppc32_Addi(env->dbg, env->block, op2, env->mode);
261
262
263
264
265
266
				set_ppc32_constant_tarval(addnode, get_ppc32_constant_tarval(op1));
				set_ppc32_offset_mode(addnode, ppc32_ao_None);
				return addnode;
			}
			if(is_16bit_signed_const(op2))
			{
267
				ir_node *addnode = new_bd_ppc32_Addi(env->dbg, env->block, op1, env->mode);
268
269
270
271
272
				set_ppc32_constant_tarval(addnode, get_ppc32_constant_tarval(op2));
				set_ppc32_offset_mode(addnode, ppc32_ao_None);
				return addnode;
			}

273
			return new_bd_ppc32_Add(env->dbg, env->block, op1, op2, env->mode);
274
275

		default:
276
			panic("Mode for Add not supported: %F", env->mode);
277
278
279
280
281
282
	}
}

/**
 * Creates an ppc Mul.
 *
283
 * @param env   The transformation environment
284
285
 * @return the created ppc Mul node
 */
286
287
288
289
static ir_node *gen_Mul(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Mul_left(env->irn);
	ir_node *op2 = get_Mul_right(env->irn);

290
291
	switch(get_nice_modecode(env->mode)){
		case irm_D:
292
			return new_bd_ppc32_fMul(env->dbg, env->block, op1, op2, env->mode);
293
		case irm_F:
294
			return new_bd_ppc32_fMuls(env->dbg, env->block, op1, op2, env->mode);
295
296
297
298
299
300
		case irm_Is:
		case irm_Iu:
		case irm_Hs:
		case irm_Hu:
		case irm_Bs:
		case irm_Bu:
301
			return new_bd_ppc32_Mullw(env->dbg, env->block, op1, op2, env->mode);
302
303
304

		case irm_P:
		default:
305
			panic("Mode for Mul not supported: %F", env->mode);
306
307
308
309
310
311
	}
}

/**
 * Creates an ppc Mulh.
 *
312
 * @param env   The transformation environment
313
314
 * @return the created ppc Mulh node
 */
315
316
317
318
static ir_node *gen_Mulh(ppc32_transform_env_t *env) {
	ir_node *op1 = get_irn_n(env->irn, 0);
	ir_node *op2 = get_irn_n(env->irn, 1);

319
320
321
322
	switch(get_nice_modecode(env->mode)){
		case irm_Is:
		case irm_Hs:
		case irm_Bs:
323
			return new_bd_ppc32_Mulhw(env->dbg, env->block, op1, op2, env->mode);
324
325
326
327

		case irm_Iu:
		case irm_Hu:
		case irm_Bu:
328
			return new_bd_ppc32_Mulhwu(env->dbg, env->block, op1, op2, env->mode);
329
330
331
332
333

		case irm_D:
		case irm_F:
		case irm_P:
		default:
334
			panic("Mode for Mulh not supported: %F", env->mode);
335
336
337
338
339
340
	}
}

/**
 * Creates an ppc And.
 *
341
 * @param env   The transformation environment
342
343
 * @return the created ppc And node
 */
344
345
346
347
static ir_node *gen_And(ppc32_transform_env_t *env) {
	ir_node *op1 = get_And_left(env->irn);
	ir_node *op2 = get_And_right(env->irn);

348
	return new_bd_ppc32_And(env->dbg, env->block, op1, op2, env->mode);
349
350
351
352
353
}

/**
 * Creates an ppc Or.
 *
354
 * @param env   The transformation environment
355
356
 * @return the created ppc Or node
 */
357
358
359
360
static ir_node *gen_Or(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Or_left(env->irn);
	ir_node *op2 = get_Or_right(env->irn);

361
	return new_bd_ppc32_Or(env->dbg, env->block, op1, op2, env->mode);
362
363
364
365
366
}

/**
 * Creates an ppc Xor.
 *
367
 * @param env   The transformation environment
368
369
 * @return the created ppc Xor node
 */
370
371
372
373
static ir_node *gen_Eor(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Eor_left(env->irn);
	ir_node *op2 = get_Eor_right(env->irn);

374
	return new_bd_ppc32_Xor(env->dbg, env->block, op1, op2, env->mode);
375
376
377
378
379
}

/**
 * Creates an ppc Sub.
 *
380
 * @param env   The transformation environment
381
382
 * @return the created ppc Sub node
 */
383
384
385
386
static ir_node *gen_Sub(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Sub_left(env->irn);
	ir_node *op2 = get_Sub_right(env->irn);

387
388
	switch(get_nice_modecode(env->mode)){
		case irm_D:
389
			return new_bd_ppc32_fSub(env->dbg, env->block, op1, op2, env->mode);
390
		case irm_F:
391
			return new_bd_ppc32_fSubs(env->dbg, env->block, op1, op2, env->mode);
392
393
394
395
396
397
398
		case irm_Is:
		case irm_Iu:
		case irm_Hs:
		case irm_Hu:
		case irm_Bs:
		case irm_Bu:
		case irm_P:
399
			return new_bd_ppc32_Sub(env->dbg, env->block, op1, op2, env->mode);
400
401

		default:
402
			panic("Mode for Sub not supported: %F", env->mode);
403
404
405
406
407
408
	}
}

/**
 * Creates an ppc floating Div.
 *
409
 * @param env   The transformation environment
410
411
 * @return the created ppc fDiv node
 */
412
413
414
415
static ir_node *gen_Quot(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Quot_left(env->irn);
	ir_node *op2 = get_Quot_right(env->irn);

416
417
	switch(get_nice_modecode(env->mode)){
		case irm_D:
418
			return new_bd_ppc32_fDiv(env->dbg, env->block, op1, op2, env->mode);
419
		case irm_F:
420
			return new_bd_ppc32_fDivs(env->dbg, env->block, op1, op2, env->mode);
421
422

		default:
423
			panic("Mode for Quot not supported: %F", env->mode);
424
425
426
427
428
429
	}
}

/**
 * Creates an ppc integer Div.
 *
430
 * @param env   The transformation environment
431
432
 * @return the created ppc Div node
 */
433
434
435
static ir_node *gen_Div(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Div_left(env->irn);
	ir_node *op2 = get_Div_right(env->irn);
436

437
	switch(get_nice_modecode(get_irn_mode(op1))){
438
439
440
		case irm_Is:
		case irm_Hs:
		case irm_Bs:
441
			return new_bd_ppc32_Divw(env->dbg, env->block, op1, op2, mode_T);
442
443
444
445

		case irm_Iu:
		case irm_Hu:
		case irm_Bu:
446
			return new_bd_ppc32_Divwu(env->dbg, env->block, op1, op2, mode_T);
447
448

		default:
449
			panic("Mode for Div not supported: %F", get_irn_mode(op1));
450
451
452
453
454
455
	}
}

/**
 * Creates an ppc integer Div and Mod.
 *
456
 * @param env   The transformation environment
457
458
 * @return the created ppc Div node
 */
459
460
461
static ir_node *gen_DivMod(ppc32_transform_env_t *env) {
	ir_node *op1 = get_DivMod_left(env->irn);
	ir_node *op2 = get_DivMod_right(env->irn);
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
	ir_node *proj_div = NULL, *proj_mod = NULL;
	ir_node *div_result;
	const ir_edge_t *edge;
	ir_mode *res_mode;

	foreach_out_edge(env->irn, edge)
	{
		if (is_Proj(edge->src))
		{
			switch(get_Proj_proj(edge->src)){
				case pn_DivMod_res_div:
					proj_div = edge->src;
					break;
				case pn_DivMod_res_mod:
					proj_mod = edge->src;
					break;
				default:
					break;
			}
		}
	}

	assert(proj_div!=NULL || proj_mod!=NULL);

	res_mode = get_irn_mode(proj_div);

	switch(get_nice_modecode(res_mode))
	{
		case irm_Is:
		case irm_Hs:
		case irm_Bs:
493
			div_result = new_bd_ppc32_Divw(env->dbg, env->block, op1, op2, mode_T);
494
495
496
497
498
			break;

		case irm_Iu:
		case irm_Hu:
		case irm_Bu:
499
			div_result = new_bd_ppc32_Divwu(env->dbg, env->block, op1, op2, mode_T);
500
501
502
			break;

		default:
503
			panic("Mode for DivMod not supported: %F", res_mode);
504
505
506
507
508
509
510
511
512
	}

	if (proj_div == NULL)
		proj_div = new_rd_Proj(env->dbg, env->irg, env->block, div_result, get_irn_mode(proj_mod), pn_DivMod_res_div);

	if (proj_mod!=NULL){
		ir_node *mul_result;
		ir_node *mod_result;

513
514
		mul_result = new_bd_ppc32_Mullw(env->dbg, env->block, proj_div, op2, res_mode);
		mod_result = new_bd_ppc32_Sub(env->dbg, env->block, op1, mul_result, res_mode);
515
516
517
518
519
520
521
522
523
524

		exchange(proj_mod, mod_result);
	}

	return div_result;
}

/**
 * Creates an ppc integer Mod.
 *
525
 * @param env   The transformation environment
526
527
 * @return the created ppc Mod result node
 */
528
529
530
static ir_node *gen_Mod(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Mod_left(env->irn);
	ir_node *op2 = get_Mod_right(env->irn);
531
532
533
534
535
536
537
538
	ir_node *proj_div = NULL, *proj_mod = NULL;
	ir_node *div_result;
	ir_mode *res_mode;
	ir_node *mul_result;
	ir_node *mod_result;

	proj_mod = get_succ_Proj(env->irn, pn_Mod_res);

539
	assert(proj_mod != NULL);
540
541
542
543
544
545
546
	res_mode = get_irn_mode(proj_mod);

	switch(get_nice_modecode(res_mode))
	{
		case irm_Is:
		case irm_Hs:
		case irm_Bs:
547
			div_result = new_bd_ppc32_Divw(env->dbg, env->block, op1, op2, mode_T);
548
549
550
551
552
			break;

		case irm_Iu:
		case irm_Hu:
		case irm_Bu:
553
			div_result = new_bd_ppc32_Divwu(env->dbg, env->block, op1, op2, mode_T);
554
555
556
557
558
			break;

		default:
			fprintf(stderr, "Mode for Mod not supported: %s\n", get_mode_name(res_mode));
			assert(0);
559
			return NULL;
560
561
562
563
564

	}

	proj_div = new_rd_Proj(env->dbg, env->irg, env->block, div_result, res_mode, pn_DivMod_res_div);

565
566
	mul_result = new_bd_ppc32_Mullw(env->dbg, env->block, proj_div, op2, res_mode);
	mod_result = new_bd_ppc32_Sub(env->dbg, env->block, op1, mul_result, res_mode);
567
568
569
570
571
572
573
574
575

	exchange(proj_mod, mod_result);

	return div_result;
}

/**
 * Creates an ppc Shl.
 *
576
 * @param env   The transformation environment
577
578
 * @return the created ppc Shl node
 */
579
580
581
582
static ir_node *gen_Shl(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Shl_left(env->irn);
	ir_node *op2 = get_Shl_right(env->irn);

583
584
	if(is_ppc32_Const(op2))
	{
585
		ir_node *shift = new_bd_ppc32_Rlwinm(env->dbg, env->block, op1, env->mode);
586
587
588
589
590
591
		tarval *tv_const = get_ppc32_constant_tarval(op2);
		int sh = get_tarval_long(tv_const);
		assert(0<=sh && sh<=31);
		set_ppc32_rlwimi_const(shift, sh, 0, 31-sh);
		return shift;
	}
592
	return new_bd_ppc32_Slw(env->dbg, env->block, op1, op2, env->mode);
593
594
595
596
597
}

/**
 * Creates an ppc Srw.
 *
598
 * @param env   The transformation environment
599
600
 * @return the created ppc Shr node
 */
601
602
603
604
static ir_node *gen_Shr(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Shr_left(env->irn);
	ir_node *op2 = get_Shr_right(env->irn);

605
606
	if(is_ppc32_Const(op2))
	{
607
		ir_node *shift = new_bd_ppc32_Rlwinm(env->dbg, env->block, op1, env->mode);
608
609
610
611
612
613
		tarval *tv_const = get_ppc32_constant_tarval(op2);
		int sh = get_tarval_long(tv_const);
		assert(0<=sh && sh<=31);
		set_ppc32_rlwimi_const(shift, 32-sh, sh, 31);
		return shift;
	}
614
	return new_bd_ppc32_Srw(env->dbg, env->block, op1, op2, env->mode);
615
616
617
618
619
}

/**
 * Creates an ppc Sraw.
 *
620
 * @param env   The transformation environment
621
622
 * @return the created ppc Sraw node
 */
623
624
625
626
static ir_node *gen_Shrs(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Shrs_left(env->irn);
	ir_node *op2 = get_Shrs_right(env->irn);

627
628
	if(is_ppc32_Const(op2))
	{
629
		ir_node *shift = new_bd_ppc32_Srawi(env->dbg, env->block, op1, env->mode);
630
631
632
		tarval *tv_const = get_ppc32_constant_tarval(op2);
		int sh = get_tarval_long(tv_const);
		assert(0<=sh && sh<=31);
633
		(void) sh;
634
635
636
637
		set_ppc32_constant_tarval(shift, tv_const);
		set_ppc32_offset_mode(shift, ppc32_ao_None);
		return shift;
	}
638
	return new_bd_ppc32_Sraw(env->dbg, env->block, op1, op2, env->mode);
639
640
641
}

/**
642
 * Creates an ppc Rotl.
643
 *
644
 * @param env   The transformation environment
645
 * @return the created ppc Rotl node
646
 */
647
648
649
static ir_node *gen_Rotl(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Rotl_left(env->irn);
	ir_node *op2 = get_Rotl_right(env->irn);
650

651
652
	if(is_ppc32_Const(op2))
	{
653
		ir_node *rot = new_bd_ppc32_Rlwinm(env->dbg, env->block, op1, env->mode);
654
655
656
657
658
659
		tarval *tv_const = get_ppc32_constant_tarval(op2);
		int sh = get_tarval_long(tv_const);
		assert(0<=sh && sh<=31);
		set_ppc32_rlwimi_const(rot, sh, 0, 31);
		return rot;
	}
660
	return new_bd_ppc32_Rlwnm(env->dbg, env->block, op1, op2, env->mode);
661
662
663
664
665
}

/**
 * Creates an ppc Cmp.
 *
666
 * @param env   The transformation environment
667
668
 * @return the created ppc Cmp node
 */
669
670
671
672
static ir_node *gen_Cmp(ppc32_transform_env_t *env) {
	ir_node *op1 = get_Cmp_left(env->irn);
	ir_node *op2 = get_Cmp_right(env->irn);

673
674
675
676
677
678
679
680
	const ir_edge_t *edge;
	foreach_out_edge(env->irn, edge)
	{
		if (is_Proj(edge->src))
			set_irn_mode(edge->src, get_ppc32_mode_Cond());
	}

	if(mode_is_float(env->mode))
681
		return new_bd_ppc32_fCmpu(env->dbg, env->block, op1, op2, env->mode);
682
683
684
685
	else if(mode_is_signed(env->mode))
	{
		if(is_16bit_signed_const(op2))
		{
686
			ir_node *cmp = new_bd_ppc32_Cmpi(env->dbg, env->block, op1, env->mode);
687
688
689
690
691
692
693
			tarval *tv_const = get_ppc32_constant_tarval(op2);
			set_ppc32_constant_tarval(cmp, tv_const);
			set_ppc32_offset_mode(cmp, ppc32_ao_None);
			return cmp;
		}
		else
		{
694
			return new_bd_ppc32_Cmp(env->dbg, env->block, op1, op2, env->mode);
695
696
697
698
699
700
		}
	}
	else
	{
		if(is_16bit_unsigned_const(op2))
		{
701
			ir_node *cmp = new_bd_ppc32_Cmpli(env->dbg, env->block, op1, env->mode);
702
703
704
705
706
707
708
709
			tarval *tv_const = get_ppc32_constant_tarval(op2);
			set_ppc32_constant_tarval(cmp, tv_const);
			set_ppc32_offset_mode(cmp, ppc32_ao_None);

			return cmp;
		}
		else
		{
710
			return new_bd_ppc32_Cmpl(env->dbg, env->block, op1, op2, env->mode);
711
712
713
714
715
716
717
		}
	}
}

/**
 * Transforms a Minus node.
 *
718
 * @param env   The transformation environment
719
720
 * @return the created ppc Minus node
 */
721
722
723
static ir_node *gen_Minus(ppc32_transform_env_t *env) {
	ir_node *op = get_Minus_op(env->irn);

724
725
726
	switch(get_nice_modecode(env->mode)){
		case irm_D:
		case irm_F:
727
			return new_bd_ppc32_fNeg(env->dbg, env->block, op, env->mode);
728
729
730
731
732
733
734
		case irm_Is:
		case irm_Iu:
		case irm_Hs:
		case irm_Hu:
		case irm_Bs:
		case irm_Bu:
		case irm_P:
735
			return new_bd_ppc32_Neg(env->dbg, env->block, op, env->mode);
736
737

		default:
738
			panic("Mode for Neg not supported: %F", env->mode);
739
740
741
742
743
744
	}
}

/**
 * Transforms a Not node.
 *
745
 * @param env   The transformation environment
746
747
 * @return the created ppc Not node
 */
748
static ir_node *gen_Not(ppc32_transform_env_t *env) {
749
	return new_bd_ppc32_Not(env->dbg, env->block, get_Not_op(env->irn), env->mode);
750
751
752
753
754
}


static ir_node *own_gen_Andi_dot_lo16(ppc32_transform_env_t *env, ir_node *op, int mask)
{
755
	ir_node *andi = new_bd_ppc32_Andi_dot(env->dbg, env->block, op, mode_T);
756
757
758
759
760
761
762
763
764
765
766
	ir_node* in[1];
	set_ppc32_offset_mode(andi, ppc32_ao_Lo16);
	set_ppc32_constant_tarval(andi, new_tarval_from_long(mask, mode_Is));
	in[0] = new_rd_Proj(env->dbg, env->irg, env->block, andi, env->mode,1);
	be_new_Keep(&ppc32_reg_classes[CLASS_ppc32_condition], env->irg, env->block, 1, in);
	return new_rd_Proj(env->dbg, env->irg, env->block, andi, env->mode,0);
}

/**
 * Transforms a Conv node.
 *
767
 * @param env   The transformation environment
768
769
 * @return the created ppc Conv node
 */
770
771
static ir_node *gen_Conv(ppc32_transform_env_t *env) {
	ir_node *op = get_Conv_op(env->irn);
772
773
	ir_modecode from_mode=get_nice_modecode(get_irn_mode(op));
	ir_modecode to_mode=get_nice_modecode(env->mode);
774

775
#define SKIP return op
776
777
778
779
780
781
782
783

	if(from_mode == to_mode) SKIP;

	switch(from_mode){
		case irm_F:
			switch(to_mode)
			{
				case irm_D: SKIP;
784
785
				default:
					break;
786
787
788
789
790
791
792
			}
			break;

		case irm_D:
			switch(to_mode)
			{
				case irm_F:
793
					return new_bd_ppc32_fRsp(env->dbg, env->block, op, env->mode);
794
795
				default:
					break;
796
797
798
799
800
801
802
803
			}
			break;

		case irm_Is:
		case irm_Iu:
			switch(to_mode)
			{
				case irm_Hs:
804
					return new_bd_ppc32_Extsh(env->dbg, env->block, op, env->mode);
805
806
807
				case irm_Hu:
					return own_gen_Andi_dot_lo16(env, op, 0xffff);
				case irm_Bs:
808
					return new_bd_ppc32_Extsb(env->dbg, env->block, op, env->mode);
809
810
811
812
813
				case irm_Bu:
					return own_gen_Andi_dot_lo16(env, op, 0xff);
				case irm_Is:
				case irm_Iu:
					SKIP;
814
815
				default:
					break;
816
817
818
819
820
821
822
823
824
825
826
827
828
829
			}
			break;

		case irm_Hs:
		case irm_Hu:
			switch(to_mode)
			{
				case irm_Iu:
					if(from_mode==irm_Hu)
				case irm_Hu:
						return own_gen_Andi_dot_lo16(env, op, 0xffff);
				case irm_Is:
					SKIP;
				case irm_Bs:
830
					return new_bd_ppc32_Extsb(env->dbg, env->block, op, env->mode);
831
832
833
				case irm_Bu:
					return own_gen_Andi_dot_lo16(env, op, 0xff);
				case irm_Hs:
834
					return new_bd_ppc32_Extsh(env->dbg, env->block, op, env->mode);
835
836
				default:
					break;
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
			}
			break;

		case irm_Bs:
		case irm_Bu:
			switch(to_mode)
			{
				case irm_Iu:
				case irm_Hu:
					if(from_mode==irm_Bs)
				case irm_Bu:
						return own_gen_Andi_dot_lo16(env, op, 0xff);
				case irm_Is:
				case irm_Hs:
					SKIP;
				case irm_Bs:
853
					return new_bd_ppc32_Extsb(env->dbg, env->block, op, env->mode);
854
855
				default:
					break;
856
857
858
859
860
			}
			break;
		case irm_P:
			if(to_mode==irm_Is || to_mode==irm_Iu) SKIP;
			break;
861
862
		default:
			break;
863
864
	}

865
	panic("Mode for Conv not supported: %F -> %F", get_irn_mode(op), env->mode);
866
#undef SKIP
867
}
868
869
870
871

/**
 * Transforms an Abs node.
 *
872
 * @param env   The transformation environment
873
874
 * @return the ppc node generating the absolute value
 */
875
876
static ir_node *gen_Abs(ppc32_transform_env_t *env) {
	ir_node *op = get_Abs_op(env->irn);
877
	int shift = 7;
878
879
	ir_node *n1,*n2;

880
881
882
883
	switch(get_nice_modecode(env->mode))
	{
		case irm_F:
		case irm_D:
884
			return new_bd_ppc32_fAbs(env->dbg, env->block, op, env->mode);
885
886
887
888
		case irm_Is:
			shift += 16;
		case irm_Hs:
			shift += 8;
889
		case irm_Bs:
890
			n1 = new_bd_ppc32_Srawi(env->dbg, env->block, op, env->mode);
891
892
			set_ppc32_constant_tarval(n1, new_tarval_from_long(shift, mode_Is));
			set_ppc32_offset_mode(n1, ppc32_ao_None);
893
894
			n2 = new_bd_ppc32_Add(env->dbg, env->block, op, n1, env->mode);
			return new_bd_ppc32_Xor(env->dbg, env->block, n2, n1, env->mode);
895
896
		default:
			break;
897
	}
898
	panic("Mode for Abs not supported: %F", env->mode);
899
	return NULL;
900
901
902
903
904
}

/**
 * Transforms an Cond node.
 *
905
 * @param env   The transformation environment
906
907
908
909
910
911
912
913
 * @return a ppc branch node
 */
static ir_node *gen_Cond(ppc32_transform_env_t *env) {
	ir_node *selector = get_Cond_selector(env->irn);
	ir_mode *projmode = get_irn_mode(selector);
	if(is_Proj(selector) && projmode==get_ppc32_mode_Cond())
	{
		int projnum = get_Proj_proj(selector);
914
		ir_node *branch = new_bd_ppc32_Branch(env->dbg, env->block, selector, env->mode);
915
916
917
918
919
		set_ppc32_proj_nr(branch, projnum);
		return branch;
	}
	else
	{
920
921
		ir_node *unknown_gpr = new_bd_ppc32_Unknown(env->dbg, env->block, mode_Is);
		ir_node *unknown_cond = new_bd_ppc32_cUnknown(env->dbg, env->block, get_ppc32_mode_Cond());
922

923
		ir_node *switch_node = new_bd_ppc32_Switch(env->dbg, env->block, selector,
924
925
926
927
928
929
930
931
932
933
			unknown_gpr, unknown_cond, env->mode);
		set_ppc32_proj_nr(switch_node, get_Cond_defaultProj(env->irn));

		return switch_node;
	}
}

/**
 * Transforms an Unknown node.
 *
934
 * @param env   The transformation environment
935
936
937
938
 * @return a ppc Unknown node
 */
static ir_node *gen_Unknown(ppc32_transform_env_t *env) {
	if(mode_is_float(env->mode))
939
		return new_bd_ppc32_fUnknown(env->dbg, env->block, env->mode);
940
	else if (mode_is_int(env->mode))
941
		return new_bd_ppc32_Unknown(env->dbg, env->block, env->mode);
942
	else
943
		panic("Mode %F for unknown value not supported.", env->mode);
944
945
946
947
948
949
950
951
952
}

static ir_node *ldst_insert_const(ir_node *ptr, tarval **ptv, ident **pid, ppc32_transform_env_t *env) {
	tarval *tv_const = NULL;
	ident *id_symconst = NULL;

	if(is_ppc32_Const(ptr))
	{
		tv_const = get_ppc32_constant_tarval(ptr);
953
		ptr = new_bd_ppc32_Addis_zero(env->dbg, env->block, mode_P, ppc32_ao_Ha16, tv_const, NULL);
954
955
956
	}
	else if(is_ppc32_SymConst(ptr))
	{
957
		ir_entity *ent = get_ppc32_frame_entity(ptr);
958
959
960
		if(is_direct_entity(ent))
		{
			id_symconst = get_entity_ident(ent);
961
			ptr = new_bd_ppc32_Addis_zero(env->dbg, env->block, mode_P, ppc32_ao_Ha16, NULL, id_symconst);
962
963
964
965
966
967
968
969
970
971
		}
	}
	*ptv = tv_const;
	*pid = id_symconst;
	return ptr;
}

/**
 * Transforms a Load.
 *
972
 * @param env   The transformation environment
973
974
975
976
977
978
979
980
981
982
983
984
985
 * @return the created ppc Load node
 */
static ir_node *gen_Load(ppc32_transform_env_t *env) {
	ir_node *node = env->irn;
	ir_node *loadptr = get_Load_ptr(node);
	ir_node *load;
	ir_mode *mode = get_Load_mode(node);
	tarval *tv_const = NULL;
	ident *id_symconst = NULL;

	loadptr = ldst_insert_const(loadptr, &tv_const, &id_symconst, env);
	switch(get_nice_modecode(mode)){
		case irm_Bu:
986
			load = new_bd_ppc32_Lbz(env->dbg, env->block, loadptr, get_Load_mem(node));
987
988
989
990
991
			break;

		case irm_Bs:
		{
			ir_node *proj_load, *extsb_node;
992
			load =  new_bd_ppc32_Lbz(env->dbg, env->block, loadptr, get_Load_mem(node));
993
			proj_load = new_rd_Proj(env->dbg, env->irg, env->block, load, mode, pn_Load_res);
994
			extsb_node = new_bd_ppc32_Extsb(env->dbg, env->block, proj_load, mode);
995
996
997
998
999
1000
			exchange(get_succ_Proj(env->irn, pn_Load_res), extsb_node);
			break;
		}


		case irm_Hu:
1001
			load = new_bd_ppc32_Lhz(env->dbg, env->block, loadptr, get_Load_mem(node));
1002
1003
			break;
		case irm_Hs:
1004
			load =new_bd_ppc32_Lha(env->dbg, env->block, loadptr, get_Load_mem(node));
1005
1006
1007
1008
			break;
		case irm_Is:
		case irm_Iu:
		case irm_P:
1009
			load = new_bd_ppc32_Lwz(env->dbg, env->block, loadptr, get_Load_mem(node));
1010
1011
1012
			break;

		case irm_D:
1013
			load = new_bd_ppc32_Lfd(env->dbg, env->block, loadptr, get_Load_mem(node));
1014
1015
			break;
		case irm_F:
1016
			load = new_bd_ppc32_Lfs(env->dbg, env->block, loadptr, get_Load_mem(node));
1017
1018
1019
			break;

		default:
1020
			panic("Mode for Load not supported: %F", env->mode);
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
	}

	if(tv_const)
	{
		set_ppc32_offset_mode(load, ppc32_ao_Lo16);
		set_ppc32_constant_tarval(load, tv_const);
	}
	else if(id_symconst)
	{
		set_ppc32_offset_mode(load, ppc32_ao_Lo16);
		set_ppc32_symconst_ident(load, id_symconst);
	}
	return load;
}



/**
 * Transforms a Store.
 *
1041
 * @param env   The transformation environment
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
 * @return the created ppc Store node
 */
static ir_node *gen_Store(ppc32_transform_env_t *env) {
	ir_node *node = env->irn;
	ir_node *storeptr = get_Store_ptr(node);
	ir_node *valuenode = get_Store_value(node);
	ir_mode *mode = get_irn_mode(valuenode);
	ir_node *store;
	tarval *tv_const = NULL;
	ident *id_symconst = NULL;

	storeptr = ldst_insert_const(storeptr, &tv_const, &id_symconst, env);

	switch(get_nice_modecode(mode)){
		case irm_Bu:
		case irm_Bs:
1058
			store = new_bd_ppc32_Stb(env->dbg, env->block, storeptr, get_Store_value(node), get_Store_mem(node));
1059
1060
1061
1062
			break;

		case irm_Hu:
		case irm_Hs:
1063
			store = new_bd_ppc32_Sth(env->dbg, env->block, storeptr, get_Store_value(node), get_Store_mem(node));
1064
1065
1066
1067
			break;
		case irm_Is:
		case irm_Iu:
		case irm_P:
1068
			store = new_bd_ppc32_Stw(env->dbg, env->block, storeptr, get_Store_value(node), get_Store_mem(node));
1069
1070
1071
			break;

		case irm_D:
1072
			store = new_bd_ppc32_Stfd(env->dbg, env->block, storeptr, get_Store_value(node), get_Store_mem(node));
1073
1074
			break;
		case irm_F:
1075
			store = new_bd_ppc32_Stfs(env->dbg, env->block, storeptr, get_Store_value(node), get_Store_mem(node));
1076
1077
1078
			break;

		default:
1079
			panic("Mode for Store not supported: %F", env->mode);
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
	}
	if(tv_const)
	{
		set_ppc32_offset_mode(store, ppc32_ao_Lo16);
		set_ppc32_constant_tarval(store, tv_const);
	}
	else if(id_symconst)
	{
		set_ppc32_offset_mode(store, ppc32_ao_Lo16);
		set_ppc32_symconst_ident(store, id_symconst);
	}
	return store;
}

/**
 * Transforms a CopyB.
 *
1097
 * @param env   The transformation environment
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
 * @return the created ppc CopyB node
 */
static ir_node *gen_CopyB(ppc32_transform_env_t *env) {
	ir_node *mem = get_CopyB_mem(env->irn);
	ir_node *src = get_CopyB_src(env->irn);
	ir_node *dest = get_CopyB_dst(env->irn);
	ir_type *type = get_CopyB_type(env->irn);
	int size = get_type_size_bytes(type);
	int offset = 0;

Matthias Braun's avatar
Matthias Braun committed
1108
	ir_node *load, *store = NULL;
1109

Matthias Braun's avatar
Matthias Braun committed
1110
	if(size/4 >= 1)
1111
1112
1113
1114
1115
	{
		ir_node *res;
		tarval *offset0 = new_tarval_from_long(0, mode_Is);
		tarval *offset4 = new_tarval_from_long(4, mode_Is);

1116
		load = new_bd_ppc32_Lwz(env->dbg, env->block, src, mem);
1117
1118
1119
1120
1121
		set_ppc32_constant_tarval(load, offset0);
		set_ppc32_offset_mode(load, ppc32_ao_None);
		mem = new_rd_Proj(env->dbg, env->irg, env->block, load, mode_M, pn_Load_M);
		res = new_rd_Proj(env->dbg, env->irg, env->block, load, mode_Is, pn_Load_res);

1122
		store = new_bd_ppc32_Stw(env->dbg, env->block, dest, res, mem);
1123
1124
1125
1126
1127
1128
		set_ppc32_constant_tarval(store, offset0);
		set_ppc32_offset_mode(store, ppc32_ao_None);
		mem = new_rd_Proj(env->dbg, env->irg, env->block, store, mode_M, pn_Store_M);

		if(size/4==2)
		{
1129
			load = new_bd_ppc32_Lwz(env->dbg, env->block, src, mem);
1130
1131
1132
1133
1134
			set_ppc32_constant_tarval(load, offset4);
			set_ppc32_offset_mode(load, ppc32_ao_None);
			mem = new_rd_Proj(env->dbg, env->irg, env->block, load, mode_M, pn_Load_M);
			res = new_rd_Proj(env->dbg, env->irg, env->block, load, mode_Is, pn_Load_res);

1135
			store = new_bd_ppc32_Stw(env->dbg, env->block, dest, res, mem);
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
			set_ppc32_constant_tarval(store, offset4);
			set_ppc32_offset_mode(store, ppc32_ao_None);
			mem = new_rd_Proj(env->dbg, env->irg, env->block, store, mode_M, pn_Store_M);

			offset = 8;
		}
		else
		{
			ir_node *ornode, *mtctrnode;
			ir_node* in[3];
			assert(size/4-1<=0xffff);
			if(size/4-1<0x8000)
			{
1149
				ornode = new_bd_ppc32_Addi_zero(env->dbg, env->block, mode_Is);
1150
1151
1152
1153
				set_ppc32_offset_mode(ornode, ppc32_ao_None);
			}
			else
			{
1154
				ir_node *zeroreg = new_bd_ppc32_Addi_zero(env->dbg, env->block, mode_Is);
1155
1156
				set_ppc32_offset_mode(zeroreg, ppc32_ao_None);
				set_ppc32_constant_tarval(zeroreg, new_tarval_from_long(0, mode_Is));
1157
				ornode = new_bd_ppc32_Ori(env->dbg, env->block, zeroreg, mode_Is);
1158
1159
1160
1161
				set_ppc32_offset_mode(ornode, ppc32_ao_Lo16);
			}

			set_ppc32_constant_tarval(ornode, new_tarval_from_long(size/4-1, mode_Is));
1162
1163
			mtctrnode = new_bd_ppc32_Mtctr(env->dbg, env->block, ornode, mode_Is);
			store = new_bd_ppc32_LoopCopy(env->dbg, env->block, src, dest, mtctrnode, mem, mode_T);
1164
1165
1166
1167

			in[0] = new_rd_Proj(env->dbg, env->irg, env->block, store, mode_Is, 1); // src
			in[1] =	new_rd_Proj(env->dbg, env->irg, env->block, store, mode_Is, 2);	// dest
			in[2] =	new_rd_Proj(env->dbg, env->irg, env->block, store, mode_Is, 4);	// temp
Michael Beck's avatar
Michael Beck committed
1168
			be_new_Keep(&ppc32_reg_classes[CLASS_ppc32_gp], env->irg, env->block, 3, in);
1169
1170
1171
1172
1173
1174
1175
1176
1177
			in[0] = new_rd_Proj(env->dbg, env->irg, env->block, store, mode_Is, 3); // ctr
			be_new_Keep(&ppc32_reg_classes[CLASS_ppc32_count], env->irg, env->block, 1, in);

			mem = new_rd_Proj(env->dbg, env->irg, env->block, store, mode_M, 0);

			offset = 4;
		}
	}

1178
	if(size & 2)
1179
1180
1181
	{
		ir_node *res;
		tarval* offset_tarval = new_tarval_from_long(offset, mode_Is);
1182
		load = new_bd_ppc32_Lhz(env->dbg, env->block, src, mem);
1183
1184
1185
1186
1187
		set_ppc32_constant_tarval(load, offset_tarval);
		set_ppc32_offset_mode(load, ppc32_ao_None);
		mem = new_rd_Proj(env->dbg, env->irg, env->block, load, mode_M, pn_Load_M);
		res = new_rd_Proj(env->dbg, env->irg, env->block, load, mode_Is, pn_Load_res);

1188
		store = new_bd_ppc32_Sth(env->dbg, env->block, dest, res, mem);
1189
1190
1191
1192
1193
1194
1195
		set_ppc32_constant_tarval(store, offset_tarval);
		set_ppc32_offset_mode(store, ppc32_ao_None);
		mem = new_rd_Proj(env->dbg, env->irg, env->block, store, mode_M, pn_Store_M);

		offset += 2;
	}

1196
	if(size & 1)
1197
1198
1199
	{
		ir_node *res;
		tarval* offset_tarval = new_tarval_from_long(offset, mode_Is);
1200
		load = new_bd_ppc32_Lbz(env->dbg, env->block, src, mem);
1201
1202
1203
1204
1205
		set_ppc32_constant_tarval(load, offset_tarval);
		set_ppc32_offset_mode(load, ppc32_ao_None);
		mem = new_rd_Proj(env->dbg, env->irg, env->block, load, mode_M, pn_Load_M);
		res = new_rd_Proj(env->dbg, env->irg, env->block, load, mode_Is, pn_Load_res);

1206
		store = new_bd_ppc32_Stb(env->dbg, env->block, dest, res, mem);
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
		set_ppc32_constant_tarval(store, offset_tarval);
		set_ppc32_offset_mode(store, ppc32_ao_None);
		// mem = new_rd_Proj(env->dbg, env->irg, env->block, store, mode_M, pn_Store_M);
	}

	return store;
}

/**
 * Transforms a FrameAddr into a ppc Add.
1217
1218
 *
 * @param env   The transformation environment
1219
 */
1220
static ir_node *gen_be_FrameAddr(ppc32_transform_env_t *env) {
1221
	ir_node *op = get_irn_n(env->irn, 0);
1222
	ir_node *add = new_bd_ppc32_Addi(env->dbg, env->block, op, mode_P);
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
	set_ppc32_frame_entity(add, be_get_frame_entity(env->irn));
	return add;
}


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

1238
1239
1240
1241
/**
 * the BAD transformer.
 */
static ir_node *bad_transform(ppc32_transform_env_t *env) {
1242
	panic("Transformation not implemented: %+F\n", env->irn);
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
/**
 * Enters all transform functions into the generic pointer
 */
void ppc32_register_transformers(void) {
	ir_op *op_Max, *op_Min, *op_Mulh;

	/* first clear the generic function pointer for all ops */
	clear_irp_opcodes_generic_func();

#define FIRM_OP(a)     op_##a->ops.generic = (op_func)gen_##a
#define BAD(a)         op_##a->ops.generic = (op_func)bad_transform
#define IGN(a)

	FIRM_OP(Add);
	FIRM_OP(Mul);
	FIRM_OP(And);
	FIRM_OP(Or);
	FIRM_OP(Eor);

	FIRM_OP(Sub);
	FIRM_OP(Shl);
	FIRM_OP(Shr);
	FIRM_OP(Shrs);
1268
	FIRM_OP(Rotl);
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
1305
1306
1307
1308
1309
1310
1311
	FIRM_OP(Quot);
	FIRM_OP(Div);
	FIRM_OP(DivMod);
	FIRM_OP(Mod);
	FIRM_OP(Cmp);

	FIRM_OP(Minus);
	FIRM_OP(Not);
	FIRM_OP(Conv);
	FIRM_OP(Abs);

	FIRM_OP(Load);
	FIRM_OP(Store);
	FIRM_OP(Cond);
	FIRM_OP(Unknown);
	FIRM_OP(CopyB);

	/* TODO: implement these nodes */
	BAD(Mux);

	/* You probably don't need to handle the following nodes */

	IGN(Call);
	IGN(Proj);
	IGN(Alloc);

	IGN(Block);
	IGN(Start);
	IGN(End);
	IGN(NoMem);
	IGN(Phi);
	IGN(IJmp);
	IGN(Jmp);
	IGN(Break);
	IGN(Sync);

	BAD(Raise);
	BAD(Sel);
	BAD(InstOf);
	BAD(Cast);
	BAD(Free);
	BAD(Tuple);
	BAD(Id);
1312
	//BAD(Bad);
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
	BAD(Confirm);
	BAD(Filter);
	BAD(CallBegin);
	BAD(EndReg);
	BAD(EndExcept);

	FIRM_OP(be_FrameAddr);
	op_Mulh = get_op_Mulh();
	if (op_Mulh)
		FIRM_OP(Mulh);
	op_Max = get_op_Max();
	if (op_Max)
		BAD(Max);
	op_Min = get_op_Min();
	if (op_Min)
		BAD(Min);
}

typedef ir_node *(transform_func)(ppc32_transform_env_t *env);
1332
1333
1334
1335
1336
1337
1338
1339
1340

/**
 * Transforms the given firm node (and maybe some other related nodes)
 * into one or more assembler nodes.
 *
 * @param node    the firm node
 * @param env     the debug module
 */
void ppc32_transform_node(ir_node *node, void *env) {
1341
1342
1343
	ppc32_code_gen_t *cg = (ppc32_code_gen_t *)env;
	ir_op *op            = get_irn_op(node);
	ir_node *asm_node    = NULL;
1344
	(void) cg;
1345

1346
	if (op == op_Block)
1347
1348
		return;

1349
	DBG((cg->mod, LEVEL_1, "check %+F ... ", node));
1350

1351
1352
1353
	if (op->ops.generic) {
		ppc32_transform_env_t tenv;
		transform_func *transform = (transform_func *)op->ops.generic;