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 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 64-bit SPARC-V9 support by Michael Tiemann, Jim Wilson, and Doug Evans,
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
27 #include "coretypes.h"
32 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
48 #include "target-def.h"
49 #include "cfglayout.h"
50 #include "tree-gimple.h"
54 struct processor_costs cypress_costs = {
55 COSTS_N_INSNS (2), /* int load */
56 COSTS_N_INSNS (2), /* int signed load */
57 COSTS_N_INSNS (2), /* int zeroed load */
58 COSTS_N_INSNS (2), /* float load */
59 COSTS_N_INSNS (5), /* fmov, fneg, fabs */
60 COSTS_N_INSNS (5), /* fadd, fsub */
61 COSTS_N_INSNS (1), /* fcmp */
62 COSTS_N_INSNS (1), /* fmov, fmovr */
63 COSTS_N_INSNS (7), /* fmul */
64 COSTS_N_INSNS (37), /* fdivs */
65 COSTS_N_INSNS (37), /* fdivd */
66 COSTS_N_INSNS (63), /* fsqrts */
67 COSTS_N_INSNS (63), /* fsqrtd */
68 COSTS_N_INSNS (1), /* imul */
69 COSTS_N_INSNS (1), /* imulX */
70 0, /* imul bit factor */
71 COSTS_N_INSNS (1), /* idiv */
72 COSTS_N_INSNS (1), /* idivX */
73 COSTS_N_INSNS (1), /* movcc/movr */
74 0, /* shift penalty */
78 struct processor_costs supersparc_costs = {
79 COSTS_N_INSNS (1), /* int load */
80 COSTS_N_INSNS (1), /* int signed load */
81 COSTS_N_INSNS (1), /* int zeroed load */
82 COSTS_N_INSNS (0), /* float load */
83 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
84 COSTS_N_INSNS (3), /* fadd, fsub */
85 COSTS_N_INSNS (3), /* fcmp */
86 COSTS_N_INSNS (1), /* fmov, fmovr */
87 COSTS_N_INSNS (3), /* fmul */
88 COSTS_N_INSNS (6), /* fdivs */
89 COSTS_N_INSNS (9), /* fdivd */
90 COSTS_N_INSNS (12), /* fsqrts */
91 COSTS_N_INSNS (12), /* fsqrtd */
92 COSTS_N_INSNS (4), /* imul */
93 COSTS_N_INSNS (4), /* imulX */
94 0, /* imul bit factor */
95 COSTS_N_INSNS (4), /* idiv */
96 COSTS_N_INSNS (4), /* idivX */
97 COSTS_N_INSNS (1), /* movcc/movr */
98 1, /* shift penalty */
102 struct processor_costs hypersparc_costs = {
103 COSTS_N_INSNS (1), /* int load */
104 COSTS_N_INSNS (1), /* int signed load */
105 COSTS_N_INSNS (1), /* int zeroed load */
106 COSTS_N_INSNS (1), /* float load */
107 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
108 COSTS_N_INSNS (1), /* fadd, fsub */
109 COSTS_N_INSNS (1), /* fcmp */
110 COSTS_N_INSNS (1), /* fmov, fmovr */
111 COSTS_N_INSNS (1), /* fmul */
112 COSTS_N_INSNS (8), /* fdivs */
113 COSTS_N_INSNS (12), /* fdivd */
114 COSTS_N_INSNS (17), /* fsqrts */
115 COSTS_N_INSNS (17), /* fsqrtd */
116 COSTS_N_INSNS (17), /* imul */
117 COSTS_N_INSNS (17), /* imulX */
118 0, /* imul bit factor */
119 COSTS_N_INSNS (17), /* idiv */
120 COSTS_N_INSNS (17), /* idivX */
121 COSTS_N_INSNS (1), /* movcc/movr */
122 0, /* shift penalty */
126 struct processor_costs sparclet_costs = {
127 COSTS_N_INSNS (3), /* int load */
128 COSTS_N_INSNS (3), /* int signed load */
129 COSTS_N_INSNS (1), /* int zeroed load */
130 COSTS_N_INSNS (1), /* float load */
131 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
132 COSTS_N_INSNS (1), /* fadd, fsub */
133 COSTS_N_INSNS (1), /* fcmp */
134 COSTS_N_INSNS (1), /* fmov, fmovr */
135 COSTS_N_INSNS (1), /* fmul */
136 COSTS_N_INSNS (1), /* fdivs */
137 COSTS_N_INSNS (1), /* fdivd */
138 COSTS_N_INSNS (1), /* fsqrts */
139 COSTS_N_INSNS (1), /* fsqrtd */
140 COSTS_N_INSNS (5), /* imul */
141 COSTS_N_INSNS (5), /* imulX */
142 0, /* imul bit factor */
143 COSTS_N_INSNS (5), /* idiv */
144 COSTS_N_INSNS (5), /* idivX */
145 COSTS_N_INSNS (1), /* movcc/movr */
146 0, /* shift penalty */
150 struct processor_costs ultrasparc_costs = {
151 COSTS_N_INSNS (2), /* int load */
152 COSTS_N_INSNS (3), /* int signed load */
153 COSTS_N_INSNS (2), /* int zeroed load */
154 COSTS_N_INSNS (2), /* float load */
155 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
156 COSTS_N_INSNS (4), /* fadd, fsub */
157 COSTS_N_INSNS (1), /* fcmp */
158 COSTS_N_INSNS (2), /* fmov, fmovr */
159 COSTS_N_INSNS (4), /* fmul */
160 COSTS_N_INSNS (13), /* fdivs */
161 COSTS_N_INSNS (23), /* fdivd */
162 COSTS_N_INSNS (13), /* fsqrts */
163 COSTS_N_INSNS (23), /* fsqrtd */
164 COSTS_N_INSNS (4), /* imul */
165 COSTS_N_INSNS (4), /* imulX */
166 2, /* imul bit factor */
167 COSTS_N_INSNS (37), /* idiv */
168 COSTS_N_INSNS (68), /* idivX */
169 COSTS_N_INSNS (2), /* movcc/movr */
170 2, /* shift penalty */
174 struct processor_costs ultrasparc3_costs = {
175 COSTS_N_INSNS (2), /* int load */
176 COSTS_N_INSNS (3), /* int signed load */
177 COSTS_N_INSNS (3), /* int zeroed load */
178 COSTS_N_INSNS (2), /* float load */
179 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
180 COSTS_N_INSNS (4), /* fadd, fsub */
181 COSTS_N_INSNS (5), /* fcmp */
182 COSTS_N_INSNS (3), /* fmov, fmovr */
183 COSTS_N_INSNS (4), /* fmul */
184 COSTS_N_INSNS (17), /* fdivs */
185 COSTS_N_INSNS (20), /* fdivd */
186 COSTS_N_INSNS (20), /* fsqrts */
187 COSTS_N_INSNS (29), /* fsqrtd */
188 COSTS_N_INSNS (6), /* imul */
189 COSTS_N_INSNS (6), /* imulX */
190 0, /* imul bit factor */
191 COSTS_N_INSNS (40), /* idiv */
192 COSTS_N_INSNS (71), /* idivX */
193 COSTS_N_INSNS (2), /* movcc/movr */
194 0, /* shift penalty */
197 const struct processor_costs *sparc_costs = &cypress_costs;
199 #ifdef HAVE_AS_RELAX_OPTION
200 /* If 'as' and 'ld' are relaxing tail call insns into branch always, use
201 "or %o7,%g0,X; call Y; or X,%g0,%o7" always, so that it can be optimized.
202 With sethi/jmp, neither 'as' nor 'ld' has an easy way how to find out if
203 somebody does not branch between the sethi and jmp. */
204 #define LEAF_SIBCALL_SLOT_RESERVED_P 1
206 #define LEAF_SIBCALL_SLOT_RESERVED_P \
207 ((TARGET_ARCH64 && !TARGET_CM_MEDLOW) || flag_pic)
210 /* Global variables for machine-dependent things. */
212 /* Size of frame. Need to know this to emit return insns from leaf procedures.
213 ACTUAL_FSIZE is set by sparc_compute_frame_size() which is called during the
214 reload pass. This is important as the value is later used for scheduling
215 (to see what can go in a delay slot).
216 APPARENT_FSIZE is the size of the stack less the register save area and less
217 the outgoing argument area. It is used when saving call preserved regs. */
218 static HOST_WIDE_INT apparent_fsize;
219 static HOST_WIDE_INT actual_fsize;
221 /* Number of live general or floating point registers needed to be
222 saved (as 4-byte quantities). */
223 static int num_gfregs;
225 /* The alias set for prologue/epilogue register save/restore. */
226 static GTY(()) int sparc_sr_alias_set;
228 /* Save the operands last given to a compare for use when we
229 generate a scc or bcc insn. */
230 rtx sparc_compare_op0, sparc_compare_op1;
232 /* Vector to say how input registers are mapped to output registers.
233 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
234 eliminate it. You must use -fomit-frame-pointer to get that. */
235 char leaf_reg_remap[] =
236 { 0, 1, 2, 3, 4, 5, 6, 7,
237 -1, -1, -1, -1, -1, -1, 14, -1,
238 -1, -1, -1, -1, -1, -1, -1, -1,
239 8, 9, 10, 11, 12, 13, -1, 15,
241 32, 33, 34, 35, 36, 37, 38, 39,
242 40, 41, 42, 43, 44, 45, 46, 47,
243 48, 49, 50, 51, 52, 53, 54, 55,
244 56, 57, 58, 59, 60, 61, 62, 63,
245 64, 65, 66, 67, 68, 69, 70, 71,
246 72, 73, 74, 75, 76, 77, 78, 79,
247 80, 81, 82, 83, 84, 85, 86, 87,
248 88, 89, 90, 91, 92, 93, 94, 95,
249 96, 97, 98, 99, 100};
251 /* Vector, indexed by hard register number, which contains 1
252 for a register that is allowable in a candidate for leaf
253 function treatment. */
254 char sparc_leaf_regs[] =
255 { 1, 1, 1, 1, 1, 1, 1, 1,
256 0, 0, 0, 0, 0, 0, 1, 0,
257 0, 0, 0, 0, 0, 0, 0, 0,
258 1, 1, 1, 1, 1, 1, 0, 1,
259 1, 1, 1, 1, 1, 1, 1, 1,
260 1, 1, 1, 1, 1, 1, 1, 1,
261 1, 1, 1, 1, 1, 1, 1, 1,
262 1, 1, 1, 1, 1, 1, 1, 1,
263 1, 1, 1, 1, 1, 1, 1, 1,
264 1, 1, 1, 1, 1, 1, 1, 1,
265 1, 1, 1, 1, 1, 1, 1, 1,
266 1, 1, 1, 1, 1, 1, 1, 1,
269 struct machine_function GTY(())
271 /* Some local-dynamic TLS symbol name. */
272 const char *some_ld_name;
274 /* True if the current function is leaf and uses only leaf regs,
275 so that the SPARC leaf function optimization can be applied.
276 Private version of current_function_uses_only_leaf_regs, see
277 sparc_expand_prologue for the rationale. */
280 /* True if the data calculated by sparc_expand_prologue are valid. */
281 bool prologue_data_valid_p;
284 #define sparc_leaf_function_p cfun->machine->leaf_function_p
285 #define sparc_prologue_data_valid_p cfun->machine->prologue_data_valid_p
287 /* Register we pretend to think the frame pointer is allocated to.
288 Normally, this is %fp, but if we are in a leaf procedure, this
289 is %sp+"something". We record "something" separately as it may
290 be too big for reg+constant addressing. */
291 static rtx frame_base_reg;
292 static HOST_WIDE_INT frame_base_offset;
294 /* 1 if the next opcode is to be specially indented. */
295 int sparc_indent_opcode = 0;
297 static void sparc_init_modes (void);
298 static void scan_record_type (tree, int *, int *, int *);
299 static int function_arg_slotno (const CUMULATIVE_ARGS *, enum machine_mode,
300 tree, int, int, int *, int *);
302 static int supersparc_adjust_cost (rtx, rtx, rtx, int);
303 static int hypersparc_adjust_cost (rtx, rtx, rtx, int);
305 static void sparc_output_addr_vec (rtx);
306 static void sparc_output_addr_diff_vec (rtx);
307 static void sparc_output_deferred_case_vectors (void);
308 static rtx sparc_builtin_saveregs (void);
309 static int epilogue_renumber (rtx *, int);
310 static bool sparc_assemble_integer (rtx, unsigned int, int);
311 static int set_extends (rtx);
312 static void load_pic_register (void);
313 static int save_or_restore_regs (int, int, rtx, int, int);
314 static void emit_save_regs (void);
315 static void emit_restore_regs (void);
316 static void sparc_asm_function_prologue (FILE *, HOST_WIDE_INT);
317 static void sparc_asm_function_epilogue (FILE *, HOST_WIDE_INT);
318 #ifdef OBJECT_FORMAT_ELF
319 static void sparc_elf_asm_named_section (const char *, unsigned int, tree);
322 static int sparc_adjust_cost (rtx, rtx, rtx, int);
323 static int sparc_issue_rate (void);
324 static void sparc_sched_init (FILE *, int, int);
325 static int sparc_use_sched_lookahead (void);
327 static void emit_soft_tfmode_libcall (const char *, int, rtx *);
328 static void emit_soft_tfmode_binop (enum rtx_code, rtx *);
329 static void emit_soft_tfmode_unop (enum rtx_code, rtx *);
330 static void emit_soft_tfmode_cvt (enum rtx_code, rtx *);
331 static void emit_hard_tfmode_operation (enum rtx_code, rtx *);
333 static bool sparc_function_ok_for_sibcall (tree, tree);
334 static void sparc_init_libfuncs (void);
335 static void sparc_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
336 HOST_WIDE_INT, tree);
337 static struct machine_function * sparc_init_machine_status (void);
338 static bool sparc_cannot_force_const_mem (rtx);
339 static rtx sparc_tls_get_addr (void);
340 static rtx sparc_tls_got (void);
341 static const char *get_some_local_dynamic_name (void);
342 static int get_some_local_dynamic_name_1 (rtx *, void *);
343 static bool sparc_rtx_costs (rtx, int, int, int *);
344 static bool sparc_promote_prototypes (tree);
345 static rtx sparc_struct_value_rtx (tree, int);
346 static bool sparc_return_in_memory (tree, tree);
347 static bool sparc_strict_argument_naming (CUMULATIVE_ARGS *);
348 static tree sparc_gimplify_va_arg (tree, tree, tree *, tree *);
349 static bool sparc_pass_by_reference (CUMULATIVE_ARGS *,
350 enum machine_mode, tree, bool);
351 #ifdef SUBTARGET_ATTRIBUTE_TABLE
352 const struct attribute_spec sparc_attribute_table[];
355 /* Option handling. */
357 /* Code model option as passed by user. */
358 const char *sparc_cmodel_string;
360 enum cmodel sparc_cmodel;
362 char sparc_hard_reg_printed[8];
364 struct sparc_cpu_select sparc_select[] =
366 /* switch name, tune arch */
367 { (char *)0, "default", 1, 1 },
368 { (char *)0, "-mcpu=", 1, 1 },
369 { (char *)0, "-mtune=", 1, 0 },
373 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
374 enum processor_type sparc_cpu;
376 /* Initialize the GCC target structure. */
378 /* The sparc default is to use .half rather than .short for aligned
379 HI objects. Use .word instead of .long on non-ELF systems. */
380 #undef TARGET_ASM_ALIGNED_HI_OP
381 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
382 #ifndef OBJECT_FORMAT_ELF
383 #undef TARGET_ASM_ALIGNED_SI_OP
384 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
387 #undef TARGET_ASM_UNALIGNED_HI_OP
388 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
389 #undef TARGET_ASM_UNALIGNED_SI_OP
390 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
391 #undef TARGET_ASM_UNALIGNED_DI_OP
392 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
394 /* The target hook has to handle DI-mode values. */
395 #undef TARGET_ASM_INTEGER
396 #define TARGET_ASM_INTEGER sparc_assemble_integer
398 #undef TARGET_ASM_FUNCTION_PROLOGUE
399 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
400 #undef TARGET_ASM_FUNCTION_EPILOGUE
401 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
403 #undef TARGET_SCHED_ADJUST_COST
404 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
405 #undef TARGET_SCHED_ISSUE_RATE
406 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
407 #undef TARGET_SCHED_INIT
408 #define TARGET_SCHED_INIT sparc_sched_init
409 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
410 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
412 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
413 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
415 #undef TARGET_INIT_LIBFUNCS
416 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
419 #undef TARGET_HAVE_TLS
420 #define TARGET_HAVE_TLS true
422 #undef TARGET_CANNOT_FORCE_CONST_MEM
423 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
425 #undef TARGET_ASM_OUTPUT_MI_THUNK
426 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
427 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
428 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
430 #undef TARGET_RTX_COSTS
431 #define TARGET_RTX_COSTS sparc_rtx_costs
432 #undef TARGET_ADDRESS_COST
433 #define TARGET_ADDRESS_COST hook_int_rtx_0
435 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
436 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
437 test for this value. */
438 #undef TARGET_PROMOTE_FUNCTION_ARGS
439 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
441 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
442 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
443 test for this value. */
444 #undef TARGET_PROMOTE_FUNCTION_RETURN
445 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
447 #undef TARGET_PROMOTE_PROTOTYPES
448 #define TARGET_PROMOTE_PROTOTYPES sparc_promote_prototypes
450 #undef TARGET_STRUCT_VALUE_RTX
451 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
452 #undef TARGET_RETURN_IN_MEMORY
453 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
454 #undef TARGET_MUST_PASS_IN_STACK
455 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
456 #undef TARGET_PASS_BY_REFERENCE
457 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
459 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
460 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
461 #undef TARGET_STRICT_ARGUMENT_NAMING
462 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
464 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
465 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
467 #ifdef SUBTARGET_INSERT_ATTRIBUTES
468 #undef TARGET_INSERT_ATTRIBUTES
469 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
472 #ifdef SUBTARGET_ATTRIBUTE_TABLE
473 #undef TARGET_ATTRIBUTE_TABLE
474 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
477 struct gcc_target targetm = TARGET_INITIALIZER;
479 /* Validate and override various options, and do some machine dependent
483 sparc_override_options (void)
485 static struct code_model {
486 const char *const name;
488 } const cmodels[] = {
490 { "medlow", CM_MEDLOW },
491 { "medmid", CM_MEDMID },
492 { "medany", CM_MEDANY },
493 { "embmedany", CM_EMBMEDANY },
496 const struct code_model *cmodel;
497 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
498 static struct cpu_default {
500 const char *const name;
501 } const cpu_default[] = {
502 /* There must be one entry here for each TARGET_CPU value. */
503 { TARGET_CPU_sparc, "cypress" },
504 { TARGET_CPU_sparclet, "tsc701" },
505 { TARGET_CPU_sparclite, "f930" },
506 { TARGET_CPU_v8, "v8" },
507 { TARGET_CPU_hypersparc, "hypersparc" },
508 { TARGET_CPU_sparclite86x, "sparclite86x" },
509 { TARGET_CPU_supersparc, "supersparc" },
510 { TARGET_CPU_v9, "v9" },
511 { TARGET_CPU_ultrasparc, "ultrasparc" },
512 { TARGET_CPU_ultrasparc3, "ultrasparc3" },
515 const struct cpu_default *def;
516 /* Table of values for -m{cpu,tune}=. */
517 static struct cpu_table {
518 const char *const name;
519 const enum processor_type processor;
522 } const cpu_table[] = {
523 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
524 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
525 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
526 /* TI TMS390Z55 supersparc */
527 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
528 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
529 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
530 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
531 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
532 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
533 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
534 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
536 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
538 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
539 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
540 /* TI ultrasparc I, II, IIi */
541 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
542 /* Although insns using %y are deprecated, it is a clear win on current
544 |MASK_DEPRECATED_V8_INSNS},
545 /* TI ultrasparc III */
546 /* ??? Check if %y issue still holds true in ultra3. */
547 { "ultrasparc3", PROCESSOR_ULTRASPARC3, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
550 const struct cpu_table *cpu;
551 const struct sparc_cpu_select *sel;
554 #ifndef SPARC_BI_ARCH
555 /* Check for unsupported architecture size. */
556 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
557 error ("%s is not supported by this configuration",
558 DEFAULT_ARCH32_P ? "-m64" : "-m32");
561 /* We force all 64bit archs to use 128 bit long double */
562 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
564 error ("-mlong-double-64 not allowed with -m64");
565 target_flags |= MASK_LONG_DOUBLE_128;
568 /* Code model selection. */
569 sparc_cmodel = SPARC_DEFAULT_CMODEL;
573 sparc_cmodel = CM_32;
576 if (sparc_cmodel_string != NULL)
580 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
581 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
583 if (cmodel->name == NULL)
584 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
586 sparc_cmodel = cmodel->value;
589 error ("-mcmodel= is not supported on 32 bit systems");
592 fpu = TARGET_FPU; /* save current -mfpu status */
594 /* Set the default CPU. */
595 for (def = &cpu_default[0]; def->name; ++def)
596 if (def->cpu == TARGET_CPU_DEFAULT)
600 sparc_select[0].string = def->name;
602 for (sel = &sparc_select[0]; sel->name; ++sel)
606 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
607 if (! strcmp (sel->string, cpu->name))
610 sparc_cpu = cpu->processor;
614 target_flags &= ~cpu->disable;
615 target_flags |= cpu->enable;
621 error ("bad value (%s) for %s switch", sel->string, sel->name);
625 /* If -mfpu or -mno-fpu was explicitly used, don't override with
626 the processor default. Clear MASK_FPU_SET to avoid confusing
627 the reverse mapping from switch values to names. */
630 target_flags = (target_flags & ~MASK_FPU) | fpu;
631 target_flags &= ~MASK_FPU_SET;
634 /* Don't allow -mvis if FPU is disabled. */
636 target_flags &= ~MASK_VIS;
638 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
640 -m64 also implies v9. */
641 if (TARGET_VIS || TARGET_ARCH64)
643 target_flags |= MASK_V9;
644 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
647 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
648 if (TARGET_V9 && TARGET_ARCH32)
649 target_flags |= MASK_DEPRECATED_V8_INSNS;
651 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
652 if (! TARGET_V9 || TARGET_ARCH64)
653 target_flags &= ~MASK_V8PLUS;
655 /* Don't use stack biasing in 32 bit mode. */
657 target_flags &= ~MASK_STACK_BIAS;
659 /* Supply a default value for align_functions. */
660 if (align_functions == 0
661 && (sparc_cpu == PROCESSOR_ULTRASPARC
662 || sparc_cpu == PROCESSOR_ULTRASPARC3))
663 align_functions = 32;
665 /* Validate PCC_STRUCT_RETURN. */
666 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
667 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
669 /* Only use .uaxword when compiling for a 64-bit target. */
671 targetm.asm_out.unaligned_op.di = NULL;
673 /* Do various machine dependent initializations. */
676 /* Acquire a unique set number for our register saves and restores. */
677 sparc_sr_alias_set = new_alias_set ();
679 /* Set up function hooks. */
680 init_machine_status = sparc_init_machine_status;
685 case PROCESSOR_CYPRESS:
686 sparc_costs = &cypress_costs;
689 case PROCESSOR_SPARCLITE:
690 case PROCESSOR_SUPERSPARC:
691 sparc_costs = &supersparc_costs;
695 case PROCESSOR_HYPERSPARC:
696 case PROCESSOR_SPARCLITE86X:
697 sparc_costs = &hypersparc_costs;
699 case PROCESSOR_SPARCLET:
700 case PROCESSOR_TSC701:
701 sparc_costs = &sparclet_costs;
704 case PROCESSOR_ULTRASPARC:
705 sparc_costs = &ultrasparc_costs;
707 case PROCESSOR_ULTRASPARC3:
708 sparc_costs = &ultrasparc3_costs;
713 #ifdef SUBTARGET_ATTRIBUTE_TABLE
714 /* Table of valid machine attributes. */
715 const struct attribute_spec sparc_attribute_table[] =
717 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
718 SUBTARGET_ATTRIBUTE_TABLE,
719 { NULL, 0, 0, false, false, false, NULL }
723 /* Miscellaneous utilities. */
725 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
726 or branch on register contents instructions. */
729 v9_regcmp_p (enum rtx_code code)
731 return (code == EQ || code == NE || code == GE || code == LT
732 || code == LE || code == GT);
736 /* Operand constraints. */
738 /* Return nonzero only if OP is a register of mode MODE,
742 reg_or_0_operand (rtx op, enum machine_mode mode)
744 if (register_operand (op, mode))
746 if (op == const0_rtx)
748 if (GET_MODE (op) == VOIDmode && GET_CODE (op) == CONST_DOUBLE
749 && CONST_DOUBLE_HIGH (op) == 0
750 && CONST_DOUBLE_LOW (op) == 0)
752 if (fp_zero_operand (op, mode))
757 /* Return nonzero only if OP is const1_rtx. */
760 const1_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
762 return op == const1_rtx;
765 /* Nonzero if OP is a floating point value with value 0.0. */
768 fp_zero_operand (rtx op, enum machine_mode mode)
770 if (GET_MODE_CLASS (GET_MODE (op)) != MODE_FLOAT)
772 return op == CONST0_RTX (mode);
775 /* Nonzero if OP is a register operand in floating point register. */
778 fp_register_operand (rtx op, enum machine_mode mode)
780 if (! register_operand (op, mode))
782 if (GET_CODE (op) == SUBREG)
783 op = SUBREG_REG (op);
784 return GET_CODE (op) == REG && SPARC_FP_REG_P (REGNO (op));
787 /* Nonzero if OP is a floating point constant which can
788 be loaded into an integer register using a single
789 sethi instruction. */
794 if (GET_CODE (op) == CONST_DOUBLE)
799 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
800 if (REAL_VALUES_EQUAL (r, dconst0) &&
801 ! REAL_VALUE_MINUS_ZERO (r))
803 REAL_VALUE_TO_TARGET_SINGLE (r, i);
804 if (SPARC_SETHI_P (i))
811 /* Nonzero if OP is a floating point constant which can
812 be loaded into an integer register using a single
818 if (GET_CODE (op) == CONST_DOUBLE)
823 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
824 if (REAL_VALUES_EQUAL (r, dconst0) &&
825 ! REAL_VALUE_MINUS_ZERO (r))
827 REAL_VALUE_TO_TARGET_SINGLE (r, i);
828 if (SPARC_SIMM13_P (i))
835 /* Nonzero if OP is a floating point constant which can
836 be loaded into an integer register using a high/losum
837 instruction sequence. */
840 fp_high_losum_p (rtx op)
842 /* The constraints calling this should only be in
843 SFmode move insns, so any constant which cannot
844 be moved using a single insn will do. */
845 if (GET_CODE (op) == CONST_DOUBLE)
850 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
851 if (REAL_VALUES_EQUAL (r, dconst0) &&
852 ! REAL_VALUE_MINUS_ZERO (r))
854 REAL_VALUE_TO_TARGET_SINGLE (r, i);
855 if (! SPARC_SETHI_P (i)
856 && ! SPARC_SIMM13_P (i))
863 /* Nonzero if OP is an integer register. */
866 intreg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
868 return (register_operand (op, SImode)
869 || (TARGET_ARCH64 && register_operand (op, DImode)));
872 /* Nonzero if OP is a floating point condition code register. */
875 fcc_reg_operand (rtx op, enum machine_mode mode)
877 /* This can happen when recog is called from combine. Op may be a MEM.
878 Fail instead of calling abort in this case. */
879 if (GET_CODE (op) != REG)
882 if (mode != VOIDmode && mode != GET_MODE (op))
885 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
888 #if 0 /* ??? ==> 1 when %fcc0-3 are pseudos first. See gen_compare_reg(). */
889 if (reg_renumber == 0)
890 return REGNO (op) >= FIRST_PSEUDO_REGISTER;
891 return REGNO_OK_FOR_CCFP_P (REGNO (op));
893 return (unsigned) REGNO (op) - SPARC_FIRST_V9_FCC_REG < 4;
897 /* Nonzero if OP is a floating point condition code fcc0 register. */
900 fcc0_reg_operand (rtx op, enum machine_mode mode)
902 /* This can happen when recog is called from combine. Op may be a MEM.
903 Fail instead of calling abort in this case. */
904 if (GET_CODE (op) != REG)
907 if (mode != VOIDmode && mode != GET_MODE (op))
910 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
913 return REGNO (op) == SPARC_FCC_REG;
916 /* Nonzero if OP is an integer or floating point condition code register. */
919 icc_or_fcc_reg_operand (rtx op, enum machine_mode mode)
921 if (GET_CODE (op) == REG && REGNO (op) == SPARC_ICC_REG)
923 if (mode != VOIDmode && mode != GET_MODE (op))
926 && GET_MODE (op) != CCmode && GET_MODE (op) != CCXmode)
931 return fcc_reg_operand (op, mode);
934 /* Call insn on SPARC can take a PC-relative constant address, or any regular
938 call_operand (rtx op, enum machine_mode mode)
940 if (GET_CODE (op) != MEM)
943 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
947 call_operand_address (rtx op, enum machine_mode mode)
949 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
952 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
953 otherwise return 0. */
956 tls_symbolic_operand (rtx op)
958 if (GET_CODE (op) != SYMBOL_REF)
960 return SYMBOL_REF_TLS_MODEL (op);
964 tgd_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
966 return tls_symbolic_operand (op) == TLS_MODEL_GLOBAL_DYNAMIC;
970 tld_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
972 return tls_symbolic_operand (op) == TLS_MODEL_LOCAL_DYNAMIC;
976 tie_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
978 return tls_symbolic_operand (op) == TLS_MODEL_INITIAL_EXEC;
982 tle_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
984 return tls_symbolic_operand (op) == TLS_MODEL_LOCAL_EXEC;
987 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
988 reference and a constant. */
991 symbolic_operand (register rtx op, enum machine_mode mode)
993 enum machine_mode omode = GET_MODE (op);
995 if (omode != mode && omode != VOIDmode && mode != VOIDmode)
998 switch (GET_CODE (op))
1001 return !SYMBOL_REF_TLS_MODEL (op);
1008 return (((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
1009 && !SYMBOL_REF_TLS_MODEL (XEXP (op, 0)))
1010 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
1011 && GET_CODE (XEXP (op, 1)) == CONST_INT);
1018 /* Return truth value of statement that OP is a symbolic memory
1019 operand of mode MODE. */
1022 symbolic_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1024 if (GET_CODE (op) == SUBREG)
1025 op = SUBREG_REG (op);
1026 if (GET_CODE (op) != MEM)
1029 return ((GET_CODE (op) == SYMBOL_REF && !SYMBOL_REF_TLS_MODEL (op))
1030 || GET_CODE (op) == CONST || GET_CODE (op) == HIGH
1031 || GET_CODE (op) == LABEL_REF);
1034 /* Return truth value of statement that OP is a LABEL_REF of mode MODE. */
1037 label_ref_operand (rtx op, enum machine_mode mode)
1039 if (GET_CODE (op) != LABEL_REF)
1041 if (GET_MODE (op) != mode)
1046 /* Return 1 if the operand is an argument used in generating pic references
1047 in either the medium/low or medium/anywhere code models of sparc64. */
1050 sp64_medium_pic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1052 /* Check for (const (minus (symbol_ref:GOT)
1053 (const (minus (label) (pc))))). */
1054 if (GET_CODE (op) != CONST)
1057 if (GET_CODE (op) != MINUS)
1059 if (GET_CODE (XEXP (op, 0)) != SYMBOL_REF)
1061 /* ??? Ensure symbol is GOT. */
1062 if (GET_CODE (XEXP (op, 1)) != CONST)
1064 if (GET_CODE (XEXP (XEXP (op, 1), 0)) != MINUS)
1069 /* Return 1 if the operand is a data segment reference. This includes
1070 the readonly data segment, or in other words anything but the text segment.
1071 This is needed in the medium/anywhere code model on v9. These values
1072 are accessed with EMBMEDANY_BASE_REG. */
1075 data_segment_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1077 switch (GET_CODE (op))
1080 return ! SYMBOL_REF_FUNCTION_P (op);
1082 /* Assume canonical format of symbol + constant.
1085 return data_segment_operand (XEXP (op, 0), VOIDmode);
1091 /* Return 1 if the operand is a text segment reference.
1092 This is needed in the medium/anywhere code model on v9. */
1095 text_segment_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1097 switch (GET_CODE (op))
1102 return SYMBOL_REF_FUNCTION_P (op);
1104 /* Assume canonical format of symbol + constant.
1107 return text_segment_operand (XEXP (op, 0), VOIDmode);
1113 /* Return 1 if the operand is either a register or a memory operand that is
1117 reg_or_nonsymb_mem_operand (register rtx op, enum machine_mode mode)
1119 if (register_operand (op, mode))
1122 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
1129 splittable_symbolic_memory_operand (rtx op,
1130 enum machine_mode mode ATTRIBUTE_UNUSED)
1132 if (GET_CODE (op) != MEM)
1134 if (! symbolic_operand (XEXP (op, 0), Pmode))
1140 splittable_immediate_memory_operand (rtx op,
1141 enum machine_mode mode ATTRIBUTE_UNUSED)
1143 if (GET_CODE (op) != MEM)
1145 if (! immediate_operand (XEXP (op, 0), Pmode))
1150 /* Return truth value of whether OP is EQ or NE. */
1153 eq_or_neq (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1155 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
1158 /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
1159 or LTU for non-floating-point. We handle those specially. */
1162 normal_comp_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1166 if (!COMPARISON_P (op))
1169 if (GET_MODE (XEXP (op, 0)) == CCFPmode
1170 || GET_MODE (XEXP (op, 0)) == CCFPEmode)
1173 code = GET_CODE (op);
1174 return (code != NE && code != EQ && code != GEU && code != LTU);
1177 /* Return 1 if this is a comparison operator. This allows the use of
1178 MATCH_OPERATOR to recognize all the branch insns. */
1181 noov_compare_op (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1185 if (!COMPARISON_P (op))
1188 code = GET_CODE (op);
1189 if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode
1190 || GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
1191 /* These are the only branches which work with CC_NOOVmode. */
1192 return (code == EQ || code == NE || code == GE || code == LT);
1196 /* Return 1 if this is a 64-bit comparison operator. This allows the use of
1197 MATCH_OPERATOR to recognize all the branch insns. */
1200 noov_compare64_op (register rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1207 if (!COMPARISON_P (op))
1210 code = GET_CODE (op);
1211 if (GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
1212 /* These are the only branches which work with CCX_NOOVmode. */
1213 return (code == EQ || code == NE || code == GE || code == LT);
1214 return (GET_MODE (XEXP (op, 0)) == CCXmode);
1217 /* Nonzero if OP is a comparison operator suitable for use in v9
1218 conditional move or branch on register contents instructions. */
1221 v9_regcmp_op (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1225 if (!COMPARISON_P (op))
1228 code = GET_CODE (op);
1229 return v9_regcmp_p (code);
1232 /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */
1235 extend_op (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1237 return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
1240 /* Return nonzero if OP is an operator of mode MODE which can set
1241 the condition codes explicitly. We do not include PLUS and MINUS
1242 because these require CC_NOOVmode, which we handle explicitly. */
1245 cc_arithop (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1247 if (GET_CODE (op) == AND
1248 || GET_CODE (op) == IOR
1249 || GET_CODE (op) == XOR)
1255 /* Return nonzero if OP is an operator of mode MODE which can bitwise
1256 complement its second operand and set the condition codes explicitly. */
1259 cc_arithopn (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1261 /* XOR is not here because combine canonicalizes (xor (not ...) ...)
1262 and (xor ... (not ...)) to (not (xor ...)). */
1263 return (GET_CODE (op) == AND
1264 || GET_CODE (op) == IOR);
1267 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1268 signed 13 bit immediate field. This is an acceptable SImode operand for
1269 most 3 address instructions. */
1272 arith_operand (rtx op, enum machine_mode mode)
1274 if (register_operand (op, mode))
1276 if (GET_CODE (op) != CONST_INT)
1278 return SMALL_INT32 (op);
1281 /* Return true if OP is a constant 4096 */
1284 arith_4096_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1286 if (GET_CODE (op) != CONST_INT)
1289 return INTVAL (op) == 4096;
1292 /* Return true if OP is suitable as second operand for add/sub */
1295 arith_add_operand (rtx op, enum machine_mode mode)
1297 return arith_operand (op, mode) || arith_4096_operand (op, mode);
1300 /* Return true if OP is a CONST_INT or a CONST_DOUBLE which can fit in the
1301 immediate field of OR and XOR instructions. Used for 64-bit
1302 constant formation patterns. */
1304 const64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1306 return ((GET_CODE (op) == CONST_INT
1307 && SPARC_SIMM13_P (INTVAL (op)))
1308 #if HOST_BITS_PER_WIDE_INT != 64
1309 || (GET_CODE (op) == CONST_DOUBLE
1310 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1311 && (CONST_DOUBLE_HIGH (op) ==
1312 ((CONST_DOUBLE_LOW (op) & 0x80000000) != 0 ?
1313 (HOST_WIDE_INT)-1 : 0)))
1318 /* The same, but only for sethi instructions. */
1320 const64_high_operand (rtx op, enum machine_mode mode)
1322 return ((GET_CODE (op) == CONST_INT
1323 && (INTVAL (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1324 && SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1326 || (GET_CODE (op) == CONST_DOUBLE
1327 && CONST_DOUBLE_HIGH (op) == 0
1328 && (CONST_DOUBLE_LOW (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1329 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op))));
1332 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1333 signed 11 bit immediate field. This is an acceptable SImode operand for
1334 the movcc instructions. */
1337 arith11_operand (rtx op, enum machine_mode mode)
1339 return (register_operand (op, mode)
1340 || (GET_CODE (op) == CONST_INT && SPARC_SIMM11_P (INTVAL (op))));
1343 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1344 signed 10 bit immediate field. This is an acceptable SImode operand for
1345 the movrcc instructions. */
1348 arith10_operand (rtx op, enum machine_mode mode)
1350 return (register_operand (op, mode)
1351 || (GET_CODE (op) == CONST_INT && SPARC_SIMM10_P (INTVAL (op))));
1354 /* Return true if OP is a register, is a CONST_INT that fits in a 13 bit
1355 immediate field, or is a CONST_DOUBLE whose both parts fit in a 13 bit
1357 ARCH64: Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1358 can fit in a 13 bit immediate field. This is an acceptable DImode operand
1359 for most 3 address instructions. */
1362 arith_double_operand (rtx op, enum machine_mode mode)
1364 return (register_operand (op, mode)
1365 || (GET_CODE (op) == CONST_INT && SMALL_INT (op))
1367 && GET_CODE (op) == CONST_DOUBLE
1368 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1369 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_HIGH (op) + 0x1000) < 0x2000)
1371 && GET_CODE (op) == CONST_DOUBLE
1372 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1373 && ((CONST_DOUBLE_HIGH (op) == -1
1374 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
1375 || (CONST_DOUBLE_HIGH (op) == 0
1376 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
1379 /* Return true if OP is a constant 4096 for DImode on ARCH64 */
1382 arith_double_4096_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1384 return (TARGET_ARCH64 &&
1385 ((GET_CODE (op) == CONST_INT && INTVAL (op) == 4096) ||
1386 (GET_CODE (op) == CONST_DOUBLE &&
1387 CONST_DOUBLE_LOW (op) == 4096 &&
1388 CONST_DOUBLE_HIGH (op) == 0)));
1391 /* Return true if OP is suitable as second operand for add/sub in DImode */
1394 arith_double_add_operand (rtx op, enum machine_mode mode)
1396 return arith_double_operand (op, mode) || arith_double_4096_operand (op, mode);
1399 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1400 can fit in an 11 bit immediate field. This is an acceptable DImode
1401 operand for the movcc instructions. */
1402 /* ??? Replace with arith11_operand? */
1405 arith11_double_operand (rtx op, enum machine_mode mode)
1407 return (register_operand (op, mode)
1408 || (GET_CODE (op) == CONST_DOUBLE
1409 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1410 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x400) < 0x800
1411 && ((CONST_DOUBLE_HIGH (op) == -1
1412 && (CONST_DOUBLE_LOW (op) & 0x400) == 0x400)
1413 || (CONST_DOUBLE_HIGH (op) == 0
1414 && (CONST_DOUBLE_LOW (op) & 0x400) == 0)))
1415 || (GET_CODE (op) == CONST_INT
1416 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1417 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x400) < 0x800));
1420 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1421 can fit in an 10 bit immediate field. This is an acceptable DImode
1422 operand for the movrcc instructions. */
1423 /* ??? Replace with arith10_operand? */
1426 arith10_double_operand (rtx op, enum machine_mode mode)
1428 return (register_operand (op, mode)
1429 || (GET_CODE (op) == CONST_DOUBLE
1430 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1431 && (unsigned) (CONST_DOUBLE_LOW (op) + 0x200) < 0x400
1432 && ((CONST_DOUBLE_HIGH (op) == -1
1433 && (CONST_DOUBLE_LOW (op) & 0x200) == 0x200)
1434 || (CONST_DOUBLE_HIGH (op) == 0
1435 && (CONST_DOUBLE_LOW (op) & 0x200) == 0)))
1436 || (GET_CODE (op) == CONST_INT
1437 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1438 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x200) < 0x400));
1441 /* Return truth value of whether OP is an integer which fits the
1442 range constraining immediate operands in most three-address insns,
1443 which have a 13 bit immediate field. */
1446 small_int (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1448 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
1452 small_int_or_double (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1454 return ((GET_CODE (op) == CONST_INT && SMALL_INT (op))
1455 || (GET_CODE (op) == CONST_DOUBLE
1456 && CONST_DOUBLE_HIGH (op) == 0
1457 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))));
1460 /* Recognize operand values for the umul instruction. That instruction sign
1461 extends immediate values just like all other sparc instructions, but
1462 interprets the extended result as an unsigned number. */
1465 uns_small_int (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1467 #if HOST_BITS_PER_WIDE_INT > 32
1468 /* All allowed constants will fit a CONST_INT. */
1469 return (GET_CODE (op) == CONST_INT
1470 && ((INTVAL (op) >= 0 && INTVAL (op) < 0x1000)
1471 || (INTVAL (op) >= 0xFFFFF000
1472 && INTVAL (op) <= 0xFFFFFFFF)));
1474 return ((GET_CODE (op) == CONST_INT && (unsigned) INTVAL (op) < 0x1000)
1475 || (GET_CODE (op) == CONST_DOUBLE
1476 && CONST_DOUBLE_HIGH (op) == 0
1477 && (unsigned) CONST_DOUBLE_LOW (op) - 0xFFFFF000 < 0x1000));
1482 uns_arith_operand (rtx op, enum machine_mode mode)
1484 return register_operand (op, mode) || uns_small_int (op, mode);
1487 /* Return truth value of statement that OP is a call-clobbered register. */
1489 clobbered_register (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1491 return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
1494 /* Return 1 if OP is a valid operand for the source of a move insn. */
1497 input_operand (rtx op, enum machine_mode mode)
1499 /* If both modes are non-void they must be the same. */
1500 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1503 /* Allow any one instruction integer constant, and all CONST_INT
1504 variants when we are working in DImode and !arch64. */
1505 if (GET_MODE_CLASS (mode) == MODE_INT
1506 && ((GET_CODE (op) == CONST_INT
1507 && (SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1508 || SPARC_SIMM13_P (INTVAL (op))
1510 && ! TARGET_ARCH64)))
1512 && GET_CODE (op) == CONST_DOUBLE
1513 && ((CONST_DOUBLE_HIGH (op) == 0
1514 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op)))
1516 #if HOST_BITS_PER_WIDE_INT == 64
1517 (CONST_DOUBLE_HIGH (op) == 0
1518 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op)))
1520 (SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1521 && (((CONST_DOUBLE_LOW (op) & 0x80000000) == 0
1522 && CONST_DOUBLE_HIGH (op) == 0)
1523 || (CONST_DOUBLE_HIGH (op) == -1
1524 && CONST_DOUBLE_LOW (op) & 0x80000000) != 0))
1529 /* If !arch64 and this is a DImode const, allow it so that
1530 the splits can be generated. */
1533 && GET_CODE (op) == CONST_DOUBLE)
1536 if (register_operand (op, mode))
1539 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1540 && GET_CODE (op) == CONST_DOUBLE)
1543 /* If this is a SUBREG, look inside so that we handle
1544 paradoxical ones. */
1545 if (GET_CODE (op) == SUBREG)
1546 op = SUBREG_REG (op);
1548 /* Check for valid MEM forms. */
1549 if (GET_CODE (op) == MEM)
1550 return memory_address_p (mode, XEXP (op, 0));
1555 /* Return 1 if OP is valid for the lhs of a compare insn. */
1558 compare_operand (rtx op, enum machine_mode mode)
1560 if (GET_CODE (op) == ZERO_EXTRACT)
1561 return (register_operand (XEXP (op, 0), mode)
1562 && small_int_or_double (XEXP (op, 1), mode)
1563 && small_int_or_double (XEXP (op, 2), mode)
1564 /* This matches cmp_zero_extract. */
1566 && ((GET_CODE (XEXP (op, 2)) == CONST_INT
1567 && INTVAL (XEXP (op, 2)) > 19)
1568 || (GET_CODE (XEXP (op, 2)) == CONST_DOUBLE
1569 && CONST_DOUBLE_LOW (XEXP (op, 2)) > 19)))
1570 /* This matches cmp_zero_extract_sp64. */
1573 && ((GET_CODE (XEXP (op, 2)) == CONST_INT
1574 && INTVAL (XEXP (op, 2)) > 51)
1575 || (GET_CODE (XEXP (op, 2)) == CONST_DOUBLE
1576 && CONST_DOUBLE_LOW (XEXP (op, 2)) > 51)))));
1578 return register_operand (op, mode);
1582 /* We know it can't be done in one insn when we get here,
1583 the movsi expander guarantees this. */
1585 sparc_emit_set_const32 (rtx op0, rtx op1)
1587 enum machine_mode mode = GET_MODE (op0);
1590 if (GET_CODE (op1) == CONST_INT)
1592 HOST_WIDE_INT value = INTVAL (op1);
1594 if (SPARC_SETHI_P (value & GET_MODE_MASK (mode))
1595 || SPARC_SIMM13_P (value))
1599 /* Full 2-insn decomposition is needed. */
1600 if (reload_in_progress || reload_completed)
1603 temp = gen_reg_rtx (mode);
1605 if (GET_CODE (op1) == CONST_INT)
1607 /* Emit them as real moves instead of a HIGH/LO_SUM,
1608 this way CSE can see everything and reuse intermediate
1609 values if it wants. */
1611 && HOST_BITS_PER_WIDE_INT != 64
1612 && (INTVAL (op1) & 0x80000000) != 0)
1613 emit_insn (gen_rtx_SET
1615 immed_double_const (INTVAL (op1) & ~(HOST_WIDE_INT)0x3ff,
1618 emit_insn (gen_rtx_SET (VOIDmode, temp,
1619 GEN_INT (INTVAL (op1)
1620 & ~(HOST_WIDE_INT)0x3ff)));
1622 emit_insn (gen_rtx_SET (VOIDmode,
1624 gen_rtx_IOR (mode, temp,
1625 GEN_INT (INTVAL (op1) & 0x3ff))));
1629 /* A symbol, emit in the traditional way. */
1630 emit_insn (gen_rtx_SET (VOIDmode, temp,
1631 gen_rtx_HIGH (mode, op1)));
1632 emit_insn (gen_rtx_SET (VOIDmode,
1633 op0, gen_rtx_LO_SUM (mode, temp, op1)));
1639 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
1640 If TEMP is nonzero, we are forbidden to use any other scratch
1641 registers. Otherwise, we are allowed to generate them as needed.
1643 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
1644 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
1646 sparc_emit_set_symbolic_const64 (rtx op0, rtx op1, rtx temp)
1648 rtx temp1, temp2, temp3, temp4, temp5;
1651 if (temp && GET_MODE (temp) == TImode)
1654 temp = gen_rtx_REG (DImode, REGNO (temp));
1657 /* SPARC-V9 code-model support. */
1658 switch (sparc_cmodel)
1661 /* The range spanned by all instructions in the object is less
1662 than 2^31 bytes (2GB) and the distance from any instruction
1663 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1664 than 2^31 bytes (2GB).
1666 The executable must be in the low 4TB of the virtual address
1669 sethi %hi(symbol), %temp1
1670 or %temp1, %lo(symbol), %reg */
1672 temp1 = temp; /* op0 is allowed. */
1674 temp1 = gen_reg_rtx (DImode);
1676 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1677 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1681 /* The range spanned by all instructions in the object is less
1682 than 2^31 bytes (2GB) and the distance from any instruction
1683 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1684 than 2^31 bytes (2GB).
1686 The executable must be in the low 16TB of the virtual address
1689 sethi %h44(symbol), %temp1
1690 or %temp1, %m44(symbol), %temp2
1691 sllx %temp2, 12, %temp3
1692 or %temp3, %l44(symbol), %reg */
1697 temp3 = temp; /* op0 is allowed. */
1701 temp1 = gen_reg_rtx (DImode);
1702 temp2 = gen_reg_rtx (DImode);
1703 temp3 = gen_reg_rtx (DImode);
1706 emit_insn (gen_seth44 (temp1, op1));
1707 emit_insn (gen_setm44 (temp2, temp1, op1));
1708 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1709 gen_rtx_ASHIFT (DImode, temp2, GEN_INT (12))));
1710 emit_insn (gen_setl44 (op0, temp3, op1));
1714 /* The range spanned by all instructions in the object is less
1715 than 2^31 bytes (2GB) and the distance from any instruction
1716 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1717 than 2^31 bytes (2GB).
1719 The executable can be placed anywhere in the virtual address
1722 sethi %hh(symbol), %temp1
1723 sethi %lm(symbol), %temp2
1724 or %temp1, %hm(symbol), %temp3
1725 sllx %temp3, 32, %temp4
1726 or %temp4, %temp2, %temp5
1727 or %temp5, %lo(symbol), %reg */
1730 /* It is possible that one of the registers we got for operands[2]
1731 might coincide with that of operands[0] (which is why we made
1732 it TImode). Pick the other one to use as our scratch. */
1733 if (rtx_equal_p (temp, op0))
1736 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1741 temp2 = temp; /* op0 is _not_ allowed, see above. */
1748 temp1 = gen_reg_rtx (DImode);
1749 temp2 = gen_reg_rtx (DImode);
1750 temp3 = gen_reg_rtx (DImode);
1751 temp4 = gen_reg_rtx (DImode);
1752 temp5 = gen_reg_rtx (DImode);
1755 emit_insn (gen_sethh (temp1, op1));
1756 emit_insn (gen_setlm (temp2, op1));
1757 emit_insn (gen_sethm (temp3, temp1, op1));
1758 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1759 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1760 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1761 gen_rtx_PLUS (DImode, temp4, temp2)));
1762 emit_insn (gen_setlo (op0, temp5, op1));
1766 /* Old old old backwards compatibility kruft here.
1767 Essentially it is MEDLOW with a fixed 64-bit
1768 virtual base added to all data segment addresses.
1769 Text-segment stuff is computed like MEDANY, we can't
1770 reuse the code above because the relocation knobs
1773 Data segment: sethi %hi(symbol), %temp1
1774 add %temp1, EMBMEDANY_BASE_REG, %temp2
1775 or %temp2, %lo(symbol), %reg */
1776 if (data_segment_operand (op1, GET_MODE (op1)))
1780 temp1 = temp; /* op0 is allowed. */
1785 temp1 = gen_reg_rtx (DImode);
1786 temp2 = gen_reg_rtx (DImode);
1789 emit_insn (gen_embmedany_sethi (temp1, op1));
1790 emit_insn (gen_embmedany_brsum (temp2, temp1));
1791 emit_insn (gen_embmedany_losum (op0, temp2, op1));
1794 /* Text segment: sethi %uhi(symbol), %temp1
1795 sethi %hi(symbol), %temp2
1796 or %temp1, %ulo(symbol), %temp3
1797 sllx %temp3, 32, %temp4
1798 or %temp4, %temp2, %temp5
1799 or %temp5, %lo(symbol), %reg */
1804 /* It is possible that one of the registers we got for operands[2]
1805 might coincide with that of operands[0] (which is why we made
1806 it TImode). Pick the other one to use as our scratch. */
1807 if (rtx_equal_p (temp, op0))
1810 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1815 temp2 = temp; /* op0 is _not_ allowed, see above. */
1822 temp1 = gen_reg_rtx (DImode);
1823 temp2 = gen_reg_rtx (DImode);
1824 temp3 = gen_reg_rtx (DImode);
1825 temp4 = gen_reg_rtx (DImode);
1826 temp5 = gen_reg_rtx (DImode);
1829 emit_insn (gen_embmedany_textuhi (temp1, op1));
1830 emit_insn (gen_embmedany_texthi (temp2, op1));
1831 emit_insn (gen_embmedany_textulo (temp3, temp1, op1));
1832 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1833 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1834 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1835 gen_rtx_PLUS (DImode, temp4, temp2)));
1836 emit_insn (gen_embmedany_textlo (op0, temp5, op1));
1845 /* These avoid problems when cross compiling. If we do not
1846 go through all this hair then the optimizer will see
1847 invalid REG_EQUAL notes or in some cases none at all. */
1848 static void sparc_emit_set_safe_HIGH64 (rtx, HOST_WIDE_INT);
1849 static rtx gen_safe_SET64 (rtx, HOST_WIDE_INT);
1850 static rtx gen_safe_OR64 (rtx, HOST_WIDE_INT);
1851 static rtx gen_safe_XOR64 (rtx, HOST_WIDE_INT);
1853 #if HOST_BITS_PER_WIDE_INT == 64
1854 #define GEN_HIGHINT64(__x) GEN_INT ((__x) & ~(HOST_WIDE_INT)0x3ff)
1855 #define GEN_INT64(__x) GEN_INT (__x)
1857 #define GEN_HIGHINT64(__x) \
1858 immed_double_const ((__x) & ~(HOST_WIDE_INT)0x3ff, 0, DImode)
1859 #define GEN_INT64(__x) \
1860 immed_double_const ((__x) & 0xffffffff, \
1861 ((__x) & 0x80000000 ? -1 : 0), DImode)
1864 /* The optimizer is not to assume anything about exactly
1865 which bits are set for a HIGH, they are unspecified.
1866 Unfortunately this leads to many missed optimizations
1867 during CSE. We mask out the non-HIGH bits, and matches
1868 a plain movdi, to alleviate this problem. */
1870 sparc_emit_set_safe_HIGH64 (rtx dest, HOST_WIDE_INT val)
1872 emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_HIGHINT64 (val)));
1876 gen_safe_SET64 (rtx dest, HOST_WIDE_INT val)
1878 return gen_rtx_SET (VOIDmode, dest, GEN_INT64 (val));
1882 gen_safe_OR64 (rtx src, HOST_WIDE_INT val)
1884 return gen_rtx_IOR (DImode, src, GEN_INT64 (val));
1888 gen_safe_XOR64 (rtx src, HOST_WIDE_INT val)
1890 return gen_rtx_XOR (DImode, src, GEN_INT64 (val));
1893 /* Worker routines for 64-bit constant formation on arch64.
1894 One of the key things to be doing in these emissions is
1895 to create as many temp REGs as possible. This makes it
1896 possible for half-built constants to be used later when
1897 such values are similar to something required later on.
1898 Without doing this, the optimizer cannot see such
1901 static void sparc_emit_set_const64_quick1 (rtx, rtx,
1902 unsigned HOST_WIDE_INT, int);
1905 sparc_emit_set_const64_quick1 (rtx op0, rtx temp,
1906 unsigned HOST_WIDE_INT low_bits, int is_neg)
1908 unsigned HOST_WIDE_INT high_bits;
1911 high_bits = (~low_bits) & 0xffffffff;
1913 high_bits = low_bits;
1915 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1918 emit_insn (gen_rtx_SET (VOIDmode, op0,
1919 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1923 /* If we are XOR'ing with -1, then we should emit a one's complement
1924 instead. This way the combiner will notice logical operations
1925 such as ANDN later on and substitute. */
1926 if ((low_bits & 0x3ff) == 0x3ff)
1928 emit_insn (gen_rtx_SET (VOIDmode, op0,
1929 gen_rtx_NOT (DImode, temp)));
1933 emit_insn (gen_rtx_SET (VOIDmode, op0,
1934 gen_safe_XOR64 (temp,
1935 (-(HOST_WIDE_INT)0x400
1936 | (low_bits & 0x3ff)))));
1941 static void sparc_emit_set_const64_quick2 (rtx, rtx, unsigned HOST_WIDE_INT,
1942 unsigned HOST_WIDE_INT, int);
1945 sparc_emit_set_const64_quick2 (rtx op0, rtx temp,
1946 unsigned HOST_WIDE_INT high_bits,
1947 unsigned HOST_WIDE_INT low_immediate,
1952 if ((high_bits & 0xfffffc00) != 0)
1954 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1955 if ((high_bits & ~0xfffffc00) != 0)
1956 emit_insn (gen_rtx_SET (VOIDmode, op0,
1957 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1963 emit_insn (gen_safe_SET64 (temp, high_bits));
1967 /* Now shift it up into place. */
1968 emit_insn (gen_rtx_SET (VOIDmode, op0,
1969 gen_rtx_ASHIFT (DImode, temp2,
1970 GEN_INT (shift_count))));
1972 /* If there is a low immediate part piece, finish up by
1973 putting that in as well. */
1974 if (low_immediate != 0)
1975 emit_insn (gen_rtx_SET (VOIDmode, op0,
1976 gen_safe_OR64 (op0, low_immediate)));
1979 static void sparc_emit_set_const64_longway (rtx, rtx, unsigned HOST_WIDE_INT,
1980 unsigned HOST_WIDE_INT);
1982 /* Full 64-bit constant decomposition. Even though this is the
1983 'worst' case, we still optimize a few things away. */
1985 sparc_emit_set_const64_longway (rtx op0, rtx temp,
1986 unsigned HOST_WIDE_INT high_bits,
1987 unsigned HOST_WIDE_INT low_bits)
1991 if (reload_in_progress || reload_completed)
1994 sub_temp = gen_reg_rtx (DImode);
1996 if ((high_bits & 0xfffffc00) != 0)
1998 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1999 if ((high_bits & ~0xfffffc00) != 0)
2000 emit_insn (gen_rtx_SET (VOIDmode,
2002 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
2008 emit_insn (gen_safe_SET64 (temp, high_bits));
2012 if (!reload_in_progress && !reload_completed)
2014 rtx temp2 = gen_reg_rtx (DImode);
2015 rtx temp3 = gen_reg_rtx (DImode);
2016 rtx temp4 = gen_reg_rtx (DImode);
2018 emit_insn (gen_rtx_SET (VOIDmode, temp4,
2019 gen_rtx_ASHIFT (DImode, sub_temp,
2022 sparc_emit_set_safe_HIGH64 (temp2, low_bits);
2023 if ((low_bits & ~0xfffffc00) != 0)
2025 emit_insn (gen_rtx_SET (VOIDmode, temp3,
2026 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
2027 emit_insn (gen_rtx_SET (VOIDmode, op0,
2028 gen_rtx_PLUS (DImode, temp4, temp3)));
2032 emit_insn (gen_rtx_SET (VOIDmode, op0,
2033 gen_rtx_PLUS (DImode, temp4, temp2)));
2038 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
2039 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
2040 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
2043 /* We are in the middle of reload, so this is really
2044 painful. However we do still make an attempt to
2045 avoid emitting truly stupid code. */
2046 if (low1 != const0_rtx)
2048 emit_insn (gen_rtx_SET (VOIDmode, op0,
2049 gen_rtx_ASHIFT (DImode, sub_temp,
2050 GEN_INT (to_shift))));
2051 emit_insn (gen_rtx_SET (VOIDmode, op0,
2052 gen_rtx_IOR (DImode, op0, low1)));
2060 if (low2 != const0_rtx)
2062 emit_insn (gen_rtx_SET (VOIDmode, op0,
2063 gen_rtx_ASHIFT (DImode, sub_temp,
2064 GEN_INT (to_shift))));
2065 emit_insn (gen_rtx_SET (VOIDmode, op0,
2066 gen_rtx_IOR (DImode, op0, low2)));
2074 emit_insn (gen_rtx_SET (VOIDmode, op0,
2075 gen_rtx_ASHIFT (DImode, sub_temp,
2076 GEN_INT (to_shift))));
2077 if (low3 != const0_rtx)
2078 emit_insn (gen_rtx_SET (VOIDmode, op0,
2079 gen_rtx_IOR (DImode, op0, low3)));
2084 /* Analyze a 64-bit constant for certain properties. */
2085 static void analyze_64bit_constant (unsigned HOST_WIDE_INT,
2086 unsigned HOST_WIDE_INT,
2087 int *, int *, int *);
2090 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits,
2091 unsigned HOST_WIDE_INT low_bits,
2092 int *hbsp, int *lbsp, int *abbasp)
2094 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
2097 lowest_bit_set = highest_bit_set = -1;
2101 if ((lowest_bit_set == -1)
2102 && ((low_bits >> i) & 1))
2104 if ((highest_bit_set == -1)
2105 && ((high_bits >> (32 - i - 1)) & 1))
2106 highest_bit_set = (64 - i - 1);
2109 && ((highest_bit_set == -1)
2110 || (lowest_bit_set == -1)));
2116 if ((lowest_bit_set == -1)
2117 && ((high_bits >> i) & 1))
2118 lowest_bit_set = i + 32;
2119 if ((highest_bit_set == -1)
2120 && ((low_bits >> (32 - i - 1)) & 1))
2121 highest_bit_set = 32 - i - 1;
2124 && ((highest_bit_set == -1)
2125 || (lowest_bit_set == -1)));
2127 /* If there are no bits set this should have gone out
2128 as one instruction! */
2129 if (lowest_bit_set == -1
2130 || highest_bit_set == -1)
2132 all_bits_between_are_set = 1;
2133 for (i = lowest_bit_set; i <= highest_bit_set; i++)
2137 if ((low_bits & (1 << i)) != 0)
2142 if ((high_bits & (1 << (i - 32))) != 0)
2145 all_bits_between_are_set = 0;
2148 *hbsp = highest_bit_set;
2149 *lbsp = lowest_bit_set;
2150 *abbasp = all_bits_between_are_set;
2153 static int const64_is_2insns (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2156 const64_is_2insns (unsigned HOST_WIDE_INT high_bits,
2157 unsigned HOST_WIDE_INT low_bits)
2159 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
2162 || high_bits == 0xffffffff)
2165 analyze_64bit_constant (high_bits, low_bits,
2166 &highest_bit_set, &lowest_bit_set,
2167 &all_bits_between_are_set);
2169 if ((highest_bit_set == 63
2170 || lowest_bit_set == 0)
2171 && all_bits_between_are_set != 0)
2174 if ((highest_bit_set - lowest_bit_set) < 21)
2180 static unsigned HOST_WIDE_INT create_simple_focus_bits (unsigned HOST_WIDE_INT,
2181 unsigned HOST_WIDE_INT,
2184 static unsigned HOST_WIDE_INT
2185 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits,
2186 unsigned HOST_WIDE_INT low_bits,
2187 int lowest_bit_set, int shift)
2189 HOST_WIDE_INT hi, lo;
2191 if (lowest_bit_set < 32)
2193 lo = (low_bits >> lowest_bit_set) << shift;
2194 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
2199 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
2206 /* Here we are sure to be arch64 and this is an integer constant
2207 being loaded into a register. Emit the most efficient
2208 insn sequence possible. Detection of all the 1-insn cases
2209 has been done already. */
2211 sparc_emit_set_const64 (rtx op0, rtx op1)
2213 unsigned HOST_WIDE_INT high_bits, low_bits;
2214 int lowest_bit_set, highest_bit_set;
2215 int all_bits_between_are_set;
2218 /* Sanity check that we know what we are working with. */
2219 if (! TARGET_ARCH64)
2222 if (GET_CODE (op0) != SUBREG)
2224 if (GET_CODE (op0) != REG
2225 || (REGNO (op0) >= SPARC_FIRST_FP_REG
2226 && REGNO (op0) <= SPARC_LAST_V9_FP_REG))
2230 if (reload_in_progress || reload_completed)
2233 if (GET_CODE (op1) != CONST_DOUBLE
2234 && GET_CODE (op1) != CONST_INT)
2236 sparc_emit_set_symbolic_const64 (op0, op1, temp);
2241 temp = gen_reg_rtx (DImode);
2243 if (GET_CODE (op1) == CONST_DOUBLE)
2245 #if HOST_BITS_PER_WIDE_INT == 64
2246 high_bits = (CONST_DOUBLE_LOW (op1) >> 32) & 0xffffffff;
2247 low_bits = CONST_DOUBLE_LOW (op1) & 0xffffffff;
2249 high_bits = CONST_DOUBLE_HIGH (op1);
2250 low_bits = CONST_DOUBLE_LOW (op1);
2255 #if HOST_BITS_PER_WIDE_INT == 64
2256 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
2257 low_bits = (INTVAL (op1) & 0xffffffff);
2259 high_bits = ((INTVAL (op1) < 0) ?
2262 low_bits = INTVAL (op1);
2266 /* low_bits bits 0 --> 31
2267 high_bits bits 32 --> 63 */
2269 analyze_64bit_constant (high_bits, low_bits,
2270 &highest_bit_set, &lowest_bit_set,
2271 &all_bits_between_are_set);
2273 /* First try for a 2-insn sequence. */
2275 /* These situations are preferred because the optimizer can
2276 * do more things with them:
2278 * sllx %reg, shift, %reg
2280 * srlx %reg, shift, %reg
2281 * 3) mov some_small_const, %reg
2282 * sllx %reg, shift, %reg
2284 if (((highest_bit_set == 63
2285 || lowest_bit_set == 0)
2286 && all_bits_between_are_set != 0)
2287 || ((highest_bit_set - lowest_bit_set) < 12))
2289 HOST_WIDE_INT the_const = -1;
2290 int shift = lowest_bit_set;
2292 if ((highest_bit_set != 63
2293 && lowest_bit_set != 0)
2294 || all_bits_between_are_set == 0)
2297 create_simple_focus_bits (high_bits, low_bits,
2300 else if (lowest_bit_set == 0)
2301 shift = -(63 - highest_bit_set);
2303 if (! SPARC_SIMM13_P (the_const))
2306 emit_insn (gen_safe_SET64 (temp, the_const));
2308 emit_insn (gen_rtx_SET (VOIDmode,
2310 gen_rtx_ASHIFT (DImode,
2314 emit_insn (gen_rtx_SET (VOIDmode,
2316 gen_rtx_LSHIFTRT (DImode,
2318 GEN_INT (-shift))));
2324 /* Now a range of 22 or less bits set somewhere.
2325 * 1) sethi %hi(focus_bits), %reg
2326 * sllx %reg, shift, %reg
2327 * 2) sethi %hi(focus_bits), %reg
2328 * srlx %reg, shift, %reg
2330 if ((highest_bit_set - lowest_bit_set) < 21)
2332 unsigned HOST_WIDE_INT focus_bits =
2333 create_simple_focus_bits (high_bits, low_bits,
2334 lowest_bit_set, 10);
2336 if (! SPARC_SETHI_P (focus_bits))
2339 sparc_emit_set_safe_HIGH64 (temp, focus_bits);
2341 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
2342 if (lowest_bit_set < 10)
2343 emit_insn (gen_rtx_SET (VOIDmode,
2345 gen_rtx_LSHIFTRT (DImode, temp,
2346 GEN_INT (10 - lowest_bit_set))));
2347 else if (lowest_bit_set > 10)
2348 emit_insn (gen_rtx_SET (VOIDmode,
2350 gen_rtx_ASHIFT (DImode, temp,
2351 GEN_INT (lowest_bit_set - 10))));
2357 /* 1) sethi %hi(low_bits), %reg
2358 * or %reg, %lo(low_bits), %reg
2359 * 2) sethi %hi(~low_bits), %reg
2360 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
2363 || high_bits == 0xffffffff)
2365 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
2366 (high_bits == 0xffffffff));
2370 /* Now, try 3-insn sequences. */
2372 /* 1) sethi %hi(high_bits), %reg
2373 * or %reg, %lo(high_bits), %reg
2374 * sllx %reg, 32, %reg
2378 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
2382 /* We may be able to do something quick
2383 when the constant is negated, so try that. */
2384 if (const64_is_2insns ((~high_bits) & 0xffffffff,
2385 (~low_bits) & 0xfffffc00))
2387 /* NOTE: The trailing bits get XOR'd so we need the
2388 non-negated bits, not the negated ones. */
2389 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
2391 if ((((~high_bits) & 0xffffffff) == 0
2392 && ((~low_bits) & 0x80000000) == 0)
2393 || (((~high_bits) & 0xffffffff) == 0xffffffff
2394 && ((~low_bits) & 0x80000000) != 0))
2396 int fast_int = (~low_bits & 0xffffffff);
2398 if ((SPARC_SETHI_P (fast_int)
2399 && (~high_bits & 0xffffffff) == 0)
2400 || SPARC_SIMM13_P (fast_int))
2401 emit_insn (gen_safe_SET64 (temp, fast_int));
2403 sparc_emit_set_const64 (temp, GEN_INT64 (fast_int));
2408 #if HOST_BITS_PER_WIDE_INT == 64
2409 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2410 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2412 negated_const = immed_double_const ((~low_bits) & 0xfffffc00,
2413 (~high_bits) & 0xffffffff,
2416 sparc_emit_set_const64 (temp, negated_const);
2419 /* If we are XOR'ing with -1, then we should emit a one's complement
2420 instead. This way the combiner will notice logical operations
2421 such as ANDN later on and substitute. */
2422 if (trailing_bits == 0x3ff)
2424 emit_insn (gen_rtx_SET (VOIDmode, op0,
2425 gen_rtx_NOT (DImode, temp)));
2429 emit_insn (gen_rtx_SET (VOIDmode,
2431 gen_safe_XOR64 (temp,
2432 (-0x400 | trailing_bits))));
2437 /* 1) sethi %hi(xxx), %reg
2438 * or %reg, %lo(xxx), %reg
2439 * sllx %reg, yyy, %reg
2441 * ??? This is just a generalized version of the low_bits==0
2442 * thing above, FIXME...
2444 if ((highest_bit_set - lowest_bit_set) < 32)
2446 unsigned HOST_WIDE_INT focus_bits =
2447 create_simple_focus_bits (high_bits, low_bits,
2450 /* We can't get here in this state. */
2451 if (highest_bit_set < 32
2452 || lowest_bit_set >= 32)
2455 /* So what we know is that the set bits straddle the
2456 middle of the 64-bit word. */
2457 sparc_emit_set_const64_quick2 (op0, temp,
2463 /* 1) sethi %hi(high_bits), %reg
2464 * or %reg, %lo(high_bits), %reg
2465 * sllx %reg, 32, %reg
2466 * or %reg, low_bits, %reg
2468 if (SPARC_SIMM13_P(low_bits)
2469 && ((int)low_bits > 0))
2471 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2475 /* The easiest way when all else fails, is full decomposition. */
2477 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
2478 high_bits, low_bits, ~high_bits, ~low_bits);
2480 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2483 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2484 return the mode to be used for the comparison. For floating-point,
2485 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2486 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2487 processing is needed. */
2490 select_cc_mode (enum rtx_code op, rtx x, rtx y ATTRIBUTE_UNUSED)
2492 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2518 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2519 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2521 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2522 return CCX_NOOVmode;
2528 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2535 /* X and Y are two things to compare using CODE. Emit the compare insn and
2536 return the rtx for the cc reg in the proper mode. */
2539 gen_compare_reg (enum rtx_code code, rtx x, rtx y)
2541 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
2544 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2545 fcc regs (cse can't tell they're really call clobbered regs and will
2546 remove a duplicate comparison even if there is an intervening function
2547 call - it will then try to reload the cc reg via an int reg which is why
2548 we need the movcc patterns). It is possible to provide the movcc
2549 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2550 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2551 to tell cse that CCFPE mode registers (even pseudos) are call
2554 /* ??? This is an experiment. Rather than making changes to cse which may
2555 or may not be easy/clean, we do our own cse. This is possible because
2556 we will generate hard registers. Cse knows they're call clobbered (it
2557 doesn't know the same thing about pseudos). If we guess wrong, no big
2558 deal, but if we win, great! */
2560 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2561 #if 1 /* experiment */
2564 /* We cycle through the registers to ensure they're all exercised. */
2565 static int next_fcc_reg = 0;
2566 /* Previous x,y for each fcc reg. */
2567 static rtx prev_args[4][2];
2569 /* Scan prev_args for x,y. */
2570 for (reg = 0; reg < 4; reg++)
2571 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2576 prev_args[reg][0] = x;
2577 prev_args[reg][1] = y;
2578 next_fcc_reg = (next_fcc_reg + 1) & 3;
2580 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2583 cc_reg = gen_reg_rtx (mode);
2584 #endif /* ! experiment */
2585 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2586 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2588 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2590 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2591 gen_rtx_COMPARE (mode, x, y)));
2596 /* This function is used for v9 only.
2597 CODE is the code for an Scc's comparison.
2598 OPERANDS[0] is the target of the Scc insn.
2599 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
2600 been generated yet).
2602 This function is needed to turn
2605 (gt (reg:CCX 100 %icc)
2609 (gt:DI (reg:CCX 100 %icc)
2612 IE: The instruction recognizer needs to see the mode of the comparison to
2613 find the right instruction. We could use "gt:DI" right in the
2614 define_expand, but leaving it out allows us to handle DI, SI, etc.
2616 We refer to the global sparc compare operands sparc_compare_op0 and
2617 sparc_compare_op1. */
2620 gen_v9_scc (enum rtx_code compare_code, register rtx *operands)
2625 && (GET_MODE (sparc_compare_op0) == DImode
2626 || GET_MODE (operands[0]) == DImode))
2629 op0 = sparc_compare_op0;
2630 op1 = sparc_compare_op1;
2632 /* Try to use the movrCC insns. */
2634 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
2635 && op1 == const0_rtx
2636 && v9_regcmp_p (compare_code))
2638 /* Special case for op0 != 0. This can be done with one instruction if
2639 operands[0] == sparc_compare_op0. */
2641 if (compare_code == NE
2642 && GET_MODE (operands[0]) == DImode
2643 && rtx_equal_p (op0, operands[0]))
2645 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2646 gen_rtx_IF_THEN_ELSE (DImode,
2647 gen_rtx_fmt_ee (compare_code, DImode,
2654 if (reg_overlap_mentioned_p (operands[0], op0))
2656 /* Handle the case where operands[0] == sparc_compare_op0.
2657 We "early clobber" the result. */
2658 op0 = gen_reg_rtx (GET_MODE (sparc_compare_op0));
2659 emit_move_insn (op0, sparc_compare_op0);
2662 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2663 if (GET_MODE (op0) != DImode)
2665 temp = gen_reg_rtx (DImode);
2666 convert_move (temp, op0, 0);
2670 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2671 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2672 gen_rtx_fmt_ee (compare_code, DImode,
2680 operands[1] = gen_compare_reg (compare_code, op0, op1);
2682 switch (GET_MODE (operands[1]))
2692 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2693 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2694 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2695 gen_rtx_fmt_ee (compare_code,
2696 GET_MODE (operands[1]),
2697 operands[1], const0_rtx),
2698 const1_rtx, operands[0])));
2703 /* Emit a conditional jump insn for the v9 architecture using comparison code
2704 CODE and jump target LABEL.
2705 This function exists to take advantage of the v9 brxx insns. */
2708 emit_v9_brxx_insn (enum rtx_code code, rtx op0, rtx label)
2710 emit_jump_insn (gen_rtx_SET (VOIDmode,
2712 gen_rtx_IF_THEN_ELSE (VOIDmode,
2713 gen_rtx_fmt_ee (code, GET_MODE (op0),
2715 gen_rtx_LABEL_REF (VOIDmode, label),
2719 /* Generate a DFmode part of a hard TFmode register.
2720 REG is the TFmode hard register, LOW is 1 for the
2721 low 64bit of the register and 0 otherwise.
2724 gen_df_reg (rtx reg, int low)
2726 int regno = REGNO (reg);
2728 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2729 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
2730 return gen_rtx_REG (DFmode, regno);
2733 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
2734 Unlike normal calls, TFmode operands are passed by reference. It is
2735 assumed that no more than 3 operands are required. */
2738 emit_soft_tfmode_libcall (const char *func_name, int nargs, rtx *operands)
2740 rtx ret_slot = NULL, arg[3], func_sym;
2743 /* We only expect to be called for conversions, unary, and binary ops. */
2744 if (nargs < 2 || nargs > 3)
2747 for (i = 0; i < nargs; ++i)
2749 rtx this_arg = operands[i];
2752 /* TFmode arguments and return values are passed by reference. */
2753 if (GET_MODE (this_arg) == TFmode)
2755 int force_stack_temp;
2757 force_stack_temp = 0;
2758 if (TARGET_BUGGY_QP_LIB && i == 0)
2759 force_stack_temp = 1;
2761 if (GET_CODE (this_arg) == MEM
2762 && ! force_stack_temp)
2763 this_arg = XEXP (this_arg, 0);
2764 else if (CONSTANT_P (this_arg)
2765 && ! force_stack_temp)
2767 this_slot = force_const_mem (TFmode, this_arg);
2768 this_arg = XEXP (this_slot, 0);
2772 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode), 0);
2774 /* Operand 0 is the return value. We'll copy it out later. */
2776 emit_move_insn (this_slot, this_arg);
2778 ret_slot = this_slot;
2780 this_arg = XEXP (this_slot, 0);
2787 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
2789 if (GET_MODE (operands[0]) == TFmode)
2792 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
2793 arg[0], GET_MODE (arg[0]),
2794 arg[1], GET_MODE (arg[1]));
2796 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
2797 arg[0], GET_MODE (arg[0]),
2798 arg[1], GET_MODE (arg[1]),
2799 arg[2], GET_MODE (arg[2]));
2802 emit_move_insn (operands[0], ret_slot);
2811 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
2812 GET_MODE (operands[0]), 1,
2813 arg[1], GET_MODE (arg[1]));
2815 if (ret != operands[0])
2816 emit_move_insn (operands[0], ret);
2820 /* Expand soft-float TFmode calls to sparc abi routines. */
2823 emit_soft_tfmode_binop (enum rtx_code code, rtx *operands)
2845 emit_soft_tfmode_libcall (func, 3, operands);
2849 emit_soft_tfmode_unop (enum rtx_code code, rtx *operands)
2862 emit_soft_tfmode_libcall (func, 2, operands);
2866 emit_soft_tfmode_cvt (enum rtx_code code, rtx *operands)
2873 switch (GET_MODE (operands[1]))
2886 case FLOAT_TRUNCATE:
2887 switch (GET_MODE (operands[0]))
2901 switch (GET_MODE (operands[1]))
2914 case UNSIGNED_FLOAT:
2915 switch (GET_MODE (operands[1]))
2929 switch (GET_MODE (operands[0]))
2943 switch (GET_MODE (operands[0]))
2960 emit_soft_tfmode_libcall (func, 2, operands);
2963 /* Expand a hard-float tfmode operation. All arguments must be in
2967 emit_hard_tfmode_operation (enum rtx_code code, rtx *operands)
2971 if (GET_RTX_CLASS (code) == RTX_UNARY)
2973 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2974 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
2978 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2979 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
2980 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
2981 operands[1], operands[2]);
2984 if (register_operand (operands[0], VOIDmode))
2987 dest = gen_reg_rtx (GET_MODE (operands[0]));
2989 emit_insn (gen_rtx_SET (VOIDmode, dest, op));
2991 if (dest != operands[0])
2992 emit_move_insn (operands[0], dest);
2996 emit_tfmode_binop (enum rtx_code code, rtx *operands)
2998 if (TARGET_HARD_QUAD)
2999 emit_hard_tfmode_operation (code, operands);
3001 emit_soft_tfmode_binop (code, operands);
3005 emit_tfmode_unop (enum rtx_code code, rtx *operands)
3007 if (TARGET_HARD_QUAD)
3008 emit_hard_tfmode_operation (code, operands);
3010 emit_soft_tfmode_unop (code, operands);
3014 emit_tfmode_cvt (enum rtx_code code, rtx *operands)
3016 if (TARGET_HARD_QUAD)
3017 emit_hard_tfmode_operation (code, operands);
3019 emit_soft_tfmode_cvt (code, operands);
3022 /* Return nonzero if a branch/jump/call instruction will be emitting
3023 nop into its delay slot. */
3026 empty_delay_slot (rtx insn)
3030 /* If no previous instruction (should not happen), return true. */
3031 if (PREV_INSN (insn) == NULL)
3034 seq = NEXT_INSN (PREV_INSN (insn));
3035 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
3041 /* Return nonzero if TRIAL can go into the call delay slot. */
3044 tls_call_delay (rtx trial)
3049 call __tls_get_addr, %tgd_call (foo)
3050 add %l7, %o0, %o0, %tgd_add (foo)
3051 while Sun as/ld does not. */
3052 if (TARGET_GNU_TLS || !TARGET_TLS)
3055 pat = PATTERN (trial);
3056 if (GET_CODE (pat) != SET || GET_CODE (SET_DEST (pat)) != PLUS)
3059 unspec = XEXP (SET_DEST (pat), 1);
3060 if (GET_CODE (unspec) != UNSPEC
3061 || (XINT (unspec, 1) != UNSPEC_TLSGD
3062 && XINT (unspec, 1) != UNSPEC_TLSLDM))
3068 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
3069 instruction. RETURN_P is true if the v9 variant 'return' is to be
3070 considered in the test too.
3072 TRIAL must be a SET whose destination is a REG appropriate for the
3073 'restore' instruction or, if RETURN_P is true, for the 'return'
3077 eligible_for_restore_insn (rtx trial, bool return_p)
3079 rtx pat = PATTERN (trial);
3080 rtx src = SET_SRC (pat);
3082 /* The 'restore src,%g0,dest' pattern for word mode and below. */
3083 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3084 && arith_operand (src, GET_MODE (src)))
3087 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3089 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
3092 /* The 'restore src,%g0,dest' pattern for double-word mode. */
3093 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3094 && arith_double_operand (src, GET_MODE (src)))
3095 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3097 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
3098 else if (! TARGET_FPU && register_operand (src, SFmode))
3101 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
3102 else if (! TARGET_FPU && TARGET_ARCH64 && register_operand (src, DFmode))
3105 /* If we have the 'return' instruction, anything that does not use
3106 local or output registers and can go into a delay slot wins. */
3107 else if (return_p && TARGET_V9 && ! epilogue_renumber (&pat, 1)
3108 && (get_attr_in_uncond_branch_delay (trial)
3109 == IN_UNCOND_BRANCH_DELAY_TRUE))
3112 /* The 'restore src1,src2,dest' pattern for SImode. */
3113 else if (GET_CODE (src) == PLUS
3114 && register_operand (XEXP (src, 0), SImode)
3115 && arith_operand (XEXP (src, 1), SImode))
3118 /* The 'restore src1,src2,dest' pattern for DImode. */
3119 else if (GET_CODE (src) == PLUS
3120 && register_operand (XEXP (src, 0), DImode)
3121 && arith_double_operand (XEXP (src, 1), DImode))
3124 /* The 'restore src1,%lo(src2),dest' pattern. */
3125 else if (GET_CODE (src) == LO_SUM
3126 && ! TARGET_CM_MEDMID
3127 && ((register_operand (XEXP (src, 0), SImode)
3128 && immediate_operand (XEXP (src, 1), SImode))
3130 && register_operand (XEXP (src, 0), DImode)
3131 && immediate_operand (XEXP (src, 1), DImode))))
3134 /* The 'restore src,src,dest' pattern. */
3135 else if (GET_CODE (src) == ASHIFT
3136 && (register_operand (XEXP (src, 0), SImode)
3137 || register_operand (XEXP (src, 0), DImode))
3138 && XEXP (src, 1) == const1_rtx)
3144 /* Return nonzero if TRIAL can go into the function return's
3148 eligible_for_return_delay (rtx trial)
3152 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
3155 if (get_attr_length (trial) != 1)
3158 /* If there are any call-saved registers, we should scan TRIAL if it
3159 does not reference them. For now just make it easy. */
3163 /* If the function uses __builtin_eh_return, the eh_return machinery
3164 occupies the delay slot. */
3165 if (current_function_calls_eh_return)
3168 /* In the case of a true leaf function, anything can go into the slot. */
3169 if (sparc_leaf_function_p)
3170 return get_attr_in_uncond_branch_delay (trial)
3171 == IN_UNCOND_BRANCH_DELAY_TRUE;
3173 pat = PATTERN (trial);
3175 /* Otherwise, only operations which can be done in tandem with
3176 a `restore' or `return' insn can go into the delay slot. */
3177 if (GET_CODE (SET_DEST (pat)) != REG
3178 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24))
3181 /* If this instruction sets up floating point register and we have a return
3182 instruction, it can probably go in. But restore will not work
3184 if (REGNO (SET_DEST (pat)) >= 32)
3186 && ! epilogue_renumber (&pat, 1)
3187 && (get_attr_in_uncond_branch_delay (trial)
3188 == IN_UNCOND_BRANCH_DELAY_TRUE));
3190 return eligible_for_restore_insn (trial, true);
3193 /* Return nonzero if TRIAL can go into the sibling call's
3197 eligible_for_sibcall_delay (rtx trial)
3201 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
3204 if (get_attr_length (trial) != 1)
3207 pat = PATTERN (trial);
3209 if (sparc_leaf_function_p)
3211 /* If the tail call is done using the call instruction,
3212 we have to restore %o7 in the delay slot. */
3213 if (LEAF_SIBCALL_SLOT_RESERVED_P)
3216 /* %g1 is used to build the function address */
3217 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
3223 /* Otherwise, only operations which can be done in tandem with
3224 a `restore' insn can go into the delay slot. */
3225 if (GET_CODE (SET_DEST (pat)) != REG
3226 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24)
3227 || REGNO (SET_DEST (pat)) >= 32)
3230 /* If it mentions %o7, it can't go in, because sibcall will clobber it
3232 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
3235 return eligible_for_restore_insn (trial, false);
3239 short_branch (int uid1, int uid2)
3241 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
3243 /* Leave a few words of "slop". */
3244 if (delta >= -1023 && delta <= 1022)
3250 /* Return nonzero if REG is not used after INSN.
3251 We assume REG is a reload reg, and therefore does
3252 not live past labels or calls or jumps. */
3254 reg_unused_after (rtx reg, rtx insn)
3256 enum rtx_code code, prev_code = UNKNOWN;
3258 while ((insn = NEXT_INSN (insn)))
3260 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
3263 code = GET_CODE (insn);
3264 if (GET_CODE (insn) == CODE_LABEL)
3269 rtx set = single_set (insn);
3270 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
3273 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
3275 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
3283 /* Determine if it's legal to put X into the constant pool. This
3284 is not possible if X contains the address of a symbol that is
3285 not constant (TLS) or not known at final link time (PIC). */
3288 sparc_cannot_force_const_mem (rtx x)
3290 switch (GET_CODE (x))
3294 /* Accept all non-symbolic constants. */
3298 /* Labels are OK iff we are non-PIC. */
3299 return flag_pic != 0;
3302 /* 'Naked' TLS symbol references are never OK,
3303 non-TLS symbols are OK iff we are non-PIC. */
3304 if (SYMBOL_REF_TLS_MODEL (x))
3307 return flag_pic != 0;
3310 return sparc_cannot_force_const_mem (XEXP (x, 0));
3313 return sparc_cannot_force_const_mem (XEXP (x, 0))
3314 || sparc_cannot_force_const_mem (XEXP (x, 1));
3322 /* The table we use to reference PIC data. */
3323 static GTY(()) rtx global_offset_table;
3325 /* The function we use to get at it. */
3326 static GTY(()) rtx add_pc_to_pic_symbol;
3327 static GTY(()) char add_pc_to_pic_symbol_name[256];
3329 /* Ensure that we are not using patterns that are not OK with PIC. */
3337 if (GET_CODE (recog_data.operand[i]) == SYMBOL_REF
3338 || (GET_CODE (recog_data.operand[i]) == CONST
3339 && ! (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
3340 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
3341 == global_offset_table)
3342 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
3351 /* Return true if X is an address which needs a temporary register when
3352 reloaded while generating PIC code. */
3355 pic_address_needs_scratch (rtx x)
3357 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
3358 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3359 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
3360 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3361 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
3367 /* Determine if a given RTX is a valid constant. We already know this
3368 satisfies CONSTANT_P. */
3371 legitimate_constant_p (rtx x)
3375 switch (GET_CODE (x))
3378 /* TLS symbols are not constant. */
3379 if (SYMBOL_REF_TLS_MODEL (x))
3384 inner = XEXP (x, 0);
3386 /* Offsets of TLS symbols are never valid.
3387 Discourage CSE from creating them. */
3388 if (GET_CODE (inner) == PLUS
3389 && tls_symbolic_operand (XEXP (inner, 0)))
3394 if (GET_MODE (x) == VOIDmode)
3397 /* Floating point constants are generally not ok.
3398 The only exception is 0.0 in VIS. */
3400 && (GET_MODE (x) == SFmode
3401 || GET_MODE (x) == DFmode
3402 || GET_MODE (x) == TFmode)
3403 && fp_zero_operand (x, GET_MODE (x)))
3415 /* Determine if a given RTX is a valid constant address. */
3418 constant_address_p (rtx x)
3420 switch (GET_CODE (x))
3428 if (flag_pic && pic_address_needs_scratch (x))
3430 return legitimate_constant_p (x);
3433 return !flag_pic && legitimate_constant_p (x);
3440 /* Nonzero if the constant value X is a legitimate general operand
3441 when generating PIC code. It is given that flag_pic is on and
3442 that X satisfies CONSTANT_P or is a CONST_DOUBLE. */
3445 legitimate_pic_operand_p (rtx x)
3447 if (pic_address_needs_scratch (x))
3449 if (tls_symbolic_operand (x)
3450 || (GET_CODE (x) == CONST
3451 && GET_CODE (XEXP (x, 0)) == PLUS
3452 && tls_symbolic_operand (XEXP (XEXP (x, 0), 0))))
3457 /* Return nonzero if ADDR is a valid memory address.
3458 STRICT specifies whether strict register checking applies. */
3461 legitimate_address_p (enum machine_mode mode, rtx addr, int strict)
3463 rtx rs1 = NULL, rs2 = NULL, imm1 = NULL, imm2;
3465 if (REG_P (addr) || GET_CODE (addr) == SUBREG)
3467 else if (GET_CODE (addr) == PLUS)
3469 rs1 = XEXP (addr, 0);
3470 rs2 = XEXP (addr, 1);
3472 /* Canonicalize. REG comes first, if there are no regs,
3473 LO_SUM comes first. */
3475 && GET_CODE (rs1) != SUBREG
3477 || GET_CODE (rs2) == SUBREG
3478 || (GET_CODE (rs2) == LO_SUM && GET_CODE (rs1) != LO_SUM)))
3480 rs1 = XEXP (addr, 1);
3481 rs2 = XEXP (addr, 0);
3485 && rs1 == pic_offset_table_rtx
3487 && GET_CODE (rs2) != SUBREG
3488 && GET_CODE (rs2) != LO_SUM
3489 && GET_CODE (rs2) != MEM
3490 && !tls_symbolic_operand (rs2)
3491 && (! symbolic_operand (rs2, VOIDmode) || mode == Pmode)
3492 && (GET_CODE (rs2) != CONST_INT || SMALL_INT (rs2)))
3494 || GET_CODE (rs1) == SUBREG)
3495 && RTX_OK_FOR_OFFSET_P (rs2)))
3500 else if ((REG_P (rs1) || GET_CODE (rs1) == SUBREG)
3501 && (REG_P (rs2) || GET_CODE (rs2) == SUBREG))
3503 /* We prohibit REG + REG for TFmode when there are no quad move insns
3504 and we consequently need to split. We do this because REG+REG
3505 is not an offsettable address. If we get the situation in reload
3506 where source and destination of a movtf pattern are both MEMs with
3507 REG+REG address, then only one of them gets converted to an
3508 offsettable address. */
3510 && ! (TARGET_FPU && TARGET_ARCH64 && TARGET_HARD_QUAD))
3513 /* We prohibit REG + REG on ARCH32 if not optimizing for
3514 DFmode/DImode because then mem_min_alignment is likely to be zero
3515 after reload and the forced split would lack a matching splitter
3517 if (TARGET_ARCH32 && !optimize
3518 && (mode == DFmode || mode == DImode))
3521 else if (USE_AS_OFFSETABLE_LO10
3522 && GET_CODE (rs1) == LO_SUM
3524 && ! TARGET_CM_MEDMID
3525 && RTX_OK_FOR_OLO10_P (rs2))
3529 imm1 = XEXP (rs1, 1);
3530 rs1 = XEXP (rs1, 0);
3531 if (! CONSTANT_P (imm1) || tls_symbolic_operand (rs1))
3535 else if (GET_CODE (addr) == LO_SUM)
3537 rs1 = XEXP (addr, 0);
3538 imm1 = XEXP (addr, 1);
3540 if (! CONSTANT_P (imm1) || tls_symbolic_operand (rs1))
3543 if (USE_AS_OFFSETABLE_LO10)
3545 /* We can't allow TFmode, because an offset greater than or equal to
3546 the alignment (8) may cause the LO_SUM to overflow if !v9. */
3547 if (mode == TFmode && ! TARGET_V9)
3552 /* We prohibit LO_SUM for TFmode when there are no quad move insns
3553 and we consequently need to split. We do this because LO_SUM
3554 is not an offsettable address. If we get the situation in reload
3555 where source and destination of a movtf pattern are both MEMs with
3556 LO_SUM address, then only one of them gets converted to an
3557 offsettable address. */
3559 && ! (TARGET_FPU && TARGET_ARCH64 && TARGET_HARD_QUAD))
3563 else if (GET_CODE (addr) == CONST_INT && SMALL_INT (addr))
3568 if (GET_CODE (rs1) == SUBREG)
3569 rs1 = SUBREG_REG (rs1);
3575 if (GET_CODE (rs2) == SUBREG)
3576 rs2 = SUBREG_REG (rs2);
3583 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1))
3584 || (rs2 && !REGNO_OK_FOR_BASE_P (REGNO (rs2))))
3589 if ((REGNO (rs1) >= 32
3590 && REGNO (rs1) != FRAME_POINTER_REGNUM
3591 && REGNO (rs1) < FIRST_PSEUDO_REGISTER)
3593 && (REGNO (rs2) >= 32
3594 && REGNO (rs2) != FRAME_POINTER_REGNUM
3595 && REGNO (rs2) < FIRST_PSEUDO_REGISTER)))
3601 /* Construct the SYMBOL_REF for the tls_get_offset function. */
3603 static GTY(()) rtx sparc_tls_symbol;
3605 sparc_tls_get_addr (void)
3607 if (!sparc_tls_symbol)
3608 sparc_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_addr");
3610 return sparc_tls_symbol;
3614 sparc_tls_got (void)
3619 current_function_uses_pic_offset_table = 1;
3620 return pic_offset_table_rtx;
3623 if (!global_offset_table)
3624 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3625 temp = gen_reg_rtx (Pmode);
3626 emit_move_insn (temp, global_offset_table);
3631 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3632 this (thread-local) address. */
3635 legitimize_tls_address (rtx addr)
3637 rtx temp1, temp2, temp3, ret, o0, got, insn;
3642 if (GET_CODE (addr) == SYMBOL_REF)
3643 switch (SYMBOL_REF_TLS_MODEL (addr))
3645 case TLS_MODEL_GLOBAL_DYNAMIC:
3647 temp1 = gen_reg_rtx (SImode);
3648 temp2 = gen_reg_rtx (SImode);
3649 ret = gen_reg_rtx (Pmode);
3650 o0 = gen_rtx_REG (Pmode, 8);
3651 got = sparc_tls_got ();
3652 emit_insn (gen_tgd_hi22 (temp1, addr));
3653 emit_insn (gen_tgd_lo10 (temp2, temp1, addr));
3656 emit_insn (gen_tgd_add32 (o0, got, temp2, addr));
3657 insn = emit_call_insn (gen_tgd_call32 (o0, sparc_tls_get_addr (),
3662 emit_insn (gen_tgd_add64 (o0, got, temp2, addr));
3663 insn = emit_call_insn (gen_tgd_call64 (o0, sparc_tls_get_addr (),
3666 CALL_INSN_FUNCTION_USAGE (insn)
3667 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
3668 CALL_INSN_FUNCTION_USAGE (insn));
3669 insn = get_insns ();
3671 emit_libcall_block (insn, ret, o0, addr);
3674 case TLS_MODEL_LOCAL_DYNAMIC:
3676 temp1 = gen_reg_rtx (SImode);
3677 temp2 = gen_reg_rtx (SImode);
3678 temp3 = gen_reg_rtx (Pmode);
3679 ret = gen_reg_rtx (Pmode);
3680 o0 = gen_rtx_REG (Pmode, 8);
3681 got = sparc_tls_got ();
3682 emit_insn (gen_tldm_hi22 (temp1));
3683 emit_insn (gen_tldm_lo10 (temp2, temp1));
3686 emit_insn (gen_tldm_add32 (o0, got, temp2));
3687 insn = emit_call_insn (gen_tldm_call32 (o0, sparc_tls_get_addr (),
3692 emit_insn (gen_tldm_add64 (o0, got, temp2));
3693 insn = emit_call_insn (gen_tldm_call64 (o0, sparc_tls_get_addr (),
3696 CALL_INSN_FUNCTION_USAGE (insn)
3697 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
3698 CALL_INSN_FUNCTION_USAGE (insn));
3699 insn = get_insns ();
3701 emit_libcall_block (insn, temp3, o0,
3702 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3703 UNSPEC_TLSLD_BASE));
3704 temp1 = gen_reg_rtx (SImode);
3705 temp2 = gen_reg_rtx (SImode);
3706 emit_insn (gen_tldo_hix22 (temp1, addr));
3707 emit_insn (gen_tldo_lox10 (temp2, temp1, addr));
3709 emit_insn (gen_tldo_add32 (ret, temp3, temp2, addr));
3711 emit_insn (gen_tldo_add64 (ret, temp3, temp2, addr));
3714 case TLS_MODEL_INITIAL_EXEC:
3715 temp1 = gen_reg_rtx (SImode);
3716 temp2 = gen_reg_rtx (SImode);
3717 temp3 = gen_reg_rtx (Pmode);
3718 got = sparc_tls_got ();
3719 emit_insn (gen_tie_hi22 (temp1, addr));
3720 emit_insn (gen_tie_lo10 (temp2, temp1, addr));
3722 emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
3724 emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
3727 ret = gen_reg_rtx (Pmode);
3729 emit_insn (gen_tie_add32 (ret, gen_rtx_REG (Pmode, 7),
3732 emit_insn (gen_tie_add64 (ret, gen_rtx_REG (Pmode, 7),
3736 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp3);
3739 case TLS_MODEL_LOCAL_EXEC:
3740 temp1 = gen_reg_rtx (Pmode);
3741 temp2 = gen_reg_rtx (Pmode);
3744 emit_insn (gen_tle_hix22_sp32 (temp1, addr));
3745 emit_insn (gen_tle_lox10_sp32 (temp2, temp1, addr));
3749 emit_insn (gen_tle_hix22_sp64 (temp1, addr));
3750 emit_insn (gen_tle_lox10_sp64 (temp2, temp1, addr));
3752 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp2);
3760 abort (); /* for now ... */
3766 /* Legitimize PIC addresses. If the address is already position-independent,
3767 we return ORIG. Newly generated position-independent addresses go into a
3768 reg. This is REG if nonzero, otherwise we allocate register(s) as
3772 legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
3775 if (GET_CODE (orig) == SYMBOL_REF)
3777 rtx pic_ref, address;
3782 if (reload_in_progress || reload_completed)
3785 reg = gen_reg_rtx (Pmode);
3790 /* If not during reload, allocate another temp reg here for loading
3791 in the address, so that these instructions can be optimized
3793 rtx temp_reg = ((reload_in_progress || reload_completed)
3794 ? reg : gen_reg_rtx (Pmode));
3796 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
3797 won't get confused into thinking that these two instructions
3798 are loading in the true address of the symbol. If in the
3799 future a PIC rtx exists, that should be used instead. */
3800 if (Pmode == SImode)
3802 emit_insn (gen_movsi_high_pic (temp_reg, orig));
3803 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
3807 emit_insn (gen_movdi_high_pic (temp_reg, orig));
3808 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
3815 pic_ref = gen_const_mem (Pmode,
3816 gen_rtx_PLUS (Pmode,
3817 pic_offset_table_rtx, address));
3818 current_function_uses_pic_offset_table = 1;
3819 insn = emit_move_insn (reg, pic_ref);
3820 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3822 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
3826 else if (GET_CODE (orig) == CONST)
3830 if (GET_CODE (XEXP (orig, 0)) == PLUS
3831 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3836 if (reload_in_progress || reload_completed)
3839 reg = gen_reg_rtx (Pmode);
3842 if (GET_CODE (XEXP (orig, 0)) == PLUS)
3844 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
3845 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
3846 base == reg ? 0 : reg);
3851 if (GET_CODE (offset) == CONST_INT)
3853 if (SMALL_INT (offset))
3854 return plus_constant (base, INTVAL (offset));
3855 else if (! reload_in_progress && ! reload_completed)
3856 offset = force_reg (Pmode, offset);
3858 /* If we reach here, then something is seriously wrong. */
3861 return gen_rtx_PLUS (Pmode, base, offset);
3863 else if (GET_CODE (orig) == LABEL_REF)
3864 /* ??? Why do we do this? */
3865 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
3866 the register is live instead, in case it is eliminated. */
3867 current_function_uses_pic_offset_table = 1;
3872 /* Try machine-dependent ways of modifying an illegitimate address X
3873 to be legitimate. If we find one, return the new, valid address.
3875 OLDX is the address as it was before break_out_memory_refs was called.
3876 In some cases it is useful to look at this to decide what needs to be done.
3878 MODE is the mode of the operand pointed to by X. */
3881 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
3885 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT)
3886 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3887 force_operand (XEXP (x, 0), NULL_RTX));
3888 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == MULT)
3889 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3890 force_operand (XEXP (x, 1), NULL_RTX));
3891 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS)
3892 x = gen_rtx_PLUS (Pmode, force_operand (XEXP (x, 0), NULL_RTX),
3894 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == PLUS)
3895 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3896 force_operand (XEXP (x, 1), NULL_RTX));
3898 if (x != orig_x && legitimate_address_p (mode, x, FALSE))
3901 if (tls_symbolic_operand (x))
3902 x = legitimize_tls_address (x);
3904 x = legitimize_pic_address (x, mode, 0);
3905 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 1)))
3906 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3907 copy_to_mode_reg (Pmode, XEXP (x, 1)));
3908 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 0)))
3909 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3910 copy_to_mode_reg (Pmode, XEXP (x, 0)));
3911 else if (GET_CODE (x) == SYMBOL_REF
3912 || GET_CODE (x) == CONST
3913 || GET_CODE (x) == LABEL_REF)
3914 x = copy_to_suggested_reg (x, NULL_RTX, Pmode);
3918 /* Emit the special PIC prologue. */
3921 load_pic_register (void)
3923 int orig_flag_pic = flag_pic;
3925 /* If we haven't emitted the special helper function, do so now. */
3926 if (add_pc_to_pic_symbol_name[0] == 0)
3928 const char *pic_name = reg_names[REGNO (pic_offset_table_rtx)];
3931 ASM_GENERATE_INTERNAL_LABEL (add_pc_to_pic_symbol_name, "LADDPC", 0);
3934 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
3936 ASM_OUTPUT_ALIGN (asm_out_file, align);
3937 ASM_OUTPUT_LABEL (asm_out_file, add_pc_to_pic_symbol_name);
3938 if (flag_delayed_branch)
3939 fprintf (asm_out_file, "\tjmp %%o7+8\n\t add\t%%o7, %s, %s\n",
3940 pic_name, pic_name);
3942 fprintf (asm_out_file, "\tadd\t%%o7, %s, %s\n\tjmp %%o7+8\n\t nop\n",
3943 pic_name, pic_name);
3946 /* Initialize every time through, since we can't easily
3947 know this to be permanent. */
3948 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3949 add_pc_to_pic_symbol = gen_rtx_SYMBOL_REF (Pmode, add_pc_to_pic_symbol_name);
3952 emit_insn (gen_load_pcrel_sym (pic_offset_table_rtx, global_offset_table,
3953 add_pc_to_pic_symbol));
3954 flag_pic = orig_flag_pic;
3956 /* Need to emit this whether or not we obey regdecls,
3957 since setjmp/longjmp can cause life info to screw up.
3958 ??? In the case where we don't obey regdecls, this is not sufficient
3959 since we may not fall out the bottom. */
3960 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3963 /* Return 1 if RTX is a MEM which is known to be aligned to at
3964 least a DESIRED byte boundary. */
3967 mem_min_alignment (rtx mem, int desired)
3969 rtx addr, base, offset;
3971 /* If it's not a MEM we can't accept it. */
3972 if (GET_CODE (mem) != MEM)
3975 addr = XEXP (mem, 0);
3976 base = offset = NULL_RTX;
3977 if (GET_CODE (addr) == PLUS)
3979 if (GET_CODE (XEXP (addr, 0)) == REG)
3981 base = XEXP (addr, 0);
3983 /* What we are saying here is that if the base
3984 REG is aligned properly, the compiler will make
3985 sure any REG based index upon it will be so
3987 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3988 offset = XEXP (addr, 1);
3990 offset = const0_rtx;
3993 else if (GET_CODE (addr) == REG)
3996 offset = const0_rtx;
3999 if (base != NULL_RTX)
4001 int regno = REGNO (base);
4003 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
4005 /* Check if the compiler has recorded some information
4006 about the alignment of the base REG. If reload has
4007 completed, we already matched with proper alignments.
4008 If not running global_alloc, reload might give us
4009 unaligned pointer to local stack though. */
4011 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
4012 || (optimize && reload_completed))
4013 && (INTVAL (offset) & (desired - 1)) == 0)
4018 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
4022 else if (! TARGET_UNALIGNED_DOUBLES
4023 || CONSTANT_P (addr)
4024 || GET_CODE (addr) == LO_SUM)
4026 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
4027 is true, in which case we can only assume that an access is aligned if
4028 it is to a constant address, or the address involves a LO_SUM. */
4032 /* An obviously unaligned address. */
4037 /* Vectors to keep interesting information about registers where it can easily
4038 be got. We used to use the actual mode value as the bit number, but there
4039 are more than 32 modes now. Instead we use two tables: one indexed by
4040 hard register number, and one indexed by mode. */
4042 /* The purpose of sparc_mode_class is to shrink the range of modes so that
4043 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
4044 mapped into one sparc_mode_class mode. */
4046 enum sparc_mode_class {
4047 S_MODE, D_MODE, T_MODE, O_MODE,
4048 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
4052 /* Modes for single-word and smaller quantities. */
4053 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
4055 /* Modes for double-word and smaller quantities. */
4056 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
4058 /* Modes for quad-word and smaller quantities. */
4059 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
4061 /* Modes for 8-word and smaller quantities. */
4062 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
4064 /* Modes for single-float quantities. We must allow any single word or
4065 smaller quantity. This is because the fix/float conversion instructions
4066 take integer inputs/outputs from the float registers. */
4067 #define SF_MODES (S_MODES)
4069 /* Modes for double-float and smaller quantities. */
4070 #define DF_MODES (S_MODES | D_MODES)
4072 /* Modes for double-float only quantities. */
4073 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
4075 /* Modes for quad-float only quantities. */
4076 #define TF_ONLY_MODES (1 << (int) TF_MODE)
4078 /* Modes for quad-float and smaller quantities. */
4079 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
4081 /* Modes for quad-float and double-float quantities. */
4082 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
4084 /* Modes for quad-float pair only quantities. */
4085 #define OF_ONLY_MODES (1 << (int) OF_MODE)
4087 /* Modes for quad-float pairs and smaller quantities. */
4088 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
4090 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
4092 /* Modes for condition codes. */
4093 #define CC_MODES (1 << (int) CC_MODE)
4094 #define CCFP_MODES (1 << (int) CCFP_MODE)
4096 /* Value is 1 if register/mode pair is acceptable on sparc.
4097 The funny mixture of D and T modes is because integer operations
4098 do not specially operate on tetra quantities, so non-quad-aligned
4099 registers can hold quadword quantities (except %o4 and %i4 because
4100 they cross fixed registers). */
4102 /* This points to either the 32 bit or the 64 bit version. */
4103 const int *hard_regno_mode_classes;
4105 static const int hard_32bit_mode_classes[] = {
4106 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
4107 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
4108 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
4109 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
4111 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4112 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4113 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4114 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
4116 /* FP regs f32 to f63. Only the even numbered registers actually exist,
4117 and none can hold SFmode/SImode values. */
4118 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4119 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4120 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4121 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4124 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
4130 static const int hard_64bit_mode_classes[] = {
4131 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4132 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4133 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4134 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4136 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4137 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4138 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4139 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
4141 /* FP regs f32 to f63. Only the even numbered registers actually exist,
4142 and none can hold SFmode/SImode values. */
4143 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4144 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4145 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4146 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4149 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
4155 int sparc_mode_class [NUM_MACHINE_MODES];
4157 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
4160 sparc_init_modes (void)
4164 for (i = 0; i < NUM_MACHINE_MODES; i++)
4166 switch (GET_MODE_CLASS (i))
4169 case MODE_PARTIAL_INT:
4170 case MODE_COMPLEX_INT:
4171 if (GET_MODE_SIZE (i) <= 4)
4172 sparc_mode_class[i] = 1 << (int) S_MODE;
4173 else if (GET_MODE_SIZE (i) == 8)
4174 sparc_mode_class[i] = 1 << (int) D_MODE;
4175 else if (GET_MODE_SIZE (i) == 16)
4176 sparc_mode_class[i] = 1 << (int) T_MODE;
4177 else if (GET_MODE_SIZE (i) == 32)
4178 sparc_mode_class[i] = 1 << (int) O_MODE;
4180 sparc_mode_class[i] = 0;
4183 case MODE_COMPLEX_FLOAT:
4184 if (GET_MODE_SIZE (i) <= 4)
4185 sparc_mode_class[i] = 1 << (int) SF_MODE;
4186 else if (GET_MODE_SIZE (i) == 8)
4187 sparc_mode_class[i] = 1 << (int) DF_MODE;
4188 else if (GET_MODE_SIZE (i) == 16)
4189 sparc_mode_class[i] = 1 << (int) TF_MODE;
4190 else if (GET_MODE_SIZE (i) == 32)
4191 sparc_mode_class[i] = 1 << (int) OF_MODE;
4193 sparc_mode_class[i] = 0;
4196 if (i == (int) CCFPmode || i == (int) CCFPEmode)
4197 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
4199 sparc_mode_class[i] = 1 << (int) CC_MODE;
4202 sparc_mode_class[i] = 0;
4208 hard_regno_mode_classes = hard_64bit_mode_classes;
4210 hard_regno_mode_classes = hard_32bit_mode_classes;
4212 /* Initialize the array used by REGNO_REG_CLASS. */
4213 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4215 if (i < 16 && TARGET_V8PLUS)
4216 sparc_regno_reg_class[i] = I64_REGS;
4217 else if (i < 32 || i == FRAME_POINTER_REGNUM)
4218 sparc_regno_reg_class[i] = GENERAL_REGS;
4220 sparc_regno_reg_class[i] = FP_REGS;
4222 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
4224 sparc_regno_reg_class[i] = FPCC_REGS;
4226 sparc_regno_reg_class[i] = NO_REGS;
4230 /* Compute the frame size required by the function. This function is called
4231 during the reload pass and also by sparc_expand_prologue. */
4234 sparc_compute_frame_size (HOST_WIDE_INT size, int leaf_function_p)
4236 int outgoing_args_size = (current_function_outgoing_args_size
4237 + REG_PARM_STACK_SPACE (current_function_decl));
4238 int n_regs = 0; /* N_REGS is the number of 4-byte regs saved thus far. */
4243 for (i = 0; i < 8; i++)
4244 if (regs_ever_live[i] && ! call_used_regs[i])
4249 for (i = 0; i < 8; i += 2)
4250 if ((regs_ever_live[i] && ! call_used_regs[i])
4251 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
4255 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
4256 if ((regs_ever_live[i] && ! call_used_regs[i])
4257 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
4260 /* Set up values for use in prologue and epilogue. */
4261 num_gfregs = n_regs;
4266 && current_function_outgoing_args_size == 0)
4267 actual_fsize = apparent_fsize = 0;
4270 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
4271 apparent_fsize = (size - STARTING_FRAME_OFFSET + 7) & -8;
4272 apparent_fsize += n_regs * 4;
4273 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
4276 /* Make sure nothing can clobber our register windows.
4277 If a SAVE must be done, or there is a stack-local variable,
4278 the register window area must be allocated.
4279 ??? For v8 we apparently need an additional 8 bytes of reserved space. */
4280 if (! leaf_function_p || size > 0)
4281 actual_fsize += (16 * UNITS_PER_WORD) + (TARGET_ARCH64 ? 0 : 8);
4283 return SPARC_STACK_ALIGN (actual_fsize);
4286 /* Output any necessary .register pseudo-ops. */
4289 sparc_output_scratch_registers (FILE *file ATTRIBUTE_UNUSED)
4291 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
4297 /* Check if %g[2367] were used without
4298 .register being printed for them already. */
4299 for (i = 2; i < 8; i++)
4301 if (regs_ever_live [i]
4302 && ! sparc_hard_reg_printed [i])
4304 sparc_hard_reg_printed [i] = 1;
4305 fprintf (file, "\t.register\t%%g%d, #scratch\n", i);
4312 /* Save/restore call-saved registers from LOW to HIGH at BASE+OFFSET
4313 as needed. LOW should be double-word aligned for 32-bit registers.
4314 Return the new OFFSET. */
4317 #define SORR_RESTORE 1
4320 save_or_restore_regs (int low, int high, rtx base, int offset, int action)
4325 if (TARGET_ARCH64 && high <= 32)
4327 for (i = low; i < high; i++)
4329 if (regs_ever_live[i] && ! call_used_regs[i])
4331 mem = gen_rtx_MEM (DImode, plus_constant (base, offset));
4332 set_mem_alias_set (mem, sparc_sr_alias_set);
4333 if (action == SORR_SAVE)
4335 insn = emit_move_insn (mem, gen_rtx_REG (DImode, i));
4336 RTX_FRAME_RELATED_P (insn) = 1;
4338 else /* action == SORR_RESTORE */
4339 emit_move_insn (gen_rtx_REG (DImode, i), mem);
4346 for (i = low; i < high; i += 2)
4348 bool reg0 = regs_ever_live[i] && ! call_used_regs[i];
4349 bool reg1 = regs_ever_live[i+1] && ! call_used_regs[i+1];
4350 enum machine_mode mode;
4355 mode = i < 32 ? DImode : DFmode;
4360 mode = i < 32 ? SImode : SFmode;
4365 mode = i < 32 ? SImode : SFmode;
4372 mem = gen_rtx_MEM (mode, plus_constant (base, offset));
4373 set_mem_alias_set (mem, sparc_sr_alias_set);
4374 if (action == SORR_SAVE)
4376 insn = emit_move_insn (mem, gen_rtx_REG (mode, regno));
4377 RTX_FRAME_RELATED_P (insn) = 1;
4379 else /* action == SORR_RESTORE */
4380 emit_move_insn (gen_rtx_REG (mode, regno), mem);
4382 /* Always preserve double-word alignment. */
4383 offset = (offset + 7) & -8;
4390 /* Emit code to save call-saved registers. */
4393 emit_save_regs (void)
4395 HOST_WIDE_INT offset;
4398 offset = frame_base_offset - apparent_fsize;
4400 if (offset < -4096 || offset + num_gfregs * 4 > 4096)
4402 /* ??? This might be optimized a little as %g1 might already have a
4403 value close enough that a single add insn will do. */
4404 /* ??? Although, all of this is probably only a temporary fix
4405 because if %g1 can hold a function result, then
4406 sparc_expand_epilogue will lose (the result will be
4408 base = gen_rtx_REG (Pmode, 1);
4409 emit_move_insn (base, GEN_INT (offset));
4410 emit_insn (gen_rtx_SET (VOIDmode,
4412 gen_rtx_PLUS (Pmode, frame_base_reg, base)));
4416 base = frame_base_reg;
4418 offset = save_or_restore_regs (0, 8, base, offset, SORR_SAVE);
4419 save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, SORR_SAVE);
4422 /* Emit code to restore call-saved registers. */
4425 emit_restore_regs (void)
4427 HOST_WIDE_INT offset;
4430 offset = frame_base_offset - apparent_fsize;
4432 if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/)
4434 base = gen_rtx_REG (Pmode, 1);
4435 emit_move_insn (base, GEN_INT (offset));
4436 emit_insn (gen_rtx_SET (VOIDmode,
4438 gen_rtx_PLUS (Pmode, frame_base_reg, base)));
4442 base = frame_base_reg;
4444 offset = save_or_restore_regs (0, 8, base, offset, SORR_RESTORE);
4445 save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, SORR_RESTORE);
4448 /* Emit an increment for the stack pointer. */
4451 emit_stack_pointer_increment (rtx increment)
4454 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx, increment));
4456 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, increment));
4459 /* Emit a decrement for the stack pointer. */
4462 emit_stack_pointer_decrement (rtx decrement)
4465 emit_insn (gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, decrement));
4467 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, decrement));
4470 /* Expand the function prologue. The prologue is responsible for reserving
4471 storage for the frame, saving the call-saved registers and loading the
4472 PIC register if needed. */
4475 sparc_expand_prologue (void)
4477 /* Compute a snapshot of current_function_uses_only_leaf_regs. Relying
4478 on the final value of the flag means deferring the prologue/epilogue
4479 expansion until just before the second scheduling pass, which is too
4480 late to emit multiple epilogues or return insns.
4482 Of course we are making the assumption that the value of the flag
4483 will not change between now and its final value. Of the three parts
4484 of the formula, only the last one can reasonably vary. Let's take a
4485 closer look, after assuming that the first two ones are set to true
4486 (otherwise the last value is effectively silenced).
4488 If only_leaf_regs_used returns false, the global predicate will also
4489 be false so the actual frame size calculated below will be positive.
4490 As a consequence, the save_register_window insn will be emitted in
4491 the instruction stream; now this insn explicitly references %fp
4492 which is not a leaf register so only_leaf_regs_used will always
4493 return false subsequently.
4495 If only_leaf_regs_used returns true, we hope that the subsequent
4496 optimization passes won't cause non-leaf registers to pop up. For
4497 example, the regrename pass has special provisions to not rename to
4498 non-leaf registers in a leaf function. */
4499 sparc_leaf_function_p
4500 = optimize > 0 && leaf_function_p () && only_leaf_regs_used ();
4502 /* Need to use actual_fsize, since we are also allocating
4503 space for our callee (and our own register save area). */
4505 = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p);
4507 /* Advertise that the data calculated just above are now valid. */
4508 sparc_prologue_data_valid_p = true;
4510 if (sparc_leaf_function_p)
4512 frame_base_reg = stack_pointer_rtx;
4513 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
4517 frame_base_reg = hard_frame_pointer_rtx;
4518 frame_base_offset = SPARC_STACK_BIAS;
4521 if (actual_fsize == 0)
4523 else if (sparc_leaf_function_p)
4525 if (actual_fsize <= 4096)
4526 emit_stack_pointer_increment (GEN_INT (- actual_fsize));
4527 else if (actual_fsize <= 8192)
4529 emit_stack_pointer_increment (GEN_INT (-4096));
4530 emit_stack_pointer_increment (GEN_INT (4096 - actual_fsize));
4534 rtx reg = gen_rtx_REG (Pmode, 1);
4535 emit_move_insn (reg, GEN_INT (-actual_fsize));
4536 emit_stack_pointer_increment (reg);
4541 if (actual_fsize <= 4096)
4542 emit_insn (gen_save_register_window (GEN_INT (-actual_fsize)));
4543 else if (actual_fsize <= 8192)
4545 emit_insn (gen_save_register_window (GEN_INT (-4096)));
4546 emit_stack_pointer_increment (GEN_INT (4096 - actual_fsize));
4550 rtx reg = gen_rtx_REG (Pmode, 1);
4551 emit_move_insn (reg, GEN_INT (-actual_fsize));
4552 emit_insn (gen_save_register_window (reg));
4556 /* Call-saved registers are saved just above the outgoing argument area. */
4560 /* Load the PIC register if needed. */
4561 if (flag_pic && current_function_uses_pic_offset_table)
4562 load_pic_register ();
4565 /* This function generates the assembly code for function entry, which boils
4566 down to emitting the necessary .register directives. It also informs the
4567 DWARF-2 back-end on the layout of the frame.
4569 ??? Historical cruft: "On SPARC, move-double insns between fpu and cpu need
4570 an 8-byte block of memory. If any fpu reg is used in the function, we
4571 allocate such a block here, at the bottom of the frame, just in case it's
4572 needed." Could this explain the -8 in emit_restore_regs? */
4575 sparc_asm_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4577 /* Check that the assumption we made in sparc_expand_prologue is valid. */
4578 if (sparc_leaf_function_p != current_function_uses_only_leaf_regs)
4581 sparc_output_scratch_registers (file);
4583 if (dwarf2out_do_frame () && actual_fsize)
4585 char *label = dwarf2out_cfi_label ();
4587 /* The canonical frame address refers to the top of the frame. */
4588 dwarf2out_def_cfa (label,
4589 sparc_leaf_function_p
4590 ? STACK_POINTER_REGNUM
4591 : HARD_FRAME_POINTER_REGNUM,
4594 if (! sparc_leaf_function_p)
4596 /* Note the register window save. This tells the unwinder that
4597 it needs to restore the window registers from the previous
4598 frame's window save area at 0(cfa). */
4599 dwarf2out_window_save (label);
4601 /* The return address (-8) is now in %i7. */
4602 dwarf2out_return_reg (label, 31);
4607 /* Expand the function epilogue, either normal or part of a sibcall.
4608 We emit all the instructions except the return or the call. */
4611 sparc_expand_epilogue (void)
4614 emit_restore_regs ();
4616 if (actual_fsize == 0)
4618 else if (sparc_leaf_function_p)
4620 if (actual_fsize <= 4096)
4621 emit_stack_pointer_decrement (GEN_INT (- actual_fsize));
4622 else if (actual_fsize <= 8192)
4624 emit_stack_pointer_decrement (GEN_INT (-4096));
4625 emit_stack_pointer_decrement (GEN_INT (4096 - actual_fsize));
4629 rtx reg = gen_rtx_REG (Pmode, 1);
4630 emit_move_insn (reg, GEN_INT (-actual_fsize));
4631 emit_stack_pointer_decrement (reg);
4636 /* Return true if it is appropriate to emit `return' instructions in the
4637 body of a function. */
4640 sparc_can_use_return_insn_p (void)
4642 return sparc_prologue_data_valid_p
4643 && (actual_fsize == 0 || !sparc_leaf_function_p);
4646 /* This function generates the assembly code for function exit. */
4649 sparc_asm_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4651 /* If code does not drop into the epilogue, we have to still output
4652 a dummy nop for the sake of sane backtraces. Otherwise, if the
4653 last two instructions of a function were "call foo; dslot;" this
4654 can make the return PC of foo (i.e. address of call instruction
4655 plus 8) point to the first instruction in the next function. */
4657 rtx insn, last_real_insn;
4659 insn = get_last_insn ();
4661 last_real_insn = prev_real_insn (insn);
4663 && GET_CODE (last_real_insn) == INSN
4664 && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE)
4665 last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0);
4667 if (last_real_insn && GET_CODE (last_real_insn) == CALL_INSN)
4668 fputs("\tnop\n", file);
4670 sparc_output_deferred_case_vectors ();
4673 /* Output a 'restore' instruction. */
4676 output_restore (rtx pat)
4682 fputs ("\t restore\n", asm_out_file);
4686 if (GET_CODE (pat) != SET)
4689 operands[0] = SET_DEST (pat);
4690 pat = SET_SRC (pat);
4692 switch (GET_CODE (pat))
4695 operands[1] = XEXP (pat, 0);
4696 operands[2] = XEXP (pat, 1);
4697 output_asm_insn (" restore %r1, %2, %Y0", operands);
4700 operands[1] = XEXP (pat, 0);
4701 operands[2] = XEXP (pat, 1);
4702 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
4705 operands[1] = XEXP (pat, 0);
4706 if (XEXP (pat, 1) != const1_rtx)
4708 output_asm_insn (" restore %r1, %r1, %Y0", operands);
4712 output_asm_insn (" restore %%g0, %1, %Y0", operands);
4717 /* Output a return. */
4720 output_return (rtx insn)
4722 if (sparc_leaf_function_p)
4724 /* This is a leaf function so we don't have to bother restoring the
4725 register window, which frees us from dealing with the convoluted
4726 semantics of restore/return. We simply output the jump to the
4727 return address and the insn in the delay slot (if any). */
4729 if (current_function_calls_eh_return)
4732 return "jmp\t%%o7+%)%#";
4736 /* This is a regular function so we have to restore the register window.
4737 We may have a pending insn for the delay slot, which will be either
4738 combined with the 'restore' instruction or put in the delay slot of
4739 the 'return' instruction. */
4741 if (current_function_calls_eh_return)
4743 /* If the function uses __builtin_eh_return, the eh_return
4744 machinery occupies the delay slot. */
4748 if (! flag_delayed_branch)
4749 fputs ("\tadd\t%fp, %g1, %fp\n", asm_out_file);
4752 fputs ("\treturn\t%i7+8\n", asm_out_file);
4754 fputs ("\trestore\n\tjmp\t%o7+8\n", asm_out_file);
4756 if (flag_delayed_branch)
4757 fputs ("\t add\t%sp, %g1, %sp\n", asm_out_file);
4759 fputs ("\t nop\n", asm_out_file);
4761 else if (final_sequence)
4765 delay = NEXT_INSN (insn);
4769 pat = PATTERN (delay);
4771 if (TARGET_V9 && ! epilogue_renumber (&pat, 1))
4773 epilogue_renumber (&pat, 0);
4774 return "return\t%%i7+%)%#";
4778 output_asm_insn ("jmp\t%%i7+%)", NULL);
4779 output_restore (pat);
4780 PATTERN (delay) = gen_blockage ();
4781 INSN_CODE (delay) = -1;
4786 /* The delay slot is empty. */
4788 return "return\t%%i7+%)\n\t nop";
4789 else if (flag_delayed_branch)
4790 return "jmp\t%%i7+%)\n\t restore";
4792 return "restore\n\tjmp\t%%o7+%)\n\t nop";
4799 /* Output a sibling call. */
4802 output_sibcall (rtx insn, rtx call_operand)
4806 if (! flag_delayed_branch)
4809 operands[0] = call_operand;
4811 if (sparc_leaf_function_p)
4813 /* This is a leaf function so we don't have to bother restoring the
4814 register window. We simply output the jump to the function and
4815 the insn in the delay slot (if any). */
4817 if (LEAF_SIBCALL_SLOT_RESERVED_P && final_sequence)
4821 output_asm_insn ("sethi\t%%hi(%a0), %%g1\n\tjmp\t%%g1 + %%lo(%a0)%#",
4824 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
4825 it into branch if possible. */
4826 output_asm_insn ("or\t%%o7, %%g0, %%g1\n\tcall\t%a0, 0\n\t or\t%%g1, %%g0, %%o7",
4831 /* This is a regular function so we have to restore the register window.
4832 We may have a pending insn for the delay slot, which will be combined
4833 with the 'restore' instruction. */
4835 output_asm_insn ("call\t%a0, 0", operands);
4839 rtx delay = NEXT_INSN (insn);
4843 output_restore (PATTERN (delay));
4845 PATTERN (delay) = gen_blockage ();
4846 INSN_CODE (delay) = -1;
4849 output_restore (NULL_RTX);
4855 /* Functions for handling argument passing.
4857 For 32-bit, the first 6 args are normally in registers and the rest are
4858 pushed. Any arg that starts within the first 6 words is at least
4859 partially passed in a register unless its data type forbids.
4861 For 64-bit, the argument registers are laid out as an array of 16 elements
4862 and arguments are added sequentially. The first 6 int args and up to the
4863 first 16 fp args (depending on size) are passed in regs.
4865 Slot Stack Integral Float Float in structure Double Long Double
4866 ---- ----- -------- ----- ------------------ ------ -----------
4867 15 [SP+248] %f31 %f30,%f31 %d30
4868 14 [SP+240] %f29 %f28,%f29 %d28 %q28
4869 13 [SP+232] %f27 %f26,%f27 %d26
4870 12 [SP+224] %f25 %f24,%f25 %d24 %q24
4871 11 [SP+216] %f23 %f22,%f23 %d22
4872 10 [SP+208] %f21 %f20,%f21 %d20 %q20
4873 9 [SP+200] %f19 %f18,%f19 %d18
4874 8 [SP+192] %f17 %f16,%f17 %d16 %q16
4875 7 [SP+184] %f15 %f14,%f15 %d14
4876 6 [SP+176] %f13 %f12,%f13 %d12 %q12
4877 5 [SP+168] %o5 %f11 %f10,%f11 %d10
4878 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
4879 3 [SP+152] %o3 %f7 %f6,%f7 %d6
4880 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
4881 1 [SP+136] %o1 %f3 %f2,%f3 %d2
4882 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
4884 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
4886 Integral arguments are always passed as 64-bit quantities appropriately
4889 Passing of floating point values is handled as follows.
4890 If a prototype is in scope:
4891 If the value is in a named argument (i.e. not a stdarg function or a
4892 value not part of the `...') then the value is passed in the appropriate
4894 If the value is part of the `...' and is passed in one of the first 6
4895 slots then the value is passed in the appropriate int reg.
4896 If the value is part of the `...' and is not passed in one of the first 6
4897 slots then the value is passed in memory.
4898 If a prototype is not in scope:
4899 If the value is one of the first 6 arguments the value is passed in the
4900 appropriate integer reg and the appropriate fp reg.
4901 If the value is not one of the first 6 arguments the value is passed in
4902 the appropriate fp reg and in memory.
4905 Summary of the calling conventions implemented by GCC on SPARC:
4908 size argument return value
4910 small integer <4 int. reg. int. reg.
4911 word 4 int. reg. int. reg.
4912 double word 8 int. reg. int. reg.
4914 _Complex small integer <8 int. reg. int. reg.
4915 _Complex word 8 int. reg. int. reg.
4916 _Complex double word 16 memory int. reg.
4918 vector integer <=8 int. reg. FP reg.
4919 vector integer >8 memory memory
4921 float 4 int. reg. FP reg.
4922 double 8 int. reg. FP reg.
4923 long double 16 memory memory
4925 _Complex float 8 memory FP reg.
4926 _Complex double 16 memory FP reg.
4927 _Complex long double 32 memory FP reg.
4929 vector float <=32 memory FP reg.
4930 vector float >32 memory memory
4932 aggregate any memory memory
4937 size argument return value
4939 small integer <8 int. reg. int. reg.
4940 word 8 int. reg. int. reg.
4941 double word 16 int. reg. int. reg.
4943 _Complex small integer <16 int. reg. int. reg.
4944 _Complex word 16 int. reg. int. reg.
4945 _Complex double word 32 memory int. reg.
4947 vector integer <=16 FP reg. FP reg.
4948 vector integer 16<s<=32 memory FP reg.
4949 vector integer >32 memory memory
4951 float 4 FP reg. FP reg.
4952 double 8 FP reg. FP reg.
4953 long double 16 FP reg. FP reg.
4955 _Complex float 8 FP reg. FP reg.
4956 _Complex double 16 FP reg. FP reg.
4957 _Complex long double 32 memory FP reg.
4959 vector float <=16 FP reg. FP reg.
4960 vector float 16<s<=32 memory FP reg.
4961 vector float >32 memory memory
4963 aggregate <=16 reg. reg.
4964 aggregate 16<s<=32 memory reg.
4965 aggregate >32 memory memory
4969 Note #1: complex floating-point types follow the extended SPARC ABIs as
4970 implemented by the Sun compiler.
4972 Note #2: integral vector types follow the scalar floating-point types
4973 conventions to match what is implemented by the Sun VIS SDK.
4975 Note #3: floating-point vector types follow the complex floating-point
4976 types conventions. */
4979 /* Maximum number of int regs for args. */
4980 #define SPARC_INT_ARG_MAX 6
4981 /* Maximum number of fp regs for args. */
4982 #define SPARC_FP_ARG_MAX 16
4984 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
4986 /* Handle the INIT_CUMULATIVE_ARGS macro.
4987 Initialize a variable CUM of type CUMULATIVE_ARGS
4988 for a call to a function whose data type is FNTYPE.
4989 For a library call, FNTYPE is 0. */
4992 init_cumulative_args (struct sparc_args *cum, tree fntype,
4993 rtx libname ATTRIBUTE_UNUSED,
4994 tree fndecl ATTRIBUTE_UNUSED)
4997 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
4998 cum->libcall_p = fntype == 0;
5001 /* Handle the TARGET_PROMOTE_PROTOTYPES target hook.
5002 When a prototype says `char' or `short', really pass an `int'. */
5005 sparc_promote_prototypes (tree fntype ATTRIBUTE_UNUSED)
5007 return TARGET_ARCH32 ? true : false;
5010 /* Handle the TARGET_STRICT_ARGUMENT_NAMING target hook. */
5013 sparc_strict_argument_naming (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED)
5015 return TARGET_ARCH64 ? true : false;
5018 /* Scan the record type TYPE and return the following predicates:
5019 - INTREGS_P: the record contains at least one field or sub-field
5020 that is eligible for promotion in integer registers.
5021 - FP_REGS_P: the record contains at least one field or sub-field
5022 that is eligible for promotion in floating-point registers.
5023 - PACKED_P: the record contains at least one field that is packed.
5025 Sub-fields are not taken into account for the PACKED_P predicate. */
5028 scan_record_type (tree type, int *intregs_p, int *fpregs_p, int *packed_p)
5032 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5034 if (TREE_CODE (field) == FIELD_DECL)
5036 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
5037 scan_record_type (TREE_TYPE (field), intregs_p, fpregs_p, 0);
5038 else if (FLOAT_TYPE_P (TREE_TYPE (field)) && TARGET_FPU)
5043 if (packed_p && DECL_PACKED (field))
5049 /* Compute the slot number to pass an argument in.
5050 Return the slot number or -1 if passing on the stack.
5052 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5053 the preceding args and about the function being called.
5054 MODE is the argument's machine mode.
5055 TYPE is the data type of the argument (as a tree).
5056 This is null for libcalls where that information may
5058 NAMED is nonzero if this argument is a named parameter
5059 (otherwise it is an extra parameter matching an ellipsis).
5060 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
5061 *PREGNO records the register number to use if scalar type.
5062 *PPADDING records the amount of padding needed in words. */
5065 function_arg_slotno (const struct sparc_args *cum, enum machine_mode mode,
5066 tree type, int named, int incoming_p,
5067 int *pregno, int *ppadding)
5069 int regbase = (incoming_p
5070 ? SPARC_INCOMING_INT_ARG_FIRST
5071 : SPARC_OUTGOING_INT_ARG_FIRST);
5072 int slotno = cum->words;
5077 if (type && TREE_ADDRESSABLE (type))
5083 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
5086 /* For SPARC64, objects requiring 16-byte alignment get it. */
5088 && GET_MODE_ALIGNMENT (mode) >= 2 * BITS_PER_WORD
5089 && (slotno & 1) != 0)
5090 slotno++, *ppadding = 1;
5092 switch (GET_MODE_CLASS (mode))
5095 case MODE_COMPLEX_FLOAT:
5096 case MODE_VECTOR_INT:
5097 case MODE_VECTOR_FLOAT:
5098 if (TARGET_ARCH64 && TARGET_FPU && named)
5100 if (slotno >= SPARC_FP_ARG_MAX)
5102 regno = SPARC_FP_ARG_FIRST + slotno * 2;
5103 /* Arguments filling only one single FP register are
5104 right-justified in the outer double FP register. */
5105 if (GET_MODE_SIZE (mode) <= 4)
5112 case MODE_COMPLEX_INT:
5113 if (slotno >= SPARC_INT_ARG_MAX)
5115 regno = regbase + slotno;
5119 if (mode == VOIDmode)
5120 /* MODE is VOIDmode when generating the actual call. */
5123 if (mode != BLKmode)
5126 /* For SPARC64, objects requiring 16-byte alignment get it. */
5129 && TYPE_ALIGN (type) >= 2 * BITS_PER_WORD
5130 && (slotno & 1) != 0)
5131 slotno++, *ppadding = 1;
5133 if (TARGET_ARCH32 || (type && TREE_CODE (type) == UNION_TYPE))
5135 if (slotno >= SPARC_INT_ARG_MAX)
5137 regno = regbase + slotno;
5139 else /* TARGET_ARCH64 && type && TREE_CODE (type) == RECORD_TYPE */
5141 int intregs_p = 0, fpregs_p = 0, packed_p = 0;
5143 /* First see what kinds of registers we would need. */
5144 scan_record_type (type, &intregs_p, &fpregs_p, &packed_p);
5146 /* The ABI obviously doesn't specify how packed structures
5147 are passed. These are defined to be passed in int regs
5148 if possible, otherwise memory. */
5149 if (packed_p || !named)
5150 fpregs_p = 0, intregs_p = 1;
5152 /* If all arg slots are filled, then must pass on stack. */
5153 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
5156 /* If there are only int args and all int arg slots are filled,
5157 then must pass on stack. */
5158 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
5161 /* Note that even if all int arg slots are filled, fp members may
5162 still be passed in regs if such regs are available.
5163 *PREGNO isn't set because there may be more than one, it's up
5164 to the caller to compute them. */
5177 /* Handle recursive register counting for structure field layout. */
5179 struct function_arg_record_value_parms
5181 rtx ret; /* return expression being built. */
5182 int slotno; /* slot number of the argument. */
5183 int named; /* whether the argument is named. */
5184 int regbase; /* regno of the base register. */
5185 int stack; /* 1 if part of the argument is on the stack. */
5186 int intoffset; /* offset of the first pending integer field. */
5187 unsigned int nregs; /* number of words passed in registers. */
5190 static void function_arg_record_value_3
5191 (HOST_WIDE_INT, struct function_arg_record_value_parms *);
5192 static void function_arg_record_value_2
5193 (tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
5194 static void function_arg_record_value_1
5195 (tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
5196 static rtx function_arg_record_value (tree, enum machine_mode, int, int, int);
5197 static rtx function_arg_union_value (int, enum machine_mode, int);
5199 /* A subroutine of function_arg_record_value. Traverse the structure
5200 recursively and determine how many registers will be required. */
5203 function_arg_record_value_1 (tree type, HOST_WIDE_INT startbitpos,
5204 struct function_arg_record_value_parms *parms,
5209 /* We need to compute how many registers are needed so we can
5210 allocate the PARALLEL but before we can do that we need to know
5211 whether there are any packed fields. The ABI obviously doesn't
5212 specify how structures are passed in this case, so they are
5213 defined to be passed in int regs if possible, otherwise memory,
5214 regardless of whether there are fp values present. */
5217 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5219 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
5226 /* Compute how many registers we need. */
5227 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5229 if (TREE_CODE (field) == FIELD_DECL)
5231 HOST_WIDE_INT bitpos = startbitpos;
5233 if (DECL_SIZE (field) != 0
5234 && host_integerp (bit_position (field), 1))
5235 bitpos += int_bit_position (field);
5237 /* ??? FIXME: else assume zero offset. */
5239 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
5240 function_arg_record_value_1 (TREE_TYPE (field),
5244 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
5245 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
5250 if (parms->intoffset != -1)
5252 unsigned int startbit, endbit;
5253 int intslots, this_slotno;
5255 startbit = parms->intoffset & -BITS_PER_WORD;
5256 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
5258 intslots = (endbit - startbit) / BITS_PER_WORD;
5259 this_slotno = parms->slotno + parms->intoffset
5262 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
5264 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
5265 /* We need to pass this field on the stack. */
5269 parms->nregs += intslots;
5270 parms->intoffset = -1;
5273 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
5274 If it wasn't true we wouldn't be here. */
5276 if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
5281 if (parms->intoffset == -1)
5282 parms->intoffset = bitpos;
5288 /* A subroutine of function_arg_record_value. Assign the bits of the
5289 structure between parms->intoffset and bitpos to integer registers. */
5292 function_arg_record_value_3 (HOST_WIDE_INT bitpos,
5293 struct function_arg_record_value_parms *parms)
5295 enum machine_mode mode;
5297 unsigned int startbit, endbit;
5298 int this_slotno, intslots, intoffset;
5301 if (parms->intoffset == -1)
5304 intoffset = parms->intoffset;
5305 parms->intoffset = -1;
5307 startbit = intoffset & -BITS_PER_WORD;
5308 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
5309 intslots = (endbit - startbit) / BITS_PER_WORD;
5310 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
5312 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
5316 /* If this is the trailing part of a word, only load that much into
5317 the register. Otherwise load the whole register. Note that in
5318 the latter case we may pick up unwanted bits. It's not a problem
5319 at the moment but may wish to revisit. */
5321 if (intoffset % BITS_PER_WORD != 0)
5322 mode = mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
5327 intoffset /= BITS_PER_UNIT;
5330 regno = parms->regbase + this_slotno;
5331 reg = gen_rtx_REG (mode, regno);
5332 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
5333 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
5336 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
5341 while (intslots > 0);
5344 /* A subroutine of function_arg_record_value. Traverse the structure
5345 recursively and assign bits to floating point registers. Track which
5346 bits in between need integer registers; invoke function_arg_record_value_3
5347 to make that happen. */
5350 function_arg_record_value_2 (tree type, HOST_WIDE_INT startbitpos,
5351 struct function_arg_record_value_parms *parms,
5357 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5359 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
5366 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5368 if (TREE_CODE (field) == FIELD_DECL)
5370 HOST_WIDE_INT bitpos = startbitpos;
5372 if (DECL_SIZE (field) != 0
5373 && host_integerp (bit_position (field), 1))
5374 bitpos += int_bit_position (field);
5376 /* ??? FIXME: else assume zero offset. */
5378 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
5379 function_arg_record_value_2 (TREE_TYPE (field),
5383 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
5384 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
5389 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
5391 enum machine_mode mode = DECL_MODE (field);
5394 function_arg_record_value_3 (bitpos, parms);
5397 case SCmode: mode = SFmode; break;
5398 case DCmode: mode = DFmode; break;
5399 case TCmode: mode = TFmode; break;
5402 regno = SPARC_FP_ARG_FIRST + this_slotno * 2;
5403 if (GET_MODE_SIZE (mode) <= 4 && (bitpos & 32) != 0)
5405 reg = gen_rtx_REG (mode, regno);
5406 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
5407 = gen_rtx_EXPR_LIST (VOIDmode, reg,
5408 GEN_INT (bitpos / BITS_PER_UNIT));
5410 if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
5412 regno += GET_MODE_SIZE (mode) / 4;
5413 reg = gen_rtx_REG (mode, regno);
5414 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
5415 = gen_rtx_EXPR_LIST (VOIDmode, reg,
5416 GEN_INT ((bitpos + GET_MODE_BITSIZE (mode))
5423 if (parms->intoffset == -1)
5424 parms->intoffset = bitpos;
5430 /* Used by function_arg and function_value to implement the complex
5431 conventions of the 64-bit ABI for passing and returning structures.
5432 Return an expression valid as a return value for the two macros
5433 FUNCTION_ARG and FUNCTION_VALUE.
5435 TYPE is the data type of the argument (as a tree).
5436 This is null for libcalls where that information may
5438 MODE is the argument's machine mode.
5439 SLOTNO is the index number of the argument's slot in the parameter array.
5440 NAMED is nonzero if this argument is a named parameter
5441 (otherwise it is an extra parameter matching an ellipsis).
5442 REGBASE is the regno of the base register for the parameter array. */
5445 function_arg_record_value (tree type, enum machine_mode mode,
5446 int slotno, int named, int regbase)
5448 HOST_WIDE_INT typesize = int_size_in_bytes (type);
5449 struct function_arg_record_value_parms parms;
5452 parms.ret = NULL_RTX;
5453 parms.slotno = slotno;
5454 parms.named = named;
5455 parms.regbase = regbase;
5458 /* Compute how many registers we need. */
5460 parms.intoffset = 0;
5461 function_arg_record_value_1 (type, 0, &parms, false);
5463 /* Take into account pending integer fields. */
5464 if (parms.intoffset != -1)
5466 unsigned int startbit, endbit;
5467 int intslots, this_slotno;
5469 startbit = parms.intoffset & -BITS_PER_WORD;
5470 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
5471 intslots = (endbit - startbit) / BITS_PER_WORD;
5472 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
5474 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
5476 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
5477 /* We need to pass this field on the stack. */
5481 parms.nregs += intslots;
5483 nregs = parms.nregs;
5485 /* Allocate the vector and handle some annoying special cases. */
5488 /* ??? Empty structure has no value? Duh? */
5491 /* Though there's nothing really to store, return a word register
5492 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
5493 leads to breakage due to the fact that there are zero bytes to
5495 return gen_rtx_REG (mode, regbase);
5499 /* ??? C++ has structures with no fields, and yet a size. Give up
5500 for now and pass everything back in integer registers. */
5501 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5503 if (nregs + slotno > SPARC_INT_ARG_MAX)
5504 nregs = SPARC_INT_ARG_MAX - slotno;
5509 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (parms.stack + nregs));
5511 /* If at least one field must be passed on the stack, generate
5512 (parallel [(expr_list (nil) ...) ...]) so that all fields will
5513 also be passed on the stack. We can't do much better because the
5514 semantics of FUNCTION_ARG_PARTIAL_NREGS doesn't handle the case
5515 of structures for which the fields passed exclusively in registers
5516 are not at the beginning of the structure. */
5518 XVECEXP (parms.ret, 0, 0)
5519 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
5521 /* Fill in the entries. */
5523 parms.intoffset = 0;
5524 function_arg_record_value_2 (type, 0, &parms, false);
5525 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
5527 if (parms.nregs != nregs)
5533 /* Used by function_arg and function_value to implement the conventions
5534 of the 64-bit ABI for passing and returning unions.
5535 Return an expression valid as a return value for the two macros
5536 FUNCTION_ARG and FUNCTION_VALUE.
5538 SIZE is the size in bytes of the union.
5539 MODE is the argument's machine mode.
5540 REGNO is the hard register the union will be passed in. */
5543 function_arg_union_value (int size, enum machine_mode mode, int regno)
5545 int nwords = ROUND_ADVANCE (size), i;
5548 /* Unions are passed left-justified. */
5549 regs = gen_rtx_PARALLEL (mode, rtvec_alloc (nwords));
5551 for (i = 0; i < nwords; i++)
5552 XVECEXP (regs, 0, i)
5553 = gen_rtx_EXPR_LIST (VOIDmode,
5554 gen_rtx_REG (word_mode, regno + i),
5555 GEN_INT (UNITS_PER_WORD * i));
5560 /* Handle the FUNCTION_ARG macro.
5561 Determine where to put an argument to a function.
5562 Value is zero to push the argument on the stack,
5563 or a hard register in which to store the argument.
5565 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5566 the preceding args and about the function being called.
5567 MODE is the argument's machine mode.
5568 TYPE is the data type of the argument (as a tree).
5569 This is null for libcalls where that information may
5571 NAMED is nonzero if this argument is a named parameter
5572 (otherwise it is an extra parameter matching an ellipsis).
5573 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
5576 function_arg (const struct sparc_args *cum, enum machine_mode mode,
5577 tree type, int named, int incoming_p)
5579 int regbase = (incoming_p
5580 ? SPARC_INCOMING_INT_ARG_FIRST
5581 : SPARC_OUTGOING_INT_ARG_FIRST);
5582 int slotno, regno, padding;
5585 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
5593 reg = gen_rtx_REG (mode, regno);
5597 if (type && TREE_CODE (type) == RECORD_TYPE)
5599 /* Structures up to 16 bytes in size are passed in arg slots on the
5600 stack and are promoted to registers where possible. */
5602 if (int_size_in_bytes (type) > 16)
5603 abort (); /* shouldn't get here */
5605 return function_arg_record_value (type, mode, slotno, named, regbase);
5607 else if (type && TREE_CODE (type) == UNION_TYPE)
5609 HOST_WIDE_INT size = int_size_in_bytes (type);
5612 abort (); /* shouldn't get here */
5614 return function_arg_union_value (size, mode, regno);
5616 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
5617 but also have the slot allocated for them.
5618 If no prototype is in scope fp values in register slots get passed
5619 in two places, either fp regs and int regs or fp regs and memory. */
5620 else if ((GET_MODE_CLASS (mode) == MODE_FLOAT
5621 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5622 || GET_MODE_CLASS (mode) == MODE_VECTOR_INT
5623 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
5624 && SPARC_FP_REG_P (regno))
5626 reg = gen_rtx_REG (mode, regno);
5627 if (cum->prototype_p || cum->libcall_p)
5629 /* "* 2" because fp reg numbers are recorded in 4 byte
5632 /* ??? This will cause the value to be passed in the fp reg and
5633 in the stack. When a prototype exists we want to pass the
5634 value in the reg but reserve space on the stack. That's an
5635 optimization, and is deferred [for a bit]. */
5636 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
5637 return gen_rtx_PARALLEL (mode,
5639 gen_rtx_EXPR_LIST (VOIDmode,
5640 NULL_RTX, const0_rtx),
5641 gen_rtx_EXPR_LIST (VOIDmode,
5645 /* ??? It seems that passing back a register even when past
5646 the area declared by REG_PARM_STACK_SPACE will allocate
5647 space appropriately, and will not copy the data onto the
5648 stack, exactly as we desire.
5650 This is due to locate_and_pad_parm being called in
5651 expand_call whenever reg_parm_stack_space > 0, which
5652 while beneficial to our example here, would seem to be
5653 in error from what had been intended. Ho hum... -- r~ */
5661 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
5665 /* On incoming, we don't need to know that the value
5666 is passed in %f0 and %i0, and it confuses other parts
5667 causing needless spillage even on the simplest cases. */
5671 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
5672 + (regno - SPARC_FP_ARG_FIRST) / 2);
5674 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5675 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
5677 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5681 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
5682 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5683 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5689 /* Scalar or complex int. */
5690 reg = gen_rtx_REG (mode, regno);
5696 /* Handle the FUNCTION_ARG_PARTIAL_NREGS macro.
5697 For an arg passed partly in registers and partly in memory,
5698 this is the number of registers used.
5699 For args passed entirely in registers or entirely in memory, zero.
5701 Any arg that starts in the first 6 regs but won't entirely fit in them
5702 needs partial registers on v8. On v9, structures with integer
5703 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
5704 values that begin in the last fp reg [where "last fp reg" varies with the
5705 mode] will be split between that reg and memory. */
5708 function_arg_partial_nregs (const struct sparc_args *cum,
5709 enum machine_mode mode, tree type, int named)
5711 int slotno, regno, padding;
5713 /* We pass 0 for incoming_p here, it doesn't matter. */
5714 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5721 if ((slotno + (mode == BLKmode
5722 ? ROUND_ADVANCE (int_size_in_bytes (type))
5723 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
5724 > SPARC_INT_ARG_MAX)
5725 return SPARC_INT_ARG_MAX - slotno;
5729 /* We are guaranteed by pass_by_reference that the size of the
5730 argument is not greater than 16 bytes, so we only need to
5731 return 1 if the argument is partially passed in registers. */
5733 if (type && AGGREGATE_TYPE_P (type))
5735 int size = int_size_in_bytes (type);
5737 if (size > UNITS_PER_WORD
5738 && slotno == SPARC_INT_ARG_MAX - 1)
5741 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
5742 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5743 && ! (TARGET_FPU && named)))
5745 /* The complex types are passed as packed types. */
5746 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
5747 && slotno == SPARC_INT_ARG_MAX - 1)
5750 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
5752 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
5761 /* Return true if the argument should be passed by reference.
5762 !v9: The SPARC ABI stipulates passing struct arguments (of any size) and
5763 quad-precision floats by invisible reference.
5764 v9: Aggregates greater than 16 bytes are passed by reference.
5765 For Pascal, also pass arrays by reference. */
5768 sparc_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5769 enum machine_mode mode, tree type,
5770 bool named ATTRIBUTE_UNUSED)
5774 return ((type && AGGREGATE_TYPE_P (type))
5775 /* Extended ABI (as implemented by the Sun compiler) says
5776 that all complex floats are passed in memory. */
5778 /* Enforce the 2-word cap for passing arguments in registers.
5779 This affects CDImode, TFmode, DCmode, TCmode and large
5781 || GET_MODE_SIZE (mode) > 8);
5785 return ((type && TREE_CODE (type) == ARRAY_TYPE)
5787 && AGGREGATE_TYPE_P (type)
5788 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16)
5789 /* Enforce the 2-word cap for passing arguments in registers.
5790 This affects CTImode, TCmode and large vector modes. */
5791 || GET_MODE_SIZE (mode) > 16);
5795 /* Handle the FUNCTION_ARG_ADVANCE macro.
5796 Update the data in CUM to advance over an argument
5797 of mode MODE and data type TYPE.
5798 TYPE is null for libcalls where that information may not be available. */
5801 function_arg_advance (struct sparc_args *cum, enum machine_mode mode,
5802 tree type, int named)
5804 int slotno, regno, padding;
5806 /* We pass 0 for incoming_p here, it doesn't matter. */
5807 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5809 /* If register required leading padding, add it. */
5811 cum->words += padding;
5815 cum->words += (mode != BLKmode
5816 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5817 : ROUND_ADVANCE (int_size_in_bytes (type)));
5821 if (type && AGGREGATE_TYPE_P (type))
5823 int size = int_size_in_bytes (type);
5827 else if (size <= 16)
5829 else /* passed by reference */
5834 cum->words += (mode != BLKmode
5835 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5836 : ROUND_ADVANCE (int_size_in_bytes (type)));
5841 /* Handle the FUNCTION_ARG_PADDING macro.
5842 For the 64 bit ABI structs are always stored left shifted in their
5846 function_arg_padding (enum machine_mode mode, tree type)
5848 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
5851 /* Fall back to the default. */
5852 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
5855 /* Handle the TARGET_RETURN_IN_MEMORY target hook.
5856 Specify whether to return the return value in memory. */
5859 sparc_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
5862 /* Original SPARC 32-bit ABI says that quad-precision floats
5863 and all structures are returned in memory. Extended ABI
5864 (as implemented by the Sun compiler) says that all complex
5865 floats are returned in registers (8 FP registers at most
5866 for '_Complex long double'). Return all complex integers
5867 in registers (4 at most for '_Complex long long'). */
5868 return (TYPE_MODE (type) == BLKmode
5869 || TYPE_MODE (type) == TFmode
5870 /* Integral vector types follow the scalar FP types conventions. */
5871 || (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_VECTOR_INT
5872 && GET_MODE_SIZE (TYPE_MODE (type)) > 8)
5873 /* FP vector types follow the complex FP types conventions. */
5874 || (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_VECTOR_FLOAT
5875 && GET_MODE_SIZE (TYPE_MODE (type)) > 32));
5877 /* Original SPARC 64-bit ABI says that structures and unions
5878 smaller than 32 bytes are returned in registers. Extended
5879 ABI (as implemented by the Sun compiler) says that all complex
5880 floats are returned in registers (8 FP registers at most
5881 for '_Complex long double'). Return all complex integers
5882 in registers (4 at most for '_Complex TItype'). */
5883 return ((TYPE_MODE (type) == BLKmode
5884 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 32)
5885 || GET_MODE_SIZE (TYPE_MODE (type)) > 32);
5888 /* Handle the TARGET_STRUCT_VALUE target hook.
5889 Return where to find the structure return value address. */
5892 sparc_struct_value_rtx (tree fndecl ATTRIBUTE_UNUSED, int incoming)
5899 return gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx,
5900 STRUCT_VALUE_OFFSET));
5902 return gen_rtx_MEM (Pmode, plus_constant (stack_pointer_rtx,
5903 STRUCT_VALUE_OFFSET));
5907 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
5908 For v9, function return values are subject to the same rules as arguments,
5909 except that up to 32 bytes may be returned in registers. */
5912 function_value (tree type, enum machine_mode mode, int incoming_p)
5914 /* Beware that the two values are swapped here wrt function_arg. */
5915 int regbase = (incoming_p
5916 ? SPARC_OUTGOING_INT_ARG_FIRST
5917 : SPARC_INCOMING_INT_ARG_FIRST);
5920 if (TARGET_ARCH64 && type)
5922 if (TREE_CODE (type) == RECORD_TYPE)
5924 /* Structures up to 32 bytes in size are passed in registers,
5925 promoted to fp registers where possible. */
5927 if (int_size_in_bytes (type) > 32)
5928 abort (); /* shouldn't get here */
5930 return function_arg_record_value (type, mode, 0, 1, regbase);
5932 else if (TREE_CODE (type) == UNION_TYPE)
5934 HOST_WIDE_INT size = int_size_in_bytes (type);
5937 abort (); /* shouldn't get here */
5939 return function_arg_union_value (size, mode, regbase);
5941 else if (AGGREGATE_TYPE_P (type))
5943 /* All other aggregate types are passed in an integer register
5944 in a mode corresponding to the size of the type. */
5945 HOST_WIDE_INT bytes = int_size_in_bytes (type);
5948 abort (); /* shouldn't get here */
5950 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
5952 /* ??? We probably should have made the same ABI change in
5953 3.4.0 as the one we made for unions. The latter was
5954 required by the SCD though, while the former is not
5955 specified, so we favored compatibility and efficiency.
5957 Now we're stuck for aggregates larger than 16 bytes,
5958 because OImode vanished in the meantime. Let's not
5959 try to be unduly clever, and simply follow the ABI
5960 for unions in that case. */
5961 if (mode == BLKmode)
5962 return function_arg_union_value (bytes, mode, regbase);
5964 else if (GET_MODE_CLASS (mode) == MODE_INT
5965 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
5969 if (TARGET_FPU && (FLOAT_MODE_P (mode) || VECTOR_MODE_P (mode)))
5970 regno = SPARC_FP_ARG_FIRST;
5974 return gen_rtx_REG (mode, regno);
5977 /* Do what is necessary for `va_start'. We look at the current function
5978 to determine if stdarg or varargs is used and return the address of
5979 the first unnamed parameter. */
5982 sparc_builtin_saveregs (void)
5984 int first_reg = current_function_args_info.words;
5988 for (regno = first_reg; regno < SPARC_INT_ARG_MAX; regno++)
5989 emit_move_insn (gen_rtx_MEM (word_mode,
5990 gen_rtx_PLUS (Pmode,
5992 GEN_INT (FIRST_PARM_OFFSET (0)
5995 gen_rtx_REG (word_mode,
5996 SPARC_INCOMING_INT_ARG_FIRST + regno));
5998 address = gen_rtx_PLUS (Pmode,
6000 GEN_INT (FIRST_PARM_OFFSET (0)
6001 + UNITS_PER_WORD * first_reg));
6006 /* Implement `va_start' for stdarg. */
6009 sparc_va_start (tree valist, rtx nextarg)
6011 nextarg = expand_builtin_saveregs ();
6012 std_expand_builtin_va_start (valist, nextarg);
6015 /* Implement `va_arg' for stdarg. */
6018 sparc_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
6020 HOST_WIDE_INT size, rsize, align;
6023 tree ptrtype = build_pointer_type (type);
6025 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
6028 size = rsize = UNITS_PER_WORD;
6034 size = int_size_in_bytes (type);
6035 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
6040 /* For SPARC64, objects requiring 16-byte alignment get it. */
6041 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
6042 align = 2 * UNITS_PER_WORD;
6044 /* SPARC-V9 ABI states that structures up to 16 bytes in size
6045 are left-justified in their slots. */
6046 if (AGGREGATE_TYPE_P (type))
6049 size = rsize = UNITS_PER_WORD;
6059 incr = fold (build2 (PLUS_EXPR, ptr_type_node, incr,
6060 ssize_int (align - 1)));
6061 incr = fold (build2 (BIT_AND_EXPR, ptr_type_node, incr,
6062 ssize_int (-align)));
6065 gimplify_expr (&incr, pre_p, post_p, is_gimple_val, fb_rvalue);
6068 if (BYTES_BIG_ENDIAN && size < rsize)
6069 addr = fold (build2 (PLUS_EXPR, ptr_type_node, incr,
6070 ssize_int (rsize - size)));
6074 addr = fold_convert (build_pointer_type (ptrtype), addr);
6075 addr = build_va_arg_indirect_ref (addr);
6077 /* If the address isn't aligned properly for the type,
6078 we may need to copy to a temporary.
6079 FIXME: This is inefficient. Usually we can do this
6082 && TYPE_ALIGN (type) > BITS_PER_WORD)
6084 tree tmp = create_tmp_var (type, "va_arg_tmp");
6085 tree dest_addr = build_fold_addr_expr (tmp);
6087 tree copy = build_function_call_expr
6088 (implicit_built_in_decls[BUILT_IN_MEMCPY],
6089 tree_cons (NULL_TREE, dest_addr,
6090 tree_cons (NULL_TREE, addr,
6091 tree_cons (NULL_TREE, size_int (rsize),
6094 gimplify_and_add (copy, pre_p);
6098 addr = fold_convert (ptrtype, addr);
6100 incr = fold (build2 (PLUS_EXPR, ptr_type_node, incr, ssize_int (rsize)));
6101 incr = build2 (MODIFY_EXPR, ptr_type_node, valist, incr);
6102 gimplify_and_add (incr, post_p);
6104 return build_va_arg_indirect_ref (addr);
6107 /* Return the string to output an unconditional branch to LABEL, which is
6108 the operand number of the label.
6110 DEST is the destination insn (i.e. the label), INSN is the source. */
6113 output_ubranch (rtx dest, int label, rtx insn)
6115 static char string[64];
6116 bool v9_form = false;
6119 if (TARGET_V9 && INSN_ADDRESSES_SET_P ())
6121 int delta = (INSN_ADDRESSES (INSN_UID (dest))
6122 - INSN_ADDRESSES (INSN_UID (insn)));
6123 /* Leave some instructions for "slop". */
6124 if (delta >= -260000 && delta < 260000)
6129 strcpy (string, "ba%*,pt\t%%xcc, ");
6131 strcpy (string, "b%*\t");
6133 p = strchr (string, '\0');
6144 /* Return the string to output a conditional branch to LABEL, which is
6145 the operand number of the label. OP is the conditional expression.
6146 XEXP (OP, 0) is assumed to be a condition code register (integer or
6147 floating point) and its mode specifies what kind of comparison we made.
6149 DEST is the destination insn (i.e. the label), INSN is the source.
6151 REVERSED is nonzero if we should reverse the sense of the comparison.
6153 ANNUL is nonzero if we should generate an annulling branch. */
6156 output_cbranch (rtx op, rtx dest, int label, int reversed, int annul,
6159 static char string[64];
6160 enum rtx_code code = GET_CODE (op);
6161 rtx cc_reg = XEXP (op, 0);
6162 enum machine_mode mode = GET_MODE (cc_reg);
6163 const char *labelno, *branch;
6164 int spaces = 8, far;
6167 /* v9 branches are limited to +-1MB. If it is too far away,
6180 fbne,a,pn %fcc2, .LC29
6188 far = TARGET_V9 && (get_attr_length (insn) >= 3);
6191 /* Reversal of FP compares takes care -- an ordered compare
6192 becomes an unordered compare and vice versa. */
6193 if (mode == CCFPmode || mode == CCFPEmode)
6194 code = reverse_condition_maybe_unordered (code);
6196 code = reverse_condition (code);
6199 /* Start by writing the branch condition. */
6200 if (mode == CCFPmode || mode == CCFPEmode)
6251 /* ??? !v9: FP branches cannot be preceded by another floating point
6252 insn. Because there is currently no concept of pre-delay slots,
6253 we can fix this only by always emitting a nop before a floating
6258 strcpy (string, "nop\n\t");
6259 strcat (string, branch);
6272 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
6284 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
6305 strcpy (string, branch);
6307 spaces -= strlen (branch);
6308 p = strchr (string, '\0');
6310 /* Now add the annulling, the label, and a possible noop. */
6323 if (! far && insn && INSN_ADDRESSES_SET_P ())
6325 int delta = (INSN_ADDRESSES (INSN_UID (dest))
6326 - INSN_ADDRESSES (INSN_UID (insn)));
6327 /* Leave some instructions for "slop". */
6328 if (delta < -260000 || delta >= 260000)
6332 if (mode == CCFPmode || mode == CCFPEmode)
6334 static char v9_fcc_labelno[] = "%%fccX, ";
6335 /* Set the char indicating the number of the fcc reg to use. */
6336 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
6337 labelno = v9_fcc_labelno;
6340 if (REGNO (cc_reg) == SPARC_FCC_REG)
6346 else if (mode == CCXmode || mode == CCX_NOOVmode)
6348 labelno = "%%xcc, ";
6354 labelno = "%%icc, ";
6359 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
6362 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
6375 strcpy (p, labelno);
6376 p = strchr (p, '\0');
6379 strcpy (p, ".+12\n\t nop\n\tb\t");
6380 /* Skip the next insn if requested or
6381 if we know that it will be a nop. */
6382 if (annul || ! final_sequence)
6396 /* Emit a library call comparison between floating point X and Y.
6397 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
6398 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
6399 values as arguments instead of the TFmode registers themselves,
6400 that's why we cannot call emit_float_lib_cmp. */
6402 sparc_emit_float_lib_cmp (rtx x, rtx y, enum rtx_code comparison)
6405 rtx slot0, slot1, result, tem, tem2;
6406 enum machine_mode mode;
6411 qpfunc = (TARGET_ARCH64) ? "_Qp_feq" : "_Q_feq";
6415 qpfunc = (TARGET_ARCH64) ? "_Qp_fne" : "_Q_fne";
6419 qpfunc = (TARGET_ARCH64) ? "_Qp_fgt" : "_Q_fgt";
6423 qpfunc = (TARGET_ARCH64) ? "_Qp_fge" : "_Q_fge";
6427 qpfunc = (TARGET_ARCH64) ? "_Qp_flt" : "_Q_flt";
6431 qpfunc = (TARGET_ARCH64) ? "_Qp_fle" : "_Q_fle";
6442 qpfunc = (TARGET_ARCH64) ? "_Qp_cmp" : "_Q_cmp";
6452 if (GET_CODE (x) != MEM)
6454 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
6455 emit_insn (gen_rtx_SET (VOIDmode, slot0, x));
6460 if (GET_CODE (y) != MEM)
6462 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
6463 emit_insn (gen_rtx_SET (VOIDmode, slot1, y));
6468 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
6470 XEXP (slot0, 0), Pmode,
6471 XEXP (slot1, 0), Pmode);
6477 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
6479 x, TFmode, y, TFmode);
6485 /* Immediately move the result of the libcall into a pseudo
6486 register so reload doesn't clobber the value if it needs
6487 the return register for a spill reg. */
6488 result = gen_reg_rtx (mode);
6489 emit_move_insn (result, hard_libcall_value (mode));
6494 emit_cmp_insn (result, const0_rtx, NE, NULL_RTX, mode, 0);
6498 emit_cmp_insn (result, GEN_INT(3), comparison == UNORDERED ? EQ : NE,
6503 emit_cmp_insn (result, const1_rtx,
6504 comparison == UNGT ? GT : NE, NULL_RTX, mode, 0);
6507 emit_cmp_insn (result, const2_rtx, NE, NULL_RTX, mode, 0);
6510 tem = gen_reg_rtx (mode);
6512 emit_insn (gen_andsi3 (tem, result, const1_rtx));
6514 emit_insn (gen_anddi3 (tem, result, const1_rtx));
6515 emit_cmp_insn (tem, const0_rtx, NE, NULL_RTX, mode, 0);
6519 tem = gen_reg_rtx (mode);
6521 emit_insn (gen_addsi3 (tem, result, const1_rtx));
6523 emit_insn (gen_adddi3 (tem, result, const1_rtx));
6524 tem2 = gen_reg_rtx (mode);
6526 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
6528 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
6529 emit_cmp_insn (tem2, const0_rtx, comparison == UNEQ ? EQ : NE,
6535 /* Generate an unsigned DImode to FP conversion. This is the same code
6536 optabs would emit if we didn't have TFmode patterns. */
6539 sparc_emit_floatunsdi (rtx *operands, enum machine_mode mode)
6541 rtx neglab, donelab, i0, i1, f0, in, out;
6544 in = force_reg (DImode, operands[1]);
6545 neglab = gen_label_rtx ();
6546 donelab = gen_label_rtx ();
6547 i0 = gen_reg_rtx (DImode);
6548 i1 = gen_reg_rtx (DImode);
6549 f0 = gen_reg_rtx (mode);
6551 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
6553 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
6554 emit_jump_insn (gen_jump (donelab));
6557 emit_label (neglab);
6559 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
6560 emit_insn (gen_anddi3 (i1, in, const1_rtx));
6561 emit_insn (gen_iordi3 (i0, i0, i1));
6562 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
6563 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
6565 emit_label (donelab);
6568 /* Generate an FP to unsigned DImode conversion. This is the same code
6569 optabs would emit if we didn't have TFmode patterns. */
6572 sparc_emit_fixunsdi (rtx *operands, enum machine_mode mode)
6574 rtx neglab, donelab, i0, i1, f0, in, out, limit;
6577 in = force_reg (mode, operands[1]);
6578 neglab = gen_label_rtx ();
6579 donelab = gen_label_rtx ();
6580 i0 = gen_reg_rtx (DImode);
6581 i1 = gen_reg_rtx (DImode);
6582 limit = gen_reg_rtx (mode);
6583 f0 = gen_reg_rtx (mode);
6585 emit_move_insn (limit,
6586 CONST_DOUBLE_FROM_REAL_VALUE (
6587 REAL_VALUE_ATOF ("9223372036854775808.0", mode), mode));
6588 emit_cmp_and_jump_insns (in, limit, GE, NULL_RTX, mode, 0, neglab);
6590 emit_insn (gen_rtx_SET (VOIDmode,
6592 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, in))));
6593 emit_jump_insn (gen_jump (donelab));
6596 emit_label (neglab);
6598 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_MINUS (mode, in, limit)));
6599 emit_insn (gen_rtx_SET (VOIDmode,
6601 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, f0))));
6602 emit_insn (gen_movdi (i1, const1_rtx));
6603 emit_insn (gen_ashldi3 (i1, i1, GEN_INT (63)));
6604 emit_insn (gen_xordi3 (out, i0, i1));
6606 emit_label (donelab);
6609 /* Return the string to output a conditional branch to LABEL, testing
6610 register REG. LABEL is the operand number of the label; REG is the
6611 operand number of the reg. OP is the conditional expression. The mode
6612 of REG says what kind of comparison we made.
6614 DEST is the destination insn (i.e. the label), INSN is the source.
6616 REVERSED is nonzero if we should reverse the sense of the comparison.
6618 ANNUL is nonzero if we should generate an annulling branch. */
6621 output_v9branch (rtx op, rtx dest, int reg, int label, int reversed,
6622 int annul, rtx insn)
6624 static char string[64];
6625 enum rtx_code code = GET_CODE (op);
6626 enum machine_mode mode = GET_MODE (XEXP (op, 0));
6631 /* branch on register are limited to +-128KB. If it is too far away,
6644 brgez,a,pn %o1, .LC29
6650 ba,pt %xcc, .LC29 */
6652 far = get_attr_length (insn) >= 3;
6654 /* If not floating-point or if EQ or NE, we can just reverse the code. */
6656 code = reverse_condition (code);
6658 /* Only 64 bit versions of these instructions exist. */
6662 /* Start by writing the branch condition. */
6667 strcpy (string, "brnz");
6671 strcpy (string, "brz");
6675 strcpy (string, "brgez");
6679 strcpy (string, "brlz");
6683 strcpy (string, "brlez");
6687 strcpy (string, "brgz");
6694 p = strchr (string, '\0');
6696 /* Now add the annulling, reg, label, and nop. */
6703 if (insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
6706 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
6711 *p = p < string + 8 ? '\t' : ' ';
6719 int veryfar = 1, delta;
6721 if (INSN_ADDRESSES_SET_P ())
6723 delta = (INSN_ADDRESSES (INSN_UID (dest))
6724 - INSN_ADDRESSES (INSN_UID (insn)));
6725 /* Leave some instructions for "slop". */
6726 if (delta >= -260000 && delta < 260000)
6730 strcpy (p, ".+12\n\t nop\n\t");
6731 /* Skip the next insn if requested or
6732 if we know that it will be a nop. */
6733 if (annul || ! final_sequence)
6743 strcpy (p, "ba,pt\t%%xcc, ");
6757 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
6758 Such instructions cannot be used in the delay slot of return insn on v9.
6759 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
6763 epilogue_renumber (register rtx *where, int test)
6765 register const char *fmt;
6767 register enum rtx_code code;
6772 code = GET_CODE (*where);
6777 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
6779 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
6780 *where = gen_rtx_REG (GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
6788 /* Do not replace the frame pointer with the stack pointer because
6789 it can cause the delayed instruction to load below the stack.
6790 This occurs when instructions like:
6792 (set (reg/i:SI 24 %i0)
6793 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
6794 (const_int -20 [0xffffffec])) 0))
6796 are in the return delayed slot. */
6798 if (GET_CODE (XEXP (*where, 0)) == REG
6799 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
6800 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
6801 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
6806 if (SPARC_STACK_BIAS
6807 && GET_CODE (XEXP (*where, 0)) == REG
6808 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
6816 fmt = GET_RTX_FORMAT (code);
6818 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6823 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
6824 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
6827 else if (fmt[i] == 'e'
6828 && epilogue_renumber (&(XEXP (*where, i)), test))
6834 /* Leaf functions and non-leaf functions have different needs. */
6837 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
6840 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
6842 static const int *const reg_alloc_orders[] = {
6843 reg_leaf_alloc_order,
6844 reg_nonleaf_alloc_order};
6847 order_regs_for_local_alloc (void)
6849 static int last_order_nonleaf = 1;
6851 if (regs_ever_live[15] != last_order_nonleaf)
6853 last_order_nonleaf = !last_order_nonleaf;
6854 memcpy ((char *) reg_alloc_order,
6855 (const char *) reg_alloc_orders[last_order_nonleaf],
6856 FIRST_PSEUDO_REGISTER * sizeof (int));
6860 /* Return 1 if REG and MEM are legitimate enough to allow the various
6861 mem<-->reg splits to be run. */
6864 sparc_splitdi_legitimate (rtx reg, rtx mem)
6866 /* Punt if we are here by mistake. */
6867 if (! reload_completed)
6870 /* We must have an offsettable memory reference. */
6871 if (! offsettable_memref_p (mem))
6874 /* If we have legitimate args for ldd/std, we do not want
6875 the split to happen. */
6876 if ((REGNO (reg) % 2) == 0
6877 && mem_min_alignment (mem, 8))
6884 /* Return 1 if x and y are some kind of REG and they refer to
6885 different hard registers. This test is guaranteed to be
6886 run after reload. */
6889 sparc_absnegfloat_split_legitimate (rtx x, rtx y)
6891 if (GET_CODE (x) != REG)
6893 if (GET_CODE (y) != REG)
6895 if (REGNO (x) == REGNO (y))
6900 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
6901 This makes them candidates for using ldd and std insns.
6903 Note reg1 and reg2 *must* be hard registers. */
6906 registers_ok_for_ldd_peep (rtx reg1, rtx reg2)
6908 /* We might have been passed a SUBREG. */
6909 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
6912 if (REGNO (reg1) % 2 != 0)
6915 /* Integer ldd is deprecated in SPARC V9 */
6916 if (TARGET_V9 && REGNO (reg1) < 32)
6919 return (REGNO (reg1) == REGNO (reg2) - 1);
6922 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
6925 This can only happen when addr1 and addr2, the addresses in mem1
6926 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
6927 addr1 must also be aligned on a 64-bit boundary.
6929 Also iff dependent_reg_rtx is not null it should not be used to
6930 compute the address for mem1, i.e. we cannot optimize a sequence
6942 But, note that the transformation from:
6947 is perfectly fine. Thus, the peephole2 patterns always pass us
6948 the destination register of the first load, never the second one.
6950 For stores we don't have a similar problem, so dependent_reg_rtx is
6954 mems_ok_for_ldd_peep (rtx mem1, rtx mem2, rtx dependent_reg_rtx)
6958 HOST_WIDE_INT offset1;
6960 /* The mems cannot be volatile. */
6961 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
6964 /* MEM1 should be aligned on a 64-bit boundary. */
6965 if (MEM_ALIGN (mem1) < 64)
6968 addr1 = XEXP (mem1, 0);
6969 addr2 = XEXP (mem2, 0);
6971 /* Extract a register number and offset (if used) from the first addr. */
6972 if (GET_CODE (addr1) == PLUS)
6974 /* If not a REG, return zero. */
6975 if (GET_CODE (XEXP (addr1, 0)) != REG)
6979 reg1 = REGNO (XEXP (addr1, 0));
6980 /* The offset must be constant! */
6981 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
6983 offset1 = INTVAL (XEXP (addr1, 1));
6986 else if (GET_CODE (addr1) != REG)
6990 reg1 = REGNO (addr1);
6991 /* This was a simple (mem (reg)) expression. Offset is 0. */
6995 /* Make sure the second address is a (mem (plus (reg) (const_int). */
6996 if (GET_CODE (addr2) != PLUS)
6999 if (GET_CODE (XEXP (addr2, 0)) != REG
7000 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
7003 if (reg1 != REGNO (XEXP (addr2, 0)))
7006 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
7009 /* The first offset must be evenly divisible by 8 to ensure the
7010 address is 64 bit aligned. */
7011 if (offset1 % 8 != 0)
7014 /* The offset for the second addr must be 4 more than the first addr. */
7015 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
7018 /* All the tests passed. addr1 and addr2 are valid for ldd and std
7023 /* Return 1 if reg is a pseudo, or is the first register in
7024 a hard register pair. This makes it a candidate for use in
7025 ldd and std insns. */
7028 register_ok_for_ldd (rtx reg)
7030 /* We might have been passed a SUBREG. */
7031 if (GET_CODE (reg) != REG)
7034 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
7035 return (REGNO (reg) % 2 == 0);
7040 /* Print operand X (an rtx) in assembler syntax to file FILE.
7041 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
7042 For `%' followed by punctuation, CODE is the punctuation and X is null. */
7045 print_operand (FILE *file, rtx x, int code)
7050 /* Output an insn in a delay slot. */
7052 sparc_indent_opcode = 1;
7054 fputs ("\n\t nop", file);
7057 /* Output an annul flag if there's nothing for the delay slot and we
7058 are optimizing. This is always used with '(' below.
7059 Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
7060 this is a dbx bug. So, we only do this when optimizing.
7061 On UltraSPARC, a branch in a delay slot causes a pipeline flush.
7062 Always emit a nop in case the next instruction is a branch. */
7063 if (! final_sequence && (optimize && (int)sparc_cpu < PROCESSOR_V9))
7067 /* Output a 'nop' if there's nothing for the delay slot and we are
7068 not optimizing. This is always used with '*' above. */
7069 if (! final_sequence && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
7070 fputs ("\n\t nop", file);
7071 else if (final_sequence)
7072 sparc_indent_opcode = 1;
7075 /* Output the right displacement from the saved PC on function return.
7076 The caller may have placed an "unimp" insn immediately after the call
7077 so we have to account for it. This insn is used in the 32-bit ABI
7078 when calling a function that returns a non zero-sized structure. The
7079 64-bit ABI doesn't have it. Be careful to have this test be the same
7080 as that used on the call. */
7082 && current_function_returns_struct
7083 && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl)))
7085 && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))))
7091 /* Output the Embedded Medium/Anywhere code model base register. */
7092 fputs (EMBMEDANY_BASE_REG, file);
7095 /* Print some local dynamic TLS name. */
7096 assemble_name (file, get_some_local_dynamic_name ());
7100 /* Adjust the operand to take into account a RESTORE operation. */
7101 if (GET_CODE (x) == CONST_INT)
7103 else if (GET_CODE (x) != REG)
7104 output_operand_lossage ("invalid %%Y operand");
7105 else if (REGNO (x) < 8)
7106 fputs (reg_names[REGNO (x)], file);
7107 else if (REGNO (x) >= 24 && REGNO (x) < 32)
7108 fputs (reg_names[REGNO (x)-16], file);
7110 output_operand_lossage ("invalid %%Y operand");
7113 /* Print out the low order register name of a register pair. */
7114 if (WORDS_BIG_ENDIAN)
7115 fputs (reg_names[REGNO (x)+1], file);
7117 fputs (reg_names[REGNO (x)], file);
7120 /* Print out the high order register name of a register pair. */
7121 if (WORDS_BIG_ENDIAN)
7122 fputs (reg_names[REGNO (x)], file);
7124 fputs (reg_names[REGNO (x)+1], file);
7127 /* Print out the second register name of a register pair or quad.
7128 I.e., R (%o0) => %o1. */
7129 fputs (reg_names[REGNO (x)+1], file);
7132 /* Print out the third register name of a register quad.
7133 I.e., S (%o0) => %o2. */
7134 fputs (reg_names[REGNO (x)+2], file);
7137 /* Print out the fourth register name of a register quad.
7138 I.e., T (%o0) => %o3. */
7139 fputs (reg_names[REGNO (x)+3], file);
7142 /* Print a condition code register. */
7143 if (REGNO (x) == SPARC_ICC_REG)
7145 /* We don't handle CC[X]_NOOVmode because they're not supposed
7147 if (GET_MODE (x) == CCmode)
7148 fputs ("%icc", file);
7149 else if (GET_MODE (x) == CCXmode)
7150 fputs ("%xcc", file);
7155 /* %fccN register */
7156 fputs (reg_names[REGNO (x)], file);
7159 /* Print the operand's address only. */
7160 output_address (XEXP (x, 0));
7163 /* In this case we need a register. Use %g0 if the
7164 operand is const0_rtx. */
7166 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
7168 fputs ("%g0", file);
7175 switch (GET_CODE (x))
7177 case IOR: fputs ("or", file); break;
7178 case AND: fputs ("and", file); break;
7179 case XOR: fputs ("xor", file); break;
7180 default: output_operand_lossage ("invalid %%A operand");
7185 switch (GET_CODE (x))
7187 case IOR: fputs ("orn", file); break;
7188 case AND: fputs ("andn", file); break;
7189 case XOR: fputs ("xnor", file); break;
7190 default: output_operand_lossage ("invalid %%B operand");
7194 /* These are used by the conditional move instructions. */
7198 enum rtx_code rc = GET_CODE (x);
7202 enum machine_mode mode = GET_MODE (XEXP (x, 0));
7203 if (mode == CCFPmode || mode == CCFPEmode)
7204 rc = reverse_condition_maybe_unordered (GET_CODE (x));
7206 rc = reverse_condition (GET_CODE (x));
7210 case NE: fputs ("ne", file); break;
7211 case EQ: fputs ("e", file); break;
7212 case GE: fputs ("ge", file); break;
7213 case GT: fputs ("g", file); break;
7214 case LE: fputs ("le", file); break;
7215 case LT: fputs ("l", file); break;
7216 case GEU: fputs ("geu", file); break;
7217 case GTU: fputs ("gu", file); break;
7218 case LEU: fputs ("leu", file); break;
7219 case LTU: fputs ("lu", file); break;
7220 case LTGT: fputs ("lg", file); break;
7221 case UNORDERED: fputs ("u", file); break;
7222 case ORDERED: fputs ("o", file); break;
7223 case UNLT: fputs ("ul", file); break;
7224 case UNLE: fputs ("ule", file); break;
7225 case UNGT: fputs ("ug", file); break;
7226 case UNGE: fputs ("uge", file); break;
7227 case UNEQ: fputs ("ue", file); break;
7228 default: output_operand_lossage (code == 'c'
7229 ? "invalid %%c operand"
7230 : "invalid %%C operand");
7235 /* These are used by the movr instruction pattern. */
7239 enum rtx_code rc = (code == 'd'
7240 ? reverse_condition (GET_CODE (x))
7244 case NE: fputs ("ne", file); break;
7245 case EQ: fputs ("e", file); break;
7246 case GE: fputs ("gez", file); break;
7247 case LT: fputs ("lz", file); break;
7248 case LE: fputs ("lez", file); break;
7249 case GT: fputs ("gz", file); break;
7250 default: output_operand_lossage (code == 'd'
7251 ? "invalid %%d operand"
7252 : "invalid %%D operand");
7259 /* Print a sign-extended character. */
7260 int i = trunc_int_for_mode (INTVAL (x), QImode);
7261 fprintf (file, "%d", i);
7266 /* Operand must be a MEM; write its address. */
7267 if (GET_CODE (x) != MEM)
7268 output_operand_lossage ("invalid %%f operand");
7269 output_address (XEXP (x, 0));
7274 /* Print a sign-extended 32-bit value. */
7276 if (GET_CODE(x) == CONST_INT)
7278 else if (GET_CODE(x) == CONST_DOUBLE)
7279 i = CONST_DOUBLE_LOW (x);
7282 output_operand_lossage ("invalid %%s operand");
7285 i = trunc_int_for_mode (i, SImode);
7286 fprintf (file, HOST_WIDE_INT_PRINT_DEC, i);
7291 /* Do nothing special. */
7295 /* Undocumented flag. */
7296 output_operand_lossage ("invalid operand output code");
7299 if (GET_CODE (x) == REG)
7300 fputs (reg_names[REGNO (x)], file);
7301 else if (GET_CODE (x) == MEM)
7304 /* Poor Sun assembler doesn't understand absolute addressing. */
7305 if (CONSTANT_P (XEXP (x, 0)))
7306 fputs ("%g0+", file);
7307 output_address (XEXP (x, 0));
7310 else if (GET_CODE (x) == HIGH)
7312 fputs ("%hi(", file);
7313 output_addr_const (file, XEXP (x, 0));
7316 else if (GET_CODE (x) == LO_SUM)
7318 print_operand (file, XEXP (x, 0), 0);
7319 if (TARGET_CM_MEDMID)
7320 fputs ("+%l44(", file);
7322 fputs ("+%lo(", file);
7323 output_addr_const (file, XEXP (x, 1));
7326 else if (GET_CODE (x) == CONST_DOUBLE
7327 && (GET_MODE (x) == VOIDmode
7328 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
7330 if (CONST_DOUBLE_HIGH (x) == 0)
7331 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
7332 else if (CONST_DOUBLE_HIGH (x) == -1
7333 && CONST_DOUBLE_LOW (x) < 0)
7334 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
7336 output_operand_lossage ("long long constant not a valid immediate operand");
7338 else if (GET_CODE (x) == CONST_DOUBLE)
7339 output_operand_lossage ("floating point constant not a valid immediate operand");
7340 else { output_addr_const (file, x); }
7343 /* Target hook for assembling integer objects. The sparc version has
7344 special handling for aligned DI-mode objects. */
7347 sparc_assemble_integer (rtx x, unsigned int size, int aligned_p)
7349 /* ??? We only output .xword's for symbols and only then in environments
7350 where the assembler can handle them. */
7351 if (aligned_p && size == 8
7352 && (GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE))
7356 assemble_integer_with_op ("\t.xword\t", x);
7361 assemble_aligned_integer (4, const0_rtx);
7362 assemble_aligned_integer (4, x);
7366 return default_assemble_integer (x, size, aligned_p);
7369 /* Return the value of a code used in the .proc pseudo-op that says
7370 what kind of result this function returns. For non-C types, we pick
7371 the closest C type. */
7373 #ifndef SHORT_TYPE_SIZE
7374 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
7377 #ifndef INT_TYPE_SIZE
7378 #define INT_TYPE_SIZE BITS_PER_WORD
7381 #ifndef LONG_TYPE_SIZE
7382 #define LONG_TYPE_SIZE BITS_PER_WORD
7385 #ifndef LONG_LONG_TYPE_SIZE
7386 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
7389 #ifndef FLOAT_TYPE_SIZE
7390 #define FLOAT_TYPE_SIZE BITS_PER_WORD
7393 #ifndef DOUBLE_TYPE_SIZE
7394 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
7397 #ifndef LONG_DOUBLE_TYPE_SIZE
7398 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
7402 sparc_type_code (register tree type)
7404 register unsigned long qualifiers = 0;
7405 register unsigned shift;
7407 /* Only the first 30 bits of the qualifier are valid. We must refrain from
7408 setting more, since some assemblers will give an error for this. Also,
7409 we must be careful to avoid shifts of 32 bits or more to avoid getting
7410 unpredictable results. */
7412 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
7414 switch (TREE_CODE (type))
7420 qualifiers |= (3 << shift);
7425 qualifiers |= (2 << shift);
7429 case REFERENCE_TYPE:
7431 qualifiers |= (1 << shift);
7435 return (qualifiers | 8);
7438 case QUAL_UNION_TYPE:
7439 return (qualifiers | 9);
7442 return (qualifiers | 10);
7445 return (qualifiers | 16);
7448 /* If this is a range type, consider it to be the underlying
7450 if (TREE_TYPE (type) != 0)
7453 /* Carefully distinguish all the standard types of C,
7454 without messing up if the language is not C. We do this by
7455 testing TYPE_PRECISION and TYPE_UNSIGNED. The old code used to
7456 look at both the names and the above fields, but that's redundant.
7457 Any type whose size is between two C types will be considered
7458 to be the wider of the two types. Also, we do not have a
7459 special code to use for "long long", so anything wider than
7460 long is treated the same. Note that we can't distinguish
7461 between "int" and "long" in this code if they are the same
7462 size, but that's fine, since neither can the assembler. */
7464 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
7465 return (qualifiers | (TYPE_UNSIGNED (type) ? 12 : 2));
7467 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
7468 return (qualifiers | (TYPE_UNSIGNED (type) ? 13 : 3));
7470 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
7471 return (qualifiers | (TYPE_UNSIGNED (type) ? 14 : 4));
7474 return (qualifiers | (TYPE_UNSIGNED (type) ? 15 : 5));
7477 /* If this is a range type, consider it to be the underlying
7479 if (TREE_TYPE (type) != 0)
7482 /* Carefully distinguish all the standard types of C,
7483 without messing up if the language is not C. */
7485 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
7486 return (qualifiers | 6);
7489 return (qualifiers | 7);
7491 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
7492 /* ??? We need to distinguish between double and float complex types,
7493 but I don't know how yet because I can't reach this code from
7494 existing front-ends. */
7495 return (qualifiers | 7); /* Who knows? */
7498 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
7499 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
7500 case FILE_TYPE: /* GNU Pascal FILE type. */
7501 case SET_TYPE: /* GNU Pascal SET type. */
7502 case LANG_TYPE: /* ? */
7506 abort (); /* Not a type! */
7513 /* Nested function support. */
7515 /* Emit RTL insns to initialize the variable parts of a trampoline.
7516 FNADDR is an RTX for the address of the function's pure code.
7517 CXT is an RTX for the static chain value for the function.
7519 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
7520 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
7521 (to store insns). This is a bit excessive. Perhaps a different
7522 mechanism would be better here.
7524 Emit enough FLUSH insns to synchronize the data and instruction caches. */
7527 sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
7529 /* SPARC 32-bit trampoline:
7532 sethi %hi(static), %g2
7534 or %g2, %lo(static), %g2
7536 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
7537 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
7541 (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
7542 expand_binop (SImode, ior_optab,
7543 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
7544 size_int (10), 0, 1),
7545 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
7546 NULL_RTX, 1, OPTAB_DIRECT));
7549 (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
7550 expand_binop (SImode, ior_optab,
7551 expand_shift (RSHIFT_EXPR, SImode, cxt,
7552 size_int (10), 0, 1),
7553 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
7554 NULL_RTX, 1, OPTAB_DIRECT));
7557 (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
7558 expand_binop (SImode, ior_optab,
7559 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
7560 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
7561 NULL_RTX, 1, OPTAB_DIRECT));
7564 (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
7565 expand_binop (SImode, ior_optab,
7566 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
7567 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
7568 NULL_RTX, 1, OPTAB_DIRECT));
7570 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
7571 aligned on a 16 byte boundary so one flush clears it all. */
7572 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
7573 if (sparc_cpu != PROCESSOR_ULTRASPARC
7574 && sparc_cpu != PROCESSOR_ULTRASPARC3)
7575 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
7576 plus_constant (tramp, 8)))));
7578 /* Call __enable_execute_stack after writing onto the stack to make sure
7579 the stack address is accessible. */
7580 #ifdef ENABLE_EXECUTE_STACK
7581 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
7582 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
7587 /* The 64-bit version is simpler because it makes more sense to load the
7588 values as "immediate" data out of the trampoline. It's also easier since
7589 we can read the PC without clobbering a register. */
7592 sparc64_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
7594 /* SPARC 64-bit trampoline:
7603 emit_move_insn (gen_rtx_MEM (SImode, tramp),
7604 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
7605 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
7606 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
7607 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
7608 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
7609 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
7610 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
7611 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
7612 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
7613 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
7615 if (sparc_cpu != PROCESSOR_ULTRASPARC
7616 && sparc_cpu != PROCESSOR_ULTRASPARC3)
7617 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
7619 /* Call __enable_execute_stack after writing onto the stack to make sure
7620 the stack address is accessible. */
7621 #ifdef ENABLE_EXECUTE_STACK
7622 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
7623 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
7627 /* Adjust the cost of a scheduling dependency. Return the new cost of
7628 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7631 supersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
7633 enum attr_type insn_type;
7635 if (! recog_memoized (insn))
7638 insn_type = get_attr_type (insn);
7640 if (REG_NOTE_KIND (link) == 0)
7642 /* Data dependency; DEP_INSN writes a register that INSN reads some
7645 /* if a load, then the dependence must be on the memory address;
7646 add an extra "cycle". Note that the cost could be two cycles
7647 if the reg was written late in an instruction group; we ca not tell
7649 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
7652 /* Get the delay only if the address of the store is the dependence. */
7653 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
7655 rtx pat = PATTERN(insn);
7656 rtx dep_pat = PATTERN (dep_insn);
7658 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7659 return cost; /* This should not happen! */
7661 /* The dependency between the two instructions was on the data that
7662 is being stored. Assume that this implies that the address of the
7663 store is not dependent. */
7664 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7667 return cost + 3; /* An approximation. */
7670 /* A shift instruction cannot receive its data from an instruction
7671 in the same cycle; add a one cycle penalty. */
7672 if (insn_type == TYPE_SHIFT)
7673 return cost + 3; /* Split before cascade into shift. */
7677 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7678 INSN writes some cycles later. */
7680 /* These are only significant for the fpu unit; writing a fp reg before
7681 the fpu has finished with it stalls the processor. */
7683 /* Reusing an integer register causes no problems. */
7684 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7692 hypersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
7694 enum attr_type insn_type, dep_type;
7695 rtx pat = PATTERN(insn);
7696 rtx dep_pat = PATTERN (dep_insn);
7698 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7701 insn_type = get_attr_type (insn);
7702 dep_type = get_attr_type (dep_insn);
7704 switch (REG_NOTE_KIND (link))
7707 /* Data dependency; DEP_INSN writes a register that INSN reads some
7714 /* Get the delay iff the address of the store is the dependence. */
7715 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7718 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7725 /* If a load, then the dependence must be on the memory address. If
7726 the addresses aren't equal, then it might be a false dependency */
7727 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7729 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7730 || GET_CODE (SET_DEST (dep_pat)) != MEM
7731 || GET_CODE (SET_SRC (pat)) != MEM
7732 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
7733 XEXP (SET_SRC (pat), 0)))
7741 /* Compare to branch latency is 0. There is no benefit from
7742 separating compare and branch. */
7743 if (dep_type == TYPE_COMPARE)
7745 /* Floating point compare to branch latency is less than
7746 compare to conditional move. */
7747 if (dep_type == TYPE_FPCMP)
7756 /* Anti-dependencies only penalize the fpu unit. */
7757 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7769 sparc_adjust_cost(rtx insn, rtx link, rtx dep, int cost)
7773 case PROCESSOR_SUPERSPARC:
7774 cost = supersparc_adjust_cost (insn, link, dep, cost);
7776 case PROCESSOR_HYPERSPARC:
7777 case PROCESSOR_SPARCLITE86X:
7778 cost = hypersparc_adjust_cost (insn, link, dep, cost);
7787 sparc_sched_init (FILE *dump ATTRIBUTE_UNUSED,
7788 int sched_verbose ATTRIBUTE_UNUSED,
7789 int max_ready ATTRIBUTE_UNUSED)
7794 sparc_use_sched_lookahead (void)
7796 if (sparc_cpu == PROCESSOR_ULTRASPARC
7797 || sparc_cpu == PROCESSOR_ULTRASPARC3)
7799 if ((1 << sparc_cpu) &
7800 ((1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
7801 (1 << PROCESSOR_SPARCLITE86X)))
7807 sparc_issue_rate (void)
7814 /* Assume V9 processors are capable of at least dual-issue. */
7816 case PROCESSOR_SUPERSPARC:
7818 case PROCESSOR_HYPERSPARC:
7819 case PROCESSOR_SPARCLITE86X:
7821 case PROCESSOR_ULTRASPARC:
7822 case PROCESSOR_ULTRASPARC3:
7828 set_extends (rtx insn)
7830 register rtx pat = PATTERN (insn);
7832 switch (GET_CODE (SET_SRC (pat)))
7834 /* Load and some shift instructions zero extend. */
7837 /* sethi clears the high bits */
7839 /* LO_SUM is used with sethi. sethi cleared the high
7840 bits and the values used with lo_sum are positive */
7842 /* Store flag stores 0 or 1 */
7852 rtx op0 = XEXP (SET_SRC (pat), 0);
7853 rtx op1 = XEXP (SET_SRC (pat), 1);
7854 if (GET_CODE (op1) == CONST_INT)
7855 return INTVAL (op1) >= 0;
7856 if (GET_CODE (op0) != REG)
7858 if (sparc_check_64 (op0, insn) == 1)
7860 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7865 rtx op0 = XEXP (SET_SRC (pat), 0);
7866 rtx op1 = XEXP (SET_SRC (pat), 1);
7867 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
7869 if (GET_CODE (op1) == CONST_INT)
7870 return INTVAL (op1) >= 0;
7871 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7874 return GET_MODE (SET_SRC (pat)) == SImode;
7875 /* Positive integers leave the high bits zero. */
7877 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
7879 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
7882 return - (GET_MODE (SET_SRC (pat)) == SImode);
7884 return sparc_check_64 (SET_SRC (pat), insn);
7890 /* We _ought_ to have only one kind per function, but... */
7891 static GTY(()) rtx sparc_addr_diff_list;
7892 static GTY(()) rtx sparc_addr_list;
7895 sparc_defer_case_vector (rtx lab, rtx vec, int diff)
7897 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
7899 sparc_addr_diff_list
7900 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
7902 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
7906 sparc_output_addr_vec (rtx vec)
7908 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7909 int idx, vlen = XVECLEN (body, 0);
7911 #ifdef ASM_OUTPUT_ADDR_VEC_START
7912 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7915 #ifdef ASM_OUTPUT_CASE_LABEL
7916 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7919 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7922 for (idx = 0; idx < vlen; idx++)
7924 ASM_OUTPUT_ADDR_VEC_ELT
7925 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
7928 #ifdef ASM_OUTPUT_ADDR_VEC_END
7929 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7934 sparc_output_addr_diff_vec (rtx vec)
7936 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7937 rtx base = XEXP (XEXP (body, 0), 0);
7938 int idx, vlen = XVECLEN (body, 1);
7940 #ifdef ASM_OUTPUT_ADDR_VEC_START
7941 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7944 #ifdef ASM_OUTPUT_CASE_LABEL
7945 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7948 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7951 for (idx = 0; idx < vlen; idx++)
7953 ASM_OUTPUT_ADDR_DIFF_ELT
7956 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
7957 CODE_LABEL_NUMBER (base));
7960 #ifdef ASM_OUTPUT_ADDR_VEC_END
7961 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7966 sparc_output_deferred_case_vectors (void)
7971 if (sparc_addr_list == NULL_RTX
7972 && sparc_addr_diff_list == NULL_RTX)
7975 /* Align to cache line in the function's code section. */
7976 function_section (current_function_decl);
7978 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
7980 ASM_OUTPUT_ALIGN (asm_out_file, align);
7982 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
7983 sparc_output_addr_vec (XEXP (t, 0));
7984 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
7985 sparc_output_addr_diff_vec (XEXP (t, 0));
7987 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
7990 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
7991 unknown. Return 1 if the high bits are zero, -1 if the register is
7994 sparc_check_64 (rtx x, rtx insn)
7996 /* If a register is set only once it is safe to ignore insns this
7997 code does not know how to handle. The loop will either recognize
7998 the single set and return the correct value or fail to recognize
8003 if (GET_CODE (x) != REG)
8006 if (GET_MODE (x) == DImode)
8007 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
8009 if (flag_expensive_optimizations
8010 && REG_N_SETS (REGNO (y)) == 1)
8016 insn = get_last_insn_anywhere ();
8021 while ((insn = PREV_INSN (insn)))
8023 switch (GET_CODE (insn))
8036 rtx pat = PATTERN (insn);
8037 if (GET_CODE (pat) != SET)
8039 if (rtx_equal_p (x, SET_DEST (pat)))
8040 return set_extends (insn);
8041 if (y && rtx_equal_p (y, SET_DEST (pat)))
8042 return set_extends (insn);
8043 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
8051 /* Returns assembly code to perform a DImode shift using
8052 a 64-bit global or out register on SPARC-V8+. */
8054 output_v8plus_shift (rtx *operands, rtx insn, const char *opcode)
8056 static char asm_code[60];
8058 /* The scratch register is only required when the destination
8059 register is not a 64-bit global or out register. */
8060 if (which_alternative != 2)
8061 operands[3] = operands[0];
8063 /* We can only shift by constants <= 63. */
8064 if (GET_CODE (operands[2]) == CONST_INT)
8065 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
8067 if (GET_CODE (operands[1]) == CONST_INT)
8069 output_asm_insn ("mov\t%1, %3", operands);
8073 output_asm_insn ("sllx\t%H1, 32, %3", operands);
8074 if (sparc_check_64 (operands[1], insn) <= 0)
8075 output_asm_insn ("srl\t%L1, 0, %L1", operands);
8076 output_asm_insn ("or\t%L1, %3, %3", operands);
8079 strcpy(asm_code, opcode);
8081 if (which_alternative != 2)
8082 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
8084 return strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
8087 /* Output rtl to increment the profiler label LABELNO
8088 for profiling a function entry. */
8091 sparc_profile_hook (int labelno)
8096 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
8097 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
8098 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
8100 emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lab, Pmode);
8103 #ifdef OBJECT_FORMAT_ELF
8105 sparc_elf_asm_named_section (const char *name, unsigned int flags,
8108 if (flags & SECTION_MERGE)
8110 /* entsize cannot be expressed in this section attributes
8112 default_elf_asm_named_section (name, flags, decl);
8116 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
8118 if (!(flags & SECTION_DEBUG))
8119 fputs (",#alloc", asm_out_file);
8120 if (flags & SECTION_WRITE)
8121 fputs (",#write", asm_out_file);
8122 if (flags & SECTION_TLS)
8123 fputs (",#tls", asm_out_file);
8124 if (flags & SECTION_CODE)
8125 fputs (",#execinstr", asm_out_file);
8127 /* ??? Handle SECTION_BSS. */
8129 fputc ('\n', asm_out_file);
8131 #endif /* OBJECT_FORMAT_ELF */
8133 /* We do not allow indirect calls to be optimized into sibling calls.
8135 We cannot use sibling calls when delayed branches are disabled
8136 because they will likely require the call delay slot to be filled.
8138 Also, on SPARC 32-bit we cannot emit a sibling call when the
8139 current function returns a structure. This is because the "unimp
8140 after call" convention would cause the callee to return to the
8141 wrong place. The generic code already disallows cases where the
8142 function being called returns a structure.
8144 It may seem strange how this last case could occur. Usually there
8145 is code after the call which jumps to epilogue code which dumps the
8146 return value into the struct return area. That ought to invalidate
8147 the sibling call right? Well, in the C++ case we can end up passing
8148 the pointer to the struct return area to a constructor (which returns
8149 void) and then nothing else happens. Such a sibling call would look
8150 valid without the added check here. */
8152 sparc_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
8155 && flag_delayed_branch
8156 && (TARGET_ARCH64 || ! current_function_returns_struct));
8159 /* libfunc renaming. */
8160 #include "config/gofast.h"
8163 sparc_init_libfuncs (void)
8167 /* Use the subroutines that Sun's library provides for integer
8168 multiply and divide. The `*' prevents an underscore from
8169 being prepended by the compiler. .umul is a little faster
8171 set_optab_libfunc (smul_optab, SImode, "*.umul");
8172 set_optab_libfunc (sdiv_optab, SImode, "*.div");
8173 set_optab_libfunc (udiv_optab, SImode, "*.udiv");
8174 set_optab_libfunc (smod_optab, SImode, "*.rem");
8175 set_optab_libfunc (umod_optab, SImode, "*.urem");
8177 /* TFmode arithmetic. These names are part of the SPARC 32bit ABI. */
8178 set_optab_libfunc (add_optab, TFmode, "_Q_add");
8179 set_optab_libfunc (sub_optab, TFmode, "_Q_sub");
8180 set_optab_libfunc (neg_optab, TFmode, "_Q_neg");
8181 set_optab_libfunc (smul_optab, TFmode, "_Q_mul");
8182 set_optab_libfunc (sdiv_optab, TFmode, "_Q_div");
8184 /* We can define the TFmode sqrt optab only if TARGET_FPU. This
8185 is because with soft-float, the SFmode and DFmode sqrt
8186 instructions will be absent, and the compiler will notice and
8187 try to use the TFmode sqrt instruction for calls to the
8188 builtin function sqrt, but this fails. */
8190 set_optab_libfunc (sqrt_optab, TFmode, "_Q_sqrt");
8192 set_optab_libfunc (eq_optab, TFmode, "_Q_feq");
8193 set_optab_libfunc (ne_optab, TFmode, "_Q_fne");
8194 set_optab_libfunc (gt_optab, TFmode, "_Q_fgt");
8195 set_optab_libfunc (ge_optab, TFmode, "_Q_fge");
8196 set_optab_libfunc (lt_optab, TFmode, "_Q_flt");
8197 set_optab_libfunc (le_optab, TFmode, "_Q_fle");
8199 set_conv_libfunc (sext_optab, TFmode, SFmode, "_Q_stoq");
8200 set_conv_libfunc (sext_optab, TFmode, DFmode, "_Q_dtoq");
8201 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_Q_qtos");
8202 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_Q_qtod");
8204 set_conv_libfunc (sfix_optab, SImode, TFmode, "_Q_qtoi");
8205 set_conv_libfunc (ufix_optab, SImode, TFmode, "_Q_qtou");
8206 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_Q_itoq");
8208 if (DITF_CONVERSION_LIBFUNCS)
8210 set_conv_libfunc (sfix_optab, DImode, TFmode, "_Q_qtoll");
8211 set_conv_libfunc (ufix_optab, DImode, TFmode, "_Q_qtoull");
8212 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_Q_lltoq");
8215 if (SUN_CONVERSION_LIBFUNCS)
8217 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftoll");
8218 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoull");
8219 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtoll");
8220 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoull");
8225 /* In the SPARC 64bit ABI, SImode multiply and divide functions
8226 do not exist in the library. Make sure the compiler does not
8227 emit calls to them by accident. (It should always use the
8228 hardware instructions.) */
8229 set_optab_libfunc (smul_optab, SImode, 0);
8230 set_optab_libfunc (sdiv_optab, SImode, 0);
8231 set_optab_libfunc (udiv_optab, SImode, 0);
8232 set_optab_libfunc (smod_optab, SImode, 0);
8233 set_optab_libfunc (umod_optab, SImode, 0);
8235 if (SUN_INTEGER_MULTIPLY_64)
8237 set_optab_libfunc (smul_optab, DImode, "__mul64");
8238 set_optab_libfunc (sdiv_optab, DImode, "__div64");
8239 set_optab_libfunc (udiv_optab, DImode, "__udiv64");
8240 set_optab_libfunc (smod_optab, DImode, "__rem64");
8241 set_optab_libfunc (umod_optab, DImode, "__urem64");
8244 if (SUN_CONVERSION_LIBFUNCS)
8246 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftol");
8247 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoul");
8248 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtol");
8249 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoul");
8253 gofast_maybe_init_libfuncs ();
8257 sparc_extra_constraint_check (rtx op, int c, int strict)
8262 && (c == 'T' || c == 'U'))
8268 return fp_sethi_p (op);
8271 return fp_mov_p (op);
8274 return fp_high_losum_p (op);
8278 || (GET_CODE (op) == REG
8279 && (REGNO (op) < FIRST_PSEUDO_REGISTER
8280 || reg_renumber[REGNO (op)] >= 0)))
8281 return register_ok_for_ldd (op);
8293 /* Our memory extra constraints have to emulate the
8294 behavior of 'm' and 'o' in order for reload to work
8296 if (GET_CODE (op) == MEM)
8299 if ((TARGET_ARCH64 || mem_min_alignment (op, 8))
8301 || strict_memory_address_p (Pmode, XEXP (op, 0))))
8306 reload_ok_mem = (reload_in_progress
8307 && GET_CODE (op) == REG
8308 && REGNO (op) >= FIRST_PSEUDO_REGISTER
8309 && reg_renumber [REGNO (op)] < 0);
8312 return reload_ok_mem;
8315 /* ??? This duplicates information provided to the compiler by the
8316 ??? scheduler description. Some day, teach genautomata to output
8317 ??? the latencies and then CSE will just use that. */
8320 sparc_rtx_costs (rtx x, int code, int outer_code, int *total)
8322 enum machine_mode mode = GET_MODE (x);
8323 bool float_mode_p = FLOAT_MODE_P (mode);
8328 if (INTVAL (x) < 0x1000 && INTVAL (x) >= -0x1000)
8346 if (GET_MODE (x) == DImode
8347 && ((XINT (x, 3) == 0
8348 && (unsigned HOST_WIDE_INT) XINT (x, 2) < 0x1000)
8349 || (XINT (x, 3) == -1
8351 && XINT (x, 2) >= -0x1000)))
8358 /* If outer-code was a sign or zero extension, a cost
8359 of COSTS_N_INSNS (1) was already added in. This is
8360 why we are subtracting it back out. */
8361 if (outer_code == ZERO_EXTEND)
8363 *total = sparc_costs->int_zload - COSTS_N_INSNS (1);
8365 else if (outer_code == SIGN_EXTEND)
8367 *total = sparc_costs->int_sload - COSTS_N_INSNS (1);
8369 else if (float_mode_p)
8371 *total = sparc_costs->float_load;
8375 *total = sparc_costs->int_load;
8383 *total = sparc_costs->float_plusminus;
8385 *total = COSTS_N_INSNS (1);
8390 *total = sparc_costs->float_mul;
8391 else if (! TARGET_HARD_MUL)
8392 *total = COSTS_N_INSNS (25);
8398 if (sparc_costs->int_mul_bit_factor)
8402 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
8404 unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
8405 for (nbits = 0; value != 0; value &= value - 1)
8408 else if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
8409 && GET_MODE (XEXP (x, 1)) == DImode)
8411 rtx x1 = XEXP (x, 1);
8412 unsigned HOST_WIDE_INT value1 = XINT (x1, 2);
8413 unsigned HOST_WIDE_INT value2 = XINT (x1, 3);
8415 for (nbits = 0; value1 != 0; value1 &= value1 - 1)
8417 for (; value2 != 0; value2 &= value2 - 1)
8425 bit_cost = (nbits - 3) / sparc_costs->int_mul_bit_factor;
8426 bit_cost = COSTS_N_INSNS (bit_cost);
8430 *total = sparc_costs->int_mulX + bit_cost;
8432 *total = sparc_costs->int_mul + bit_cost;
8439 *total = COSTS_N_INSNS (1) + sparc_costs->shift_penalty;
8449 *total = sparc_costs->float_div_df;
8451 *total = sparc_costs->float_div_sf;
8456 *total = sparc_costs->int_divX;
8458 *total = sparc_costs->int_div;
8465 *total = COSTS_N_INSNS (1);
8472 case UNSIGNED_FLOAT:
8476 case FLOAT_TRUNCATE:
8477 *total = sparc_costs->float_move;
8482 *total = sparc_costs->float_sqrt_df;
8484 *total = sparc_costs->float_sqrt_sf;
8489 *total = sparc_costs->float_cmp;
8491 *total = COSTS_N_INSNS (1);
8496 *total = sparc_costs->float_cmove;
8498 *total = sparc_costs->int_cmove;
8506 /* Emit the sequence of insns SEQ while preserving the register REG. */
8509 emit_and_preserve (rtx seq, rtx reg)
8511 rtx slot = gen_rtx_MEM (word_mode,
8512 plus_constant (stack_pointer_rtx, SPARC_STACK_BIAS));
8514 emit_stack_pointer_decrement (GEN_INT (UNITS_PER_WORD));
8515 emit_insn (gen_rtx_SET (VOIDmode, slot, reg));
8517 emit_insn (gen_rtx_SET (VOIDmode, reg, slot));
8518 emit_stack_pointer_increment (GEN_INT (UNITS_PER_WORD));
8521 /* Output code to add DELTA to the first argument, and then jump to FUNCTION.
8522 Used for C++ multiple inheritance. */
8525 sparc_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
8526 HOST_WIDE_INT delta,
8527 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
8530 rtx this, insn, funexp, delta_rtx;
8531 unsigned int int_arg_first;
8533 reload_completed = 1;
8534 epilogue_completed = 1;
8536 reset_block_changes ();
8538 emit_note (NOTE_INSN_PROLOGUE_END);
8540 if (flag_delayed_branch)
8542 /* We will emit a regular sibcall below, so we need to instruct
8543 output_sibcall that we are in a leaf function. */
8544 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 1;
8546 /* This will cause final.c to invoke leaf_renumber_regs so we
8547 must behave as if we were in a not-yet-leafified function. */
8548 int_arg_first = SPARC_INCOMING_INT_ARG_FIRST;
8552 /* We will emit the sibcall manually below, so we will need to
8553 manually spill non-leaf registers. */
8554 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 0;
8556 /* We really are in a leaf function. */
8557 int_arg_first = SPARC_OUTGOING_INT_ARG_FIRST;
8560 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
8561 returns a structure, the structure return pointer is there instead. */
8562 if (TARGET_ARCH64 && aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
8563 this = gen_rtx_REG (Pmode, int_arg_first + 1);
8565 this = gen_rtx_REG (Pmode, int_arg_first);
8567 /* Add DELTA. When possible use a plain add, otherwise load it into
8568 a register first. */
8569 delta_rtx = GEN_INT (delta);
8570 if (!SPARC_SIMM13_P (delta))
8572 rtx scratch = gen_rtx_REG (Pmode, 1);
8574 if (input_operand (delta_rtx, GET_MODE (scratch)))
8575 emit_insn (gen_rtx_SET (VOIDmode, scratch, delta_rtx));
8579 sparc_emit_set_const64 (scratch, delta_rtx);
8581 sparc_emit_set_const32 (scratch, delta_rtx);
8584 delta_rtx = scratch;
8587 emit_insn (gen_rtx_SET (VOIDmode,
8589 gen_rtx_PLUS (Pmode, this, delta_rtx)));
8591 /* Generate a tail call to the target function. */
8592 if (! TREE_USED (function))
8594 assemble_external (function);
8595 TREE_USED (function) = 1;
8597 funexp = XEXP (DECL_RTL (function), 0);
8599 if (flag_delayed_branch)
8601 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
8602 insn = emit_call_insn (gen_sibcall (funexp));
8603 SIBLING_CALL_P (insn) = 1;
8607 /* The hoops we have to jump through in order to generate a sibcall
8608 without using delay slots... */
8609 rtx spill_reg, seq, scratch = gen_rtx_REG (Pmode, 1);
8613 spill_reg = gen_rtx_REG (word_mode, 15); /* %o7 */
8615 load_pic_register (); /* clobbers %o7 */
8616 scratch = legitimize_pic_address (funexp, Pmode, scratch);
8619 emit_and_preserve (seq, spill_reg);
8621 else if (TARGET_ARCH32)
8623 emit_insn (gen_rtx_SET (VOIDmode,
8625 gen_rtx_HIGH (SImode, funexp)));
8626 emit_insn (gen_rtx_SET (VOIDmode,
8628 gen_rtx_LO_SUM (SImode, scratch, funexp)));
8630 else /* TARGET_ARCH64 */
8632 switch (sparc_cmodel)
8636 /* The destination can serve as a temporary. */
8637 sparc_emit_set_symbolic_const64 (scratch, funexp, scratch);
8642 /* The destination cannot serve as a temporary. */
8643 spill_reg = gen_rtx_REG (DImode, 15); /* %o7 */
8645 sparc_emit_set_symbolic_const64 (scratch, funexp, spill_reg);
8648 emit_and_preserve (seq, spill_reg);
8656 emit_jump_insn (gen_indirect_jump (scratch));
8661 /* Run just enough of rest_of_compilation to get the insns emitted.
8662 There's not really enough bulk here to make other passes such as
8663 instruction scheduling worth while. Note that use_thunk calls
8664 assemble_start_function and assemble_end_function. */
8665 insn = get_insns ();
8666 insn_locators_initialize ();
8667 shorten_branches (insn);
8668 final_start_function (insn, file, 1);
8669 final (insn, file, 1, 0);
8670 final_end_function ();
8672 reload_completed = 0;
8673 epilogue_completed = 0;
8677 /* How to allocate a 'struct machine_function'. */
8679 static struct machine_function *
8680 sparc_init_machine_status (void)
8682 return ggc_alloc_cleared (sizeof (struct machine_function));
8685 /* Locate some local-dynamic symbol still in use by this function
8686 so that we can print its name in local-dynamic base patterns. */
8689 get_some_local_dynamic_name (void)
8693 if (cfun->machine->some_ld_name)
8694 return cfun->machine->some_ld_name;
8696 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8698 && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
8699 return cfun->machine->some_ld_name;
8705 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
8710 && GET_CODE (x) == SYMBOL_REF
8711 && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8713 cfun->machine->some_ld_name = XSTR (x, 0);
8720 /* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
8721 We need to emit DTP-relative relocations. */
8724 sparc_output_dwarf_dtprel (FILE *file, int size, rtx x)
8729 fputs ("\t.word\t%r_tls_dtpoff32(", file);
8732 fputs ("\t.xword\t%r_tls_dtpoff64(", file);
8737 output_addr_const (file, x);
8741 #include "gt-sparc.h"