bearch_sparc.c 18.4 KB
Newer Older
Hannes Rapp's avatar
Hannes Rapp committed
1
/*
Michael Beck's avatar
Michael Beck committed
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    The main sparc backend driver file.
Matthias Braun's avatar
Matthias Braun committed
23
 * @author   Hannes Rapp, Matthias Braun
Michael Beck's avatar
Michael Beck committed
24
 * @version  $Id$
Hannes Rapp's avatar
Hannes Rapp committed
25
26
27
28
29
30
31
32
33
34
35
36
37
 */
#include "config.h"

#include "lc_opts.h"
#include "lc_opts_enum.h"

#include "irgwalk.h"
#include "irprog.h"
#include "irprintf.h"
#include "ircons.h"
#include "irgmod.h"
#include "irgopt.h"
#include "iroptimize.h"
38
39
#include "irtools.h"
#include "irdump.h"
Hannes Rapp's avatar
Hannes Rapp committed
40
#include "lowering.h"
41
#include "lower_dw.h"
Hannes Rapp's avatar
Hannes Rapp committed
42
43
44
45

#include "bitset.h"
#include "debug.h"
#include "array_t.h"
46
#include "error.h"
47
#include "util.h"
Hannes Rapp's avatar
Hannes Rapp committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#include "../bearch.h"
#include "../benode.h"
#include "../belower.h"
#include "../besched.h"
#include "be.h"
#include "../bemachine.h"
#include "../bemodule.h"
#include "../beirg.h"
#include "../bespillslots.h"
#include "../begnuas.h"
#include "../belistsched.h"
#include "../beflags.h"

#include "bearch_sparc_t.h"

#include "sparc_new_nodes.h"
#include "gen_sparc_regalloc_if.h"
#include "sparc_transform.h"
#include "sparc_emitter.h"
68

Hannes Rapp's avatar
Hannes Rapp committed
69
70
DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)

71
static arch_irn_class_t sparc_classify(const ir_node *node)
Hannes Rapp's avatar
Hannes Rapp committed
72
{
73
	(void) node;
74
	return arch_irn_class_none;
Hannes Rapp's avatar
Hannes Rapp committed
75
76
}

77
static ir_entity *sparc_get_frame_entity(const ir_node *node)
Hannes Rapp's avatar
Hannes Rapp committed
78
{
79
80
81
	if (is_sparc_FrameAddr(node)) {
		const sparc_attr_t *attr = get_sparc_attr_const(node);
		return attr->immediate_value_entity;
Hannes Rapp's avatar
Hannes Rapp committed
82
83
	}

84
85
86
	if (sparc_has_load_store_attr(node)) {
		const sparc_load_store_attr_t *load_store_attr
			= get_sparc_load_store_attr_const(node);
Hannes Rapp's avatar
Hannes Rapp committed
87
		if (load_store_attr->is_frame_entity) {
88
			return load_store_attr->base.immediate_value_entity;
Hannes Rapp's avatar
Hannes Rapp committed
89
90
91
		}
	}

Hannes Rapp's avatar
Hannes Rapp committed
92
93
94
95
96
97
98
	return NULL;
}

/**
 * This function is called by the generic backend to correct offsets for
 * nodes accessing the stack.
 */
99
static void sparc_set_frame_offset(ir_node *node, int offset)
Hannes Rapp's avatar
Hannes Rapp committed
100
{
101
102
103
104
105
106
	sparc_attr_t *attr = get_sparc_attr(node);
	attr->immediate_value += offset;

	/* must be a FrameAddr or a load/store node with frame_entity */
	assert(is_sparc_FrameAddr(node) ||
			get_sparc_load_store_attr_const(node)->is_frame_entity);
Hannes Rapp's avatar
Hannes Rapp committed
107
108
}

