1 /* Subroutines for insn-output.c for SPARC.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5 Free Software Foundation, Inc.
6 Contributed by Michael Tiemann (tiemann@cygnus.com)
7 64-bit SPARC-V9 support by Michael Tiemann, Jim Wilson, and Doug Evans,
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GCC is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GCC; see the file COPYING3. If not see
24 <http://www.gnu.org/licenses/>. */
28 #include "coretypes.h"
33 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "insn-codes.h"
36 #include "conditions.h"
38 #include "insn-attr.h"
45 #include "diagnostic-core.h"
50 #include "target-def.h"
51 #include "common/common-target.h"
52 #include "cfglayout.h"
54 #include "langhooks.h"
58 #include "dwarf2out.h"
63 struct processor_costs {
67 /* Integer signed load */
70 /* Integer zeroed load */
76 /* fmov, fneg, fabs */
80 const int float_plusminus;
86 const int float_cmove;
92 const int float_div_sf;
95 const int float_div_df;
98 const int float_sqrt_sf;
101 const int float_sqrt_df;
109 /* integer multiply cost for each bit set past the most
110 significant 3, so the formula for multiply cost becomes:
113 highest_bit = highest_clear_bit(rs1);
115 highest_bit = highest_set_bit(rs1);
118 cost = int_mul{,X} + ((highest_bit - 3) / int_mul_bit_factor);
120 A value of zero indicates that the multiply costs is fixed,
122 const int int_mul_bit_factor;
133 /* penalty for shifts, due to scheduling rules etc. */
134 const int shift_penalty;
138 struct processor_costs cypress_costs = {
139 COSTS_N_INSNS (2), /* int load */
140 COSTS_N_INSNS (2), /* int signed load */
141 COSTS_N_INSNS (2), /* int zeroed load */
142 COSTS_N_INSNS (2), /* float load */
143 COSTS_N_INSNS (5), /* fmov, fneg, fabs */
144 COSTS_N_INSNS (5), /* fadd, fsub */
145 COSTS_N_INSNS (1), /* fcmp */
146 COSTS_N_INSNS (1), /* fmov, fmovr */
147 COSTS_N_INSNS (7), /* fmul */
148 COSTS_N_INSNS (37), /* fdivs */
149 COSTS_N_INSNS (37), /* fdivd */
150 COSTS_N_INSNS (63), /* fsqrts */
151 COSTS_N_INSNS (63), /* fsqrtd */
152 COSTS_N_INSNS (1), /* imul */
153 COSTS_N_INSNS (1), /* imulX */
154 0, /* imul bit factor */
155 COSTS_N_INSNS (1), /* idiv */
156 COSTS_N_INSNS (1), /* idivX */
157 COSTS_N_INSNS (1), /* movcc/movr */
158 0, /* shift penalty */
162 struct processor_costs supersparc_costs = {
163 COSTS_N_INSNS (1), /* int load */
164 COSTS_N_INSNS (1), /* int signed load */
165 COSTS_N_INSNS (1), /* int zeroed load */
166 COSTS_N_INSNS (0), /* float load */
167 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
168 COSTS_N_INSNS (3), /* fadd, fsub */
169 COSTS_N_INSNS (3), /* fcmp */
170 COSTS_N_INSNS (1), /* fmov, fmovr */
171 COSTS_N_INSNS (3), /* fmul */
172 COSTS_N_INSNS (6), /* fdivs */
173 COSTS_N_INSNS (9), /* fdivd */
174 COSTS_N_INSNS (12), /* fsqrts */
175 COSTS_N_INSNS (12), /* fsqrtd */
176 COSTS_N_INSNS (4), /* imul */
177 COSTS_N_INSNS (4), /* imulX */
178 0, /* imul bit factor */
179 COSTS_N_INSNS (4), /* idiv */
180 COSTS_N_INSNS (4), /* idivX */
181 COSTS_N_INSNS (1), /* movcc/movr */
182 1, /* shift penalty */
186 struct processor_costs hypersparc_costs = {
187 COSTS_N_INSNS (1), /* int load */
188 COSTS_N_INSNS (1), /* int signed load */
189 COSTS_N_INSNS (1), /* int zeroed load */
190 COSTS_N_INSNS (1), /* float load */
191 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
192 COSTS_N_INSNS (1), /* fadd, fsub */
193 COSTS_N_INSNS (1), /* fcmp */
194 COSTS_N_INSNS (1), /* fmov, fmovr */
195 COSTS_N_INSNS (1), /* fmul */
196 COSTS_N_INSNS (8), /* fdivs */
197 COSTS_N_INSNS (12), /* fdivd */
198 COSTS_N_INSNS (17), /* fsqrts */
199 COSTS_N_INSNS (17), /* fsqrtd */
200 COSTS_N_INSNS (17), /* imul */
201 COSTS_N_INSNS (17), /* imulX */
202 0, /* imul bit factor */
203 COSTS_N_INSNS (17), /* idiv */
204 COSTS_N_INSNS (17), /* idivX */
205 COSTS_N_INSNS (1), /* movcc/movr */
206 0, /* shift penalty */
210 struct processor_costs leon_costs = {
211 COSTS_N_INSNS (1), /* int load */
212 COSTS_N_INSNS (1), /* int signed load */
213 COSTS_N_INSNS (1), /* int zeroed load */
214 COSTS_N_INSNS (1), /* float load */
215 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
216 COSTS_N_INSNS (1), /* fadd, fsub */
217 COSTS_N_INSNS (1), /* fcmp */
218 COSTS_N_INSNS (1), /* fmov, fmovr */
219 COSTS_N_INSNS (1), /* fmul */
220 COSTS_N_INSNS (15), /* fdivs */
221 COSTS_N_INSNS (15), /* fdivd */
222 COSTS_N_INSNS (23), /* fsqrts */
223 COSTS_N_INSNS (23), /* fsqrtd */
224 COSTS_N_INSNS (5), /* imul */
225 COSTS_N_INSNS (5), /* imulX */
226 0, /* imul bit factor */
227 COSTS_N_INSNS (5), /* idiv */
228 COSTS_N_INSNS (5), /* idivX */
229 COSTS_N_INSNS (1), /* movcc/movr */
230 0, /* shift penalty */
234 struct processor_costs sparclet_costs = {
235 COSTS_N_INSNS (3), /* int load */
236 COSTS_N_INSNS (3), /* int signed load */
237 COSTS_N_INSNS (1), /* int zeroed load */
238 COSTS_N_INSNS (1), /* float load */
239 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
240 COSTS_N_INSNS (1), /* fadd, fsub */
241 COSTS_N_INSNS (1), /* fcmp */
242 COSTS_N_INSNS (1), /* fmov, fmovr */
243 COSTS_N_INSNS (1), /* fmul */
244 COSTS_N_INSNS (1), /* fdivs */
245 COSTS_N_INSNS (1), /* fdivd */
246 COSTS_N_INSNS (1), /* fsqrts */
247 COSTS_N_INSNS (1), /* fsqrtd */
248 COSTS_N_INSNS (5), /* imul */
249 COSTS_N_INSNS (5), /* imulX */
250 0, /* imul bit factor */
251 COSTS_N_INSNS (5), /* idiv */
252 COSTS_N_INSNS (5), /* idivX */
253 COSTS_N_INSNS (1), /* movcc/movr */
254 0, /* shift penalty */
258 struct processor_costs ultrasparc_costs = {
259 COSTS_N_INSNS (2), /* int load */
260 COSTS_N_INSNS (3), /* int signed load */
261 COSTS_N_INSNS (2), /* int zeroed load */
262 COSTS_N_INSNS (2), /* float load */
263 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
264 COSTS_N_INSNS (4), /* fadd, fsub */
265 COSTS_N_INSNS (1), /* fcmp */
266 COSTS_N_INSNS (2), /* fmov, fmovr */
267 COSTS_N_INSNS (4), /* fmul */
268 COSTS_N_INSNS (13), /* fdivs */
269 COSTS_N_INSNS (23), /* fdivd */
270 COSTS_N_INSNS (13), /* fsqrts */
271 COSTS_N_INSNS (23), /* fsqrtd */
272 COSTS_N_INSNS (4), /* imul */
273 COSTS_N_INSNS (4), /* imulX */
274 2, /* imul bit factor */
275 COSTS_N_INSNS (37), /* idiv */
276 COSTS_N_INSNS (68), /* idivX */
277 COSTS_N_INSNS (2), /* movcc/movr */
278 2, /* shift penalty */
282 struct processor_costs ultrasparc3_costs = {
283 COSTS_N_INSNS (2), /* int load */
284 COSTS_N_INSNS (3), /* int signed load */
285 COSTS_N_INSNS (3), /* int zeroed load */
286 COSTS_N_INSNS (2), /* float load */
287 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
288 COSTS_N_INSNS (4), /* fadd, fsub */
289 COSTS_N_INSNS (5), /* fcmp */
290 COSTS_N_INSNS (3), /* fmov, fmovr */
291 COSTS_N_INSNS (4), /* fmul */
292 COSTS_N_INSNS (17), /* fdivs */
293 COSTS_N_INSNS (20), /* fdivd */
294 COSTS_N_INSNS (20), /* fsqrts */
295 COSTS_N_INSNS (29), /* fsqrtd */
296 COSTS_N_INSNS (6), /* imul */
297 COSTS_N_INSNS (6), /* imulX */
298 0, /* imul bit factor */
299 COSTS_N_INSNS (40), /* idiv */
300 COSTS_N_INSNS (71), /* idivX */
301 COSTS_N_INSNS (2), /* movcc/movr */
302 0, /* shift penalty */
306 struct processor_costs niagara_costs = {
307 COSTS_N_INSNS (3), /* int load */
308 COSTS_N_INSNS (3), /* int signed load */
309 COSTS_N_INSNS (3), /* int zeroed load */
310 COSTS_N_INSNS (9), /* float load */
311 COSTS_N_INSNS (8), /* fmov, fneg, fabs */
312 COSTS_N_INSNS (8), /* fadd, fsub */
313 COSTS_N_INSNS (26), /* fcmp */
314 COSTS_N_INSNS (8), /* fmov, fmovr */
315 COSTS_N_INSNS (29), /* fmul */
316 COSTS_N_INSNS (54), /* fdivs */
317 COSTS_N_INSNS (83), /* fdivd */
318 COSTS_N_INSNS (100), /* fsqrts - not implemented in hardware */
319 COSTS_N_INSNS (100), /* fsqrtd - not implemented in hardware */
320 COSTS_N_INSNS (11), /* imul */
321 COSTS_N_INSNS (11), /* imulX */
322 0, /* imul bit factor */
323 COSTS_N_INSNS (72), /* idiv */
324 COSTS_N_INSNS (72), /* idivX */
325 COSTS_N_INSNS (1), /* movcc/movr */
326 0, /* shift penalty */
330 struct processor_costs niagara2_costs = {
331 COSTS_N_INSNS (3), /* int load */
332 COSTS_N_INSNS (3), /* int signed load */
333 COSTS_N_INSNS (3), /* int zeroed load */
334 COSTS_N_INSNS (3), /* float load */
335 COSTS_N_INSNS (6), /* fmov, fneg, fabs */
336 COSTS_N_INSNS (6), /* fadd, fsub */
337 COSTS_N_INSNS (6), /* fcmp */
338 COSTS_N_INSNS (6), /* fmov, fmovr */
339 COSTS_N_INSNS (6), /* fmul */
340 COSTS_N_INSNS (19), /* fdivs */
341 COSTS_N_INSNS (33), /* fdivd */
342 COSTS_N_INSNS (19), /* fsqrts */
343 COSTS_N_INSNS (33), /* fsqrtd */
344 COSTS_N_INSNS (5), /* imul */
345 COSTS_N_INSNS (5), /* imulX */
346 0, /* imul bit factor */
347 COSTS_N_INSNS (26), /* idiv, average of 12 - 41 cycle range */
348 COSTS_N_INSNS (26), /* idivX, average of 12 - 41 cycle range */
349 COSTS_N_INSNS (1), /* movcc/movr */
350 0, /* shift penalty */
354 struct processor_costs niagara3_costs = {
355 COSTS_N_INSNS (3), /* int load */
356 COSTS_N_INSNS (3), /* int signed load */
357 COSTS_N_INSNS (3), /* int zeroed load */
358 COSTS_N_INSNS (3), /* float load */
359 COSTS_N_INSNS (9), /* fmov, fneg, fabs */
360 COSTS_N_INSNS (9), /* fadd, fsub */
361 COSTS_N_INSNS (9), /* fcmp */
362 COSTS_N_INSNS (9), /* fmov, fmovr */
363 COSTS_N_INSNS (9), /* fmul */
364 COSTS_N_INSNS (23), /* fdivs */
365 COSTS_N_INSNS (37), /* fdivd */
366 COSTS_N_INSNS (23), /* fsqrts */
367 COSTS_N_INSNS (37), /* fsqrtd */
368 COSTS_N_INSNS (9), /* imul */
369 COSTS_N_INSNS (9), /* imulX */
370 0, /* imul bit factor */
371 COSTS_N_INSNS (31), /* idiv, average of 17 - 45 cycle range */
372 COSTS_N_INSNS (30), /* idivX, average of 16 - 44 cycle range */
373 COSTS_N_INSNS (1), /* movcc/movr */
374 0, /* shift penalty */
377 static const struct processor_costs *sparc_costs = &cypress_costs;
379 #ifdef HAVE_AS_RELAX_OPTION
380 /* If 'as' and 'ld' are relaxing tail call insns into branch always, use
381 "or %o7,%g0,X; call Y; or X,%g0,%o7" always, so that it can be optimized.
382 With sethi/jmp, neither 'as' nor 'ld' has an easy way how to find out if
383 somebody does not branch between the sethi and jmp. */
384 #define LEAF_SIBCALL_SLOT_RESERVED_P 1
386 #define LEAF_SIBCALL_SLOT_RESERVED_P \
387 ((TARGET_ARCH64 && !TARGET_CM_MEDLOW) || flag_pic)
390 /* Vector to say how input registers are mapped to output registers.
391 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
392 eliminate it. You must use -fomit-frame-pointer to get that. */
393 char leaf_reg_remap[] =
394 { 0, 1, 2, 3, 4, 5, 6, 7,
395 -1, -1, -1, -1, -1, -1, 14, -1,
396 -1, -1, -1, -1, -1, -1, -1, -1,
397 8, 9, 10, 11, 12, 13, -1, 15,
399 32, 33, 34, 35, 36, 37, 38, 39,
400 40, 41, 42, 43, 44, 45, 46, 47,
401 48, 49, 50, 51, 52, 53, 54, 55,
402 56, 57, 58, 59, 60, 61, 62, 63,
403 64, 65, 66, 67, 68, 69, 70, 71,
404 72, 73, 74, 75, 76, 77, 78, 79,
405 80, 81, 82, 83, 84, 85, 86, 87,
406 88, 89, 90, 91, 92, 93, 94, 95,
407 96, 97, 98, 99, 100, 101, 102};
409 /* Vector, indexed by hard register number, which contains 1
410 for a register that is allowable in a candidate for leaf
411 function treatment. */
412 char sparc_leaf_regs[] =
413 { 1, 1, 1, 1, 1, 1, 1, 1,
414 0, 0, 0, 0, 0, 0, 1, 0,
415 0, 0, 0, 0, 0, 0, 0, 0,
416 1, 1, 1, 1, 1, 1, 0, 1,
417 1, 1, 1, 1, 1, 1, 1, 1,
418 1, 1, 1, 1, 1, 1, 1, 1,
419 1, 1, 1, 1, 1, 1, 1, 1,
420 1, 1, 1, 1, 1, 1, 1, 1,
421 1, 1, 1, 1, 1, 1, 1, 1,
422 1, 1, 1, 1, 1, 1, 1, 1,
423 1, 1, 1, 1, 1, 1, 1, 1,
424 1, 1, 1, 1, 1, 1, 1, 1,
425 1, 1, 1, 1, 1, 1, 1};
427 struct GTY(()) machine_function
429 /* Size of the frame of the function. */
430 HOST_WIDE_INT frame_size;
432 /* Size of the frame of the function minus the register window save area
433 and the outgoing argument area. */
434 HOST_WIDE_INT apparent_frame_size;
436 /* Register we pretend the frame pointer is allocated to. Normally, this
437 is %fp, but if we are in a leaf procedure, this is (%sp + offset). We
438 record "offset" separately as it may be too big for (reg + disp). */
440 HOST_WIDE_INT frame_base_offset;
442 /* Some local-dynamic TLS symbol name. */
443 const char *some_ld_name;
445 /* Number of global or FP registers to be saved (as 4-byte quantities). */
446 int n_global_fp_regs;
448 /* True if the current function is leaf and uses only leaf regs,
449 so that the SPARC leaf function optimization can be applied.
450 Private version of current_function_uses_only_leaf_regs, see
451 sparc_expand_prologue for the rationale. */
454 /* True if the prologue saves local or in registers. */
455 bool save_local_in_regs_p;
457 /* True if the data calculated by sparc_expand_prologue are valid. */
458 bool prologue_data_valid_p;
461 #define sparc_frame_size cfun->machine->frame_size
462 #define sparc_apparent_frame_size cfun->machine->apparent_frame_size
463 #define sparc_frame_base_reg cfun->machine->frame_base_reg
464 #define sparc_frame_base_offset cfun->machine->frame_base_offset
465 #define sparc_n_global_fp_regs cfun->machine->n_global_fp_regs
466 #define sparc_leaf_function_p cfun->machine->leaf_function_p
467 #define sparc_save_local_in_regs_p cfun->machine->save_local_in_regs_p
468 #define sparc_prologue_data_valid_p cfun->machine->prologue_data_valid_p
470 /* 1 if the next opcode is to be specially indented. */
471 int sparc_indent_opcode = 0;
473 static void sparc_option_override (void);
474 static void sparc_init_modes (void);
475 static void scan_record_type (const_tree, int *, int *, int *);
476 static int function_arg_slotno (const CUMULATIVE_ARGS *, enum machine_mode,
477 const_tree, bool, bool, int *, int *);
479 static int supersparc_adjust_cost (rtx, rtx, rtx, int);
480 static int hypersparc_adjust_cost (rtx, rtx, rtx, int);
482 static void sparc_emit_set_const32 (rtx, rtx);
483 static void sparc_emit_set_const64 (rtx, rtx);
484 static void sparc_output_addr_vec (rtx);
485 static void sparc_output_addr_diff_vec (rtx);
486 static void sparc_output_deferred_case_vectors (void);
487 static bool sparc_legitimate_address_p (enum machine_mode, rtx, bool);
488 static bool sparc_legitimate_constant_p (enum machine_mode, rtx);
489 static rtx sparc_builtin_saveregs (void);
490 static int epilogue_renumber (rtx *, int);
491 static bool sparc_assemble_integer (rtx, unsigned int, int);
492 static int set_extends (rtx);
493 static void sparc_asm_function_prologue (FILE *, HOST_WIDE_INT);
494 static void sparc_asm_function_epilogue (FILE *, HOST_WIDE_INT);
495 #ifdef TARGET_SOLARIS
496 static void sparc_solaris_elf_asm_named_section (const char *, unsigned int,
497 tree) ATTRIBUTE_UNUSED;
499 static int sparc_adjust_cost (rtx, rtx, rtx, int);
500 static int sparc_issue_rate (void);
501 static void sparc_sched_init (FILE *, int, int);
502 static int sparc_use_sched_lookahead (void);
504 static void emit_soft_tfmode_libcall (const char *, int, rtx *);
505 static void emit_soft_tfmode_binop (enum rtx_code, rtx *);
506 static void emit_soft_tfmode_unop (enum rtx_code, rtx *);
507 static void emit_soft_tfmode_cvt (enum rtx_code, rtx *);
508 static void emit_hard_tfmode_operation (enum rtx_code, rtx *);
510 static bool sparc_function_ok_for_sibcall (tree, tree);
511 static void sparc_init_libfuncs (void);
512 static void sparc_init_builtins (void);
513 static void sparc_vis_init_builtins (void);
514 static rtx sparc_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
515 static tree sparc_fold_builtin (tree, int, tree *, bool);
516 static int sparc_vis_mul8x16 (int, int);
517 static tree sparc_handle_vis_mul8x16 (int, tree, tree, tree);
518 static void sparc_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
519 HOST_WIDE_INT, tree);
520 static bool sparc_can_output_mi_thunk (const_tree, HOST_WIDE_INT,
521 HOST_WIDE_INT, const_tree);
522 static void sparc_reorg (void);
523 static struct machine_function * sparc_init_machine_status (void);
524 static bool sparc_cannot_force_const_mem (enum machine_mode, rtx);
525 static rtx sparc_tls_get_addr (void);
526 static rtx sparc_tls_got (void);
527 static const char *get_some_local_dynamic_name (void);
528 static int get_some_local_dynamic_name_1 (rtx *, void *);
529 static int sparc_register_move_cost (enum machine_mode,
530 reg_class_t, reg_class_t);
531 static bool sparc_rtx_costs (rtx, int, int, int, int *, bool);
532 static rtx sparc_function_value (const_tree, const_tree, bool);
533 static rtx sparc_libcall_value (enum machine_mode, const_rtx);
534 static bool sparc_function_value_regno_p (const unsigned int);
535 static rtx sparc_struct_value_rtx (tree, int);
536 static enum machine_mode sparc_promote_function_mode (const_tree, enum machine_mode,
537 int *, const_tree, int);
538 static bool sparc_return_in_memory (const_tree, const_tree);
539 static bool sparc_strict_argument_naming (cumulative_args_t);
540 static void sparc_va_start (tree, rtx);
541 static tree sparc_gimplify_va_arg (tree, tree, gimple_seq *, gimple_seq *);
542 static bool sparc_vector_mode_supported_p (enum machine_mode);
543 static bool sparc_tls_referenced_p (rtx);
544 static rtx sparc_legitimize_tls_address (rtx);
545 static rtx sparc_legitimize_pic_address (rtx, rtx);
546 static rtx sparc_legitimize_address (rtx, rtx, enum machine_mode);
547 static rtx sparc_delegitimize_address (rtx);
548 static bool sparc_mode_dependent_address_p (const_rtx);
549 static bool sparc_pass_by_reference (cumulative_args_t,
550 enum machine_mode, const_tree, bool);
551 static void sparc_function_arg_advance (cumulative_args_t,
552 enum machine_mode, const_tree, bool);
553 static rtx sparc_function_arg_1 (cumulative_args_t,
554 enum machine_mode, const_tree, bool, bool);
555 static rtx sparc_function_arg (cumulative_args_t,
556 enum machine_mode, const_tree, bool);
557 static rtx sparc_function_incoming_arg (cumulative_args_t,
558 enum machine_mode, const_tree, bool);
559 static unsigned int sparc_function_arg_boundary (enum machine_mode,
561 static int sparc_arg_partial_bytes (cumulative_args_t,
562 enum machine_mode, tree, bool);
563 static void sparc_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
564 static void sparc_file_end (void);
565 static bool sparc_frame_pointer_required (void);
566 static bool sparc_can_eliminate (const int, const int);
567 static rtx sparc_builtin_setjmp_frame_value (void);
568 static void sparc_conditional_register_usage (void);
569 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
570 static const char *sparc_mangle_type (const_tree);
572 static void sparc_trampoline_init (rtx, tree, rtx);
573 static enum machine_mode sparc_preferred_simd_mode (enum machine_mode);
574 static reg_class_t sparc_preferred_reload_class (rtx x, reg_class_t rclass);
575 static bool sparc_print_operand_punct_valid_p (unsigned char);
576 static void sparc_print_operand (FILE *, rtx, int);
577 static void sparc_print_operand_address (FILE *, rtx);
578 static reg_class_t sparc_secondary_reload (bool, rtx, reg_class_t,
580 secondary_reload_info *);
582 #ifdef SUBTARGET_ATTRIBUTE_TABLE
583 /* Table of valid machine attributes. */
584 static const struct attribute_spec sparc_attribute_table[] =
586 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
588 SUBTARGET_ATTRIBUTE_TABLE,
589 { NULL, 0, 0, false, false, false, NULL, false }
593 /* Option handling. */
596 enum cmodel sparc_cmodel;
598 char sparc_hard_reg_printed[8];
600 /* Initialize the GCC target structure. */
602 /* The default is to use .half rather than .short for aligned HI objects. */
603 #undef TARGET_ASM_ALIGNED_HI_OP
604 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
606 #undef TARGET_ASM_UNALIGNED_HI_OP
607 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
608 #undef TARGET_ASM_UNALIGNED_SI_OP
609 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
610 #undef TARGET_ASM_UNALIGNED_DI_OP
611 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
613 /* The target hook has to handle DI-mode values. */
614 #undef TARGET_ASM_INTEGER
615 #define TARGET_ASM_INTEGER sparc_assemble_integer
617 #undef TARGET_ASM_FUNCTION_PROLOGUE
618 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
619 #undef TARGET_ASM_FUNCTION_EPILOGUE
620 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
622 #undef TARGET_SCHED_ADJUST_COST
623 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
624 #undef TARGET_SCHED_ISSUE_RATE
625 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
626 #undef TARGET_SCHED_INIT
627 #define TARGET_SCHED_INIT sparc_sched_init
628 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
629 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
631 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
632 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
634 #undef TARGET_INIT_LIBFUNCS
635 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
636 #undef TARGET_INIT_BUILTINS
637 #define TARGET_INIT_BUILTINS sparc_init_builtins
639 #undef TARGET_LEGITIMIZE_ADDRESS
640 #define TARGET_LEGITIMIZE_ADDRESS sparc_legitimize_address
641 #undef TARGET_DELEGITIMIZE_ADDRESS
642 #define TARGET_DELEGITIMIZE_ADDRESS sparc_delegitimize_address
643 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
644 #define TARGET_MODE_DEPENDENT_ADDRESS_P sparc_mode_dependent_address_p
646 #undef TARGET_EXPAND_BUILTIN
647 #define TARGET_EXPAND_BUILTIN sparc_expand_builtin
648 #undef TARGET_FOLD_BUILTIN
649 #define TARGET_FOLD_BUILTIN sparc_fold_builtin
652 #undef TARGET_HAVE_TLS
653 #define TARGET_HAVE_TLS true
656 #undef TARGET_CANNOT_FORCE_CONST_MEM
657 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
659 #undef TARGET_ASM_OUTPUT_MI_THUNK
660 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
661 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
662 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
664 #undef TARGET_MACHINE_DEPENDENT_REORG
665 #define TARGET_MACHINE_DEPENDENT_REORG sparc_reorg
667 #undef TARGET_RTX_COSTS
668 #define TARGET_RTX_COSTS sparc_rtx_costs
669 #undef TARGET_ADDRESS_COST
670 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
671 #undef TARGET_REGISTER_MOVE_COST
672 #define TARGET_REGISTER_MOVE_COST sparc_register_move_cost
674 #undef TARGET_PROMOTE_FUNCTION_MODE
675 #define TARGET_PROMOTE_FUNCTION_MODE sparc_promote_function_mode
677 #undef TARGET_FUNCTION_VALUE
678 #define TARGET_FUNCTION_VALUE sparc_function_value
679 #undef TARGET_LIBCALL_VALUE
680 #define TARGET_LIBCALL_VALUE sparc_libcall_value
681 #undef TARGET_FUNCTION_VALUE_REGNO_P
682 #define TARGET_FUNCTION_VALUE_REGNO_P sparc_function_value_regno_p
684 #undef TARGET_STRUCT_VALUE_RTX
685 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
686 #undef TARGET_RETURN_IN_MEMORY
687 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
688 #undef TARGET_MUST_PASS_IN_STACK
689 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
690 #undef TARGET_PASS_BY_REFERENCE
691 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
692 #undef TARGET_ARG_PARTIAL_BYTES
693 #define TARGET_ARG_PARTIAL_BYTES sparc_arg_partial_bytes
694 #undef TARGET_FUNCTION_ARG_ADVANCE
695 #define TARGET_FUNCTION_ARG_ADVANCE sparc_function_arg_advance
696 #undef TARGET_FUNCTION_ARG
697 #define TARGET_FUNCTION_ARG sparc_function_arg
698 #undef TARGET_FUNCTION_INCOMING_ARG
699 #define TARGET_FUNCTION_INCOMING_ARG sparc_function_incoming_arg
700 #undef TARGET_FUNCTION_ARG_BOUNDARY
701 #define TARGET_FUNCTION_ARG_BOUNDARY sparc_function_arg_boundary
703 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
704 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
705 #undef TARGET_STRICT_ARGUMENT_NAMING
706 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
708 #undef TARGET_EXPAND_BUILTIN_VA_START
709 #define TARGET_EXPAND_BUILTIN_VA_START sparc_va_start
710 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
711 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
713 #undef TARGET_VECTOR_MODE_SUPPORTED_P
714 #define TARGET_VECTOR_MODE_SUPPORTED_P sparc_vector_mode_supported_p
716 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
717 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE sparc_preferred_simd_mode
719 #ifdef SUBTARGET_INSERT_ATTRIBUTES
720 #undef TARGET_INSERT_ATTRIBUTES
721 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
724 #ifdef SUBTARGET_ATTRIBUTE_TABLE
725 #undef TARGET_ATTRIBUTE_TABLE
726 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
729 #undef TARGET_RELAXED_ORDERING
730 #define TARGET_RELAXED_ORDERING SPARC_RELAXED_ORDERING
732 #undef TARGET_OPTION_OVERRIDE
733 #define TARGET_OPTION_OVERRIDE sparc_option_override
735 #if TARGET_GNU_TLS && defined(HAVE_AS_SPARC_UA_PCREL)
736 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
737 #define TARGET_ASM_OUTPUT_DWARF_DTPREL sparc_output_dwarf_dtprel
740 #undef TARGET_ASM_FILE_END
741 #define TARGET_ASM_FILE_END sparc_file_end
743 #undef TARGET_FRAME_POINTER_REQUIRED
744 #define TARGET_FRAME_POINTER_REQUIRED sparc_frame_pointer_required
746 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
747 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE sparc_builtin_setjmp_frame_value
749 #undef TARGET_CAN_ELIMINATE
750 #define TARGET_CAN_ELIMINATE sparc_can_eliminate
752 #undef TARGET_PREFERRED_RELOAD_CLASS
753 #define TARGET_PREFERRED_RELOAD_CLASS sparc_preferred_reload_class
755 #undef TARGET_SECONDARY_RELOAD
756 #define TARGET_SECONDARY_RELOAD sparc_secondary_reload
758 #undef TARGET_CONDITIONAL_REGISTER_USAGE
759 #define TARGET_CONDITIONAL_REGISTER_USAGE sparc_conditional_register_usage
761 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
762 #undef TARGET_MANGLE_TYPE
763 #define TARGET_MANGLE_TYPE sparc_mangle_type
766 #undef TARGET_LEGITIMATE_ADDRESS_P
767 #define TARGET_LEGITIMATE_ADDRESS_P sparc_legitimate_address_p
769 #undef TARGET_LEGITIMATE_CONSTANT_P
770 #define TARGET_LEGITIMATE_CONSTANT_P sparc_legitimate_constant_p
772 #undef TARGET_TRAMPOLINE_INIT
773 #define TARGET_TRAMPOLINE_INIT sparc_trampoline_init
775 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
776 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P sparc_print_operand_punct_valid_p
777 #undef TARGET_PRINT_OPERAND
778 #define TARGET_PRINT_OPERAND sparc_print_operand
779 #undef TARGET_PRINT_OPERAND_ADDRESS
780 #define TARGET_PRINT_OPERAND_ADDRESS sparc_print_operand_address
782 struct gcc_target targetm = TARGET_INITIALIZER;
785 dump_target_flag_bits (const int flags)
787 if (flags & MASK_64BIT)
788 fprintf (stderr, "64BIT ");
789 if (flags & MASK_APP_REGS)
790 fprintf (stderr, "APP_REGS ");
791 if (flags & MASK_FASTER_STRUCTS)
792 fprintf (stderr, "FASTER_STRUCTS ");
793 if (flags & MASK_FLAT)
794 fprintf (stderr, "FLAT ");
795 if (flags & MASK_FMAF)
796 fprintf (stderr, "FMAF ");
797 if (flags & MASK_FPU)
798 fprintf (stderr, "FPU ");
799 if (flags & MASK_HARD_QUAD)
800 fprintf (stderr, "HARD_QUAD ");
801 if (flags & MASK_POPC)
802 fprintf (stderr, "POPC ");
803 if (flags & MASK_PTR64)
804 fprintf (stderr, "PTR64 ");
805 if (flags & MASK_STACK_BIAS)
806 fprintf (stderr, "STACK_BIAS ");
807 if (flags & MASK_UNALIGNED_DOUBLES)
808 fprintf (stderr, "UNALIGNED_DOUBLES ");
809 if (flags & MASK_V8PLUS)
810 fprintf (stderr, "V8PLUS ");
811 if (flags & MASK_VIS)
812 fprintf (stderr, "VIS ");
813 if (flags & MASK_VIS2)
814 fprintf (stderr, "VIS2 ");
815 if (flags & MASK_VIS3)
816 fprintf (stderr, "VIS3 ");
817 if (flags & MASK_DEPRECATED_V8_INSNS)
818 fprintf (stderr, "DEPRECATED_V8_INSNS ");
819 if (flags & MASK_SPARCLET)
820 fprintf (stderr, "SPARCLET ");
821 if (flags & MASK_SPARCLITE)
822 fprintf (stderr, "SPARCLITE ");
824 fprintf (stderr, "V8 ");
826 fprintf (stderr, "V9 ");
830 dump_target_flags (const char *prefix, const int flags)
832 fprintf (stderr, "%s: (%08x) [ ", prefix, flags);
833 dump_target_flag_bits (flags);
834 fprintf(stderr, "]\n");
837 /* Validate and override various options, and do some machine dependent
841 sparc_option_override (void)
843 static struct code_model {
844 const char *const name;
845 const enum cmodel value;
846 } const cmodels[] = {
848 { "medlow", CM_MEDLOW },
849 { "medmid", CM_MEDMID },
850 { "medany", CM_MEDANY },
851 { "embmedany", CM_EMBMEDANY },
852 { NULL, (enum cmodel) 0 }
854 const struct code_model *cmodel;
855 /* Map TARGET_CPU_DEFAULT to value for -m{cpu,tune}=. */
856 static struct cpu_default {
858 const enum processor_type processor;
859 } const cpu_default[] = {
860 /* There must be one entry here for each TARGET_CPU value. */
861 { TARGET_CPU_sparc, PROCESSOR_CYPRESS },
862 { TARGET_CPU_v8, PROCESSOR_V8 },
863 { TARGET_CPU_supersparc, PROCESSOR_SUPERSPARC },
864 { TARGET_CPU_hypersparc, PROCESSOR_HYPERSPARC },
865 { TARGET_CPU_leon, PROCESSOR_LEON },
866 { TARGET_CPU_sparclite, PROCESSOR_F930 },
867 { TARGET_CPU_sparclite86x, PROCESSOR_SPARCLITE86X },
868 { TARGET_CPU_sparclet, PROCESSOR_TSC701 },
869 { TARGET_CPU_v9, PROCESSOR_V9 },
870 { TARGET_CPU_ultrasparc, PROCESSOR_ULTRASPARC },
871 { TARGET_CPU_ultrasparc3, PROCESSOR_ULTRASPARC3 },
872 { TARGET_CPU_niagara, PROCESSOR_NIAGARA },
873 { TARGET_CPU_niagara2, PROCESSOR_NIAGARA2 },
874 { TARGET_CPU_niagara3, PROCESSOR_NIAGARA3 },
875 { TARGET_CPU_niagara4, PROCESSOR_NIAGARA4 },
878 const struct cpu_default *def;
879 /* Table of values for -m{cpu,tune}=. This must match the order of
880 the PROCESSOR_* enumeration. */
881 static struct cpu_table {
882 const char *const name;
885 } const cpu_table[] = {
886 { "v7", MASK_ISA, 0 },
887 { "cypress", MASK_ISA, 0 },
888 { "v8", MASK_ISA, MASK_V8 },
889 /* TI TMS390Z55 supersparc */
890 { "supersparc", MASK_ISA, MASK_V8 },
891 { "hypersparc", MASK_ISA, MASK_V8|MASK_FPU },
893 { "leon", MASK_ISA, MASK_V8|MASK_FPU },
894 { "sparclite", MASK_ISA, MASK_SPARCLITE },
895 /* The Fujitsu MB86930 is the original sparclite chip, with no FPU. */
896 { "f930", MASK_ISA|MASK_FPU, MASK_SPARCLITE },
897 /* The Fujitsu MB86934 is the recent sparclite chip, with an FPU. */
898 { "f934", MASK_ISA, MASK_SPARCLITE|MASK_FPU },
899 { "sparclite86x", MASK_ISA|MASK_FPU, MASK_SPARCLITE },
900 { "sparclet", MASK_ISA, MASK_SPARCLET },
902 { "tsc701", MASK_ISA, MASK_SPARCLET },
903 { "v9", MASK_ISA, MASK_V9 },
904 /* UltraSPARC I, II, IIi */
905 { "ultrasparc", MASK_ISA,
906 /* Although insns using %y are deprecated, it is a clear win. */
907 MASK_V9|MASK_DEPRECATED_V8_INSNS },
909 /* ??? Check if %y issue still holds true. */
910 { "ultrasparc3", MASK_ISA,
911 MASK_V9|MASK_DEPRECATED_V8_INSNS|MASK_VIS2 },
913 { "niagara", MASK_ISA,
914 MASK_V9|MASK_DEPRECATED_V8_INSNS },
916 { "niagara2", MASK_ISA,
917 MASK_V9|MASK_POPC|MASK_VIS2 },
919 { "niagara3", MASK_ISA,
920 MASK_V9|MASK_POPC|MASK_VIS2|MASK_VIS3|MASK_FMAF },
922 { "niagara4", MASK_ISA,
923 MASK_V9|MASK_POPC|MASK_VIS2|MASK_VIS3|MASK_FMAF },
925 const struct cpu_table *cpu;
929 if (sparc_debug_string != NULL)
934 p = ASTRDUP (sparc_debug_string);
935 while ((q = strtok (p, ",")) != NULL)
949 if (! strcmp (q, "all"))
950 mask = MASK_DEBUG_ALL;
951 else if (! strcmp (q, "options"))
952 mask = MASK_DEBUG_OPTIONS;
954 error ("unknown -mdebug-%s switch", q);
957 sparc_debug &= ~mask;
963 if (TARGET_DEBUG_OPTIONS)
965 dump_target_flags("Initial target_flags", target_flags);
966 dump_target_flags("target_flags_explicit", target_flags_explicit);
969 #ifdef SUBTARGET_OVERRIDE_OPTIONS
970 SUBTARGET_OVERRIDE_OPTIONS;
973 #ifndef SPARC_BI_ARCH
974 /* Check for unsupported architecture size. */
975 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
976 error ("%s is not supported by this configuration",
977 DEFAULT_ARCH32_P ? "-m64" : "-m32");
980 /* We force all 64bit archs to use 128 bit long double */
981 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
983 error ("-mlong-double-64 not allowed with -m64");
984 target_flags |= MASK_LONG_DOUBLE_128;
987 /* Code model selection. */
988 sparc_cmodel = SPARC_DEFAULT_CMODEL;
992 sparc_cmodel = CM_32;
995 if (sparc_cmodel_string != NULL)
999 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
1000 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
1002 if (cmodel->name == NULL)
1003 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
1005 sparc_cmodel = cmodel->value;
1008 error ("-mcmodel= is not supported on 32 bit systems");
1011 /* Check that -fcall-saved-REG wasn't specified for out registers. */
1012 for (i = 8; i < 16; i++)
1013 if (!call_used_regs [i])
1015 error ("-fcall-saved-REG is not supported for out registers");
1016 call_used_regs [i] = 1;
1019 fpu = target_flags & MASK_FPU; /* save current -mfpu status */
1021 /* Set the default CPU. */
1022 if (!global_options_set.x_sparc_cpu_and_features)
1024 for (def = &cpu_default[0]; def->cpu != -1; ++def)
1025 if (def->cpu == TARGET_CPU_DEFAULT)
1027 gcc_assert (def->cpu != -1);
1028 sparc_cpu_and_features = def->processor;
1031 if (!global_options_set.x_sparc_cpu)
1032 sparc_cpu = sparc_cpu_and_features;
1034 cpu = &cpu_table[(int) sparc_cpu_and_features];
1036 if (TARGET_DEBUG_OPTIONS)
1038 fprintf (stderr, "sparc_cpu_and_features: %s\n", cpu->name);
1039 fprintf (stderr, "sparc_cpu: %s\n",
1040 cpu_table[(int) sparc_cpu].name);
1041 dump_target_flags ("cpu->disable", cpu->disable);
1042 dump_target_flags ("cpu->enable", cpu->enable);
1045 target_flags &= ~cpu->disable;
1046 target_flags |= (cpu->enable
1047 #ifndef HAVE_AS_FMAF_HPC_VIS3
1048 & ~(MASK_FMAF | MASK_VIS3)
1052 /* If -mfpu or -mno-fpu was explicitly used, don't override with
1053 the processor default. */
1054 if (target_flags_explicit & MASK_FPU)
1055 target_flags = (target_flags & ~MASK_FPU) | fpu;
1057 /* -mvis2 implies -mvis */
1059 target_flags |= MASK_VIS;
1061 /* -mvis3 implies -mvis2 and -mvis */
1063 target_flags |= MASK_VIS2 | MASK_VIS;
1065 /* Don't allow -mvis, -mvis2, -mvis3, or -mfmaf if FPU is disabled. */
1067 target_flags &= ~(MASK_VIS | MASK_VIS2 | MASK_VIS3 | MASK_FMAF);
1069 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
1071 -m64 also implies v9. */
1072 if (TARGET_VIS || TARGET_ARCH64)
1074 target_flags |= MASK_V9;
1075 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
1078 /* -mvis also implies -mv8plus on 32-bit */
1079 if (TARGET_VIS && ! TARGET_ARCH64)
1080 target_flags |= MASK_V8PLUS;
1082 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
1083 if (TARGET_V9 && TARGET_ARCH32)
1084 target_flags |= MASK_DEPRECATED_V8_INSNS;
1086 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
1087 if (! TARGET_V9 || TARGET_ARCH64)
1088 target_flags &= ~MASK_V8PLUS;
1090 /* Don't use stack biasing in 32 bit mode. */
1092 target_flags &= ~MASK_STACK_BIAS;
1094 /* Supply a default value for align_functions. */
1095 if (align_functions == 0
1096 && (sparc_cpu == PROCESSOR_ULTRASPARC
1097 || sparc_cpu == PROCESSOR_ULTRASPARC3
1098 || sparc_cpu == PROCESSOR_NIAGARA
1099 || sparc_cpu == PROCESSOR_NIAGARA2
1100 || sparc_cpu == PROCESSOR_NIAGARA3
1101 || sparc_cpu == PROCESSOR_NIAGARA4))
1102 align_functions = 32;
1104 /* Validate PCC_STRUCT_RETURN. */
1105 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
1106 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
1108 /* Only use .uaxword when compiling for a 64-bit target. */
1110 targetm.asm_out.unaligned_op.di = NULL;
1112 /* Do various machine dependent initializations. */
1113 sparc_init_modes ();
1115 /* Set up function hooks. */
1116 init_machine_status = sparc_init_machine_status;
1121 case PROCESSOR_CYPRESS:
1122 sparc_costs = &cypress_costs;
1125 case PROCESSOR_SPARCLITE:
1126 case PROCESSOR_SUPERSPARC:
1127 sparc_costs = &supersparc_costs;
1129 case PROCESSOR_F930:
1130 case PROCESSOR_F934:
1131 case PROCESSOR_HYPERSPARC:
1132 case PROCESSOR_SPARCLITE86X:
1133 sparc_costs = &hypersparc_costs;
1135 case PROCESSOR_LEON:
1136 sparc_costs = &leon_costs;
1138 case PROCESSOR_SPARCLET:
1139 case PROCESSOR_TSC701:
1140 sparc_costs = &sparclet_costs;
1143 case PROCESSOR_ULTRASPARC:
1144 sparc_costs = &ultrasparc_costs;
1146 case PROCESSOR_ULTRASPARC3:
1147 sparc_costs = &ultrasparc3_costs;
1149 case PROCESSOR_NIAGARA:
1150 sparc_costs = &niagara_costs;
1152 case PROCESSOR_NIAGARA2:
1153 sparc_costs = &niagara2_costs;
1155 case PROCESSOR_NIAGARA3:
1156 case PROCESSOR_NIAGARA4:
1157 sparc_costs = &niagara3_costs;
1159 case PROCESSOR_NATIVE:
1163 if (sparc_memory_model == SMM_DEFAULT)
1165 /* Choose the memory model for the operating system. */
1166 enum sparc_memory_model_type os_default = SUBTARGET_DEFAULT_MEMORY_MODEL;
1167 if (os_default != SMM_DEFAULT)
1168 sparc_memory_model = os_default;
1169 /* Choose the most relaxed model for the processor. */
1171 sparc_memory_model = SMM_RMO;
1173 sparc_memory_model = SMM_PSO;
1175 sparc_memory_model = SMM_SC;
1178 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
1179 if (!(target_flags_explicit & MASK_LONG_DOUBLE_128))
1180 target_flags |= MASK_LONG_DOUBLE_128;
1183 if (TARGET_DEBUG_OPTIONS)
1184 dump_target_flags ("Final target_flags", target_flags);
1186 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
1187 ((sparc_cpu == PROCESSOR_ULTRASPARC
1188 || sparc_cpu == PROCESSOR_NIAGARA
1189 || sparc_cpu == PROCESSOR_NIAGARA2
1190 || sparc_cpu == PROCESSOR_NIAGARA3
1191 || sparc_cpu == PROCESSOR_NIAGARA4)
1193 : (sparc_cpu == PROCESSOR_ULTRASPARC3
1195 global_options.x_param_values,
1196 global_options_set.x_param_values);
1197 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
1198 ((sparc_cpu == PROCESSOR_ULTRASPARC
1199 || sparc_cpu == PROCESSOR_ULTRASPARC3
1200 || sparc_cpu == PROCESSOR_NIAGARA
1201 || sparc_cpu == PROCESSOR_NIAGARA2
1202 || sparc_cpu == PROCESSOR_NIAGARA3
1203 || sparc_cpu == PROCESSOR_NIAGARA4)
1205 global_options.x_param_values,
1206 global_options_set.x_param_values);
1208 /* Disable save slot sharing for call-clobbered registers by default.
1209 The IRA sharing algorithm works on single registers only and this
1210 pessimizes for double floating-point registers. */
1211 if (!global_options_set.x_flag_ira_share_save_slots)
1212 flag_ira_share_save_slots = 0;
1215 /* Miscellaneous utilities. */
1217 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
1218 or branch on register contents instructions. */
1221 v9_regcmp_p (enum rtx_code code)
1223 return (code == EQ || code == NE || code == GE || code == LT
1224 || code == LE || code == GT);
1227 /* Nonzero if OP is a floating point constant which can
1228 be loaded into an integer register using a single
1229 sethi instruction. */
1234 if (GET_CODE (op) == CONST_DOUBLE)
1239 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
1240 REAL_VALUE_TO_TARGET_SINGLE (r, i);
1241 return !SPARC_SIMM13_P (i) && SPARC_SETHI_P (i);
1247 /* Nonzero if OP is a floating point constant which can
1248 be loaded into an integer register using a single
1254 if (GET_CODE (op) == CONST_DOUBLE)
1259 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
1260 REAL_VALUE_TO_TARGET_SINGLE (r, i);
1261 return SPARC_SIMM13_P (i);
1267 /* Nonzero if OP is a floating point constant which can
1268 be loaded into an integer register using a high/losum
1269 instruction sequence. */
1272 fp_high_losum_p (rtx op)
1274 /* The constraints calling this should only be in
1275 SFmode move insns, so any constant which cannot
1276 be moved using a single insn will do. */
1277 if (GET_CODE (op) == CONST_DOUBLE)
1282 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
1283 REAL_VALUE_TO_TARGET_SINGLE (r, i);
1284 return !SPARC_SIMM13_P (i) && !SPARC_SETHI_P (i);
1290 /* Return true if the address of LABEL can be loaded by means of the
1291 mov{si,di}_pic_label_ref patterns in PIC mode. */
1294 can_use_mov_pic_label_ref (rtx label)
1296 /* VxWorks does not impose a fixed gap between segments; the run-time
1297 gap can be different from the object-file gap. We therefore can't
1298 assume X - _GLOBAL_OFFSET_TABLE_ is a link-time constant unless we
1299 are absolutely sure that X is in the same segment as the GOT.
1300 Unfortunately, the flexibility of linker scripts means that we
1301 can't be sure of that in general, so assume that GOT-relative
1302 accesses are never valid on VxWorks. */
1303 if (TARGET_VXWORKS_RTP)
1306 /* Similarly, if the label is non-local, it might end up being placed
1307 in a different section than the current one; now mov_pic_label_ref
1308 requires the label and the code to be in the same section. */
1309 if (LABEL_REF_NONLOCAL_P (label))
1312 /* Finally, if we are reordering basic blocks and partition into hot
1313 and cold sections, this might happen for any label. */
1314 if (flag_reorder_blocks_and_partition)
1320 /* Expand a move instruction. Return true if all work is done. */
1323 sparc_expand_move (enum machine_mode mode, rtx *operands)
1325 /* Handle sets of MEM first. */
1326 if (GET_CODE (operands[0]) == MEM)
1328 /* 0 is a register (or a pair of registers) on SPARC. */
1329 if (register_or_zero_operand (operands[1], mode))
1332 if (!reload_in_progress)
1334 operands[0] = validize_mem (operands[0]);
1335 operands[1] = force_reg (mode, operands[1]);
1339 /* Fixup TLS cases. */
1341 && CONSTANT_P (operands[1])
1342 && sparc_tls_referenced_p (operands [1]))
1344 operands[1] = sparc_legitimize_tls_address (operands[1]);
1348 /* Fixup PIC cases. */
1349 if (flag_pic && CONSTANT_P (operands[1]))
1351 if (pic_address_needs_scratch (operands[1]))
1352 operands[1] = sparc_legitimize_pic_address (operands[1], NULL_RTX);
1354 /* We cannot use the mov{si,di}_pic_label_ref patterns in all cases. */
1355 if (GET_CODE (operands[1]) == LABEL_REF
1356 && can_use_mov_pic_label_ref (operands[1]))
1360 emit_insn (gen_movsi_pic_label_ref (operands[0], operands[1]));
1366 gcc_assert (TARGET_ARCH64);
1367 emit_insn (gen_movdi_pic_label_ref (operands[0], operands[1]));
1372 if (symbolic_operand (operands[1], mode))
1375 = sparc_legitimize_pic_address (operands[1],
1377 ? operands[0] : NULL_RTX);
1382 /* If we are trying to toss an integer constant into FP registers,
1383 or loading a FP or vector constant, force it into memory. */
1384 if (CONSTANT_P (operands[1])
1385 && REG_P (operands[0])
1386 && (SPARC_FP_REG_P (REGNO (operands[0]))
1387 || SCALAR_FLOAT_MODE_P (mode)
1388 || VECTOR_MODE_P (mode)))
1390 /* emit_group_store will send such bogosity to us when it is
1391 not storing directly into memory. So fix this up to avoid
1392 crashes in output_constant_pool. */
1393 if (operands [1] == const0_rtx)
1394 operands[1] = CONST0_RTX (mode);
1396 /* We can clear or set to all-ones FP registers if TARGET_VIS, and
1397 always other regs. */
1398 if ((TARGET_VIS || REGNO (operands[0]) < SPARC_FIRST_FP_REG)
1399 && (const_zero_operand (operands[1], mode)
1400 || const_all_ones_operand (operands[1], mode)))
1403 if (REGNO (operands[0]) < SPARC_FIRST_FP_REG
1404 /* We are able to build any SF constant in integer registers
1405 with at most 2 instructions. */
1407 /* And any DF constant in integer registers. */
1409 && ! can_create_pseudo_p ())))
1412 operands[1] = force_const_mem (mode, operands[1]);
1413 if (!reload_in_progress)
1414 operands[1] = validize_mem (operands[1]);
1418 /* Accept non-constants and valid constants unmodified. */
1419 if (!CONSTANT_P (operands[1])
1420 || GET_CODE (operands[1]) == HIGH
1421 || input_operand (operands[1], mode))
1427 /* All QImode constants require only one insn, so proceed. */
1432 sparc_emit_set_const32 (operands[0], operands[1]);
1436 /* input_operand should have filtered out 32-bit mode. */
1437 sparc_emit_set_const64 (operands[0], operands[1]);
1447 /* Load OP1, a 32-bit constant, into OP0, a register.
1448 We know it can't be done in one insn when we get
1449 here, the move expander guarantees this. */
1452 sparc_emit_set_const32 (rtx op0, rtx op1)
1454 enum machine_mode mode = GET_MODE (op0);
1457 if (can_create_pseudo_p ())
1458 temp = gen_reg_rtx (mode);
1460 if (GET_CODE (op1) == CONST_INT)
1462 gcc_assert (!small_int_operand (op1, mode)
1463 && !const_high_operand (op1, mode));
1465 /* Emit them as real moves instead of a HIGH/LO_SUM,
1466 this way CSE can see everything and reuse intermediate
1467 values if it wants. */
1468 emit_insn (gen_rtx_SET (VOIDmode, temp,
1469 GEN_INT (INTVAL (op1)
1470 & ~(HOST_WIDE_INT)0x3ff)));
1472 emit_insn (gen_rtx_SET (VOIDmode,
1474 gen_rtx_IOR (mode, temp,
1475 GEN_INT (INTVAL (op1) & 0x3ff))));
1479 /* A symbol, emit in the traditional way. */
1480 emit_insn (gen_rtx_SET (VOIDmode, temp,
1481 gen_rtx_HIGH (mode, op1)));
1482 emit_insn (gen_rtx_SET (VOIDmode,
1483 op0, gen_rtx_LO_SUM (mode, temp, op1)));
1487 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
1488 If TEMP is nonzero, we are forbidden to use any other scratch
1489 registers. Otherwise, we are allowed to generate them as needed.
1491 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
1492 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
1495 sparc_emit_set_symbolic_const64 (rtx op0, rtx op1, rtx temp)
1497 rtx temp1, temp2, temp3, temp4, temp5;
1500 if (temp && GET_MODE (temp) == TImode)
1503 temp = gen_rtx_REG (DImode, REGNO (temp));
1506 /* SPARC-V9 code-model support. */
1507 switch (sparc_cmodel)
1510 /* The range spanned by all instructions in the object is less
1511 than 2^31 bytes (2GB) and the distance from any instruction
1512 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1513 than 2^31 bytes (2GB).
1515 The executable must be in the low 4TB of the virtual address
1518 sethi %hi(symbol), %temp1
1519 or %temp1, %lo(symbol), %reg */
1521 temp1 = temp; /* op0 is allowed. */
1523 temp1 = gen_reg_rtx (DImode);
1525 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1526 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1530 /* The range spanned by all instructions in the object is less
1531 than 2^31 bytes (2GB) and the distance from any instruction
1532 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1533 than 2^31 bytes (2GB).
1535 The executable must be in the low 16TB of the virtual address
1538 sethi %h44(symbol), %temp1
1539 or %temp1, %m44(symbol), %temp2
1540 sllx %temp2, 12, %temp3
1541 or %temp3, %l44(symbol), %reg */
1546 temp3 = temp; /* op0 is allowed. */
1550 temp1 = gen_reg_rtx (DImode);
1551 temp2 = gen_reg_rtx (DImode);
1552 temp3 = gen_reg_rtx (DImode);
1555 emit_insn (gen_seth44 (temp1, op1));
1556 emit_insn (gen_setm44 (temp2, temp1, op1));
1557 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1558 gen_rtx_ASHIFT (DImode, temp2, GEN_INT (12))));
1559 emit_insn (gen_setl44 (op0, temp3, op1));
1563 /* The range spanned by all instructions in the object is less
1564 than 2^31 bytes (2GB) and the distance from any instruction
1565 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1566 than 2^31 bytes (2GB).
1568 The executable can be placed anywhere in the virtual address
1571 sethi %hh(symbol), %temp1
1572 sethi %lm(symbol), %temp2
1573 or %temp1, %hm(symbol), %temp3
1574 sllx %temp3, 32, %temp4
1575 or %temp4, %temp2, %temp5
1576 or %temp5, %lo(symbol), %reg */
1579 /* It is possible that one of the registers we got for operands[2]
1580 might coincide with that of operands[0] (which is why we made
1581 it TImode). Pick the other one to use as our scratch. */
1582 if (rtx_equal_p (temp, op0))
1584 gcc_assert (ti_temp);
1585 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1588 temp2 = temp; /* op0 is _not_ allowed, see above. */
1595 temp1 = gen_reg_rtx (DImode);
1596 temp2 = gen_reg_rtx (DImode);
1597 temp3 = gen_reg_rtx (DImode);
1598 temp4 = gen_reg_rtx (DImode);
1599 temp5 = gen_reg_rtx (DImode);
1602 emit_insn (gen_sethh (temp1, op1));
1603 emit_insn (gen_setlm (temp2, op1));
1604 emit_insn (gen_sethm (temp3, temp1, op1));
1605 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1606 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1607 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1608 gen_rtx_PLUS (DImode, temp4, temp2)));
1609 emit_insn (gen_setlo (op0, temp5, op1));
1613 /* Old old old backwards compatibility kruft here.
1614 Essentially it is MEDLOW with a fixed 64-bit
1615 virtual base added to all data segment addresses.
1616 Text-segment stuff is computed like MEDANY, we can't
1617 reuse the code above because the relocation knobs
1620 Data segment: sethi %hi(symbol), %temp1
1621 add %temp1, EMBMEDANY_BASE_REG, %temp2
1622 or %temp2, %lo(symbol), %reg */
1623 if (data_segment_operand (op1, GET_MODE (op1)))
1627 temp1 = temp; /* op0 is allowed. */
1632 temp1 = gen_reg_rtx (DImode);
1633 temp2 = gen_reg_rtx (DImode);
1636 emit_insn (gen_embmedany_sethi (temp1, op1));
1637 emit_insn (gen_embmedany_brsum (temp2, temp1));
1638 emit_insn (gen_embmedany_losum (op0, temp2, op1));
1641 /* Text segment: sethi %uhi(symbol), %temp1
1642 sethi %hi(symbol), %temp2
1643 or %temp1, %ulo(symbol), %temp3
1644 sllx %temp3, 32, %temp4
1645 or %temp4, %temp2, %temp5
1646 or %temp5, %lo(symbol), %reg */
1651 /* It is possible that one of the registers we got for operands[2]
1652 might coincide with that of operands[0] (which is why we made
1653 it TImode). Pick the other one to use as our scratch. */
1654 if (rtx_equal_p (temp, op0))
1656 gcc_assert (ti_temp);
1657 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1660 temp2 = temp; /* op0 is _not_ allowed, see above. */
1667 temp1 = gen_reg_rtx (DImode);
1668 temp2 = gen_reg_rtx (DImode);
1669 temp3 = gen_reg_rtx (DImode);
1670 temp4 = gen_reg_rtx (DImode);
1671 temp5 = gen_reg_rtx (DImode);
1674 emit_insn (gen_embmedany_textuhi (temp1, op1));
1675 emit_insn (gen_embmedany_texthi (temp2, op1));
1676 emit_insn (gen_embmedany_textulo (temp3, temp1, op1));
1677 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1678 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1679 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1680 gen_rtx_PLUS (DImode, temp4, temp2)));
1681 emit_insn (gen_embmedany_textlo (op0, temp5, op1));
1690 #if HOST_BITS_PER_WIDE_INT == 32
1692 sparc_emit_set_const64 (rtx op0 ATTRIBUTE_UNUSED, rtx op1 ATTRIBUTE_UNUSED)
1697 /* These avoid problems when cross compiling. If we do not
1698 go through all this hair then the optimizer will see
1699 invalid REG_EQUAL notes or in some cases none at all. */
1700 static rtx gen_safe_HIGH64 (rtx, HOST_WIDE_INT);
1701 static rtx gen_safe_SET64 (rtx, HOST_WIDE_INT);
1702 static rtx gen_safe_OR64 (rtx, HOST_WIDE_INT);
1703 static rtx gen_safe_XOR64 (rtx, HOST_WIDE_INT);
1705 /* The optimizer is not to assume anything about exactly
1706 which bits are set for a HIGH, they are unspecified.
1707 Unfortunately this leads to many missed optimizations
1708 during CSE. We mask out the non-HIGH bits, and matches
1709 a plain movdi, to alleviate this problem. */
1711 gen_safe_HIGH64 (rtx dest, HOST_WIDE_INT val)
1713 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val & ~(HOST_WIDE_INT)0x3ff));
1717 gen_safe_SET64 (rtx dest, HOST_WIDE_INT val)
1719 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val));
1723 gen_safe_OR64 (rtx src, HOST_WIDE_INT val)
1725 return gen_rtx_IOR (DImode, src, GEN_INT (val));
1729 gen_safe_XOR64 (rtx src, HOST_WIDE_INT val)
1731 return gen_rtx_XOR (DImode, src, GEN_INT (val));
1734 /* Worker routines for 64-bit constant formation on arch64.
1735 One of the key things to be doing in these emissions is
1736 to create as many temp REGs as possible. This makes it
1737 possible for half-built constants to be used later when
1738 such values are similar to something required later on.
1739 Without doing this, the optimizer cannot see such
1742 static void sparc_emit_set_const64_quick1 (rtx, rtx,
1743 unsigned HOST_WIDE_INT, int);
1746 sparc_emit_set_const64_quick1 (rtx op0, rtx temp,
1747 unsigned HOST_WIDE_INT low_bits, int is_neg)
1749 unsigned HOST_WIDE_INT high_bits;
1752 high_bits = (~low_bits) & 0xffffffff;
1754 high_bits = low_bits;
1756 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1759 emit_insn (gen_rtx_SET (VOIDmode, op0,
1760 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1764 /* If we are XOR'ing with -1, then we should emit a one's complement
1765 instead. This way the combiner will notice logical operations
1766 such as ANDN later on and substitute. */
1767 if ((low_bits & 0x3ff) == 0x3ff)
1769 emit_insn (gen_rtx_SET (VOIDmode, op0,
1770 gen_rtx_NOT (DImode, temp)));
1774 emit_insn (gen_rtx_SET (VOIDmode, op0,
1775 gen_safe_XOR64 (temp,
1776 (-(HOST_WIDE_INT)0x400
1777 | (low_bits & 0x3ff)))));
1782 static void sparc_emit_set_const64_quick2 (rtx, rtx, unsigned HOST_WIDE_INT,
1783 unsigned HOST_WIDE_INT, int);
1786 sparc_emit_set_const64_quick2 (rtx op0, rtx temp,
1787 unsigned HOST_WIDE_INT high_bits,
1788 unsigned HOST_WIDE_INT low_immediate,
1793 if ((high_bits & 0xfffffc00) != 0)
1795 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1796 if ((high_bits & ~0xfffffc00) != 0)
1797 emit_insn (gen_rtx_SET (VOIDmode, op0,
1798 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1804 emit_insn (gen_safe_SET64 (temp, high_bits));
1808 /* Now shift it up into place. */
1809 emit_insn (gen_rtx_SET (VOIDmode, op0,
1810 gen_rtx_ASHIFT (DImode, temp2,
1811 GEN_INT (shift_count))));
1813 /* If there is a low immediate part piece, finish up by
1814 putting that in as well. */
1815 if (low_immediate != 0)
1816 emit_insn (gen_rtx_SET (VOIDmode, op0,
1817 gen_safe_OR64 (op0, low_immediate)));
1820 static void sparc_emit_set_const64_longway (rtx, rtx, unsigned HOST_WIDE_INT,
1821 unsigned HOST_WIDE_INT);
1823 /* Full 64-bit constant decomposition. Even though this is the
1824 'worst' case, we still optimize a few things away. */
1826 sparc_emit_set_const64_longway (rtx op0, rtx temp,
1827 unsigned HOST_WIDE_INT high_bits,
1828 unsigned HOST_WIDE_INT low_bits)
1832 if (can_create_pseudo_p ())
1833 sub_temp = gen_reg_rtx (DImode);
1835 if ((high_bits & 0xfffffc00) != 0)
1837 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1838 if ((high_bits & ~0xfffffc00) != 0)
1839 emit_insn (gen_rtx_SET (VOIDmode,
1841 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1847 emit_insn (gen_safe_SET64 (temp, high_bits));
1851 if (can_create_pseudo_p ())
1853 rtx temp2 = gen_reg_rtx (DImode);
1854 rtx temp3 = gen_reg_rtx (DImode);
1855 rtx temp4 = gen_reg_rtx (DImode);
1857 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1858 gen_rtx_ASHIFT (DImode, sub_temp,
1861 emit_insn (gen_safe_HIGH64 (temp2, low_bits));
1862 if ((low_bits & ~0xfffffc00) != 0)
1864 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1865 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1866 emit_insn (gen_rtx_SET (VOIDmode, op0,
1867 gen_rtx_PLUS (DImode, temp4, temp3)));
1871 emit_insn (gen_rtx_SET (VOIDmode, op0,
1872 gen_rtx_PLUS (DImode, temp4, temp2)));
1877 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1878 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1879 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1882 /* We are in the middle of reload, so this is really
1883 painful. However we do still make an attempt to
1884 avoid emitting truly stupid code. */
1885 if (low1 != const0_rtx)
1887 emit_insn (gen_rtx_SET (VOIDmode, op0,
1888 gen_rtx_ASHIFT (DImode, sub_temp,
1889 GEN_INT (to_shift))));
1890 emit_insn (gen_rtx_SET (VOIDmode, op0,
1891 gen_rtx_IOR (DImode, op0, low1)));
1899 if (low2 != const0_rtx)
1901 emit_insn (gen_rtx_SET (VOIDmode, op0,
1902 gen_rtx_ASHIFT (DImode, sub_temp,
1903 GEN_INT (to_shift))));
1904 emit_insn (gen_rtx_SET (VOIDmode, op0,
1905 gen_rtx_IOR (DImode, op0, low2)));
1913 emit_insn (gen_rtx_SET (VOIDmode, op0,
1914 gen_rtx_ASHIFT (DImode, sub_temp,
1915 GEN_INT (to_shift))));
1916 if (low3 != const0_rtx)
1917 emit_insn (gen_rtx_SET (VOIDmode, op0,
1918 gen_rtx_IOR (DImode, op0, low3)));
1923 /* Analyze a 64-bit constant for certain properties. */
1924 static void analyze_64bit_constant (unsigned HOST_WIDE_INT,
1925 unsigned HOST_WIDE_INT,
1926 int *, int *, int *);
1929 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits,
1930 unsigned HOST_WIDE_INT low_bits,
1931 int *hbsp, int *lbsp, int *abbasp)
1933 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1936 lowest_bit_set = highest_bit_set = -1;
1940 if ((lowest_bit_set == -1)
1941 && ((low_bits >> i) & 1))
1943 if ((highest_bit_set == -1)
1944 && ((high_bits >> (32 - i - 1)) & 1))
1945 highest_bit_set = (64 - i - 1);
1948 && ((highest_bit_set == -1)
1949 || (lowest_bit_set == -1)));
1955 if ((lowest_bit_set == -1)
1956 && ((high_bits >> i) & 1))
1957 lowest_bit_set = i + 32;
1958 if ((highest_bit_set == -1)
1959 && ((low_bits >> (32 - i - 1)) & 1))
1960 highest_bit_set = 32 - i - 1;
1963 && ((highest_bit_set == -1)
1964 || (lowest_bit_set == -1)));
1966 /* If there are no bits set this should have gone out
1967 as one instruction! */
1968 gcc_assert (lowest_bit_set != -1 && highest_bit_set != -1);
1969 all_bits_between_are_set = 1;
1970 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1974 if ((low_bits & (1 << i)) != 0)
1979 if ((high_bits & (1 << (i - 32))) != 0)
1982 all_bits_between_are_set = 0;
1985 *hbsp = highest_bit_set;
1986 *lbsp = lowest_bit_set;
1987 *abbasp = all_bits_between_are_set;
1990 static int const64_is_2insns (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
1993 const64_is_2insns (unsigned HOST_WIDE_INT high_bits,
1994 unsigned HOST_WIDE_INT low_bits)
1996 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1999 || high_bits == 0xffffffff)
2002 analyze_64bit_constant (high_bits, low_bits,
2003 &highest_bit_set, &lowest_bit_set,
2004 &all_bits_between_are_set);
2006 if ((highest_bit_set == 63
2007 || lowest_bit_set == 0)
2008 && all_bits_between_are_set != 0)
2011 if ((highest_bit_set - lowest_bit_set) < 21)
2017 static unsigned HOST_WIDE_INT create_simple_focus_bits (unsigned HOST_WIDE_INT,
2018 unsigned HOST_WIDE_INT,
2021 static unsigned HOST_WIDE_INT
2022 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits,
2023 unsigned HOST_WIDE_INT low_bits,
2024 int lowest_bit_set, int shift)
2026 HOST_WIDE_INT hi, lo;
2028 if (lowest_bit_set < 32)
2030 lo = (low_bits >> lowest_bit_set) << shift;
2031 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
2036 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
2038 gcc_assert (! (hi & lo));
2042 /* Here we are sure to be arch64 and this is an integer constant
2043 being loaded into a register. Emit the most efficient
2044 insn sequence possible. Detection of all the 1-insn cases
2045 has been done already. */
2047 sparc_emit_set_const64 (rtx op0, rtx op1)
2049 unsigned HOST_WIDE_INT high_bits, low_bits;
2050 int lowest_bit_set, highest_bit_set;
2051 int all_bits_between_are_set;
2054 /* Sanity check that we know what we are working with. */
2055 gcc_assert (TARGET_ARCH64
2056 && (GET_CODE (op0) == SUBREG
2057 || (REG_P (op0) && ! SPARC_FP_REG_P (REGNO (op0)))));
2059 if (! can_create_pseudo_p ())
2062 if (GET_CODE (op1) != CONST_INT)
2064 sparc_emit_set_symbolic_const64 (op0, op1, temp);
2069 temp = gen_reg_rtx (DImode);
2071 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
2072 low_bits = (INTVAL (op1) & 0xffffffff);
2074 /* low_bits bits 0 --> 31
2075 high_bits bits 32 --> 63 */
2077 analyze_64bit_constant (high_bits, low_bits,
2078 &highest_bit_set, &lowest_bit_set,
2079 &all_bits_between_are_set);
2081 /* First try for a 2-insn sequence. */
2083 /* These situations are preferred because the optimizer can
2084 * do more things with them:
2086 * sllx %reg, shift, %reg
2088 * srlx %reg, shift, %reg
2089 * 3) mov some_small_const, %reg
2090 * sllx %reg, shift, %reg
2092 if (((highest_bit_set == 63
2093 || lowest_bit_set == 0)
2094 && all_bits_between_are_set != 0)
2095 || ((highest_bit_set - lowest_bit_set) < 12))
2097 HOST_WIDE_INT the_const = -1;
2098 int shift = lowest_bit_set;
2100 if ((highest_bit_set != 63
2101 && lowest_bit_set != 0)
2102 || all_bits_between_are_set == 0)
2105 create_simple_focus_bits (high_bits, low_bits,
2108 else if (lowest_bit_set == 0)
2109 shift = -(63 - highest_bit_set);
2111 gcc_assert (SPARC_SIMM13_P (the_const));
2112 gcc_assert (shift != 0);
2114 emit_insn (gen_safe_SET64 (temp, the_const));
2116 emit_insn (gen_rtx_SET (VOIDmode,
2118 gen_rtx_ASHIFT (DImode,
2122 emit_insn (gen_rtx_SET (VOIDmode,
2124 gen_rtx_LSHIFTRT (DImode,
2126 GEN_INT (-shift))));
2130 /* Now a range of 22 or less bits set somewhere.
2131 * 1) sethi %hi(focus_bits), %reg
2132 * sllx %reg, shift, %reg
2133 * 2) sethi %hi(focus_bits), %reg
2134 * srlx %reg, shift, %reg
2136 if ((highest_bit_set - lowest_bit_set) < 21)
2138 unsigned HOST_WIDE_INT focus_bits =
2139 create_simple_focus_bits (high_bits, low_bits,
2140 lowest_bit_set, 10);
2142 gcc_assert (SPARC_SETHI_P (focus_bits));
2143 gcc_assert (lowest_bit_set != 10);
2145 emit_insn (gen_safe_HIGH64 (temp, focus_bits));
2147 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
2148 if (lowest_bit_set < 10)
2149 emit_insn (gen_rtx_SET (VOIDmode,
2151 gen_rtx_LSHIFTRT (DImode, temp,
2152 GEN_INT (10 - lowest_bit_set))));
2153 else if (lowest_bit_set > 10)
2154 emit_insn (gen_rtx_SET (VOIDmode,
2156 gen_rtx_ASHIFT (DImode, temp,
2157 GEN_INT (lowest_bit_set - 10))));
2161 /* 1) sethi %hi(low_bits), %reg
2162 * or %reg, %lo(low_bits), %reg
2163 * 2) sethi %hi(~low_bits), %reg
2164 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
2167 || high_bits == 0xffffffff)
2169 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
2170 (high_bits == 0xffffffff));
2174 /* Now, try 3-insn sequences. */
2176 /* 1) sethi %hi(high_bits), %reg
2177 * or %reg, %lo(high_bits), %reg
2178 * sllx %reg, 32, %reg
2182 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
2186 /* We may be able to do something quick
2187 when the constant is negated, so try that. */
2188 if (const64_is_2insns ((~high_bits) & 0xffffffff,
2189 (~low_bits) & 0xfffffc00))
2191 /* NOTE: The trailing bits get XOR'd so we need the
2192 non-negated bits, not the negated ones. */
2193 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
2195 if ((((~high_bits) & 0xffffffff) == 0
2196 && ((~low_bits) & 0x80000000) == 0)
2197 || (((~high_bits) & 0xffffffff) == 0xffffffff
2198 && ((~low_bits) & 0x80000000) != 0))
2200 unsigned HOST_WIDE_INT fast_int = (~low_bits & 0xffffffff);
2202 if ((SPARC_SETHI_P (fast_int)
2203 && (~high_bits & 0xffffffff) == 0)
2204 || SPARC_SIMM13_P (fast_int))
2205 emit_insn (gen_safe_SET64 (temp, fast_int));
2207 sparc_emit_set_const64 (temp, GEN_INT (fast_int));
2212 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2213 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2214 sparc_emit_set_const64 (temp, negated_const);
2217 /* If we are XOR'ing with -1, then we should emit a one's complement
2218 instead. This way the combiner will notice logical operations
2219 such as ANDN later on and substitute. */
2220 if (trailing_bits == 0x3ff)
2222 emit_insn (gen_rtx_SET (VOIDmode, op0,
2223 gen_rtx_NOT (DImode, temp)));
2227 emit_insn (gen_rtx_SET (VOIDmode,
2229 gen_safe_XOR64 (temp,
2230 (-0x400 | trailing_bits))));
2235 /* 1) sethi %hi(xxx), %reg
2236 * or %reg, %lo(xxx), %reg
2237 * sllx %reg, yyy, %reg
2239 * ??? This is just a generalized version of the low_bits==0
2240 * thing above, FIXME...
2242 if ((highest_bit_set - lowest_bit_set) < 32)
2244 unsigned HOST_WIDE_INT focus_bits =
2245 create_simple_focus_bits (high_bits, low_bits,
2248 /* We can't get here in this state. */
2249 gcc_assert (highest_bit_set >= 32 && lowest_bit_set < 32);
2251 /* So what we know is that the set bits straddle the
2252 middle of the 64-bit word. */
2253 sparc_emit_set_const64_quick2 (op0, temp,
2259 /* 1) sethi %hi(high_bits), %reg
2260 * or %reg, %lo(high_bits), %reg
2261 * sllx %reg, 32, %reg
2262 * or %reg, low_bits, %reg
2264 if (SPARC_SIMM13_P(low_bits)
2265 && ((int)low_bits > 0))
2267 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2271 /* The easiest way when all else fails, is full decomposition. */
2272 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2274 #endif /* HOST_BITS_PER_WIDE_INT == 32 */
2276 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2277 return the mode to be used for the comparison. For floating-point,
2278 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2279 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2280 processing is needed. */
2283 select_cc_mode (enum rtx_code op, rtx x, rtx y ATTRIBUTE_UNUSED)
2285 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2311 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2312 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2314 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2315 return CCX_NOOVmode;
2321 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2328 /* Emit the compare insn and return the CC reg for a CODE comparison
2329 with operands X and Y. */
2332 gen_compare_reg_1 (enum rtx_code code, rtx x, rtx y)
2334 enum machine_mode mode;
2337 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
2340 mode = SELECT_CC_MODE (code, x, y);
2342 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2343 fcc regs (cse can't tell they're really call clobbered regs and will
2344 remove a duplicate comparison even if there is an intervening function
2345 call - it will then try to reload the cc reg via an int reg which is why
2346 we need the movcc patterns). It is possible to provide the movcc
2347 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2348 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2349 to tell cse that CCFPE mode registers (even pseudos) are call
2352 /* ??? This is an experiment. Rather than making changes to cse which may
2353 or may not be easy/clean, we do our own cse. This is possible because
2354 we will generate hard registers. Cse knows they're call clobbered (it
2355 doesn't know the same thing about pseudos). If we guess wrong, no big
2356 deal, but if we win, great! */
2358 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2359 #if 1 /* experiment */
2362 /* We cycle through the registers to ensure they're all exercised. */
2363 static int next_fcc_reg = 0;
2364 /* Previous x,y for each fcc reg. */
2365 static rtx prev_args[4][2];
2367 /* Scan prev_args for x,y. */
2368 for (reg = 0; reg < 4; reg++)
2369 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2374 prev_args[reg][0] = x;
2375 prev_args[reg][1] = y;
2376 next_fcc_reg = (next_fcc_reg + 1) & 3;
2378 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2381 cc_reg = gen_reg_rtx (mode);
2382 #endif /* ! experiment */
2383 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2384 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2386 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2388 /* We shouldn't get there for TFmode if !TARGET_HARD_QUAD. If we do, this
2389 will only result in an unrecognizable insn so no point in asserting. */
2390 emit_insn (gen_rtx_SET (VOIDmode, cc_reg, gen_rtx_COMPARE (mode, x, y)));
2396 /* Emit the compare insn and return the CC reg for the comparison in CMP. */
2399 gen_compare_reg (rtx cmp)
2401 return gen_compare_reg_1 (GET_CODE (cmp), XEXP (cmp, 0), XEXP (cmp, 1));
2404 /* This function is used for v9 only.
2405 DEST is the target of the Scc insn.
2406 CODE is the code for an Scc's comparison.
2407 X and Y are the values we compare.
2409 This function is needed to turn
2412 (gt (reg:CCX 100 %icc)
2416 (gt:DI (reg:CCX 100 %icc)
2419 IE: The instruction recognizer needs to see the mode of the comparison to
2420 find the right instruction. We could use "gt:DI" right in the
2421 define_expand, but leaving it out allows us to handle DI, SI, etc. */
2424 gen_v9_scc (rtx dest, enum rtx_code compare_code, rtx x, rtx y)
2427 && (GET_MODE (x) == DImode
2428 || GET_MODE (dest) == DImode))
2431 /* Try to use the movrCC insns. */
2433 && GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2435 && v9_regcmp_p (compare_code))
2440 /* Special case for op0 != 0. This can be done with one instruction if
2443 if (compare_code == NE
2444 && GET_MODE (dest) == DImode
2445 && rtx_equal_p (op0, dest))
2447 emit_insn (gen_rtx_SET (VOIDmode, dest,
2448 gen_rtx_IF_THEN_ELSE (DImode,
2449 gen_rtx_fmt_ee (compare_code, DImode,
2456 if (reg_overlap_mentioned_p (dest, op0))
2458 /* Handle the case where dest == x.
2459 We "early clobber" the result. */
2460 op0 = gen_reg_rtx (GET_MODE (x));
2461 emit_move_insn (op0, x);
2464 emit_insn (gen_rtx_SET (VOIDmode, dest, const0_rtx));
2465 if (GET_MODE (op0) != DImode)
2467 temp = gen_reg_rtx (DImode);
2468 convert_move (temp, op0, 0);
2472 emit_insn (gen_rtx_SET (VOIDmode, dest,
2473 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2474 gen_rtx_fmt_ee (compare_code, DImode,
2482 x = gen_compare_reg_1 (compare_code, x, y);
2485 gcc_assert (GET_MODE (x) != CC_NOOVmode
2486 && GET_MODE (x) != CCX_NOOVmode);
2488 emit_insn (gen_rtx_SET (VOIDmode, dest, const0_rtx));
2489 emit_insn (gen_rtx_SET (VOIDmode, dest,
2490 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2491 gen_rtx_fmt_ee (compare_code,
2492 GET_MODE (x), x, y),
2493 const1_rtx, dest)));
2499 /* Emit an scc insn. For seq, sne, sgeu, and sltu, we can do this
2500 without jumps using the addx/subx instructions. */
2503 emit_scc_insn (rtx operands[])
2510 /* The quad-word fp compare library routines all return nonzero to indicate
2511 true, which is different from the equivalent libgcc routines, so we must
2512 handle them specially here. */
2513 if (GET_MODE (operands[2]) == TFmode && ! TARGET_HARD_QUAD)
2515 operands[1] = sparc_emit_float_lib_cmp (operands[2], operands[3],
2516 GET_CODE (operands[1]));
2517 operands[2] = XEXP (operands[1], 0);
2518 operands[3] = XEXP (operands[1], 1);
2521 code = GET_CODE (operands[1]);
2525 /* For seq/sne on v9 we use the same code as v8 (the addx/subx method has
2526 more applications). The exception to this is "reg != 0" which can
2527 be done in one instruction on v9 (so we do it). */
2530 if (GET_MODE (x) == SImode)
2532 rtx pat = gen_seqsi_special (operands[0], x, y);
2536 else if (GET_MODE (x) == DImode)
2538 rtx pat = gen_seqdi_special (operands[0], x, y);
2546 if (GET_MODE (x) == SImode)
2548 rtx pat = gen_snesi_special (operands[0], x, y);
2552 else if (GET_MODE (x) == DImode)
2556 pat = gen_snedi_special_vis3 (operands[0], x, y);
2558 pat = gen_snedi_special (operands[0], x, y);
2566 && GET_MODE (x) == DImode
2568 && (code == GTU || code == LTU))
2569 && gen_v9_scc (operands[0], code, x, y))
2572 /* We can do LTU and GEU using the addx/subx instructions too. And
2573 for GTU/LEU, if both operands are registers swap them and fall
2574 back to the easy case. */
2575 if (code == GTU || code == LEU)
2577 if ((GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
2578 && (GET_CODE (y) == REG || GET_CODE (y) == SUBREG))
2583 code = swap_condition (code);
2588 || (!TARGET_VIS3 && code == GEU))
2590 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2591 gen_rtx_fmt_ee (code, SImode,
2592 gen_compare_reg_1 (code, x, y),
2597 /* All the posibilities to use addx/subx based sequences has been
2598 exhausted, try for a 3 instruction sequence using v9 conditional
2600 if (TARGET_V9 && gen_v9_scc (operands[0], code, x, y))
2603 /* Nope, do branches. */
2607 /* Emit a conditional jump insn for the v9 architecture using comparison code
2608 CODE and jump target LABEL.
2609 This function exists to take advantage of the v9 brxx insns. */
2612 emit_v9_brxx_insn (enum rtx_code code, rtx op0, rtx label)
2614 emit_jump_insn (gen_rtx_SET (VOIDmode,
2616 gen_rtx_IF_THEN_ELSE (VOIDmode,
2617 gen_rtx_fmt_ee (code, GET_MODE (op0),
2619 gen_rtx_LABEL_REF (VOIDmode, label),
2624 emit_conditional_branch_insn (rtx operands[])
2626 /* The quad-word fp compare library routines all return nonzero to indicate
2627 true, which is different from the equivalent libgcc routines, so we must
2628 handle them specially here. */
2629 if (GET_MODE (operands[1]) == TFmode && ! TARGET_HARD_QUAD)
2631 operands[0] = sparc_emit_float_lib_cmp (operands[1], operands[2],
2632 GET_CODE (operands[0]));
2633 operands[1] = XEXP (operands[0], 0);
2634 operands[2] = XEXP (operands[0], 1);
2637 if (TARGET_ARCH64 && operands[2] == const0_rtx
2638 && GET_CODE (operands[1]) == REG
2639 && GET_MODE (operands[1]) == DImode)
2641 emit_v9_brxx_insn (GET_CODE (operands[0]), operands[1], operands[3]);
2645 operands[1] = gen_compare_reg (operands[0]);
2646 operands[2] = const0_rtx;
2647 operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]), VOIDmode,
2648 operands[1], operands[2]);
2649 emit_jump_insn (gen_cbranchcc4 (operands[0], operands[1], operands[2],
2654 /* Generate a DFmode part of a hard TFmode register.
2655 REG is the TFmode hard register, LOW is 1 for the
2656 low 64bit of the register and 0 otherwise.
2659 gen_df_reg (rtx reg, int low)
2661 int regno = REGNO (reg);
2663 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2664 regno += (TARGET_ARCH64 && SPARC_INT_REG_P (regno)) ? 1 : 2;
2665 return gen_rtx_REG (DFmode, regno);
2668 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
2669 Unlike normal calls, TFmode operands are passed by reference. It is
2670 assumed that no more than 3 operands are required. */
2673 emit_soft_tfmode_libcall (const char *func_name, int nargs, rtx *operands)
2675 rtx ret_slot = NULL, arg[3], func_sym;
2678 /* We only expect to be called for conversions, unary, and binary ops. */
2679 gcc_assert (nargs == 2 || nargs == 3);
2681 for (i = 0; i < nargs; ++i)
2683 rtx this_arg = operands[i];
2686 /* TFmode arguments and return values are passed by reference. */
2687 if (GET_MODE (this_arg) == TFmode)
2689 int force_stack_temp;
2691 force_stack_temp = 0;
2692 if (TARGET_BUGGY_QP_LIB && i == 0)
2693 force_stack_temp = 1;
2695 if (GET_CODE (this_arg) == MEM
2696 && ! force_stack_temp)
2697 this_arg = XEXP (this_arg, 0);
2698 else if (CONSTANT_P (this_arg)
2699 && ! force_stack_temp)
2701 this_slot = force_const_mem (TFmode, this_arg);
2702 this_arg = XEXP (this_slot, 0);
2706 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode), 0);
2708 /* Operand 0 is the return value. We'll copy it out later. */
2710 emit_move_insn (this_slot, this_arg);
2712 ret_slot = this_slot;
2714 this_arg = XEXP (this_slot, 0);
2721 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
2723 if (GET_MODE (operands[0]) == TFmode)
2726 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
2727 arg[0], GET_MODE (arg[0]),
2728 arg[1], GET_MODE (arg[1]));
2730 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
2731 arg[0], GET_MODE (arg[0]),
2732 arg[1], GET_MODE (arg[1]),
2733 arg[2], GET_MODE (arg[2]));
2736 emit_move_insn (operands[0], ret_slot);
2742 gcc_assert (nargs == 2);
2744 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
2745 GET_MODE (operands[0]), 1,
2746 arg[1], GET_MODE (arg[1]));
2748 if (ret != operands[0])
2749 emit_move_insn (operands[0], ret);
2753 /* Expand soft-float TFmode calls to sparc abi routines. */
2756 emit_soft_tfmode_binop (enum rtx_code code, rtx *operands)
2778 emit_soft_tfmode_libcall (func, 3, operands);
2782 emit_soft_tfmode_unop (enum rtx_code code, rtx *operands)
2786 gcc_assert (code == SQRT);
2789 emit_soft_tfmode_libcall (func, 2, operands);
2793 emit_soft_tfmode_cvt (enum rtx_code code, rtx *operands)
2800 switch (GET_MODE (operands[1]))
2813 case FLOAT_TRUNCATE:
2814 switch (GET_MODE (operands[0]))
2828 switch (GET_MODE (operands[1]))
2833 operands[1] = gen_rtx_SIGN_EXTEND (DImode, operands[1]);
2843 case UNSIGNED_FLOAT:
2844 switch (GET_MODE (operands[1]))
2849 operands[1] = gen_rtx_ZERO_EXTEND (DImode, operands[1]);
2860 switch (GET_MODE (operands[0]))
2874 switch (GET_MODE (operands[0]))
2891 emit_soft_tfmode_libcall (func, 2, operands);
2894 /* Expand a hard-float tfmode operation. All arguments must be in
2898 emit_hard_tfmode_operation (enum rtx_code code, rtx *operands)
2902 if (GET_RTX_CLASS (code) == RTX_UNARY)
2904 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2905 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
2909 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2910 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
2911 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
2912 operands[1], operands[2]);
2915 if (register_operand (operands[0], VOIDmode))
2918 dest = gen_reg_rtx (GET_MODE (operands[0]));
2920 emit_insn (gen_rtx_SET (VOIDmode, dest, op));
2922 if (dest != operands[0])
2923 emit_move_insn (operands[0], dest);
2927 emit_tfmode_binop (enum rtx_code code, rtx *operands)
2929 if (TARGET_HARD_QUAD)
2930 emit_hard_tfmode_operation (code, operands);
2932 emit_soft_tfmode_binop (code, operands);
2936 emit_tfmode_unop (enum rtx_code code, rtx *operands)
2938 if (TARGET_HARD_QUAD)
2939 emit_hard_tfmode_operation (code, operands);
2941 emit_soft_tfmode_unop (code, operands);
2945 emit_tfmode_cvt (enum rtx_code code, rtx *operands)
2947 if (TARGET_HARD_QUAD)
2948 emit_hard_tfmode_operation (code, operands);
2950 emit_soft_tfmode_cvt (code, operands);
2953 /* Return nonzero if a branch/jump/call instruction will be emitting
2954 nop into its delay slot. */
2957 empty_delay_slot (rtx insn)
2961 /* If no previous instruction (should not happen), return true. */
2962 if (PREV_INSN (insn) == NULL)
2965 seq = NEXT_INSN (PREV_INSN (insn));
2966 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
2972 /* Return nonzero if TRIAL can go into the call delay slot. */
2975 tls_call_delay (rtx trial)
2980 call __tls_get_addr, %tgd_call (foo)
2981 add %l7, %o0, %o0, %tgd_add (foo)
2982 while Sun as/ld does not. */
2983 if (TARGET_GNU_TLS || !TARGET_TLS)
2986 pat = PATTERN (trial);
2988 /* We must reject tgd_add{32|64}, i.e.
2989 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSGD)))
2990 and tldm_add{32|64}, i.e.
2991 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSLDM)))
2993 if (GET_CODE (pat) == SET
2994 && GET_CODE (SET_SRC (pat)) == PLUS)
2996 rtx unspec = XEXP (SET_SRC (pat), 1);
2998 if (GET_CODE (unspec) == UNSPEC
2999 && (XINT (unspec, 1) == UNSPEC_TLSGD
3000 || XINT (unspec, 1) == UNSPEC_TLSLDM))
3007 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
3008 instruction. RETURN_P is true if the v9 variant 'return' is to be
3009 considered in the test too.
3011 TRIAL must be a SET whose destination is a REG appropriate for the
3012 'restore' instruction or, if RETURN_P is true, for the 'return'
3016 eligible_for_restore_insn (rtx trial, bool return_p)
3018 rtx pat = PATTERN (trial);
3019 rtx src = SET_SRC (pat);
3020 bool src_is_freg = false;
3023 /* Since we now can do moves between float and integer registers when
3024 VIS3 is enabled, we have to catch this case. We can allow such
3025 moves when doing a 'return' however. */
3027 if (GET_CODE (src_reg) == SUBREG)
3028 src_reg = SUBREG_REG (src_reg);
3029 if (GET_CODE (src_reg) == REG
3030 && SPARC_FP_REG_P (REGNO (src_reg)))
3033 /* The 'restore src,%g0,dest' pattern for word mode and below. */
3034 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3035 && arith_operand (src, GET_MODE (src))
3039 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3041 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
3044 /* The 'restore src,%g0,dest' pattern for double-word mode. */
3045 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3046 && arith_double_operand (src, GET_MODE (src))
3048 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3050 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
3051 else if (! TARGET_FPU && register_operand (src, SFmode))
3054 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
3055 else if (! TARGET_FPU && TARGET_ARCH64 && register_operand (src, DFmode))
3058 /* If we have the 'return' instruction, anything that does not use
3059 local or output registers and can go into a delay slot wins. */
3062 && !epilogue_renumber (&pat, 1)
3063 && get_attr_in_uncond_branch_delay (trial)
3064 == IN_UNCOND_BRANCH_DELAY_TRUE)
3067 /* The 'restore src1,src2,dest' pattern for SImode. */
3068 else if (GET_CODE (src) == PLUS
3069 && register_operand (XEXP (src, 0), SImode)
3070 && arith_operand (XEXP (src, 1), SImode))
3073 /* The 'restore src1,src2,dest' pattern for DImode. */
3074 else if (GET_CODE (src) == PLUS
3075 && register_operand (XEXP (src, 0), DImode)
3076 && arith_double_operand (XEXP (src, 1), DImode))
3079 /* The 'restore src1,%lo(src2),dest' pattern. */
3080 else if (GET_CODE (src) == LO_SUM
3081 && ! TARGET_CM_MEDMID
3082 && ((register_operand (XEXP (src, 0), SImode)
3083 && immediate_operand (XEXP (src, 1), SImode))
3085 && register_operand (XEXP (src, 0), DImode)
3086 && immediate_operand (XEXP (src, 1), DImode))))
3089 /* The 'restore src,src,dest' pattern. */
3090 else if (GET_CODE (src) == ASHIFT
3091 && (register_operand (XEXP (src, 0), SImode)
3092 || register_operand (XEXP (src, 0), DImode))
3093 && XEXP (src, 1) == const1_rtx)
3099 /* Return nonzero if TRIAL can go into the function return's delay slot. */
3102 eligible_for_return_delay (rtx trial)
3107 if (GET_CODE (trial) != INSN)
3110 if (get_attr_length (trial) != 1)
3113 /* If the function uses __builtin_eh_return, the eh_return machinery
3114 occupies the delay slot. */
3115 if (crtl->calls_eh_return)
3118 /* In the case of a leaf or flat function, anything can go into the slot. */
3119 if (sparc_leaf_function_p || TARGET_FLAT)
3121 get_attr_in_uncond_branch_delay (trial) == IN_UNCOND_BRANCH_DELAY_TRUE;
3123 pat = PATTERN (trial);
3124 if (GET_CODE (pat) == PARALLEL)
3130 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
3132 rtx expr = XVECEXP (pat, 0, i);
3133 if (GET_CODE (expr) != SET)
3135 if (GET_CODE (SET_DEST (expr)) != REG)
3137 regno = REGNO (SET_DEST (expr));
3138 if (regno >= 8 && regno < 24)
3141 return !epilogue_renumber (&pat, 1)
3142 && (get_attr_in_uncond_branch_delay (trial)
3143 == IN_UNCOND_BRANCH_DELAY_TRUE);
3146 if (GET_CODE (pat) != SET)
3149 if (GET_CODE (SET_DEST (pat)) != REG)
3152 regno = REGNO (SET_DEST (pat));
3154 /* Otherwise, only operations which can be done in tandem with
3155 a `restore' or `return' insn can go into the delay slot. */
3156 if (regno >= 8 && regno < 24)
3159 /* If this instruction sets up floating point register and we have a return
3160 instruction, it can probably go in. But restore will not work
3162 if (! SPARC_INT_REG_P (regno))
3164 && !epilogue_renumber (&pat, 1)
3165 && get_attr_in_uncond_branch_delay (trial)
3166 == IN_UNCOND_BRANCH_DELAY_TRUE);
3168 return eligible_for_restore_insn (trial, true);
3171 /* Return nonzero if TRIAL can go into the sibling call's delay slot. */
3174 eligible_for_sibcall_delay (rtx trial)
3178 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
3181 if (get_attr_length (trial) != 1)
3184 pat = PATTERN (trial);
3186 if (sparc_leaf_function_p || TARGET_FLAT)
3188 /* If the tail call is done using the call instruction,
3189 we have to restore %o7 in the delay slot. */
3190 if (LEAF_SIBCALL_SLOT_RESERVED_P)
3193 /* %g1 is used to build the function address */
3194 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
3200 /* Otherwise, only operations which can be done in tandem with
3201 a `restore' insn can go into the delay slot. */
3202 if (GET_CODE (SET_DEST (pat)) != REG
3203 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24)
3204 || ! SPARC_INT_REG_P (REGNO (SET_DEST (pat))))
3207 /* If it mentions %o7, it can't go in, because sibcall will clobber it
3209 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
3212 return eligible_for_restore_insn (trial, false);
3215 /* Determine if it's legal to put X into the constant pool. This
3216 is not possible if X contains the address of a symbol that is
3217 not constant (TLS) or not known at final link time (PIC). */
3220 sparc_cannot_force_const_mem (enum machine_mode mode, rtx x)
3222 switch (GET_CODE (x))
3227 /* Accept all non-symbolic constants. */
3231 /* Labels are OK iff we are non-PIC. */
3232 return flag_pic != 0;
3235 /* 'Naked' TLS symbol references are never OK,
3236 non-TLS symbols are OK iff we are non-PIC. */
3237 if (SYMBOL_REF_TLS_MODEL (x))
3240 return flag_pic != 0;
3243 return sparc_cannot_force_const_mem (mode, XEXP (x, 0));
3246 return sparc_cannot_force_const_mem (mode, XEXP (x, 0))
3247 || sparc_cannot_force_const_mem (mode, XEXP (x, 1));
3255 /* Global Offset Table support. */
3256 static GTY(()) rtx got_helper_rtx = NULL_RTX;
3257 static GTY(()) rtx global_offset_table_rtx = NULL_RTX;
3259 /* Return the SYMBOL_REF for the Global Offset Table. */
3261 static GTY(()) rtx sparc_got_symbol = NULL_RTX;
3266 if (!sparc_got_symbol)
3267 sparc_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3269 return sparc_got_symbol;
3272 /* Ensure that we are not using patterns that are not OK with PIC. */
3282 op = recog_data.operand[i];
3283 gcc_assert (GET_CODE (op) != SYMBOL_REF
3284 && (GET_CODE (op) != CONST
3285 || (GET_CODE (XEXP (op, 0)) == MINUS
3286 && XEXP (XEXP (op, 0), 0) == sparc_got ()
3287 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST)));
3294 /* Return true if X is an address which needs a temporary register when
3295 reloaded while generating PIC code. */
3298 pic_address_needs_scratch (rtx x)
3300 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
3301 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3302 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
3303 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3304 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
3310 /* Determine if a given RTX is a valid constant. We already know this
3311 satisfies CONSTANT_P. */
3314 sparc_legitimate_constant_p (enum machine_mode mode, rtx x)
3316 switch (GET_CODE (x))
3320 if (sparc_tls_referenced_p (x))
3325 if (GET_MODE (x) == VOIDmode)
3328 /* Floating point constants are generally not ok.
3329 The only exception is 0.0 and all-ones in VIS. */
3331 && SCALAR_FLOAT_MODE_P (mode)
3332 && (const_zero_operand (x, mode)
3333 || const_all_ones_operand (x, mode)))
3339 /* Vector constants are generally not ok.
3340 The only exception is 0 or -1 in VIS. */
3342 && (const_zero_operand (x, mode)
3343 || const_all_ones_operand (x, mode)))
3355 /* Determine if a given RTX is a valid constant address. */
3358 constant_address_p (rtx x)
3360 switch (GET_CODE (x))
3368 if (flag_pic && pic_address_needs_scratch (x))
3370 return sparc_legitimate_constant_p (Pmode, x);
3373 return !flag_pic && sparc_legitimate_constant_p (Pmode, x);
3380 /* Nonzero if the constant value X is a legitimate general operand
3381 when generating PIC code. It is given that flag_pic is on and
3382 that X satisfies CONSTANT_P or is a CONST_DOUBLE. */
3385 legitimate_pic_operand_p (rtx x)
3387 if (pic_address_needs_scratch (x))
3389 if (sparc_tls_referenced_p (x))
3394 #define RTX_OK_FOR_OFFSET_P(X, MODE) \
3396 && INTVAL (X) >= -0x1000 \
3397 && INTVAL (X) < (0x1000 - GET_MODE_SIZE (MODE)))
3399 #define RTX_OK_FOR_OLO10_P(X, MODE) \
3401 && INTVAL (X) >= -0x1000 \
3402 && INTVAL (X) < (0xc00 - GET_MODE_SIZE (MODE)))
3404 /* Handle the TARGET_LEGITIMATE_ADDRESS_P target hook.
3406 On SPARC, the actual legitimate addresses must be REG+REG or REG+SMALLINT
3407 ordinarily. This changes a bit when generating PIC. */
3410 sparc_legitimate_address_p (enum machine_mode mode, rtx addr, bool strict)
3412 rtx rs1 = NULL, rs2 = NULL, imm1 = NULL;
3414 if (REG_P (addr) || GET_CODE (addr) == SUBREG)
3416 else if (GET_CODE (addr) == PLUS)
3418 rs1 = XEXP (addr, 0);
3419 rs2 = XEXP (addr, 1);
3421 /* Canonicalize. REG comes first, if there are no regs,
3422 LO_SUM comes first. */
3424 && GET_CODE (rs1) != SUBREG
3426 || GET_CODE (rs2) == SUBREG
3427 || (GET_CODE (rs2) == LO_SUM && GET_CODE (rs1) != LO_SUM)))
3429 rs1 = XEXP (addr, 1);
3430 rs2 = XEXP (addr, 0);
3434 && rs1 == pic_offset_table_rtx
3436 && GET_CODE (rs2) != SUBREG
3437 && GET_CODE (rs2) != LO_SUM
3438 && GET_CODE (rs2) != MEM
3439 && !(GET_CODE (rs2) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs2))
3440 && (! symbolic_operand (rs2, VOIDmode) || mode == Pmode)
3441 && (GET_CODE (rs2) != CONST_INT || SMALL_INT (rs2)))
3443 || GET_CODE (rs1) == SUBREG)
3444 && RTX_OK_FOR_OFFSET_P (rs2, mode)))
3449 else if ((REG_P (rs1) || GET_CODE (rs1) == SUBREG)
3450 && (REG_P (rs2) || GET_CODE (rs2) == SUBREG))
3452 /* We prohibit REG + REG for TFmode when there are no quad move insns
3453 and we consequently need to split. We do this because REG+REG
3454 is not an offsettable address. If we get the situation in reload
3455 where source and destination of a movtf pattern are both MEMs with
3456 REG+REG address, then only one of them gets converted to an
3457 offsettable address. */
3459 && ! (TARGET_ARCH64 && TARGET_HARD_QUAD))
3462 /* We prohibit REG + REG on ARCH32 if not optimizing for
3463 DFmode/DImode because then mem_min_alignment is likely to be zero
3464 after reload and the forced split would lack a matching splitter
3466 if (TARGET_ARCH32 && !optimize
3467 && (mode == DFmode || mode == DImode))
3470 else if (USE_AS_OFFSETABLE_LO10
3471 && GET_CODE (rs1) == LO_SUM
3473 && ! TARGET_CM_MEDMID
3474 && RTX_OK_FOR_OLO10_P (rs2, mode))
3477 imm1 = XEXP (rs1, 1);
3478 rs1 = XEXP (rs1, 0);
3479 if (!CONSTANT_P (imm1)
3480 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
3484 else if (GET_CODE (addr) == LO_SUM)
3486 rs1 = XEXP (addr, 0);
3487 imm1 = XEXP (addr, 1);
3489 if (!CONSTANT_P (imm1)
3490 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
3493 /* We can't allow TFmode in 32-bit mode, because an offset greater
3494 than the alignment (8) may cause the LO_SUM to overflow. */
3495 if (mode == TFmode && TARGET_ARCH32)
3498 else if (GET_CODE (addr) == CONST_INT && SMALL_INT (addr))
3503 if (GET_CODE (rs1) == SUBREG)
3504 rs1 = SUBREG_REG (rs1);
3510 if (GET_CODE (rs2) == SUBREG)
3511 rs2 = SUBREG_REG (rs2);
3518 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1))
3519 || (rs2 && !REGNO_OK_FOR_BASE_P (REGNO (rs2))))
3524 if ((! SPARC_INT_REG_P (REGNO (rs1))
3525 && REGNO (rs1) != FRAME_POINTER_REGNUM
3526 && REGNO (rs1) < FIRST_PSEUDO_REGISTER)
3528 && (! SPARC_INT_REG_P (REGNO (rs2))
3529 && REGNO (rs2) != FRAME_POINTER_REGNUM
3530 && REGNO (rs2) < FIRST_PSEUDO_REGISTER)))
3536 /* Return the SYMBOL_REF for the tls_get_addr function. */
3538 static GTY(()) rtx sparc_tls_symbol = NULL_RTX;
3541 sparc_tls_get_addr (void)
3543 if (!sparc_tls_symbol)
3544 sparc_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_addr");
3546 return sparc_tls_symbol;
3549 /* Return the Global Offset Table to be used in TLS mode. */
3552 sparc_tls_got (void)
3554 /* In PIC mode, this is just the PIC offset table. */
3557 crtl->uses_pic_offset_table = 1;
3558 return pic_offset_table_rtx;
3561 /* In non-PIC mode, Sun as (unlike GNU as) emits PC-relative relocations for
3562 the GOT symbol with the 32-bit ABI, so we reload the GOT register. */
3563 if (TARGET_SUN_TLS && TARGET_ARCH32)
3565 load_got_register ();
3566 return global_offset_table_rtx;
3569 /* In all other cases, we load a new pseudo with the GOT symbol. */
3570 return copy_to_reg (sparc_got ());
3573 /* Return true if X contains a thread-local symbol. */
3576 sparc_tls_referenced_p (rtx x)
3578 if (!TARGET_HAVE_TLS)
3581 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
3582 x = XEXP (XEXP (x, 0), 0);
3584 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x))
3587 /* That's all we handle in sparc_legitimize_tls_address for now. */
3591 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3592 this (thread-local) address. */
3595 sparc_legitimize_tls_address (rtx addr)
3597 rtx temp1, temp2, temp3, ret, o0, got, insn;
3599 gcc_assert (can_create_pseudo_p ());
3601 if (GET_CODE (addr) == SYMBOL_REF)
3602 switch (SYMBOL_REF_TLS_MODEL (addr))
3604 case TLS_MODEL_GLOBAL_DYNAMIC:
3606 temp1 = gen_reg_rtx (SImode);
3607 temp2 = gen_reg_rtx (SImode);
3608 ret = gen_reg_rtx (Pmode);
3609 o0 = gen_rtx_REG (Pmode, 8);
3610 got = sparc_tls_got ();
3611 emit_insn (gen_tgd_hi22 (temp1, addr));
3612 emit_insn (gen_tgd_lo10 (temp2, temp1, addr));
3615 emit_insn (gen_tgd_add32 (o0, got, temp2, addr));
3616 insn = emit_call_insn (gen_tgd_call32 (o0, sparc_tls_get_addr (),
3621 emit_insn (gen_tgd_add64 (o0, got, temp2, addr));
3622 insn = emit_call_insn (gen_tgd_call64 (o0, sparc_tls_get_addr (),
3625 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), o0);
3626 insn = get_insns ();
3628 emit_libcall_block (insn, ret, o0, addr);
3631 case TLS_MODEL_LOCAL_DYNAMIC:
3633 temp1 = gen_reg_rtx (SImode);
3634 temp2 = gen_reg_rtx (SImode);
3635 temp3 = gen_reg_rtx (Pmode);
3636 ret = gen_reg_rtx (Pmode);
3637 o0 = gen_rtx_REG (Pmode, 8);
3638 got = sparc_tls_got ();
3639 emit_insn (gen_tldm_hi22 (temp1));
3640 emit_insn (gen_tldm_lo10 (temp2, temp1));
3643 emit_insn (gen_tldm_add32 (o0, got, temp2));
3644 insn = emit_call_insn (gen_tldm_call32 (o0, sparc_tls_get_addr (),
3649 emit_insn (gen_tldm_add64 (o0, got, temp2));
3650 insn = emit_call_insn (gen_tldm_call64 (o0, sparc_tls_get_addr (),
3653 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), o0);
3654 insn = get_insns ();
3656 emit_libcall_block (insn, temp3, o0,
3657 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3658 UNSPEC_TLSLD_BASE));
3659 temp1 = gen_reg_rtx (SImode);
3660 temp2 = gen_reg_rtx (SImode);
3661 emit_insn (gen_tldo_hix22 (temp1, addr));
3662 emit_insn (gen_tldo_lox10 (temp2, temp1, addr));
3664 emit_insn (gen_tldo_add32 (ret, temp3, temp2, addr));
3666 emit_insn (gen_tldo_add64 (ret, temp3, temp2, addr));
3669 case TLS_MODEL_INITIAL_EXEC:
3670 temp1 = gen_reg_rtx (SImode);
3671 temp2 = gen_reg_rtx (SImode);
3672 temp3 = gen_reg_rtx (Pmode);
3673 got = sparc_tls_got ();
3674 emit_insn (gen_tie_hi22 (temp1, addr));
3675 emit_insn (gen_tie_lo10 (temp2, temp1, addr));
3677 emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
3679 emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
3682 ret = gen_reg_rtx (Pmode);
3684 emit_insn (gen_tie_add32 (ret, gen_rtx_REG (Pmode, 7),
3687 emit_insn (gen_tie_add64 (ret, gen_rtx_REG (Pmode, 7),
3691 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp3);
3694 case TLS_MODEL_LOCAL_EXEC:
3695 temp1 = gen_reg_rtx (Pmode);
3696 temp2 = gen_reg_rtx (Pmode);
3699 emit_insn (gen_tle_hix22_sp32 (temp1, addr));
3700 emit_insn (gen_tle_lox10_sp32 (temp2, temp1, addr));
3704 emit_insn (gen_tle_hix22_sp64 (temp1, addr));
3705 emit_insn (gen_tle_lox10_sp64 (temp2, temp1, addr));
3707 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp2);
3714 else if (GET_CODE (addr) == CONST)
3718 gcc_assert (GET_CODE (XEXP (addr, 0)) == PLUS);
3720 base = sparc_legitimize_tls_address (XEXP (XEXP (addr, 0), 0));
3721 offset = XEXP (XEXP (addr, 0), 1);
3723 base = force_operand (base, NULL_RTX);
3724 if (!(GET_CODE (offset) == CONST_INT && SMALL_INT (offset)))
3725 offset = force_reg (Pmode, offset);
3726 ret = gen_rtx_PLUS (Pmode, base, offset);
3730 gcc_unreachable (); /* for now ... */
3735 /* Legitimize PIC addresses. If the address is already position-independent,
3736 we return ORIG. Newly generated position-independent addresses go into a
3737 reg. This is REG if nonzero, otherwise we allocate register(s) as
3741 sparc_legitimize_pic_address (rtx orig, rtx reg)
3743 bool gotdata_op = false;
3745 if (GET_CODE (orig) == SYMBOL_REF
3746 /* See the comment in sparc_expand_move. */
3747 || (GET_CODE (orig) == LABEL_REF && !can_use_mov_pic_label_ref (orig)))
3749 rtx pic_ref, address;
3754 gcc_assert (can_create_pseudo_p ());
3755 reg = gen_reg_rtx (Pmode);
3760 /* If not during reload, allocate another temp reg here for loading
3761 in the address, so that these instructions can be optimized
3763 rtx temp_reg = (! can_create_pseudo_p ()
3764 ? reg : gen_reg_rtx (Pmode));
3766 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
3767 won't get confused into thinking that these two instructions
3768 are loading in the true address of the symbol. If in the
3769 future a PIC rtx exists, that should be used instead. */
3772 emit_insn (gen_movdi_high_pic (temp_reg, orig));
3773 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
3777 emit_insn (gen_movsi_high_pic (temp_reg, orig));
3778 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
3786 crtl->uses_pic_offset_table = 1;
3790 insn = emit_insn (gen_movdi_pic_gotdata_op (reg,
3791 pic_offset_table_rtx,
3794 insn = emit_insn (gen_movsi_pic_gotdata_op (reg,
3795 pic_offset_table_rtx,
3801 = gen_const_mem (Pmode,
3802 gen_rtx_PLUS (Pmode,
3803 pic_offset_table_rtx, address));
3804 insn = emit_move_insn (reg, pic_ref);
3807 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3809 set_unique_reg_note (insn, REG_EQUAL, orig);
3812 else if (GET_CODE (orig) == CONST)
3816 if (GET_CODE (XEXP (orig, 0)) == PLUS
3817 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3822 gcc_assert (can_create_pseudo_p ());
3823 reg = gen_reg_rtx (Pmode);
3826 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
3827 base = sparc_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), reg);
3828 offset = sparc_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
3829 base == reg ? NULL_RTX : reg);
3831 if (GET_CODE (offset) == CONST_INT)
3833 if (SMALL_INT (offset))
3834 return plus_constant (base, INTVAL (offset));
3835 else if (can_create_pseudo_p ())
3836 offset = force_reg (Pmode, offset);
3838 /* If we reach here, then something is seriously wrong. */
3841 return gen_rtx_PLUS (Pmode, base, offset);
3843 else if (GET_CODE (orig) == LABEL_REF)
3844 /* ??? We ought to be checking that the register is live instead, in case
3845 it is eliminated. */
3846 crtl->uses_pic_offset_table = 1;
3851 /* Try machine-dependent ways of modifying an illegitimate address X
3852 to be legitimate. If we find one, return the new, valid address.
3854 OLDX is the address as it was before break_out_memory_refs was called.
3855 In some cases it is useful to look at this to decide what needs to be done.
3857 MODE is the mode of the operand pointed to by X.
3859 On SPARC, change REG+N into REG+REG, and REG+(X*Y) into REG+REG. */
3862 sparc_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
3863 enum machine_mode mode)
3867 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT)
3868 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3869 force_operand (XEXP (x, 0), NULL_RTX));
3870 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == MULT)
3871 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3872 force_operand (XEXP (x, 1), NULL_RTX));
3873 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS)
3874 x = gen_rtx_PLUS (Pmode, force_operand (XEXP (x, 0), NULL_RTX),
3876 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == PLUS)
3877 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3878 force_operand (XEXP (x, 1), NULL_RTX));
3880 if (x != orig_x && sparc_legitimate_address_p (mode, x, FALSE))
3883 if (sparc_tls_referenced_p (x))
3884 x = sparc_legitimize_tls_address (x);
3886 x = sparc_legitimize_pic_address (x, NULL_RTX);
3887 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 1)))
3888 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3889 copy_to_mode_reg (Pmode, XEXP (x, 1)));
3890 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 0)))
3891 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3892 copy_to_mode_reg (Pmode, XEXP (x, 0)));
3893 else if (GET_CODE (x) == SYMBOL_REF
3894 || GET_CODE (x) == CONST
3895 || GET_CODE (x) == LABEL_REF)
3896 x = copy_to_suggested_reg (x, NULL_RTX, Pmode);
3901 /* Delegitimize an address that was legitimized by the above function. */
3904 sparc_delegitimize_address (rtx x)
3906 x = delegitimize_mem_from_attrs (x);
3908 if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 1)) == UNSPEC)
3909 switch (XINT (XEXP (x, 1), 1))
3911 case UNSPEC_MOVE_PIC:
3913 x = XVECEXP (XEXP (x, 1), 0, 0);
3914 gcc_assert (GET_CODE (x) == SYMBOL_REF);
3920 /* This is generated by mov{si,di}_pic_label_ref in PIC mode. */
3921 if (GET_CODE (x) == MINUS
3922 && REG_P (XEXP (x, 0))
3923 && REGNO (XEXP (x, 0)) == PIC_OFFSET_TABLE_REGNUM
3924 && GET_CODE (XEXP (x, 1)) == LO_SUM
3925 && GET_CODE (XEXP (XEXP (x, 1), 1)) == UNSPEC
3926 && XINT (XEXP (XEXP (x, 1), 1), 1) == UNSPEC_MOVE_PIC_LABEL)
3928 x = XVECEXP (XEXP (XEXP (x, 1), 1), 0, 0);
3929 gcc_assert (GET_CODE (x) == LABEL_REF);
3935 /* SPARC implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3936 replace the input X, or the original X if no replacement is called for.
3937 The output parameter *WIN is 1 if the calling macro should goto WIN,
3940 For SPARC, we wish to handle addresses by splitting them into
3941 HIGH+LO_SUM pairs, retaining the LO_SUM in the memory reference.
3942 This cuts the number of extra insns by one.
3944 Do nothing when generating PIC code and the address is a symbolic
3945 operand or requires a scratch register. */
3948 sparc_legitimize_reload_address (rtx x, enum machine_mode mode,
3949 int opnum, int type,
3950 int ind_levels ATTRIBUTE_UNUSED, int *win)
3952 /* Decompose SImode constants into HIGH+LO_SUM. */
3954 && (mode != TFmode || TARGET_ARCH64)
3955 && GET_MODE (x) == SImode
3956 && GET_CODE (x) != LO_SUM
3957 && GET_CODE (x) != HIGH
3958 && sparc_cmodel <= CM_MEDLOW
3960 && (symbolic_operand (x, Pmode) || pic_address_needs_scratch (x))))
3962 x = gen_rtx_LO_SUM (GET_MODE (x), gen_rtx_HIGH (GET_MODE (x), x), x);
3963 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3964 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3965 opnum, (enum reload_type)type);
3970 /* We have to recognize what we have already generated above. */
3971 if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == HIGH)
3973 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3974 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3975 opnum, (enum reload_type)type);
3984 /* Return true if ADDR (a legitimate address expression)
3985 has an effect that depends on the machine mode it is used for.
3991 is not equivalent to
3993 (mem:QI [%l7+a]) (mem:QI [%l7+a+1])
3995 because [%l7+a+1] is interpreted as the address of (a+1). */
3999 sparc_mode_dependent_address_p (const_rtx addr)
4001 if (flag_pic && GET_CODE (addr) == PLUS)
4003 rtx op0 = XEXP (addr, 0);
4004 rtx op1 = XEXP (addr, 1);
4005 if (op0 == pic_offset_table_rtx
4006 && symbolic_operand (op1, VOIDmode))
4013 #ifdef HAVE_GAS_HIDDEN
4014 # define USE_HIDDEN_LINKONCE 1
4016 # define USE_HIDDEN_LINKONCE 0
4020 get_pc_thunk_name (char name[32], unsigned int regno)
4022 const char *reg_name = reg_names[regno];
4024 /* Skip the leading '%' as that cannot be used in a
4028 if (USE_HIDDEN_LINKONCE)
4029 sprintf (name, "__sparc_get_pc_thunk.%s", reg_name);
4031 ASM_GENERATE_INTERNAL_LABEL (name, "LADDPC", regno);
4034 /* Wrapper around the load_pcrel_sym{si,di} patterns. */
4037 gen_load_pcrel_sym (rtx op0, rtx op1, rtx op2, rtx op3)
4039 int orig_flag_pic = flag_pic;
4042 /* The load_pcrel_sym{si,di} patterns require absolute addressing. */
4045 insn = gen_load_pcrel_symdi (op0,