1 /* Subroutines for insn-output.c for SPARC.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 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 "insn-codes.h"
36 #include "conditions.h"
38 #include "insn-attr.h"
49 #include "target-def.h"
50 #include "cfglayout.h"
51 #include "tree-gimple.h"
52 #include "langhooks.h"
56 struct processor_costs cypress_costs = {
57 COSTS_N_INSNS (2), /* int load */
58 COSTS_N_INSNS (2), /* int signed load */
59 COSTS_N_INSNS (2), /* int zeroed load */
60 COSTS_N_INSNS (2), /* float load */
61 COSTS_N_INSNS (5), /* fmov, fneg, fabs */
62 COSTS_N_INSNS (5), /* fadd, fsub */
63 COSTS_N_INSNS (1), /* fcmp */
64 COSTS_N_INSNS (1), /* fmov, fmovr */
65 COSTS_N_INSNS (7), /* fmul */
66 COSTS_N_INSNS (37), /* fdivs */
67 COSTS_N_INSNS (37), /* fdivd */
68 COSTS_N_INSNS (63), /* fsqrts */
69 COSTS_N_INSNS (63), /* fsqrtd */
70 COSTS_N_INSNS (1), /* imul */
71 COSTS_N_INSNS (1), /* imulX */
72 0, /* imul bit factor */
73 COSTS_N_INSNS (1), /* idiv */
74 COSTS_N_INSNS (1), /* idivX */
75 COSTS_N_INSNS (1), /* movcc/movr */
76 0, /* shift penalty */
80 struct processor_costs supersparc_costs = {
81 COSTS_N_INSNS (1), /* int load */
82 COSTS_N_INSNS (1), /* int signed load */
83 COSTS_N_INSNS (1), /* int zeroed load */
84 COSTS_N_INSNS (0), /* float load */
85 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
86 COSTS_N_INSNS (3), /* fadd, fsub */
87 COSTS_N_INSNS (3), /* fcmp */
88 COSTS_N_INSNS (1), /* fmov, fmovr */
89 COSTS_N_INSNS (3), /* fmul */
90 COSTS_N_INSNS (6), /* fdivs */
91 COSTS_N_INSNS (9), /* fdivd */
92 COSTS_N_INSNS (12), /* fsqrts */
93 COSTS_N_INSNS (12), /* fsqrtd */
94 COSTS_N_INSNS (4), /* imul */
95 COSTS_N_INSNS (4), /* imulX */
96 0, /* imul bit factor */
97 COSTS_N_INSNS (4), /* idiv */
98 COSTS_N_INSNS (4), /* idivX */
99 COSTS_N_INSNS (1), /* movcc/movr */
100 1, /* shift penalty */
104 struct processor_costs hypersparc_costs = {
105 COSTS_N_INSNS (1), /* int load */
106 COSTS_N_INSNS (1), /* int signed load */
107 COSTS_N_INSNS (1), /* int zeroed load */
108 COSTS_N_INSNS (1), /* float load */
109 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
110 COSTS_N_INSNS (1), /* fadd, fsub */
111 COSTS_N_INSNS (1), /* fcmp */
112 COSTS_N_INSNS (1), /* fmov, fmovr */
113 COSTS_N_INSNS (1), /* fmul */
114 COSTS_N_INSNS (8), /* fdivs */
115 COSTS_N_INSNS (12), /* fdivd */
116 COSTS_N_INSNS (17), /* fsqrts */
117 COSTS_N_INSNS (17), /* fsqrtd */
118 COSTS_N_INSNS (17), /* imul */
119 COSTS_N_INSNS (17), /* imulX */
120 0, /* imul bit factor */
121 COSTS_N_INSNS (17), /* idiv */
122 COSTS_N_INSNS (17), /* idivX */
123 COSTS_N_INSNS (1), /* movcc/movr */
124 0, /* shift penalty */
128 struct processor_costs sparclet_costs = {
129 COSTS_N_INSNS (3), /* int load */
130 COSTS_N_INSNS (3), /* int signed load */
131 COSTS_N_INSNS (1), /* int zeroed load */
132 COSTS_N_INSNS (1), /* float load */
133 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
134 COSTS_N_INSNS (1), /* fadd, fsub */
135 COSTS_N_INSNS (1), /* fcmp */
136 COSTS_N_INSNS (1), /* fmov, fmovr */
137 COSTS_N_INSNS (1), /* fmul */
138 COSTS_N_INSNS (1), /* fdivs */
139 COSTS_N_INSNS (1), /* fdivd */
140 COSTS_N_INSNS (1), /* fsqrts */
141 COSTS_N_INSNS (1), /* fsqrtd */
142 COSTS_N_INSNS (5), /* imul */
143 COSTS_N_INSNS (5), /* imulX */
144 0, /* imul bit factor */
145 COSTS_N_INSNS (5), /* idiv */
146 COSTS_N_INSNS (5), /* idivX */
147 COSTS_N_INSNS (1), /* movcc/movr */
148 0, /* shift penalty */
152 struct processor_costs ultrasparc_costs = {
153 COSTS_N_INSNS (2), /* int load */
154 COSTS_N_INSNS (3), /* int signed load */
155 COSTS_N_INSNS (2), /* int zeroed load */
156 COSTS_N_INSNS (2), /* float load */
157 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
158 COSTS_N_INSNS (4), /* fadd, fsub */
159 COSTS_N_INSNS (1), /* fcmp */
160 COSTS_N_INSNS (2), /* fmov, fmovr */
161 COSTS_N_INSNS (4), /* fmul */
162 COSTS_N_INSNS (13), /* fdivs */
163 COSTS_N_INSNS (23), /* fdivd */
164 COSTS_N_INSNS (13), /* fsqrts */
165 COSTS_N_INSNS (23), /* fsqrtd */
166 COSTS_N_INSNS (4), /* imul */
167 COSTS_N_INSNS (4), /* imulX */
168 2, /* imul bit factor */
169 COSTS_N_INSNS (37), /* idiv */
170 COSTS_N_INSNS (68), /* idivX */
171 COSTS_N_INSNS (2), /* movcc/movr */
172 2, /* shift penalty */
176 struct processor_costs ultrasparc3_costs = {
177 COSTS_N_INSNS (2), /* int load */
178 COSTS_N_INSNS (3), /* int signed load */
179 COSTS_N_INSNS (3), /* int zeroed load */
180 COSTS_N_INSNS (2), /* float load */
181 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
182 COSTS_N_INSNS (4), /* fadd, fsub */
183 COSTS_N_INSNS (5), /* fcmp */
184 COSTS_N_INSNS (3), /* fmov, fmovr */
185 COSTS_N_INSNS (4), /* fmul */
186 COSTS_N_INSNS (17), /* fdivs */
187 COSTS_N_INSNS (20), /* fdivd */
188 COSTS_N_INSNS (20), /* fsqrts */
189 COSTS_N_INSNS (29), /* fsqrtd */
190 COSTS_N_INSNS (6), /* imul */
191 COSTS_N_INSNS (6), /* imulX */
192 0, /* imul bit factor */
193 COSTS_N_INSNS (40), /* idiv */
194 COSTS_N_INSNS (71), /* idivX */
195 COSTS_N_INSNS (2), /* movcc/movr */
196 0, /* shift penalty */
199 const struct processor_costs *sparc_costs = &cypress_costs;
201 #ifdef HAVE_AS_RELAX_OPTION
202 /* If 'as' and 'ld' are relaxing tail call insns into branch always, use
203 "or %o7,%g0,X; call Y; or X,%g0,%o7" always, so that it can be optimized.
204 With sethi/jmp, neither 'as' nor 'ld' has an easy way how to find out if
205 somebody does not branch between the sethi and jmp. */
206 #define LEAF_SIBCALL_SLOT_RESERVED_P 1
208 #define LEAF_SIBCALL_SLOT_RESERVED_P \
209 ((TARGET_ARCH64 && !TARGET_CM_MEDLOW) || flag_pic)
212 /* Global variables for machine-dependent things. */
214 /* Size of frame. Need to know this to emit return insns from leaf procedures.
215 ACTUAL_FSIZE is set by sparc_compute_frame_size() which is called during the
216 reload pass. This is important as the value is later used for scheduling
217 (to see what can go in a delay slot).
218 APPARENT_FSIZE is the size of the stack less the register save area and less
219 the outgoing argument area. It is used when saving call preserved regs. */
220 static HOST_WIDE_INT apparent_fsize;
221 static HOST_WIDE_INT actual_fsize;
223 /* Number of live general or floating point registers needed to be
224 saved (as 4-byte quantities). */
225 static int num_gfregs;
227 /* The alias set for prologue/epilogue register save/restore. */
228 static GTY(()) int sparc_sr_alias_set;
230 /* The alias set for the structure return value. */
231 static GTY(()) int struct_value_alias_set;
233 /* Save the operands last given to a compare for use when we
234 generate a scc or bcc insn. */
235 rtx sparc_compare_op0, sparc_compare_op1;
237 /* Vector to say how input registers are mapped to output registers.
238 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
239 eliminate it. You must use -fomit-frame-pointer to get that. */
240 char leaf_reg_remap[] =
241 { 0, 1, 2, 3, 4, 5, 6, 7,
242 -1, -1, -1, -1, -1, -1, 14, -1,
243 -1, -1, -1, -1, -1, -1, -1, -1,
244 8, 9, 10, 11, 12, 13, -1, 15,
246 32, 33, 34, 35, 36, 37, 38, 39,
247 40, 41, 42, 43, 44, 45, 46, 47,
248 48, 49, 50, 51, 52, 53, 54, 55,
249 56, 57, 58, 59, 60, 61, 62, 63,
250 64, 65, 66, 67, 68, 69, 70, 71,
251 72, 73, 74, 75, 76, 77, 78, 79,
252 80, 81, 82, 83, 84, 85, 86, 87,
253 88, 89, 90, 91, 92, 93, 94, 95,
254 96, 97, 98, 99, 100};
256 /* Vector, indexed by hard register number, which contains 1
257 for a register that is allowable in a candidate for leaf
258 function treatment. */
259 char sparc_leaf_regs[] =
260 { 1, 1, 1, 1, 1, 1, 1, 1,
261 0, 0, 0, 0, 0, 0, 1, 0,
262 0, 0, 0, 0, 0, 0, 0, 0,
263 1, 1, 1, 1, 1, 1, 0, 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,
267 1, 1, 1, 1, 1, 1, 1, 1,
268 1, 1, 1, 1, 1, 1, 1, 1,
269 1, 1, 1, 1, 1, 1, 1, 1,
270 1, 1, 1, 1, 1, 1, 1, 1,
271 1, 1, 1, 1, 1, 1, 1, 1,
274 struct machine_function GTY(())
276 /* Some local-dynamic TLS symbol name. */
277 const char *some_ld_name;
279 /* True if the current function is leaf and uses only leaf regs,
280 so that the SPARC leaf function optimization can be applied.
281 Private version of current_function_uses_only_leaf_regs, see
282 sparc_expand_prologue for the rationale. */
285 /* True if the data calculated by sparc_expand_prologue are valid. */
286 bool prologue_data_valid_p;
289 #define sparc_leaf_function_p cfun->machine->leaf_function_p
290 #define sparc_prologue_data_valid_p cfun->machine->prologue_data_valid_p
292 /* Register we pretend to think the frame pointer is allocated to.
293 Normally, this is %fp, but if we are in a leaf procedure, this
294 is %sp+"something". We record "something" separately as it may
295 be too big for reg+constant addressing. */
296 static rtx frame_base_reg;
297 static HOST_WIDE_INT frame_base_offset;
299 /* 1 if the next opcode is to be specially indented. */
300 int sparc_indent_opcode = 0;
302 static void sparc_init_modes (void);
303 static void scan_record_type (tree, int *, int *, int *);
304 static int function_arg_slotno (const CUMULATIVE_ARGS *, enum machine_mode,
305 tree, int, int, int *, int *);
307 static int supersparc_adjust_cost (rtx, rtx, rtx, int);
308 static int hypersparc_adjust_cost (rtx, rtx, rtx, int);
310 static void sparc_output_addr_vec (rtx);
311 static void sparc_output_addr_diff_vec (rtx);
312 static void sparc_output_deferred_case_vectors (void);
313 static rtx sparc_builtin_saveregs (void);
314 static int epilogue_renumber (rtx *, int);
315 static bool sparc_assemble_integer (rtx, unsigned int, int);
316 static int set_extends (rtx);
317 static void load_pic_register (void);
318 static int save_or_restore_regs (int, int, rtx, int, int);
319 static void emit_save_regs (void);
320 static void emit_restore_regs (void);
321 static void sparc_asm_function_prologue (FILE *, HOST_WIDE_INT);
322 static void sparc_asm_function_epilogue (FILE *, HOST_WIDE_INT);
323 #ifdef OBJECT_FORMAT_ELF
324 static void sparc_elf_asm_named_section (const char *, unsigned int, tree);
327 static int sparc_adjust_cost (rtx, rtx, rtx, int);
328 static int sparc_issue_rate (void);
329 static void sparc_sched_init (FILE *, int, int);
330 static int sparc_use_sched_lookahead (void);
332 static void emit_soft_tfmode_libcall (const char *, int, rtx *);
333 static void emit_soft_tfmode_binop (enum rtx_code, rtx *);
334 static void emit_soft_tfmode_unop (enum rtx_code, rtx *);
335 static void emit_soft_tfmode_cvt (enum rtx_code, rtx *);
336 static void emit_hard_tfmode_operation (enum rtx_code, rtx *);
338 static bool sparc_function_ok_for_sibcall (tree, tree);
339 static void sparc_init_libfuncs (void);
340 static void sparc_init_builtins (void);
341 static void sparc_vis_init_builtins (void);
342 static rtx sparc_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
343 static void sparc_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
344 HOST_WIDE_INT, tree);
345 static bool sparc_can_output_mi_thunk (tree, HOST_WIDE_INT,
346 HOST_WIDE_INT, tree);
347 static struct machine_function * sparc_init_machine_status (void);
348 static bool sparc_cannot_force_const_mem (rtx);
349 static rtx sparc_tls_get_addr (void);
350 static rtx sparc_tls_got (void);
351 static const char *get_some_local_dynamic_name (void);
352 static int get_some_local_dynamic_name_1 (rtx *, void *);
353 static bool sparc_rtx_costs (rtx, int, int, int *);
354 static bool sparc_promote_prototypes (tree);
355 static rtx sparc_struct_value_rtx (tree, int);
356 static bool sparc_return_in_memory (tree, tree);
357 static bool sparc_strict_argument_naming (CUMULATIVE_ARGS *);
358 static tree sparc_gimplify_va_arg (tree, tree, tree *, tree *);
359 static bool sparc_vector_mode_supported_p (enum machine_mode);
360 static bool sparc_pass_by_reference (CUMULATIVE_ARGS *,
361 enum machine_mode, tree, bool);
362 static int sparc_arg_partial_bytes (CUMULATIVE_ARGS *,
363 enum machine_mode, tree, bool);
364 static void sparc_dwarf_handle_frame_unspec (const char *, rtx, int);
365 #ifdef SUBTARGET_ATTRIBUTE_TABLE
366 const struct attribute_spec sparc_attribute_table[];
369 /* Option handling. */
371 /* Code model option as passed by user. */
372 const char *sparc_cmodel_string;
374 enum cmodel sparc_cmodel;
376 char sparc_hard_reg_printed[8];
378 struct sparc_cpu_select sparc_select[] =
380 /* switch name, tune arch */
381 { (char *)0, "default", 1, 1 },
382 { (char *)0, "-mcpu=", 1, 1 },
383 { (char *)0, "-mtune=", 1, 0 },
387 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
388 enum processor_type sparc_cpu;
390 /* Initialize the GCC target structure. */
392 /* The sparc default is to use .half rather than .short for aligned
393 HI objects. Use .word instead of .long on non-ELF systems. */
394 #undef TARGET_ASM_ALIGNED_HI_OP
395 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
396 #ifndef OBJECT_FORMAT_ELF
397 #undef TARGET_ASM_ALIGNED_SI_OP
398 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
401 #undef TARGET_ASM_UNALIGNED_HI_OP
402 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
403 #undef TARGET_ASM_UNALIGNED_SI_OP
404 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
405 #undef TARGET_ASM_UNALIGNED_DI_OP
406 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
408 /* The target hook has to handle DI-mode values. */
409 #undef TARGET_ASM_INTEGER
410 #define TARGET_ASM_INTEGER sparc_assemble_integer
412 #undef TARGET_ASM_FUNCTION_PROLOGUE
413 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
414 #undef TARGET_ASM_FUNCTION_EPILOGUE
415 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
417 #undef TARGET_SCHED_ADJUST_COST
418 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
419 #undef TARGET_SCHED_ISSUE_RATE
420 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
421 #undef TARGET_SCHED_INIT
422 #define TARGET_SCHED_INIT sparc_sched_init
423 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
424 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
426 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
427 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
429 #undef TARGET_INIT_LIBFUNCS
430 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
431 #undef TARGET_INIT_BUILTINS
432 #define TARGET_INIT_BUILTINS sparc_init_builtins
434 #undef TARGET_EXPAND_BUILTIN
435 #define TARGET_EXPAND_BUILTIN sparc_expand_builtin
438 #undef TARGET_HAVE_TLS
439 #define TARGET_HAVE_TLS true
441 #undef TARGET_CANNOT_FORCE_CONST_MEM
442 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
444 #undef TARGET_ASM_OUTPUT_MI_THUNK
445 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
446 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
447 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
449 #undef TARGET_RTX_COSTS
450 #define TARGET_RTX_COSTS sparc_rtx_costs
451 #undef TARGET_ADDRESS_COST
452 #define TARGET_ADDRESS_COST hook_int_rtx_0
454 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
455 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
456 test for this value. */
457 #undef TARGET_PROMOTE_FUNCTION_ARGS
458 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
460 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
461 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
462 test for this value. */
463 #undef TARGET_PROMOTE_FUNCTION_RETURN
464 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
466 #undef TARGET_PROMOTE_PROTOTYPES
467 #define TARGET_PROMOTE_PROTOTYPES sparc_promote_prototypes
469 #undef TARGET_STRUCT_VALUE_RTX
470 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
471 #undef TARGET_RETURN_IN_MEMORY
472 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
473 #undef TARGET_MUST_PASS_IN_STACK
474 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
475 #undef TARGET_PASS_BY_REFERENCE
476 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
477 #undef TARGET_ARG_PARTIAL_BYTES
478 #define TARGET_ARG_PARTIAL_BYTES sparc_arg_partial_bytes
480 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
481 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
482 #undef TARGET_STRICT_ARGUMENT_NAMING
483 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
485 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
486 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
488 #undef TARGET_VECTOR_MODE_SUPPORTED_P
489 #define TARGET_VECTOR_MODE_SUPPORTED_P sparc_vector_mode_supported_p
491 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
492 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC sparc_dwarf_handle_frame_unspec
494 #ifdef SUBTARGET_INSERT_ATTRIBUTES
495 #undef TARGET_INSERT_ATTRIBUTES
496 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
499 #ifdef SUBTARGET_ATTRIBUTE_TABLE
500 #undef TARGET_ATTRIBUTE_TABLE
501 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
504 #undef TARGET_RELAXED_ORDERING
505 #define TARGET_RELAXED_ORDERING SPARC_RELAXED_ORDERING
507 struct gcc_target targetm = TARGET_INITIALIZER;
509 /* Validate and override various options, and do some machine dependent
513 sparc_override_options (void)
515 static struct code_model {
516 const char *const name;
518 } const cmodels[] = {
520 { "medlow", CM_MEDLOW },
521 { "medmid", CM_MEDMID },
522 { "medany", CM_MEDANY },
523 { "embmedany", CM_EMBMEDANY },
526 const struct code_model *cmodel;
527 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
528 static struct cpu_default {
530 const char *const name;
531 } const cpu_default[] = {
532 /* There must be one entry here for each TARGET_CPU value. */
533 { TARGET_CPU_sparc, "cypress" },
534 { TARGET_CPU_sparclet, "tsc701" },
535 { TARGET_CPU_sparclite, "f930" },
536 { TARGET_CPU_v8, "v8" },
537 { TARGET_CPU_hypersparc, "hypersparc" },
538 { TARGET_CPU_sparclite86x, "sparclite86x" },
539 { TARGET_CPU_supersparc, "supersparc" },
540 { TARGET_CPU_v9, "v9" },
541 { TARGET_CPU_ultrasparc, "ultrasparc" },
542 { TARGET_CPU_ultrasparc3, "ultrasparc3" },
545 const struct cpu_default *def;
546 /* Table of values for -m{cpu,tune}=. */
547 static struct cpu_table {
548 const char *const name;
549 const enum processor_type processor;
552 } const cpu_table[] = {
553 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
554 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
555 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
556 /* TI TMS390Z55 supersparc */
557 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
558 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
559 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
560 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
561 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
562 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
563 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
564 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
566 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
568 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
569 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
570 /* TI ultrasparc I, II, IIi */
571 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
572 /* Although insns using %y are deprecated, it is a clear win on current
574 |MASK_DEPRECATED_V8_INSNS},
575 /* TI ultrasparc III */
576 /* ??? Check if %y issue still holds true in ultra3. */
577 { "ultrasparc3", PROCESSOR_ULTRASPARC3, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
580 const struct cpu_table *cpu;
581 const struct sparc_cpu_select *sel;
584 #ifndef SPARC_BI_ARCH
585 /* Check for unsupported architecture size. */
586 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
587 error ("%s is not supported by this configuration",
588 DEFAULT_ARCH32_P ? "-m64" : "-m32");
591 /* We force all 64bit archs to use 128 bit long double */
592 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
594 error ("-mlong-double-64 not allowed with -m64");
595 target_flags |= MASK_LONG_DOUBLE_128;
598 /* Code model selection. */
599 sparc_cmodel = SPARC_DEFAULT_CMODEL;
603 sparc_cmodel = CM_32;
606 if (sparc_cmodel_string != NULL)
610 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
611 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
613 if (cmodel->name == NULL)
614 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
616 sparc_cmodel = cmodel->value;
619 error ("-mcmodel= is not supported on 32 bit systems");
622 fpu = TARGET_FPU; /* save current -mfpu status */
624 /* Set the default CPU. */
625 for (def = &cpu_default[0]; def->name; ++def)
626 if (def->cpu == TARGET_CPU_DEFAULT)
630 sparc_select[0].string = def->name;
632 for (sel = &sparc_select[0]; sel->name; ++sel)
636 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
637 if (! strcmp (sel->string, cpu->name))
640 sparc_cpu = cpu->processor;
644 target_flags &= ~cpu->disable;
645 target_flags |= cpu->enable;
651 error ("bad value (%s) for %s switch", sel->string, sel->name);
655 /* If -mfpu or -mno-fpu was explicitly used, don't override with
656 the processor default. Clear MASK_FPU_SET to avoid confusing
657 the reverse mapping from switch values to names. */
660 target_flags = (target_flags & ~MASK_FPU) | fpu;
661 target_flags &= ~MASK_FPU_SET;
664 /* Don't allow -mvis if FPU is disabled. */
666 target_flags &= ~MASK_VIS;
668 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
670 -m64 also implies v9. */
671 if (TARGET_VIS || TARGET_ARCH64)
673 target_flags |= MASK_V9;
674 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
677 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
678 if (TARGET_V9 && TARGET_ARCH32)
679 target_flags |= MASK_DEPRECATED_V8_INSNS;
681 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
682 if (! TARGET_V9 || TARGET_ARCH64)
683 target_flags &= ~MASK_V8PLUS;
685 /* Don't use stack biasing in 32 bit mode. */
687 target_flags &= ~MASK_STACK_BIAS;
689 /* Supply a default value for align_functions. */
690 if (align_functions == 0
691 && (sparc_cpu == PROCESSOR_ULTRASPARC
692 || sparc_cpu == PROCESSOR_ULTRASPARC3))
693 align_functions = 32;
695 /* Validate PCC_STRUCT_RETURN. */
696 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
697 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
699 /* Only use .uaxword when compiling for a 64-bit target. */
701 targetm.asm_out.unaligned_op.di = NULL;
703 /* Do various machine dependent initializations. */
706 /* Acquire unique alias sets for our private stuff. */
707 sparc_sr_alias_set = new_alias_set ();
708 struct_value_alias_set = new_alias_set ();
710 /* Set up function hooks. */
711 init_machine_status = sparc_init_machine_status;
716 case PROCESSOR_CYPRESS:
717 sparc_costs = &cypress_costs;
720 case PROCESSOR_SPARCLITE:
721 case PROCESSOR_SUPERSPARC:
722 sparc_costs = &supersparc_costs;
726 case PROCESSOR_HYPERSPARC:
727 case PROCESSOR_SPARCLITE86X:
728 sparc_costs = &hypersparc_costs;
730 case PROCESSOR_SPARCLET:
731 case PROCESSOR_TSC701:
732 sparc_costs = &sparclet_costs;
735 case PROCESSOR_ULTRASPARC:
736 sparc_costs = &ultrasparc_costs;
738 case PROCESSOR_ULTRASPARC3:
739 sparc_costs = &ultrasparc3_costs;
744 #ifdef SUBTARGET_ATTRIBUTE_TABLE
745 /* Table of valid machine attributes. */
746 const struct attribute_spec sparc_attribute_table[] =
748 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
749 SUBTARGET_ATTRIBUTE_TABLE,
750 { NULL, 0, 0, false, false, false, NULL }
754 /* Miscellaneous utilities. */
756 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
757 or branch on register contents instructions. */
760 v9_regcmp_p (enum rtx_code code)
762 return (code == EQ || code == NE || code == GE || code == LT
763 || code == LE || code == GT);
767 /* Operand constraints. */
769 /* Return nonzero only if OP is a register of mode MODE,
773 reg_or_0_operand (rtx op, enum machine_mode mode)
775 if (register_operand (op, mode))
777 if (op == const0_rtx)
779 if (GET_MODE (op) == VOIDmode && GET_CODE (op) == CONST_DOUBLE
780 && CONST_DOUBLE_HIGH (op) == 0
781 && CONST_DOUBLE_LOW (op) == 0)
783 if (fp_zero_operand (op, mode))
788 /* Return nonzero only if OP is const1_rtx. */
791 const1_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
793 return op == const1_rtx;
796 /* Nonzero if OP is a floating point value with value 0.0. */
799 fp_zero_operand (rtx op, enum machine_mode mode)
801 enum mode_class mclass = GET_MODE_CLASS (GET_MODE (op));
802 if (mclass != MODE_FLOAT && mclass != MODE_VECTOR_INT)
804 return op == CONST0_RTX (mode);
807 /* Nonzero if OP is a register operand in floating point register. */
810 fp_register_operand (rtx op, enum machine_mode mode)
812 if (! register_operand (op, mode))
814 if (GET_CODE (op) == SUBREG)
815 op = SUBREG_REG (op);
816 return GET_CODE (op) == REG && SPARC_FP_REG_P (REGNO (op));
819 /* Nonzero if OP is a floating point constant which can
820 be loaded into an integer register using a single
821 sethi instruction. */
826 if (GET_CODE (op) == CONST_DOUBLE)
831 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
832 if (REAL_VALUES_EQUAL (r, dconst0) &&
833 ! REAL_VALUE_MINUS_ZERO (r))
835 REAL_VALUE_TO_TARGET_SINGLE (r, i);
836 if (SPARC_SETHI_P (i))
843 /* Nonzero if OP is a floating point constant which can
844 be loaded into an integer register using a single
850 if (GET_CODE (op) == CONST_DOUBLE)
855 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
856 if (REAL_VALUES_EQUAL (r, dconst0) &&
857 ! REAL_VALUE_MINUS_ZERO (r))
859 REAL_VALUE_TO_TARGET_SINGLE (r, i);
860 if (SPARC_SIMM13_P (i))
867 /* Nonzero if OP is a floating point constant which can
868 be loaded into an integer register using a high/losum
869 instruction sequence. */
872 fp_high_losum_p (rtx op)
874 /* The constraints calling this should only be in
875 SFmode move insns, so any constant which cannot
876 be moved using a single insn will do. */
877 if (GET_CODE (op) == CONST_DOUBLE)
882 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
883 if (REAL_VALUES_EQUAL (r, dconst0) &&
884 ! REAL_VALUE_MINUS_ZERO (r))
886 REAL_VALUE_TO_TARGET_SINGLE (r, i);
887 if (! SPARC_SETHI_P (i)
888 && ! SPARC_SIMM13_P (i))
895 /* Nonzero if OP is an integer register. */
898 intreg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
900 return (register_operand (op, SImode)
901 || (TARGET_ARCH64 && register_operand (op, DImode)));
904 /* Nonzero if OP is a floating point condition code register. */
907 fcc_reg_operand (rtx op, enum machine_mode mode)
909 /* This can happen when recog is called from combine. Op may be a MEM.
910 Fail instead of calling abort in this case. */
911 if (GET_CODE (op) != REG)
914 if (mode != VOIDmode && mode != GET_MODE (op))
917 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
920 #if 0 /* ??? ==> 1 when %fcc0-3 are pseudos first. See gen_compare_reg(). */
921 if (reg_renumber == 0)
922 return REGNO (op) >= FIRST_PSEUDO_REGISTER;
923 return REGNO_OK_FOR_CCFP_P (REGNO (op));
925 return (unsigned) REGNO (op) - SPARC_FIRST_V9_FCC_REG < 4;
929 /* Nonzero if OP is a floating point condition code fcc0 register. */
932 fcc0_reg_operand (rtx op, enum machine_mode mode)
934 /* This can happen when recog is called from combine. Op may be a MEM.
935 Fail instead of calling abort in this case. */
936 if (GET_CODE (op) != REG)
939 if (mode != VOIDmode && mode != GET_MODE (op))
942 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
945 return REGNO (op) == SPARC_FCC_REG;
948 /* Nonzero if OP is an integer or floating point condition code register. */
951 icc_or_fcc_reg_operand (rtx op, enum machine_mode mode)
953 if (GET_CODE (op) == REG && REGNO (op) == SPARC_ICC_REG)
955 if (mode != VOIDmode && mode != GET_MODE (op))
958 && GET_MODE (op) != CCmode && GET_MODE (op) != CCXmode)
963 return fcc_reg_operand (op, mode);
966 /* Call insn on SPARC can take a PC-relative constant address, or any regular
970 call_operand (rtx op, enum machine_mode mode)
972 if (GET_CODE (op) != MEM)
975 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
979 call_operand_address (rtx op, enum machine_mode mode)
981 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
984 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
985 otherwise return 0. */
988 tls_symbolic_operand (rtx op)
990 if (GET_CODE (op) != SYMBOL_REF)
992 return SYMBOL_REF_TLS_MODEL (op);
996 tgd_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
998 return tls_symbolic_operand (op) == TLS_MODEL_GLOBAL_DYNAMIC;
1002 tld_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1004 return tls_symbolic_operand (op) == TLS_MODEL_LOCAL_DYNAMIC;
1008 tie_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1010 return tls_symbolic_operand (op) == TLS_MODEL_INITIAL_EXEC;
1014 tle_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1016 return tls_symbolic_operand (op) == TLS_MODEL_LOCAL_EXEC;
1019 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
1020 reference and a constant. */
1023 symbolic_operand (register rtx op, enum machine_mode mode)
1025 enum machine_mode omode = GET_MODE (op);
1027 if (omode != mode && omode != VOIDmode && mode != VOIDmode)
1030 switch (GET_CODE (op))
1033 return !SYMBOL_REF_TLS_MODEL (op);
1040 return (((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
1041 && !SYMBOL_REF_TLS_MODEL (XEXP (op, 0)))
1042 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
1043 && GET_CODE (XEXP (op, 1)) == CONST_INT);
1050 /* Return truth value of statement that OP is a symbolic memory
1051 operand of mode MODE. */
1054 symbolic_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1056 if (GET_CODE (op) == SUBREG)
1057 op = SUBREG_REG (op);
1058 if (GET_CODE (op) != MEM)
1061 return ((GET_CODE (op) == SYMBOL_REF && !SYMBOL_REF_TLS_MODEL (op))
1062 || GET_CODE (op) == CONST || GET_CODE (op) == HIGH
1063 || GET_CODE (op) == LABEL_REF);
1066 /* Return truth value of statement that OP is a LABEL_REF of mode MODE. */
1069 label_ref_operand (rtx op, enum machine_mode mode)
1071 if (GET_CODE (op) != LABEL_REF)
1073 if (GET_MODE (op) != mode)
1078 /* Return 1 if the operand is an argument used in generating pic references
1079 in either the medium/low or medium/anywhere code models of sparc64. */
1082 sp64_medium_pic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1084 /* Check for (const (minus (symbol_ref:GOT)
1085 (const (minus (label) (pc))))). */
1086 if (GET_CODE (op) != CONST)
1089 if (GET_CODE (op) != MINUS)
1091 if (GET_CODE (XEXP (op, 0)) != SYMBOL_REF)
1093 /* ??? Ensure symbol is GOT. */
1094 if (GET_CODE (XEXP (op, 1)) != CONST)
1096 if (GET_CODE (XEXP (XEXP (op, 1), 0)) != MINUS)
1101 /* Return 1 if the operand is a data segment reference. This includes
1102 the readonly data segment, or in other words anything but the text segment.
1103 This is needed in the medium/anywhere code model on v9. These values
1104 are accessed with EMBMEDANY_BASE_REG. */
1107 data_segment_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1109 switch (GET_CODE (op))
1112 return ! SYMBOL_REF_FUNCTION_P (op);
1114 /* Assume canonical format of symbol + constant.
1117 return data_segment_operand (XEXP (op, 0), VOIDmode);
1123 /* Return 1 if the operand is a text segment reference.
1124 This is needed in the medium/anywhere code model on v9. */
1127 text_segment_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1129 switch (GET_CODE (op))
1134 return SYMBOL_REF_FUNCTION_P (op);
1136 /* Assume canonical format of symbol + constant.
1139 return text_segment_operand (XEXP (op, 0), VOIDmode);
1145 /* Return 1 if the operand is either a register or a memory operand that is
1149 reg_or_nonsymb_mem_operand (register rtx op, enum machine_mode mode)
1151 if (register_operand (op, mode))
1154 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
1161 splittable_symbolic_memory_operand (rtx op,
1162 enum machine_mode mode ATTRIBUTE_UNUSED)
1164 if (GET_CODE (op) != MEM)
1166 if (! symbolic_operand (XEXP (op, 0), Pmode))
1172 splittable_immediate_memory_operand (rtx op,
1173 enum machine_mode mode ATTRIBUTE_UNUSED)
1175 if (GET_CODE (op) != MEM)
1177 if (! immediate_operand (XEXP (op, 0), Pmode))
1182 /* Return truth value of whether OP is EQ or NE. */
1185 eq_or_neq (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1187 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
1190 /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
1191 or LTU for non-floating-point. We handle those specially. */
1194 normal_comp_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1198 if (!COMPARISON_P (op))
1201 if (GET_MODE (XEXP (op, 0)) == CCFPmode
1202 || GET_MODE (XEXP (op, 0)) == CCFPEmode)
1205 code = GET_CODE (op);
1206 return (code != NE && code != EQ && code != GEU && code != LTU);
1209 /* Return 1 if this is a comparison operator. This allows the use of
1210 MATCH_OPERATOR to recognize all the branch insns. */
1213 noov_compare_op (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1217 if (!COMPARISON_P (op))
1220 code = GET_CODE (op);
1221 if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode
1222 || GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
1223 /* These are the only branches which work with CC_NOOVmode. */
1224 return (code == EQ || code == NE || code == GE || code == LT);
1228 /* Return 1 if this is a 64-bit comparison operator. This allows the use of
1229 MATCH_OPERATOR to recognize all the branch insns. */
1232 noov_compare64_op (register rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1239 if (!COMPARISON_P (op))
1242 code = GET_CODE (op);
1243 if (GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
1244 /* These are the only branches which work with CCX_NOOVmode. */
1245 return (code == EQ || code == NE || code == GE || code == LT);
1246 return (GET_MODE (XEXP (op, 0)) == CCXmode);
1249 /* Nonzero if OP is a comparison operator suitable for use in v9
1250 conditional move or branch on register contents instructions. */
1253 v9_regcmp_op (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1257 if (!COMPARISON_P (op))
1260 code = GET_CODE (op);
1261 return v9_regcmp_p (code);
1264 /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */
1267 extend_op (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1269 return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
1272 /* Return nonzero if OP is an operator of mode MODE which can set
1273 the condition codes explicitly. We do not include PLUS and MINUS
1274 because these require CC_NOOVmode, which we handle explicitly. */
1277 cc_arithop (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1279 if (GET_CODE (op) == AND
1280 || GET_CODE (op) == IOR
1281 || GET_CODE (op) == XOR)
1287 /* Return nonzero if OP is an operator of mode MODE which can bitwise
1288 complement its second operand and set the condition codes explicitly. */
1291 cc_arithopn (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1293 /* XOR is not here because combine canonicalizes (xor (not ...) ...)
1294 and (xor ... (not ...)) to (not (xor ...)). */
1295 return (GET_CODE (op) == AND
1296 || GET_CODE (op) == IOR);
1299 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1300 signed 13 bit immediate field. This is an acceptable SImode operand for
1301 most 3 address instructions. */
1304 arith_operand (rtx op, enum machine_mode mode)
1306 if (register_operand (op, mode))
1308 if (GET_CODE (op) != CONST_INT)
1310 return SMALL_INT32 (op);
1313 /* Return true if OP is a constant 4096 */
1316 arith_4096_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1318 if (GET_CODE (op) != CONST_INT)
1321 return INTVAL (op) == 4096;
1324 /* Return true if OP is suitable as second operand for add/sub */
1327 arith_add_operand (rtx op, enum machine_mode mode)
1329 return arith_operand (op, mode) || arith_4096_operand (op, mode);
1332 /* Return true if OP is a CONST_INT or a CONST_DOUBLE which can fit in the
1333 immediate field of OR and XOR instructions. Used for 64-bit
1334 constant formation patterns. */
1336 const64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1338 return ((GET_CODE (op) == CONST_INT
1339 && SPARC_SIMM13_P (INTVAL (op)))
1340 #if HOST_BITS_PER_WIDE_INT != 64
1341 || (GET_CODE (op) == CONST_DOUBLE
1342 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1343 && (CONST_DOUBLE_HIGH (op) ==
1344 ((CONST_DOUBLE_LOW (op) & 0x80000000) != 0 ?
1345 (HOST_WIDE_INT)-1 : 0)))
1350 /* The same, but only for sethi instructions. */
1352 const64_high_operand (rtx op, enum machine_mode mode)
1354 return ((GET_CODE (op) == CONST_INT
1355 && (INTVAL (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1356 && SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1358 || (GET_CODE (op) == CONST_DOUBLE
1359 && CONST_DOUBLE_HIGH (op) == 0
1360 && (CONST_DOUBLE_LOW (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1361 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op))));
1364 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1365 signed 11 bit immediate field. This is an acceptable SImode operand for
1366 the movcc instructions. */
1369 arith11_operand (rtx op, enum machine_mode mode)
1371 return (register_operand (op, mode)
1372 || (GET_CODE (op) == CONST_INT && SPARC_SIMM11_P (INTVAL (op))));
1375 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1376 signed 10 bit immediate field. This is an acceptable SImode operand for
1377 the movrcc instructions. */
1380 arith10_operand (rtx op, enum machine_mode mode)
1382 return (register_operand (op, mode)
1383 || (GET_CODE (op) == CONST_INT && SPARC_SIMM10_P (INTVAL (op))));
1386 /* Return true if OP is a register, is a CONST_INT that fits in a 13 bit
1387 immediate field, or is a CONST_DOUBLE whose both parts fit in a 13 bit
1389 ARCH64: Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1390 can fit in a 13 bit immediate field. This is an acceptable DImode operand
1391 for most 3 address instructions. */
1394 arith_double_operand (rtx op, enum machine_mode mode)
1396 return (register_operand (op, mode)
1397 || (GET_CODE (op) == CONST_INT && SMALL_INT (op))
1399 && GET_CODE (op) == CONST_DOUBLE
1400 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1401 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_HIGH (op) + 0x1000) < 0x2000)
1403 && GET_CODE (op) == CONST_DOUBLE
1404 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1405 && ((CONST_DOUBLE_HIGH (op) == -1
1406 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
1407 || (CONST_DOUBLE_HIGH (op) == 0
1408 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
1411 /* Return true if OP is a constant 4096 for DImode on ARCH64 */
1414 arith_double_4096_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1416 return (TARGET_ARCH64 &&
1417 ((GET_CODE (op) == CONST_INT && INTVAL (op) == 4096) ||
1418 (GET_CODE (op) == CONST_DOUBLE &&
1419 CONST_DOUBLE_LOW (op) == 4096 &&
1420 CONST_DOUBLE_HIGH (op) == 0)));
1423 /* Return true if OP is suitable as second operand for add/sub in DImode */
1426 arith_double_add_operand (rtx op, enum machine_mode mode)
1428 return arith_double_operand (op, mode) || arith_double_4096_operand (op, mode);
1431 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1432 can fit in an 11 bit immediate field. This is an acceptable DImode
1433 operand for the movcc instructions. */
1434 /* ??? Replace with arith11_operand? */
1437 arith11_double_operand (rtx op, enum machine_mode mode)
1439 return (register_operand (op, mode)
1440 || (GET_CODE (op) == CONST_DOUBLE
1441 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1442 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x400) < 0x800
1443 && ((CONST_DOUBLE_HIGH (op) == -1
1444 && (CONST_DOUBLE_LOW (op) & 0x400) == 0x400)
1445 || (CONST_DOUBLE_HIGH (op) == 0
1446 && (CONST_DOUBLE_LOW (op) & 0x400) == 0)))
1447 || (GET_CODE (op) == CONST_INT
1448 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1449 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x400) < 0x800));
1452 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1453 can fit in an 10 bit immediate field. This is an acceptable DImode
1454 operand for the movrcc instructions. */
1455 /* ??? Replace with arith10_operand? */
1458 arith10_double_operand (rtx op, enum machine_mode mode)
1460 return (register_operand (op, mode)
1461 || (GET_CODE (op) == CONST_DOUBLE
1462 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1463 && (unsigned) (CONST_DOUBLE_LOW (op) + 0x200) < 0x400
1464 && ((CONST_DOUBLE_HIGH (op) == -1
1465 && (CONST_DOUBLE_LOW (op) & 0x200) == 0x200)
1466 || (CONST_DOUBLE_HIGH (op) == 0
1467 && (CONST_DOUBLE_LOW (op) & 0x200) == 0)))
1468 || (GET_CODE (op) == CONST_INT
1469 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1470 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x200) < 0x400));
1473 /* Return truth value of whether OP is an integer which fits the
1474 range constraining immediate operands in most three-address insns,
1475 which have a 13 bit immediate field. */
1478 small_int (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1480 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
1484 small_int_or_double (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1486 return ((GET_CODE (op) == CONST_INT && SMALL_INT (op))
1487 || (GET_CODE (op) == CONST_DOUBLE
1488 && CONST_DOUBLE_HIGH (op) == 0
1489 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))));
1492 /* Recognize operand values for the umul instruction. That instruction sign
1493 extends immediate values just like all other sparc instructions, but
1494 interprets the extended result as an unsigned number. */
1497 uns_small_int (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1499 #if HOST_BITS_PER_WIDE_INT > 32
1500 /* All allowed constants will fit a CONST_INT. */
1501 return (GET_CODE (op) == CONST_INT
1502 && ((INTVAL (op) >= 0 && INTVAL (op) < 0x1000)
1503 || (INTVAL (op) >= 0xFFFFF000
1504 && INTVAL (op) <= 0xFFFFFFFF)));
1506 return ((GET_CODE (op) == CONST_INT && (unsigned) INTVAL (op) < 0x1000)
1507 || (GET_CODE (op) == CONST_DOUBLE
1508 && CONST_DOUBLE_HIGH (op) == 0
1509 && (unsigned) CONST_DOUBLE_LOW (op) - 0xFFFFF000 < 0x1000));
1514 uns_arith_operand (rtx op, enum machine_mode mode)
1516 return register_operand (op, mode) || uns_small_int (op, mode);
1519 /* Return truth value of statement that OP is a call-clobbered register. */
1521 clobbered_register (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1523 return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
1526 /* Return 1 if OP is a valid operand for the source of a move insn. */
1529 input_operand (rtx op, enum machine_mode mode)
1531 enum mode_class mclass;
1533 /* If both modes are non-void they must be the same. */
1534 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1537 /* Allow any one instruction integer constant, and all CONST_INT
1538 variants when we are working in DImode and !arch64. */
1539 if (GET_MODE_CLASS (mode) == MODE_INT
1540 && ((GET_CODE (op) == CONST_INT
1541 && (SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1542 || SPARC_SIMM13_P (INTVAL (op))
1544 && ! TARGET_ARCH64)))
1546 && GET_CODE (op) == CONST_DOUBLE
1547 && ((CONST_DOUBLE_HIGH (op) == 0
1548 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op)))
1550 #if HOST_BITS_PER_WIDE_INT == 64
1551 (CONST_DOUBLE_HIGH (op) == 0
1552 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op)))
1554 (SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1555 && (((CONST_DOUBLE_LOW (op) & 0x80000000) == 0
1556 && CONST_DOUBLE_HIGH (op) == 0)
1557 || (CONST_DOUBLE_HIGH (op) == -1
1558 && CONST_DOUBLE_LOW (op) & 0x80000000) != 0))
1563 /* If !arch64 and this is a DImode const, allow it so that
1564 the splits can be generated. */
1567 && GET_CODE (op) == CONST_DOUBLE)
1570 if (register_operand (op, mode))
1573 mclass = GET_MODE_CLASS (mode);
1574 if ((mclass == MODE_FLOAT && GET_CODE (op) == CONST_DOUBLE)
1575 || (mclass == MODE_VECTOR_INT && GET_CODE (op) == CONST_VECTOR))
1578 /* If this is a SUBREG, look inside so that we handle
1579 paradoxical ones. */
1580 if (GET_CODE (op) == SUBREG)
1581 op = SUBREG_REG (op);
1583 /* Check for valid MEM forms. */
1584 if (GET_CODE (op) == MEM)
1585 return memory_address_p (mode, XEXP (op, 0));
1590 /* Return 1 if OP is valid for the lhs of a compare insn. */
1593 compare_operand (rtx op, enum machine_mode mode)
1595 if (GET_CODE (op) == ZERO_EXTRACT)
1596 return (register_operand (XEXP (op, 0), mode)
1597 && small_int_or_double (XEXP (op, 1), mode)
1598 && small_int_or_double (XEXP (op, 2), mode)
1599 /* This matches cmp_zero_extract. */
1601 && ((GET_CODE (XEXP (op, 2)) == CONST_INT
1602 && INTVAL (XEXP (op, 2)) > 19)
1603 || (GET_CODE (XEXP (op, 2)) == CONST_DOUBLE
1604 && CONST_DOUBLE_LOW (XEXP (op, 2)) > 19)))
1605 /* This matches cmp_zero_extract_sp64. */
1608 && ((GET_CODE (XEXP (op, 2)) == CONST_INT
1609 && INTVAL (XEXP (op, 2)) > 51)
1610 || (GET_CODE (XEXP (op, 2)) == CONST_DOUBLE
1611 && CONST_DOUBLE_LOW (XEXP (op, 2)) > 51)))));
1613 return register_operand (op, mode);
1617 /* We know it can't be done in one insn when we get here,
1618 the movsi expander guarantees this. */
1620 sparc_emit_set_const32 (rtx op0, rtx op1)
1622 enum machine_mode mode = GET_MODE (op0);
1625 if (GET_CODE (op1) == CONST_INT)
1627 HOST_WIDE_INT value = INTVAL (op1);
1629 if (SPARC_SETHI_P (value & GET_MODE_MASK (mode))
1630 || SPARC_SIMM13_P (value))
1634 /* Full 2-insn decomposition is needed. */
1635 if (reload_in_progress || reload_completed)
1638 temp = gen_reg_rtx (mode);
1640 if (GET_CODE (op1) == CONST_INT)
1642 /* Emit them as real moves instead of a HIGH/LO_SUM,
1643 this way CSE can see everything and reuse intermediate
1644 values if it wants. */
1646 && HOST_BITS_PER_WIDE_INT != 64
1647 && (INTVAL (op1) & 0x80000000) != 0)
1648 emit_insn (gen_rtx_SET
1650 immed_double_const (INTVAL (op1) & ~(HOST_WIDE_INT)0x3ff,
1653 emit_insn (gen_rtx_SET (VOIDmode, temp,
1654 GEN_INT (INTVAL (op1)
1655 & ~(HOST_WIDE_INT)0x3ff)));
1657 emit_insn (gen_rtx_SET (VOIDmode,
1659 gen_rtx_IOR (mode, temp,
1660 GEN_INT (INTVAL (op1) & 0x3ff))));
1664 /* A symbol, emit in the traditional way. */
1665 emit_insn (gen_rtx_SET (VOIDmode, temp,
1666 gen_rtx_HIGH (mode, op1)));
1667 emit_insn (gen_rtx_SET (VOIDmode,
1668 op0, gen_rtx_LO_SUM (mode, temp, op1)));
1674 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
1675 If TEMP is nonzero, we are forbidden to use any other scratch
1676 registers. Otherwise, we are allowed to generate them as needed.
1678 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
1679 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
1681 sparc_emit_set_symbolic_const64 (rtx op0, rtx op1, rtx temp)
1683 rtx temp1, temp2, temp3, temp4, temp5;
1686 if (temp && GET_MODE (temp) == TImode)
1689 temp = gen_rtx_REG (DImode, REGNO (temp));
1692 /* SPARC-V9 code-model support. */
1693 switch (sparc_cmodel)
1696 /* The range spanned by all instructions in the object is less
1697 than 2^31 bytes (2GB) and the distance from any instruction
1698 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1699 than 2^31 bytes (2GB).
1701 The executable must be in the low 4TB of the virtual address
1704 sethi %hi(symbol), %temp1
1705 or %temp1, %lo(symbol), %reg */
1707 temp1 = temp; /* op0 is allowed. */
1709 temp1 = gen_reg_rtx (DImode);
1711 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1712 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1716 /* The range spanned by all instructions in the object is less
1717 than 2^31 bytes (2GB) and the distance from any instruction
1718 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1719 than 2^31 bytes (2GB).
1721 The executable must be in the low 16TB of the virtual address
1724 sethi %h44(symbol), %temp1
1725 or %temp1, %m44(symbol), %temp2
1726 sllx %temp2, 12, %temp3
1727 or %temp3, %l44(symbol), %reg */
1732 temp3 = temp; /* op0 is allowed. */
1736 temp1 = gen_reg_rtx (DImode);
1737 temp2 = gen_reg_rtx (DImode);
1738 temp3 = gen_reg_rtx (DImode);
1741 emit_insn (gen_seth44 (temp1, op1));
1742 emit_insn (gen_setm44 (temp2, temp1, op1));
1743 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1744 gen_rtx_ASHIFT (DImode, temp2, GEN_INT (12))));
1745 emit_insn (gen_setl44 (op0, temp3, op1));
1749 /* The range spanned by all instructions in the object is less
1750 than 2^31 bytes (2GB) and the distance from any instruction
1751 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1752 than 2^31 bytes (2GB).
1754 The executable can be placed anywhere in the virtual address
1757 sethi %hh(symbol), %temp1
1758 sethi %lm(symbol), %temp2
1759 or %temp1, %hm(symbol), %temp3
1760 sllx %temp3, 32, %temp4
1761 or %temp4, %temp2, %temp5
1762 or %temp5, %lo(symbol), %reg */
1765 /* It is possible that one of the registers we got for operands[2]
1766 might coincide with that of operands[0] (which is why we made
1767 it TImode). Pick the other one to use as our scratch. */
1768 if (rtx_equal_p (temp, op0))
1771 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1776 temp2 = temp; /* op0 is _not_ allowed, see above. */
1783 temp1 = gen_reg_rtx (DImode);
1784 temp2 = gen_reg_rtx (DImode);
1785 temp3 = gen_reg_rtx (DImode);
1786 temp4 = gen_reg_rtx (DImode);
1787 temp5 = gen_reg_rtx (DImode);
1790 emit_insn (gen_sethh (temp1, op1));
1791 emit_insn (gen_setlm (temp2, op1));
1792 emit_insn (gen_sethm (temp3, temp1, op1));
1793 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1794 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1795 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1796 gen_rtx_PLUS (DImode, temp4, temp2)));
1797 emit_insn (gen_setlo (op0, temp5, op1));
1801 /* Old old old backwards compatibility kruft here.
1802 Essentially it is MEDLOW with a fixed 64-bit
1803 virtual base added to all data segment addresses.
1804 Text-segment stuff is computed like MEDANY, we can't
1805 reuse the code above because the relocation knobs
1808 Data segment: sethi %hi(symbol), %temp1
1809 add %temp1, EMBMEDANY_BASE_REG, %temp2
1810 or %temp2, %lo(symbol), %reg */
1811 if (data_segment_operand (op1, GET_MODE (op1)))
1815 temp1 = temp; /* op0 is allowed. */
1820 temp1 = gen_reg_rtx (DImode);
1821 temp2 = gen_reg_rtx (DImode);
1824 emit_insn (gen_embmedany_sethi (temp1, op1));
1825 emit_insn (gen_embmedany_brsum (temp2, temp1));
1826 emit_insn (gen_embmedany_losum (op0, temp2, op1));
1829 /* Text segment: sethi %uhi(symbol), %temp1
1830 sethi %hi(symbol), %temp2
1831 or %temp1, %ulo(symbol), %temp3
1832 sllx %temp3, 32, %temp4
1833 or %temp4, %temp2, %temp5
1834 or %temp5, %lo(symbol), %reg */
1839 /* It is possible that one of the registers we got for operands[2]
1840 might coincide with that of operands[0] (which is why we made
1841 it TImode). Pick the other one to use as our scratch. */
1842 if (rtx_equal_p (temp, op0))
1845 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1850 temp2 = temp; /* op0 is _not_ allowed, see above. */
1857 temp1 = gen_reg_rtx (DImode);
1858 temp2 = gen_reg_rtx (DImode);
1859 temp3 = gen_reg_rtx (DImode);
1860 temp4 = gen_reg_rtx (DImode);
1861 temp5 = gen_reg_rtx (DImode);
1864 emit_insn (gen_embmedany_textuhi (temp1, op1));
1865 emit_insn (gen_embmedany_texthi (temp2, op1));
1866 emit_insn (gen_embmedany_textulo (temp3, temp1, op1));
1867 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1868 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1869 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1870 gen_rtx_PLUS (DImode, temp4, temp2)));
1871 emit_insn (gen_embmedany_textlo (op0, temp5, op1));
1880 /* These avoid problems when cross compiling. If we do not
1881 go through all this hair then the optimizer will see
1882 invalid REG_EQUAL notes or in some cases none at all. */
1883 static void sparc_emit_set_safe_HIGH64 (rtx, HOST_WIDE_INT);
1884 static rtx gen_safe_SET64 (rtx, HOST_WIDE_INT);
1885 static rtx gen_safe_OR64 (rtx, HOST_WIDE_INT);
1886 static rtx gen_safe_XOR64 (rtx, HOST_WIDE_INT);
1888 #if HOST_BITS_PER_WIDE_INT == 64
1889 #define GEN_HIGHINT64(__x) GEN_INT ((__x) & ~(HOST_WIDE_INT)0x3ff)
1890 #define GEN_INT64(__x) GEN_INT (__x)
1892 #define GEN_HIGHINT64(__x) \
1893 immed_double_const ((__x) & ~(HOST_WIDE_INT)0x3ff, 0, DImode)
1894 #define GEN_INT64(__x) \
1895 immed_double_const ((__x) & 0xffffffff, \
1896 ((__x) & 0x80000000 ? -1 : 0), DImode)
1899 /* The optimizer is not to assume anything about exactly
1900 which bits are set for a HIGH, they are unspecified.
1901 Unfortunately this leads to many missed optimizations
1902 during CSE. We mask out the non-HIGH bits, and matches
1903 a plain movdi, to alleviate this problem. */
1905 sparc_emit_set_safe_HIGH64 (rtx dest, HOST_WIDE_INT val)
1907 emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_HIGHINT64 (val)));
1911 gen_safe_SET64 (rtx dest, HOST_WIDE_INT val)
1913 return gen_rtx_SET (VOIDmode, dest, GEN_INT64 (val));
1917 gen_safe_OR64 (rtx src, HOST_WIDE_INT val)
1919 return gen_rtx_IOR (DImode, src, GEN_INT64 (val));
1923 gen_safe_XOR64 (rtx src, HOST_WIDE_INT val)
1925 return gen_rtx_XOR (DImode, src, GEN_INT64 (val));
1928 /* Worker routines for 64-bit constant formation on arch64.
1929 One of the key things to be doing in these emissions is
1930 to create as many temp REGs as possible. This makes it
1931 possible for half-built constants to be used later when
1932 such values are similar to something required later on.
1933 Without doing this, the optimizer cannot see such
1936 static void sparc_emit_set_const64_quick1 (rtx, rtx,
1937 unsigned HOST_WIDE_INT, int);
1940 sparc_emit_set_const64_quick1 (rtx op0, rtx temp,
1941 unsigned HOST_WIDE_INT low_bits, int is_neg)
1943 unsigned HOST_WIDE_INT high_bits;
1946 high_bits = (~low_bits) & 0xffffffff;
1948 high_bits = low_bits;
1950 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1953 emit_insn (gen_rtx_SET (VOIDmode, op0,
1954 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1958 /* If we are XOR'ing with -1, then we should emit a one's complement
1959 instead. This way the combiner will notice logical operations
1960 such as ANDN later on and substitute. */
1961 if ((low_bits & 0x3ff) == 0x3ff)
1963 emit_insn (gen_rtx_SET (VOIDmode, op0,
1964 gen_rtx_NOT (DImode, temp)));
1968 emit_insn (gen_rtx_SET (VOIDmode, op0,
1969 gen_safe_XOR64 (temp,
1970 (-(HOST_WIDE_INT)0x400
1971 | (low_bits & 0x3ff)))));
1976 static void sparc_emit_set_const64_quick2 (rtx, rtx, unsigned HOST_WIDE_INT,
1977 unsigned HOST_WIDE_INT, int);
1980 sparc_emit_set_const64_quick2 (rtx op0, rtx temp,
1981 unsigned HOST_WIDE_INT high_bits,
1982 unsigned HOST_WIDE_INT low_immediate,
1987 if ((high_bits & 0xfffffc00) != 0)
1989 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1990 if ((high_bits & ~0xfffffc00) != 0)
1991 emit_insn (gen_rtx_SET (VOIDmode, op0,
1992 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1998 emit_insn (gen_safe_SET64 (temp, high_bits));
2002 /* Now shift it up into place. */
2003 emit_insn (gen_rtx_SET (VOIDmode, op0,
2004 gen_rtx_ASHIFT (DImode, temp2,
2005 GEN_INT (shift_count))));
2007 /* If there is a low immediate part piece, finish up by
2008 putting that in as well. */
2009 if (low_immediate != 0)
2010 emit_insn (gen_rtx_SET (VOIDmode, op0,
2011 gen_safe_OR64 (op0, low_immediate)));
2014 static void sparc_emit_set_const64_longway (rtx, rtx, unsigned HOST_WIDE_INT,
2015 unsigned HOST_WIDE_INT);
2017 /* Full 64-bit constant decomposition. Even though this is the
2018 'worst' case, we still optimize a few things away. */
2020 sparc_emit_set_const64_longway (rtx op0, rtx temp,
2021 unsigned HOST_WIDE_INT high_bits,
2022 unsigned HOST_WIDE_INT low_bits)
2026 if (reload_in_progress || reload_completed)
2029 sub_temp = gen_reg_rtx (DImode);
2031 if ((high_bits & 0xfffffc00) != 0)
2033 sparc_emit_set_safe_HIGH64 (temp, high_bits);
2034 if ((high_bits & ~0xfffffc00) != 0)
2035 emit_insn (gen_rtx_SET (VOIDmode,
2037 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
2043 emit_insn (gen_safe_SET64 (temp, high_bits));
2047 if (!reload_in_progress && !reload_completed)
2049 rtx temp2 = gen_reg_rtx (DImode);
2050 rtx temp3 = gen_reg_rtx (DImode);
2051 rtx temp4 = gen_reg_rtx (DImode);
2053 emit_insn (gen_rtx_SET (VOIDmode, temp4,
2054 gen_rtx_ASHIFT (DImode, sub_temp,
2057 sparc_emit_set_safe_HIGH64 (temp2, low_bits);
2058 if ((low_bits & ~0xfffffc00) != 0)
2060 emit_insn (gen_rtx_SET (VOIDmode, temp3,
2061 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
2062 emit_insn (gen_rtx_SET (VOIDmode, op0,
2063 gen_rtx_PLUS (DImode, temp4, temp3)));
2067 emit_insn (gen_rtx_SET (VOIDmode, op0,
2068 gen_rtx_PLUS (DImode, temp4, temp2)));
2073 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
2074 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
2075 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
2078 /* We are in the middle of reload, so this is really
2079 painful. However we do still make an attempt to
2080 avoid emitting truly stupid code. */
2081 if (low1 != const0_rtx)
2083 emit_insn (gen_rtx_SET (VOIDmode, op0,
2084 gen_rtx_ASHIFT (DImode, sub_temp,
2085 GEN_INT (to_shift))));
2086 emit_insn (gen_rtx_SET (VOIDmode, op0,
2087 gen_rtx_IOR (DImode, op0, low1)));
2095 if (low2 != const0_rtx)
2097 emit_insn (gen_rtx_SET (VOIDmode, op0,
2098 gen_rtx_ASHIFT (DImode, sub_temp,
2099 GEN_INT (to_shift))));
2100 emit_insn (gen_rtx_SET (VOIDmode, op0,
2101 gen_rtx_IOR (DImode, op0, low2)));
2109 emit_insn (gen_rtx_SET (VOIDmode, op0,
2110 gen_rtx_ASHIFT (DImode, sub_temp,
2111 GEN_INT (to_shift))));
2112 if (low3 != const0_rtx)
2113 emit_insn (gen_rtx_SET (VOIDmode, op0,
2114 gen_rtx_IOR (DImode, op0, low3)));
2119 /* Analyze a 64-bit constant for certain properties. */
2120 static void analyze_64bit_constant (unsigned HOST_WIDE_INT,
2121 unsigned HOST_WIDE_INT,
2122 int *, int *, int *);
2125 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits,
2126 unsigned HOST_WIDE_INT low_bits,
2127 int *hbsp, int *lbsp, int *abbasp)
2129 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
2132 lowest_bit_set = highest_bit_set = -1;
2136 if ((lowest_bit_set == -1)
2137 && ((low_bits >> i) & 1))
2139 if ((highest_bit_set == -1)
2140 && ((high_bits >> (32 - i - 1)) & 1))
2141 highest_bit_set = (64 - i - 1);
2144 && ((highest_bit_set == -1)
2145 || (lowest_bit_set == -1)));
2151 if ((lowest_bit_set == -1)
2152 && ((high_bits >> i) & 1))
2153 lowest_bit_set = i + 32;
2154 if ((highest_bit_set == -1)
2155 && ((low_bits >> (32 - i - 1)) & 1))
2156 highest_bit_set = 32 - i - 1;
2159 && ((highest_bit_set == -1)
2160 || (lowest_bit_set == -1)));
2162 /* If there are no bits set this should have gone out
2163 as one instruction! */
2164 if (lowest_bit_set == -1
2165 || highest_bit_set == -1)
2167 all_bits_between_are_set = 1;
2168 for (i = lowest_bit_set; i <= highest_bit_set; i++)
2172 if ((low_bits & (1 << i)) != 0)
2177 if ((high_bits & (1 << (i - 32))) != 0)
2180 all_bits_between_are_set = 0;
2183 *hbsp = highest_bit_set;
2184 *lbsp = lowest_bit_set;
2185 *abbasp = all_bits_between_are_set;
2188 static int const64_is_2insns (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2191 const64_is_2insns (unsigned HOST_WIDE_INT high_bits,
2192 unsigned HOST_WIDE_INT low_bits)
2194 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
2197 || high_bits == 0xffffffff)
2200 analyze_64bit_constant (high_bits, low_bits,
2201 &highest_bit_set, &lowest_bit_set,
2202 &all_bits_between_are_set);
2204 if ((highest_bit_set == 63
2205 || lowest_bit_set == 0)
2206 && all_bits_between_are_set != 0)
2209 if ((highest_bit_set - lowest_bit_set) < 21)
2215 static unsigned HOST_WIDE_INT create_simple_focus_bits (unsigned HOST_WIDE_INT,
2216 unsigned HOST_WIDE_INT,
2219 static unsigned HOST_WIDE_INT
2220 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits,
2221 unsigned HOST_WIDE_INT low_bits,
2222 int lowest_bit_set, int shift)
2224 HOST_WIDE_INT hi, lo;
2226 if (lowest_bit_set < 32)
2228 lo = (low_bits >> lowest_bit_set) << shift;
2229 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
2234 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
2241 /* Here we are sure to be arch64 and this is an integer constant
2242 being loaded into a register. Emit the most efficient
2243 insn sequence possible. Detection of all the 1-insn cases
2244 has been done already. */
2246 sparc_emit_set_const64 (rtx op0, rtx op1)
2248 unsigned HOST_WIDE_INT high_bits, low_bits;
2249 int lowest_bit_set, highest_bit_set;
2250 int all_bits_between_are_set;
2253 /* Sanity check that we know what we are working with. */
2254 if (! TARGET_ARCH64)
2257 if (GET_CODE (op0) != SUBREG)
2259 if (GET_CODE (op0) != REG
2260 || (REGNO (op0) >= SPARC_FIRST_FP_REG
2261 && REGNO (op0) <= SPARC_LAST_V9_FP_REG))
2265 if (reload_in_progress || reload_completed)
2268 if (GET_CODE (op1) != CONST_DOUBLE
2269 && GET_CODE (op1) != CONST_INT)
2271 sparc_emit_set_symbolic_const64 (op0, op1, temp);
2276 temp = gen_reg_rtx (DImode);
2278 if (GET_CODE (op1) == CONST_DOUBLE)
2280 #if HOST_BITS_PER_WIDE_INT == 64
2281 high_bits = (CONST_DOUBLE_LOW (op1) >> 32) & 0xffffffff;
2282 low_bits = CONST_DOUBLE_LOW (op1) & 0xffffffff;
2284 high_bits = CONST_DOUBLE_HIGH (op1);
2285 low_bits = CONST_DOUBLE_LOW (op1);
2290 #if HOST_BITS_PER_WIDE_INT == 64
2291 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
2292 low_bits = (INTVAL (op1) & 0xffffffff);
2294 high_bits = ((INTVAL (op1) < 0) ?
2297 low_bits = INTVAL (op1);
2301 /* low_bits bits 0 --> 31
2302 high_bits bits 32 --> 63 */
2304 analyze_64bit_constant (high_bits, low_bits,
2305 &highest_bit_set, &lowest_bit_set,
2306 &all_bits_between_are_set);
2308 /* First try for a 2-insn sequence. */
2310 /* These situations are preferred because the optimizer can
2311 * do more things with them:
2313 * sllx %reg, shift, %reg
2315 * srlx %reg, shift, %reg
2316 * 3) mov some_small_const, %reg
2317 * sllx %reg, shift, %reg
2319 if (((highest_bit_set == 63
2320 || lowest_bit_set == 0)
2321 && all_bits_between_are_set != 0)
2322 || ((highest_bit_set - lowest_bit_set) < 12))
2324 HOST_WIDE_INT the_const = -1;
2325 int shift = lowest_bit_set;
2327 if ((highest_bit_set != 63
2328 && lowest_bit_set != 0)
2329 || all_bits_between_are_set == 0)
2332 create_simple_focus_bits (high_bits, low_bits,
2335 else if (lowest_bit_set == 0)
2336 shift = -(63 - highest_bit_set);
2338 if (! SPARC_SIMM13_P (the_const))
2341 emit_insn (gen_safe_SET64 (temp, the_const));
2343 emit_insn (gen_rtx_SET (VOIDmode,
2345 gen_rtx_ASHIFT (DImode,
2349 emit_insn (gen_rtx_SET (VOIDmode,
2351 gen_rtx_LSHIFTRT (DImode,
2353 GEN_INT (-shift))));
2359 /* Now a range of 22 or less bits set somewhere.
2360 * 1) sethi %hi(focus_bits), %reg
2361 * sllx %reg, shift, %reg
2362 * 2) sethi %hi(focus_bits), %reg
2363 * srlx %reg, shift, %reg
2365 if ((highest_bit_set - lowest_bit_set) < 21)
2367 unsigned HOST_WIDE_INT focus_bits =
2368 create_simple_focus_bits (high_bits, low_bits,
2369 lowest_bit_set, 10);
2371 if (! SPARC_SETHI_P (focus_bits))
2374 sparc_emit_set_safe_HIGH64 (temp, focus_bits);
2376 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
2377 if (lowest_bit_set < 10)
2378 emit_insn (gen_rtx_SET (VOIDmode,
2380 gen_rtx_LSHIFTRT (DImode, temp,
2381 GEN_INT (10 - lowest_bit_set))));
2382 else if (lowest_bit_set > 10)
2383 emit_insn (gen_rtx_SET (VOIDmode,
2385 gen_rtx_ASHIFT (DImode, temp,
2386 GEN_INT (lowest_bit_set - 10))));
2392 /* 1) sethi %hi(low_bits), %reg
2393 * or %reg, %lo(low_bits), %reg
2394 * 2) sethi %hi(~low_bits), %reg
2395 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
2398 || high_bits == 0xffffffff)
2400 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
2401 (high_bits == 0xffffffff));
2405 /* Now, try 3-insn sequences. */
2407 /* 1) sethi %hi(high_bits), %reg
2408 * or %reg, %lo(high_bits), %reg
2409 * sllx %reg, 32, %reg
2413 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
2417 /* We may be able to do something quick
2418 when the constant is negated, so try that. */
2419 if (const64_is_2insns ((~high_bits) & 0xffffffff,
2420 (~low_bits) & 0xfffffc00))
2422 /* NOTE: The trailing bits get XOR'd so we need the
2423 non-negated bits, not the negated ones. */
2424 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
2426 if ((((~high_bits) & 0xffffffff) == 0
2427 && ((~low_bits) & 0x80000000) == 0)
2428 || (((~high_bits) & 0xffffffff) == 0xffffffff
2429 && ((~low_bits) & 0x80000000) != 0))
2431 int fast_int = (~low_bits & 0xffffffff);
2433 if ((SPARC_SETHI_P (fast_int)
2434 && (~high_bits & 0xffffffff) == 0)
2435 || SPARC_SIMM13_P (fast_int))
2436 emit_insn (gen_safe_SET64 (temp, fast_int));
2438 sparc_emit_set_const64 (temp, GEN_INT64 (fast_int));
2443 #if HOST_BITS_PER_WIDE_INT == 64
2444 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2445 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2447 negated_const = immed_double_const ((~low_bits) & 0xfffffc00,
2448 (~high_bits) & 0xffffffff,
2451 sparc_emit_set_const64 (temp, negated_const);
2454 /* If we are XOR'ing with -1, then we should emit a one's complement
2455 instead. This way the combiner will notice logical operations
2456 such as ANDN later on and substitute. */
2457 if (trailing_bits == 0x3ff)
2459 emit_insn (gen_rtx_SET (VOIDmode, op0,
2460 gen_rtx_NOT (DImode, temp)));
2464 emit_insn (gen_rtx_SET (VOIDmode,
2466 gen_safe_XOR64 (temp,
2467 (-0x400 | trailing_bits))));
2472 /* 1) sethi %hi(xxx), %reg
2473 * or %reg, %lo(xxx), %reg
2474 * sllx %reg, yyy, %reg
2476 * ??? This is just a generalized version of the low_bits==0
2477 * thing above, FIXME...
2479 if ((highest_bit_set - lowest_bit_set) < 32)
2481 unsigned HOST_WIDE_INT focus_bits =
2482 create_simple_focus_bits (high_bits, low_bits,
2485 /* We can't get here in this state. */
2486 if (highest_bit_set < 32
2487 || lowest_bit_set >= 32)
2490 /* So what we know is that the set bits straddle the
2491 middle of the 64-bit word. */
2492 sparc_emit_set_const64_quick2 (op0, temp,
2498 /* 1) sethi %hi(high_bits), %reg
2499 * or %reg, %lo(high_bits), %reg
2500 * sllx %reg, 32, %reg
2501 * or %reg, low_bits, %reg
2503 if (SPARC_SIMM13_P(low_bits)
2504 && ((int)low_bits > 0))
2506 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2510 /* The easiest way when all else fails, is full decomposition. */
2512 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
2513 high_bits, low_bits, ~high_bits, ~low_bits);
2515 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2518 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2519 return the mode to be used for the comparison. For floating-point,
2520 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2521 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2522 processing is needed. */
2525 select_cc_mode (enum rtx_code op, rtx x, rtx y ATTRIBUTE_UNUSED)
2527 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2553 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2554 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2556 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2557 return CCX_NOOVmode;
2563 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2570 /* X and Y are two things to compare using CODE. Emit the compare insn and
2571 return the rtx for the cc reg in the proper mode. */
2574 gen_compare_reg (enum rtx_code code, rtx x, rtx y)
2576 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
2579 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2580 fcc regs (cse can't tell they're really call clobbered regs and will
2581 remove a duplicate comparison even if there is an intervening function
2582 call - it will then try to reload the cc reg via an int reg which is why
2583 we need the movcc patterns). It is possible to provide the movcc
2584 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2585 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2586 to tell cse that CCFPE mode registers (even pseudos) are call
2589 /* ??? This is an experiment. Rather than making changes to cse which may
2590 or may not be easy/clean, we do our own cse. This is possible because
2591 we will generate hard registers. Cse knows they're call clobbered (it
2592 doesn't know the same thing about pseudos). If we guess wrong, no big
2593 deal, but if we win, great! */
2595 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2596 #if 1 /* experiment */
2599 /* We cycle through the registers to ensure they're all exercised. */
2600 static int next_fcc_reg = 0;
2601 /* Previous x,y for each fcc reg. */
2602 static rtx prev_args[4][2];
2604 /* Scan prev_args for x,y. */
2605 for (reg = 0; reg < 4; reg++)
2606 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2611 prev_args[reg][0] = x;
2612 prev_args[reg][1] = y;
2613 next_fcc_reg = (next_fcc_reg + 1) & 3;
2615 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2618 cc_reg = gen_reg_rtx (mode);
2619 #endif /* ! experiment */
2620 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2621 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2623 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2625 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2626 gen_rtx_COMPARE (mode, x, y)));
2631 /* This function is used for v9 only.
2632 CODE is the code for an Scc's comparison.
2633 OPERANDS[0] is the target of the Scc insn.
2634 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
2635 been generated yet).
2637 This function is needed to turn
2640 (gt (reg:CCX 100 %icc)
2644 (gt:DI (reg:CCX 100 %icc)
2647 IE: The instruction recognizer needs to see the mode of the comparison to
2648 find the right instruction. We could use "gt:DI" right in the
2649 define_expand, but leaving it out allows us to handle DI, SI, etc.
2651 We refer to the global sparc compare operands sparc_compare_op0 and
2652 sparc_compare_op1. */
2655 gen_v9_scc (enum rtx_code compare_code, register rtx *operands)
2660 && (GET_MODE (sparc_compare_op0) == DImode
2661 || GET_MODE (operands[0]) == DImode))
2664 op0 = sparc_compare_op0;
2665 op1 = sparc_compare_op1;
2667 /* Try to use the movrCC insns. */
2669 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
2670 && op1 == const0_rtx
2671 && v9_regcmp_p (compare_code))
2673 /* Special case for op0 != 0. This can be done with one instruction if
2674 operands[0] == sparc_compare_op0. */
2676 if (compare_code == NE
2677 && GET_MODE (operands[0]) == DImode
2678 && rtx_equal_p (op0, operands[0]))
2680 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2681 gen_rtx_IF_THEN_ELSE (DImode,
2682 gen_rtx_fmt_ee (compare_code, DImode,
2689 if (reg_overlap_mentioned_p (operands[0], op0))
2691 /* Handle the case where operands[0] == sparc_compare_op0.
2692 We "early clobber" the result. */
2693 op0 = gen_reg_rtx (GET_MODE (sparc_compare_op0));
2694 emit_move_insn (op0, sparc_compare_op0);
2697 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2698 if (GET_MODE (op0) != DImode)
2700 temp = gen_reg_rtx (DImode);
2701 convert_move (temp, op0, 0);
2705 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2706 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2707 gen_rtx_fmt_ee (compare_code, DImode,
2715 operands[1] = gen_compare_reg (compare_code, op0, op1);
2717 switch (GET_MODE (operands[1]))
2727 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2728 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2729 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2730 gen_rtx_fmt_ee (compare_code,
2731 GET_MODE (operands[1]),
2732 operands[1], const0_rtx),
2733 const1_rtx, operands[0])));
2738 /* Emit a conditional jump insn for the v9 architecture using comparison code
2739 CODE and jump target LABEL.
2740 This function exists to take advantage of the v9 brxx insns. */
2743 emit_v9_brxx_insn (enum rtx_code code, rtx op0, rtx label)
2745 emit_jump_insn (gen_rtx_SET (VOIDmode,
2747 gen_rtx_IF_THEN_ELSE (VOIDmode,
2748 gen_rtx_fmt_ee (code, GET_MODE (op0),
2750 gen_rtx_LABEL_REF (VOIDmode, label),
2754 /* Generate a DFmode part of a hard TFmode register.
2755 REG is the TFmode hard register, LOW is 1 for the
2756 low 64bit of the register and 0 otherwise.
2759 gen_df_reg (rtx reg, int low)
2761 int regno = REGNO (reg);
2763 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2764 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
2765 return gen_rtx_REG (DFmode, regno);
2768 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
2769 Unlike normal calls, TFmode operands are passed by reference. It is
2770 assumed that no more than 3 operands are required. */
2773 emit_soft_tfmode_libcall (const char *func_name, int nargs, rtx *operands)
2775 rtx ret_slot = NULL, arg[3], func_sym;
2778 /* We only expect to be called for conversions, unary, and binary ops. */
2779 if (nargs < 2 || nargs > 3)
2782 for (i = 0; i < nargs; ++i)
2784 rtx this_arg = operands[i];
2787 /* TFmode arguments and return values are passed by reference. */
2788 if (GET_MODE (this_arg) == TFmode)
2790 int force_stack_temp;
2792 force_stack_temp = 0;
2793 if (TARGET_BUGGY_QP_LIB && i == 0)
2794 force_stack_temp = 1;
2796 if (GET_CODE (this_arg) == MEM
2797 && ! force_stack_temp)
2798 this_arg = XEXP (this_arg, 0);
2799 else if (CONSTANT_P (this_arg)
2800 && ! force_stack_temp)
2802 this_slot = force_const_mem (TFmode, this_arg);
2803 this_arg = XEXP (this_slot, 0);
2807 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode), 0);
2809 /* Operand 0 is the return value. We'll copy it out later. */
2811 emit_move_insn (this_slot, this_arg);
2813 ret_slot = this_slot;
2815 this_arg = XEXP (this_slot, 0);
2822 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
2824 if (GET_MODE (operands[0]) == TFmode)
2827 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
2828 arg[0], GET_MODE (arg[0]),
2829 arg[1], GET_MODE (arg[1]));
2831 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
2832 arg[0], GET_MODE (arg[0]),
2833 arg[1], GET_MODE (arg[1]),
2834 arg[2], GET_MODE (arg[2]));
2837 emit_move_insn (operands[0], ret_slot);
2846 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
2847 GET_MODE (operands[0]), 1,
2848 arg[1], GET_MODE (arg[1]));
2850 if (ret != operands[0])
2851 emit_move_insn (operands[0], ret);
2855 /* Expand soft-float TFmode calls to sparc abi routines. */
2858 emit_soft_tfmode_binop (enum rtx_code code, rtx *operands)
2880 emit_soft_tfmode_libcall (func, 3, operands);
2884 emit_soft_tfmode_unop (enum rtx_code code, rtx *operands)
2897 emit_soft_tfmode_libcall (func, 2, operands);
2901 emit_soft_tfmode_cvt (enum rtx_code code, rtx *operands)
2908 switch (GET_MODE (operands[1]))
2921 case FLOAT_TRUNCATE:
2922 switch (GET_MODE (operands[0]))
2936 switch (GET_MODE (operands[1]))
2949 case UNSIGNED_FLOAT:
2950 switch (GET_MODE (operands[1]))
2964 switch (GET_MODE (operands[0]))
2978 switch (GET_MODE (operands[0]))
2995 emit_soft_tfmode_libcall (func, 2, operands);
2998 /* Expand a hard-float tfmode operation. All arguments must be in
3002 emit_hard_tfmode_operation (enum rtx_code code, rtx *operands)
3006 if (GET_RTX_CLASS (code) == RTX_UNARY)
3008 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
3009 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
3013 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
3014 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
3015 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
3016 operands[1], operands[2]);
3019 if (register_operand (operands[0], VOIDmode))
3022 dest = gen_reg_rtx (GET_MODE (operands[0]));
3024 emit_insn (gen_rtx_SET (VOIDmode, dest, op));
3026 if (dest != operands[0])
3027 emit_move_insn (operands[0], dest);
3031 emit_tfmode_binop (enum rtx_code code, rtx *operands)
3033 if (TARGET_HARD_QUAD)
3034 emit_hard_tfmode_operation (code, operands);
3036 emit_soft_tfmode_binop (code, operands);
3040 emit_tfmode_unop (enum rtx_code code, rtx *operands)
3042 if (TARGET_HARD_QUAD)
3043 emit_hard_tfmode_operation (code, operands);
3045 emit_soft_tfmode_unop (code, operands);
3049 emit_tfmode_cvt (enum rtx_code code, rtx *operands)
3051 if (TARGET_HARD_QUAD)
3052 emit_hard_tfmode_operation (code, operands);
3054 emit_soft_tfmode_cvt (code, operands);
3057 /* Return nonzero if a branch/jump/call instruction will be emitting
3058 nop into its delay slot. */
3061 empty_delay_slot (rtx insn)
3065 /* If no previous instruction (should not happen), return true. */
3066 if (PREV_INSN (insn) == NULL)
3069 seq = NEXT_INSN (PREV_INSN (insn));
3070 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
3076 /* Return nonzero if TRIAL can go into the call delay slot. */
3079 tls_call_delay (rtx trial)
3084 call __tls_get_addr, %tgd_call (foo)
3085 add %l7, %o0, %o0, %tgd_add (foo)
3086 while Sun as/ld does not. */
3087 if (TARGET_GNU_TLS || !TARGET_TLS)
3090 pat = PATTERN (trial);
3091 if (GET_CODE (pat) != SET || GET_CODE (SET_DEST (pat)) != PLUS)
3094 unspec = XEXP (SET_DEST (pat), 1);
3095 if (GET_CODE (unspec) != UNSPEC
3096 || (XINT (unspec, 1) != UNSPEC_TLSGD
3097 && XINT (unspec, 1) != UNSPEC_TLSLDM))
3103 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
3104 instruction. RETURN_P is true if the v9 variant 'return' is to be
3105 considered in the test too.
3107 TRIAL must be a SET whose destination is a REG appropriate for the
3108 'restore' instruction or, if RETURN_P is true, for the 'return'
3112 eligible_for_restore_insn (rtx trial, bool return_p)
3114 rtx pat = PATTERN (trial);
3115 rtx src = SET_SRC (pat);
3117 /* The 'restore src,%g0,dest' pattern for word mode and below. */
3118 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3119 && arith_operand (src, GET_MODE (src)))
3122 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3124 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
3127 /* The 'restore src,%g0,dest' pattern for double-word mode. */
3128 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3129 && arith_double_operand (src, GET_MODE (src)))
3130 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3132 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
3133 else if (! TARGET_FPU && register_operand (src, SFmode))
3136 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
3137 else if (! TARGET_FPU && TARGET_ARCH64 && register_operand (src, DFmode))
3140 /* If we have the 'return' instruction, anything that does not use
3141 local or output registers and can go into a delay slot wins. */
3142 else if (return_p && TARGET_V9 && ! epilogue_renumber (&pat, 1)
3143 && (get_attr_in_uncond_branch_delay (trial)
3144 == IN_UNCOND_BRANCH_DELAY_TRUE))
3147 /* The 'restore src1,src2,dest' pattern for SImode. */
3148 else if (GET_CODE (src) == PLUS
3149 && register_operand (XEXP (src, 0), SImode)
3150 && arith_operand (XEXP (src, 1), SImode))
3153 /* The 'restore src1,src2,dest' pattern for DImode. */
3154 else if (GET_CODE (src) == PLUS
3155 && register_operand (XEXP (src, 0), DImode)
3156 && arith_double_operand (XEXP (src, 1), DImode))
3159 /* The 'restore src1,%lo(src2),dest' pattern. */
3160 else if (GET_CODE (src) == LO_SUM
3161 && ! TARGET_CM_MEDMID
3162 && ((register_operand (XEXP (src, 0), SImode)
3163 && immediate_operand (XEXP (src, 1), SImode))
3165 && register_operand (XEXP (src, 0), DImode)
3166 && immediate_operand (XEXP (src, 1), DImode))))
3169 /* The 'restore src,src,dest' pattern. */
3170 else if (GET_CODE (src) == ASHIFT
3171 && (register_operand (XEXP (src, 0), SImode)
3172 || register_operand (XEXP (src, 0), DImode))
3173 && XEXP (src, 1) == const1_rtx)
3179 /* Return nonzero if TRIAL can go into the function return's
3183 eligible_for_return_delay (rtx trial)
3187 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
3190 if (get_attr_length (trial) != 1)
3193 /* If there are any call-saved registers, we should scan TRIAL if it
3194 does not reference them. For now just make it easy. */
3198 /* If the function uses __builtin_eh_return, the eh_return machinery
3199 occupies the delay slot. */
3200 if (current_function_calls_eh_return)
3203 /* In the case of a true leaf function, anything can go into the slot. */
3204 if (sparc_leaf_function_p)
3205 return get_attr_in_uncond_branch_delay (trial)
3206 == IN_UNCOND_BRANCH_DELAY_TRUE;
3208 pat = PATTERN (trial);
3210 /* Otherwise, only operations which can be done in tandem with
3211 a `restore' or `return' insn can go into the delay slot. */
3212 if (GET_CODE (SET_DEST (pat)) != REG
3213 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24))
3216 /* If this instruction sets up floating point register and we have a return
3217 instruction, it can probably go in. But restore will not work
3219 if (REGNO (SET_DEST (pat)) >= 32)
3221 && ! epilogue_renumber (&pat, 1)
3222 && (get_attr_in_uncond_branch_delay (trial)
3223 == IN_UNCOND_BRANCH_DELAY_TRUE));
3225 return eligible_for_restore_insn (trial, true);
3228 /* Return nonzero if TRIAL can go into the sibling call's
3232 eligible_for_sibcall_delay (rtx trial)
3236 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
3239 if (get_attr_length (trial) != 1)
3242 pat = PATTERN (trial);
3244 if (sparc_leaf_function_p)
3246 /* If the tail call is done using the call instruction,
3247 we have to restore %o7 in the delay slot. */
3248 if (LEAF_SIBCALL_SLOT_RESERVED_P)
3251 /* %g1 is used to build the function address */
3252 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
3258 /* Otherwise, only operations which can be done in tandem with
3259 a `restore' insn can go into the delay slot. */
3260 if (GET_CODE (SET_DEST (pat)) != REG
3261 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24)
3262 || REGNO (SET_DEST (pat)) >= 32)
3265 /* If it mentions %o7, it can't go in, because sibcall will clobber it
3267 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
3270 return eligible_for_restore_insn (trial, false);
3274 short_branch (int uid1, int uid2)
3276 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
3278 /* Leave a few words of "slop". */
3279 if (delta >= -1023 && delta <= 1022)
3285 /* Return nonzero if REG is not used after INSN.
3286 We assume REG is a reload reg, and therefore does
3287 not live past labels or calls or jumps. */
3289 reg_unused_after (rtx reg, rtx insn)
3291 enum rtx_code code, prev_code = UNKNOWN;
3293 while ((insn = NEXT_INSN (insn)))
3295 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
3298 code = GET_CODE (insn);
3299 if (GET_CODE (insn) == CODE_LABEL)
3304 rtx set = single_set (insn);
3305 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
3308 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
3310 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
3318 /* Determine if it's legal to put X into the constant pool. This
3319 is not possible if X contains the address of a symbol that is
3320 not constant (TLS) or not known at final link time (PIC). */
3323 sparc_cannot_force_const_mem (rtx x)
3325 switch (GET_CODE (x))
3330 /* Accept all non-symbolic constants. */
3334 /* Labels are OK iff we are non-PIC. */
3335 return flag_pic != 0;
3338 /* 'Naked' TLS symbol references are never OK,
3339 non-TLS symbols are OK iff we are non-PIC. */
3340 if (SYMBOL_REF_TLS_MODEL (x))
3343 return flag_pic != 0;
3346 return sparc_cannot_force_const_mem (XEXP (x, 0));
3349 return sparc_cannot_force_const_mem (XEXP (x, 0))
3350 || sparc_cannot_force_const_mem (XEXP (x, 1));
3358 /* The table we use to reference PIC data. */
3359 static GTY(()) rtx global_offset_table;
3361 /* The function we use to get at it. */
3362 static GTY(()) rtx add_pc_to_pic_symbol;
3363 static GTY(()) char add_pc_to_pic_symbol_name[256];
3365 /* Ensure that we are not using patterns that are not OK with PIC. */
3373 if (GET_CODE (recog_data.operand[i]) == SYMBOL_REF
3374 || (GET_CODE (recog_data.operand[i]) == CONST
3375 && ! (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
3376 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
3377 == global_offset_table)
3378 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
3387 /* Return true if X is an address which needs a temporary register when
3388 reloaded while generating PIC code. */
3391 pic_address_needs_scratch (rtx x)
3393 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
3394 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3395 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
3396 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3397 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
3403 /* Determine if a given RTX is a valid constant. We already know this
3404 satisfies CONSTANT_P. */
3407 legitimate_constant_p (rtx x)
3411 switch (GET_CODE (x))
3414 /* TLS symbols are not constant. */
3415 if (SYMBOL_REF_TLS_MODEL (x))
3420 inner = XEXP (x, 0);
3422 /* Offsets of TLS symbols are never valid.
3423 Discourage CSE from creating them. */
3424 if (GET_CODE (inner) == PLUS
3425 && tls_symbolic_operand (XEXP (inner, 0)))
3430 if (GET_MODE (x) == VOIDmode)
3433 /* Floating point constants are generally not ok.
3434 The only exception is 0.0 in VIS. */
3436 && (GET_MODE (x) == SFmode
3437 || GET_MODE (x) == DFmode
3438 || GET_MODE (x) == TFmode)
3439 && fp_zero_operand (x, GET_MODE (x)))
3451 /* Determine if a given RTX is a valid constant address. */
3454 constant_address_p (rtx x)
3456 switch (GET_CODE (x))
3464 if (flag_pic && pic_address_needs_scratch (x))
3466 return legitimate_constant_p (x);
3469 return !flag_pic && legitimate_constant_p (x);
3476 /* Nonzero if the constant value X is a legitimate general operand
3477 when generating PIC code. It is given that flag_pic is on and
3478 that X satisfies CONSTANT_P or is a CONST_DOUBLE. */
3481 legitimate_pic_operand_p (rtx x)
3483 if (pic_address_needs_scratch (x))
3485 if (tls_symbolic_operand (x)
3486 || (GET_CODE (x) == CONST
3487 && GET_CODE (XEXP (x, 0)) == PLUS
3488 && tls_symbolic_operand (XEXP (XEXP (x, 0), 0))))
3493 /* Return nonzero if ADDR is a valid memory address.
3494 STRICT specifies whether strict register checking applies. */
3497 legitimate_address_p (enum machine_mode mode, rtx addr, int strict)
3499 rtx rs1 = NULL, rs2 = NULL, imm1 = NULL, imm2;
3501 if (REG_P (addr) || GET_CODE (addr) == SUBREG)
3503 else if (GET_CODE (addr) == PLUS)
3505 rs1 = XEXP (addr, 0);
3506 rs2 = XEXP (addr, 1);
3508 /* Canonicalize. REG comes first, if there are no regs,
3509 LO_SUM comes first. */
3511 && GET_CODE (rs1) != SUBREG
3513 || GET_CODE (rs2) == SUBREG
3514 || (GET_CODE (rs2) == LO_SUM && GET_CODE (rs1) != LO_SUM)))
3516 rs1 = XEXP (addr, 1);
3517 rs2 = XEXP (addr, 0);
3521 && rs1 == pic_offset_table_rtx
3523 && GET_CODE (rs2) != SUBREG
3524 && GET_CODE (rs2) != LO_SUM
3525 && GET_CODE (rs2) != MEM
3526 && !tls_symbolic_operand (rs2)
3527 && (! symbolic_operand (rs2, VOIDmode) || mode == Pmode)
3528 && (GET_CODE (rs2) != CONST_INT || SMALL_INT (rs2)))
3530 || GET_CODE (rs1) == SUBREG)
3531 && RTX_OK_FOR_OFFSET_P (rs2)))
3536 else if ((REG_P (rs1) || GET_CODE (rs1) == SUBREG)
3537 && (REG_P (rs2) || GET_CODE (rs2) == SUBREG))
3539 /* We prohibit REG + REG for TFmode when there are no quad move insns
3540 and we consequently need to split. We do this because REG+REG
3541 is not an offsettable address. If we get the situation in reload
3542 where source and destination of a movtf pattern are both MEMs with
3543 REG+REG address, then only one of them gets converted to an
3544 offsettable address. */
3546 && ! (TARGET_FPU && TARGET_ARCH64 && TARGET_HARD_QUAD))
3549 /* We prohibit REG + REG on ARCH32 if not optimizing for
3550 DFmode/DImode because then mem_min_alignment is likely to be zero
3551 after reload and the forced split would lack a matching splitter
3553 if (TARGET_ARCH32 && !optimize
3554 && (mode == DFmode || mode == DImode))
3557 else if (USE_AS_OFFSETABLE_LO10
3558 && GET_CODE (rs1) == LO_SUM
3560 && ! TARGET_CM_MEDMID
3561 && RTX_OK_FOR_OLO10_P (rs2))
3565 imm1 = XEXP (rs1, 1);
3566 rs1 = XEXP (rs1, 0);
3567 if (! CONSTANT_P (imm1) || tls_symbolic_operand (rs1))
3571 else if (GET_CODE (addr) == LO_SUM)
3573 rs1 = XEXP (addr, 0);
3574 imm1 = XEXP (addr, 1);
3576 if (! CONSTANT_P (imm1) || tls_symbolic_operand (rs1))
3579 if (USE_AS_OFFSETABLE_LO10)
3581 /* We can't allow TFmode, because an offset greater than or equal to
3582 the alignment (8) may cause the LO_SUM to overflow if !v9. */
3583 if (mode == TFmode && ! TARGET_V9)
3588 /* We prohibit LO_SUM for TFmode when there are no quad move insns
3589 and we consequently need to split. We do this because LO_SUM
3590 is not an offsettable address. If we get the situation in reload
3591 where source and destination of a movtf pattern are both MEMs with
3592 LO_SUM address, then only one of them gets converted to an
3593 offsettable address. */
3595 && ! (TARGET_FPU && TARGET_ARCH64 && TARGET_HARD_QUAD))
3599 else if (GET_CODE (addr) == CONST_INT && SMALL_INT (addr))
3604 if (GET_CODE (rs1) == SUBREG)
3605 rs1 = SUBREG_REG (rs1);
3611 if (GET_CODE (rs2) == SUBREG)
3612 rs2 = SUBREG_REG (rs2);
3619 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1))
3620 || (rs2 && !REGNO_OK_FOR_BASE_P (REGNO (rs2))))
3625 if ((REGNO (rs1) >= 32
3626 && REGNO (rs1) != FRAME_POINTER_REGNUM
3627 && REGNO (rs1) < FIRST_PSEUDO_REGISTER)
3629 && (REGNO (rs2) >= 32
3630 && REGNO (rs2) != FRAME_POINTER_REGNUM
3631 && REGNO (rs2) < FIRST_PSEUDO_REGISTER)))
3637 /* Construct the SYMBOL_REF for the tls_get_offset function. */
3639 static GTY(()) rtx sparc_tls_symbol;
3641 sparc_tls_get_addr (void)
3643 if (!sparc_tls_symbol)
3644 sparc_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_addr");
3646 return sparc_tls_symbol;
3650 sparc_tls_got (void)
3655 current_function_uses_pic_offset_table = 1;
3656 return pic_offset_table_rtx;
3659 if (!global_offset_table)
3660 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3661 temp = gen_reg_rtx (Pmode);
3662 emit_move_insn (temp, global_offset_table);
3667 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3668 this (thread-local) address. */
3671 legitimize_tls_address (rtx addr)
3673 rtx temp1, temp2, temp3, ret, o0, got, insn;
3678 if (GET_CODE (addr) == SYMBOL_REF)
3679 switch (SYMBOL_REF_TLS_MODEL (addr))
3681 case TLS_MODEL_GLOBAL_DYNAMIC:
3683 temp1 = gen_reg_rtx (SImode);
3684 temp2 = gen_reg_rtx (SImode);
3685 ret = gen_reg_rtx (Pmode);
3686 o0 = gen_rtx_REG (Pmode, 8);
3687 got = sparc_tls_got ();
3688 emit_insn (gen_tgd_hi22 (temp1, addr));
3689 emit_insn (gen_tgd_lo10 (temp2, temp1, addr));
3692 emit_insn (gen_tgd_add32 (o0, got, temp2, addr));
3693 insn = emit_call_insn (gen_tgd_call32 (o0, sparc_tls_get_addr (),
3698 emit_insn (gen_tgd_add64 (o0, got, temp2, addr));
3699 insn = emit_call_insn (gen_tgd_call64 (o0, sparc_tls_get_addr (),
3702 CALL_INSN_FUNCTION_USAGE (insn)
3703 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
3704 CALL_INSN_FUNCTION_USAGE (insn));
3705 insn = get_insns ();
3707 emit_libcall_block (insn, ret, o0, addr);
3710 case TLS_MODEL_LOCAL_DYNAMIC:
3712 temp1 = gen_reg_rtx (SImode);
3713 temp2 = gen_reg_rtx (SImode);
3714 temp3 = gen_reg_rtx (Pmode);
3715 ret = gen_reg_rtx (Pmode);
3716 o0 = gen_rtx_REG (Pmode, 8);
3717 got = sparc_tls_got ();
3718 emit_insn (gen_tldm_hi22 (temp1));
3719 emit_insn (gen_tldm_lo10 (temp2, temp1));
3722 emit_insn (gen_tldm_add32 (o0, got, temp2));
3723 insn = emit_call_insn (gen_tldm_call32 (o0, sparc_tls_get_addr (),
3728 emit_insn (gen_tldm_add64 (o0, got, temp2));
3729 insn = emit_call_insn (gen_tldm_call64 (o0, sparc_tls_get_addr (),
3732 CALL_INSN_FUNCTION_USAGE (insn)
3733 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
3734 CALL_INSN_FUNCTION_USAGE (insn));
3735 insn = get_insns ();
3737 emit_libcall_block (insn, temp3, o0,
3738 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3739 UNSPEC_TLSLD_BASE));
3740 temp1 = gen_reg_rtx (SImode);
3741 temp2 = gen_reg_rtx (SImode);
3742 emit_insn (gen_tldo_hix22 (temp1, addr));
3743 emit_insn (gen_tldo_lox10 (temp2, temp1, addr));
3745 emit_insn (gen_tldo_add32 (ret, temp3, temp2, addr));
3747 emit_insn (gen_tldo_add64 (ret, temp3, temp2, addr));
3750 case TLS_MODEL_INITIAL_EXEC:
3751 temp1 = gen_reg_rtx (SImode);
3752 temp2 = gen_reg_rtx (SImode);
3753 temp3 = gen_reg_rtx (Pmode);
3754 got = sparc_tls_got ();
3755 emit_insn (gen_tie_hi22 (temp1, addr));
3756 emit_insn (gen_tie_lo10 (temp2, temp1, addr));
3758 emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
3760 emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
3763 ret = gen_reg_rtx (Pmode);
3765 emit_insn (gen_tie_add32 (ret, gen_rtx_REG (Pmode, 7),
3768 emit_insn (gen_tie_add64 (ret, gen_rtx_REG (Pmode, 7),
3772 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp3);
3775 case TLS_MODEL_LOCAL_EXEC:
3776 temp1 = gen_reg_rtx (Pmode);
3777 temp2 = gen_reg_rtx (Pmode);
3780 emit_insn (gen_tle_hix22_sp32 (temp1, addr));
3781 emit_insn (gen_tle_lox10_sp32 (temp2, temp1, addr));
3785 emit_insn (gen_tle_hix22_sp64 (temp1, addr));
3786 emit_insn (gen_tle_lox10_sp64 (temp2, temp1, addr));
3788 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp2);
3796 abort (); /* for now ... */
3802 /* Legitimize PIC addresses. If the address is already position-independent,
3803 we return ORIG. Newly generated position-independent addresses go into a
3804 reg. This is REG if nonzero, otherwise we allocate register(s) as
3808 legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
3811 if (GET_CODE (orig) == SYMBOL_REF)
3813 rtx pic_ref, address;
3818 if (reload_in_progress || reload_completed)
3821 reg = gen_reg_rtx (Pmode);
3826 /* If not during reload, allocate another temp reg here for loading
3827 in the address, so that these instructions can be optimized
3829 rtx temp_reg = ((reload_in_progress || reload_completed)
3830 ? reg : gen_reg_rtx (Pmode));
3832 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
3833 won't get confused into thinking that these two instructions
3834 are loading in the true address of the symbol. If in the
3835 future a PIC rtx exists, that should be used instead. */
3836 if (Pmode == SImode)
3838 emit_insn (gen_movsi_high_pic (temp_reg, orig));
3839 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
3843 emit_insn (gen_movdi_high_pic (temp_reg, orig));
3844 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
3851 pic_ref = gen_const_mem (Pmode,
3852 gen_rtx_PLUS (Pmode,
3853 pic_offset_table_rtx, address));
3854 current_function_uses_pic_offset_table = 1;
3855 insn = emit_move_insn (reg, pic_ref);
3856 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3858 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
3862 else if (GET_CODE (orig) == CONST)
3866 if (GET_CODE (XEXP (orig, 0)) == PLUS
3867 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3872 if (reload_in_progress || reload_completed)
3875 reg = gen_reg_rtx (Pmode);
3878 if (GET_CODE (XEXP (orig, 0)) == PLUS)
3880 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
3881 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
3882 base == reg ? 0 : reg);
3887 if (GET_CODE (offset) == CONST_INT)
3889 if (SMALL_INT (offset))
3890 return plus_constant (base, INTVAL (offset));
3891 else if (! reload_in_progress && ! reload_completed)
3892 offset = force_reg (Pmode, offset);
3894 /* If we reach here, then something is seriously wrong. */
3897 return gen_rtx_PLUS (Pmode, base, offset);
3899 else if (GET_CODE (orig) == LABEL_REF)
3900 /* ??? Why do we do this? */
3901 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
3902 the register is live instead, in case it is eliminated. */
3903 current_function_uses_pic_offset_table = 1;
3908 /* Try machine-dependent ways of modifying an illegitimate address X
3909 to be legitimate. If we find one, return the new, valid address.
3911 OLDX is the address as it was before break_out_memory_refs was called.
3912 In some cases it is useful to look at this to decide what needs to be done.
3914 MODE is the mode of the operand pointed to by X. */
3917 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
3921 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT)
3922 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3923 force_operand (XEXP (x, 0), NULL_RTX));
3924 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == MULT)
3925 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3926 force_operand (XEXP (x, 1), NULL_RTX));
3927 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS)
3928 x = gen_rtx_PLUS (Pmode, force_operand (XEXP (x, 0), NULL_RTX),
3930 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == PLUS)
3931 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3932 force_operand (XEXP (x, 1), NULL_RTX));
3934 if (x != orig_x && legitimate_address_p (mode, x, FALSE))
3937 if (tls_symbolic_operand (x))
3938 x = legitimize_tls_address (x);
3940 x = legitimize_pic_address (x, mode, 0);
3941 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 1)))
3942 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3943 copy_to_mode_reg (Pmode, XEXP (x, 1)));
3944 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 0)))
3945 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3946 copy_to_mode_reg (Pmode, XEXP (x, 0)));
3947 else if (GET_CODE (x) == SYMBOL_REF
3948 || GET_CODE (x) == CONST
3949 || GET_CODE (x) == LABEL_REF)
3950 x = copy_to_suggested_reg (x, NULL_RTX, Pmode);
3954 /* Emit the special PIC prologue. */
3957 load_pic_register (void)
3959 int orig_flag_pic = flag_pic;
3961 /* If we haven't emitted the special helper function, do so now. */
3962 if (add_pc_to_pic_symbol_name[0] == 0)
3964 const char *pic_name = reg_names[REGNO (pic_offset_table_rtx)];
3967 ASM_GENERATE_INTERNAL_LABEL (add_pc_to_pic_symbol_name, "LADDPC", 0);
3970 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
3972 ASM_OUTPUT_ALIGN (asm_out_file, align);
3973 ASM_OUTPUT_LABEL (asm_out_file, add_pc_to_pic_symbol_name);
3974 if (flag_delayed_branch)
3975 fprintf (asm_out_file, "\tjmp %%o7+8\n\t add\t%%o7, %s, %s\n",
3976 pic_name, pic_name);
3978 fprintf (asm_out_file, "\tadd\t%%o7, %s, %s\n\tjmp %%o7+8\n\t nop\n",
3979 pic_name, pic_name);
3982 /* Initialize every time through, since we can't easily
3983 know this to be permanent. */
3984 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3985 add_pc_to_pic_symbol = gen_rtx_SYMBOL_REF (Pmode, add_pc_to_pic_symbol_name);
3989 emit_insn (gen_load_pcrel_symdi (pic_offset_table_rtx, global_offset_table,
3990 add_pc_to_pic_symbol));
3992 emit_insn (gen_load_pcrel_symsi (pic_offset_table_rtx, global_offset_table,
3993 add_pc_to_pic_symbol));
3994 flag_pic = orig_flag_pic;
3996 /* Need to emit this whether or not we obey regdecls,
3997 since setjmp/longjmp can cause life info to screw up.
3998 ??? In the case where we don't obey regdecls, this is not sufficient
3999 since we may not fall out the bottom. */
4000 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
4003 /* Return 1 if RTX is a MEM which is known to be aligned to at
4004 least a DESIRED byte boundary. */
4007 mem_min_alignment (rtx mem, int desired)
4009 rtx addr, base, offset;
4011 /* If it's not a MEM we can't accept it. */
4012 if (GET_CODE (mem) != MEM)
4016 if (MEM_ALIGN (mem) / BITS_PER_UNIT >= (unsigned)desired)
4019 /* ??? The rest of the function predates MEM_ALIGN so
4020 there is probably a bit of redundancy. */
4021 addr = XEXP (mem, 0);
4022 base = offset = NULL_RTX;
4023 if (GET_CODE (addr) == PLUS)
4025 if (GET_CODE (XEXP (addr, 0)) == REG)
4027 base = XEXP (addr, 0);
4029 /* What we are saying here is that if the base
4030 REG is aligned properly, the compiler will make
4031 sure any REG based index upon it will be so
4033 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
4034 offset = XEXP (addr, 1);
4036 offset = const0_rtx;
4039 else if (GET_CODE (addr) == REG)
4042 offset = const0_rtx;
4045 if (base != NULL_RTX)
4047 int regno = REGNO (base);
4049 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
4051 /* Check if the compiler has recorded some information
4052 about the alignment of the base REG. If reload has
4053 completed, we already matched with proper alignments.
4054 If not running global_alloc, reload might give us
4055 unaligned pointer to local stack though. */
4057 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
4058 || (optimize && reload_completed))
4059 && (INTVAL (offset) & (desired - 1)) == 0)
4064 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
4068 else if (! TARGET_UNALIGNED_DOUBLES
4069 || CONSTANT_P (addr)
4070 || GET_CODE (addr) == LO_SUM)
4072 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
4073 is true, in which case we can only assume that an access is aligned if
4074 it is to a constant address, or the address involves a LO_SUM. */
4078 /* An obviously unaligned address. */
4083 /* Vectors to keep interesting information about registers where it can easily
4084 be got. We used to use the actual mode value as the bit number, but there
4085 are more than 32 modes now. Instead we use two tables: one indexed by
4086 hard register number, and one indexed by mode. */
4088 /* The purpose of sparc_mode_class is to shrink the range of modes so that
4089 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
4090 mapped into one sparc_mode_class mode. */
4092 enum sparc_mode_class {
4093 S_MODE, D_MODE, T_MODE, O_MODE,
4094 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
4098 /* Modes for single-word and smaller quantities. */
4099 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
4101 /* Modes for double-word and smaller quantities. */
4102 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
4104 /* Modes for quad-word and smaller quantities. */
4105 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
4107 /* Modes for 8-word and smaller quantities. */
4108 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
4110 /* Modes for single-float quantities. We must allow any single word or
4111 smaller quantity. This is because the fix/float conversion instructions
4112 take integer inputs/outputs from the float registers. */
4113 #define SF_MODES (S_MODES)
4115 /* Modes for double-float and smaller quantities. */
4116 #define DF_MODES (S_MODES | D_MODES)
4118 /* Modes for double-float only quantities. */
4119 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
4121 /* Modes for quad-float only quantities. */
4122 #define TF_ONLY_MODES (1 << (int) TF_MODE)
4124 /* Modes for quad-float and smaller quantities. */
4125 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
4127 /* Modes for quad-float and double-float quantities. */
4128 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
4130 /* Modes for quad-float pair only quantities. */
4131 #define OF_ONLY_MODES (1 << (int) OF_MODE)
4133 /* Modes for quad-float pairs and smaller quantities. */
4134 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
4136 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
4138 /* Modes for condition codes. */
4139 #define CC_MODES (1 << (int) CC_MODE)
4140 #define CCFP_MODES (1 << (int) CCFP_MODE)
4142 /* Value is 1 if register/mode pair is acceptable on sparc.
4143 The funny mixture of D and T modes is because integer operations
4144 do not specially operate on tetra quantities, so non-quad-aligned
4145 registers can hold quadword quantities (except %o4 and %i4 because
4146 they cross fixed registers). */
4148 /* This points to either the 32 bit or the 64 bit version. */
4149 const int *hard_regno_mode_classes;
4151 static const int hard_32bit_mode_classes[] = {
4152 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
4153 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
4154 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
4155 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
4157 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4158 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4159 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4160 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
4162 /* FP regs f32 to f63. Only the even numbered registers actually exist,
4163 and none can hold SFmode/SImode values. */
4164 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4165 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4166 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4167 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4170 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
4176 static const int hard_64bit_mode_classes[] = {
4177 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4178 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4179 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4180 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4182 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4183 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4184 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4185 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
4187 /* FP regs f32 to f63. Only the even numbered registers actually exist,
4188 and none can hold SFmode/SImode values. */
4189 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4190 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4191 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4192 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4195 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
4201 int sparc_mode_class [NUM_MACHINE_MODES];
4203 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
4206 sparc_init_modes (void)
4210 for (i = 0; i < NUM_MACHINE_MODES; i++)
4212 switch (GET_MODE_CLASS (i))
4215 case MODE_PARTIAL_INT:
4216 case MODE_COMPLEX_INT:
4217 if (GET_MODE_SIZE (i) <= 4)
4218 sparc_mode_class[i] = 1 << (int) S_MODE;
4219 else if (GET_MODE_SIZE (i) == 8)
4220 sparc_mode_class[i] = 1 << (int) D_MODE;
4221 else if (GET_MODE_SIZE (i) == 16)
4222 sparc_mode_class[i] = 1 << (int) T_MODE;
4223 else if (GET_MODE_SIZE (i) == 32)
4224 sparc_mode_class[i] = 1 << (int) O_MODE;
4226 sparc_mode_class[i] = 0;
4228 case MODE_VECTOR_INT:
4229 if (GET_MODE_SIZE (i) <= 4)
4230 sparc_mode_class[i] = 1 << (int)SF_MODE;
4231 else if (GET_MODE_SIZE (i) == 8)
4232 sparc_mode_class[i] = 1 << (int)DF_MODE;
4235 case MODE_COMPLEX_FLOAT:
4236 if (GET_MODE_SIZE (i) <= 4)
4237 sparc_mode_class[i] = 1 << (int) SF_MODE;
4238 else if (GET_MODE_SIZE (i) == 8)
4239 sparc_mode_class[i] = 1 << (int) DF_MODE;
4240 else if (GET_MODE_SIZE (i) == 16)
4241 sparc_mode_class[i] = 1 << (int) TF_MODE;
4242 else if (GET_MODE_SIZE (i) == 32)
4243 sparc_mode_class[i] = 1 << (int) OF_MODE;
4245 sparc_mode_class[i] = 0;
4248 if (i == (int) CCFPmode || i == (int) CCFPEmode)
4249 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
4251 sparc_mode_class[i] = 1 << (int) CC_MODE;
4254 sparc_mode_class[i] = 0;
4260 hard_regno_mode_classes = hard_64bit_mode_classes;
4262 hard_regno_mode_classes = hard_32bit_mode_classes;
4264 /* Initialize the array used by REGNO_REG_CLASS. */
4265 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4267 if (i < 16 && TARGET_V8PLUS)
4268 sparc_regno_reg_class[i] = I64_REGS;
4269 else if (i < 32 || i == FRAME_POINTER_REGNUM)
4270 sparc_regno_reg_class[i] = GENERAL_REGS;
4272 sparc_regno_reg_class[i] = FP_REGS;
4274 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
4276 sparc_regno_reg_class[i] = FPCC_REGS;
4278 sparc_regno_reg_class[i] = NO_REGS;
4282 /* Compute the frame size required by the function. This function is called
4283 during the reload pass and also by sparc_expand_prologue. */
4286 sparc_compute_frame_size (HOST_WIDE_INT size, int leaf_function_p)
4288 int outgoing_args_size = (current_function_outgoing_args_size
4289 + REG_PARM_STACK_SPACE (current_function_decl));
4290 int n_regs = 0; /* N_REGS is the number of 4-byte regs saved thus far. */
4295 for (i = 0; i < 8; i++)
4296 if (regs_ever_live[i] && ! call_used_regs[i])
4301 for (i = 0; i < 8; i += 2)
4302 if ((regs_ever_live[i] && ! call_used_regs[i])
4303 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
4307 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
4308 if ((regs_ever_live[i] && ! call_used_regs[i])
4309 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
4312 /* Set up values for use in prologue and epilogue. */
4313 num_gfregs = n_regs;
4318 && current_function_outgoing_args_size == 0)
4319 actual_fsize = apparent_fsize = 0;
4322 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
4323 apparent_fsize = (size - STARTING_FRAME_OFFSET + 7) & -8;
4324 apparent_fsize += n_regs * 4;
4325 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
4328 /* Make sure nothing can clobber our register windows.
4329 If a SAVE must be done, or there is a stack-local variable,
4330 the register window area must be allocated.
4331 ??? For v8 we apparently need an additional 8 bytes of reserved space. */
4332 if (! leaf_function_p || size > 0)
4333 actual_fsize += (16 * UNITS_PER_WORD) + (TARGET_ARCH64 ? 0 : 8);
4335 return SPARC_STACK_ALIGN (actual_fsize);
4338 /* Output any necessary .register pseudo-ops. */
4341 sparc_output_scratch_registers (FILE *file ATTRIBUTE_UNUSED)
4343 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
4349 /* Check if %g[2367] were used without
4350 .register being printed for them already. */
4351 for (i = 2; i < 8; i++)
4353 if (regs_ever_live [i]
4354 && ! sparc_hard_reg_printed [i])
4356 sparc_hard_reg_printed [i] = 1;
4357 fprintf (file, "\t.register\t%%g%d, #scratch\n", i);
4364 /* Save/restore call-saved registers from LOW to HIGH at BASE+OFFSET
4365 as needed. LOW should be double-word aligned for 32-bit registers.
4366 Return the new OFFSET. */
4369 #define SORR_RESTORE 1
4372 save_or_restore_regs (int low, int high, rtx base, int offset, int action)
4377 if (TARGET_ARCH64 && high <= 32)
4379 for (i = low; i < high; i++)
4381 if (regs_ever_live[i] && ! call_used_regs[i])
4383 mem = gen_rtx_MEM (DImode, plus_constant (base, offset));
4384 set_mem_alias_set (mem, sparc_sr_alias_set);
4385 if (action == SORR_SAVE)
4387 insn = emit_move_insn (mem, gen_rtx_REG (DImode, i));
4388 RTX_FRAME_RELATED_P (insn) = 1;
4390 else /* action == SORR_RESTORE */
4391 emit_move_insn (gen_rtx_REG (DImode, i), mem);
4398 for (i = low; i < high; i += 2)
4400 bool reg0 = regs_ever_live[i] && ! call_used_regs[i];
4401 bool reg1 = regs_ever_live[i+1] && ! call_used_regs[i+1];
4402 enum machine_mode mode;
4407 mode = i < 32 ? DImode : DFmode;
4412 mode = i < 32 ? SImode : SFmode;
4417 mode = i < 32 ? SImode : SFmode;
4424 mem = gen_rtx_MEM (mode, plus_constant (base, offset));
4425 set_mem_alias_set (mem, sparc_sr_alias_set);
4426 if (action == SORR_SAVE)
4428 insn = emit_move_insn (mem, gen_rtx_REG (mode, regno));
4429 RTX_FRAME_RELATED_P (insn) = 1;
4431 else /* action == SORR_RESTORE */
4432 emit_move_insn (gen_rtx_REG (mode, regno), mem);
4434 /* Always preserve double-word alignment. */
4435 offset = (offset + 7) & -8;
4442 /* Emit code to save call-saved registers. */
4445 emit_save_regs (void)
4447 HOST_WIDE_INT offset;
4450 offset = frame_base_offset - apparent_fsize;
4452 if (offset < -4096 || offset + num_gfregs * 4 > 4096)
4454 /* ??? This might be optimized a little as %g1 might already have a
4455 value close enough that a single add insn will do. */
4456 /* ??? Although, all of this is probably only a temporary fix
4457 because if %g1 can hold a function result, then
4458 sparc_expand_epilogue will lose (the result will be
4460 base = gen_rtx_REG (Pmode, 1);
4461 emit_move_insn (base, GEN_INT (offset));
4462 emit_insn (gen_rtx_SET (VOIDmode,
4464 gen_rtx_PLUS (Pmode, frame_base_reg, base)));
4468 base = frame_base_reg;
4470 offset = save_or_restore_regs (0, 8, base, offset, SORR_SAVE);
4471 save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, SORR_SAVE);
4474 /* Emit code to restore call-saved registers. */
4477 emit_restore_regs (void)
4479 HOST_WIDE_INT offset;
4482 offset = frame_base_offset - apparent_fsize;
4484 if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/)
4486 base = gen_rtx_REG (Pmode, 1);
4487 emit_move_insn (base, GEN_INT (offset));
4488 emit_insn (gen_rtx_SET (VOIDmode,
4490 gen_rtx_PLUS (Pmode, frame_base_reg, base)));
4494 base = frame_base_reg;
4496 offset = save_or_restore_regs (0, 8, base, offset, SORR_RESTORE);
4497 save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, SORR_RESTORE);
4500 /* Generate a save_register_window insn. */
4503 gen_save_register_window (rtx increment)
4506 return gen_save_register_windowdi (increment);
4508 return gen_save_register_windowsi (increment);
4511 /* Generate an increment for the stack pointer. */
4514 gen_stack_pointer_inc (rtx increment)
4517 return gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx, increment);
4519 return gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, increment);
4522 /* Generate a decrement for the stack pointer. */
4525 gen_stack_pointer_dec (rtx decrement)
4528 return gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, decrement);
4530 return gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, decrement);
4533 /* Expand the function prologue. The prologue is responsible for reserving
4534 storage for the frame, saving the call-saved registers and loading the
4535 PIC register if needed. */
4538 sparc_expand_prologue (void)
4543 /* Compute a snapshot of current_function_uses_only_leaf_regs. Relying
4544 on the final value of the flag means deferring the prologue/epilogue
4545 expansion until just before the second scheduling pass, which is too
4546 late to emit multiple epilogues or return insns.
4548 Of course we are making the assumption that the value of the flag
4549 will not change between now and its final value. Of the three parts
4550 of the formula, only the last one can reasonably vary. Let's take a
4551 closer look, after assuming that the first two ones are set to true
4552 (otherwise the last value is effectively silenced).
4554 If only_leaf_regs_used returns false, the global predicate will also
4555 be false so the actual frame size calculated below will be positive.
4556 As a consequence, the save_register_window insn will be emitted in
4557 the instruction stream; now this insn explicitly references %fp
4558 which is not a leaf register so only_leaf_regs_used will always
4559 return false subsequently.
4561 If only_leaf_regs_used returns true, we hope that the subsequent
4562 optimization passes won't cause non-leaf registers to pop up. For
4563 example, the regrename pass has special provisions to not rename to
4564 non-leaf registers in a leaf function. */
4565 sparc_leaf_function_p
4566 = optimize > 0 && leaf_function_p () && only_leaf_regs_used ();
4568 /* Need to use actual_fsize, since we are also allocating
4569 space for our callee (and our own register save area). */
4571 = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p);
4573 /* Advertise that the data calculated just above are now valid. */
4574 sparc_prologue_data_valid_p = true;
4576 if (sparc_leaf_function_p)
4578 frame_base_reg = stack_pointer_rtx;
4579 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
4583 frame_base_reg = hard_frame_pointer_rtx;
4584 frame_base_offset = SPARC_STACK_BIAS;
4587 if (actual_fsize == 0)
4589 else if (sparc_leaf_function_p)
4591 if (actual_fsize <= 4096)
4592 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-actual_fsize)));
4593 else if (actual_fsize <= 8192)
4595 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-4096)));
4596 /* %sp is still the CFA register. */
4597 RTX_FRAME_RELATED_P (insn) = 1;
4599 = emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize)));
4603 rtx reg = gen_rtx_REG (Pmode, 1);
4604 emit_move_insn (reg, GEN_INT (-actual_fsize));
4605 insn = emit_insn (gen_stack_pointer_inc (reg));
4607 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
4608 PATTERN (gen_stack_pointer_inc (GEN_INT (-actual_fsize))),
4612 RTX_FRAME_RELATED_P (insn) = 1;
4616 if (actual_fsize <= 4096)
4617 insn = emit_insn (gen_save_register_window (GEN_INT (-actual_fsize)));
4618 else if (actual_fsize <= 8192)
4620 insn = emit_insn (gen_save_register_window (GEN_INT (-4096)));
4621 /* %sp is not the CFA register anymore. */
4622 emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize)));
4626 rtx reg = gen_rtx_REG (Pmode, 1);
4627 emit_move_insn (reg, GEN_INT (-actual_fsize));
4628 insn = emit_insn (gen_save_register_window (reg));
4631 RTX_FRAME_RELATED_P (insn) = 1;
4632 for (i=0; i < XVECLEN (PATTERN (insn), 0); i++)
4633 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, i)) = 1;
4636 /* Call-saved registers are saved just above the outgoing argument area. */
4640 /* Load the PIC register if needed. */
4641 if (flag_pic && current_function_uses_pic_offset_table)
4642 load_pic_register ();
4645 /* This function generates the assembly code for function entry, which boils
4646 down to emitting the necessary .register directives.
4648 ??? Historical cruft: "On SPARC, move-double insns between fpu and cpu need
4649 an 8-byte block of memory. If any fpu reg is used in the function, we
4650 allocate such a block here, at the bottom of the frame, just in case it's
4651 needed." Could this explain the -8 in emit_restore_regs? */
4654 sparc_asm_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4656 /* Check that the assumption we made in sparc_expand_prologue is valid. */
4657 if (sparc_leaf_function_p != current_function_uses_only_leaf_regs)
4660 sparc_output_scratch_registers (file);
4663 /* Expand the function epilogue, either normal or part of a sibcall.
4664 We emit all the instructions except the return or the call. */
4667 sparc_expand_epilogue (void)
4670 emit_restore_regs ();
4672 if (actual_fsize == 0)
4674 else if (sparc_leaf_function_p)
4676 if (actual_fsize <= 4096)
4677 emit_insn (gen_stack_pointer_dec (GEN_INT (- actual_fsize)));
4678 else if (actual_fsize <= 8192)
4680 emit_insn (gen_stack_pointer_dec (GEN_INT (-4096)));
4681 emit_insn (gen_stack_pointer_dec (GEN_INT (4096 - actual_fsize)));
4685 rtx reg = gen_rtx_REG (Pmode, 1);
4686 emit_move_insn (reg, GEN_INT (-actual_fsize));
4687 emit_insn (gen_stack_pointer_dec (reg));
4692 /* Return true if it is appropriate to emit `return' instructions in the
4693 body of a function. */
4696 sparc_can_use_return_insn_p (void)
4698 return sparc_prologue_data_valid_p
4699 && (actual_fsize == 0 || !sparc_leaf_function_p);
4702 /* This function generates the assembly code for function exit. */
4705 sparc_asm_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4707 /* If code does not drop into the epilogue, we have to still output
4708 a dummy nop for the sake of sane backtraces. Otherwise, if the
4709 last two instructions of a function were "call foo; dslot;" this
4710 can make the return PC of foo (i.e. address of call instruction
4711 plus 8) point to the first instruction in the next function. */
4713 rtx insn, last_real_insn;
4715 insn = get_last_insn ();
4717 last_real_insn = prev_real_insn (insn);
4719 && GET_CODE (last_real_insn) == INSN
4720 && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE)
4721 last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0);
4723 if (last_real_insn && GET_CODE (last_real_insn) == CALL_INSN)
4724 fputs("\tnop\n", file);
4726 sparc_output_deferred_case_vectors ();
4729 /* Output a 'restore' instruction. */
4732 output_restore (rtx pat)
4738 fputs ("\t restore\n", asm_out_file);
4742 if (GET_CODE (pat) != SET)
4745 operands[0] = SET_DEST (pat);
4746 pat = SET_SRC (pat);
4748 switch (GET_CODE (pat))
4751 operands[1] = XEXP (pat, 0);
4752 operands[2] = XEXP (pat, 1);
4753 output_asm_insn (" restore %r1, %2, %Y0", operands);
4756 operands[1] = XEXP (pat, 0);
4757 operands[2] = XEXP (pat, 1);
4758 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
4761 operands[1] = XEXP (pat, 0);
4762 if (XEXP (pat, 1) != const1_rtx)
4764 output_asm_insn (" restore %r1, %r1, %Y0", operands);
4768 output_asm_insn (" restore %%g0, %1, %Y0", operands);
4773 /* Output a return. */
4776 output_return (rtx insn)
4778 if (sparc_leaf_function_p)
4780 /* This is a leaf function so we don't have to bother restoring the
4781 register window, which frees us from dealing with the convoluted
4782 semantics of restore/return. We simply output the jump to the
4783 return address and the insn in the delay slot (if any). */
4785 if (current_function_calls_eh_return)
4788 return "jmp\t%%o7+%)%#";
4792 /* This is a regular function so we have to restore the register window.
4793 We may have a pending insn for the delay slot, which will be either
4794 combined with the 'restore' instruction or put in the delay slot of
4795 the 'return' instruction. */
4797 if (current_function_calls_eh_return)
4799 /* If the function uses __builtin_eh_return, the eh_return
4800 machinery occupies the delay slot. */
4804 if (! flag_delayed_branch)
4805 fputs ("\tadd\t%fp, %g1, %fp\n", asm_out_file);
4808 fputs ("\treturn\t%i7+8\n", asm_out_file);
4810 fputs ("\trestore\n\tjmp\t%o7+8\n", asm_out_file);
4812 if (flag_delayed_branch)
4813 fputs ("\t add\t%sp, %g1, %sp\n", asm_out_file);
4815 fputs ("\t nop\n", asm_out_file);
4817 else if (final_sequence)
4821 delay = NEXT_INSN (insn);
4825 pat = PATTERN (delay);
4827 if (TARGET_V9 && ! epilogue_renumber (&pat, 1))
4829 epilogue_renumber (&pat, 0);
4830 return "return\t%%i7+%)%#";
4834 output_asm_insn ("jmp\t%%i7+%)", NULL);
4835 output_restore (pat);
4836 PATTERN (delay) = gen_blockage ();
4837 INSN_CODE (delay) = -1;
4842 /* The delay slot is empty. */
4844 return "return\t%%i7+%)\n\t nop";
4845 else if (flag_delayed_branch)
4846 return "jmp\t%%i7+%)\n\t restore";
4848 return "restore\n\tjmp\t%%o7+%)\n\t nop";
4855 /* Output a sibling call. */
4858 output_sibcall (rtx insn, rtx call_operand)
4862 if (! flag_delayed_branch)
4865 operands[0] = call_operand;
4867 if (sparc_leaf_function_p)
4869 /* This is a leaf function so we don't have to bother restoring the
4870 register window. We simply output the jump to the function and
4871 the insn in the delay slot (if any). */
4873 if (LEAF_SIBCALL_SLOT_RESERVED_P && final_sequence)
4877 output_asm_insn ("sethi\t%%hi(%a0), %%g1\n\tjmp\t%%g1 + %%lo(%a0)%#",
4880 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
4881 it into branch if possible. */
4882 output_asm_insn ("or\t%%o7, %%g0, %%g1\n\tcall\t%a0, 0\n\t or\t%%g1, %%g0, %%o7",
4887 /* This is a regular function so we have to restore the register window.
4888 We may have a pending insn for the delay slot, which will be combined
4889 with the 'restore' instruction. */
4891 output_asm_insn ("call\t%a0, 0", operands);
4895 rtx delay = NEXT_INSN (insn);
4899 output_restore (PATTERN (delay));
4901 PATTERN (delay) = gen_blockage ();
4902 INSN_CODE (delay) = -1;
4905 output_restore (NULL_RTX);
4911 /* Functions for handling argument passing.
4913 For 32-bit, the first 6 args are normally in registers and the rest are
4914 pushed. Any arg that starts within the first 6 words is at least
4915 partially passed in a register unless its data type forbids.
4917 For 64-bit, the argument registers are laid out as an array of 16 elements
4918 and arguments are added sequentially. The first 6 int args and up to the
4919 first 16 fp args (depending on size) are passed in regs.
4921 Slot Stack Integral Float Float in structure Double Long Double
4922 ---- ----- -------- ----- ------------------ ------ -----------
4923 15 [SP+248] %f31 %f30,%f31 %d30
4924 14 [SP+240] %f29 %f28,%f29 %d28 %q28
4925 13 [SP+232] %f27 %f26,%f27 %d26
4926 12 [SP+224] %f25 %f24,%f25 %d24 %q24
4927 11 [SP+216] %f23 %f22,%f23 %d22
4928 10 [SP+208] %f21 %f20,%f21 %d20 %q20
4929 9 [SP+200] %f19 %f18,%f19 %d18
4930 8 [SP+192] %f17 %f16,%f17 %d16 %q16
4931 7 [SP+184] %f15 %f14,%f15 %d14
4932 6 [SP+176] %f13 %f12,%f13 %d12 %q12
4933 5 [SP+168] %o5 %f11 %f10,%f11 %d10
4934 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
4935 3 [SP+152] %o3 %f7 %f6,%f7 %d6
4936 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
4937 1 [SP+136] %o1 %f3 %f2,%f3 %d2
4938 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
4940 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
4942 Integral arguments are always passed as 64-bit quantities appropriately
4945 Passing of floating point values is handled as follows.
4946 If a prototype is in scope:
4947 If the value is in a named argument (i.e. not a stdarg function or a
4948 value not part of the `...') then the value is passed in the appropriate
4950 If the value is part of the `...' and is passed in one of the first 6
4951 slots then the value is passed in the appropriate int reg.
4952 If the value is part of the `...' and is not passed in one of the first 6
4953 slots then the value is passed in memory.
4954 If a prototype is not in scope:
4955 If the value is one of the first 6 arguments the value is passed in the
4956 appropriate integer reg and the appropriate fp reg.
4957 If the value is not one of the first 6 arguments the value is passed in
4958 the appropriate fp reg and in memory.
4961 Summary of the calling conventions implemented by GCC on SPARC:
4964 size argument return value
4966 small integer <4 int. reg. int. reg.
4967 word 4 int. reg. int. reg.
4968 double word 8 int. reg. int. reg.
4970 _Complex small integer <8 int. reg. int. reg.
4971 _Complex word 8 int. reg. int. reg.
4972 _Complex double word 16 memory int. reg.
4974 vector integer <=8 int. reg. FP reg.
4975 vector integer >8 memory memory
4977 float 4 int. reg. FP reg.
4978 double 8 int. reg. FP reg.
4979 long double 16 memory memory
4981 _Complex float 8 memory FP reg.
4982 _Complex double 16 memory FP reg.
4983 _Complex long double 32 memory FP reg.
4985 vector float any memory memory
4987 aggregate any memory memory
4992 size argument return value
4994 small integer <8 int. reg. int. reg.
4995 word 8 int. reg. int. reg.
4996 double word 16 int. reg. int. reg.
4998 _Complex small integer <16 int. reg. int. reg.
4999 _Complex word 16 int. reg. int. reg.
5000 _Complex double word 32 memory int. reg.
5002 vector integer <=16 FP reg. FP reg.
5003 vector integer 16<s<=32 memory FP reg.
5004 vector integer >32 memory memory
5006 float 4 FP reg. FP reg.
5007 double 8 FP reg. FP reg.
5008 long double 16 FP reg. FP reg.
5010 _Complex float 8 FP reg. FP reg.
5011 _Complex double 16 FP reg. FP reg.
5012 _Complex long double 32 memory FP reg.
5014 vector float <=16 FP reg. FP reg.
5015 vector float 16<s<=32 memory FP reg.
5016 vector float >32 memory memory
5018 aggregate <=16 reg. reg.
5019 aggregate 16<s<=32 memory reg.
5020 aggregate >32 memory memory
5024 Note #1: complex floating-point types follow the extended SPARC ABIs as
5025 implemented by the Sun compiler.
5027 Note #2: integral vector types follow the scalar floating-point types
5028 conventions to match what is implemented by the Sun VIS SDK.
5030 Note #3: floating-point vector types follow the aggregate types
5034 /* Maximum number of int regs for args. */
5035 #define SPARC_INT_ARG_MAX 6
5036 /* Maximum number of fp regs for args. */
5037 #define SPARC_FP_ARG_MAX 16
5039 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
5041 /* Handle the INIT_CUMULATIVE_ARGS macro.
5042 Initialize a variable CUM of type CUMULATIVE_ARGS
5043 for a call to a function whose data type is FNTYPE.
5044 For a library call, FNTYPE is 0. */
5047 init_cumulative_args (struct sparc_args *cum, tree fntype,
5048 rtx libname ATTRIBUTE_UNUSED,
5049 tree fndecl ATTRIBUTE_UNUSED)
5052 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
5053 cum->libcall_p = fntype == 0;
5056 /* Handle the TARGET_PROMOTE_PROTOTYPES target hook.
5057 When a prototype says `char' or `short', really pass an `int'. */
5060 sparc_promote_prototypes (tree fntype ATTRIBUTE_UNUSED)
5062 return TARGET_ARCH32 ? true : false;
5065 /* Handle the TARGET_STRICT_ARGUMENT_NAMING target hook. */
5068 sparc_strict_argument_naming (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED)
5070 return TARGET_ARCH64 ? true : false;
5073 /* Scan the record type TYPE and return the following predicates:
5074 - INTREGS_P: the record contains at least one field or sub-field
5075 that is eligible for promotion in integer registers.
5076 - FP_REGS_P: the record contains at least one field or sub-field
5077 that is eligible for promotion in floating-point registers.
5078 - PACKED_P: the record contains at least one field that is packed.
5080 Sub-fields are not taken into account for the PACKED_P predicate. */
5083 scan_record_type (tree type, int *intregs_p, int *fpregs_p, int *packed_p)
5087 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5089 if (TREE_CODE (field) == FIELD_DECL)
5091 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
5092 scan_record_type (TREE_TYPE (field), intregs_p, fpregs_p, 0);
5093 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
5094 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
5100 if (packed_p && DECL_PACKED (field))
5106 /* Compute the slot number to pass an argument in.
5107 Return the slot number or -1 if passing on the stack.
5109 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5110 the preceding args and about the function being called.
5111 MODE is the argument's machine mode.
5112 TYPE is the data type of the argument (as a tree).
5113 This is null for libcalls where that information may
5115 NAMED is nonzero if this argument is a named parameter
5116 (otherwise it is an extra parameter matching an ellipsis).
5117 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
5118 *PREGNO records the register number to use if scalar type.
5119 *PPADDING records the amount of padding needed in words. */
5122 function_arg_slotno (const struct sparc_args *cum, enum machine_mode mode,
5123 tree type, int named, int incoming_p,
5124 int *pregno, int *ppadding)
5126 int regbase = (incoming_p
5127 ? SPARC_INCOMING_INT_ARG_FIRST
5128 : SPARC_OUTGOING_INT_ARG_FIRST);
5129 int slotno = cum->words;
5130 enum mode_class mclass;
5135 if (type && TREE_ADDRESSABLE (type))
5141 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
5144 /* For SPARC64, objects requiring 16-byte alignment get it. */
5146 && GET_MODE_ALIGNMENT (mode) >= 2 * BITS_PER_WORD
5147 && (slotno & 1) != 0)
5148 slotno++, *ppadding = 1;
5150 mclass = GET_MODE_CLASS (mode);
5151 if (type && TREE_CODE (type) == VECTOR_TYPE)
5153 /* Vector types deserve special treatment because they are
5154 polymorphic wrt their mode, depending upon whether VIS
5155 instructions are enabled. */
5156 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
5158 /* The SPARC port defines no floating-point vector modes. */
5159 if (mode != BLKmode)
5164 /* Integral vector types should either have a vector
5165 mode or an integral mode, because we are guaranteed
5166 by pass_by_reference that their size is not greater
5167 than 16 bytes and TImode is 16-byte wide. */
5168 if (mode == BLKmode)
5171 /* Vector integers are handled like floats according to
5173 mclass = MODE_FLOAT;
5180 case MODE_COMPLEX_FLOAT:
5181 if (TARGET_ARCH64 && TARGET_FPU && named)
5183 if (slotno >= SPARC_FP_ARG_MAX)
5185 regno = SPARC_FP_ARG_FIRST + slotno * 2;
5186 /* Arguments filling only one single FP register are
5187 right-justified in the outer double FP register. */
5188 if (GET_MODE_SIZE (mode) <= 4)
5195 case MODE_COMPLEX_INT:
5196 if (slotno >= SPARC_INT_ARG_MAX)
5198 regno = regbase + slotno;
5202 if (mode == VOIDmode)
5203 /* MODE is VOIDmode when generating the actual call. */
5206 if (mode != BLKmode)
5209 /* For SPARC64, objects requiring 16-byte alignment get it. */
5212 && TYPE_ALIGN (type) >= 2 * BITS_PER_WORD
5213 && (slotno & 1) != 0)
5214 slotno++, *ppadding = 1;
5216 if (TARGET_ARCH32 || !type || (TREE_CODE (type) == UNION_TYPE))
5218 if (slotno >= SPARC_INT_ARG_MAX)
5220 regno = regbase + slotno;
5222 else /* TARGET_ARCH64 && type */
5224 int intregs_p = 0, fpregs_p = 0, packed_p = 0;
5226 /* First see what kinds of registers we would need. */
5227 if (TREE_CODE (type) == VECTOR_TYPE)
5230 scan_record_type (type, &intregs_p, &fpregs_p, &packed_p);
5232 /* The ABI obviously doesn't specify how packed structures
5233 are passed. These are defined to be passed in int regs
5234 if possible, otherwise memory. */
5235 if (packed_p || !named)
5236 fpregs_p = 0, intregs_p = 1;
5238 /* If all arg slots are filled, then must pass on stack. */
5239 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
5242 /* If there are only int args and all int arg slots are filled,
5243 then must pass on stack. */
5244 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
5247 /* Note that even if all int arg slots are filled, fp members may
5248 still be passed in regs if such regs are available.
5249 *PREGNO isn't set because there may be more than one, it's up
5250 to the caller to compute them. */
5263 /* Handle recursive register counting for structure field layout. */
5265 struct function_arg_record_value_parms
5267 rtx ret; /* return expression being built. */
5268 int slotno; /* slot number of the argument. */
5269 int named; /* whether the argument is named. */
5270 int regbase; /* regno of the base register. */
5271 int stack; /* 1 if part of the argument is on the stack. */
5272 int intoffset; /* offset of the first pending integer field. */
5273 unsigned int nregs; /* number of words passed in registers. */
5276 static void function_arg_record_value_3
5277 (HOST_WIDE_INT, struct function_arg_record_value_parms *);
5278 static void function_arg_record_value_2
5279 (tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
5280 static void function_arg_record_value_1
5281 (tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
5282 static rtx function_arg_record_value (tree, enum machine_mode, int, int, int);
5283 static rtx function_arg_union_value (int, enum machine_mode, int, int);
5285 /* A subroutine of function_arg_record_value. Traverse the structure
5286 recursively and determine how many registers will be required. */
5289 function_arg_record_value_1 (tree type, HOST_WIDE_INT startbitpos,
5290 struct function_arg_record_value_parms *parms,
5295 /* We need to compute how many registers are needed so we can
5296 allocate the PARALLEL but before we can do that we need to know
5297 whether there are any packed fields. The ABI obviously doesn't
5298 specify how structures are passed in this case, so they are
5299 defined to be passed in int regs if possible, otherwise memory,
5300 regardless of whether there are fp values present. */
5303 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5305 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
5312 /* Compute how many registers we need. */
5313 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5315 if (TREE_CODE (field) == FIELD_DECL)
5317 HOST_WIDE_INT bitpos = startbitpos;
5319 if (DECL_SIZE (field) != 0)
5321 if (integer_zerop (DECL_SIZE (field)))
5324 if (host_integerp (bit_position (field), 1))
5325 bitpos += int_bit_position (field);
5328 /* ??? FIXME: else assume zero offset. */
5330 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
5331 function_arg_record_value_1 (TREE_TYPE (field),
5335 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
5336 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
5341 if (parms->intoffset != -1)
5343 unsigned int startbit, endbit;
5344 int intslots, this_slotno;
5346 startbit = parms->intoffset & -BITS_PER_WORD;
5347 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
5349 intslots = (endbit - startbit) / BITS_PER_WORD;
5350 this_slotno = parms->slotno + parms->intoffset
5353 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
5355 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
5356 /* We need to pass this field on the stack. */
5360 parms->nregs += intslots;
5361 parms->intoffset = -1;
5364 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
5365 If it wasn't true we wouldn't be here. */
5366 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
5367 && DECL_MODE (field) == BLKmode)
5368 parms->nregs += TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
5369 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
5376 if (parms->intoffset == -1)
5377 parms->intoffset = bitpos;
5383 /* A subroutine of function_arg_record_value. Assign the bits of the
5384 structure between parms->intoffset and bitpos to integer registers. */
5387 function_arg_record_value_3 (HOST_WIDE_INT bitpos,
5388 struct function_arg_record_value_parms *parms)
5390 enum machine_mode mode;
5392 unsigned int startbit, endbit;
5393 int this_slotno, intslots, intoffset;
5396 if (parms->intoffset == -1)
5399 intoffset = parms->intoffset;
5400 parms->intoffset = -1;
5402 startbit = intoffset & -BITS_PER_WORD;
5403 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
5404 intslots = (endbit - startbit) / BITS_PER_WORD;
5405 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
5407 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
5411 /* If this is the trailing part of a word, only load that much into
5412 the register. Otherwise load the whole register. Note that in
5413 the latter case we may pick up unwanted bits. It's not a problem
5414 at the moment but may wish to revisit. */
5416 if (intoffset % BITS_PER_WORD != 0)
5417 mode = smallest_mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
5422 intoffset /= BITS_PER_UNIT;
5425 regno = parms->regbase + this_slotno;
5426 reg = gen_rtx_REG (mode, regno);
5427 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
5428 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
5431 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
5436 while (intslots > 0);
5439 /* A subroutine of function_arg_record_value. Traverse the structure
5440 recursively and assign bits to floating point registers. Track which
5441 bits in between need integer registers; invoke function_arg_record_value_3
5442 to make that happen. */
5445 function_arg_record_value_2 (tree type, HOST_WIDE_INT startbitpos,
5446 struct function_arg_record_value_parms *parms,
5452 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5454 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
5461 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5463 if (TREE_CODE (field) == FIELD_DECL)
5465 HOST_WIDE_INT bitpos = startbitpos;
5467 if (DECL_SIZE (field) != 0)
5469 if (integer_zerop (DECL_SIZE (field)))
5472 if (host_integerp (bit_position (field), 1))
5473 bitpos += int_bit_position (field);
5476 /* ??? FIXME: else assume zero offset. */
5478 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
5479 function_arg_record_value_2 (TREE_TYPE (field),
5483 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
5484 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
5489 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
5490 int regno, nregs, pos;
5491 enum machine_mode mode = DECL_MODE (field);
5494 function_arg_record_value_3 (bitpos, parms);
5496 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
5499 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
5500 nregs = TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
5502 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
5504 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
5510 regno = SPARC_FP_ARG_FIRST + this_slotno * 2;
5511 if (GET_MODE_SIZE (mode) <= 4 && (bitpos & 32) != 0)
5513 reg = gen_rtx_REG (mode, regno);
5514 pos = bitpos / BITS_PER_UNIT;
5515 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
5516 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
5520 regno += GET_MODE_SIZE (mode) / 4;
5521 reg = gen_rtx_REG (mode, regno);
5522 pos += GET_MODE_SIZE (mode);
5523 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
5524 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
5530 if (parms->intoffset == -1)
5531 parms->intoffset = bitpos;
5537 /* Used by function_arg and function_value to implement the complex
5538 conventions of the 64-bit ABI for passing and returning structures.
5539 Return an expression valid as a return value for the two macros
5540 FUNCTION_ARG and FUNCTION_VALUE.
5542 TYPE is the data type of the argument (as a tree).
5543 This is null for libcalls where that information may
5545 MODE is the argument's machine mode.
5546 SLOTNO is the index number of the argument's slot in the parameter array.
5547 NAMED is nonzero if this argument is a named parameter
5548 (otherwise it is an extra parameter matching an ellipsis).
5549 REGBASE is the regno of the base register for the parameter array. */
5552 function_arg_record_value (tree type, enum machine_mode mode,
5553 int slotno, int named, int regbase)
5555 HOST_WIDE_INT typesize = int_size_in_bytes (type);
5556 struct function_arg_record_value_parms parms;
5559 parms.ret = NULL_RTX;
5560 parms.slotno = slotno;
5561 parms.named = named;
5562 parms.regbase = regbase;
5565 /* Compute how many registers we need. */
5567 parms.intoffset = 0;
5568 function_arg_record_value_1 (type, 0, &parms, false);
5570 /* Take into account pending integer fields. */
5571 if (parms.intoffset != -1)
5573 unsigned int startbit, endbit;
5574 int intslots, this_slotno;
5576 startbit = parms.intoffset & -BITS_PER_WORD;
5577 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
5578 intslots = (endbit - startbit) / BITS_PER_WORD;
5579 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
5581 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
5583 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
5584 /* We need to pass this field on the stack. */
5588 parms.nregs += intslots;
5590 nregs = parms.nregs;
5592 /* Allocate the vector and handle some annoying special cases. */
5595 /* ??? Empty structure has no value? Duh? */
5598 /* Though there's nothing really to store, return a word register
5599 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
5600 leads to breakage due to the fact that there are zero bytes to
5602 return gen_rtx_REG (mode, regbase);
5606 /* ??? C++ has structures with no fields, and yet a size. Give up
5607 for now and pass everything back in integer registers. */
5608 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5610 if (nregs + slotno > SPARC_INT_ARG_MAX)
5611 nregs = SPARC_INT_ARG_MAX - slotno;
5616 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (parms.stack + nregs));
5618 /* If at least one field must be passed on the stack, generate
5619 (parallel [(expr_list (nil) ...) ...]) so that all fields will
5620 also be passed on the stack. We can't do much better because the
5621 semantics of TARGET_ARG_PARTIAL_BYTES doesn't handle the case
5622 of structures for which the fields passed exclusively in registers
5623 are not at the beginning of the structure. */
5625 XVECEXP (parms.ret, 0, 0)
5626 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
5628 /* Fill in the entries. */
5630 parms.intoffset = 0;
5631 function_arg_record_value_2 (type, 0, &parms, false);
5632 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
5634 if (parms.nregs != nregs)
5640 /* Used by function_arg and function_value to implement the conventions
5641 of the 64-bit ABI for passing and returning unions.
5642 Return an expression valid as a return value for the two macros
5643 FUNCTION_ARG and FUNCTION_VALUE.
5645 SIZE is the size in bytes of the union.
5646 MODE is the argument's machine mode.
5647 REGNO is the hard register the union will be passed in. */
5650 function_arg_union_value (int size, enum machine_mode mode, int slotno,
5653 int nwords = ROUND_ADVANCE (size), i;
5656 /* See comment in previous function for empty structures. */
5658 return gen_rtx_REG (mode, regno);
5660 if (slotno == SPARC_INT_ARG_MAX - 1)
5663 regs = gen_rtx_PARALLEL (mode, rtvec_alloc (nwords));
5665 for (i = 0; i < nwords; i++)
5667 /* Unions are passed left-justified. */
5668 XVECEXP (regs, 0, i)
5669 = gen_rtx_EXPR_LIST (VOIDmode,
5670 gen_rtx_REG (word_mode, regno),
5671 GEN_INT (UNITS_PER_WORD * i));
5678 /* Used by function_arg and function_value to implement the conventions
5679 for passing and returning large (BLKmode) vectors.
5680 Return an expression valid as a return value for the two macros
5681 FUNCTION_ARG and FUNCTION_VALUE.
5683 SIZE is the size in bytes of the vector.
5684 BASE_MODE is the argument's base machine mode.
5685 REGNO is the FP hard register the vector will be passed in. */
5688 function_arg_vector_value (int size, enum machine_mode base_mode, int regno)
5690 unsigned short base_mode_size = GET_MODE_SIZE (base_mode);
5691 int nregs = size / base_mode_size, i;
5694 regs = gen_rtx_PARALLEL (BLKmode, rtvec_alloc (nregs));
5696 for (i = 0; i < nregs; i++)
5698 XVECEXP (regs, 0, i)
5699 = gen_rtx_EXPR_LIST (VOIDmode,
5700 gen_rtx_REG (base_mode, regno),
5701 GEN_INT (base_mode_size * i));
5702 regno += base_mode_size / 4;
5708 /* Handle the FUNCTION_ARG macro.
5709 Determine where to put an argument to a function.
5710 Value is zero to push the argument on the stack,
5711 or a hard register in which to store the argument.
5713 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5714 the preceding args and about the function being called.
5715 MODE is the argument's machine mode.
5716 TYPE is the data type of the argument (as a tree).
5717 This is null for libcalls where that information may
5719 NAMED is nonzero if this argument is a named parameter
5720 (otherwise it is an extra parameter matching an ellipsis).
5721 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
5724 function_arg (const struct sparc_args *cum, enum machine_mode mode,
5725 tree type, int named, int incoming_p)
5727 int regbase = (incoming_p
5728 ? SPARC_INCOMING_INT_ARG_FIRST
5729 : SPARC_OUTGOING_INT_ARG_FIRST);
5730 int slotno, regno, padding;
5731 enum mode_class mclass = GET_MODE_CLASS (mode);
5734 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
5742 reg = gen_rtx_REG (mode, regno);
5746 if (type && TREE_CODE (type) == RECORD_TYPE)
5748 /* Structures up to 16 bytes in size are passed in arg slots on the
5749 stack and are promoted to registers where possible. */
5751 if (int_size_in_bytes (type) > 16)
5752 abort (); /* shouldn't get here */
5754 return function_arg_record_value (type, mode, slotno, named, regbase);
5756 else if (type && TREE_CODE (type) == UNION_TYPE)
5758 HOST_WIDE_INT size = int_size_in_bytes (type);
5761 abort (); /* shouldn't get here */
5763 return function_arg_union_value (size, mode, slotno, regno);
5765 else if (type && TREE_CODE (type) == VECTOR_TYPE)
5767 /* Vector types deserve special treatment because they are
5768 polymorphic wrt their mode, depending upon whether VIS
5769 instructions are enabled. */
5770 HOST_WIDE_INT size = int_size_in_bytes (type);
5773 abort (); /* shouldn't get here */
5775 if (mode == BLKmode)
5776 return function_arg_vector_value (size,
5777 TYPE_MODE (TREE_TYPE (type)),
5778 SPARC_FP_ARG_FIRST + 2*slotno);
5780 mclass = MODE_FLOAT;
5783 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
5784 but also have the slot allocated for them.
5785 If no prototype is in scope fp values in register slots get passed
5786 in two places, either fp regs and int regs or fp regs and memory. */
5787 if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
5788 && SPARC_FP_REG_P (regno))
5790 reg = gen_rtx_REG (mode, regno);
5791 if (cum->prototype_p || cum->libcall_p)
5793 /* "* 2" because fp reg numbers are recorded in 4 byte
5796 /* ??? This will cause the value to be passed in the fp reg and
5797 in the stack. When a prototype exists we want to pass the
5798 value in the reg but reserve space on the stack. That's an
5799 optimization, and is deferred [for a bit]. */
5800 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
5801 return gen_rtx_PARALLEL (mode,
5803 gen_rtx_EXPR_LIST (VOIDmode,
5804 NULL_RTX, const0_rtx),
5805 gen_rtx_EXPR_LIST (VOIDmode,
5809 /* ??? It seems that passing back a register even when past
5810 the area declared by REG_PARM_STACK_SPACE will allocate
5811 space appropriately, and will not copy the data onto the
5812 stack, exactly as we desire.
5814 This is due to locate_and_pad_parm being called in
5815 expand_call whenever reg_parm_stack_space > 0, which
5816 while beneficial to our example here, would seem to be
5817 in error from what had been intended. Ho hum... -- r~ */
5825 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
5829 /* On incoming, we don't need to know that the value
5830 is passed in %f0 and %i0, and it confuses other parts
5831 causing needless spillage even on the simplest cases. */
5835 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
5836 + (regno - SPARC_FP_ARG_FIRST) / 2);
5838 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5839 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
5841 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5845 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
5846 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5847 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5853 /* Scalar or complex int. */
5854 reg = gen_rtx_REG (mode, regno);
5860 /* For an arg passed partly in registers and partly in memory,
5861 this is the number of bytes of registers used.
5862 For args passed entirely in registers or entirely in memory, zero.
5864 Any arg that starts in the first 6 regs but won't entirely fit in them
5865 needs partial registers on v8. On v9, structures with integer
5866 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
5867 values that begin in the last fp reg [where "last fp reg" varies with the
5868 mode] will be split between that reg and memory. */
5871 sparc_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5872 tree type, bool named)
5874 int slotno, regno, padding;
5876 /* We pass 0 for incoming_p here, it doesn't matter. */
5877 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5884 if ((slotno + (mode == BLKmode
5885 ? ROUND_ADVANCE (int_size_in_bytes (type))
5886 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
5887 > SPARC_INT_ARG_MAX)
5888 return (SPARC_INT_ARG_MAX - slotno) * UNITS_PER_WORD;
5892 /* We are guaranteed by pass_by_reference that the size of the
5893 argument is not greater than 16 bytes, so we only need to return
5894 one word if the argument is partially passed in registers. */
5896 if (type && AGGREGATE_TYPE_P (type))
5898 int size = int_size_in_bytes (type);
5900 if (size > UNITS_PER_WORD
5901 && slotno == SPARC_INT_ARG_MAX - 1)
5902 return UNITS_PER_WORD;
5904 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
5905 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5906 && ! (TARGET_FPU && named)))
5908 /* The complex types are passed as packed types. */
5909 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
5910 && slotno == SPARC_INT_ARG_MAX - 1)
5911 return UNITS_PER_WORD;
5913 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
5915 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
5917 return UNITS_PER_WORD;
5924 /* Handle the TARGET_PASS_BY_REFERENCE target hook.
5925 Specify whether to pass the argument by reference. */
5928 sparc_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5929 enum machine_mode mode, tree type,
5930 bool named ATTRIBUTE_UNUSED)
5934 /* Original SPARC 32-bit ABI says that structures and unions,
5935 and quad-precision floats are passed by reference. For Pascal,
5936 also pass arrays by reference. All other base types are passed
5939 Extended ABI (as implemented by the Sun compiler) says that all
5940 complex floats are passed by reference. Pass complex integers
5941 in registers up to 8 bytes. More generally, enforce the 2-word
5942 cap for passing arguments in registers.
5944 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5945 integers are passed like floats of the same size, that is in
5946 registers up to 8 bytes. Pass all vector floats by reference
5947 like structure and unions. */
5948 return ((type && (AGGREGATE_TYPE_P (type) || VECTOR_FLOAT_TYPE_P (type)))
5950 /* Catch CDImode, TFmode, DCmode and TCmode. */
5951 || GET_MODE_SIZE (mode) > 8
5953 && TREE_CODE (type) == VECTOR_TYPE
5954 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
5958 /* Original SPARC 64-bit ABI says that structures and unions
5959 smaller than 16 bytes are passed in registers, as well as
5960 all other base types. For Pascal, pass arrays by reference.
5962 Extended ABI (as implemented by the Sun compiler) says that
5963 complex floats are passed in registers up to 16 bytes. Pass
5964 all complex integers in registers up to 16 bytes. More generally,
5965 enforce the 2-word cap for passing arguments in registers.
5967 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5968 integers are passed like floats of the same size, that is in
5969 registers (up to 16 bytes). Pass all vector floats like structure
5971 return ((type && TREE_CODE (type) == ARRAY_TYPE)
5973 && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == VECTOR_TYPE)
5974 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16)
5975 /* Catch CTImode and TCmode. */
5976 || GET_MODE_SIZE (mode) > 16);
5980 /* Handle the FUNCTION_ARG_ADVANCE macro.
5981 Update the data in CUM to advance over an argument
5982 of mode MODE and data type TYPE.
5983 TYPE is null for libcalls where that information may not be available. */
5986 function_arg_advance (struct sparc_args *cum, enum machine_mode mode,
5987 tree type, int named)
5989 int slotno, regno, padding;
5991 /* We pass 0 for incoming_p here, it doesn't matter. */
5992 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5994 /* If register required leading padding, add it. */
5996 cum->words += padding;
6000 cum->words += (mode != BLKmode
6001 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
6002 : ROUND_ADVANCE (int_size_in_bytes (type)));
6006 if (type && AGGREGATE_TYPE_P (type))
6008 int size = int_size_in_bytes (type);
6012 else if (size <= 16)
6014 else /* passed by reference */
6019 cum->words += (mode != BLKmode
6020 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
6021 : ROUND_ADVANCE (int_size_in_bytes (type)));
6026 /* Handle the FUNCTION_ARG_PADDING macro.
6027 For the 64 bit ABI structs are always stored left shifted in their
6031 function_arg_padding (enum machine_mode mode, tree type)
6033 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
6036 /* Fall back to the default. */
6037 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
6040 /* Handle the TARGET_RETURN_IN_MEMORY target hook.
6041 Specify whether to return the return value in memory. */
6044 sparc_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
6047 /* Original SPARC 32-bit ABI says that structures and unions,
6048 and quad-precision floats are returned in memory. All other
6049 base types are returned in registers.
6051 Extended ABI (as implemented by the Sun compiler) says that
6052 all complex floats are returned in registers (8 FP registers
6053 at most for '_Complex long double'). Return all complex integers
6054 in registers (4 at most for '_Complex long long').
6056 Vector ABI (as implemented by the Sun VIS SDK) says that vector
6057 integers are returned like floats of the same size, that is in
6058 registers up to 8 bytes and in memory otherwise. Return all
6059 vector floats in memory like structure and unions; note that
6060 they always have BLKmode like the latter. */
6061 return (TYPE_MODE (type) == BLKmode
6062 || TYPE_MODE (type) == TFmode
6063 || (TREE_CODE (type) == VECTOR_TYPE
6064 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
6066 /* Original SPARC 64-bit ABI says that structures and unions
6067 smaller than 32 bytes are returned in registers, as well as
6068 all other base types.
6070 Extended ABI (as implemented by the Sun compiler) says that all
6071 complex floats are returned in registers (8 FP registers at most
6072 for '_Complex long double'). Return all complex integers in
6073 registers (4 at most for '_Complex TItype').
6075 Vector ABI (as implemented by the Sun VIS SDK) says that vector
6076 integers are returned like floats of the same size, that is in
6077 registers. Return all vector floats like structure and unions;
6078 note that they always have BLKmode like the latter. */
6079 return ((TYPE_MODE (type) == BLKmode
6080 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 32));
6083 /* Handle the TARGET_STRUCT_VALUE target hook.
6084 Return where to find the structure return value address. */
6087 sparc_struct_value_rtx (tree fndecl ATTRIBUTE_UNUSED, int incoming)
6096 mem = gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx,
6097 STRUCT_VALUE_OFFSET));
6099 mem = gen_rtx_MEM (Pmode, plus_constant (stack_pointer_rtx,
6100 STRUCT_VALUE_OFFSET));
6102 set_mem_alias_set (mem, struct_value_alias_set);
6107 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
6108 For v9, function return values are subject to the same rules as arguments,
6109 except that up to 32 bytes may be returned in registers. */
6112 function_value (tree type, enum machine_mode mode, int incoming_p)
6114 /* Beware that the two values are swapped here wrt function_arg. */
6115 int regbase = (incoming_p
6116 ? SPARC_OUTGOING_INT_ARG_FIRST
6117 : SPARC_INCOMING_INT_ARG_FIRST);
6118 enum mode_class mclass = GET_MODE_CLASS (mode);
6121 if (type && TREE_CODE (type) == VECTOR_TYPE)
6123 /* Vector types deserve special treatment because they are
6124 polymorphic wrt their mode, depending upon whether VIS
6125 instructions are enabled. */
6126 HOST_WIDE_INT size = int_size_in_bytes (type);
6128 if ((TARGET_ARCH32 && size > 8) || (TARGET_ARCH64 && size > 32))
6129 abort (); /* shouldn't get here */
6131 if (mode == BLKmode)
6132 return function_arg_vector_value (size,
6133 TYPE_MODE (TREE_TYPE (type)),
6134 SPARC_FP_ARG_FIRST);
6136 mclass = MODE_FLOAT;
6138 else if (type && TARGET_ARCH64)
6140 if (TREE_CODE (type) == RECORD_TYPE)
6142 /* Structures up to 32 bytes in size are passed in registers,
6143 promoted to fp registers where possible. */
6145 if (int_size_in_bytes (type) > 32)
6146 abort (); /* shouldn't get here */
6148 return function_arg_record_value (type, mode, 0, 1, regbase);
6150 else if (TREE_CODE (type) == UNION_TYPE)
6152 HOST_WIDE_INT size = int_size_in_bytes (type);
6155 abort (); /* shouldn't get here */
6157 return function_arg_union_value (size, mode, 0, regbase);
6159 else if (AGGREGATE_TYPE_P (type))
6161 /* All other aggregate types are passed in an integer register
6162 in a mode corresponding to the size of the type. */
6163 HOST_WIDE_INT bytes = int_size_in_bytes (type);
6166 abort (); /* shouldn't get here */
6168 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
6170 /* ??? We probably should have made the same ABI change in
6171 3.4.0 as the one we made for unions. The latter was
6172 required by the SCD though, while the former is not
6173 specified, so we favored compatibility and efficiency.
6175 Now we're stuck for aggregates larger than 16 bytes,
6176 because OImode vanished in the meantime. Let's not
6177 try to be unduly clever, and simply follow the ABI
6178 for unions in that case. */
6179 if (mode == BLKmode)
6180 return function_arg_union_value (bytes, mode, 0, regbase);
6184 else if (mclass == MODE_INT
6185 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
6189 if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
6191 regno = SPARC_FP_ARG_FIRST;
6195 return gen_rtx_REG (mode, regno);
6198 /* Do what is necessary for `va_start'. We look at the current function
6199 to determine if stdarg or varargs is used and return the address of
6200 the first unnamed parameter. */
6203 sparc_builtin_saveregs (void)
6205 int first_reg = current_function_args_info.words;
6209 for (regno = first_reg; regno < SPARC_INT_ARG_MAX; regno++)
6210 emit_move_insn (gen_rtx_MEM (word_mode,
6211 gen_rtx_PLUS (Pmode,
6213 GEN_INT (FIRST_PARM_OFFSET (0)
6216 gen_rtx_REG (word_mode,
6217 SPARC_INCOMING_INT_ARG_FIRST + regno));
6219 address = gen_rtx_PLUS (Pmode,
6221 GEN_INT (FIRST_PARM_OFFSET (0)
6222 + UNITS_PER_WORD * first_reg));
6227 /* Implement `va_start' for stdarg. */
6230 sparc_va_start (tree valist, rtx nextarg)
6232 nextarg = expand_builtin_saveregs ();
6233 std_expand_builtin_va_start (valist, nextarg);
6236 /* Implement `va_arg' for stdarg. */
6239 sparc_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
6241 HOST_WIDE_INT size, rsize, align;
6244 tree ptrtype = build_pointer_type (type);
6246 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
6249 size = rsize = UNITS_PER_WORD;
6255 size = int_size_in_bytes (type);
6256 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
6261 /* For SPARC64, objects requiring 16-byte alignment get it. */
6262 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
6263 align = 2 * UNITS_PER_WORD;
6265 /* SPARC-V9 ABI states that structures up to 16 bytes in size
6266 are left-justified in their slots. */
6267 if (AGGREGATE_TYPE_P (type))
6270 size = rsize = UNITS_PER_WORD;
6280 incr = fold (build2 (PLUS_EXPR, ptr_type_node, incr,
6281 ssize_int (align - 1)));
6282 incr = fold (build2 (BIT_AND_EXPR, ptr_type_node, incr,
6283 ssize_int (-align)));
6286 gimplify_expr (&incr, pre_p, post_p, is_gimple_val, fb_rvalue);
6289 if (BYTES_BIG_ENDIAN && size < rsize)
6290 addr = fold (build2 (PLUS_EXPR, ptr_type_node, incr,
6291 ssize_int (rsize - size)));
6295 addr = fold_convert (build_pointer_type (ptrtype), addr);
6296 addr = build_va_arg_indirect_ref (addr);
6298 /* If the address isn't aligned properly for the type,
6299 we may need to copy to a temporary.
6300 FIXME: This is inefficient. Usually we can do this
6303 && TYPE_ALIGN (type) > BITS_PER_WORD)
6305 tree tmp = create_tmp_var (type, "va_arg_tmp");
6306 tree dest_addr = build_fold_addr_expr (tmp);
6308 tree copy = build_function_call_expr
6309 (implicit_built_in_decls[BUILT_IN_MEMCPY],
6310 tree_cons (NULL_TREE, dest_addr,
6311 tree_cons (NULL_TREE, addr,
6312 tree_cons (NULL_TREE, size_int (rsize),
6315 gimplify_and_add (copy, pre_p);
6319 addr = fold_convert (ptrtype, addr);
6321 incr = fold (build2 (PLUS_EXPR, ptr_type_node, incr, ssize_int (rsize)));
6322 incr = build2 (MODIFY_EXPR, ptr_type_node, valist, incr);
6323 gimplify_and_add (incr, post_p);
6325 return build_va_arg_indirect_ref (addr);
6328 /* Implement the TARGET_VECTOR_MODE_SUPPORTED_P target hook.
6329 Specify whether the vector mode is supported by the hardware. */
6332 sparc_vector_mode_supported_p (enum machine_mode mode)
6334 return TARGET_VIS && VECTOR_MODE_P (mode) ? true : false;
6337 /* Return the string to output an unconditional branch to LABEL, which is
6338 the operand number of the label.
6340 DEST is the destination insn (i.e. the label), INSN is the source. */
6343 output_ubranch (rtx dest, int label, rtx insn)
6345 static char string[64];
6346 bool v9_form = false;
6349 if (TARGET_V9 && INSN_ADDRESSES_SET_P ())
6351 int delta = (INSN_ADDRESSES (INSN_UID (dest))
6352 - INSN_ADDRESSES (INSN_UID (insn)));
6353 /* Leave some instructions for "slop". */
6354 if (delta >= -260000 && delta < 260000)
6359 strcpy (string, "ba%*,pt\t%%xcc, ");
6361 strcpy (string, "b%*\t");
6363 p = strchr (string, '\0');
6374 /* Return the string to output a conditional branch to LABEL, which is
6375 the operand number of the label. OP is the conditional expression.
6376 XEXP (OP, 0) is assumed to be a condition code register (integer or
6377 floating point) and its mode specifies what kind of comparison we made.
6379 DEST is the destination insn (i.e. the label), INSN is the source.
6381 REVERSED is nonzero if we should reverse the sense of the comparison.
6383 ANNUL is nonzero if we should generate an annulling branch. */
6386 output_cbranch (rtx op, rtx dest, int label, int reversed, int annul,
6389 static char string[64];
6390 enum rtx_code code = GET_CODE (op);
6391 rtx cc_reg = XEXP (op, 0);
6392 enum machine_mode mode = GET_MODE (cc_reg);
6393 const char *labelno, *branch;
6394 int spaces = 8, far;
6397 /* v9 branches are limited to +-1MB. If it is too far away,
6410 fbne,a,pn %fcc2, .LC29
6418 far = TARGET_V9 && (get_attr_length (insn) >= 3);
6421 /* Reversal of FP compares takes care -- an ordered compare
6422 becomes an unordered compare and vice versa. */
6423 if (mode == CCFPmode || mode == CCFPEmode)
6424 code = reverse_condition_maybe_unordered (code);
6426 code = reverse_condition (code);
6429 /* Start by writing the branch condition. */
6430 if (mode == CCFPmode || mode == CCFPEmode)
6481 /* ??? !v9: FP branches cannot be preceded by another floating point
6482 insn. Because there is currently no concept of pre-delay slots,
6483 we can fix this only by always emitting a nop before a floating
6488 strcpy (string, "nop\n\t");
6489 strcat (string, branch);
6502 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
6514 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
6535 strcpy (string, branch);
6537 spaces -= strlen (branch);
6538 p = strchr (string, '\0');
6540 /* Now add the annulling, the label, and a possible noop. */
6553 if (! far && insn && INSN_ADDRESSES_SET_P ())
6555 int delta = (INSN_ADDRESSES (INSN_UID (dest))
6556 - INSN_ADDRESSES (INSN_UID (insn)));
6557 /* Leave some instructions for "slop". */
6558 if (delta < -260000 || delta >= 260000)
6562 if (mode == CCFPmode || mode == CCFPEmode)
6564 static char v9_fcc_labelno[] = "%%fccX, ";
6565 /* Set the char indicating the number of the fcc reg to use. */
6566 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
6567 labelno = v9_fcc_labelno;
6570 if (REGNO (cc_reg) == SPARC_FCC_REG)
6576 else if (mode == CCXmode || mode == CCX_NOOVmode)
6578 labelno = "%%xcc, ";
6584 labelno = "%%icc, ";
6589 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
6592 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
6605 strcpy (p, labelno);
6606 p = strchr (p, '\0');
6609 strcpy (p, ".+12\n\t nop\n\tb\t");
6610 /* Skip the next insn if requested or
6611 if we know that it will be a nop. */
6612 if (annul || ! final_sequence)
6626 /* Emit a library call comparison between floating point X and Y.
6627 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
6628 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
6629 values as arguments instead of the TFmode registers themselves,
6630 that's why we cannot call emit_float_lib_cmp. */
6632 sparc_emit_float_lib_cmp (rtx x, rtx y, enum rtx_code comparison)
6635 rtx slot0, slot1, result, tem, tem2;
6636 enum machine_mode mode;
6641 qpfunc = (TARGET_ARCH64) ? "_Qp_feq" : "_Q_feq";
6645 qpfunc = (TARGET_ARCH64) ? "_Qp_fne" : "_Q_fne";
6649 qpfunc = (TARGET_ARCH64) ? "_Qp_fgt" : "_Q_fgt";
6653 qpfunc = (TARGET_ARCH64) ? "_Qp_fge" : "_Q_fge";
6657 qpfunc = (TARGET_ARCH64) ? "_Qp_flt" : "_Q_flt";
6661 qpfunc = (TARGET_ARCH64) ? "_Qp_fle" : "_Q_fle";
6672 qpfunc = (TARGET_ARCH64) ? "_Qp_cmp" : "_Q_cmp";
6682 if (GET_CODE (x) != MEM)
6684 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
6685 emit_insn (gen_rtx_SET (VOIDmode, slot0, x));
6690 if (GET_CODE (y) != MEM)
6692 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
6693 emit_insn (gen_rtx_SET (VOIDmode, slot1, y));
6698 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
6700 XEXP (slot0, 0), Pmode,
6701 XEXP (slot1, 0), Pmode);
6707 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
6709 x, TFmode, y, TFmode);
6715 /* Immediately move the result of the libcall into a pseudo
6716 register so reload doesn't clobber the value if it needs
6717 the return register for a spill reg. */
6718 result = gen_reg_rtx (mode);
6719 emit_move_insn (result, hard_libcall_value (mode));
6724 emit_cmp_insn (result, const0_rtx, NE, NULL_RTX, mode, 0);
6728 emit_cmp_insn (result, GEN_INT(3), comparison == UNORDERED ? EQ : NE,
6733 emit_cmp_insn (result, const1_rtx,
6734 comparison == UNGT ? GT : NE, NULL_RTX, mode, 0);
6737 emit_cmp_insn (result, const2_rtx, NE, NULL_RTX, mode, 0);
6740 tem = gen_reg_rtx (mode);
6742 emit_insn (gen_andsi3 (tem, result, const1_rtx));
6744 emit_insn (gen_anddi3 (tem, result, const1_rtx));
6745 emit_cmp_insn (tem, const0_rtx, NE, NULL_RTX, mode, 0);
6749 tem = gen_reg_rtx (mode);
6751 emit_insn (gen_addsi3 (tem, result, const1_rtx));
6753 emit_insn (gen_adddi3 (tem, result, const1_rtx));
6754 tem2 = gen_reg_rtx (mode);
6756 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
6758 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
6759 emit_cmp_insn (tem2, const0_rtx, comparison == UNEQ ? EQ : NE,
6765 /* Generate an unsigned DImode to FP conversion. This is the same code
6766 optabs would emit if we didn't have TFmode patterns. */
6769 sparc_emit_floatunsdi (rtx *operands, enum machine_mode mode)
6771 rtx neglab, donelab, i0, i1, f0, in, out;
6774 in = force_reg (DImode, operands[1]);
6775 neglab = gen_label_rtx ();
6776 donelab = gen_label_rtx ();
6777 i0 = gen_reg_rtx (DImode);
6778 i1 = gen_reg_rtx (DImode);
6779 f0 = gen_reg_rtx (mode);
6781 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
6783 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
6784 emit_jump_insn (gen_jump (donelab));
6787 emit_label (neglab);
6789 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
6790 emit_insn (gen_anddi3 (i1, in, const1_rtx));
6791 emit_insn (gen_iordi3 (i0, i0, i1));
6792 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
6793 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
6795 emit_label (donelab);
6798 /* Generate an FP to unsigned DImode conversion. This is the same code
6799 optabs would emit if we didn't have TFmode patterns. */
6802 sparc_emit_fixunsdi (rtx *operands, enum machine_mode mode)
6804 rtx neglab, donelab, i0, i1, f0, in, out, limit;
6807 in = force_reg (mode, operands[1]);
6808 neglab = gen_label_rtx ();
6809 donelab = gen_label_rtx ();
6810 i0 = gen_reg_rtx (DImode);
6811 i1 = gen_reg_rtx (DImode);
6812 limit = gen_reg_rtx (mode);
6813 f0 = gen_reg_rtx (mode);
6815 emit_move_insn (limit,
6816 CONST_DOUBLE_FROM_REAL_VALUE (
6817 REAL_VALUE_ATOF ("9223372036854775808.0", mode), mode));
6818 emit_cmp_and_jump_insns (in, limit, GE, NULL_RTX, mode, 0, neglab);
6820 emit_insn (gen_rtx_SET (VOIDmode,
6822 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, in))));
6823 emit_jump_insn (gen_jump (donelab));
6826 emit_label (neglab);
6828 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_MINUS (mode, in, limit)));
6829 emit_insn (gen_rtx_SET (VOIDmode,
6831 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, f0))));
6832 emit_insn (gen_movdi (i1, const1_rtx));
6833 emit_insn (gen_ashldi3 (i1, i1, GEN_INT (63)));
6834 emit_insn (gen_xordi3 (out, i0, i1));
6836 emit_label (donelab);
6839 /* Return the string to output a conditional branch to LABEL, testing
6840 register REG. LABEL is the operand number of the label; REG is the
6841 operand number of the reg. OP is the conditional expression. The mode
6842 of REG says what kind of comparison we made.
6844 DEST is the destination insn (i.e. the label), INSN is the source.
6846 REVERSED is nonzero if we should reverse the sense of the comparison.
6848 ANNUL is nonzero if we should generate an annulling branch. */
6851 output_v9branch (rtx op, rtx dest, int reg, int label, int reversed,
6852 int annul, rtx insn)
6854 static char string[64];
6855 enum rtx_code code = GET_CODE (op);
6856 enum machine_mode mode = GET_MODE (XEXP (op, 0));
6861 /* branch on register are limited to +-128KB. If it is too far away,
6874 brgez,a,pn %o1, .LC29
6880 ba,pt %xcc, .LC29 */
6882 far = get_attr_length (insn) >= 3;
6884 /* If not floating-point or if EQ or NE, we can just reverse the code. */
6886 code = reverse_condition (code);
6888 /* Only 64 bit versions of these instructions exist. */
6892 /* Start by writing the branch condition. */
6897 strcpy (string, "brnz");
6901 strcpy (string, "brz");
6905 strcpy (string, "brgez");
6909 strcpy (string, "brlz");
6913 strcpy (string, "brlez");
6917 strcpy (string, "brgz");
6924 p = strchr (string, '\0');
6926 /* Now add the annulling, reg, label, and nop. */
6933 if (insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
6936 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
6941 *p = p < string + 8 ? '\t' : ' ';
6949 int veryfar = 1, delta;
6951 if (INSN_ADDRESSES_SET_P ())
6953 delta = (INSN_ADDRESSES (INSN_UID (dest))
6954 - INSN_ADDRESSES (INSN_UID (insn)));
6955 /* Leave some instructions for "slop". */
6956 if (delta >= -260000 && delta < 260000)
6960 strcpy (p, ".+12\n\t nop\n\t");
6961 /* Skip the next insn if requested or
6962 if we know that it will be a nop. */
6963 if (annul || ! final_sequence)
6973 strcpy (p, "ba,pt\t%%xcc, ");
6987 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
6988 Such instructions cannot be used in the delay slot of return insn on v9.
6989 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
6993 epilogue_renumber (register rtx *where, int test)
6995 register const char *fmt;
6997 register enum rtx_code code;
7002 code = GET_CODE (*where);
7007 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
7009 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
7010 *where = gen_rtx_REG (GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
7018 /* Do not replace the frame pointer with the stack pointer because
7019 it can cause the delayed instruction to load below the stack.
7020 This occurs when instructions like:
7022 (set (reg/i:SI 24 %i0)
7023 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
7024 (const_int -20 [0xffffffec])) 0))
7026 are in the return delayed slot. */
7028 if (GET_CODE (XEXP (*where, 0)) == REG
7029 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
7030 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
7031 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
7036 if (SPARC_STACK_BIAS
7037 && GET_CODE (XEXP (*where, 0)) == REG
7038 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
7046 fmt = GET_RTX_FORMAT (code);
7048 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
7053 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
7054 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
7057 else if (fmt[i] == 'e'
7058 && epilogue_renumber (&(XEXP (*where, i)), test))
7064 /* Leaf functions and non-leaf functions have different needs. */
7067 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
7070 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
7072 static const int *const reg_alloc_orders[] = {
7073 reg_leaf_alloc_order,
7074 reg_nonleaf_alloc_order};
7077 order_regs_for_local_alloc (void)
7079 static int last_order_nonleaf = 1;
7081 if (regs_ever_live[15] != last_order_nonleaf)
7083 last_order_nonleaf = !last_order_nonleaf;
7084 memcpy ((char *) reg_alloc_order,
7085 (const char *) reg_alloc_orders[last_order_nonleaf],
7086 FIRST_PSEUDO_REGISTER * sizeof (int));
7090 /* Return 1 if REG and MEM are legitimate enough to allow the various
7091 mem<-->reg splits to be run. */
7094 sparc_splitdi_legitimate (rtx reg, rtx mem)
7096 /* Punt if we are here by mistake. */
7097 if (! reload_completed)
7100 /* We must have an offsettable memory reference. */
7101 if (! offsettable_memref_p (mem))
7104 /* If we have legitimate args for ldd/std, we do not want
7105 the split to happen. */
7106 if ((REGNO (reg) % 2) == 0
7107 && mem_min_alignment (mem, 8))
7114 /* Return 1 if x and y are some kind of REG and they refer to
7115 different hard registers. This test is guaranteed to be
7116 run after reload. */
7119 sparc_absnegfloat_split_legitimate (rtx x, rtx y)
7121 if (GET_CODE (x) != REG)
7123 if (GET_CODE (y) != REG)
7125 if (REGNO (x) == REGNO (y))
7130 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
7131 This makes them candidates for using ldd and std insns.
7133 Note reg1 and reg2 *must* be hard registers. */
7136 registers_ok_for_ldd_peep (rtx reg1, rtx reg2)
7138 /* We might have been passed a SUBREG. */
7139 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
7142 if (REGNO (reg1) % 2 != 0)
7145 /* Integer ldd is deprecated in SPARC V9 */
7146 if (TARGET_V9 && REGNO (reg1) < 32)
7149 return (REGNO (reg1) == REGNO (reg2) - 1);
7152 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
7155 This can only happen when addr1 and addr2, the addresses in mem1
7156 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
7157 addr1 must also be aligned on a 64-bit boundary.
7159 Also iff dependent_reg_rtx is not null it should not be used to
7160 compute the address for mem1, i.e. we cannot optimize a sequence
7172 But, note that the transformation from:
7177 is perfectly fine. Thus, the peephole2 patterns always pass us
7178 the destination register of the first load, never the second one.
7180 For stores we don't have a similar problem, so dependent_reg_rtx is
7184 mems_ok_for_ldd_peep (rtx mem1, rtx mem2, rtx dependent_reg_rtx)
7188 HOST_WIDE_INT offset1;
7190 /* The mems cannot be volatile. */
7191 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
7194 /* MEM1 should be aligned on a 64-bit boundary. */
7195 if (MEM_ALIGN (mem1) < 64)
7198 addr1 = XEXP (mem1, 0);
7199 addr2 = XEXP (mem2, 0);
7201 /* Extract a register number and offset (if used) from the first addr. */
7202 if (GET_CODE (addr1) == PLUS)
7204 /* If not a REG, return zero. */
7205 if (GET_CODE (XEXP (addr1, 0)) != REG)
7209 reg1 = REGNO (XEXP (addr1, 0));
7210 /* The offset must be constant! */
7211 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
7213 offset1 = INTVAL (XEXP (addr1, 1));
7216 else if (GET_CODE (addr1) != REG)
7220 reg1 = REGNO (addr1);
7221 /* This was a simple (mem (reg)) expression. Offset is 0. */
7225 /* Make sure the second address is a (mem (plus (reg) (const_int). */
7226 if (GET_CODE (addr2) != PLUS)
7229 if (GET_CODE (XEXP (addr2, 0)) != REG
7230 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
7233 if (reg1 != REGNO (XEXP (addr2, 0)))
7236 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
7239 /* The first offset must be evenly divisible by 8 to ensure the
7240 address is 64 bit aligned. */
7241 if (offset1 % 8 != 0)
7244 /* The offset for the second addr must be 4 more than the first addr. */
7245 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
7248 /* All the tests passed. addr1 and addr2 are valid for ldd and std
7253 /* Return 1 if reg is a pseudo, or is the first register in
7254 a hard register pair. This makes it a candidate for use in
7255 ldd and std insns. */
7258 register_ok_for_ldd (rtx reg)
7260 /* We might have been passed a SUBREG. */
7261 if (GET_CODE (reg) != REG)
7264 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
7265 return (REGNO (reg) % 2 == 0);
7270 /* Print operand X (an rtx) in assembler syntax to file FILE.
7271 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
7272 For `%' followed by punctuation, CODE is the punctuation and X is null. */
7275 print_operand (FILE *file, rtx x, int code)
7280 /* Output an insn in a delay slot. */
7282 sparc_indent_opcode = 1;
7284 fputs ("\n\t nop", file);
7287 /* Output an annul flag if there's nothing for the delay slot and we
7288 are optimizing. This is always used with '(' below.
7289 Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
7290 this is a dbx bug. So, we only do this when optimizing.
7291 On UltraSPARC, a branch in a delay slot causes a pipeline flush.
7292 Always emit a nop in case the next instruction is a branch. */
7293 if (! final_sequence && (optimize && (int)sparc_cpu < PROCESSOR_V9))
7297 /* Output a 'nop' if there's nothing for the delay slot and we are
7298 not optimizing. This is always used with '*' above. */
7299 if (! final_sequence && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
7300 fputs ("\n\t nop", file);
7301 else if (final_sequence)
7302 sparc_indent_opcode = 1;
7305 /* Output the right displacement from the saved PC on function return.
7306 The caller may have placed an "unimp" insn immediately after the call
7307 so we have to account for it. This insn is used in the 32-bit ABI
7308 when calling a function that returns a non zero-sized structure. The
7309 64-bit ABI doesn't have it. Be careful to have this test be the same
7310 as that used on the call. */
7312 && current_function_returns_struct
7313 && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl)))
7315 && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))))
7321 /* Output the Embedded Medium/Anywhere code model base register. */
7322 fputs (EMBMEDANY_BASE_REG, file);
7325 /* Print some local dynamic TLS name. */
7326 assemble_name (file, get_some_local_dynamic_name ());
7330 /* Adjust the operand to take into account a RESTORE operation. */
7331 if (GET_CODE (x) == CONST_INT)
7333 else if (GET_CODE (x) != REG)
7334 output_operand_lossage ("invalid %%Y operand");
7335 else if (REGNO (x) < 8)
7336 fputs (reg_names[REGNO (x)], file);
7337 else if (REGNO (x) >= 24 && REGNO (x) < 32)
7338 fputs (reg_names[REGNO (x)-16], file);
7340 output_operand_lossage ("invalid %%Y operand");
7343 /* Print out the low order register name of a register pair. */
7344 if (WORDS_BIG_ENDIAN)
7345 fputs (reg_names[REGNO (x)+1], file);
7347 fputs (reg_names[REGNO (x)], file);
7350 /* Print out the high order register name of a register pair. */
7351 if (WORDS_BIG_ENDIAN)
7352 fputs (reg_names[REGNO (x)], file);
7354 fputs (reg_names[REGNO (x)+1], file);
7357 /* Print out the second register name of a register pair or quad.
7358 I.e., R (%o0) => %o1. */
7359 fputs (reg_names[REGNO (x)+1], file);
7362 /* Print out the third register name of a register quad.
7363 I.e., S (%o0) => %o2. */
7364 fputs (reg_names[REGNO (x)+2], file);
7367 /* Print out the fourth register name of a register quad.
7368 I.e., T (%o0) => %o3. */
7369 fputs (reg_names[REGNO (x)+3], file);
7372 /* Print a condition code register. */
7373 if (REGNO (x) == SPARC_ICC_REG)
7375 /* We don't handle CC[X]_NOOVmode because they're not supposed
7377 if (GET_MODE (x) == CCmode)
7378 fputs ("%icc", file);
7379 else if (GET_MODE (x) == CCXmode)
7380 fputs ("%xcc", file);
7385 /* %fccN register */
7386 fputs (reg_names[REGNO (x)], file);
7389 /* Print the operand's address only. */
7390 output_address (XEXP (x, 0));
7393 /* In this case we need a register. Use %g0 if the
7394 operand is const0_rtx. */
7396 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
7398 fputs ("%g0", file);
7405 switch (GET_CODE (x))
7407 case IOR: fputs ("or", file); break;
7408 case AND: fputs ("and", file); break;
7409 case XOR: fputs ("xor", file); break;
7410 default: output_operand_lossage ("invalid %%A operand");
7415 switch (GET_CODE (x))
7417 case IOR: fputs ("orn", file); break;
7418 case AND: fputs ("andn", file); break;
7419 case XOR: fputs ("xnor", file); break;
7420 default: output_operand_lossage ("invalid %%B operand");
7424 /* These are used by the conditional move instructions. */
7428 enum rtx_code rc = GET_CODE (x);
7432 enum machine_mode mode = GET_MODE (XEXP (x, 0));
7433 if (mode == CCFPmode || mode == CCFPEmode)
7434 rc = reverse_condition_maybe_unordered (GET_CODE (x));
7436 rc = reverse_condition (GET_CODE (x));
7440 case NE: fputs ("ne", file); break;
7441 case EQ: fputs ("e", file); break;
7442 case GE: fputs ("ge", file); break;
7443 case GT: fputs ("g", file); break;
7444 case LE: fputs ("le", file); break;
7445 case LT: fputs ("l", file); break;
7446 case GEU: fputs ("geu", file); break;
7447 case GTU: fputs ("gu", file); break;
7448 case LEU: fputs ("leu", file); break;
7449 case LTU: fputs ("lu", file); break;
7450 case LTGT: fputs ("lg", file); break;
7451 case UNORDERED: fputs ("u", file); break;
7452 case ORDERED: fputs ("o", file); break;
7453 case UNLT: fputs ("ul", file); break;
7454 case UNLE: fputs ("ule", file); break;
7455 case UNGT: fputs ("ug", file); break;
7456 case UNGE: fputs ("uge", file); break;
7457 case UNEQ: fputs ("ue", file); break;
7458 default: output_operand_lossage (code == 'c'
7459 ? "invalid %%c operand"
7460 : "invalid %%C operand");
7465 /* These are used by the movr instruction pattern. */
7469 enum rtx_code rc = (code == 'd'
7470 ? reverse_condition (GET_CODE (x))
7474 case NE: fputs ("ne", file); break;
7475 case EQ: fputs ("e", file); break;
7476 case GE: fputs ("gez", file); break;
7477 case LT: fputs ("lz", file); break;
7478 case LE: fputs ("lez", file); break;
7479 case GT: fputs ("gz", file); break;
7480 default: output_operand_lossage (code == 'd'
7481 ? "invalid %%d operand"
7482 : "invalid %%D operand");
7489 /* Print a sign-extended character. */
7490 int i = trunc_int_for_mode (INTVAL (x), QImode);
7491 fprintf (file, "%d", i);
7496 /* Operand must be a MEM; write its address. */
7497 if (GET_CODE (x) != MEM)
7498 output_operand_lossage ("invalid %%f operand");
7499 output_address (XEXP (x, 0));
7504 /* Print a sign-extended 32-bit value. */
7506 if (GET_CODE(x) == CONST_INT)
7508 else if (GET_CODE(x) == CONST_DOUBLE)
7509 i = CONST_DOUBLE_LOW (x);
7512 output_operand_lossage ("invalid %%s operand");
7515 i = trunc_int_for_mode (i, SImode);
7516 fprintf (file, HOST_WIDE_INT_PRINT_DEC, i);
7521 /* Do nothing special. */
7525 /* Undocumented flag. */
7526 output_operand_lossage ("invalid operand output code");
7529 if (GET_CODE (x) == REG)
7530 fputs (reg_names[REGNO (x)], file);
7531 else if (GET_CODE (x) == MEM)
7534 /* Poor Sun assembler doesn't understand absolute addressing. */
7535 if (CONSTANT_P (XEXP (x, 0)))
7536 fputs ("%g0+", file);
7537 output_address (XEXP (x, 0));
7540 else if (GET_CODE (x) == HIGH)
7542 fputs ("%hi(", file);
7543 output_addr_const (file, XEXP (x, 0));
7546 else if (GET_CODE (x) == LO_SUM)
7548 print_operand (file, XEXP (x, 0), 0);
7549 if (TARGET_CM_MEDMID)
7550 fputs ("+%l44(", file);
7552 fputs ("+%lo(", file);
7553 output_addr_const (file, XEXP (x, 1));
7556 else if (GET_CODE (x) == CONST_DOUBLE
7557 && (GET_MODE (x) == VOIDmode
7558 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
7560 if (CONST_DOUBLE_HIGH (x) == 0)
7561 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
7562 else if (CONST_DOUBLE_HIGH (x) == -1
7563 && CONST_DOUBLE_LOW (x) < 0)
7564 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
7566 output_operand_lossage ("long long constant not a valid immediate operand");
7568 else if (GET_CODE (x) == CONST_DOUBLE)
7569 output_operand_lossage ("floating point constant not a valid immediate operand");
7570 else { output_addr_const (file, x); }
7573 /* Target hook for assembling integer objects. The sparc version has
7574 special handling for aligned DI-mode objects. */
7577 sparc_assemble_integer (rtx x, unsigned int size, int aligned_p)
7579 /* ??? We only output .xword's for symbols and only then in environments
7580 where the assembler can handle them. */
7581 if (aligned_p && size == 8
7582 && (GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE))
7586 assemble_integer_with_op ("\t.xword\t", x);
7591 assemble_aligned_integer (4, const0_rtx);
7592 assemble_aligned_integer (4, x);
7596 return default_assemble_integer (x, size, aligned_p);
7599 /* Return the value of a code used in the .proc pseudo-op that says
7600 what kind of result this function returns. For non-C types, we pick
7601 the closest C type. */
7603 #ifndef SHORT_TYPE_SIZE
7604 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
7607 #ifndef INT_TYPE_SIZE
7608 #define INT_TYPE_SIZE BITS_PER_WORD
7611 #ifndef LONG_TYPE_SIZE
7612 #define LONG_TYPE_SIZE BITS_PER_WORD
7615 #ifndef LONG_LONG_TYPE_SIZE
7616 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
7619 #ifndef FLOAT_TYPE_SIZE
7620 #define FLOAT_TYPE_SIZE BITS_PER_WORD
7623 #ifndef DOUBLE_TYPE_SIZE
7624 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
7627 #ifndef LONG_DOUBLE_TYPE_SIZE
7628 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
7632 sparc_type_code (register tree type)
7634 register unsigned long qualifiers = 0;
7635 register unsigned shift;
7637 /* Only the first 30 bits of the qualifier are valid. We must refrain from
7638 setting more, since some assemblers will give an error for this. Also,
7639 we must be careful to avoid shifts of 32 bits or more to avoid getting
7640 unpredictable results. */
7642 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
7644 switch (TREE_CODE (type))
7650 qualifiers |= (3 << shift);
7655 qualifiers |= (2 << shift);
7659 case REFERENCE_TYPE:
7661 qualifiers |= (1 << shift);
7665 return (qualifiers | 8);
7668 case QUAL_UNION_TYPE:
7669 return (qualifiers | 9);
7672 return (qualifiers | 10);
7675 return (qualifiers | 16);
7678 /* If this is a range type, consider it to be the underlying
7680 if (TREE_TYPE (type) != 0)
7683 /* Carefully distinguish all the standard types of C,
7684 without messing up if the language is not C. We do this by
7685 testing TYPE_PRECISION and TYPE_UNSIGNED. The old code used to
7686 look at both the names and the above fields, but that's redundant.
7687 Any type whose size is between two C types will be considered
7688 to be the wider of the two types. Also, we do not have a
7689 special code to use for "long long", so anything wider than
7690 long is treated the same. Note that we can't distinguish
7691 between "int" and "long" in this code if they are the same
7692 size, but that's fine, since neither can the assembler. */
7694 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
7695 return (qualifiers | (TYPE_UNSIGNED (type) ? 12 : 2));
7697 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
7698 return (qualifiers | (TYPE_UNSIGNED (type) ? 13 : 3));
7700 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
7701 return (qualifiers | (TYPE_UNSIGNED (type) ? 14 : 4));
7704 return (qualifiers | (TYPE_UNSIGNED (type) ? 15 : 5));
7707 /* If this is a range type, consider it to be the underlying
7709 if (TREE_TYPE (type) != 0)
7712 /* Carefully distinguish all the standard types of C,
7713 without messing up if the language is not C. */
7715 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
7716 return (qualifiers | 6);
7719 return (qualifiers | 7);
7721 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
7722 /* ??? We need to distinguish between double and float complex types,
7723 but I don't know how yet because I can't reach this code from
7724 existing front-ends. */
7725 return (qualifiers | 7); /* Who knows? */
7728 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
7729 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
7730 case LANG_TYPE: /* ? */
7734 abort (); /* Not a type! */
7741 /* Nested function support. */
7743 /* Emit RTL insns to initialize the variable parts of a trampoline.
7744 FNADDR is an RTX for the address of the function's pure code.
7745 CXT is an RTX for the static chain value for the function.
7747 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
7748 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
7749 (to store insns). This is a bit excessive. Perhaps a different
7750 mechanism would be better here.
7752 Emit enough FLUSH insns to synchronize the data and instruction caches. */
7755 sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
7757 /* SPARC 32-bit trampoline:
7760 sethi %hi(static), %g2
7762 or %g2, %lo(static), %g2
7764 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
7765 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
7769 (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
7770 expand_binop (SImode, ior_optab,
7771 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
7772 size_int (10), 0, 1),
7773 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
7774 NULL_RTX, 1, OPTAB_DIRECT));
7777 (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
7778 expand_binop (SImode, ior_optab,
7779 expand_shift (RSHIFT_EXPR, SImode, cxt,
7780 size_int (10), 0, 1),
7781 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
7782 NULL_RTX, 1, OPTAB_DIRECT));
7785 (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
7786 expand_binop (SImode, ior_optab,
7787 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
7788 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
7789 NULL_RTX, 1, OPTAB_DIRECT));
7792 (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
7793 expand_binop (SImode, ior_optab,
7794 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
7795 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
7796 NULL_RTX, 1, OPTAB_DIRECT));
7798 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
7799 aligned on a 16 byte boundary so one flush clears it all. */
7800 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
7801 if (sparc_cpu != PROCESSOR_ULTRASPARC
7802 && sparc_cpu != PROCESSOR_ULTRASPARC3)
7803 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
7804 plus_constant (tramp, 8)))));
7806 /* Call __enable_execute_stack after writing onto the stack to make sure
7807 the stack address is accessible. */
7808 #ifdef ENABLE_EXECUTE_STACK
7809 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
7810 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
7815 /* The 64-bit version is simpler because it makes more sense to load the
7816 values as "immediate" data out of the trampoline. It's also easier since
7817 we can read the PC without clobbering a register. */
7820 sparc64_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
7822 /* SPARC 64-bit trampoline:
7831 emit_move_insn (gen_rtx_MEM (SImode, tramp),
7832 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
7833 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
7834 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
7835 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
7836 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
7837 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
7838 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
7839 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
7840 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
7841 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
7843 if (sparc_cpu != PROCESSOR_ULTRASPARC
7844 && sparc_cpu != PROCESSOR_ULTRASPARC3)
7845 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
7847 /* Call __enable_execute_stack after writing onto the stack to make sure
7848 the stack address is accessible. */
7849 #ifdef ENABLE_EXECUTE_STACK
7850 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
7851 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
7855 /* Adjust the cost of a scheduling dependency. Return the new cost of
7856 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7859 supersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
7861 enum attr_type insn_type;
7863 if (! recog_memoized (insn))
7866 insn_type = get_attr_type (insn);
7868 if (REG_NOTE_KIND (link) == 0)
7870 /* Data dependency; DEP_INSN writes a register that INSN reads some
7873 /* if a load, then the dependence must be on the memory address;
7874 add an extra "cycle". Note that the cost could be two cycles
7875 if the reg was written late in an instruction group; we ca not tell
7877 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
7880 /* Get the delay only if the address of the store is the dependence. */
7881 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
7883 rtx pat = PATTERN(insn);
7884 rtx dep_pat = PATTERN (dep_insn);
7886 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7887 return cost; /* This should not happen! */
7889 /* The dependency between the two instructions was on the data that
7890 is being stored. Assume that this implies that the address of the
7891 store is not dependent. */
7892 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7895 return cost + 3; /* An approximation. */
7898 /* A shift instruction cannot receive its data from an instruction
7899 in the same cycle; add a one cycle penalty. */
7900 if (insn_type == TYPE_SHIFT)
7901 return cost + 3; /* Split before cascade into shift. */
7905 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7906 INSN writes some cycles later. */
7908 /* These are only significant for the fpu unit; writing a fp reg before
7909 the fpu has finished with it stalls the processor. */
7911 /* Reusing an integer register causes no problems. */
7912 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7920 hypersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
7922 enum attr_type insn_type, dep_type;
7923 rtx pat = PATTERN(insn);
7924 rtx dep_pat = PATTERN (dep_insn);
7926 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7929 insn_type = get_attr_type (insn);
7930 dep_type = get_attr_type (dep_insn);
7932 switch (REG_NOTE_KIND (link))
7935 /* Data dependency; DEP_INSN writes a register that INSN reads some
7942 /* Get the delay iff the address of the store is the dependence. */
7943 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7946 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7953 /* If a load, then the dependence must be on the memory address. If
7954 the addresses aren't equal, then it might be a false dependency */
7955 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7957 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7958 || GET_CODE (SET_DEST (dep_pat)) != MEM
7959 || GET_CODE (SET_SRC (pat)) != MEM
7960 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
7961 XEXP (SET_SRC (pat), 0)))
7969 /* Compare to branch latency is 0. There is no benefit from
7970 separating compare and branch. */
7971 if (dep_type == TYPE_COMPARE)
7973 /* Floating point compare to branch latency is less than
7974 compare to conditional move. */
7975 if (dep_type == TYPE_FPCMP)
7984 /* Anti-dependencies only penalize the fpu unit. */
7985 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7997 sparc_adjust_cost(rtx insn, rtx link, rtx dep, int cost)
8001 case PROCESSOR_SUPERSPARC:
8002 cost = supersparc_adjust_cost (insn, link, dep, cost);
8004 case PROCESSOR_HYPERSPARC:
8005 case PROCESSOR_SPARCLITE86X:
8006 cost = hypersparc_adjust_cost (insn, link, dep, cost);
8015 sparc_sched_init (FILE *dump ATTRIBUTE_UNUSED,
8016 int sched_verbose ATTRIBUTE_UNUSED,
8017 int max_ready ATTRIBUTE_UNUSED)
8022 sparc_use_sched_lookahead (void)
8024 if (sparc_cpu == PROCESSOR_ULTRASPARC
8025 || sparc_cpu == PROCESSOR_ULTRASPARC3)
8027 if ((1 << sparc_cpu) &
8028 ((1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
8029 (1 << PROCESSOR_SPARCLITE86X)))
8035 sparc_issue_rate (void)
8042 /* Assume V9 processors are capable of at least dual-issue. */
8044 case PROCESSOR_SUPERSPARC:
8046 case PROCESSOR_HYPERSPARC:
8047 case PROCESSOR_SPARCLITE86X:
8049 case PROCESSOR_ULTRASPARC:
8050 case PROCESSOR_ULTRASPARC3:
8056 set_extends (rtx insn)
8058 register rtx pat = PATTERN (insn);
8060 switch (GET_CODE (SET_SRC (pat)))
8062 /* Load and some shift instructions zero extend. */
8065 /* sethi clears the high bits */
8067 /* LO_SUM is used with sethi. sethi cleared the high
8068 bits and the values used with lo_sum are positive */
8070 /* Store flag stores 0 or 1 */
8080 rtx op0 = XEXP (SET_SRC (pat), 0);
8081 rtx op1 = XEXP (SET_SRC (pat), 1);
8082 if (GET_CODE (op1) == CONST_INT)
8083 return INTVAL (op1) >= 0;
8084 if (GET_CODE (op0) != REG)
8086 if (sparc_check_64 (op0, insn) == 1)
8088 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
8093 rtx op0 = XEXP (SET_SRC (pat), 0);
8094 rtx op1 = XEXP (SET_SRC (pat), 1);
8095 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
8097 if (GET_CODE (op1) == CONST_INT)
8098 return INTVAL (op1) >= 0;
8099 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
8102 return GET_MODE (SET_SRC (pat)) == SImode;
8103 /* Positive integers leave the high bits zero. */
8105 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
8107 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
8110 return - (GET_MODE (SET_SRC (pat)) == SImode);
8112 return sparc_check_64 (SET_SRC (pat), insn);
8118 /* We _ought_ to have only one kind per function, but... */
8119 static GTY(()) rtx sparc_addr_diff_list;
8120 static GTY(()) rtx sparc_addr_list;
8123 sparc_defer_case_vector (rtx lab, rtx vec, int diff)
8125 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
8127 sparc_addr_diff_list
8128 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
8130 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
8134 sparc_output_addr_vec (rtx vec)
8136 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8137 int idx, vlen = XVECLEN (body, 0);
8139 #ifdef ASM_OUTPUT_ADDR_VEC_START
8140 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8143 #ifdef ASM_OUTPUT_CASE_LABEL
8144 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8147 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8150 for (idx = 0; idx < vlen; idx++)
8152 ASM_OUTPUT_ADDR_VEC_ELT
8153 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
8156 #ifdef ASM_OUTPUT_ADDR_VEC_END
8157 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8162 sparc_output_addr_diff_vec (rtx vec)
8164 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8165 rtx base = XEXP (XEXP (body, 0), 0);
8166 int idx, vlen = XVECLEN (body, 1);
8168 #ifdef ASM_OUTPUT_ADDR_VEC_START
8169 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8172 #ifdef ASM_OUTPUT_CASE_LABEL
8173 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8176 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8179 for (idx = 0; idx < vlen; idx++)
8181 ASM_OUTPUT_ADDR_DIFF_ELT
8184 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
8185 CODE_LABEL_NUMBER (base));
8188 #ifdef ASM_OUTPUT_ADDR_VEC_END
8189 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8194 sparc_output_deferred_case_vectors (void)
8199 if (sparc_addr_list == NULL_RTX
8200 && sparc_addr_diff_list == NULL_RTX)
8203 /* Align to cache line in the function's code section. */
8204 function_section (current_function_decl);
8206 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
8208 ASM_OUTPUT_ALIGN (asm_out_file, align);
8210 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
8211 sparc_output_addr_vec (XEXP (t, 0));
8212 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
8213 sparc_output_addr_diff_vec (XEXP (t, 0));
8215 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
8218 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
8219 unknown. Return 1 if the high bits are zero, -1 if the register is
8222 sparc_check_64 (rtx x, rtx insn)
8224 /* If a register is set only once it is safe to ignore insns this
8225 code does not know how to handle. The loop will either recognize
8226 the single set and return the correct value or fail to recognize
8231 if (GET_CODE (x) != REG)
8234 if (GET_MODE (x) == DImode)
8235 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
8237 if (flag_expensive_optimizations
8238 && REG_N_SETS (REGNO (y)) == 1)
8244 insn = get_last_insn_anywhere ();
8249 while ((insn = PREV_INSN (insn)))
8251 switch (GET_CODE (insn))
8264 rtx pat = PATTERN (insn);
8265 if (GET_CODE (pat) != SET)
8267 if (rtx_equal_p (x, SET_DEST (pat)))
8268 return set_extends (insn);
8269 if (y && rtx_equal_p (y, SET_DEST (pat)))
8270 return set_extends (insn);
8271 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
8279 /* Returns assembly code to perform a DImode shift using
8280 a 64-bit global or out register on SPARC-V8+. */
8282 output_v8plus_shift (rtx *operands, rtx insn, const char *opcode)
8284 static char asm_code[60];
8286 /* The scratch register is only required when the destination
8287 register is not a 64-bit global or out register. */
8288 if (which_alternative != 2)
8289 operands[3] = operands[0];
8291 /* We can only shift by constants <= 63. */
8292 if (GET_CODE (operands[2]) == CONST_INT)
8293 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
8295 if (GET_CODE (operands[1]) == CONST_INT)
8297 output_asm_insn ("mov\t%1, %3", operands);
8301 output_asm_insn ("sllx\t%H1, 32, %3", operands);
8302 if (sparc_check_64 (operands[1], insn) <= 0)
8303 output_asm_insn ("srl\t%L1, 0, %L1", operands);
8304 output_asm_insn ("or\t%L1, %3, %3", operands);
8307 strcpy(asm_code, opcode);
8309 if (which_alternative != 2)
8310 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
8312 return strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
8315 /* Output rtl to increment the profiler label LABELNO
8316 for profiling a function entry. */
8319 sparc_profile_hook (int labelno)
8324 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
8325 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
8326 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
8328 emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lab, Pmode);
8331 #ifdef OBJECT_FORMAT_ELF
8333 sparc_elf_asm_named_section (const char *name, unsigned int flags,
8336 if (flags & SECTION_MERGE)
8338 /* entsize cannot be expressed in this section attributes
8340 default_elf_asm_named_section (name, flags, decl);
8344 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
8346 if (!(flags & SECTION_DEBUG))
8347 fputs (",#alloc", asm_out_file);
8348 if (flags & SECTION_WRITE)
8349 fputs (",#write", asm_out_file);
8350 if (flags & SECTION_TLS)
8351 fputs (",#tls", asm_out_file);
8352 if (flags & SECTION_CODE)
8353 fputs (",#execinstr", asm_out_file);
8355 /* ??? Handle SECTION_BSS. */
8357 fputc ('\n', asm_out_file);
8359 #endif /* OBJECT_FORMAT_ELF */
8361 /* We do not allow indirect calls to be optimized into sibling calls.
8363 We cannot use sibling calls when delayed branches are disabled
8364 because they will likely require the call delay slot to be filled.
8366 Also, on SPARC 32-bit we cannot emit a sibling call when the
8367 current function returns a structure. This is because the "unimp
8368 after call" convention would cause the callee to return to the
8369 wrong place. The generic code already disallows cases where the
8370 function being called returns a structure.
8372 It may seem strange how this last case could occur. Usually there
8373 is code after the call which jumps to epilogue code which dumps the
8374 return value into the struct return area. That ought to invalidate
8375 the sibling call right? Well, in the C++ case we can end up passing
8376 the pointer to the struct return area to a constructor (which returns
8377 void) and then nothing else happens. Such a sibling call would look
8378 valid without the added check here. */
8380 sparc_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
8383 && flag_delayed_branch
8384 && (TARGET_ARCH64 || ! current_function_returns_struct));
8387 /* libfunc renaming. */
8388 #include "config/gofast.h"
8391 sparc_init_libfuncs (void)
8395 /* Use the subroutines that Sun's library provides for integer
8396 multiply and divide. The `*' prevents an underscore from
8397 being prepended by the compiler. .umul is a little faster
8399 set_optab_libfunc (smul_optab, SImode, "*.umul");
8400 set_optab_libfunc (sdiv_optab, SImode, "*.div");
8401 set_optab_libfunc (udiv_optab, SImode, "*.udiv");
8402 set_optab_libfunc (smod_optab, SImode, "*.rem");
8403 set_optab_libfunc (umod_optab, SImode, "*.urem");
8405 /* TFmode arithmetic. These names are part of the SPARC 32bit ABI. */
8406 set_optab_libfunc (add_optab, TFmode, "_Q_add");
8407 set_optab_libfunc (sub_optab, TFmode, "_Q_sub");
8408 set_optab_libfunc (neg_optab, TFmode, "_Q_neg");
8409 set_optab_libfunc (smul_optab, TFmode, "_Q_mul");
8410 set_optab_libfunc (sdiv_optab, TFmode, "_Q_div");
8412 /* We can define the TFmode sqrt optab only if TARGET_FPU. This
8413 is because with soft-float, the SFmode and DFmode sqrt
8414 instructions will be absent, and the compiler will notice and
8415 try to use the TFmode sqrt instruction for calls to the
8416 builtin function sqrt, but this fails. */
8418 set_optab_libfunc (sqrt_optab, TFmode, "_Q_sqrt");
8420 set_optab_libfunc (eq_optab, TFmode, "_Q_feq");
8421 set_optab_libfunc (ne_optab, TFmode, "_Q_fne");
8422 set_optab_libfunc (gt_optab, TFmode, "_Q_fgt");
8423 set_optab_libfunc (ge_optab, TFmode, "_Q_fge");
8424 set_optab_libfunc (lt_optab, TFmode, "_Q_flt");
8425 set_optab_libfunc (le_optab, TFmode, "_Q_fle");
8427 set_conv_libfunc (sext_optab, TFmode, SFmode, "_Q_stoq");
8428 set_conv_libfunc (sext_optab, TFmode, DFmode, "_Q_dtoq");
8429 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_Q_qtos");
8430 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_Q_qtod");
8432 set_conv_libfunc (sfix_optab, SImode, TFmode, "_Q_qtoi");
8433 set_conv_libfunc (ufix_optab, SImode, TFmode, "_Q_qtou");
8434 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_Q_itoq");
8436 if (DITF_CONVERSION_LIBFUNCS)
8438 set_conv_libfunc (sfix_optab, DImode, TFmode, "_Q_qtoll");
8439 set_conv_libfunc (ufix_optab, DImode, TFmode, "_Q_qtoull");
8440 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_Q_lltoq");
8443 if (SUN_CONVERSION_LIBFUNCS)
8445 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftoll");
8446 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoull");
8447 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtoll");
8448 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoull");
8453 /* In the SPARC 64bit ABI, SImode multiply and divide functions
8454 do not exist in the library. Make sure the compiler does not
8455 emit calls to them by accident. (It should always use the
8456 hardware instructions.) */
8457 set_optab_libfunc (smul_optab, SImode, 0);
8458 set_optab_libfunc (sdiv_optab, SImode, 0);
8459 set_optab_libfunc (udiv_optab, SImode, 0);
8460 set_optab_libfunc (smod_optab, SImode, 0);
8461 set_optab_libfunc (umod_optab, SImode, 0);
8463 if (SUN_INTEGER_MULTIPLY_64)
8465 set_optab_libfunc (smul_optab, DImode, "__mul64");
8466 set_optab_libfunc (sdiv_optab, DImode, "__div64");
8467 set_optab_libfunc (udiv_optab, DImode, "__udiv64");
8468 set_optab_libfunc (smod_optab, DImode, "__rem64");
8469 set_optab_libfunc (umod_optab, DImode, "__urem64");
8472 if (SUN_CONVERSION_LIBFUNCS)
8474 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftol");
8475 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoul");
8476 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtol");
8477 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoul");
8481 gofast_maybe_init_libfuncs ();
8484 #define def_builtin(NAME, CODE, TYPE) \
8485 lang_hooks.builtin_function((NAME), (TYPE), (CODE), BUILT_IN_MD, NULL, \
8488 /* Implement the TARGET_INIT_BUILTINS target hook.
8489 Create builtin functions for special SPARC instructions. */
8492 sparc_init_builtins (void)
8495 sparc_vis_init_builtins ();
8498 /* Create builtin functions for VIS 1.0 instructions. */
8501 sparc_vis_init_builtins (void)
8503 tree v4qi = build_vector_type (unsigned_intQI_type_node, 4);
8504 tree v8qi = build_vector_type (unsigned_intQI_type_node, 8);
8505 tree v4hi = build_vector_type (intHI_type_node, 4);
8506 tree v2hi = build_vector_type (intHI_type_node, 2);
8507 tree v2si = build_vector_type (intSI_type_node, 2);
8509 tree v4qi_ftype_v4hi = build_function_type_list (v4qi, v4hi, 0);
8510 tree v8qi_ftype_v2si_v8qi = build_function_type_list (v8qi, v2si, v8qi, 0);
8511 tree v2hi_ftype_v2si = build_function_type_list (v2hi, v2si, 0);
8512 tree v4hi_ftype_v4qi = build_function_type_list (v4hi, v4qi, 0);
8513 tree v8qi_ftype_v4qi_v4qi = build_function_type_list (v8qi, v4qi, v4qi, 0);
8514 tree v4hi_ftype_v4qi_v4hi = build_function_type_list (v4hi, v4qi, v4hi, 0);
8515 tree v4hi_ftype_v4qi_v2hi = build_function_type_list (v4hi, v4qi, v2hi, 0);
8516 tree v2si_ftype_v4qi_v2hi = build_function_type_list (v2si, v4qi, v2hi, 0);
8517 tree v4hi_ftype_v8qi_v4hi = build_function_type_list (v4hi, v8qi, v4hi, 0);
8518 tree v4hi_ftype_v4hi_v4hi = build_function_type_list (v4hi, v4hi, v4hi, 0);
8519 tree v2si_ftype_v2si_v2si = build_function_type_list (v2si, v2si, v2si, 0);
8520 tree v8qi_ftype_v8qi_v8qi = build_function_type_list (v8qi, v8qi, v8qi, 0);
8521 tree di_ftype_v8qi_v8qi_di = build_function_type_list (intDI_type_node,
8523 intDI_type_node, 0);
8524 tree di_ftype_di_di = build_function_type_list (intDI_type_node,
8526 intDI_type_node, 0);
8527 tree ptr_ftype_ptr_si = build_function_type_list (ptr_type_node,
8529 intSI_type_node, 0);
8530 tree ptr_ftype_ptr_di = build_function_type_list (ptr_type_node,
8532 intDI_type_node, 0);
8534 /* Packing and expanding vectors. */
8535 def_builtin ("__builtin_vis_fpack16", CODE_FOR_fpack16_vis, v4qi_ftype_v4hi);
8536 def_builtin ("__builtin_vis_fpack32", CODE_FOR_fpack32_vis,
8537 v8qi_ftype_v2si_v8qi);
8538 def_builtin ("__builtin_vis_fpackfix", CODE_FOR_fpackfix_vis,
8540 def_builtin ("__builtin_vis_fexpand", CODE_FOR_fexpand_vis, v4hi_ftype_v4qi);
8541 def_builtin ("__builtin_vis_fpmerge", CODE_FOR_fpmerge_vis,
8542 v8qi_ftype_v4qi_v4qi);
8544 /* Multiplications. */
8545 def_builtin ("__builtin_vis_fmul8x16", CODE_FOR_fmul8x16_vis,
8546 v4hi_ftype_v4qi_v4hi);
8547 def_builtin ("__builtin_vis_fmul8x16au", CODE_FOR_fmul8x16au_vis,
8548 v4hi_ftype_v4qi_v2hi);
8549 def_builtin ("__builtin_vis_fmul8x16al", CODE_FOR_fmul8x16al_vis,
8550 v4hi_ftype_v4qi_v2hi);
8551 def_builtin ("__builtin_vis_fmul8sux16", CODE_FOR_fmul8sux16_vis,
8552 v4hi_ftype_v8qi_v4hi);
8553 def_builtin ("__builtin_vis_fmul8ulx16", CODE_FOR_fmul8ulx16_vis,
8554 v4hi_ftype_v8qi_v4hi);
8555 def_builtin ("__builtin_vis_fmuld8sux16", CODE_FOR_fmuld8sux16_vis,
8556 v2si_ftype_v4qi_v2hi);
8557 def_builtin ("__builtin_vis_fmuld8ulx16", CODE_FOR_fmuld8ulx16_vis,
8558 v2si_ftype_v4qi_v2hi);
8560 /* Data aligning. */
8561 def_builtin ("__builtin_vis_faligndatav4hi", CODE_FOR_faligndatav4hi_vis,
8562 v4hi_ftype_v4hi_v4hi);
8563 def_builtin ("__builtin_vis_faligndatav8qi", CODE_FOR_faligndatav8qi_vis,
8564 v8qi_ftype_v8qi_v8qi);
8565 def_builtin ("__builtin_vis_faligndatav2si", CODE_FOR_faligndatav2si_vis,
8566 v2si_ftype_v2si_v2si);
8567 def_builtin ("__builtin_vis_faligndatadi", CODE_FOR_faligndatadi_vis,
8570 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrdi_vis,
8573 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrsi_vis,
8576 /* Pixel distance. */
8577 def_builtin ("__builtin_vis_pdist", CODE_FOR_pdist_vis,
8578 di_ftype_v8qi_v8qi_di);
8581 /* Handle TARGET_EXPAND_BUILTIN target hook.
8582 Expand builtin functions for sparc instrinsics. */
8585 sparc_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
8586 enum machine_mode tmode, int ignore ATTRIBUTE_UNUSED)
8589 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
8590 unsigned int icode = DECL_FUNCTION_CODE (fndecl);
8592 enum machine_mode mode[4];
8595 mode[arg_count] = tmode;
8598 || GET_MODE (target) != tmode
8599 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
8600 op[arg_count] = gen_reg_rtx (tmode);
8602 op[arg_count] = target;
8604 for (arglist = TREE_OPERAND (exp, 1); arglist;
8605 arglist = TREE_CHAIN (arglist))
8607 tree arg = TREE_VALUE (arglist);
8610 mode[arg_count] = insn_data[icode].operand[arg_count].mode;
8611 op[arg_count] = expand_expr (arg, NULL_RTX, VOIDmode, 0);
8613 if (! (*insn_data[icode].operand[arg_count].predicate) (op[arg_count],
8615 op[arg_count] = copy_to_mode_reg (mode[arg_count], op[arg_count]);
8621 pat = GEN_FCN (icode) (op[0], op[1]);
8624 pat = GEN_FCN (icode) (op[0], op[1], op[2]);
8627 pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]);
8642 sparc_extra_constraint_check (rtx op, int c, int strict)
8647 && (c == 'T' || c == 'U'))
8653 return fp_sethi_p (op);
8656 return fp_mov_p (op);
8659 return fp_high_losum_p (op);
8663 || (GET_CODE (op) == REG
8664 && (REGNO (op) < FIRST_PSEUDO_REGISTER
8665 || reg_renumber[REGNO (op)] >= 0)))
8666 return register_ok_for_ldd (op);
8675 return fp_zero_operand (op, GET_MODE (op));
8681 /* Our memory extra constraints have to emulate the
8682 behavior of 'm' and 'o' in order for reload to work
8684 if (GET_CODE (op) == MEM)
8687 if ((TARGET_ARCH64 || mem_min_alignment (op, 8))
8689 || strict_memory_address_p (Pmode, XEXP (op, 0))))
8694 reload_ok_mem = (reload_in_progress
8695 && GET_CODE (op) == REG
8696 && REGNO (op) >= FIRST_PSEUDO_REGISTER
8697 && reg_renumber [REGNO (op)] < 0);
8700 return reload_ok_mem;
8703 /* ??? This duplicates information provided to the compiler by the
8704 ??? scheduler description. Some day, teach genautomata to output
8705 ??? the latencies and then CSE will just use that. */
8708 sparc_rtx_costs (rtx x, int code, int outer_code, int *total)
8710 enum machine_mode mode = GET_MODE (x);
8711 bool float_mode_p = FLOAT_MODE_P (mode);
8716 if (INTVAL (x) < 0x1000 && INTVAL (x) >= -0x1000)
8734 if (GET_MODE (x) == DImode
8735 && ((XINT (x, 3) == 0
8736 && (unsigned HOST_WIDE_INT) XINT (x, 2) < 0x1000)
8737 || (XINT (x, 3) == -1
8739 && XINT (x, 2) >= -0x1000)))
8746 /* If outer-code was a sign or zero extension, a cost
8747 of COSTS_N_INSNS (1) was already added in. This is
8748 why we are subtracting it back out. */
8749 if (outer_code == ZERO_EXTEND)
8751 *total = sparc_costs->int_zload - COSTS_N_INSNS (1);
8753 else if (outer_code == SIGN_EXTEND)
8755 *total = sparc_costs->int_sload - COSTS_N_INSNS (1);
8757 else if (float_mode_p)
8759 *total = sparc_costs->float_load;
8763 *total = sparc_costs->int_load;
8771 *total = sparc_costs->float_plusminus;
8773 *total = COSTS_N_INSNS (1);
8778 *total = sparc_costs->float_mul;
8779 else if (! TARGET_HARD_MUL)
8780 *total = COSTS_N_INSNS (25);
8786 if (sparc_costs->int_mul_bit_factor)
8790 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
8792 unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
8793 for (nbits = 0; value != 0; value &= value - 1)
8796 else if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
8797 && GET_MODE (XEXP (x, 1)) == DImode)
8799 rtx x1 = XEXP (x, 1);
8800 unsigned HOST_WIDE_INT value1 = XINT (x1, 2);
8801 unsigned HOST_WIDE_INT value2 = XINT (x1, 3);
8803 for (nbits = 0; value1 != 0; value1 &= value1 - 1)
8805 for (; value2 != 0; value2 &= value2 - 1)
8813 bit_cost = (nbits - 3) / sparc_costs->int_mul_bit_factor;
8814 bit_cost = COSTS_N_INSNS (bit_cost);
8818 *total = sparc_costs->int_mulX + bit_cost;
8820 *total = sparc_costs->int_mul + bit_cost;
8827 *total = COSTS_N_INSNS (1) + sparc_costs->shift_penalty;
8837 *total = sparc_costs->float_div_df;
8839 *total = sparc_costs->float_div_sf;
8844 *total = sparc_costs->int_divX;
8846 *total = sparc_costs->int_div;
8853 *total = COSTS_N_INSNS (1);
8860 case UNSIGNED_FLOAT:
8864 case FLOAT_TRUNCATE:
8865 *total = sparc_costs->float_move;
8870 *total = sparc_costs->float_sqrt_df;
8872 *total = sparc_costs->float_sqrt_sf;
8877 *total = sparc_costs->float_cmp;
8879 *total = COSTS_N_INSNS (1);
8884 *total = sparc_costs->float_cmove;
8886 *total = sparc_costs->int_cmove;
8890 /* Handle the NAND vector patterns. */
8891 if (sparc_vector_mode_supported_p (GET_MODE (x))
8892 && GET_CODE (XEXP (x, 0)) == NOT
8893 && GET_CODE (XEXP (x, 1)) == NOT)
8895 *total = COSTS_N_INSNS (1);
8906 /* Emit the sequence of insns SEQ while preserving the register REG. */
8909 emit_and_preserve (rtx seq, rtx reg)
8911 rtx slot = gen_rtx_MEM (word_mode,
8912 plus_constant (stack_pointer_rtx, SPARC_STACK_BIAS));
8914 emit_insn (gen_stack_pointer_dec (GEN_INT (STACK_BOUNDARY/BITS_PER_UNIT)));
8915 emit_insn (gen_rtx_SET (VOIDmode, slot, reg));
8917 emit_insn (gen_rtx_SET (VOIDmode, reg, slot));
8918 emit_insn (gen_stack_pointer_inc (GEN_INT (STACK_BOUNDARY/BITS_PER_UNIT)));
8921 /* Output the assembler code for a thunk function. THUNK_DECL is the
8922 declaration for the thunk function itself, FUNCTION is the decl for
8923 the target function. DELTA is an immediate constant offset to be
8924 added to THIS. If VCALL_OFFSET is nonzero, the word at address
8925 (*THIS + VCALL_OFFSET) should be additionally added to THIS. */
8928 sparc_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
8929 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
8932 rtx this, insn, funexp;
8933 unsigned int int_arg_first;
8935 reload_completed = 1;
8936 epilogue_completed = 1;
8938 reset_block_changes ();
8940 emit_note (NOTE_INSN_PROLOGUE_END);
8942 if (flag_delayed_branch)
8944 /* We will emit a regular sibcall below, so we need to instruct
8945 output_sibcall that we are in a leaf function. */
8946 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 1;
8948 /* This will cause final.c to invoke leaf_renumber_regs so we
8949 must behave as if we were in a not-yet-leafified function. */
8950 int_arg_first = SPARC_INCOMING_INT_ARG_FIRST;
8954 /* We will emit the sibcall manually below, so we will need to
8955 manually spill non-leaf registers. */
8956 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 0;
8958 /* We really are in a leaf function. */
8959 int_arg_first = SPARC_OUTGOING_INT_ARG_FIRST;
8962 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
8963 returns a structure, the structure return pointer is there instead. */
8964 if (TARGET_ARCH64 && aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
8965 this = gen_rtx_REG (Pmode, int_arg_first + 1);
8967 this = gen_rtx_REG (Pmode, int_arg_first);
8969 /* Add DELTA. When possible use a plain add, otherwise load it into
8970 a register first. */
8973 rtx delta_rtx = GEN_INT (delta);
8975 if (! SPARC_SIMM13_P (delta))
8977 rtx scratch = gen_rtx_REG (Pmode, 1);
8978 emit_move_insn (scratch, delta_rtx);
8979 delta_rtx = scratch;
8982 /* THIS += DELTA. */
8983 emit_insn (gen_add2_insn (this, delta_rtx));
8986 /* Add the word at address (*THIS + VCALL_OFFSET). */
8989 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
8990 rtx scratch = gen_rtx_REG (Pmode, 1);
8992 if (vcall_offset >= 0)
8995 /* SCRATCH = *THIS. */
8996 emit_move_insn (scratch, gen_rtx_MEM (Pmode, this));
8998 /* Prepare for adding VCALL_OFFSET. The difficulty is that we
8999 may not have any available scratch register at this point. */
9000 if (SPARC_SIMM13_P (vcall_offset))
9002 /* This is the case if ARCH64 (unless -ffixed-g5 is passed). */
9003 else if (! fixed_regs[5]
9004 /* The below sequence is made up of at least 2 insns,
9005 while the default method may need only one. */
9006 && vcall_offset < -8192)
9008 rtx scratch2 = gen_rtx_REG (Pmode, 5);
9009 emit_move_insn (scratch2, vcall_offset_rtx);
9010 vcall_offset_rtx = scratch2;
9014 rtx increment = GEN_INT (-4096);
9016 /* VCALL_OFFSET is a negative number whose typical range can be
9017 estimated as -32768..0 in 32-bit mode. In almost all cases
9018 it is therefore cheaper to emit multiple add insns than
9019 spilling and loading the constant into a register (at least
9021 while (! SPARC_SIMM13_P (vcall_offset))
9023 emit_insn (gen_add2_insn (scratch, increment));
9024 vcall_offset += 4096;
9026 vcall_offset_rtx = GEN_INT (vcall_offset); /* cannot be 0 */
9029 /* SCRATCH = *(*THIS + VCALL_OFFSET). */
9030 emit_move_insn (scratch, gen_rtx_MEM (Pmode,
9031 gen_rtx_PLUS (Pmode,
9033 vcall_offset_rtx)));
9035 /* THIS += *(*THIS + VCALL_OFFSET). */
9036 emit_insn (gen_add2_insn (this, scratch));
9039 /* Generate a tail call to the target function. */
9040 if (! TREE_USED (function))
9042 assemble_external (function);
9043 TREE_USED (function) = 1;
9045 funexp = XEXP (DECL_RTL (function), 0);
9047 if (flag_delayed_branch)
9049 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
9050 insn = emit_call_insn (gen_sibcall (funexp));
9051 SIBLING_CALL_P (insn) = 1;
9055 /* The hoops we have to jump through in order to generate a sibcall
9056 without using delay slots... */
9057 rtx spill_reg, seq, scratch = gen_rtx_REG (Pmode, 1);
9061 spill_reg = gen_rtx_REG (word_mode, 15); /* %o7 */
9063 load_pic_register (); /* clobbers %o7 */
9064 scratch = legitimize_pic_address (funexp, Pmode, scratch);
9067 emit_and_preserve (seq, spill_reg);
9069 else if (TARGET_ARCH32)
9071 emit_insn (gen_rtx_SET (VOIDmode,
9073 gen_rtx_HIGH (SImode, funexp)));
9074 emit_insn (gen_rtx_SET (VOIDmode,
9076 gen_rtx_LO_SUM (SImode, scratch, funexp)));
9078 else /* TARGET_ARCH64 */
9080 switch (sparc_cmodel)
9084 /* The destination can serve as a temporary. */
9085 sparc_emit_set_symbolic_const64 (scratch, funexp, scratch);
9090 /* The destination cannot serve as a temporary. */
9091 spill_reg = gen_rtx_REG (DImode, 15); /* %o7 */
9093 sparc_emit_set_symbolic_const64 (scratch, funexp, spill_reg);
9096 emit_and_preserve (seq, spill_reg);
9104 emit_jump_insn (gen_indirect_jump (scratch));
9109 /* Run just enough of rest_of_compilation to get the insns emitted.
9110 There's not really enough bulk here to make other passes such as
9111 instruction scheduling worth while. Note that use_thunk calls
9112 assemble_start_function and assemble_end_function. */
9113 insn = get_insns ();
9114 insn_locators_initialize ();
9115 shorten_branches (insn);
9116 final_start_function (insn, file, 1);
9117 final (insn, file, 1);
9118 final_end_function ();
9120 reload_completed = 0;
9121 epilogue_completed = 0;
9125 /* Return true if sparc_output_mi_thunk would be able to output the
9126 assembler code for the thunk function specified by the arguments
9127 it is passed, and false otherwise. */
9129 sparc_can_output_mi_thunk (tree thunk_fndecl ATTRIBUTE_UNUSED,
9130 HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
9131 HOST_WIDE_INT vcall_offset,
9132 tree function ATTRIBUTE_UNUSED)
9134 /* Bound the loop used in the default method above. */
9135 return (vcall_offset >= -32768 || ! fixed_regs[5]);
9138 /* How to allocate a 'struct machine_function'. */
9140 static struct machine_function *
9141 sparc_init_machine_status (void)
9143 return ggc_alloc_cleared (sizeof (struct machine_function));
9146 /* Locate some local-dynamic symbol still in use by this function
9147 so that we can print its name in local-dynamic base patterns. */
9150 get_some_local_dynamic_name (void)
9154 if (cfun->machine->some_ld_name)
9155 return cfun->machine->some_ld_name;
9157 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
9159 && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
9160 return cfun->machine->some_ld_name;
9166 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
9171 && GET_CODE (x) == SYMBOL_REF
9172 && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
9174 cfun->machine->some_ld_name = XSTR (x, 0);
9181 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
9182 This is called from dwarf2out.c to emit call frame instructions
9183 for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
9185 sparc_dwarf_handle_frame_unspec (const char *label,
9186 rtx pattern ATTRIBUTE_UNUSED,
9187 int index ATTRIBUTE_UNUSED)
9189 gcc_assert (index == UNSPECV_SAVEW);
9190 dwarf2out_window_save (label);
9193 /* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
9194 We need to emit DTP-relative relocations. */
9197 sparc_output_dwarf_dtprel (FILE *file, int size, rtx x)
9202 fputs ("\t.word\t%r_tls_dtpoff32(", file);
9205 fputs ("\t.xword\t%r_tls_dtpoff64(", file);
9210 output_addr_const (file, x);
9214 #include "gt-sparc.h"