109
static int sparc_get_sp_bias(const ir_node *node)
Hannes Rapp's avatar
Hannes Rapp committed
110
{
111
	if (is_sparc_Save(node)) {
112
113
114
115
116
		const sparc_attr_t *attr = get_sparc_attr_const(node);
		if (get_irn_arity(node) == 3)
			panic("no support for _reg variant yet");

		/* Note we do not report the change of the SPARC_MIN_STACKSIZE
117
118
		 * size, since we have additional magic in the emitter which
		 * calculates that! */
119
120
		assert(attr->immediate_value <= -SPARC_MIN_STACKSIZE);
		return attr->immediate_value + SPARC_MIN_STACKSIZE;
121
122
	} else if (is_sparc_RestoreZero(node)) {
		return SP_BIAS_RESET;
123
124
	}
	return 0;
Hannes Rapp's avatar
Hannes Rapp committed
125
126
127
128
}

/* fill register allocator interface */

129
const arch_irn_ops_t sparc_irn_ops = {
Hannes Rapp's avatar
Hannes Rapp committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
	sparc_classify,
	sparc_get_frame_entity,
	sparc_set_frame_offset,
	sparc_get_sp_bias,
	NULL,    /* get_inverse             */
	NULL,    /* get_op_estimated_cost   */
	NULL,    /* possible_memory_operand */
	NULL,    /* perform_memory_operand  */
};

/**
 * Transforms the standard firm graph into
 * a SPARC firm graph
 */
144
static void sparc_prepare_graph(ir_graph *irg)
Hannes Rapp's avatar
Hannes Rapp committed
145
{
146
	sparc_transform_graph(irg);
Hannes Rapp's avatar
Hannes Rapp committed
147
148
}

149
150
151
152
153
154
155
156
157
158
static bool sparc_modifies_flags(const ir_node *node)
{
	return arch_irn_get_flags(node) & sparc_arch_irn_flag_modifies_flags;
}

static bool sparc_modifies_fp_flags(const ir_node *node)
{
	return arch_irn_get_flags(node) & sparc_arch_irn_flag_modifies_fp_flags;
}

159
static void sparc_before_ra(ir_graph *irg)
Hannes Rapp's avatar
Hannes Rapp committed
160
161
{
	/* fixup flags register */
162
	be_sched_fix_flags(irg, &sparc_reg_classes[CLASS_sparc_flags_class],
163
	                   NULL, sparc_modifies_flags);
164
	be_sched_fix_flags(irg, &sparc_reg_classes[CLASS_sparc_fpflags_class],
165
	                   NULL, sparc_modifies_fp_flags);
Hannes Rapp's avatar
Hannes Rapp committed
166
167
}

Hannes Rapp's avatar
Hannes Rapp committed
168
169
170
171
172
173
174
/**
 * transform reload node => load
 */
static void transform_Reload(ir_node *node)
{
	ir_node   *block  = get_nodes_block(node);
	dbg_info  *dbgi   = get_irn_dbg_info(node);
175
176
	ir_node   *ptr    = get_irn_n(node, n_be_Spill_frame);
	ir_node   *mem    = get_irn_n(node, n_be_Reload_mem);
Hannes Rapp's avatar
Hannes Rapp committed
177
178
179
180
181
182
183
184
	ir_mode   *mode   = get_irn_mode(node);
	ir_entity *entity = be_get_frame_entity(node);
	const arch_register_t *reg;
	ir_node   *proj;
	ir_node   *load;

	ir_node  *sched_point = sched_prev(node);

185
	load = new_bd_sparc_Ld_imm(dbgi, block, ptr, mem, mode, entity, 0, true);
Hannes Rapp's avatar
Hannes Rapp committed
186
187
188
	sched_add_after(sched_point, load);
	sched_remove(node);

189
	proj = new_rd_Proj(dbgi, load, mode, pn_sparc_Ld_res);
Hannes Rapp's avatar
Hannes Rapp committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203

	reg = arch_get_irn_register(node);
	arch_set_irn_register(proj, reg);

	exchange(node, proj);
}

/**
 * transform spill node => store
 */
static void transform_Spill(ir_node *node)
{
	ir_node   *block  = get_nodes_block(node);
	dbg_info  *dbgi   = get_irn_dbg_info(node);
204
	ir_node   *ptr    = get_irn_n(node, n_be_Spill_frame);
205
	ir_graph  *irg    = get_irn_irg(node);
206
	ir_node   *mem    = get_irg_no_mem(irg);
207
	ir_node   *val    = get_irn_n(node, n_be_Spill_val);
Hannes Rapp's avatar
Hannes Rapp committed
208
209
210
211
212
213
	ir_mode   *mode   = get_irn_mode(val);
	ir_entity *entity = be_get_frame_entity(node);
	ir_node   *sched_point;
	ir_node   *store;

	sched_point = sched_prev(node);
214
	store = new_bd_sparc_St_imm(dbgi, block, val, ptr, mem, mode, entity, 0, true);
Hannes Rapp's avatar
Hannes Rapp committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
	sched_remove(node);
	sched_add_after(sched_point, store);

	exchange(node, store);
}

/**
 * walker to transform be_Spill and be_Reload nodes
 */
static void sparc_after_ra_walker(ir_node *block, void *data)
{
	ir_node *node, *prev;
	(void) data;

	for (node = sched_last(block); !sched_is_begin(node); node = prev) {
		prev = sched_prev(node);

		if (be_is_Reload(node)) {
			transform_Reload(node);
		} else if (be_is_Spill(node)) {
			transform_Spill(node);
		}
	}
}

240
241
static void sparc_collect_frame_entity_nodes(ir_node *node, void *data)
{
242
	be_fec_env_t  *env = (be_fec_env_t*)data;
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
	const ir_mode *mode;
	int            align;
	ir_entity     *entity;
	const sparc_load_store_attr_t *attr;

	if (be_is_Reload(node) && be_get_frame_entity(node) == NULL) {
		mode  = get_irn_mode(node);
		align = get_mode_size_bytes(mode);
		be_node_needs_frame_entity(env, node, mode, align);
		return;
	}

	if (!is_sparc_Ld(node) && !is_sparc_Ldf(node))
		return;

	attr   = get_sparc_load_store_attr_const(node);
259
	entity = attr->base.immediate_value_entity;
260
261
262
263
264
	mode   = attr->load_store_mode;
	if (entity != NULL)
		return;
	if (!attr->is_frame_entity)
		return;
265
266
267
	if (arch_irn_get_flags(node) & sparc_arch_irn_flag_needs_64bit_spillslot)
		mode = mode_Lu;
	align  = get_mode_size_bytes(mode);
268
269
270
271
272
273
274
275
276
277
278
	be_node_needs_frame_entity(env, node, mode, align);
}

static void sparc_set_frame_entity(ir_node *node, ir_entity *entity)
{
	if (is_be_node(node)) {
		be_node_set_frame_entity(node, entity);
	} else {
		/* we only say be_node_needs_frame_entity on nodes with load_store
		 * attributes, so this should be fine */
		sparc_load_store_attr_t *attr = get_sparc_load_store_attr(node);
279
280
281
		assert(attr->is_frame_entity);
		assert(attr->base.immediate_value_entity == NULL);
		attr->base.immediate_value_entity = entity;
282
283
284
	}
}

285
static void sparc_after_ra(ir_graph *irg)
Hannes Rapp's avatar
Hannes Rapp committed
286
{
287
288
289
	be_stack_layout_t *stack_layout = be_get_irg_stack_layout(irg);
	bool               at_begin     = stack_layout->sp_relative ? true : false;
	be_fec_env_t      *fec_env      = be_new_frame_entity_coalescer(irg);
290
291

	irg_walk_graph(irg, NULL, sparc_collect_frame_entity_nodes, fec_env);
292
	be_assign_entities(fec_env, sparc_set_frame_entity, at_begin);
293
	be_free_frame_entity_coalescer(fec_env);
Hannes Rapp's avatar
Hannes Rapp committed
294

295
	irg_block_walk_graph(irg, NULL, sparc_after_ra_walker, NULL);
296
297

	sparc_introduce_prolog_epilog(irg);
Hannes Rapp's avatar
Hannes Rapp committed
298
299
}

300
static void sparc_init_graph(ir_graph *irg)
Hannes Rapp's avatar
Hannes Rapp committed
301
{
302
	(void) irg;
Hannes Rapp's avatar
Hannes Rapp committed
303
304
}

305
extern const arch_isa_if_t sparc_isa_if;
Hannes Rapp's avatar
Hannes Rapp committed
306
307
static sparc_isa_t sparc_isa_template = {
	{
308
		&sparc_isa_if,                      /* isa interface implementation */
309
310
		N_SPARC_REGISTERS,
		sparc_registers,
311
312
		N_SPARC_CLASSES,
		sparc_reg_classes,
313
314
		&sparc_registers[REG_SP],           /* stack pointer register */
		&sparc_registers[REG_FRAME_POINTER],/* base pointer register */
315
316
317
318
319
320
321
		&sparc_reg_classes[CLASS_sparc_gp], /* link pointer register class */
		3,                                  /* power of two stack alignment
		                                       for calls */
		NULL,                               /* main environment */
		7,                                  /* costs for a spill instruction */
		5,                                  /* costs for a reload instruction */
		true,                               /* custom abi handling */
Hannes Rapp's avatar
Hannes Rapp committed
322
	},
323
	NULL,     /* constants */
Hannes Rapp's avatar
Hannes Rapp committed
324
325
};

326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/**
 * rewrite unsigned->float conversion.
 * Sparc has no instruction for this so instead we do the following:
 *
 *   int    signed_x = unsigned_value_x;
 *   double res      = signed_x;
 *   if (signed_x < 0)
 *       res += 4294967296. ;
 *   return (float) res;
 */
static void rewrite_unsigned_float_Conv(ir_node *node)
{
	ir_graph *irg         = get_irn_irg(node);
	dbg_info *dbgi        = get_irn_dbg_info(node);
	ir_node  *lower_block = get_nodes_block(node);

	part_block(node);

	{
Matthias Braun's avatar
Matthias Braun committed
345
346
347
348
349
350
351
352
		ir_node   *block       = get_nodes_block(node);
		ir_node   *unsigned_x  = get_Conv_op(node);
		ir_mode   *mode_u      = get_irn_mode(unsigned_x);
		ir_mode   *mode_s      = find_signed_mode(mode_u);
		ir_mode   *mode_d      = mode_D;
		ir_node   *signed_x    = new_rd_Conv(dbgi, block, unsigned_x, mode_s);
		ir_node   *res         = new_rd_Conv(dbgi, block, signed_x, mode_d);
		ir_node   *zero        = new_r_Const(irg, get_mode_null(mode_s));
353
354
355
		ir_node   *cmp         = new_rd_Cmp(dbgi, block, signed_x, zero,
		                                    ir_relation_less);
		ir_node   *cond        = new_rd_Cond(dbgi, block, cmp);
Matthias Braun's avatar
Matthias Braun committed
356
357
358
359
360
361
362
363
364
365
366
		ir_node   *proj_true   = new_r_Proj(cond, mode_X, pn_Cond_true);
		ir_node   *proj_false  = new_r_Proj(cond, mode_X, pn_Cond_false);
		ir_node   *in_true[1]  = { proj_true };
		ir_node   *in_false[1] = { proj_false };
		ir_node   *true_block  = new_r_Block(irg, ARRAY_SIZE(in_true), in_true);
		ir_node   *false_block = new_r_Block(irg, ARRAY_SIZE(in_false),in_false);
		ir_node   *true_jmp    = new_r_Jmp(true_block);
		ir_node   *false_jmp   = new_r_Jmp(false_block);
		ir_tarval *correction  = new_tarval_from_double(4294967296., mode_d);
		ir_node   *c_const     = new_r_Const(irg, correction);
		ir_node   *fadd        = new_rd_Add(dbgi, true_block, res, c_const,
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
		                                   mode_d);

		ir_node  *lower_in[2] = { true_jmp, false_jmp };
		ir_node  *phi_in[2]   = { fadd, res };
		ir_mode  *dest_mode   = get_irn_mode(node);
		ir_node  *phi;
		ir_node  *res_conv;

		set_irn_in(lower_block, ARRAY_SIZE(lower_in), lower_in);
		phi = new_r_Phi(lower_block, ARRAY_SIZE(phi_in), phi_in, mode_d);
		assert(get_Block_phis(lower_block) == NULL);
		set_Block_phis(lower_block, phi);
		set_Phi_next(phi, NULL);

		res_conv = new_rd_Conv(dbgi, lower_block, phi, dest_mode);

		exchange(node, res_conv);
	}
}

static int sparc_rewrite_Conv(ir_node *node, void *ctx)
{
	ir_mode *to_mode   = get_irn_mode(node);
	ir_node *op        = get_Conv_op(node);
	ir_mode *from_mode = get_irn_mode(op);
Michael Beck's avatar
Michael Beck committed
392
	(void) ctx;
393
394
395
396
397
398
399
400
401
402
403

	if (mode_is_float(to_mode) && mode_is_int(from_mode)
			&& get_mode_size_bits(from_mode) == 32
			&& !mode_is_signed(from_mode)) {
		rewrite_unsigned_float_Conv(node);
		return 1;
	}

	return 0;
}

404
405
406
407
static void sparc_handle_intrinsics(void)
{
	ir_type *tp, *int_tp, *uint_tp;
	i_record records[8];
408
	size_t n_records = 0;
409
410
411
412
413
414
415
416

	runtime_rt rt_iMod, rt_uMod;

#define ID(x) new_id_from_chars(x, sizeof(x)-1)

	int_tp  = new_type_primitive(mode_Is);
	uint_tp = new_type_primitive(mode_Iu);

417
418
419
	/* we need to rewrite some forms of int->float conversions */
	{
		i_instr_record *map_Conv = &records[n_records++].i_instr;
420

421
422
423
424
		map_Conv->kind     = INTRINSIC_INSTR;
		map_Conv->op       = op_Conv;
		map_Conv->i_mapper = sparc_rewrite_Conv;
	}
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
	/* SPARC has no signed mod instruction ... */
	{
		i_instr_record *map_Mod = &records[n_records++].i_instr;

		tp = new_type_method(2, 1);
		set_method_param_type(tp, 0, int_tp);
		set_method_param_type(tp, 1, int_tp);
		set_method_res_type(tp, 0, int_tp);

		rt_iMod.ent             = new_entity(get_glob_type(), ID(".rem"), tp);
		set_entity_ld_ident(rt_iMod.ent, ID(".rem"));
		rt_iMod.mode            = mode_T;
		rt_iMod.res_mode        = mode_Is;
		rt_iMod.mem_proj_nr     = pn_Mod_M;
		rt_iMod.regular_proj_nr = pn_Mod_X_regular;
		rt_iMod.exc_proj_nr     = pn_Mod_X_except;
		rt_iMod.res_proj_nr     = pn_Mod_res;

		set_entity_visibility(rt_iMod.ent, ir_visibility_external);

		map_Mod->kind     = INTRINSIC_INSTR;
		map_Mod->op       = op_Mod;
		map_Mod->i_mapper = (i_mapper_func)i_mapper_RuntimeCall;
		map_Mod->ctx      = &rt_iMod;
	}
	/* ... nor an unsigned mod. */
	{
		i_instr_record *map_Mod = &records[n_records++].i_instr;

		tp = new_type_method(2, 1);
		set_method_param_type(tp, 0, uint_tp);
		set_method_param_type(tp, 1, uint_tp);
		set_method_res_type(tp, 0, uint_tp);

		rt_uMod.ent             = new_entity(get_glob_type(), ID(".urem"), tp);
		set_entity_ld_ident(rt_uMod.ent, ID(".urem"));
		rt_uMod.mode            = mode_T;
		rt_uMod.res_mode        = mode_Iu;
		rt_uMod.mem_proj_nr     = pn_Mod_M;
		rt_uMod.regular_proj_nr = pn_Mod_X_regular;
		rt_uMod.exc_proj_nr     = pn_Mod_X_except;
		rt_uMod.res_proj_nr     = pn_Mod_res;

		set_entity_visibility(rt_uMod.ent, ir_visibility_external);

		map_Mod->kind     = INTRINSIC_INSTR;
		map_Mod->op       = op_Mod;
		map_Mod->i_mapper = (i_mapper_func)i_mapper_RuntimeCall;
		map_Mod->ctx      = &rt_uMod;
	}

476
477
	assert(n_records < ARRAY_SIZE(records));
	lower_intrinsics(records, n_records, /*part_block_used=*/ true);
478
479
}

Hannes Rapp's avatar
Hannes Rapp committed
480
481
482
483
484
/**
 * Initializes the backend ISA
 */
static arch_env_t *sparc_init(FILE *outfile)
{
485
	sparc_isa_t *isa = XMALLOC(sparc_isa_t);
486
	*isa = sparc_isa_template;
487
	isa->constants = pmap_create();
Hannes Rapp's avatar
Hannes Rapp committed
488
489
490
491
492

	be_emit_init(outfile);

	sparc_register_init();
	sparc_create_opcodes(&sparc_irn_ops);
493
	sparc_handle_intrinsics();
Hannes Rapp's avatar
Hannes Rapp committed
494

495
	return &isa->base;
Hannes Rapp's avatar
Hannes Rapp committed
496
497
498
499
500
501
502
}

/**
 * Closes the output file and frees the ISA structure.
 */
static void sparc_done(void *self)
{
503
	sparc_isa_t *isa = (sparc_isa_t*)self;
Hannes Rapp's avatar
Hannes Rapp committed
504
505

	/* emit now all global declarations */
506
	be_gas_emit_decls(isa->base.main_env);
Hannes Rapp's avatar
Hannes Rapp committed
507

508
	pmap_destroy(isa->constants);
Hannes Rapp's avatar
Hannes Rapp committed
509
	be_emit_exit();
510
	free(isa);
Hannes Rapp's avatar
Hannes Rapp committed
511
512
513
514
515
516
517
518
519
}


/**
 * Get the register class which shall be used to store a value of a given mode.
 * @param self The this pointer.
 * @param mode The mode in question.
 * @return A register class which can hold values of the given mode.
 */
520
static const arch_register_class_t *sparc_get_reg_class_for_mode(const ir_mode *mode)
Hannes Rapp's avatar
Hannes Rapp committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
{
	if (mode_is_float(mode))
		return &sparc_reg_classes[CLASS_sparc_fp];
	else
		return &sparc_reg_classes[CLASS_sparc_gp];
}

/**
 * Returns the necessary byte alignment for storing a register of given class.
 */
static int sparc_get_reg_class_alignment(const arch_register_class_t *cls)
{
	ir_mode *mode = arch_register_class_mode(cls);
	return get_mode_size_bytes(mode);
}

537
538
539
540
541
static ir_node *sparc_create_set(ir_node *cond)
{
	return ir_create_cond_set(cond, mode_Iu);
}

542
543
static void sparc_lower_for_target(void)
{
Michael Beck's avatar
Michael Beck committed
544
	size_t i, n_irgs = get_irp_n_irgs();
545
546
547
548
549
	lower_mode_b_config_t lower_mode_b_config = {
		mode_Iu,
		sparc_create_set,
		0,
	};
550
551
552
553
554
555
556
557
	lower_params_t params = {
		4,                                     /* def_ptr_alignment */
		LF_COMPOUND_RETURN | LF_RETURN_HIDDEN, /* flags */
		ADD_HIDDEN_ALWAYS_IN_FRONT,            /* hidden_params */
		NULL,                                  /* find pointer type */
		NULL,                                  /* ret_compound_in_regs */
	};
	lower_calls_with_compounds(&params);
558

559
560
	sparc_lower_64bit();

561
562
	for (i = 0; i < n_irgs; ++i) {
		ir_graph *irg = get_irp_irg(i);
563
		ir_lower_mode_b(irg, &lower_mode_b_config);
Matthias Braun's avatar
Matthias Braun committed
564
		lower_switch(irg, 4, 256, false);
565
	}
566
567
}

568
569
570
static int sparc_is_mux_allowed(ir_node *sel, ir_node *mux_false,
                                ir_node *mux_true)
{
571
572
573
574
575
576
577
578
579
580
581
	ir_graph *irg  = get_irn_irg(sel);
	ir_mode  *mode = get_irn_mode(mux_true);

	if (get_irg_phase_state(irg) == phase_low)
		return false;

	if (!mode_is_int(mode) && !mode_is_reference(mode) && mode != mode_b)
		return false;
	if (is_Const(mux_true) && is_Const_one(mux_true) &&
			is_Const(mux_false) && is_Const_null(mux_false))
		return true;
582
583
584
	return false;
}

Hannes Rapp's avatar
Hannes Rapp committed
585
586
587
/**
 * Returns the libFirm configuration parameter for this backend.
 */
588
589
static const backend_params *sparc_get_backend_params(void)
{
590
591
592
593
594
595
596
597
598
	static const ir_settings_arch_dep_t arch_dep = {
		1,     /* also_use_subs */
		1,     /* maximum_shifts */
		31,    /* highest_shift_amount */
		NULL,  /* evaluate_cost_func */
		1,     /* allow mulhs */
		1,     /* allow mulhu */
		32,    /* max_bits_for_mulh */
	};
Hannes Rapp's avatar
Hannes Rapp committed
599
600
	static backend_params p = {
		0,     /* no inline assembly */
601
		0,     /* no support for RotL nodes */
602
		1,     /* big endian */
603
		&arch_dep,              /* will be set later */
604
		sparc_is_mux_allowed,   /* parameter for if conversion */
605
		32,    /* machine size */
Hannes Rapp's avatar
Hannes Rapp committed
606
		NULL,  /* float arithmetic mode */
607
		128,   /* size of long double */
Hannes Rapp's avatar
Hannes Rapp committed
608
609
610
611
612
613
614
615
616
		0,     /* no trampoline support: size 0 */
		0,     /* no trampoline support: align 0 */
		NULL,  /* no trampoline support: no trampoline builder */
		4      /* alignment of stack parameter: typically 4 (32bit) or 8 (64bit) */
	};
	return &p;
}

static ir_graph **sparc_get_backend_irg_list(const void *self,
617
                                             ir_graph ***irgs)
Hannes Rapp's avatar
Hannes Rapp committed
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
{
	(void) self;
	(void) irgs;
	return NULL;
}

static asm_constraint_flags_t sparc_parse_asm_constraint(const char **c)
{
	(void) c;
	return ASM_CONSTRAINT_FLAG_INVALID;
}

static int sparc_is_valid_clobber(const char *clobber)
{
	(void) clobber;
	return 0;
}

const arch_isa_if_t sparc_isa_if = {
	sparc_init,
638
	sparc_lower_for_target,
Hannes Rapp's avatar
Hannes Rapp committed
639
640
641
	sparc_done,
	NULL,                /* handle intrinsics */
	sparc_get_reg_class_for_mode,
642
	NULL,
Hannes Rapp's avatar
Hannes Rapp committed
643
	sparc_get_reg_class_alignment,
644
	sparc_get_backend_params,
Hannes Rapp's avatar
Hannes Rapp committed
645
646
647
	sparc_get_backend_irg_list,
	NULL,                    /* mark remat */
	sparc_parse_asm_constraint,
648
649
650
651
652
653
654
655
	sparc_is_valid_clobber,

	sparc_init_graph,
	NULL, /* get_pic_base */
	NULL, /* before_abi */
	sparc_prepare_graph,
	sparc_before_ra,
	sparc_after_ra,
656
	sparc_finish,
657
	sparc_emit_routine,
658
	NULL, /* register_saved_by */
Hannes Rapp's avatar
Hannes Rapp committed
659
660
};

661
BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_sparc)
Hannes Rapp's avatar
Hannes Rapp committed
662
663
664
665
666
667
668
void be_init_arch_sparc(void)
{
	be_register_isa_if("sparc", &sparc_isa_if);
	FIRM_DBG_REGISTER(dbg, "firm.be.sparc.cg");
	sparc_init_transform();
	sparc_init_emitter();
}