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 bool sparc_handle_option (size_t, const char *, int);
303 static void sparc_init_modes (void);
304 static void scan_record_type (tree, int *, int *, int *);
305 static int function_arg_slotno (const CUMULATIVE_ARGS *, enum machine_mode,
306 tree, int, int, int *, int *);
308 static int supersparc_adjust_cost (rtx, rtx, rtx, int);
309 static int hypersparc_adjust_cost (rtx, rtx, rtx, int);
311 static void sparc_output_addr_vec (rtx);
312 static void sparc_output_addr_diff_vec (rtx);
313 static void sparc_output_deferred_case_vectors (void);
314 static rtx sparc_builtin_saveregs (void);
315 static int epilogue_renumber (rtx *, int);
316 static bool sparc_assemble_integer (rtx, unsigned int, int);
317 static int set_extends (rtx);
318 static void emit_pic_helper (void);
319 static void load_pic_register (bool);
320 static int save_or_restore_regs (int, int, rtx, int, int);
321 static void emit_save_regs (void);
322 static void emit_restore_regs (void);
323 static void sparc_asm_function_prologue (FILE *, HOST_WIDE_INT);
324 static void sparc_asm_function_epilogue (FILE *, HOST_WIDE_INT);
325 #ifdef OBJECT_FORMAT_ELF
326 static void sparc_elf_asm_named_section (const char *, unsigned int, tree);
329 static int sparc_adjust_cost (rtx, rtx, rtx, int);
330 static int sparc_issue_rate (void);
331 static void sparc_sched_init (FILE *, int, int);
332 static int sparc_use_sched_lookahead (void);
334 static void emit_soft_tfmode_libcall (const char *, int, rtx *);
335 static void emit_soft_tfmode_binop (enum rtx_code, rtx *);
336 static void emit_soft_tfmode_unop (enum rtx_code, rtx *);
337 static void emit_soft_tfmode_cvt (enum rtx_code, rtx *);
338 static void emit_hard_tfmode_operation (enum rtx_code, rtx *);
340 static bool sparc_function_ok_for_sibcall (tree, tree);
341 static void sparc_init_libfuncs (void);
342 static void sparc_init_builtins (void);
343 static void sparc_vis_init_builtins (void);
344 static rtx sparc_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
345 static void sparc_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
346 HOST_WIDE_INT, tree);
347 static bool sparc_can_output_mi_thunk (tree, HOST_WIDE_INT,
348 HOST_WIDE_INT, tree);
349 static struct machine_function * sparc_init_machine_status (void);
350 static bool sparc_cannot_force_const_mem (rtx);
351 static rtx sparc_tls_get_addr (void);
352 static rtx sparc_tls_got (void);
353 static const char *get_some_local_dynamic_name (void);
354 static int get_some_local_dynamic_name_1 (rtx *, void *);
355 static bool sparc_rtx_costs (rtx, int, int, int *);
356 static bool sparc_promote_prototypes (tree);
357 static rtx sparc_struct_value_rtx (tree, int);
358 static bool sparc_return_in_memory (tree, tree);
359 static bool sparc_strict_argument_naming (CUMULATIVE_ARGS *);
360 static tree sparc_gimplify_va_arg (tree, tree, tree *, tree *);
361 static bool sparc_vector_mode_supported_p (enum machine_mode);
362 static bool sparc_pass_by_reference (CUMULATIVE_ARGS *,
363 enum machine_mode, tree, bool);
364 static int sparc_arg_partial_bytes (CUMULATIVE_ARGS *,
365 enum machine_mode, tree, bool);
366 static void sparc_dwarf_handle_frame_unspec (const char *, rtx, int);
367 static void sparc_file_end (void);
368 #ifdef SUBTARGET_ATTRIBUTE_TABLE
369 const struct attribute_spec sparc_attribute_table[];
372 /* Option handling. */
374 /* Code model option as passed by user. */
375 const char *sparc_cmodel_string;
378 enum cmodel sparc_cmodel;
380 char sparc_hard_reg_printed[8];
382 struct sparc_cpu_select sparc_select[] =
384 /* switch name, tune arch */
385 { (char *)0, "default", 1, 1 },
386 { (char *)0, "-mcpu=", 1, 1 },
387 { (char *)0, "-mtune=", 1, 0 },
391 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
392 enum processor_type sparc_cpu;
394 /* Whether
\fan FPU option was specified. */
395 static bool fpu_option_set = false;
397 /* Initialize the GCC target structure. */
399 /* The sparc default is to use .half rather than .short for aligned
400 HI objects. Use .word instead of .long on non-ELF systems. */
401 #undef TARGET_ASM_ALIGNED_HI_OP
402 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
403 #ifndef OBJECT_FORMAT_ELF
404 #undef TARGET_ASM_ALIGNED_SI_OP
405 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
408 #undef TARGET_ASM_UNALIGNED_HI_OP
409 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
410 #undef TARGET_ASM_UNALIGNED_SI_OP
411 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
412 #undef TARGET_ASM_UNALIGNED_DI_OP
413 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
415 /* The target hook has to handle DI-mode values. */
416 #undef TARGET_ASM_INTEGER
417 #define TARGET_ASM_INTEGER sparc_assemble_integer
419 #undef TARGET_ASM_FUNCTION_PROLOGUE
420 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
421 #undef TARGET_ASM_FUNCTION_EPILOGUE
422 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
424 #undef TARGET_SCHED_ADJUST_COST
425 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
426 #undef TARGET_SCHED_ISSUE_RATE
427 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
428 #undef TARGET_SCHED_INIT
429 #define TARGET_SCHED_INIT sparc_sched_init
430 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
431 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
433 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
434 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
436 #undef TARGET_INIT_LIBFUNCS
437 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
438 #undef TARGET_INIT_BUILTINS
439 #define TARGET_INIT_BUILTINS sparc_init_builtins
441 #undef TARGET_EXPAND_BUILTIN
442 #define TARGET_EXPAND_BUILTIN sparc_expand_builtin
445 #undef TARGET_HAVE_TLS
446 #define TARGET_HAVE_TLS true
448 #undef TARGET_CANNOT_FORCE_CONST_MEM
449 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
451 #undef TARGET_ASM_OUTPUT_MI_THUNK
452 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
453 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
454 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
456 #undef TARGET_RTX_COSTS
457 #define TARGET_RTX_COSTS sparc_rtx_costs
458 #undef TARGET_ADDRESS_COST
459 #define TARGET_ADDRESS_COST hook_int_rtx_0
461 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
462 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
463 test for this value. */
464 #undef TARGET_PROMOTE_FUNCTION_ARGS
465 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
467 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
468 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
469 test for this value. */
470 #undef TARGET_PROMOTE_FUNCTION_RETURN
471 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
473 #undef TARGET_PROMOTE_PROTOTYPES
474 #define TARGET_PROMOTE_PROTOTYPES sparc_promote_prototypes
476 #undef TARGET_STRUCT_VALUE_RTX
477 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
478 #undef TARGET_RETURN_IN_MEMORY
479 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
480 #undef TARGET_MUST_PASS_IN_STACK
481 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
482 #undef TARGET_PASS_BY_REFERENCE
483 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
484 #undef TARGET_ARG_PARTIAL_BYTES
485 #define TARGET_ARG_PARTIAL_BYTES sparc_arg_partial_bytes
487 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
488 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
489 #undef TARGET_STRICT_ARGUMENT_NAMING
490 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
492 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
493 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
495 #undef TARGET_VECTOR_MODE_SUPPORTED_P
496 #define TARGET_VECTOR_MODE_SUPPORTED_P sparc_vector_mode_supported_p
498 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
499 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC sparc_dwarf_handle_frame_unspec
501 #ifdef SUBTARGET_INSERT_ATTRIBUTES
502 #undef TARGET_INSERT_ATTRIBUTES
503 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
506 #ifdef SUBTARGET_ATTRIBUTE_TABLE
507 #undef TARGET_ATTRIBUTE_TABLE
508 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
511 #undef TARGET_RELAXED_ORDERING
512 #define TARGET_RELAXED_ORDERING SPARC_RELAXED_ORDERING
514 #undef TARGET_DEFAULT_TARGET_FLAGS
515 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
516 #undef TARGET_HANDLE_OPTION
517 #define TARGET_HANDLE_OPTION sparc_handle_option
519 #undef TARGET_ASM_FILE_END
520 #define TARGET_ASM_FILE_END sparc_file_end
522 struct gcc_target targetm = TARGET_INITIALIZER;
524 /* Implement TARGET_HANDLE_OPTION. */
527 sparc_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
532 case OPT_mhard_float:
533 case OPT_msoft_float:
534 fpu_option_set = true;
538 sparc_select[1].string = arg;
542 sparc_select[2].string = arg;
546 sparc_cmodel_string = arg;
553 /* Validate and override various options, and do some machine dependent
557 sparc_override_options (void)
559 static struct code_model {
560 const char *const name;
562 } const cmodels[] = {
564 { "medlow", CM_MEDLOW },
565 { "medmid", CM_MEDMID },
566 { "medany", CM_MEDANY },
567 { "embmedany", CM_EMBMEDANY },
570 const struct code_model *cmodel;
571 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
572 static struct cpu_default {
574 const char *const name;
575 } const cpu_default[] = {
576 /* There must be one entry here for each TARGET_CPU value. */
577 { TARGET_CPU_sparc, "cypress" },
578 { TARGET_CPU_sparclet, "tsc701" },
579 { TARGET_CPU_sparclite, "f930" },
580 { TARGET_CPU_v8, "v8" },
581 { TARGET_CPU_hypersparc, "hypersparc" },
582 { TARGET_CPU_sparclite86x, "sparclite86x" },
583 { TARGET_CPU_supersparc, "supersparc" },
584 { TARGET_CPU_v9, "v9" },
585 { TARGET_CPU_ultrasparc, "ultrasparc" },
586 { TARGET_CPU_ultrasparc3, "ultrasparc3" },
589 const struct cpu_default *def;
590 /* Table of values for -m{cpu,tune}=. */
591 static struct cpu_table {
592 const char *const name;
593 const enum processor_type processor;
596 } const cpu_table[] = {
597 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
598 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
599 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
600 /* TI TMS390Z55 supersparc */
601 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
602 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
603 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
604 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
605 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
606 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
607 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
608 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
610 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
612 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
613 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
614 /* TI ultrasparc I, II, IIi */
615 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
616 /* Although insns using %y are deprecated, it is a clear win on current
618 |MASK_DEPRECATED_V8_INSNS},
619 /* TI ultrasparc III */
620 /* ??? Check if %y issue still holds true in ultra3. */
621 { "ultrasparc3", PROCESSOR_ULTRASPARC3, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
624 const struct cpu_table *cpu;
625 const struct sparc_cpu_select *sel;
628 #ifndef SPARC_BI_ARCH
629 /* Check for unsupported architecture size. */
630 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
631 error ("%s is not supported by this configuration",
632 DEFAULT_ARCH32_P ? "-m64" : "-m32");
635 /* We force all 64bit archs to use 128 bit long double */
636 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
638 error ("-mlong-double-64 not allowed with -m64");
639 target_flags |= MASK_LONG_DOUBLE_128;
642 /* Code model selection. */
643 sparc_cmodel = SPARC_DEFAULT_CMODEL;
647 sparc_cmodel = CM_32;
650 if (sparc_cmodel_string != NULL)
654 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
655 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
657 if (cmodel->name == NULL)
658 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
660 sparc_cmodel = cmodel->value;
663 error ("-mcmodel= is not supported on 32 bit systems");
666 fpu = TARGET_FPU; /* save current -mfpu status */
668 /* Set the default CPU. */
669 for (def = &cpu_default[0]; def->name; ++def)
670 if (def->cpu == TARGET_CPU_DEFAULT)
672 gcc_assert (def->name);
673 sparc_select[0].string = def->name;
675 for (sel = &sparc_select[0]; sel->name; ++sel)
679 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
680 if (! strcmp (sel->string, cpu->name))
683 sparc_cpu = cpu->processor;
687 target_flags &= ~cpu->disable;
688 target_flags |= cpu->enable;
694 error ("bad value (%s) for %s switch", sel->string, sel->name);
698 /* If -mfpu or -mno-fpu was explicitly used, don't override with
699 the processor default. */
701 target_flags = (target_flags & ~MASK_FPU) | fpu;
703 /* Don't allow -mvis if FPU is disabled. */
705 target_flags &= ~MASK_VIS;
707 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
709 -m64 also implies v9. */
710 if (TARGET_VIS || TARGET_ARCH64)
712 target_flags |= MASK_V9;
713 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
716 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
717 if (TARGET_V9 && TARGET_ARCH32)
718 target_flags |= MASK_DEPRECATED_V8_INSNS;
720 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
721 if (! TARGET_V9 || TARGET_ARCH64)
722 target_flags &= ~MASK_V8PLUS;
724 /* Don't use stack biasing in 32 bit mode. */
726 target_flags &= ~MASK_STACK_BIAS;
728 /* Supply a default value for align_functions. */
729 if (align_functions == 0
730 && (sparc_cpu == PROCESSOR_ULTRASPARC
731 || sparc_cpu == PROCESSOR_ULTRASPARC3))
732 align_functions = 32;
734 /* Validate PCC_STRUCT_RETURN. */
735 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
736 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
738 /* Only use .uaxword when compiling for a 64-bit target. */
740 targetm.asm_out.unaligned_op.di = NULL;
742 /* Do various machine dependent initializations. */
745 /* Acquire unique alias sets for our private stuff. */
746 sparc_sr_alias_set = new_alias_set ();
747 struct_value_alias_set = new_alias_set ();
749 /* Set up function hooks. */
750 init_machine_status = sparc_init_machine_status;
755 case PROCESSOR_CYPRESS:
756 sparc_costs = &cypress_costs;
759 case PROCESSOR_SPARCLITE:
760 case PROCESSOR_SUPERSPARC:
761 sparc_costs = &supersparc_costs;
765 case PROCESSOR_HYPERSPARC:
766 case PROCESSOR_SPARCLITE86X:
767 sparc_costs = &hypersparc_costs;
769 case PROCESSOR_SPARCLET:
770 case PROCESSOR_TSC701:
771 sparc_costs = &sparclet_costs;
774 case PROCESSOR_ULTRASPARC:
775 sparc_costs = &ultrasparc_costs;
777 case PROCESSOR_ULTRASPARC3:
778 sparc_costs = &ultrasparc3_costs;
783 #ifdef SUBTARGET_ATTRIBUTE_TABLE
784 /* Table of valid machine attributes. */
785 const struct attribute_spec sparc_attribute_table[] =
787 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
788 SUBTARGET_ATTRIBUTE_TABLE,
789 { NULL, 0, 0, false, false, false, NULL }
793 /* Miscellaneous utilities. */
795 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
796 or branch on register contents instructions. */
799 v9_regcmp_p (enum rtx_code code)
801 return (code == EQ || code == NE || code == GE || code == LT
802 || code == LE || code == GT);
806 /* Operand constraints. */
808 /* Nonzero if OP is a floating point constant which can
809 be loaded into an integer register using a single
810 sethi instruction. */
815 if (GET_CODE (op) == CONST_DOUBLE)
820 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
821 REAL_VALUE_TO_TARGET_SINGLE (r, i);
822 return !SPARC_SIMM13_P (i) && SPARC_SETHI_P (i);
828 /* Nonzero if OP is a floating point constant which can
829 be loaded into an integer register using a single
835 if (GET_CODE (op) == CONST_DOUBLE)
840 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
841 REAL_VALUE_TO_TARGET_SINGLE (r, i);
842 return SPARC_SIMM13_P (i);
848 /* Nonzero if OP is a floating point constant which can
849 be loaded into an integer register using a high/losum
850 instruction sequence. */
853 fp_high_losum_p (rtx op)
855 /* The constraints calling this should only be in
856 SFmode move insns, so any constant which cannot
857 be moved using a single insn will do. */
858 if (GET_CODE (op) == CONST_DOUBLE)
863 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
864 REAL_VALUE_TO_TARGET_SINGLE (r, i);
865 return !SPARC_SIMM13_P (i) && !SPARC_SETHI_P (i);
871 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
872 otherwise return 0. */
875 tls_symbolic_operand (rtx op)
877 if (GET_CODE (op) != SYMBOL_REF)
879 return SYMBOL_REF_TLS_MODEL (op);
882 /* We know it can't be done in one insn when we get here,
883 the movsi expander guarantees this. */
885 sparc_emit_set_const32 (rtx op0, rtx op1)
887 enum machine_mode mode = GET_MODE (op0);
890 if (reload_in_progress || reload_completed)
893 temp = gen_reg_rtx (mode);
895 if (GET_CODE (op1) == CONST_INT)
897 gcc_assert (!small_int_operand (op1, mode)
898 && !const_high_operand (op1, mode));
900 /* Emit them as real moves instead of a HIGH/LO_SUM,
901 this way CSE can see everything and reuse intermediate
902 values if it wants. */
903 emit_insn (gen_rtx_SET (VOIDmode, temp,
904 GEN_INT (INTVAL (op1)
905 & ~(HOST_WIDE_INT)0x3ff)));
907 emit_insn (gen_rtx_SET (VOIDmode,
909 gen_rtx_IOR (mode, temp,
910 GEN_INT (INTVAL (op1) & 0x3ff))));
914 /* A symbol, emit in the traditional way. */
915 emit_insn (gen_rtx_SET (VOIDmode, temp,
916 gen_rtx_HIGH (mode, op1)));
917 emit_insn (gen_rtx_SET (VOIDmode,
918 op0, gen_rtx_LO_SUM (mode, temp, op1)));
923 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
924 If TEMP is nonzero, we are forbidden to use any other scratch
925 registers. Otherwise, we are allowed to generate them as needed.
927 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
928 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
930 sparc_emit_set_symbolic_const64 (rtx op0, rtx op1, rtx temp)
932 rtx temp1, temp2, temp3, temp4, temp5;
935 if (temp && GET_MODE (temp) == TImode)
938 temp = gen_rtx_REG (DImode, REGNO (temp));
941 /* SPARC-V9 code-model support. */
942 switch (sparc_cmodel)
945 /* The range spanned by all instructions in the object is less
946 than 2^31 bytes (2GB) and the distance from any instruction
947 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
948 than 2^31 bytes (2GB).
950 The executable must be in the low 4TB of the virtual address
953 sethi %hi(symbol), %temp1
954 or %temp1, %lo(symbol), %reg */
956 temp1 = temp; /* op0 is allowed. */
958 temp1 = gen_reg_rtx (DImode);
960 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
961 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
965 /* The range spanned by all instructions in the object is less
966 than 2^31 bytes (2GB) and the distance from any instruction
967 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
968 than 2^31 bytes (2GB).
970 The executable must be in the low 16TB of the virtual address
973 sethi %h44(symbol), %temp1
974 or %temp1, %m44(symbol), %temp2
975 sllx %temp2, 12, %temp3
976 or %temp3, %l44(symbol), %reg */
981 temp3 = temp; /* op0 is allowed. */
985 temp1 = gen_reg_rtx (DImode);
986 temp2 = gen_reg_rtx (DImode);
987 temp3 = gen_reg_rtx (DImode);
990 emit_insn (gen_seth44 (temp1, op1));
991 emit_insn (gen_setm44 (temp2, temp1, op1));
992 emit_insn (gen_rtx_SET (VOIDmode, temp3,
993 gen_rtx_ASHIFT (DImode, temp2, GEN_INT (12))));
994 emit_insn (gen_setl44 (op0, temp3, op1));
998 /* The range spanned by all instructions in the object is less
999 than 2^31 bytes (2GB) and the distance from any instruction
1000 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1001 than 2^31 bytes (2GB).
1003 The executable can be placed anywhere in the virtual address
1006 sethi %hh(symbol), %temp1
1007 sethi %lm(symbol), %temp2
1008 or %temp1, %hm(symbol), %temp3
1009 sllx %temp3, 32, %temp4
1010 or %temp4, %temp2, %temp5
1011 or %temp5, %lo(symbol), %reg */
1014 /* It is possible that one of the registers we got for operands[2]
1015 might coincide with that of operands[0] (which is why we made
1016 it TImode). Pick the other one to use as our scratch. */
1017 if (rtx_equal_p (temp, op0))
1019 gcc_assert (ti_temp);
1020 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1023 temp2 = temp; /* op0 is _not_ allowed, see above. */
1030 temp1 = gen_reg_rtx (DImode);
1031 temp2 = gen_reg_rtx (DImode);
1032 temp3 = gen_reg_rtx (DImode);
1033 temp4 = gen_reg_rtx (DImode);
1034 temp5 = gen_reg_rtx (DImode);
1037 emit_insn (gen_sethh (temp1, op1));
1038 emit_insn (gen_setlm (temp2, op1));
1039 emit_insn (gen_sethm (temp3, temp1, op1));
1040 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1041 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1042 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1043 gen_rtx_PLUS (DImode, temp4, temp2)));
1044 emit_insn (gen_setlo (op0, temp5, op1));
1048 /* Old old old backwards compatibility kruft here.
1049 Essentially it is MEDLOW with a fixed 64-bit
1050 virtual base added to all data segment addresses.
1051 Text-segment stuff is computed like MEDANY, we can't
1052 reuse the code above because the relocation knobs
1055 Data segment: sethi %hi(symbol), %temp1
1056 add %temp1, EMBMEDANY_BASE_REG, %temp2
1057 or %temp2, %lo(symbol), %reg */
1058 if (data_segment_operand (op1, GET_MODE (op1)))
1062 temp1 = temp; /* op0 is allowed. */
1067 temp1 = gen_reg_rtx (DImode);
1068 temp2 = gen_reg_rtx (DImode);
1071 emit_insn (gen_embmedany_sethi (temp1, op1));
1072 emit_insn (gen_embmedany_brsum (temp2, temp1));
1073 emit_insn (gen_embmedany_losum (op0, temp2, op1));
1076 /* Text segment: sethi %uhi(symbol), %temp1
1077 sethi %hi(symbol), %temp2
1078 or %temp1, %ulo(symbol), %temp3
1079 sllx %temp3, 32, %temp4
1080 or %temp4, %temp2, %temp5
1081 or %temp5, %lo(symbol), %reg */
1086 /* It is possible that one of the registers we got for operands[2]
1087 might coincide with that of operands[0] (which is why we made
1088 it TImode). Pick the other one to use as our scratch. */
1089 if (rtx_equal_p (temp, op0))
1091 gcc_assert (ti_temp);
1092 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1095 temp2 = temp; /* op0 is _not_ allowed, see above. */
1102 temp1 = gen_reg_rtx (DImode);
1103 temp2 = gen_reg_rtx (DImode);
1104 temp3 = gen_reg_rtx (DImode);
1105 temp4 = gen_reg_rtx (DImode);
1106 temp5 = gen_reg_rtx (DImode);
1109 emit_insn (gen_embmedany_textuhi (temp1, op1));
1110 emit_insn (gen_embmedany_texthi (temp2, op1));
1111 emit_insn (gen_embmedany_textulo (temp3, temp1, op1));
1112 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1113 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1114 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1115 gen_rtx_PLUS (DImode, temp4, temp2)));
1116 emit_insn (gen_embmedany_textlo (op0, temp5, op1));
1125 #if HOST_BITS_PER_WIDE_INT == 32
1127 sparc_emit_set_const64 (rtx op0 ATTRIBUTE_UNUSED, rtx op1 ATTRIBUTE_UNUSED)
1132 /* These avoid problems when cross compiling. If we do not
1133 go through all this hair then the optimizer will see
1134 invalid REG_EQUAL notes or in some cases none at all. */
1135 static rtx gen_safe_HIGH64 (rtx, HOST_WIDE_INT);
1136 static rtx gen_safe_SET64 (rtx, HOST_WIDE_INT);
1137 static rtx gen_safe_OR64 (rtx, HOST_WIDE_INT);
1138 static rtx gen_safe_XOR64 (rtx, HOST_WIDE_INT);
1140 /* The optimizer is not to assume anything about exactly
1141 which bits are set for a HIGH, they are unspecified.
1142 Unfortunately this leads to many missed optimizations
1143 during CSE. We mask out the non-HIGH bits, and matches
1144 a plain movdi, to alleviate this problem. */
1146 gen_safe_HIGH64 (rtx dest, HOST_WIDE_INT val)
1148 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val & ~(HOST_WIDE_INT)0x3ff));
1152 gen_safe_SET64 (rtx dest, HOST_WIDE_INT val)
1154 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val));
1158 gen_safe_OR64 (rtx src, HOST_WIDE_INT val)
1160 return gen_rtx_IOR (DImode, src, GEN_INT (val));
1164 gen_safe_XOR64 (rtx src, HOST_WIDE_INT val)
1166 return gen_rtx_XOR (DImode, src, GEN_INT (val));
1169 /* Worker routines for 64-bit constant formation on arch64.
1170 One of the key things to be doing in these emissions is
1171 to create as many temp REGs as possible. This makes it
1172 possible for half-built constants to be used later when
1173 such values are similar to something required later on.
1174 Without doing this, the optimizer cannot see such
1177 static void sparc_emit_set_const64_quick1 (rtx, rtx,
1178 unsigned HOST_WIDE_INT, int);
1181 sparc_emit_set_const64_quick1 (rtx op0, rtx temp,
1182 unsigned HOST_WIDE_INT low_bits, int is_neg)
1184 unsigned HOST_WIDE_INT high_bits;
1187 high_bits = (~low_bits) & 0xffffffff;
1189 high_bits = low_bits;
1191 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1194 emit_insn (gen_rtx_SET (VOIDmode, op0,
1195 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1199 /* If we are XOR'ing with -1, then we should emit a one's complement
1200 instead. This way the combiner will notice logical operations
1201 such as ANDN later on and substitute. */
1202 if ((low_bits & 0x3ff) == 0x3ff)
1204 emit_insn (gen_rtx_SET (VOIDmode, op0,
1205 gen_rtx_NOT (DImode, temp)));
1209 emit_insn (gen_rtx_SET (VOIDmode, op0,
1210 gen_safe_XOR64 (temp,
1211 (-(HOST_WIDE_INT)0x400
1212 | (low_bits & 0x3ff)))));
1217 static void sparc_emit_set_const64_quick2 (rtx, rtx, unsigned HOST_WIDE_INT,
1218 unsigned HOST_WIDE_INT, int);
1221 sparc_emit_set_const64_quick2 (rtx op0, rtx temp,
1222 unsigned HOST_WIDE_INT high_bits,
1223 unsigned HOST_WIDE_INT low_immediate,
1228 if ((high_bits & 0xfffffc00) != 0)
1230 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1231 if ((high_bits & ~0xfffffc00) != 0)
1232 emit_insn (gen_rtx_SET (VOIDmode, op0,
1233 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1239 emit_insn (gen_safe_SET64 (temp, high_bits));
1243 /* Now shift it up into place. */
1244 emit_insn (gen_rtx_SET (VOIDmode, op0,
1245 gen_rtx_ASHIFT (DImode, temp2,
1246 GEN_INT (shift_count))));
1248 /* If there is a low immediate part piece, finish up by
1249 putting that in as well. */
1250 if (low_immediate != 0)
1251 emit_insn (gen_rtx_SET (VOIDmode, op0,
1252 gen_safe_OR64 (op0, low_immediate)));
1255 static void sparc_emit_set_const64_longway (rtx, rtx, unsigned HOST_WIDE_INT,
1256 unsigned HOST_WIDE_INT);
1258 /* Full 64-bit constant decomposition. Even though this is the
1259 'worst' case, we still optimize a few things away. */
1261 sparc_emit_set_const64_longway (rtx op0, rtx temp,
1262 unsigned HOST_WIDE_INT high_bits,
1263 unsigned HOST_WIDE_INT low_bits)
1267 if (reload_in_progress || reload_completed)
1270 sub_temp = gen_reg_rtx (DImode);
1272 if ((high_bits & 0xfffffc00) != 0)
1274 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1275 if ((high_bits & ~0xfffffc00) != 0)
1276 emit_insn (gen_rtx_SET (VOIDmode,
1278 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1284 emit_insn (gen_safe_SET64 (temp, high_bits));
1288 if (!reload_in_progress && !reload_completed)
1290 rtx temp2 = gen_reg_rtx (DImode);
1291 rtx temp3 = gen_reg_rtx (DImode);
1292 rtx temp4 = gen_reg_rtx (DImode);
1294 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1295 gen_rtx_ASHIFT (DImode, sub_temp,
1298 emit_insn (gen_safe_HIGH64 (temp2, low_bits));
1299 if ((low_bits & ~0xfffffc00) != 0)
1301 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1302 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1303 emit_insn (gen_rtx_SET (VOIDmode, op0,
1304 gen_rtx_PLUS (DImode, temp4, temp3)));
1308 emit_insn (gen_rtx_SET (VOIDmode, op0,
1309 gen_rtx_PLUS (DImode, temp4, temp2)));
1314 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1315 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1316 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1319 /* We are in the middle of reload, so this is really
1320 painful. However we do still make an attempt to
1321 avoid emitting truly stupid code. */
1322 if (low1 != const0_rtx)
1324 emit_insn (gen_rtx_SET (VOIDmode, op0,
1325 gen_rtx_ASHIFT (DImode, sub_temp,
1326 GEN_INT (to_shift))));
1327 emit_insn (gen_rtx_SET (VOIDmode, op0,
1328 gen_rtx_IOR (DImode, op0, low1)));
1336 if (low2 != const0_rtx)
1338 emit_insn (gen_rtx_SET (VOIDmode, op0,
1339 gen_rtx_ASHIFT (DImode, sub_temp,
1340 GEN_INT (to_shift))));
1341 emit_insn (gen_rtx_SET (VOIDmode, op0,
1342 gen_rtx_IOR (DImode, op0, low2)));
1350 emit_insn (gen_rtx_SET (VOIDmode, op0,
1351 gen_rtx_ASHIFT (DImode, sub_temp,
1352 GEN_INT (to_shift))));
1353 if (low3 != const0_rtx)
1354 emit_insn (gen_rtx_SET (VOIDmode, op0,
1355 gen_rtx_IOR (DImode, op0, low3)));
1360 /* Analyze a 64-bit constant for certain properties. */
1361 static void analyze_64bit_constant (unsigned HOST_WIDE_INT,
1362 unsigned HOST_WIDE_INT,
1363 int *, int *, int *);
1366 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits,
1367 unsigned HOST_WIDE_INT low_bits,
1368 int *hbsp, int *lbsp, int *abbasp)
1370 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1373 lowest_bit_set = highest_bit_set = -1;
1377 if ((lowest_bit_set == -1)
1378 && ((low_bits >> i) & 1))
1380 if ((highest_bit_set == -1)
1381 && ((high_bits >> (32 - i - 1)) & 1))
1382 highest_bit_set = (64 - i - 1);
1385 && ((highest_bit_set == -1)
1386 || (lowest_bit_set == -1)));
1392 if ((lowest_bit_set == -1)
1393 && ((high_bits >> i) & 1))
1394 lowest_bit_set = i + 32;
1395 if ((highest_bit_set == -1)
1396 && ((low_bits >> (32 - i - 1)) & 1))
1397 highest_bit_set = 32 - i - 1;
1400 && ((highest_bit_set == -1)
1401 || (lowest_bit_set == -1)));
1403 /* If there are no bits set this should have gone out
1404 as one instruction! */
1405 gcc_assert (lowest_bit_set != -1 && highest_bit_set != -1);
1406 all_bits_between_are_set = 1;
1407 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1411 if ((low_bits & (1 << i)) != 0)
1416 if ((high_bits & (1 << (i - 32))) != 0)
1419 all_bits_between_are_set = 0;
1422 *hbsp = highest_bit_set;
1423 *lbsp = lowest_bit_set;
1424 *abbasp = all_bits_between_are_set;
1427 static int const64_is_2insns (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
1430 const64_is_2insns (unsigned HOST_WIDE_INT high_bits,
1431 unsigned HOST_WIDE_INT low_bits)
1433 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1436 || high_bits == 0xffffffff)
1439 analyze_64bit_constant (high_bits, low_bits,
1440 &highest_bit_set, &lowest_bit_set,
1441 &all_bits_between_are_set);
1443 if ((highest_bit_set == 63
1444 || lowest_bit_set == 0)
1445 && all_bits_between_are_set != 0)
1448 if ((highest_bit_set - lowest_bit_set) < 21)
1454 static unsigned HOST_WIDE_INT create_simple_focus_bits (unsigned HOST_WIDE_INT,
1455 unsigned HOST_WIDE_INT,
1458 static unsigned HOST_WIDE_INT
1459 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits,
1460 unsigned HOST_WIDE_INT low_bits,
1461 int lowest_bit_set, int shift)
1463 HOST_WIDE_INT hi, lo;
1465 if (lowest_bit_set < 32)
1467 lo = (low_bits >> lowest_bit_set) << shift;
1468 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
1473 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
1475 gcc_assert (! (hi & lo));
1479 /* Here we are sure to be arch64 and this is an integer constant
1480 being loaded into a register. Emit the most efficient
1481 insn sequence possible. Detection of all the 1-insn cases
1482 has been done already. */
1484 sparc_emit_set_const64 (rtx op0, rtx op1)
1486 unsigned HOST_WIDE_INT high_bits, low_bits;
1487 int lowest_bit_set, highest_bit_set;
1488 int all_bits_between_are_set;
1491 /* Sanity check that we know what we are working with. */
1492 gcc_assert (TARGET_ARCH64);
1494 if (GET_CODE (op0) != SUBREG)
1496 gcc_assert (GET_CODE (op0) == REG
1497 && (REGNO (op0) < SPARC_FIRST_FP_REG
1498 || REGNO (op0) > SPARC_LAST_V9_FP_REG));
1501 if (reload_in_progress || reload_completed)
1504 if (GET_CODE (op1) != CONST_INT)
1506 sparc_emit_set_symbolic_const64 (op0, op1, temp);
1511 temp = gen_reg_rtx (DImode);
1513 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
1514 low_bits = (INTVAL (op1) & 0xffffffff);
1516 /* low_bits bits 0 --> 31
1517 high_bits bits 32 --> 63 */
1519 analyze_64bit_constant (high_bits, low_bits,
1520 &highest_bit_set, &lowest_bit_set,
1521 &all_bits_between_are_set);
1523 /* First try for a 2-insn sequence. */
1525 /* These situations are preferred because the optimizer can
1526 * do more things with them:
1528 * sllx %reg, shift, %reg
1530 * srlx %reg, shift, %reg
1531 * 3) mov some_small_const, %reg
1532 * sllx %reg, shift, %reg
1534 if (((highest_bit_set == 63
1535 || lowest_bit_set == 0)
1536 && all_bits_between_are_set != 0)
1537 || ((highest_bit_set - lowest_bit_set) < 12))
1539 HOST_WIDE_INT the_const = -1;
1540 int shift = lowest_bit_set;
1542 if ((highest_bit_set != 63
1543 && lowest_bit_set != 0)
1544 || all_bits_between_are_set == 0)
1547 create_simple_focus_bits (high_bits, low_bits,
1550 else if (lowest_bit_set == 0)
1551 shift = -(63 - highest_bit_set);
1553 gcc_assert (SPARC_SIMM13_P (the_const));
1554 gcc_assert (shift != 0);
1556 emit_insn (gen_safe_SET64 (temp, the_const));
1558 emit_insn (gen_rtx_SET (VOIDmode,
1560 gen_rtx_ASHIFT (DImode,
1564 emit_insn (gen_rtx_SET (VOIDmode,
1566 gen_rtx_LSHIFTRT (DImode,
1568 GEN_INT (-shift))));
1572 /* Now a range of 22 or less bits set somewhere.
1573 * 1) sethi %hi(focus_bits), %reg
1574 * sllx %reg, shift, %reg
1575 * 2) sethi %hi(focus_bits), %reg
1576 * srlx %reg, shift, %reg
1578 if ((highest_bit_set - lowest_bit_set) < 21)
1580 unsigned HOST_WIDE_INT focus_bits =
1581 create_simple_focus_bits (high_bits, low_bits,
1582 lowest_bit_set, 10);
1584 gcc_assert (SPARC_SETHI_P (focus_bits));
1585 gcc_assert (lowest_bit_set != 10);
1587 emit_insn (gen_safe_HIGH64 (temp, focus_bits));
1589 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
1590 if (lowest_bit_set < 10)
1591 emit_insn (gen_rtx_SET (VOIDmode,
1593 gen_rtx_LSHIFTRT (DImode, temp,
1594 GEN_INT (10 - lowest_bit_set))));
1595 else if (lowest_bit_set > 10)
1596 emit_insn (gen_rtx_SET (VOIDmode,
1598 gen_rtx_ASHIFT (DImode, temp,
1599 GEN_INT (lowest_bit_set - 10))));
1603 /* 1) sethi %hi(low_bits), %reg
1604 * or %reg, %lo(low_bits), %reg
1605 * 2) sethi %hi(~low_bits), %reg
1606 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
1609 || high_bits == 0xffffffff)
1611 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
1612 (high_bits == 0xffffffff));
1616 /* Now, try 3-insn sequences. */
1618 /* 1) sethi %hi(high_bits), %reg
1619 * or %reg, %lo(high_bits), %reg
1620 * sllx %reg, 32, %reg
1624 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
1628 /* We may be able to do something quick
1629 when the constant is negated, so try that. */
1630 if (const64_is_2insns ((~high_bits) & 0xffffffff,
1631 (~low_bits) & 0xfffffc00))
1633 /* NOTE: The trailing bits get XOR'd so we need the
1634 non-negated bits, not the negated ones. */
1635 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
1637 if ((((~high_bits) & 0xffffffff) == 0
1638 && ((~low_bits) & 0x80000000) == 0)
1639 || (((~high_bits) & 0xffffffff) == 0xffffffff
1640 && ((~low_bits) & 0x80000000) != 0))
1642 unsigned HOST_WIDE_INT fast_int = (~low_bits & 0xffffffff);
1644 if ((SPARC_SETHI_P (fast_int)
1645 && (~high_bits & 0xffffffff) == 0)
1646 || SPARC_SIMM13_P (fast_int))
1647 emit_insn (gen_safe_SET64 (temp, fast_int));
1649 sparc_emit_set_const64 (temp, GEN_INT (fast_int));
1654 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
1655 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
1656 sparc_emit_set_const64 (temp, negated_const);
1659 /* If we are XOR'ing with -1, then we should emit a one's complement
1660 instead. This way the combiner will notice logical operations
1661 such as ANDN later on and substitute. */
1662 if (trailing_bits == 0x3ff)
1664 emit_insn (gen_rtx_SET (VOIDmode, op0,
1665 gen_rtx_NOT (DImode, temp)));
1669 emit_insn (gen_rtx_SET (VOIDmode,
1671 gen_safe_XOR64 (temp,
1672 (-0x400 | trailing_bits))));
1677 /* 1) sethi %hi(xxx), %reg
1678 * or %reg, %lo(xxx), %reg
1679 * sllx %reg, yyy, %reg
1681 * ??? This is just a generalized version of the low_bits==0
1682 * thing above, FIXME...
1684 if ((highest_bit_set - lowest_bit_set) < 32)
1686 unsigned HOST_WIDE_INT focus_bits =
1687 create_simple_focus_bits (high_bits, low_bits,
1690 /* We can't get here in this state. */
1691 gcc_assert (highest_bit_set >= 32 && lowest_bit_set < 32);
1693 /* So what we know is that the set bits straddle the
1694 middle of the 64-bit word. */
1695 sparc_emit_set_const64_quick2 (op0, temp,
1701 /* 1) sethi %hi(high_bits), %reg
1702 * or %reg, %lo(high_bits), %reg
1703 * sllx %reg, 32, %reg
1704 * or %reg, low_bits, %reg
1706 if (SPARC_SIMM13_P(low_bits)
1707 && ((int)low_bits > 0))
1709 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
1713 /* The easiest way when all else fails, is full decomposition. */
1715 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
1716 high_bits, low_bits, ~high_bits, ~low_bits);
1718 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
1720 #endif /* HOST_BITS_PER_WIDE_INT == 32 */
1722 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
1723 return the mode to be used for the comparison. For floating-point,
1724 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
1725 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
1726 processing is needed. */
1729 select_cc_mode (enum rtx_code op, rtx x, rtx y ATTRIBUTE_UNUSED)
1731 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1757 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
1758 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
1760 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
1761 return CCX_NOOVmode;
1767 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
1774 /* X and Y are two things to compare using CODE. Emit the compare insn and
1775 return the rtx for the cc reg in the proper mode. */
1778 gen_compare_reg (enum rtx_code code, rtx x, rtx y)
1780 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
1783 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
1784 fcc regs (cse can't tell they're really call clobbered regs and will
1785 remove a duplicate comparison even if there is an intervening function
1786 call - it will then try to reload the cc reg via an int reg which is why
1787 we need the movcc patterns). It is possible to provide the movcc
1788 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
1789 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
1790 to tell cse that CCFPE mode registers (even pseudos) are call
1793 /* ??? This is an experiment. Rather than making changes to cse which may
1794 or may not be easy/clean, we do our own cse. This is possible because
1795 we will generate hard registers. Cse knows they're call clobbered (it
1796 doesn't know the same thing about pseudos). If we guess wrong, no big
1797 deal, but if we win, great! */
1799 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1800 #if 1 /* experiment */
1803 /* We cycle through the registers to ensure they're all exercised. */
1804 static int next_fcc_reg = 0;
1805 /* Previous x,y for each fcc reg. */
1806 static rtx prev_args[4][2];
1808 /* Scan prev_args for x,y. */
1809 for (reg = 0; reg < 4; reg++)
1810 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
1815 prev_args[reg][0] = x;
1816 prev_args[reg][1] = y;
1817 next_fcc_reg = (next_fcc_reg + 1) & 3;
1819 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
1822 cc_reg = gen_reg_rtx (mode);
1823 #endif /* ! experiment */
1824 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1825 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
1827 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
1829 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
1830 gen_rtx_COMPARE (mode, x, y)));
1835 /* This function is used for v9 only.
1836 CODE is the code for an Scc's comparison.
1837 OPERANDS[0] is the target of the Scc insn.
1838 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
1839 been generated yet).
1841 This function is needed to turn
1844 (gt (reg:CCX 100 %icc)
1848 (gt:DI (reg:CCX 100 %icc)
1851 IE: The instruction recognizer needs to see the mode of the comparison to
1852 find the right instruction. We could use "gt:DI" right in the
1853 define_expand, but leaving it out allows us to handle DI, SI, etc.
1855 We refer to the global sparc compare operands sparc_compare_op0 and
1856 sparc_compare_op1. */
1859 gen_v9_scc (enum rtx_code compare_code, register rtx *operands)
1864 && (GET_MODE (sparc_compare_op0) == DImode
1865 || GET_MODE (operands[0]) == DImode))
1868 op0 = sparc_compare_op0;
1869 op1 = sparc_compare_op1;
1871 /* Try to use the movrCC insns. */
1873 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
1874 && op1 == const0_rtx
1875 && v9_regcmp_p (compare_code))
1877 /* Special case for op0 != 0. This can be done with one instruction if
1878 operands[0] == sparc_compare_op0. */
1880 if (compare_code == NE
1881 && GET_MODE (operands[0]) == DImode
1882 && rtx_equal_p (op0, operands[0]))
1884 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
1885 gen_rtx_IF_THEN_ELSE (DImode,
1886 gen_rtx_fmt_ee (compare_code, DImode,
1893 if (reg_overlap_mentioned_p (operands[0], op0))
1895 /* Handle the case where operands[0] == sparc_compare_op0.
1896 We "early clobber" the result. */
1897 op0 = gen_reg_rtx (GET_MODE (sparc_compare_op0));
1898 emit_move_insn (op0, sparc_compare_op0);
1901 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
1902 if (GET_MODE (op0) != DImode)
1904 temp = gen_reg_rtx (DImode);
1905 convert_move (temp, op0, 0);
1909 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
1910 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
1911 gen_rtx_fmt_ee (compare_code, DImode,
1919 operands[1] = gen_compare_reg (compare_code, op0, op1);
1921 switch (GET_MODE (operands[1]))
1931 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
1932 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
1933 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
1934 gen_rtx_fmt_ee (compare_code,
1935 GET_MODE (operands[1]),
1936 operands[1], const0_rtx),
1937 const1_rtx, operands[0])));
1942 /* Emit a conditional jump insn for the v9 architecture using comparison code
1943 CODE and jump target LABEL.
1944 This function exists to take advantage of the v9 brxx insns. */
1947 emit_v9_brxx_insn (enum rtx_code code, rtx op0, rtx label)
1949 emit_jump_insn (gen_rtx_SET (VOIDmode,
1951 gen_rtx_IF_THEN_ELSE (VOIDmode,
1952 gen_rtx_fmt_ee (code, GET_MODE (op0),
1954 gen_rtx_LABEL_REF (VOIDmode, label),
1958 /* Generate a DFmode part of a hard TFmode register.
1959 REG is the TFmode hard register, LOW is 1 for the
1960 low 64bit of the register and 0 otherwise.
1963 gen_df_reg (rtx reg, int low)
1965 int regno = REGNO (reg);
1967 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
1968 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
1969 return gen_rtx_REG (DFmode, regno);
1972 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
1973 Unlike normal calls, TFmode operands are passed by reference. It is
1974 assumed that no more than 3 operands are required. */
1977 emit_soft_tfmode_libcall (const char *func_name, int nargs, rtx *operands)
1979 rtx ret_slot = NULL, arg[3], func_sym;
1982 /* We only expect to be called for conversions, unary, and binary ops. */
1983 gcc_assert (nargs == 2 || nargs == 3);
1985 for (i = 0; i < nargs; ++i)
1987 rtx this_arg = operands[i];
1990 /* TFmode arguments and return values are passed by reference. */
1991 if (GET_MODE (this_arg) == TFmode)
1993 int force_stack_temp;
1995 force_stack_temp = 0;
1996 if (TARGET_BUGGY_QP_LIB && i == 0)
1997 force_stack_temp = 1;
1999 if (GET_CODE (this_arg) == MEM
2000 && ! force_stack_temp)
2001 this_arg = XEXP (this_arg, 0);
2002 else if (CONSTANT_P (this_arg)
2003 && ! force_stack_temp)
2005 this_slot = force_const_mem (TFmode, this_arg);
2006 this_arg = XEXP (this_slot, 0);
2010 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode), 0);
2012 /* Operand 0 is the return value. We'll copy it out later. */
2014 emit_move_insn (this_slot, this_arg);
2016 ret_slot = this_slot;
2018 this_arg = XEXP (this_slot, 0);
2025 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
2027 if (GET_MODE (operands[0]) == TFmode)
2030 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
2031 arg[0], GET_MODE (arg[0]),
2032 arg[1], GET_MODE (arg[1]));
2034 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
2035 arg[0], GET_MODE (arg[0]),
2036 arg[1], GET_MODE (arg[1]),
2037 arg[2], GET_MODE (arg[2]));
2040 emit_move_insn (operands[0], ret_slot);
2046 gcc_assert (nargs == 2);
2048 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
2049 GET_MODE (operands[0]), 1,
2050 arg[1], GET_MODE (arg[1]));
2052 if (ret != operands[0])
2053 emit_move_insn (operands[0], ret);
2057 /* Expand soft-float TFmode calls to sparc abi routines. */
2060 emit_soft_tfmode_binop (enum rtx_code code, rtx *operands)
2082 emit_soft_tfmode_libcall (func, 3, operands);
2086 emit_soft_tfmode_unop (enum rtx_code code, rtx *operands)
2090 gcc_assert (code == SQRT);
2093 emit_soft_tfmode_libcall (func, 2, operands);
2097 emit_soft_tfmode_cvt (enum rtx_code code, rtx *operands)
2104 switch (GET_MODE (operands[1]))
2117 case FLOAT_TRUNCATE:
2118 switch (GET_MODE (operands[0]))
2132 switch (GET_MODE (operands[1]))
2145 case UNSIGNED_FLOAT:
2146 switch (GET_MODE (operands[1]))
2160 switch (GET_MODE (operands[0]))
2174 switch (GET_MODE (operands[0]))
2191 emit_soft_tfmode_libcall (func, 2, operands);
2194 /* Expand a hard-float tfmode operation. All arguments must be in
2198 emit_hard_tfmode_operation (enum rtx_code code, rtx *operands)
2202 if (GET_RTX_CLASS (code) == RTX_UNARY)
2204 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2205 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
2209 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2210 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
2211 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
2212 operands[1], operands[2]);
2215 if (register_operand (operands[0], VOIDmode))
2218 dest = gen_reg_rtx (GET_MODE (operands[0]));
2220 emit_insn (gen_rtx_SET (VOIDmode, dest, op));
2222 if (dest != operands[0])
2223 emit_move_insn (operands[0], dest);
2227 emit_tfmode_binop (enum rtx_code code, rtx *operands)
2229 if (TARGET_HARD_QUAD)
2230 emit_hard_tfmode_operation (code, operands);
2232 emit_soft_tfmode_binop (code, operands);
2236 emit_tfmode_unop (enum rtx_code code, rtx *operands)
2238 if (TARGET_HARD_QUAD)
2239 emit_hard_tfmode_operation (code, operands);
2241 emit_soft_tfmode_unop (code, operands);
2245 emit_tfmode_cvt (enum rtx_code code, rtx *operands)
2247 if (TARGET_HARD_QUAD)
2248 emit_hard_tfmode_operation (code, operands);
2250 emit_soft_tfmode_cvt (code, operands);
2253 /* Return nonzero if a branch/jump/call instruction will be emitting
2254 nop into its delay slot. */
2257 empty_delay_slot (rtx insn)
2261 /* If no previous instruction (should not happen), return true. */
2262 if (PREV_INSN (insn) == NULL)
2265 seq = NEXT_INSN (PREV_INSN (insn));
2266 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
2272 /* Return nonzero if TRIAL can go into the call delay slot. */
2275 tls_call_delay (rtx trial)
2280 call __tls_get_addr, %tgd_call (foo)
2281 add %l7, %o0, %o0, %tgd_add (foo)
2282 while Sun as/ld does not. */
2283 if (TARGET_GNU_TLS || !TARGET_TLS)
2286 pat = PATTERN (trial);
2287 if (GET_CODE (pat) != SET || GET_CODE (SET_DEST (pat)) != PLUS)
2290 unspec = XEXP (SET_DEST (pat), 1);
2291 if (GET_CODE (unspec) != UNSPEC
2292 || (XINT (unspec, 1) != UNSPEC_TLSGD
2293 && XINT (unspec, 1) != UNSPEC_TLSLDM))
2299 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
2300 instruction. RETURN_P is true if the v9 variant 'return' is to be
2301 considered in the test too.
2303 TRIAL must be a SET whose destination is a REG appropriate for the
2304 'restore' instruction or, if RETURN_P is true, for the 'return'
2308 eligible_for_restore_insn (rtx trial, bool return_p)
2310 rtx pat = PATTERN (trial);
2311 rtx src = SET_SRC (pat);
2313 /* The 'restore src,%g0,dest' pattern for word mode and below. */
2314 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2315 && arith_operand (src, GET_MODE (src)))
2318 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2320 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2323 /* The 'restore src,%g0,dest' pattern for double-word mode. */
2324 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2325 && arith_double_operand (src, GET_MODE (src)))
2326 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2328 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
2329 else if (! TARGET_FPU && register_operand (src, SFmode))
2332 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
2333 else if (! TARGET_FPU && TARGET_ARCH64 && register_operand (src, DFmode))
2336 /* If we have the 'return' instruction, anything that does not use
2337 local or output registers and can go into a delay slot wins. */
2338 else if (return_p && TARGET_V9 && ! epilogue_renumber (&pat, 1)
2339 && (get_attr_in_uncond_branch_delay (trial)
2340 == IN_UNCOND_BRANCH_DELAY_TRUE))
2343 /* The 'restore src1,src2,dest' pattern for SImode. */
2344 else if (GET_CODE (src) == PLUS
2345 && register_operand (XEXP (src, 0), SImode)
2346 && arith_operand (XEXP (src, 1), SImode))
2349 /* The 'restore src1,src2,dest' pattern for DImode. */
2350 else if (GET_CODE (src) == PLUS
2351 && register_operand (XEXP (src, 0), DImode)
2352 && arith_double_operand (XEXP (src, 1), DImode))
2355 /* The 'restore src1,%lo(src2),dest' pattern. */
2356 else if (GET_CODE (src) == LO_SUM
2357 && ! TARGET_CM_MEDMID
2358 && ((register_operand (XEXP (src, 0), SImode)
2359 && immediate_operand (XEXP (src, 1), SImode))
2361 && register_operand (XEXP (src, 0), DImode)
2362 && immediate_operand (XEXP (src, 1), DImode))))
2365 /* The 'restore src,src,dest' pattern. */
2366 else if (GET_CODE (src) == ASHIFT
2367 && (register_operand (XEXP (src, 0), SImode)
2368 || register_operand (XEXP (src, 0), DImode))
2369 && XEXP (src, 1) == const1_rtx)
2375 /* Return nonzero if TRIAL can go into the function return's
2379 eligible_for_return_delay (rtx trial)
2383 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2386 if (get_attr_length (trial) != 1)
2389 /* If there are any call-saved registers, we should scan TRIAL if it
2390 does not reference them. For now just make it easy. */
2394 /* If the function uses __builtin_eh_return, the eh_return machinery
2395 occupies the delay slot. */
2396 if (current_function_calls_eh_return)
2399 /* In the case of a true leaf function, anything can go into the slot. */
2400 if (sparc_leaf_function_p)
2401 return get_attr_in_uncond_branch_delay (trial)
2402 == IN_UNCOND_BRANCH_DELAY_TRUE;
2404 pat = PATTERN (trial);
2406 /* Otherwise, only operations which can be done in tandem with
2407 a `restore' or `return' insn can go into the delay slot. */
2408 if (GET_CODE (SET_DEST (pat)) != REG
2409 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24))
2412 /* If this instruction sets up floating point register and we have a return
2413 instruction, it can probably go in. But restore will not work
2415 if (REGNO (SET_DEST (pat)) >= 32)
2417 && ! epilogue_renumber (&pat, 1)
2418 && (get_attr_in_uncond_branch_delay (trial)
2419 == IN_UNCOND_BRANCH_DELAY_TRUE));
2421 return eligible_for_restore_insn (trial, true);
2424 /* Return nonzero if TRIAL can go into the sibling call's
2428 eligible_for_sibcall_delay (rtx trial)
2432 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2435 if (get_attr_length (trial) != 1)
2438 pat = PATTERN (trial);
2440 if (sparc_leaf_function_p)
2442 /* If the tail call is done using the call instruction,
2443 we have to restore %o7 in the delay slot. */
2444 if (LEAF_SIBCALL_SLOT_RESERVED_P)
2447 /* %g1 is used to build the function address */
2448 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
2454 /* Otherwise, only operations which can be done in tandem with
2455 a `restore' insn can go into the delay slot. */
2456 if (GET_CODE (SET_DEST (pat)) != REG
2457 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24)
2458 || REGNO (SET_DEST (pat)) >= 32)
2461 /* If it mentions %o7, it can't go in, because sibcall will clobber it
2463 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
2466 return eligible_for_restore_insn (trial, false);
2470 short_branch (int uid1, int uid2)
2472 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
2474 /* Leave a few words of "slop". */
2475 if (delta >= -1023 && delta <= 1022)
2481 /* Return nonzero if REG is not used after INSN.
2482 We assume REG is a reload reg, and therefore does
2483 not live past labels or calls or jumps. */
2485 reg_unused_after (rtx reg, rtx insn)
2487 enum rtx_code code, prev_code = UNKNOWN;
2489 while ((insn = NEXT_INSN (insn)))
2491 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
2494 code = GET_CODE (insn);
2495 if (GET_CODE (insn) == CODE_LABEL)
2500 rtx set = single_set (insn);
2501 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
2504 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
2506 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
2514 /* Determine if it's legal to put X into the constant pool. This
2515 is not possible if X contains the address of a symbol that is
2516 not constant (TLS) or not known at final link time (PIC). */
2519 sparc_cannot_force_const_mem (rtx x)
2521 switch (GET_CODE (x))
2526 /* Accept all non-symbolic constants. */
2530 /* Labels are OK iff we are non-PIC. */
2531 return flag_pic != 0;
2534 /* 'Naked' TLS symbol references are never OK,
2535 non-TLS symbols are OK iff we are non-PIC. */
2536 if (SYMBOL_REF_TLS_MODEL (x))
2539 return flag_pic != 0;
2542 return sparc_cannot_force_const_mem (XEXP (x, 0));
2545 return sparc_cannot_force_const_mem (XEXP (x, 0))
2546 || sparc_cannot_force_const_mem (XEXP (x, 1));
2555 static GTY(()) char pic_helper_symbol_name[256];
2556 static GTY(()) rtx pic_helper_symbol;
2557 static GTY(()) bool pic_helper_emitted_p = false;
2558 static GTY(()) rtx global_offset_table;
2560 /* Ensure that we are not using patterns that are not OK with PIC. */
2568 gcc_assert (GET_CODE (recog_data.operand[i]) != SYMBOL_REF
2569 && (GET_CODE (recog_data.operand[i]) != CONST
2570 || (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
2571 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
2572 == global_offset_table)
2573 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
2581 /* Return true if X is an address which needs a temporary register when
2582 reloaded while generating PIC code. */
2585 pic_address_needs_scratch (rtx x)
2587 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
2588 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2589 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2590 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2591 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
2597 /* Determine if a given RTX is a valid constant. We already know this
2598 satisfies CONSTANT_P. */
2601 legitimate_constant_p (rtx x)
2605 switch (GET_CODE (x))
2608 /* TLS symbols are not constant. */
2609 if (SYMBOL_REF_TLS_MODEL (x))
2614 inner = XEXP (x, 0);
2616 /* Offsets of TLS symbols are never valid.
2617 Discourage CSE from creating them. */
2618 if (GET_CODE (inner) == PLUS
2619 && tls_symbolic_operand (XEXP (inner, 0)))
2624 if (GET_MODE (x) == VOIDmode)
2627 /* Floating point constants are generally not ok.
2628 The only exception is 0.0 in VIS. */
2630 && (GET_MODE (x) == SFmode
2631 || GET_MODE (x) == DFmode
2632 || GET_MODE (x) == TFmode)
2633 && const_zero_operand (x, GET_MODE (x)))
2645 /* Determine if a given RTX is a valid constant address. */
2648 constant_address_p (rtx x)
2650 switch (GET_CODE (x))
2658 if (flag_pic && pic_address_needs_scratch (x))
2660 return legitimate_constant_p (x);
2663 return !flag_pic && legitimate_constant_p (x);
2670 /* Nonzero if the constant value X is a legitimate general operand
2671 when generating PIC code. It is given that flag_pic is on and
2672 that X satisfies CONSTANT_P or is a CONST_DOUBLE. */
2675 legitimate_pic_operand_p (rtx x)
2677 if (pic_address_needs_scratch (x))
2679 if (tls_symbolic_operand (x)
2680 || (GET_CODE (x) == CONST
2681 && GET_CODE (XEXP (x, 0)) == PLUS
2682 && tls_symbolic_operand (XEXP (XEXP (x, 0), 0))))
2687 /* Return nonzero if ADDR is a valid memory address.
2688 STRICT specifies whether strict register checking applies. */
2691 legitimate_address_p (enum machine_mode mode, rtx addr, int strict)
2693 rtx rs1 = NULL, rs2 = NULL, imm1 = NULL;
2695 if (REG_P (addr) || GET_CODE (addr) == SUBREG)
2697 else if (GET_CODE (addr) == PLUS)
2699 rs1 = XEXP (addr, 0);
2700 rs2 = XEXP (addr, 1);
2702 /* Canonicalize. REG comes first, if there are no regs,
2703 LO_SUM comes first. */
2705 && GET_CODE (rs1) != SUBREG
2707 || GET_CODE (rs2) == SUBREG
2708 || (GET_CODE (rs2) == LO_SUM && GET_CODE (rs1) != LO_SUM)))
2710 rs1 = XEXP (addr, 1);
2711 rs2 = XEXP (addr, 0);
2715 && rs1 == pic_offset_table_rtx
2717 && GET_CODE (rs2) != SUBREG
2718 && GET_CODE (rs2) != LO_SUM
2719 && GET_CODE (rs2) != MEM
2720 && !tls_symbolic_operand (rs2)
2721 && (! symbolic_operand (rs2, VOIDmode) || mode == Pmode)
2722 && (GET_CODE (rs2) != CONST_INT || SMALL_INT (rs2)))
2724 || GET_CODE (rs1) == SUBREG)
2725 && RTX_OK_FOR_OFFSET_P (rs2)))
2730 else if ((REG_P (rs1) || GET_CODE (rs1) == SUBREG)
2731 && (REG_P (rs2) || GET_CODE (rs2) == SUBREG))
2733 /* We prohibit REG + REG for TFmode when there are no quad move insns
2734 and we consequently need to split. We do this because REG+REG
2735 is not an offsettable address. If we get the situation in reload
2736 where source and destination of a movtf pattern are both MEMs with
2737 REG+REG address, then only one of them gets converted to an
2738 offsettable address. */
2740 && ! (TARGET_FPU && TARGET_ARCH64 && TARGET_HARD_QUAD))
2743 /* We prohibit REG + REG on ARCH32 if not optimizing for
2744 DFmode/DImode because then mem_min_alignment is likely to be zero
2745 after reload and the forced split would lack a matching splitter
2747 if (TARGET_ARCH32 && !optimize
2748 && (mode == DFmode || mode == DImode))
2751 else if (USE_AS_OFFSETABLE_LO10
2752 && GET_CODE (rs1) == LO_SUM
2754 && ! TARGET_CM_MEDMID
2755 && RTX_OK_FOR_OLO10_P (rs2))
2758 imm1 = XEXP (rs1, 1);
2759 rs1 = XEXP (rs1, 0);
2760 if (! CONSTANT_P (imm1) || tls_symbolic_operand (rs1))
2764 else if (GET_CODE (addr) == LO_SUM)
2766 rs1 = XEXP (addr, 0);
2767 imm1 = XEXP (addr, 1);
2769 if (! CONSTANT_P (imm1) || tls_symbolic_operand (rs1))
2772 /* We can't allow TFmode in 32-bit mode, because an offset greater
2773 than the alignment (8) may cause the LO_SUM to overflow. */
2774 if (mode == TFmode && TARGET_ARCH32)
2777 else if (GET_CODE (addr) == CONST_INT && SMALL_INT (addr))
2782 if (GET_CODE (rs1) == SUBREG)
2783 rs1 = SUBREG_REG (rs1);
2789 if (GET_CODE (rs2) == SUBREG)
2790 rs2 = SUBREG_REG (rs2);
2797 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1))
2798 || (rs2 && !REGNO_OK_FOR_BASE_P (REGNO (rs2))))
2803 if ((REGNO (rs1) >= 32
2804 && REGNO (rs1) != FRAME_POINTER_REGNUM
2805 && REGNO (rs1) < FIRST_PSEUDO_REGISTER)
2807 && (REGNO (rs2) >= 32
2808 && REGNO (rs2) != FRAME_POINTER_REGNUM
2809 && REGNO (rs2) < FIRST_PSEUDO_REGISTER)))
2815 /* Construct the SYMBOL_REF for the tls_get_offset function. */
2817 static GTY(()) rtx sparc_tls_symbol;
2819 sparc_tls_get_addr (void)
2821 if (!sparc_tls_symbol)
2822 sparc_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_addr");
2824 return sparc_tls_symbol;
2828 sparc_tls_got (void)
2833 current_function_uses_pic_offset_table = 1;
2834 return pic_offset_table_rtx;
2837 if (!global_offset_table)
2838 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2839 temp = gen_reg_rtx (Pmode);
2840 emit_move_insn (temp, global_offset_table);
2845 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2846 this (thread-local) address. */
2849 legitimize_tls_address (rtx addr)
2851 rtx temp1, temp2, temp3, ret, o0, got, insn;
2853 gcc_assert (! no_new_pseudos);
2855 if (GET_CODE (addr) == SYMBOL_REF)
2856 switch (SYMBOL_REF_TLS_MODEL (addr))
2858 case TLS_MODEL_GLOBAL_DYNAMIC:
2860 temp1 = gen_reg_rtx (SImode);
2861 temp2 = gen_reg_rtx (SImode);
2862 ret = gen_reg_rtx (Pmode);
2863 o0 = gen_rtx_REG (Pmode, 8);
2864 got = sparc_tls_got ();
2865 emit_insn (gen_tgd_hi22 (temp1, addr));
2866 emit_insn (gen_tgd_lo10 (temp2, temp1, addr));
2869 emit_insn (gen_tgd_add32 (o0, got, temp2, addr));
2870 insn = emit_call_insn (gen_tgd_call32 (o0, sparc_tls_get_addr (),
2875 emit_insn (gen_tgd_add64 (o0, got, temp2, addr));
2876 insn = emit_call_insn (gen_tgd_call64 (o0, sparc_tls_get_addr (),
2879 CALL_INSN_FUNCTION_USAGE (insn)
2880 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
2881 CALL_INSN_FUNCTION_USAGE (insn));
2882 insn = get_insns ();
2884 emit_libcall_block (insn, ret, o0, addr);
2887 case TLS_MODEL_LOCAL_DYNAMIC:
2889 temp1 = gen_reg_rtx (SImode);
2890 temp2 = gen_reg_rtx (SImode);
2891 temp3 = gen_reg_rtx (Pmode);
2892 ret = gen_reg_rtx (Pmode);
2893 o0 = gen_rtx_REG (Pmode, 8);
2894 got = sparc_tls_got ();
2895 emit_insn (gen_tldm_hi22 (temp1));
2896 emit_insn (gen_tldm_lo10 (temp2, temp1));
2899 emit_insn (gen_tldm_add32 (o0, got, temp2));
2900 insn = emit_call_insn (gen_tldm_call32 (o0, sparc_tls_get_addr (),
2905 emit_insn (gen_tldm_add64 (o0, got, temp2));
2906 insn = emit_call_insn (gen_tldm_call64 (o0, sparc_tls_get_addr (),
2909 CALL_INSN_FUNCTION_USAGE (insn)
2910 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
2911 CALL_INSN_FUNCTION_USAGE (insn));
2912 insn = get_insns ();
2914 emit_libcall_block (insn, temp3, o0,
2915 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2916 UNSPEC_TLSLD_BASE));
2917 temp1 = gen_reg_rtx (SImode);
2918 temp2 = gen_reg_rtx (SImode);
2919 emit_insn (gen_tldo_hix22 (temp1, addr));
2920 emit_insn (gen_tldo_lox10 (temp2, temp1, addr));
2922 emit_insn (gen_tldo_add32 (ret, temp3, temp2, addr));
2924 emit_insn (gen_tldo_add64 (ret, temp3, temp2, addr));
2927 case TLS_MODEL_INITIAL_EXEC:
2928 temp1 = gen_reg_rtx (SImode);
2929 temp2 = gen_reg_rtx (SImode);
2930 temp3 = gen_reg_rtx (Pmode);
2931 got = sparc_tls_got ();
2932 emit_insn (gen_tie_hi22 (temp1, addr));
2933 emit_insn (gen_tie_lo10 (temp2, temp1, addr));
2935 emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
2937 emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
2940 ret = gen_reg_rtx (Pmode);
2942 emit_insn (gen_tie_add32 (ret, gen_rtx_REG (Pmode, 7),
2945 emit_insn (gen_tie_add64 (ret, gen_rtx_REG (Pmode, 7),
2949 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp3);
2952 case TLS_MODEL_LOCAL_EXEC:
2953 temp1 = gen_reg_rtx (Pmode);
2954 temp2 = gen_reg_rtx (Pmode);
2957 emit_insn (gen_tle_hix22_sp32 (temp1, addr));
2958 emit_insn (gen_tle_lox10_sp32 (temp2, temp1, addr));
2962 emit_insn (gen_tle_hix22_sp64 (temp1, addr));
2963 emit_insn (gen_tle_lox10_sp64 (temp2, temp1, addr));
2965 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp2);
2973 gcc_unreachable (); /* for now ... */
2979 /* Legitimize PIC addresses. If the address is already position-independent,
2980 we return ORIG. Newly generated position-independent addresses go into a
2981 reg. This is REG if nonzero, otherwise we allocate register(s) as
2985 legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
2988 if (GET_CODE (orig) == SYMBOL_REF)
2990 rtx pic_ref, address;
2995 gcc_assert (! reload_in_progress && ! reload_completed);
2996 reg = gen_reg_rtx (Pmode);
3001 /* If not during reload, allocate another temp reg here for loading
3002 in the address, so that these instructions can be optimized
3004 rtx temp_reg = ((reload_in_progress || reload_completed)
3005 ? reg : gen_reg_rtx (Pmode));
3007 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
3008 won't get confused into thinking that these two instructions
3009 are loading in the true address of the symbol. If in the
3010 future a PIC rtx exists, that should be used instead. */
3011 if (Pmode == SImode)
3013 emit_insn (gen_movsi_high_pic (temp_reg, orig));
3014 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
3018 emit_insn (gen_movdi_high_pic (temp_reg, orig));
3019 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
3026 pic_ref = gen_const_mem (Pmode,
3027 gen_rtx_PLUS (Pmode,
3028 pic_offset_table_rtx, address));
3029 current_function_uses_pic_offset_table = 1;
3030 insn = emit_move_insn (reg, pic_ref);
3031 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3033 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
3037 else if (GET_CODE (orig) == CONST)
3041 if (GET_CODE (XEXP (orig, 0)) == PLUS
3042 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3047 gcc_assert (! reload_in_progress && ! reload_completed);
3048 reg = gen_reg_rtx (Pmode);
3051 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
3052 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
3053 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
3054 base == reg ? 0 : reg);
3056 if (GET_CODE (offset) == CONST_INT)
3058 if (SMALL_INT (offset))
3059 return plus_constant (base, INTVAL (offset));
3060 else if (! reload_in_progress && ! reload_completed)
3061 offset = force_reg (Pmode, offset);
3063 /* If we reach here, then something is seriously wrong. */
3066 return gen_rtx_PLUS (Pmode, base, offset);
3068 else if (GET_CODE (orig) == LABEL_REF)
3069 /* ??? Why do we do this? */
3070 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
3071 the register is live instead, in case it is eliminated. */
3072 current_function_uses_pic_offset_table = 1;
3077 /* Try machine-dependent ways of modifying an illegitimate address X
3078 to be legitimate. If we find one, return the new, valid address.
3080 OLDX is the address as it was before break_out_memory_refs was called.
3081 In some cases it is useful to look at this to decide what needs to be done.
3083 MODE is the mode of the operand pointed to by X. */
3086 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
3090 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT)
3091 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3092 force_operand (XEXP (x, 0), NULL_RTX));
3093 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == MULT)
3094 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3095 force_operand (XEXP (x, 1), NULL_RTX));
3096 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS)
3097 x = gen_rtx_PLUS (Pmode, force_operand (XEXP (x, 0), NULL_RTX),
3099 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == PLUS)
3100 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3101 force_operand (XEXP (x, 1), NULL_RTX));
3103 if (x != orig_x && legitimate_address_p (mode, x, FALSE))
3106 if (tls_symbolic_operand (x))
3107 x = legitimize_tls_address (x);
3109 x = legitimize_pic_address (x, mode, 0);
3110 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 1)))
3111 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3112 copy_to_mode_reg (Pmode, XEXP (x, 1)));
3113 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 0)))
3114 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3115 copy_to_mode_reg (Pmode, XEXP (x, 0)));
3116 else if (GET_CODE (x) == SYMBOL_REF
3117 || GET_CODE (x) == CONST
3118 || GET_CODE (x) == LABEL_REF)
3119 x = copy_to_suggested_reg (x, NULL_RTX, Pmode);
3123 /* Emit the special PIC helper function. */
3126 emit_pic_helper (void)
3128 const char *pic_name = reg_names[REGNO (pic_offset_table_rtx)];
3133 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
3135 ASM_OUTPUT_ALIGN (asm_out_file, align);
3136 ASM_OUTPUT_LABEL (asm_out_file, pic_helper_symbol_name);
3137 if (flag_delayed_branch)
3138 fprintf (asm_out_file, "\tjmp\t%%o7+8\n\t add\t%%o7, %s, %s\n",
3139 pic_name, pic_name);
3141 fprintf (asm_out_file, "\tadd\t%%o7, %s, %s\n\tjmp\t%%o7+8\n\t nop\n",
3142 pic_name, pic_name);
3144 pic_helper_emitted_p = true;
3147 /* Emit code to load the PIC register. */
3150 load_pic_register (bool delay_pic_helper)
3152 int orig_flag_pic = flag_pic;
3154 /* If we haven't initialized the special PIC symbols, do so now. */
3155 if (!pic_helper_symbol_name[0])
3157 ASM_GENERATE_INTERNAL_LABEL (pic_helper_symbol_name, "LADDPC", 0);
3158 pic_helper_symbol = gen_rtx_SYMBOL_REF (Pmode, pic_helper_symbol_name);
3159 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3162 /* If we haven't emitted the special PIC helper function, do so now unless
3163 we are requested to delay it. */
3164 if (!delay_pic_helper && !pic_helper_emitted_p)
3169 emit_insn (gen_load_pcrel_symdi (pic_offset_table_rtx, global_offset_table,
3170 pic_helper_symbol));
3172 emit_insn (gen_load_pcrel_symsi (pic_offset_table_rtx, global_offset_table,
3173 pic_helper_symbol));
3174 flag_pic = orig_flag_pic;
3176 /* Need to emit this whether or not we obey regdecls,
3177 since setjmp/longjmp can cause life info to screw up.
3178 ??? In the case where we don't obey regdecls, this is not sufficient
3179 since we may not fall out the bottom. */
3180 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3183 /* Return 1 if RTX is a MEM which is known to be aligned to at
3184 least a DESIRED byte boundary. */
3187 mem_min_alignment (rtx mem, int desired)
3189 rtx addr, base, offset;
3191 /* If it's not a MEM we can't accept it. */
3192 if (GET_CODE (mem) != MEM)
3196 if (!TARGET_UNALIGNED_DOUBLES
3197 && MEM_ALIGN (mem) / BITS_PER_UNIT >= (unsigned)desired)
3200 /* ??? The rest of the function predates MEM_ALIGN so
3201 there is probably a bit of redundancy. */
3202 addr = XEXP (mem, 0);
3203 base = offset = NULL_RTX;
3204 if (GET_CODE (addr) == PLUS)
3206 if (GET_CODE (XEXP (addr, 0)) == REG)
3208 base = XEXP (addr, 0);
3210 /* What we are saying here is that if the base
3211 REG is aligned properly, the compiler will make
3212 sure any REG based index upon it will be so
3214 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3215 offset = XEXP (addr, 1);
3217 offset = const0_rtx;
3220 else if (GET_CODE (addr) == REG)
3223 offset = const0_rtx;
3226 if (base != NULL_RTX)
3228 int regno = REGNO (base);
3230 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
3232 /* Check if the compiler has recorded some information
3233 about the alignment of the base REG. If reload has
3234 completed, we already matched with proper alignments.
3235 If not running global_alloc, reload might give us
3236 unaligned pointer to local stack though. */
3238 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
3239 || (optimize && reload_completed))
3240 && (INTVAL (offset) & (desired - 1)) == 0)
3245 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
3249 else if (! TARGET_UNALIGNED_DOUBLES
3250 || CONSTANT_P (addr)
3251 || GET_CODE (addr) == LO_SUM)
3253 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
3254 is true, in which case we can only assume that an access is aligned if
3255 it is to a constant address, or the address involves a LO_SUM. */
3259 /* An obviously unaligned address. */
3264 /* Vectors to keep interesting information about registers where it can easily
3265 be got. We used to use the actual mode value as the bit number, but there
3266 are more than 32 modes now. Instead we use two tables: one indexed by
3267 hard register number, and one indexed by mode. */
3269 /* The purpose of sparc_mode_class is to shrink the range of modes so that
3270 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
3271 mapped into one sparc_mode_class mode. */
3273 enum sparc_mode_class {
3274 S_MODE, D_MODE, T_MODE, O_MODE,
3275 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
3279 /* Modes for single-word and smaller quantities. */
3280 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
3282 /* Modes for double-word and smaller quantities. */
3283 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
3285 /* Modes for quad-word and smaller quantities. */
3286 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
3288 /* Modes for 8-word and smaller quantities. */
3289 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
3291 /* Modes for single-float quantities. We must allow any single word or
3292 smaller quantity. This is because the fix/float conversion instructions
3293 take integer inputs/outputs from the float registers. */
3294 #define SF_MODES (S_MODES)
3296 /* Modes for double-float and smaller quantities. */
3297 #define DF_MODES (S_MODES | D_MODES)
3299 /* Modes for double-float only quantities. */
3300 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
3302 /* Modes for quad-float only quantities. */
3303 #define TF_ONLY_MODES (1 << (int) TF_MODE)
3305 /* Modes for quad-float and smaller quantities. */
3306 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
3308 /* Modes for quad-float and double-float quantities. */
3309 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
3311 /* Modes for quad-float pair only quantities. */
3312 #define OF_ONLY_MODES (1 << (int) OF_MODE)
3314 /* Modes for quad-float pairs and smaller quantities. */
3315 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
3317 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
3319 /* Modes for condition codes. */
3320 #define CC_MODES (1 << (int) CC_MODE)
3321 #define CCFP_MODES (1 << (int) CCFP_MODE)
3323 /* Value is 1 if register/mode pair is acceptable on sparc.
3324 The funny mixture of D and T modes is because integer operations
3325 do not specially operate on tetra quantities, so non-quad-aligned
3326 registers can hold quadword quantities (except %o4 and %i4 because
3327 they cross fixed registers). */
3329 /* This points to either the 32 bit or the 64 bit version. */
3330 const int *hard_regno_mode_classes;
3332 static const int hard_32bit_mode_classes[] = {
3333 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3334 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3335 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3336 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3338 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3339 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3340 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3341 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3343 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3344 and none can hold SFmode/SImode values. */
3345 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3346 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3347 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3348 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3351 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3357 static const int hard_64bit_mode_classes[] = {
3358 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3359 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3360 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3361 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3363 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3364 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3365 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3366 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3368 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3369 and none can hold SFmode/SImode values. */
3370 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3371 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3372 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3373 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3376 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3382 int sparc_mode_class [NUM_MACHINE_MODES];
3384 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
3387 sparc_init_modes (void)
3391 for (i = 0; i < NUM_MACHINE_MODES; i++)
3393 switch (GET_MODE_CLASS (i))
3396 case MODE_PARTIAL_INT:
3397 case MODE_COMPLEX_INT:
3398 if (GET_MODE_SIZE (i) <= 4)
3399 sparc_mode_class[i] = 1 << (int) S_MODE;
3400 else if (GET_MODE_SIZE (i) == 8)
3401 sparc_mode_class[i] = 1 << (int) D_MODE;
3402 else if (GET_MODE_SIZE (i) == 16)
3403 sparc_mode_class[i] = 1 << (int) T_MODE;
3404 else if (GET_MODE_SIZE (i) == 32)
3405 sparc_mode_class[i] = 1 << (int) O_MODE;
3407 sparc_mode_class[i] = 0;
3409 case MODE_VECTOR_INT:
3410 if (GET_MODE_SIZE (i) <= 4)
3411 sparc_mode_class[i] = 1 << (int)SF_MODE;
3412 else if (GET_MODE_SIZE (i) == 8)
3413 sparc_mode_class[i] = 1 << (int)DF_MODE;
3416 case MODE_COMPLEX_FLOAT:
3417 if (GET_MODE_SIZE (i) <= 4)
3418 sparc_mode_class[i] = 1 << (int) SF_MODE;
3419 else if (GET_MODE_SIZE (i) == 8)
3420 sparc_mode_class[i] = 1 << (int) DF_MODE;
3421 else if (GET_MODE_SIZE (i) == 16)
3422 sparc_mode_class[i] = 1 << (int) TF_MODE;
3423 else if (GET_MODE_SIZE (i) == 32)
3424 sparc_mode_class[i] = 1 << (int) OF_MODE;
3426 sparc_mode_class[i] = 0;
3429 if (i == (int) CCFPmode || i == (int) CCFPEmode)
3430 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
3432 sparc_mode_class[i] = 1 << (int) CC_MODE;
3435 sparc_mode_class[i] = 0;
3441 hard_regno_mode_classes = hard_64bit_mode_classes;
3443 hard_regno_mode_classes = hard_32bit_mode_classes;
3445 /* Initialize the array used by REGNO_REG_CLASS. */
3446 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3448 if (i < 16 && TARGET_V8PLUS)
3449 sparc_regno_reg_class[i] = I64_REGS;
3450 else if (i < 32 || i == FRAME_POINTER_REGNUM)
3451 sparc_regno_reg_class[i] = GENERAL_REGS;
3453 sparc_regno_reg_class[i] = FP_REGS;
3455 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
3457 sparc_regno_reg_class[i] = FPCC_REGS;
3459 sparc_regno_reg_class[i] = NO_REGS;
3463 /* Compute the frame size required by the function. This function is called
3464 during the reload pass and also by sparc_expand_prologue. */
3467 sparc_compute_frame_size (HOST_WIDE_INT size, int leaf_function_p)
3469 int outgoing_args_size = (current_function_outgoing_args_size
3470 + REG_PARM_STACK_SPACE (current_function_decl));
3471 int n_regs = 0; /* N_REGS is the number of 4-byte regs saved thus far. */
3476 for (i = 0; i < 8; i++)
3477 if (regs_ever_live[i] && ! call_used_regs[i])
3482 for (i = 0; i < 8; i += 2)
3483 if ((regs_ever_live[i] && ! call_used_regs[i])
3484 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3488 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
3489 if ((regs_ever_live[i] && ! call_used_regs[i])
3490 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3493 /* Set up values for use in prologue and epilogue. */
3494 num_gfregs = n_regs;
3499 && current_function_outgoing_args_size == 0)
3500 actual_fsize = apparent_fsize = 0;
3503 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
3504 apparent_fsize = (size - STARTING_FRAME_OFFSET + 7) & -8;
3505 apparent_fsize += n_regs * 4;
3506 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
3509 /* Make sure nothing can clobber our register windows.
3510 If a SAVE must be done, or there is a stack-local variable,
3511 the register window area must be allocated.
3512 ??? For v8 we apparently need an additional 8 bytes of reserved space. */
3513 if (! leaf_function_p || size > 0)
3514 actual_fsize += (16 * UNITS_PER_WORD) + (TARGET_ARCH64 ? 0 : 8);
3516 return SPARC_STACK_ALIGN (actual_fsize);
3519 /* Output any necessary .register pseudo-ops. */
3522 sparc_output_scratch_registers (FILE *file ATTRIBUTE_UNUSED)
3524 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
3530 /* Check if %g[2367] were used without
3531 .register being printed for them already. */
3532 for (i = 2; i < 8; i++)
3534 if (regs_ever_live [i]
3535 && ! sparc_hard_reg_printed [i])
3537 sparc_hard_reg_printed [i] = 1;
3538 fprintf (file, "\t.register\t%%g%d, #scratch\n", i);
3545 /* Save/restore call-saved registers from LOW to HIGH at BASE+OFFSET
3546 as needed. LOW should be double-word aligned for 32-bit registers.
3547 Return the new OFFSET. */
3550 #define SORR_RESTORE 1
3553 save_or_restore_regs (int low, int high, rtx base, int offset, int action)
3558 if (TARGET_ARCH64 && high <= 32)
3560 for (i = low; i < high; i++)
3562 if (regs_ever_live[i] && ! call_used_regs[i])
3564 mem = gen_rtx_MEM (DImode, plus_constant (base, offset));
3565 set_mem_alias_set (mem, sparc_sr_alias_set);
3566 if (action == SORR_SAVE)
3568 insn = emit_move_insn (mem, gen_rtx_REG (DImode, i));
3569 RTX_FRAME_RELATED_P (insn) = 1;
3571 else /* action == SORR_RESTORE */
3572 emit_move_insn (gen_rtx_REG (DImode, i), mem);
3579 for (i = low; i < high; i += 2)
3581 bool reg0 = regs_ever_live[i] && ! call_used_regs[i];
3582 bool reg1 = regs_ever_live[i+1] && ! call_used_regs[i+1];
3583 enum machine_mode mode;
3588 mode = i < 32 ? DImode : DFmode;
3593 mode = i < 32 ? SImode : SFmode;
3598 mode = i < 32 ? SImode : SFmode;
3605 mem = gen_rtx_MEM (mode, plus_constant (base, offset));
3606 set_mem_alias_set (mem, sparc_sr_alias_set);
3607 if (action == SORR_SAVE)
3609 insn = emit_move_insn (mem, gen_rtx_REG (mode, regno));
3610 RTX_FRAME_RELATED_P (insn) = 1;
3612 else /* action == SORR_RESTORE */
3613 emit_move_insn (gen_rtx_REG (mode, regno), mem);
3615 /* Always preserve double-word alignment. */
3616 offset = (offset + 7) & -8;
3623 /* Emit code to save call-saved registers. */
3626 emit_save_regs (void)
3628 HOST_WIDE_INT offset;
3631 offset = frame_base_offset - apparent_fsize;
3633 if (offset < -4096 || offset + num_gfregs * 4 > 4096)
3635 /* ??? This might be optimized a little as %g1 might already have a
3636 value close enough that a single add insn will do. */
3637 /* ??? Although, all of this is probably only a temporary fix
3638 because if %g1 can hold a function result, then
3639 sparc_expand_epilogue will lose (the result will be
3641 base = gen_rtx_REG (Pmode, 1);
3642 emit_move_insn (base, GEN_INT (offset));
3643 emit_insn (gen_rtx_SET (VOIDmode,
3645 gen_rtx_PLUS (Pmode, frame_base_reg, base)));
3649 base = frame_base_reg;
3651 offset = save_or_restore_regs (0, 8, base, offset, SORR_SAVE);
3652 save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, SORR_SAVE);
3655 /* Emit code to restore call-saved registers. */
3658 emit_restore_regs (void)
3660 HOST_WIDE_INT offset;
3663 offset = frame_base_offset - apparent_fsize;
3665 if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/)
3667 base = gen_rtx_REG (Pmode, 1);
3668 emit_move_insn (base, GEN_INT (offset));
3669 emit_insn (gen_rtx_SET (VOIDmode,
3671 gen_rtx_PLUS (Pmode, frame_base_reg, base)));
3675 base = frame_base_reg;
3677 offset = save_or_restore_regs (0, 8, base, offset, SORR_RESTORE);
3678 save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, SORR_RESTORE);
3681 /* Generate a save_register_window insn. */
3684 gen_save_register_window (rtx increment)
3687 return gen_save_register_windowdi (increment);
3689 return gen_save_register_windowsi (increment);
3692 /* Generate an increment for the stack pointer. */
3695 gen_stack_pointer_inc (rtx increment)
3698 return gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx, increment);
3700 return gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, increment);
3703 /* Generate a decrement for the stack pointer. */
3706 gen_stack_pointer_dec (rtx decrement)
3709 return gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, decrement);
3711 return gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, decrement);
3714 /* Expand the function prologue. The prologue is responsible for reserving
3715 storage for the frame, saving the call-saved registers and loading the
3716 PIC register if needed. */
3719 sparc_expand_prologue (void)
3724 /* Compute a snapshot of current_function_uses_only_leaf_regs. Relying
3725 on the final value of the flag means deferring the prologue/epilogue
3726 expansion until just before the second scheduling pass, which is too
3727 late to emit multiple epilogues or return insns.
3729 Of course we are making the assumption that the value of the flag
3730 will not change between now and its final value. Of the three parts
3731 of the formula, only the last one can reasonably vary. Let's take a
3732 closer look, after assuming that the first two ones are set to true
3733 (otherwise the last value is effectively silenced).
3735 If only_leaf_regs_used returns false, the global predicate will also
3736 be false so the actual frame size calculated below will be positive.
3737 As a consequence, the save_register_window insn will be emitted in
3738 the instruction stream; now this insn explicitly references %fp
3739 which is not a leaf register so only_leaf_regs_used will always
3740 return false subsequently.
3742 If only_leaf_regs_used returns true, we hope that the subsequent
3743 optimization passes won't cause non-leaf registers to pop up. For
3744 example, the regrename pass has special provisions to not rename to
3745 non-leaf registers in a leaf function. */
3746 sparc_leaf_function_p
3747 = optimize > 0 && leaf_function_p () && only_leaf_regs_used ();
3749 /* Need to use actual_fsize, since we are also allocating
3750 space for our callee (and our own register save area). */
3752 = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p);
3754 /* Advertise that the data calculated just above are now valid. */
3755 sparc_prologue_data_valid_p = true;
3757 if (sparc_leaf_function_p)
3759 frame_base_reg = stack_pointer_rtx;
3760 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
3764 frame_base_reg = hard_frame_pointer_rtx;
3765 frame_base_offset = SPARC_STACK_BIAS;
3768 if (actual_fsize == 0)
3770 else if (sparc_leaf_function_p)
3772 if (actual_fsize <= 4096)
3773 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-actual_fsize)));
3774 else if (actual_fsize <= 8192)
3776 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-4096)));
3777 /* %sp is still the CFA register. */
3778 RTX_FRAME_RELATED_P (insn) = 1;
3780 = emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize)));
3784 rtx reg = gen_rtx_REG (Pmode, 1);
3785 emit_move_insn (reg, GEN_INT (-actual_fsize));
3786 insn = emit_insn (gen_stack_pointer_inc (reg));
3788 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3789 PATTERN (gen_stack_pointer_inc (GEN_INT (-actual_fsize))),
3793 RTX_FRAME_RELATED_P (insn) = 1;
3797 if (actual_fsize <= 4096)
3798 insn = emit_insn (gen_save_register_window (GEN_INT (-actual_fsize)));
3799 else if (actual_fsize <= 8192)
3801 insn = emit_insn (gen_save_register_window (GEN_INT (-4096)));
3802 /* %sp is not the CFA register anymore. */
3803 emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize)));
3807 rtx reg = gen_rtx_REG (Pmode, 1);
3808 emit_move_insn (reg, GEN_INT (-actual_fsize));
3809 insn = emit_insn (gen_save_register_window (reg));
3812 RTX_FRAME_RELATED_P (insn) = 1;
3813 for (i=0; i < XVECLEN (PATTERN (insn), 0); i++)
3814 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, i)) = 1;
3817 /* Call-saved registers are saved just above the outgoing argument area. */
3821 /* Load the PIC register if needed. */
3822 if (flag_pic && current_function_uses_pic_offset_table)
3823 load_pic_register (false);
3826 /* This function generates the assembly code for function entry, which boils
3827 down to emitting the necessary .register directives.
3829 ??? Historical cruft: "On SPARC, move-double insns between fpu and cpu need
3830 an 8-byte block of memory. If any fpu reg is used in the function, we
3831 allocate such a block here, at the bottom of the frame, just in case it's
3832 needed." Could this explain the -8 in emit_restore_regs? */
3835 sparc_asm_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3837 /* Check that the assumption we made in sparc_expand_prologue is valid. */
3838 gcc_assert (sparc_leaf_function_p == current_function_uses_only_leaf_regs);
3840 sparc_output_scratch_registers (file);
3843 /* Expand the function epilogue, either normal or part of a sibcall.
3844 We emit all the instructions except the return or the call. */
3847 sparc_expand_epilogue (void)
3850 emit_restore_regs ();
3852 if (actual_fsize == 0)
3854 else if (sparc_leaf_function_p)
3856 if (actual_fsize <= 4096)
3857 emit_insn (gen_stack_pointer_dec (GEN_INT (- actual_fsize)));
3858 else if (actual_fsize <= 8192)
3860 emit_insn (gen_stack_pointer_dec (GEN_INT (-4096)));
3861 emit_insn (gen_stack_pointer_dec (GEN_INT (4096 - actual_fsize)));
3865 rtx reg = gen_rtx_REG (Pmode, 1);
3866 emit_move_insn (reg, GEN_INT (-actual_fsize));
3867 emit_insn (gen_stack_pointer_dec (reg));
3872 /* Return true if it is appropriate to emit `return' instructions in the
3873 body of a function. */
3876 sparc_can_use_return_insn_p (void)
3878 return sparc_prologue_data_valid_p
3879 && (actual_fsize == 0 || !sparc_leaf_function_p);
3882 /* This function generates the assembly code for function exit. */
3885 sparc_asm_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3887 /* If code does not drop into the epilogue, we have to still output
3888 a dummy nop for the sake of sane backtraces. Otherwise, if the
3889 last two instructions of a function were "call foo; dslot;" this
3890 can make the return PC of foo (i.e. address of call instruction
3891 plus 8) point to the first instruction in the next function. */
3893 rtx insn, last_real_insn;
3895 insn = get_last_insn ();
3897 last_real_insn = prev_real_insn (insn);
3899 && GET_CODE (last_real_insn) == INSN
3900 && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE)
3901 last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0);
3903 if (last_real_insn && GET_CODE (last_real_insn) == CALL_INSN)
3904 fputs("\tnop\n", file);
3906 sparc_output_deferred_case_vectors ();
3909 /* Output a 'restore' instruction. */
3912 output_restore (rtx pat)
3918 fputs ("\t restore\n", asm_out_file);
3922 gcc_assert (GET_CODE (pat) == SET);
3924 operands[0] = SET_DEST (pat);
3925 pat = SET_SRC (pat);
3927 switch (GET_CODE (pat))
3930 operands[1] = XEXP (pat, 0);
3931 operands[2] = XEXP (pat, 1);
3932 output_asm_insn (" restore %r1, %2, %Y0", operands);
3935 operands[1] = XEXP (pat, 0);
3936 operands[2] = XEXP (pat, 1);
3937 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
3940 operands[1] = XEXP (pat, 0);
3941 gcc_assert (XEXP (pat, 1) == const1_rtx);
3942 output_asm_insn (" restore %r1, %r1, %Y0", operands);
3946 output_asm_insn (" restore %%g0, %1, %Y0", operands);
3951 /* Output a return. */
3954 output_return (rtx insn)
3956 if (sparc_leaf_function_p)
3958 /* This is a leaf function so we don't have to bother restoring the
3959 register window, which frees us from dealing with the convoluted
3960 semantics of restore/return. We simply output the jump to the
3961 return address and the insn in the delay slot (if any). */
3963 gcc_assert (! current_function_calls_eh_return);
3965 return "jmp\t%%o7+%)%#";
3969 /* This is a regular function so we have to restore the register window.
3970 We may have a pending insn for the delay slot, which will be either
3971 combined with the 'restore' instruction or put in the delay slot of
3972 the 'return' instruction. */
3974 if (current_function_calls_eh_return)
3976 /* If the function uses __builtin_eh_return, the eh_return
3977 machinery occupies the delay slot. */
3978 gcc_assert (! final_sequence);
3980 if (! flag_delayed_branch)
3981 fputs ("\tadd\t%fp, %g1, %fp\n", asm_out_file);
3984 fputs ("\treturn\t%i7+8\n", asm_out_file);
3986 fputs ("\trestore\n\tjmp\t%o7+8\n", asm_out_file);
3988 if (flag_delayed_branch)
3989 fputs ("\t add\t%sp, %g1, %sp\n", asm_out_file);
3991 fputs ("\t nop\n", asm_out_file);
3993 else if (final_sequence)
3997 delay = NEXT_INSN (insn);
4000 pat = PATTERN (delay);
4002 if (TARGET_V9 && ! epilogue_renumber (&pat, 1))
4004 epilogue_renumber (&pat, 0);
4005 return "return\t%%i7+%)%#";
4009 output_asm_insn ("jmp\t%%i7+%)", NULL);
4010 output_restore (pat);
4011 PATTERN (delay) = gen_blockage ();
4012 INSN_CODE (delay) = -1;
4017 /* The delay slot is empty. */
4019 return "return\t%%i7+%)\n\t nop";
4020 else if (flag_delayed_branch)
4021 return "jmp\t%%i7+%)\n\t restore";
4023 return "restore\n\tjmp\t%%o7+%)\n\t nop";
4030 /* Output a sibling call. */
4033 output_sibcall (rtx insn, rtx call_operand)
4037 gcc_assert (flag_delayed_branch);
4039 operands[0] = call_operand;
4041 if (sparc_leaf_function_p)
4043 /* This is a leaf function so we don't have to bother restoring the
4044 register window. We simply output the jump to the function and
4045 the insn in the delay slot (if any). */
4047 gcc_assert (!(LEAF_SIBCALL_SLOT_RESERVED_P && final_sequence));
4050 output_asm_insn ("sethi\t%%hi(%a0), %%g1\n\tjmp\t%%g1 + %%lo(%a0)%#",
4053 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
4054 it into branch if possible. */
4055 output_asm_insn ("or\t%%o7, %%g0, %%g1\n\tcall\t%a0, 0\n\t or\t%%g1, %%g0, %%o7",
4060 /* This is a regular function so we have to restore the register window.
4061 We may have a pending insn for the delay slot, which will be combined
4062 with the 'restore' instruction. */
4064 output_asm_insn ("call\t%a0, 0", operands);
4068 rtx delay = NEXT_INSN (insn);
4071 output_restore (PATTERN (delay));
4073 PATTERN (delay) = gen_blockage ();
4074 INSN_CODE (delay) = -1;
4077 output_restore (NULL_RTX);
4083 /* Functions for handling argument passing.
4085 For 32-bit, the first 6 args are normally in registers and the rest are
4086 pushed. Any arg that starts within the first 6 words is at least
4087 partially passed in a register unless its data type forbids.
4089 For 64-bit, the argument registers are laid out as an array of 16 elements
4090 and arguments are added sequentially. The first 6 int args and up to the
4091 first 16 fp args (depending on size) are passed in regs.
4093 Slot Stack Integral Float Float in structure Double Long Double
4094 ---- ----- -------- ----- ------------------ ------ -----------
4095 15 [SP+248] %f31 %f30,%f31 %d30
4096 14 [SP+240] %f29 %f28,%f29 %d28 %q28
4097 13 [SP+232] %f27 %f26,%f27 %d26
4098 12 [SP+224] %f25 %f24,%f25 %d24 %q24
4099 11 [SP+216] %f23 %f22,%f23 %d22
4100 10 [SP+208] %f21 %f20,%f21 %d20 %q20
4101 9 [SP+200] %f19 %f18,%f19 %d18
4102 8 [SP+192] %f17 %f16,%f17 %d16 %q16
4103 7 [SP+184] %f15 %f14,%f15 %d14
4104 6 [SP+176] %f13 %f12,%f13 %d12 %q12
4105 5 [SP+168] %o5 %f11 %f10,%f11 %d10
4106 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
4107 3 [SP+152] %o3 %f7 %f6,%f7 %d6
4108 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
4109 1 [SP+136] %o1 %f3 %f2,%f3 %d2
4110 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
4112 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
4114 Integral arguments are always passed as 64-bit quantities appropriately
4117 Passing of floating point values is handled as follows.
4118 If a prototype is in scope:
4119 If the value is in a named argument (i.e. not a stdarg function or a
4120 value not part of the `...') then the value is passed in the appropriate
4122 If the value is part of the `...' and is passed in one of the first 6
4123 slots then the value is passed in the appropriate int reg.
4124 If the value is part of the `...' and is not passed in one of the first 6
4125 slots then the value is passed in memory.
4126 If a prototype is not in scope:
4127 If the value is one of the first 6 arguments the value is passed in the
4128 appropriate integer reg and the appropriate fp reg.
4129 If the value is not one of the first 6 arguments the value is passed in
4130 the appropriate fp reg and in memory.
4133 Summary of the calling conventions implemented by GCC on SPARC:
4136 size argument return value
4138 small integer <4 int. reg. int. reg.
4139 word 4 int. reg. int. reg.
4140 double word 8 int. reg. int. reg.
4142 _Complex small integer <8 int. reg. int. reg.
4143 _Complex word 8 int. reg. int. reg.
4144 _Complex double word 16 memory int. reg.
4146 vector integer <=8 int. reg. FP reg.
4147 vector integer >8 memory memory
4149 float 4 int. reg. FP reg.
4150 double 8 int. reg. FP reg.
4151 long double 16 memory memory
4153 _Complex float 8 memory FP reg.
4154 _Complex double 16 memory FP reg.
4155 _Complex long double 32 memory FP reg.
4157 vector float any memory memory
4159 aggregate any memory memory
4164 size argument return value
4166 small integer <8 int. reg. int. reg.
4167 word 8 int. reg. int. reg.
4168 double word 16 int. reg. int. reg.
4170 _Complex small integer <16 int. reg. int. reg.
4171 _Complex word 16 int. reg. int. reg.
4172 _Complex double word 32 memory int. reg.
4174 vector integer <=16 FP reg. FP reg.
4175 vector integer 16<s<=32 memory FP reg.
4176 vector integer >32 memory memory
4178 float 4 FP reg. FP reg.
4179 double 8 FP reg. FP reg.
4180 long double 16 FP reg. FP reg.
4182 _Complex float 8 FP reg. FP reg.
4183 _Complex double 16 FP reg. FP reg.
4184 _Complex long double 32 memory FP reg.
4186 vector float <=16 FP reg. FP reg.
4187 vector float 16<s<=32 memory FP reg.
4188 vector float >32 memory memory
4190 aggregate <=16 reg. reg.
4191 aggregate 16<s<=32 memory reg.
4192 aggregate >32 memory memory
4196 Note #1: complex floating-point types follow the extended SPARC ABIs as
4197 implemented by the Sun compiler.
4199 Note #2: integral vector types follow the scalar floating-point types
4200 conventions to match what is implemented by the Sun VIS SDK.
4202 Note #3: floating-point vector types follow the aggregate types
4206 /* Maximum number of int regs for args. */
4207 #define SPARC_INT_ARG_MAX 6
4208 /* Maximum number of fp regs for args. */
4209 #define SPARC_FP_ARG_MAX 16
4211 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
4213 /* Handle the INIT_CUMULATIVE_ARGS macro.
4214 Initialize a variable CUM of type CUMULATIVE_ARGS
4215 for a call to a function whose data type is FNTYPE.
4216 For a library call, FNTYPE is 0. */
4219 init_cumulative_args (struct sparc_args *cum, tree fntype,
4220 rtx libname ATTRIBUTE_UNUSED,
4221 tree fndecl ATTRIBUTE_UNUSED)
4224 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
4225 cum->libcall_p = fntype == 0;
4228 /* Handle the TARGET_PROMOTE_PROTOTYPES target hook.
4229 When a prototype says `char' or `short', really pass an `int'. */
4232 sparc_promote_prototypes (tree fntype ATTRIBUTE_UNUSED)
4234 return TARGET_ARCH32 ? true : false;
4237 /* Handle the TARGET_STRICT_ARGUMENT_NAMING target hook. */
4240 sparc_strict_argument_naming (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED)
4242 return TARGET_ARCH64 ? true : false;
4245 /* Scan the record type TYPE and return the following predicates:
4246 - INTREGS_P: the record contains at least one field or sub-field
4247 that is eligible for promotion in integer registers.
4248 - FP_REGS_P: the record contains at least one field or sub-field
4249 that is eligible for promotion in floating-point registers.
4250 - PACKED_P: the record contains at least one field that is packed.
4252 Sub-fields are not taken into account for the PACKED_P predicate. */
4255 scan_record_type (tree type, int *intregs_p, int *fpregs_p, int *packed_p)
4259 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4261 if (TREE_CODE (field) == FIELD_DECL)
4263 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4264 scan_record_type (TREE_TYPE (field), intregs_p, fpregs_p, 0);
4265 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
4266 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
4272 if (packed_p && DECL_PACKED (field))
4278 /* Compute the slot number to pass an argument in.
4279 Return the slot number or -1 if passing on the stack.
4281 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4282 the preceding args and about the function being called.
4283 MODE is the argument's machine mode.
4284 TYPE is the data type of the argument (as a tree).
4285 This is null for libcalls where that information may
4287 NAMED is nonzero if this argument is a named parameter
4288 (otherwise it is an extra parameter matching an ellipsis).
4289 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
4290 *PREGNO records the register number to use if scalar type.
4291 *PPADDING records the amount of padding needed in words. */
4294 function_arg_slotno (const struct sparc_args *cum, enum machine_mode mode,
4295 tree type, int named, int incoming_p,
4296 int *pregno, int *ppadding)
4298 int regbase = (incoming_p
4299 ? SPARC_INCOMING_INT_ARG_FIRST
4300 : SPARC_OUTGOING_INT_ARG_FIRST);
4301 int slotno = cum->words;
4302 enum mode_class mclass;
4307 if (type && TREE_ADDRESSABLE (type))
4313 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
4316 /* For SPARC64, objects requiring 16-byte alignment get it. */
4318 && GET_MODE_ALIGNMENT (mode) >= 2 * BITS_PER_WORD
4319 && (slotno & 1) != 0)
4320 slotno++, *ppadding = 1;
4322 mclass = GET_MODE_CLASS (mode);
4323 if (type && TREE_CODE (type) == VECTOR_TYPE)
4325 /* Vector types deserve special treatment because they are
4326 polymorphic wrt their mode, depending upon whether VIS
4327 instructions are enabled. */
4328 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
4330 /* The SPARC port defines no floating-point vector modes. */
4331 gcc_assert (mode == BLKmode);
4335 /* Integral vector types should either have a vector
4336 mode or an integral mode, because we are guaranteed
4337 by pass_by_reference that their size is not greater
4338 than 16 bytes and TImode is 16-byte wide. */
4339 gcc_assert (mode != BLKmode);
4341 /* Vector integers are handled like floats according to
4343 mclass = MODE_FLOAT;
4350 case MODE_COMPLEX_FLOAT:
4351 if (TARGET_ARCH64 && TARGET_FPU && named)
4353 if (slotno >= SPARC_FP_ARG_MAX)
4355 regno = SPARC_FP_ARG_FIRST + slotno * 2;
4356 /* Arguments filling only one single FP register are
4357 right-justified in the outer double FP register. */
4358 if (GET_MODE_SIZE (mode) <= 4)
4365 case MODE_COMPLEX_INT:
4366 if (slotno >= SPARC_INT_ARG_MAX)
4368 regno = regbase + slotno;
4372 if (mode == VOIDmode)
4373 /* MODE is VOIDmode when generating the actual call. */
4376 gcc_assert (mode == BLKmode);
4378 /* For SPARC64, objects requiring 16-byte alignment get it. */
4381 && TYPE_ALIGN (type) >= 2 * BITS_PER_WORD
4382 && (slotno & 1) != 0)
4383 slotno++, *ppadding = 1;
4385 if (TARGET_ARCH32 || !type || (TREE_CODE (type) == UNION_TYPE))
4387 if (slotno >= SPARC_INT_ARG_MAX)
4389 regno = regbase + slotno;
4391 else /* TARGET_ARCH64 && type */
4393 int intregs_p = 0, fpregs_p = 0, packed_p = 0;
4395 /* First see what kinds of registers we would need. */
4396 if (TREE_CODE (type) == VECTOR_TYPE)
4399 scan_record_type (type, &intregs_p, &fpregs_p, &packed_p);
4401 /* The ABI obviously doesn't specify how packed structures
4402 are passed. These are defined to be passed in int regs
4403 if possible, otherwise memory. */
4404 if (packed_p || !named)
4405 fpregs_p = 0, intregs_p = 1;
4407 /* If all arg slots are filled, then must pass on stack. */
4408 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
4411 /* If there are only int args and all int arg slots are filled,
4412 then must pass on stack. */
4413 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
4416 /* Note that even if all int arg slots are filled, fp members may
4417 still be passed in regs if such regs are available.
4418 *PREGNO isn't set because there may be more than one, it's up
4419 to the caller to compute them. */
4432 /* Handle recursive register counting for structure field layout. */
4434 struct function_arg_record_value_parms
4436 rtx ret; /* return expression being built. */
4437 int slotno; /* slot number of the argument. */
4438 int named; /* whether the argument is named. */
4439 int regbase; /* regno of the base register. */
4440 int stack; /* 1 if part of the argument is on the stack. */
4441 int intoffset; /* offset of the first pending integer field. */
4442 unsigned int nregs; /* number of words passed in registers. */
4445 static void function_arg_record_value_3
4446 (HOST_WIDE_INT, struct function_arg_record_value_parms *);
4447 static void function_arg_record_value_2
4448 (tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
4449 static void function_arg_record_value_1
4450 (tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
4451 static rtx function_arg_record_value (tree, enum machine_mode, int, int, int);
4452 static rtx function_arg_union_value (int, enum machine_mode, int, int);
4454 /* A subroutine of function_arg_record_value. Traverse the structure
4455 recursively and determine how many registers will be required. */
4458 function_arg_record_value_1 (tree type, HOST_WIDE_INT startbitpos,
4459 struct function_arg_record_value_parms *parms,
4464 /* We need to compute how many registers are needed so we can
4465 allocate the PARALLEL but before we can do that we need to know
4466 whether there are any packed fields. The ABI obviously doesn't
4467 specify how structures are passed in this case, so they are
4468 defined to be passed in int regs if possible, otherwise memory,
4469 regardless of whether there are fp values present. */
4472 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4474 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4481 /* Compute how many registers we need. */
4482 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4484 if (TREE_CODE (field) == FIELD_DECL)
4486 HOST_WIDE_INT bitpos = startbitpos;
4488 if (DECL_SIZE (field) != 0)
4490 if (integer_zerop (DECL_SIZE (field)))
4493 if (host_integerp (bit_position (field), 1))
4494 bitpos += int_bit_position (field);
4497 /* ??? FIXME: else assume zero offset. */
4499 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4500 function_arg_record_value_1 (TREE_TYPE (field),
4504 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
4505 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
4510 if (parms->intoffset != -1)
4512 unsigned int startbit, endbit;
4513 int intslots, this_slotno;
4515 startbit = parms->intoffset & -BITS_PER_WORD;
4516 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4518 intslots = (endbit - startbit) / BITS_PER_WORD;
4519 this_slotno = parms->slotno + parms->intoffset
4522 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
4524 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
4525 /* We need to pass this field on the stack. */
4529 parms->nregs += intslots;
4530 parms->intoffset = -1;
4533 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
4534 If it wasn't true we wouldn't be here. */
4535 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
4536 && DECL_MODE (field) == BLKmode)
4537 parms->nregs += TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
4538 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
4545 if (parms->intoffset == -1)
4546 parms->intoffset = bitpos;
4552 /* A subroutine of function_arg_record_value. Assign the bits of the
4553 structure between parms->intoffset and bitpos to integer registers. */
4556 function_arg_record_value_3 (HOST_WIDE_INT bitpos,
4557 struct function_arg_record_value_parms *parms)
4559 enum machine_mode mode;
4561 unsigned int startbit, endbit;
4562 int this_slotno, intslots, intoffset;
4565 if (parms->intoffset == -1)
4568 intoffset = parms->intoffset;
4569 parms->intoffset = -1;
4571 startbit = intoffset & -BITS_PER_WORD;
4572 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4573 intslots = (endbit - startbit) / BITS_PER_WORD;
4574 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
4576 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4580 /* If this is the trailing part of a word, only load that much into
4581 the register. Otherwise load the whole register. Note that in
4582 the latter case we may pick up unwanted bits. It's not a problem
4583 at the moment but may wish to revisit. */
4585 if (intoffset % BITS_PER_WORD != 0)
4586 mode = smallest_mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
4591 intoffset /= BITS_PER_UNIT;
4594 regno = parms->regbase + this_slotno;
4595 reg = gen_rtx_REG (mode, regno);
4596 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
4597 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
4600 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
4605 while (intslots > 0);
4608 /* A subroutine of function_arg_record_value. Traverse the structure
4609 recursively and assign bits to floating point registers. Track which
4610 bits in between need integer registers; invoke function_arg_record_value_3
4611 to make that happen. */
4614 function_arg_record_value_2 (tree type, HOST_WIDE_INT startbitpos,
4615 struct function_arg_record_value_parms *parms,
4621 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4623 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4630 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4632 if (TREE_CODE (field) == FIELD_DECL)
4634 HOST_WIDE_INT bitpos = startbitpos;
4636 if (DECL_SIZE (field) != 0)
4638 if (integer_zerop (DECL_SIZE (field)))
4641 if (host_integerp (bit_position (field), 1))
4642 bitpos += int_bit_position (field);
4645 /* ??? FIXME: else assume zero offset. */
4647 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4648 function_arg_record_value_2 (TREE_TYPE (field),
4652 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
4653 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
4658 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
4659 int regno, nregs, pos;
4660 enum machine_mode mode = DECL_MODE (field);
4663 function_arg_record_value_3 (bitpos, parms);
4665 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
4668 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
4669 nregs = TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
4671 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
4673 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
4679 regno = SPARC_FP_ARG_FIRST + this_slotno * 2;
4680 if (GET_MODE_SIZE (mode) <= 4 && (bitpos & 32) != 0)
4682 reg = gen_rtx_REG (mode, regno);
4683 pos = bitpos / BITS_PER_UNIT;
4684 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
4685 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
4689 regno += GET_MODE_SIZE (mode) / 4;
4690 reg = gen_rtx_REG (mode, regno);
4691 pos += GET_MODE_SIZE (mode);
4692 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
4693 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
4699 if (parms->intoffset == -1)
4700 parms->intoffset = bitpos;
4706 /* Used by function_arg and function_value to implement the complex
4707 conventions of the 64-bit ABI for passing and returning structures.
4708 Return an expression valid as a return value for the two macros
4709 FUNCTION_ARG and FUNCTION_VALUE.
4711 TYPE is the data type of the argument (as a tree).
4712 This is null for libcalls where that information may
4714 MODE is the argument's machine mode.
4715 SLOTNO is the index number of the argument's slot in the parameter array.
4716 NAMED is nonzero if this argument is a named parameter
4717 (otherwise it is an extra parameter matching an ellipsis).
4718 REGBASE is the regno of the base register for the parameter array. */
4721 function_arg_record_value (tree type, enum machine_mode mode,
4722 int slotno, int named, int regbase)
4724 HOST_WIDE_INT typesize = int_size_in_bytes (type);
4725 struct function_arg_record_value_parms parms;
4728 parms.ret = NULL_RTX;
4729 parms.slotno = slotno;
4730 parms.named = named;
4731 parms.regbase = regbase;
4734 /* Compute how many registers we need. */
4736 parms.intoffset = 0;
4737 function_arg_record_value_1 (type, 0, &parms, false);
4739 /* Take into account pending integer fields. */
4740 if (parms.intoffset != -1)
4742 unsigned int startbit, endbit;
4743 int intslots, this_slotno;
4745 startbit = parms.intoffset & -BITS_PER_WORD;
4746 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4747 intslots = (endbit - startbit) / BITS_PER_WORD;
4748 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
4750 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
4752 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
4753 /* We need to pass this field on the stack. */
4757 parms.nregs += intslots;
4759 nregs = parms.nregs;
4761 /* Allocate the vector and handle some annoying special cases. */
4764 /* ??? Empty structure has no value? Duh? */
4767 /* Though there's nothing really to store, return a word register
4768 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
4769 leads to breakage due to the fact that there are zero bytes to
4771 return gen_rtx_REG (mode, regbase);
4775 /* ??? C++ has structures with no fields, and yet a size. Give up
4776 for now and pass everything back in integer registers. */
4777 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4779 if (nregs + slotno > SPARC_INT_ARG_MAX)
4780 nregs = SPARC_INT_ARG_MAX - slotno;
4782 gcc_assert (nregs != 0);
4784 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (parms.stack + nregs));
4786 /* If at least one field must be passed on the stack, generate
4787 (parallel [(expr_list (nil) ...) ...]) so that all fields will
4788 also be passed on the stack. We can't do much better because the
4789 semantics of TARGET_ARG_PARTIAL_BYTES doesn't handle the case
4790 of structures for which the fields passed exclusively in registers
4791 are not at the beginning of the structure. */
4793 XVECEXP (parms.ret, 0, 0)
4794 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4796 /* Fill in the entries. */
4798 parms.intoffset = 0;
4799 function_arg_record_value_2 (type, 0, &parms, false);
4800 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
4802 gcc_assert (parms.nregs == nregs);
4807 /* Used by function_arg and function_value to implement the conventions
4808 of the 64-bit ABI for passing and returning unions.
4809 Return an expression valid as a return value for the two macros
4810 FUNCTION_ARG and FUNCTION_VALUE.
4812 SIZE is the size in bytes of the union.
4813 MODE is the argument's machine mode.
4814 REGNO is the hard register the union will be passed in. */
4817 function_arg_union_value (int size, enum machine_mode mode, int slotno,
4820 int nwords = ROUND_ADVANCE (size), i;
4823 /* See comment in previous function for empty structures. */
4825 return gen_rtx_REG (mode, regno);
4827 if (slotno == SPARC_INT_ARG_MAX - 1)
4830 regs = gen_rtx_PARALLEL (mode, rtvec_alloc (nwords));
4832 for (i = 0; i < nwords; i++)
4834 /* Unions are passed left-justified. */
4835 XVECEXP (regs, 0, i)
4836 = gen_rtx_EXPR_LIST (VOIDmode,
4837 gen_rtx_REG (word_mode, regno),
4838 GEN_INT (UNITS_PER_WORD * i));
4845 /* Used by function_arg and function_value to implement the conventions
4846 for passing and returning large (BLKmode) vectors.
4847 Return an expression valid as a return value for the two macros
4848 FUNCTION_ARG and FUNCTION_VALUE.
4850 SIZE is the size in bytes of the vector.
4851 BASE_MODE is the argument's base machine mode.
4852 REGNO is the FP hard register the vector will be passed in. */
4855 function_arg_vector_value (int size, enum machine_mode base_mode, int regno)
4857 unsigned short base_mode_size = GET_MODE_SIZE (base_mode);
4858 int nregs = size / base_mode_size, i;
4861 regs = gen_rtx_PARALLEL (BLKmode, rtvec_alloc (nregs));
4863 for (i = 0; i < nregs; i++)
4865 XVECEXP (regs, 0, i)
4866 = gen_rtx_EXPR_LIST (VOIDmode,
4867 gen_rtx_REG (base_mode, regno),
4868 GEN_INT (base_mode_size * i));
4869 regno += base_mode_size / 4;
4875 /* Handle the FUNCTION_ARG macro.
4876 Determine where to put an argument to a function.
4877 Value is zero to push the argument on the stack,
4878 or a hard register in which to store the argument.
4880 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4881 the preceding args and about the function being called.
4882 MODE is the argument's machine mode.
4883 TYPE is the data type of the argument (as a tree).
4884 This is null for libcalls where that information may
4886 NAMED is nonzero if this argument is a named parameter
4887 (otherwise it is an extra parameter matching an ellipsis).
4888 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
4891 function_arg (const struct sparc_args *cum, enum machine_mode mode,
4892 tree type, int named, int incoming_p)
4894 int regbase = (incoming_p
4895 ? SPARC_INCOMING_INT_ARG_FIRST
4896 : SPARC_OUTGOING_INT_ARG_FIRST);
4897 int slotno, regno, padding;
4898 enum mode_class mclass = GET_MODE_CLASS (mode);
4901 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
4909 reg = gen_rtx_REG (mode, regno);
4913 if (type && TREE_CODE (type) == RECORD_TYPE)
4915 /* Structures up to 16 bytes in size are passed in arg slots on the
4916 stack and are promoted to registers where possible. */
4918 gcc_assert (int_size_in_bytes (type) <= 16);
4920 return function_arg_record_value (type, mode, slotno, named, regbase);
4922 else if (type && TREE_CODE (type) == UNION_TYPE)
4924 HOST_WIDE_INT size = int_size_in_bytes (type);
4926 gcc_assert (size <= 16);
4928 return function_arg_union_value (size, mode, slotno, regno);
4930 else if (type && TREE_CODE (type) == VECTOR_TYPE)
4932 /* Vector types deserve special treatment because they are
4933 polymorphic wrt their mode, depending upon whether VIS
4934 instructions are enabled. */
4935 HOST_WIDE_INT size = int_size_in_bytes (type);
4937 gcc_assert (size <= 16);
4939 if (mode == BLKmode)
4940 return function_arg_vector_value (size,
4941 TYPE_MODE (TREE_TYPE (type)),
4942 SPARC_FP_ARG_FIRST + 2*slotno);
4944 mclass = MODE_FLOAT;
4947 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
4948 but also have the slot allocated for them.
4949 If no prototype is in scope fp values in register slots get passed
4950 in two places, either fp regs and int regs or fp regs and memory. */
4951 if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
4952 && SPARC_FP_REG_P (regno))
4954 reg = gen_rtx_REG (mode, regno);
4955 if (cum->prototype_p || cum->libcall_p)
4957 /* "* 2" because fp reg numbers are recorded in 4 byte
4960 /* ??? This will cause the value to be passed in the fp reg and
4961 in the stack. When a prototype exists we want to pass the
4962 value in the reg but reserve space on the stack. That's an
4963 optimization, and is deferred [for a bit]. */
4964 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
4965 return gen_rtx_PARALLEL (mode,
4967 gen_rtx_EXPR_LIST (VOIDmode,
4968 NULL_RTX, const0_rtx),
4969 gen_rtx_EXPR_LIST (VOIDmode,
4973 /* ??? It seems that passing back a register even when past
4974 the area declared by REG_PARM_STACK_SPACE will allocate
4975 space appropriately, and will not copy the data onto the
4976 stack, exactly as we desire.
4978 This is due to locate_and_pad_parm being called in
4979 expand_call whenever reg_parm_stack_space > 0, which
4980 while beneficial to our example here, would seem to be
4981 in error from what had been intended. Ho hum... -- r~ */
4989 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
4993 /* On incoming, we don't need to know that the value
4994 is passed in %f0 and %i0, and it confuses other parts
4995 causing needless spillage even on the simplest cases. */
4999 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
5000 + (regno - SPARC_FP_ARG_FIRST) / 2);
5002 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5003 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
5005 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5009 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
5010 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5011 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5017 /* Scalar or complex int. */
5018 reg = gen_rtx_REG (mode, regno);
5024 /* For an arg passed partly in registers and partly in memory,
5025 this is the number of bytes of registers used.
5026 For args passed entirely in registers or entirely in memory, zero.
5028 Any arg that starts in the first 6 regs but won't entirely fit in them
5029 needs partial registers on v8. On v9, structures with integer
5030 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
5031 values that begin in the last fp reg [where "last fp reg" varies with the
5032 mode] will be split between that reg and memory. */
5035 sparc_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5036 tree type, bool named)
5038 int slotno, regno, padding;
5040 /* We pass 0 for incoming_p here, it doesn't matter. */
5041 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5048 if ((slotno + (mode == BLKmode
5049 ? ROUND_ADVANCE (int_size_in_bytes (type))
5050 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
5051 > SPARC_INT_ARG_MAX)
5052 return (SPARC_INT_ARG_MAX - slotno) * UNITS_PER_WORD;
5056 /* We are guaranteed by pass_by_reference that the size of the
5057 argument is not greater than 16 bytes, so we only need to return
5058 one word if the argument is partially passed in registers. */
5060 if (type && AGGREGATE_TYPE_P (type))
5062 int size = int_size_in_bytes (type);
5064 if (size > UNITS_PER_WORD
5065 && slotno == SPARC_INT_ARG_MAX - 1)
5066 return UNITS_PER_WORD;
5068 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
5069 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5070 && ! (TARGET_FPU && named)))
5072 /* The complex types are passed as packed types. */
5073 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
5074 && slotno == SPARC_INT_ARG_MAX - 1)
5075 return UNITS_PER_WORD;
5077 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
5079 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
5081 return UNITS_PER_WORD;
5088 /* Handle the TARGET_PASS_BY_REFERENCE target hook.
5089 Specify whether to pass the argument by reference. */
5092 sparc_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5093 enum machine_mode mode, tree type,
5094 bool named ATTRIBUTE_UNUSED)
5098 /* Original SPARC 32-bit ABI says that structures and unions,
5099 and quad-precision floats are passed by reference. For Pascal,
5100 also pass arrays by reference. All other base types are passed
5103 Extended ABI (as implemented by the Sun compiler) says that all
5104 complex floats are passed by reference. Pass complex integers
5105 in registers up to 8 bytes. More generally, enforce the 2-word
5106 cap for passing arguments in registers.
5108 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5109 integers are passed like floats of the same size, that is in
5110 registers up to 8 bytes. Pass all vector floats by reference
5111 like structure and unions. */
5112 return ((type && (AGGREGATE_TYPE_P (type) || VECTOR_FLOAT_TYPE_P (type)))
5114 /* Catch CDImode, TFmode, DCmode and TCmode. */
5115 || GET_MODE_SIZE (mode) > 8
5117 && TREE_CODE (type) == VECTOR_TYPE
5118 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
5122 /* Original SPARC 64-bit ABI says that structures and unions
5123 smaller than 16 bytes are passed in registers, as well as
5124 all other base types. For Pascal, pass arrays by reference.
5126 Extended ABI (as implemented by the Sun compiler) says that
5127 complex floats are passed in registers up to 16 bytes. Pass
5128 all complex integers in registers up to 16 bytes. More generally,
5129 enforce the 2-word cap for passing arguments in registers.
5131 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5132 integers are passed like floats of the same size, that is in
5133 registers (up to 16 bytes). Pass all vector floats like structure
5135 return ((type && TREE_CODE (type) == ARRAY_TYPE)
5137 && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == VECTOR_TYPE)
5138 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16)
5139 /* Catch CTImode and TCmode. */
5140 || GET_MODE_SIZE (mode) > 16);
5144 /* Handle the FUNCTION_ARG_ADVANCE macro.
5145 Update the data in CUM to advance over an argument
5146 of mode MODE and data type TYPE.
5147 TYPE is null for libcalls where that information may not be available. */
5150 function_arg_advance (struct sparc_args *cum, enum machine_mode mode,
5151 tree type, int named)
5153 int slotno, regno, padding;
5155 /* We pass 0 for incoming_p here, it doesn't matter. */
5156 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5158 /* If register required leading padding, add it. */
5160 cum->words += padding;
5164 cum->words += (mode != BLKmode
5165 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5166 : ROUND_ADVANCE (int_size_in_bytes (type)));
5170 if (type && AGGREGATE_TYPE_P (type))
5172 int size = int_size_in_bytes (type);
5176 else if (size <= 16)
5178 else /* passed by reference */
5183 cum->words += (mode != BLKmode
5184 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5185 : ROUND_ADVANCE (int_size_in_bytes (type)));
5190 /* Handle the FUNCTION_ARG_PADDING macro.
5191 For the 64 bit ABI structs are always stored left shifted in their
5195 function_arg_padding (enum machine_mode mode, tree type)
5197 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
5200 /* Fall back to the default. */
5201 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
5204 /* Handle the TARGET_RETURN_IN_MEMORY target hook.
5205 Specify whether to return the return value in memory. */
5208 sparc_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
5211 /* Original SPARC 32-bit ABI says that structures and unions,
5212 and quad-precision floats are returned in memory. All other
5213 base types are returned in registers.
5215 Extended ABI (as implemented by the Sun compiler) says that
5216 all complex floats are returned in registers (8 FP registers
5217 at most for '_Complex long double'). Return all complex integers
5218 in registers (4 at most for '_Complex long long').
5220 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5221 integers are returned like floats of the same size, that is in
5222 registers up to 8 bytes and in memory otherwise. Return all
5223 vector floats in memory like structure and unions; note that
5224 they always have BLKmode like the latter. */
5225 return (TYPE_MODE (type) == BLKmode
5226 || TYPE_MODE (type) == TFmode
5227 || (TREE_CODE (type) == VECTOR_TYPE
5228 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
5230 /* Original SPARC 64-bit ABI says that structures and unions
5231 smaller than 32 bytes are returned in registers, as well as
5232 all other base types.
5234 Extended ABI (as implemented by the Sun compiler) says that all
5235 complex floats are returned in registers (8 FP registers at most
5236 for '_Complex long double'). Return all complex integers in
5237 registers (4 at most for '_Complex TItype').
5239 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5240 integers are returned like floats of the same size, that is in
5241 registers. Return all vector floats like structure and unions;
5242 note that they always have BLKmode like the latter. */
5243 return ((TYPE_MODE (type) == BLKmode
5244 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 32));
5247 /* Handle the TARGET_STRUCT_VALUE target hook.
5248 Return where to find the structure return value address. */
5251 sparc_struct_value_rtx (tree fndecl ATTRIBUTE_UNUSED, int incoming)
5260 mem = gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx,
5261 STRUCT_VALUE_OFFSET));
5263 mem = gen_rtx_MEM (Pmode, plus_constant (stack_pointer_rtx,
5264 STRUCT_VALUE_OFFSET));
5266 set_mem_alias_set (mem, struct_value_alias_set);
5271 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
5272 For v9, function return values are subject to the same rules as arguments,
5273 except that up to 32 bytes may be returned in registers. */
5276 function_value (tree type, enum machine_mode mode, int incoming_p)
5278 /* Beware that the two values are swapped here wrt function_arg. */
5279 int regbase = (incoming_p
5280 ? SPARC_OUTGOING_INT_ARG_FIRST
5281 : SPARC_INCOMING_INT_ARG_FIRST);
5282 enum mode_class mclass = GET_MODE_CLASS (mode);
5285 if (type && TREE_CODE (type) == VECTOR_TYPE)
5287 /* Vector types deserve special treatment because they are
5288 polymorphic wrt their mode, depending upon whether VIS
5289 instructions are enabled. */
5290 HOST_WIDE_INT size = int_size_in_bytes (type);
5292 gcc_assert ((TARGET_ARCH32 && size <= 8)
5293 || (TARGET_ARCH64 && size <= 32));
5295 if (mode == BLKmode)
5296 return function_arg_vector_value (size,
5297 TYPE_MODE (TREE_TYPE (type)),
5298 SPARC_FP_ARG_FIRST);
5300 mclass = MODE_FLOAT;
5302 else if (type && TARGET_ARCH64)
5304 if (TREE_CODE (type) == RECORD_TYPE)
5306 /* Structures up to 32 bytes in size are passed in registers,
5307 promoted to fp registers where possible. */
5309 gcc_assert (int_size_in_bytes (type) <= 32);
5311 return function_arg_record_value (type, mode, 0, 1, regbase);
5313 else if (TREE_CODE (type) == UNION_TYPE)
5315 HOST_WIDE_INT size = int_size_in_bytes (type);
5317 gcc_assert (size <= 32);
5319 return function_arg_union_value (size, mode, 0, regbase);
5321 else if (AGGREGATE_TYPE_P (type))
5323 /* All other aggregate types are passed in an integer register
5324 in a mode corresponding to the size of the type. */
5325 HOST_WIDE_INT bytes = int_size_in_bytes (type);
5327 gcc_assert (bytes <= 32);
5329 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
5331 /* ??? We probably should have made the same ABI change in
5332 3.4.0 as the one we made for unions. The latter was
5333 required by the SCD though, while the former is not
5334 specified, so we favored compatibility and efficiency.
5336 Now we're stuck for aggregates larger than 16 bytes,
5337 because OImode vanished in the meantime. Let's not
5338 try to be unduly clever, and simply follow the ABI
5339 for unions in that case. */
5340 if (mode == BLKmode)
5341 return function_arg_union_value (bytes, mode, 0, regbase);
5345 else if (mclass == MODE_INT
5346 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
5350 if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
5352 regno = SPARC_FP_ARG_FIRST;
5356 return gen_rtx_REG (mode, regno);
5359 /* Do what is necessary for `va_start'. We look at the current function
5360 to determine if stdarg or varargs is used and return the address of
5361 the first unnamed parameter. */
5364 sparc_builtin_saveregs (void)
5366 int first_reg = current_function_args_info.words;
5370 for (regno = first_reg; regno < SPARC_INT_ARG_MAX; regno++)
5371 emit_move_insn (gen_rtx_MEM (word_mode,
5372 gen_rtx_PLUS (Pmode,
5374 GEN_INT (FIRST_PARM_OFFSET (0)
5377 gen_rtx_REG (word_mode,
5378 SPARC_INCOMING_INT_ARG_FIRST + regno));
5380 address = gen_rtx_PLUS (Pmode,
5382 GEN_INT (FIRST_PARM_OFFSET (0)
5383 + UNITS_PER_WORD * first_reg));
5388 /* Implement `va_start' for stdarg. */
5391 sparc_va_start (tree valist, rtx nextarg)
5393 nextarg = expand_builtin_saveregs ();
5394 std_expand_builtin_va_start (valist, nextarg);
5397 /* Implement `va_arg' for stdarg. */
5400 sparc_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
5402 HOST_WIDE_INT size, rsize, align;
5405 tree ptrtype = build_pointer_type (type);
5407 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
5410 size = rsize = UNITS_PER_WORD;
5416 size = int_size_in_bytes (type);
5417 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
5422 /* For SPARC64, objects requiring 16-byte alignment get it. */
5423 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
5424 align = 2 * UNITS_PER_WORD;
5426 /* SPARC-V9 ABI states that structures up to 16 bytes in size
5427 are left-justified in their slots. */
5428 if (AGGREGATE_TYPE_P (type))
5431 size = rsize = UNITS_PER_WORD;
5441 incr = fold (build2 (PLUS_EXPR, ptr_type_node, incr,
5442 ssize_int (align - 1)));
5443 incr = fold (build2 (BIT_AND_EXPR, ptr_type_node, incr,
5444 ssize_int (-align)));
5447 gimplify_expr (&incr, pre_p, post_p, is_gimple_val, fb_rvalue);
5450 if (BYTES_BIG_ENDIAN && size < rsize)
5451 addr = fold (build2 (PLUS_EXPR, ptr_type_node, incr,
5452 ssize_int (rsize - size)));
5456 addr = fold_convert (build_pointer_type (ptrtype), addr);
5457 addr = build_va_arg_indirect_ref (addr);
5459 /* If the address isn't aligned properly for the type,
5460 we may need to copy to a temporary.
5461 FIXME: This is inefficient. Usually we can do this
5464 && TYPE_ALIGN (type) > BITS_PER_WORD)
5466 tree tmp = create_tmp_var (type, "va_arg_tmp");
5467 tree dest_addr = build_fold_addr_expr (tmp);
5469 tree copy = build_function_call_expr
5470 (implicit_built_in_decls[BUILT_IN_MEMCPY],
5471 tree_cons (NULL_TREE, dest_addr,
5472 tree_cons (NULL_TREE, addr,
5473 tree_cons (NULL_TREE, size_int (rsize),
5476 gimplify_and_add (copy, pre_p);
5480 addr = fold_convert (ptrtype, addr);
5482 incr = fold (build2 (PLUS_EXPR, ptr_type_node, incr, ssize_int (rsize)));
5483 incr = build2 (MODIFY_EXPR, ptr_type_node, valist, incr);
5484 gimplify_and_add (incr, post_p);
5486 return build_va_arg_indirect_ref (addr);
5489 /* Implement the TARGET_VECTOR_MODE_SUPPORTED_P target hook.
5490 Specify whether the vector mode is supported by the hardware. */
5493 sparc_vector_mode_supported_p (enum machine_mode mode)
5495 return TARGET_VIS && VECTOR_MODE_P (mode) ? true : false;
5498 /* Return the string to output an unconditional branch to LABEL, which is
5499 the operand number of the label.
5501 DEST is the destination insn (i.e. the label), INSN is the source. */
5504 output_ubranch (rtx dest, int label, rtx insn)
5506 static char string[64];
5507 bool v9_form = false;
5510 if (TARGET_V9 && INSN_ADDRESSES_SET_P ())
5512 int delta = (INSN_ADDRESSES (INSN_UID (dest))
5513 - INSN_ADDRESSES (INSN_UID (insn)));
5514 /* Leave some instructions for "slop". */
5515 if (delta >= -260000 && delta < 260000)
5520 strcpy (string, "ba%*,pt\t%%xcc, ");
5522 strcpy (string, "b%*\t");
5524 p = strchr (string, '\0');
5535 /* Return the string to output a conditional branch to LABEL, which is
5536 the operand number of the label. OP is the conditional expression.
5537 XEXP (OP, 0) is assumed to be a condition code register (integer or
5538 floating point) and its mode specifies what kind of comparison we made.
5540 DEST is the destination insn (i.e. the label), INSN is the source.
5542 REVERSED is nonzero if we should reverse the sense of the comparison.
5544 ANNUL is nonzero if we should generate an annulling branch. */
5547 output_cbranch (rtx op, rtx dest, int label, int reversed, int annul,
5550 static char string[64];
5551 enum rtx_code code = GET_CODE (op);
5552 rtx cc_reg = XEXP (op, 0);
5553 enum machine_mode mode = GET_MODE (cc_reg);
5554 const char *labelno, *branch;
5555 int spaces = 8, far;
5558 /* v9 branches are limited to +-1MB. If it is too far away,
5571 fbne,a,pn %fcc2, .LC29
5579 far = TARGET_V9 && (get_attr_length (insn) >= 3);
5582 /* Reversal of FP compares takes care -- an ordered compare
5583 becomes an unordered compare and vice versa. */
5584 if (mode == CCFPmode || mode == CCFPEmode)
5585 code = reverse_condition_maybe_unordered (code);
5587 code = reverse_condition (code);
5590 /* Start by writing the branch condition. */
5591 if (mode == CCFPmode || mode == CCFPEmode)
5642 /* ??? !v9: FP branches cannot be preceded by another floating point
5643 insn. Because there is currently no concept of pre-delay slots,
5644 we can fix this only by always emitting a nop before a floating
5649 strcpy (string, "nop\n\t");
5650 strcat (string, branch);
5663 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5675 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5696 strcpy (string, branch);
5698 spaces -= strlen (branch);
5699 p = strchr (string, '\0');
5701 /* Now add the annulling, the label, and a possible noop. */
5714 if (! far && insn && INSN_ADDRESSES_SET_P ())
5716 int delta = (INSN_ADDRESSES (INSN_UID (dest))
5717 - INSN_ADDRESSES (INSN_UID (insn)));
5718 /* Leave some instructions for "slop". */
5719 if (delta < -260000 || delta >= 260000)
5723 if (mode == CCFPmode || mode == CCFPEmode)
5725 static char v9_fcc_labelno[] = "%%fccX, ";
5726 /* Set the char indicating the number of the fcc reg to use. */
5727 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
5728 labelno = v9_fcc_labelno;
5731 gcc_assert (REGNO (cc_reg) == SPARC_FCC_REG);
5735 else if (mode == CCXmode || mode == CCX_NOOVmode)
5737 labelno = "%%xcc, ";
5742 labelno = "%%icc, ";
5747 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
5750 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
5763 strcpy (p, labelno);
5764 p = strchr (p, '\0');
5767 strcpy (p, ".+12\n\t nop\n\tb\t");
5768 /* Skip the next insn if requested or
5769 if we know that it will be a nop. */
5770 if (annul || ! final_sequence)
5784 /* Emit a library call comparison between floating point X and Y.
5785 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
5786 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
5787 values as arguments instead of the TFmode registers themselves,
5788 that's why we cannot call emit_float_lib_cmp. */
5790 sparc_emit_float_lib_cmp (rtx x, rtx y, enum rtx_code comparison)
5793 rtx slot0, slot1, result, tem, tem2;
5794 enum machine_mode mode;
5799 qpfunc = (TARGET_ARCH64) ? "_Qp_feq" : "_Q_feq";
5803 qpfunc = (TARGET_ARCH64) ? "_Qp_fne" : "_Q_fne";
5807 qpfunc = (TARGET_ARCH64) ? "_Qp_fgt" : "_Q_fgt";
5811 qpfunc = (TARGET_ARCH64) ? "_Qp_fge" : "_Q_fge";
5815 qpfunc = (TARGET_ARCH64) ? "_Qp_flt" : "_Q_flt";
5819 qpfunc = (TARGET_ARCH64) ? "_Qp_fle" : "_Q_fle";
5830 qpfunc = (TARGET_ARCH64) ? "_Qp_cmp" : "_Q_cmp";
5839 if (GET_CODE (x) != MEM)
5841 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5842 emit_insn (gen_rtx_SET (VOIDmode, slot0, x));
5847 if (GET_CODE (y) != MEM)
5849 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5850 emit_insn (gen_rtx_SET (VOIDmode, slot1, y));
5855 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
5857 XEXP (slot0, 0), Pmode,
5858 XEXP (slot1, 0), Pmode);
5864 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
5866 x, TFmode, y, TFmode);
5872 /* Immediately move the result of the libcall into a pseudo
5873 register so reload doesn't clobber the value if it needs
5874 the return register for a spill reg. */
5875 result = gen_reg_rtx (mode);
5876 emit_move_insn (result, hard_libcall_value (mode));
5881 emit_cmp_insn (result, const0_rtx, NE, NULL_RTX, mode, 0);
5885 emit_cmp_insn (result, GEN_INT(3), comparison == UNORDERED ? EQ : NE,
5890 emit_cmp_insn (result, const1_rtx,
5891 comparison == UNGT ? GT : NE, NULL_RTX, mode, 0);
5894 emit_cmp_insn (result, const2_rtx, NE, NULL_RTX, mode, 0);
5897 tem = gen_reg_rtx (mode);
5899 emit_insn (gen_andsi3 (tem, result, const1_rtx));
5901 emit_insn (gen_anddi3 (tem, result, const1_rtx));
5902 emit_cmp_insn (tem, const0_rtx, NE, NULL_RTX, mode, 0);
5906 tem = gen_reg_rtx (mode);
5908 emit_insn (gen_addsi3 (tem, result, const1_rtx));
5910 emit_insn (gen_adddi3 (tem, result, const1_rtx));
5911 tem2 = gen_reg_rtx (mode);
5913 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
5915 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
5916 emit_cmp_insn (tem2, const0_rtx, comparison == UNEQ ? EQ : NE,
5922 /* Generate an unsigned DImode to FP conversion. This is the same code
5923 optabs would emit if we didn't have TFmode patterns. */
5926 sparc_emit_floatunsdi (rtx *operands, enum machine_mode mode)
5928 rtx neglab, donelab, i0, i1, f0, in, out;
5931 in = force_reg (DImode, operands[1]);
5932 neglab = gen_label_rtx ();
5933 donelab = gen_label_rtx ();
5934 i0 = gen_reg_rtx (DImode);
5935 i1 = gen_reg_rtx (DImode);
5936 f0 = gen_reg_rtx (mode);
5938 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
5940 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
5941 emit_jump_insn (gen_jump (donelab));
5944 emit_label (neglab);
5946 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
5947 emit_insn (gen_anddi3 (i1, in, const1_rtx));
5948 emit_insn (gen_iordi3 (i0, i0, i1));
5949 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
5950 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
5952 emit_label (donelab);
5955 /* Generate an FP to unsigned DImode conversion. This is the same code
5956 optabs would emit if we didn't have TFmode patterns. */
5959 sparc_emit_fixunsdi (rtx *operands, enum machine_mode mode)
5961 rtx neglab, donelab, i0, i1, f0, in, out, limit;
5964 in = force_reg (mode, operands[1]);
5965 neglab = gen_label_rtx ();
5966 donelab = gen_label_rtx ();
5967 i0 = gen_reg_rtx (DImode);
5968 i1 = gen_reg_rtx (DImode);
5969 limit = gen_reg_rtx (mode);
5970 f0 = gen_reg_rtx (mode);
5972 emit_move_insn (limit,
5973 CONST_DOUBLE_FROM_REAL_VALUE (
5974 REAL_VALUE_ATOF ("9223372036854775808.0", mode), mode));
5975 emit_cmp_and_jump_insns (in, limit, GE, NULL_RTX, mode, 0, neglab);
5977 emit_insn (gen_rtx_SET (VOIDmode,
5979 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, in))));
5980 emit_jump_insn (gen_jump (donelab));
5983 emit_label (neglab);
5985 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_MINUS (mode, in, limit)));
5986 emit_insn (gen_rtx_SET (VOIDmode,
5988 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, f0))));
5989 emit_insn (gen_movdi (i1, const1_rtx));
5990 emit_insn (gen_ashldi3 (i1, i1, GEN_INT (63)));
5991 emit_insn (gen_xordi3 (out, i0, i1));
5993 emit_label (donelab);
5996 /* Return the string to output a conditional branch to LABEL, testing
5997 register REG. LABEL is the operand number of the label; REG is the
5998 operand number of the reg. OP is the conditional expression. The mode
5999 of REG says what kind of comparison we made.
6001 DEST is the destination insn (i.e. the label), INSN is the source.
6003 REVERSED is nonzero if we should reverse the sense of the comparison.
6005 ANNUL is nonzero if we should generate an annulling branch. */
6008 output_v9branch (rtx op, rtx dest, int reg, int label, int reversed,
6009 int annul, rtx insn)
6011 static char string[64];
6012 enum rtx_code code = GET_CODE (op);
6013 enum machine_mode mode = GET_MODE (XEXP (op, 0));
6018 /* branch on register are limited to +-128KB. If it is too far away,
6031 brgez,a,pn %o1, .LC29
6037 ba,pt %xcc, .LC29 */
6039 far = get_attr_length (insn) >= 3;
6041 /* If not floating-point or if EQ or NE, we can just reverse the code. */
6043 code = reverse_condition (code);
6045 /* Only 64 bit versions of these instructions exist. */
6046 gcc_assert (mode == DImode);
6048 /* Start by writing the branch condition. */
6053 strcpy (string, "brnz");
6057 strcpy (string, "brz");
6061 strcpy (string, "brgez");
6065 strcpy (string, "brlz");
6069 strcpy (string, "brlez");
6073 strcpy (string, "brgz");
6080 p = strchr (string, '\0');
6082 /* Now add the annulling, reg, label, and nop. */
6089 if (insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
6092 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
6097 *p = p < string + 8 ? '\t' : ' ';
6105 int veryfar = 1, delta;
6107 if (INSN_ADDRESSES_SET_P ())
6109 delta = (INSN_ADDRESSES (INSN_UID (dest))
6110 - INSN_ADDRESSES (INSN_UID (insn)));
6111 /* Leave some instructions for "slop". */
6112 if (delta >= -260000 && delta < 260000)
6116 strcpy (p, ".+12\n\t nop\n\t");
6117 /* Skip the next insn if requested or
6118 if we know that it will be a nop. */
6119 if (annul || ! final_sequence)
6129 strcpy (p, "ba,pt\t%%xcc, ");
6143 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
6144 Such instructions cannot be used in the delay slot of return insn on v9.
6145 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
6149 epilogue_renumber (register rtx *where, int test)
6151 register const char *fmt;
6153 register enum rtx_code code;
6158 code = GET_CODE (*where);
6163 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
6165 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
6166 *where = gen_rtx_REG (GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
6174 /* Do not replace the frame pointer with the stack pointer because
6175 it can cause the delayed instruction to load below the stack.
6176 This occurs when instructions like:
6178 (set (reg/i:SI 24 %i0)
6179 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
6180 (const_int -20 [0xffffffec])) 0))
6182 are in the return delayed slot. */
6184 if (GET_CODE (XEXP (*where, 0)) == REG
6185 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
6186 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
6187 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
6192 if (SPARC_STACK_BIAS
6193 && GET_CODE (XEXP (*where, 0)) == REG
6194 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
6202 fmt = GET_RTX_FORMAT (code);
6204 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6209 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
6210 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
6213 else if (fmt[i] == 'e'
6214 && epilogue_renumber (&(XEXP (*where, i)), test))
6220 /* Leaf functions and non-leaf functions have different needs. */
6223 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
6226 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
6228 static const int *const reg_alloc_orders[] = {
6229 reg_leaf_alloc_order,
6230 reg_nonleaf_alloc_order};
6233 order_regs_for_local_alloc (void)
6235 static int last_order_nonleaf = 1;
6237 if (regs_ever_live[15] != last_order_nonleaf)
6239 last_order_nonleaf = !last_order_nonleaf;
6240 memcpy ((char *) reg_alloc_order,
6241 (const char *) reg_alloc_orders[last_order_nonleaf],
6242 FIRST_PSEUDO_REGISTER * sizeof (int));
6246 /* Return 1 if REG and MEM are legitimate enough to allow the various
6247 mem<-->reg splits to be run. */
6250 sparc_splitdi_legitimate (rtx reg, rtx mem)
6252 /* Punt if we are here by mistake. */
6253 gcc_assert (reload_completed);
6255 /* We must have an offsettable memory reference. */
6256 if (! offsettable_memref_p (mem))
6259 /* If we have legitimate args for ldd/std, we do not want
6260 the split to happen. */
6261 if ((REGNO (reg) % 2) == 0
6262 && mem_min_alignment (mem, 8))
6269 /* Return 1 if x and y are some kind of REG and they refer to
6270 different hard registers. This test is guaranteed to be
6271 run after reload. */
6274 sparc_absnegfloat_split_legitimate (rtx x, rtx y)
6276 if (GET_CODE (x) != REG)
6278 if (GET_CODE (y) != REG)
6280 if (REGNO (x) == REGNO (y))
6285 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
6286 This makes them candidates for using ldd and std insns.
6288 Note reg1 and reg2 *must* be hard registers. */
6291 registers_ok_for_ldd_peep (rtx reg1, rtx reg2)
6293 /* We might have been passed a SUBREG. */
6294 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
6297 if (REGNO (reg1) % 2 != 0)
6300 /* Integer ldd is deprecated in SPARC V9 */
6301 if (TARGET_V9 && REGNO (reg1) < 32)
6304 return (REGNO (reg1) == REGNO (reg2) - 1);
6307 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
6310 This can only happen when addr1 and addr2, the addresses in mem1
6311 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
6312 addr1 must also be aligned on a 64-bit boundary.
6314 Also iff dependent_reg_rtx is not null it should not be used to
6315 compute the address for mem1, i.e. we cannot optimize a sequence
6327 But, note that the transformation from:
6332 is perfectly fine. Thus, the peephole2 patterns always pass us
6333 the destination register of the first load, never the second one.
6335 For stores we don't have a similar problem, so dependent_reg_rtx is
6339 mems_ok_for_ldd_peep (rtx mem1, rtx mem2, rtx dependent_reg_rtx)
6343 HOST_WIDE_INT offset1;
6345 /* The mems cannot be volatile. */
6346 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
6349 /* MEM1 should be aligned on a 64-bit boundary. */
6350 if (MEM_ALIGN (mem1) < 64)
6353 addr1 = XEXP (mem1, 0);
6354 addr2 = XEXP (mem2, 0);
6356 /* Extract a register number and offset (if used) from the first addr. */
6357 if (GET_CODE (addr1) == PLUS)
6359 /* If not a REG, return zero. */
6360 if (GET_CODE (XEXP (addr1, 0)) != REG)
6364 reg1 = REGNO (XEXP (addr1, 0));
6365 /* The offset must be constant! */
6366 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
6368 offset1 = INTVAL (XEXP (addr1, 1));
6371 else if (GET_CODE (addr1) != REG)
6375 reg1 = REGNO (addr1);
6376 /* This was a simple (mem (reg)) expression. Offset is 0. */
6380 /* Make sure the second address is a (mem (plus (reg) (const_int). */
6381 if (GET_CODE (addr2) != PLUS)
6384 if (GET_CODE (XEXP (addr2, 0)) != REG
6385 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
6388 if (reg1 != REGNO (XEXP (addr2, 0)))
6391 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
6394 /* The first offset must be evenly divisible by 8 to ensure the
6395 address is 64 bit aligned. */
6396 if (offset1 % 8 != 0)
6399 /* The offset for the second addr must be 4 more than the first addr. */
6400 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
6403 /* All the tests passed. addr1 and addr2 are valid for ldd and std
6408 /* Return 1 if reg is a pseudo, or is the first register in
6409 a hard register pair. This makes it a candidate for use in
6410 ldd and std insns. */
6413 register_ok_for_ldd (rtx reg)
6415 /* We might have been passed a SUBREG. */
6416 if (GET_CODE (reg) != REG)
6419 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
6420 return (REGNO (reg) % 2 == 0);
6425 /* Print operand X (an rtx) in assembler syntax to file FILE.
6426 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
6427 For `%' followed by punctuation, CODE is the punctuation and X is null. */
6430 print_operand (FILE *file, rtx x, int code)
6435 /* Output an insn in a delay slot. */
6437 sparc_indent_opcode = 1;
6439 fputs ("\n\t nop", file);
6442 /* Output an annul flag if there's nothing for the delay slot and we
6443 are optimizing. This is always used with '(' below.
6444 Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
6445 this is a dbx bug. So, we only do this when optimizing.
6446 On UltraSPARC, a branch in a delay slot causes a pipeline flush.
6447 Always emit a nop in case the next instruction is a branch. */
6448 if (! final_sequence && (optimize && (int)sparc_cpu < PROCESSOR_V9))
6452 /* Output a 'nop' if there's nothing for the delay slot and we are
6453 not optimizing. This is always used with '*' above. */
6454 if (! final_sequence && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
6455 fputs ("\n\t nop", file);
6456 else if (final_sequence)
6457 sparc_indent_opcode = 1;
6460 /* Output the right displacement from the saved PC on function return.
6461 The caller may have placed an "unimp" insn immediately after the call
6462 so we have to account for it. This insn is used in the 32-bit ABI
6463 when calling a function that returns a non zero-sized structure. The
6464 64-bit ABI doesn't have it. Be careful to have this test be the same
6465 as that used on the call. */
6467 && current_function_returns_struct
6468 && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl)))
6470 && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))))
6476 /* Output the Embedded Medium/Anywhere code model base register. */
6477 fputs (EMBMEDANY_BASE_REG, file);
6480 /* Print some local dynamic TLS name. */
6481 assemble_name (file, get_some_local_dynamic_name ());
6485 /* Adjust the operand to take into account a RESTORE operation. */
6486 if (GET_CODE (x) == CONST_INT)
6488 else if (GET_CODE (x) != REG)
6489 output_operand_lossage ("invalid %%Y operand");
6490 else if (REGNO (x) < 8)
6491 fputs (reg_names[REGNO (x)], file);
6492 else if (REGNO (x) >= 24 && REGNO (x) < 32)
6493 fputs (reg_names[REGNO (x)-16], file);
6495 output_operand_lossage ("invalid %%Y operand");
6498 /* Print out the low order register name of a register pair. */
6499 if (WORDS_BIG_ENDIAN)
6500 fputs (reg_names[REGNO (x)+1], file);
6502 fputs (reg_names[REGNO (x)], file);
6505 /* Print out the high order register name of a register pair. */
6506 if (WORDS_BIG_ENDIAN)
6507 fputs (reg_names[REGNO (x)], file);
6509 fputs (reg_names[REGNO (x)+1], file);
6512 /* Print out the second register name of a register pair or quad.
6513 I.e., R (%o0) => %o1. */
6514 fputs (reg_names[REGNO (x)+1], file);
6517 /* Print out the third register name of a register quad.
6518 I.e., S (%o0) => %o2. */
6519 fputs (reg_names[REGNO (x)+2], file);
6522 /* Print out the fourth register name of a register quad.
6523 I.e., T (%o0) => %o3. */
6524 fputs (reg_names[REGNO (x)+3], file);
6527 /* Print a condition code register. */
6528 if (REGNO (x) == SPARC_ICC_REG)
6530 /* We don't handle CC[X]_NOOVmode because they're not supposed
6532 if (GET_MODE (x) == CCmode)
6533 fputs ("%icc", file);
6534 else if (GET_MODE (x) == CCXmode)
6535 fputs ("%xcc", file);
6540 /* %fccN register */
6541 fputs (reg_names[REGNO (x)], file);
6544 /* Print the operand's address only. */
6545 output_address (XEXP (x, 0));
6548 /* In this case we need a register. Use %g0 if the
6549 operand is const0_rtx. */
6551 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
6553 fputs ("%g0", file);
6560 switch (GET_CODE (x))
6562 case IOR: fputs ("or", file); break;
6563 case AND: fputs ("and", file); break;
6564 case XOR: fputs ("xor", file); break;
6565 default: output_operand_lossage ("invalid %%A operand");
6570 switch (GET_CODE (x))
6572 case IOR: fputs ("orn", file); break;
6573 case AND: fputs ("andn", file); break;
6574 case XOR: fputs ("xnor", file); break;
6575 default: output_operand_lossage ("invalid %%B operand");
6579 /* These are used by the conditional move instructions. */
6583 enum rtx_code rc = GET_CODE (x);
6587 enum machine_mode mode = GET_MODE (XEXP (x, 0));
6588 if (mode == CCFPmode || mode == CCFPEmode)
6589 rc = reverse_condition_maybe_unordered (GET_CODE (x));
6591 rc = reverse_condition (GET_CODE (x));
6595 case NE: fputs ("ne", file); break;
6596 case EQ: fputs ("e", file); break;
6597 case GE: fputs ("ge", file); break;
6598 case GT: fputs ("g", file); break;
6599 case LE: fputs ("le", file); break;
6600 case LT: fputs ("l", file); break;
6601 case GEU: fputs ("geu", file); break;
6602 case GTU: fputs ("gu", file); break;
6603 case LEU: fputs ("leu", file); break;
6604 case LTU: fputs ("lu", file); break;
6605 case LTGT: fputs ("lg", file); break;
6606 case UNORDERED: fputs ("u", file); break;
6607 case ORDERED: fputs ("o", file); break;
6608 case UNLT: fputs ("ul", file); break;
6609 case UNLE: fputs ("ule", file); break;
6610 case UNGT: fputs ("ug", file); break;
6611 case UNGE: fputs ("uge", file); break;
6612 case UNEQ: fputs ("ue", file); break;
6613 default: output_operand_lossage (code == 'c'
6614 ? "invalid %%c operand"
6615 : "invalid %%C operand");
6620 /* These are used by the movr instruction pattern. */
6624 enum rtx_code rc = (code == 'd'
6625 ? reverse_condition (GET_CODE (x))
6629 case NE: fputs ("ne", file); break;
6630 case EQ: fputs ("e", file); break;
6631 case GE: fputs ("gez", file); break;
6632 case LT: fputs ("lz", file); break;
6633 case LE: fputs ("lez", file); break;
6634 case GT: fputs ("gz", file); break;
6635 default: output_operand_lossage (code == 'd'
6636 ? "invalid %%d operand"
6637 : "invalid %%D operand");
6644 /* Print a sign-extended character. */
6645 int i = trunc_int_for_mode (INTVAL (x), QImode);
6646 fprintf (file, "%d", i);
6651 /* Operand must be a MEM; write its address. */
6652 if (GET_CODE (x) != MEM)
6653 output_operand_lossage ("invalid %%f operand");
6654 output_address (XEXP (x, 0));
6659 /* Print a sign-extended 32-bit value. */
6661 if (GET_CODE(x) == CONST_INT)
6663 else if (GET_CODE(x) == CONST_DOUBLE)
6664 i = CONST_DOUBLE_LOW (x);
6667 output_operand_lossage ("invalid %%s operand");
6670 i = trunc_int_for_mode (i, SImode);
6671 fprintf (file, HOST_WIDE_INT_PRINT_DEC, i);
6676 /* Do nothing special. */
6680 /* Undocumented flag. */
6681 output_operand_lossage ("invalid operand output code");
6684 if (GET_CODE (x) == REG)
6685 fputs (reg_names[REGNO (x)], file);
6686 else if (GET_CODE (x) == MEM)
6689 /* Poor Sun assembler doesn't understand absolute addressing. */
6690 if (CONSTANT_P (XEXP (x, 0)))
6691 fputs ("%g0+", file);
6692 output_address (XEXP (x, 0));
6695 else if (GET_CODE (x) == HIGH)
6697 fputs ("%hi(", file);
6698 output_addr_const (file, XEXP (x, 0));
6701 else if (GET_CODE (x) == LO_SUM)
6703 print_operand (file, XEXP (x, 0), 0);
6704 if (TARGET_CM_MEDMID)
6705 fputs ("+%l44(", file);
6707 fputs ("+%lo(", file);
6708 output_addr_const (file, XEXP (x, 1));
6711 else if (GET_CODE (x) == CONST_DOUBLE
6712 && (GET_MODE (x) == VOIDmode
6713 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
6715 if (CONST_DOUBLE_HIGH (x) == 0)
6716 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
6717 else if (CONST_DOUBLE_HIGH (x) == -1
6718 && CONST_DOUBLE_LOW (x) < 0)
6719 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
6721 output_operand_lossage ("long long constant not a valid immediate operand");
6723 else if (GET_CODE (x) == CONST_DOUBLE)
6724 output_operand_lossage ("floating point constant not a valid immediate operand");
6725 else { output_addr_const (file, x); }
6728 /* Target hook for assembling integer objects. The sparc version has
6729 special handling for aligned DI-mode objects. */
6732 sparc_assemble_integer (rtx x, unsigned int size, int aligned_p)
6734 /* ??? We only output .xword's for symbols and only then in environments
6735 where the assembler can handle them. */
6736 if (aligned_p && size == 8
6737 && (GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE))
6741 assemble_integer_with_op ("\t.xword\t", x);
6746 assemble_aligned_integer (4, const0_rtx);
6747 assemble_aligned_integer (4, x);
6751 return default_assemble_integer (x, size, aligned_p);
6754 /* Return the value of a code used in the .proc pseudo-op that says
6755 what kind of result this function returns. For non-C types, we pick
6756 the closest C type. */
6758 #ifndef SHORT_TYPE_SIZE
6759 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
6762 #ifndef INT_TYPE_SIZE
6763 #define INT_TYPE_SIZE BITS_PER_WORD
6766 #ifndef LONG_TYPE_SIZE
6767 #define LONG_TYPE_SIZE BITS_PER_WORD
6770 #ifndef LONG_LONG_TYPE_SIZE
6771 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
6774 #ifndef FLOAT_TYPE_SIZE
6775 #define FLOAT_TYPE_SIZE BITS_PER_WORD
6778 #ifndef DOUBLE_TYPE_SIZE
6779 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6782 #ifndef LONG_DOUBLE_TYPE_SIZE
6783 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6787 sparc_type_code (register tree type)
6789 register unsigned long qualifiers = 0;
6790 register unsigned shift;
6792 /* Only the first 30 bits of the qualifier are valid. We must refrain from
6793 setting more, since some assemblers will give an error for this. Also,
6794 we must be careful to avoid shifts of 32 bits or more to avoid getting
6795 unpredictable results. */
6797 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
6799 switch (TREE_CODE (type))
6805 qualifiers |= (3 << shift);
6810 qualifiers |= (2 << shift);
6814 case REFERENCE_TYPE:
6816 qualifiers |= (1 << shift);
6820 return (qualifiers | 8);
6823 case QUAL_UNION_TYPE:
6824 return (qualifiers | 9);
6827 return (qualifiers | 10);
6830 return (qualifiers | 16);
6833 /* If this is a range type, consider it to be the underlying
6835 if (TREE_TYPE (type) != 0)
6838 /* Carefully distinguish all the standard types of C,
6839 without messing up if the language is not C. We do this by
6840 testing TYPE_PRECISION and TYPE_UNSIGNED. The old code used to
6841 look at both the names and the above fields, but that's redundant.
6842 Any type whose size is between two C types will be considered
6843 to be the wider of the two types. Also, we do not have a
6844 special code to use for "long long", so anything wider than
6845 long is treated the same. Note that we can't distinguish
6846 between "int" and "long" in this code if they are the same
6847 size, but that's fine, since neither can the assembler. */
6849 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
6850 return (qualifiers | (TYPE_UNSIGNED (type) ? 12 : 2));
6852 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
6853 return (qualifiers | (TYPE_UNSIGNED (type) ? 13 : 3));
6855 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
6856 return (qualifiers | (TYPE_UNSIGNED (type) ? 14 : 4));
6859 return (qualifiers | (TYPE_UNSIGNED (type) ? 15 : 5));
6862 /* If this is a range type, consider it to be the underlying
6864 if (TREE_TYPE (type) != 0)
6867 /* Carefully distinguish all the standard types of C,
6868 without messing up if the language is not C. */
6870 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
6871 return (qualifiers | 6);
6874 return (qualifiers | 7);
6876 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
6877 /* ??? We need to distinguish between double and float complex types,
6878 but I don't know how yet because I can't reach this code from
6879 existing front-ends. */
6880 return (qualifiers | 7); /* Who knows? */
6883 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
6884 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
6885 case LANG_TYPE: /* ? */
6889 gcc_unreachable (); /* Not a type! */
6896 /* Nested function support. */
6898 /* Emit RTL insns to initialize the variable parts of a trampoline.
6899 FNADDR is an RTX for the address of the function's pure code.
6900 CXT is an RTX for the static chain value for the function.
6902 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
6903 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
6904 (to store insns). This is a bit excessive. Perhaps a different
6905 mechanism would be better here.
6907 Emit enough FLUSH insns to synchronize the data and instruction caches. */
6910 sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
6912 /* SPARC 32-bit trampoline:
6915 sethi %hi(static), %g2
6917 or %g2, %lo(static), %g2
6919 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
6920 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
6924 (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
6925 expand_binop (SImode, ior_optab,
6926 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
6927 size_int (10), 0, 1),
6928 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
6929 NULL_RTX, 1, OPTAB_DIRECT));
6932 (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6933 expand_binop (SImode, ior_optab,
6934 expand_shift (RSHIFT_EXPR, SImode, cxt,
6935 size_int (10), 0, 1),
6936 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
6937 NULL_RTX, 1, OPTAB_DIRECT));
6940 (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6941 expand_binop (SImode, ior_optab,
6942 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
6943 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
6944 NULL_RTX, 1, OPTAB_DIRECT));
6947 (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6948 expand_binop (SImode, ior_optab,
6949 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
6950 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
6951 NULL_RTX, 1, OPTAB_DIRECT));
6953 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
6954 aligned on a 16 byte boundary so one flush clears it all. */
6955 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
6956 if (sparc_cpu != PROCESSOR_ULTRASPARC
6957 && sparc_cpu != PROCESSOR_ULTRASPARC3)
6958 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
6959 plus_constant (tramp, 8)))));
6961 /* Call __enable_execute_stack after writing onto the stack to make sure
6962 the stack address is accessible. */
6963 #ifdef ENABLE_EXECUTE_STACK
6964 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
6965 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
6970 /* The 64-bit version is simpler because it makes more sense to load the
6971 values as "immediate" data out of the trampoline. It's also easier since
6972 we can read the PC without clobbering a register. */
6975 sparc64_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
6977 /* SPARC 64-bit trampoline:
6986 emit_move_insn (gen_rtx_MEM (SImode, tramp),
6987 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
6988 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6989 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
6990 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6991 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
6992 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6993 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
6994 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
6995 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
6996 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
6998 if (sparc_cpu != PROCESSOR_ULTRASPARC
6999 && sparc_cpu != PROCESSOR_ULTRASPARC3)
7000 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
7002 /* Call __enable_execute_stack after writing onto the stack to make sure
7003 the stack address is accessible. */
7004 #ifdef ENABLE_EXECUTE_STACK
7005 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
7006 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
7010 /* Adjust the cost of a scheduling dependency. Return the new cost of
7011 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7014 supersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
7016 enum attr_type insn_type;
7018 if (! recog_memoized (insn))
7021 insn_type = get_attr_type (insn);
7023 if (REG_NOTE_KIND (link) == 0)
7025 /* Data dependency; DEP_INSN writes a register that INSN reads some
7028 /* if a load, then the dependence must be on the memory address;
7029 add an extra "cycle". Note that the cost could be two cycles
7030 if the reg was written late in an instruction group; we ca not tell
7032 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
7035 /* Get the delay only if the address of the store is the dependence. */
7036 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
7038 rtx pat = PATTERN(insn);
7039 rtx dep_pat = PATTERN (dep_insn);
7041 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7042 return cost; /* This should not happen! */
7044 /* The dependency between the two instructions was on the data that
7045 is being stored. Assume that this implies that the address of the
7046 store is not dependent. */
7047 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7050 return cost + 3; /* An approximation. */
7053 /* A shift instruction cannot receive its data from an instruction
7054 in the same cycle; add a one cycle penalty. */
7055 if (insn_type == TYPE_SHIFT)
7056 return cost + 3; /* Split before cascade into shift. */
7060 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7061 INSN writes some cycles later. */
7063 /* These are only significant for the fpu unit; writing a fp reg before
7064 the fpu has finished with it stalls the processor. */
7066 /* Reusing an integer register causes no problems. */
7067 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7075 hypersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
7077 enum attr_type insn_type, dep_type;
7078 rtx pat = PATTERN(insn);
7079 rtx dep_pat = PATTERN (dep_insn);
7081 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7084 insn_type = get_attr_type (insn);
7085 dep_type = get_attr_type (dep_insn);
7087 switch (REG_NOTE_KIND (link))
7090 /* Data dependency; DEP_INSN writes a register that INSN reads some
7097 /* Get the delay iff the address of the store is the dependence. */
7098 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7101 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7108 /* If a load, then the dependence must be on the memory address. If
7109 the addresses aren't equal, then it might be a false dependency */
7110 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7112 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7113 || GET_CODE (SET_DEST (dep_pat)) != MEM
7114 || GET_CODE (SET_SRC (pat)) != MEM
7115 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
7116 XEXP (SET_SRC (pat), 0)))
7124 /* Compare to branch latency is 0. There is no benefit from
7125 separating compare and branch. */
7126 if (dep_type == TYPE_COMPARE)
7128 /* Floating point compare to branch latency is less than
7129 compare to conditional move. */
7130 if (dep_type == TYPE_FPCMP)
7139 /* Anti-dependencies only penalize the fpu unit. */
7140 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7152 sparc_adjust_cost(rtx insn, rtx link, rtx dep, int cost)
7156 case PROCESSOR_SUPERSPARC:
7157 cost = supersparc_adjust_cost (insn, link, dep, cost);
7159 case PROCESSOR_HYPERSPARC:
7160 case PROCESSOR_SPARCLITE86X:
7161 cost = hypersparc_adjust_cost (insn, link, dep, cost);
7170 sparc_sched_init (FILE *dump ATTRIBUTE_UNUSED,
7171 int sched_verbose ATTRIBUTE_UNUSED,
7172 int max_ready ATTRIBUTE_UNUSED)
7177 sparc_use_sched_lookahead (void)
7179 if (sparc_cpu == PROCESSOR_ULTRASPARC
7180 || sparc_cpu == PROCESSOR_ULTRASPARC3)
7182 if ((1 << sparc_cpu) &
7183 ((1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
7184 (1 << PROCESSOR_SPARCLITE86X)))
7190 sparc_issue_rate (void)
7197 /* Assume V9 processors are capable of at least dual-issue. */
7199 case PROCESSOR_SUPERSPARC:
7201 case PROCESSOR_HYPERSPARC:
7202 case PROCESSOR_SPARCLITE86X:
7204 case PROCESSOR_ULTRASPARC:
7205 case PROCESSOR_ULTRASPARC3:
7211 set_extends (rtx insn)
7213 register rtx pat = PATTERN (insn);
7215 switch (GET_CODE (SET_SRC (pat)))
7217 /* Load and some shift instructions zero extend. */
7220 /* sethi clears the high bits */
7222 /* LO_SUM is used with sethi. sethi cleared the high
7223 bits and the values used with lo_sum are positive */
7225 /* Store flag stores 0 or 1 */
7235 rtx op0 = XEXP (SET_SRC (pat), 0);
7236 rtx op1 = XEXP (SET_SRC (pat), 1);
7237 if (GET_CODE (op1) == CONST_INT)
7238 return INTVAL (op1) >= 0;
7239 if (GET_CODE (op0) != REG)
7241 if (sparc_check_64 (op0, insn) == 1)
7243 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7248 rtx op0 = XEXP (SET_SRC (pat), 0);
7249 rtx op1 = XEXP (SET_SRC (pat), 1);
7250 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
7252 if (GET_CODE (op1) == CONST_INT)
7253 return INTVAL (op1) >= 0;
7254 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7257 return GET_MODE (SET_SRC (pat)) == SImode;
7258 /* Positive integers leave the high bits zero. */
7260 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
7262 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
7265 return - (GET_MODE (SET_SRC (pat)) == SImode);
7267 return sparc_check_64 (SET_SRC (pat), insn);
7273 /* We _ought_ to have only one kind per function, but... */
7274 static GTY(()) rtx sparc_addr_diff_list;
7275 static GTY(()) rtx sparc_addr_list;
7278 sparc_defer_case_vector (rtx lab, rtx vec, int diff)
7280 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
7282 sparc_addr_diff_list
7283 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
7285 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
7289 sparc_output_addr_vec (rtx vec)
7291 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7292 int idx, vlen = XVECLEN (body, 0);
7294 #ifdef ASM_OUTPUT_ADDR_VEC_START
7295 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7298 #ifdef ASM_OUTPUT_CASE_LABEL
7299 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7302 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7305 for (idx = 0; idx < vlen; idx++)
7307 ASM_OUTPUT_ADDR_VEC_ELT
7308 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
7311 #ifdef ASM_OUTPUT_ADDR_VEC_END
7312 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7317 sparc_output_addr_diff_vec (rtx vec)
7319 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7320 rtx base = XEXP (XEXP (body, 0), 0);
7321 int idx, vlen = XVECLEN (body, 1);
7323 #ifdef ASM_OUTPUT_ADDR_VEC_START
7324 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7327 #ifdef ASM_OUTPUT_CASE_LABEL
7328 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7331 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7334 for (idx = 0; idx < vlen; idx++)
7336 ASM_OUTPUT_ADDR_DIFF_ELT
7339 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
7340 CODE_LABEL_NUMBER (base));
7343 #ifdef ASM_OUTPUT_ADDR_VEC_END
7344 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7349 sparc_output_deferred_case_vectors (void)
7354 if (sparc_addr_list == NULL_RTX
7355 && sparc_addr_diff_list == NULL_RTX)
7358 /* Align to cache line in the function's code section. */
7359 current_function_section (current_function_decl);
7361 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
7363 ASM_OUTPUT_ALIGN (asm_out_file, align);
7365 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
7366 sparc_output_addr_vec (XEXP (t, 0));
7367 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
7368 sparc_output_addr_diff_vec (XEXP (t, 0));
7370 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
7373 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
7374 unknown. Return 1 if the high bits are zero, -1 if the register is
7377 sparc_check_64 (rtx x, rtx insn)
7379 /* If a register is set only once it is safe to ignore insns this
7380 code does not know how to handle. The loop will either recognize
7381 the single set and return the correct value or fail to recognize
7386 gcc_assert (GET_CODE (x) == REG);
7388 if (GET_MODE (x) == DImode)
7389 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
7391 if (flag_expensive_optimizations
7392 && REG_N_SETS (REGNO (y)) == 1)
7398 insn = get_last_insn_anywhere ();
7403 while ((insn = PREV_INSN (insn)))
7405 switch (GET_CODE (insn))
7418 rtx pat = PATTERN (insn);
7419 if (GET_CODE (pat) != SET)
7421 if (rtx_equal_p (x, SET_DEST (pat)))
7422 return set_extends (insn);
7423 if (y && rtx_equal_p (y, SET_DEST (pat)))
7424 return set_extends (insn);
7425 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
7433 /* Returns assembly code to perform a DImode shift using
7434 a 64-bit global or out register on SPARC-V8+. */
7436 output_v8plus_shift (rtx *operands, rtx insn, const char *opcode)
7438 static char asm_code[60];
7440 /* The scratch register is only required when the destination
7441 register is not a 64-bit global or out register. */
7442 if (which_alternative != 2)
7443 operands[3] = operands[0];
7445 /* We can only shift by constants <= 63. */
7446 if (GET_CODE (operands[2]) == CONST_INT)
7447 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
7449 if (GET_CODE (operands[1]) == CONST_INT)
7451 output_asm_insn ("mov\t%1, %3", operands);
7455 output_asm_insn ("sllx\t%H1, 32, %3", operands);
7456 if (sparc_check_64 (operands[1], insn) <= 0)
7457 output_asm_insn ("srl\t%L1, 0, %L1", operands);
7458 output_asm_insn ("or\t%L1, %3, %3", operands);
7461 strcpy(asm_code, opcode);
7463 if (which_alternative != 2)
7464 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
7466 return strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
7469 /* Output rtl to increment the profiler label LABELNO
7470 for profiling a function entry. */
7473 sparc_profile_hook (int labelno)
7478 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
7479 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
7480 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
7482 emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lab, Pmode);
7485 #ifdef OBJECT_FORMAT_ELF
7487 sparc_elf_asm_named_section (const char *name, unsigned int flags,
7490 if (flags & SECTION_MERGE)
7492 /* entsize cannot be expressed in this section attributes
7494 default_elf_asm_named_section (name, flags, decl);
7498 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
7500 if (!(flags & SECTION_DEBUG))
7501 fputs (",#alloc", asm_out_file);
7502 if (flags & SECTION_WRITE)
7503 fputs (",#write", asm_out_file);
7504 if (flags & SECTION_TLS)
7505 fputs (",#tls", asm_out_file);
7506 if (flags & SECTION_CODE)
7507 fputs (",#execinstr", asm_out_file);
7509 /* ??? Handle SECTION_BSS. */
7511 fputc ('\n', asm_out_file);
7513 #endif /* OBJECT_FORMAT_ELF */
7515 /* We do not allow indirect calls to be optimized into sibling calls.
7517 We cannot use sibling calls when delayed branches are disabled
7518 because they will likely require the call delay slot to be filled.
7520 Also, on SPARC 32-bit we cannot emit a sibling call when the
7521 current function returns a structure. This is because the "unimp
7522 after call" convention would cause the callee to return to the
7523 wrong place. The generic code already disallows cases where the
7524 function being called returns a structure.
7526 It may seem strange how this last case could occur. Usually there
7527 is code after the call which jumps to epilogue code which dumps the
7528 return value into the struct return area. That ought to invalidate
7529 the sibling call right? Well, in the C++ case we can end up passing
7530 the pointer to the struct return area to a constructor (which returns
7531 void) and then nothing else happens. Such a sibling call would look
7532 valid without the added check here. */
7534 sparc_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
7537 && flag_delayed_branch
7538 && (TARGET_ARCH64 || ! current_function_returns_struct));
7541 /* libfunc renaming. */
7542 #include "config/gofast.h"
7545 sparc_init_libfuncs (void)
7549 /* Use the subroutines that Sun's library provides for integer
7550 multiply and divide. The `*' prevents an underscore from
7551 being prepended by the compiler. .umul is a little faster
7553 set_optab_libfunc (smul_optab, SImode, "*.umul");
7554 set_optab_libfunc (sdiv_optab, SImode, "*.div");
7555 set_optab_libfunc (udiv_optab, SImode, "*.udiv");
7556 set_optab_libfunc (smod_optab, SImode, "*.rem");
7557 set_optab_libfunc (umod_optab, SImode, "*.urem");
7559 /* TFmode arithmetic. These names are part of the SPARC 32bit ABI. */
7560 set_optab_libfunc (add_optab, TFmode, "_Q_add");
7561 set_optab_libfunc (sub_optab, TFmode, "_Q_sub");
7562 set_optab_libfunc (neg_optab, TFmode, "_Q_neg");
7563 set_optab_libfunc (smul_optab, TFmode, "_Q_mul");
7564 set_optab_libfunc (sdiv_optab, TFmode, "_Q_div");
7566 /* We can define the TFmode sqrt optab only if TARGET_FPU. This
7567 is because with soft-float, the SFmode and DFmode sqrt
7568 instructions will be absent, and the compiler will notice and
7569 try to use the TFmode sqrt instruction for calls to the
7570 builtin function sqrt, but this fails. */
7572 set_optab_libfunc (sqrt_optab, TFmode, "_Q_sqrt");
7574 set_optab_libfunc (eq_optab, TFmode, "_Q_feq");
7575 set_optab_libfunc (ne_optab, TFmode, "_Q_fne");
7576 set_optab_libfunc (gt_optab, TFmode, "_Q_fgt");
7577 set_optab_libfunc (ge_optab, TFmode, "_Q_fge");
7578 set_optab_libfunc (lt_optab, TFmode, "_Q_flt");
7579 set_optab_libfunc (le_optab, TFmode, "_Q_fle");
7581 set_conv_libfunc (sext_optab, TFmode, SFmode, "_Q_stoq");
7582 set_conv_libfunc (sext_optab, TFmode, DFmode, "_Q_dtoq");
7583 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_Q_qtos");
7584 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_Q_qtod");
7586 set_conv_libfunc (sfix_optab, SImode, TFmode, "_Q_qtoi");
7587 set_conv_libfunc (ufix_optab, SImode, TFmode, "_Q_qtou");
7588 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_Q_itoq");
7590 if (DITF_CONVERSION_LIBFUNCS)
7592 set_conv_libfunc (sfix_optab, DImode, TFmode, "_Q_qtoll");
7593 set_conv_libfunc (ufix_optab, DImode, TFmode, "_Q_qtoull");
7594 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_Q_lltoq");
7597 if (SUN_CONVERSION_LIBFUNCS)
7599 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftoll");
7600 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoull");
7601 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtoll");
7602 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoull");
7607 /* In the SPARC 64bit ABI, SImode multiply and divide functions
7608 do not exist in the library. Make sure the compiler does not
7609 emit calls to them by accident. (It should always use the
7610 hardware instructions.) */
7611 set_optab_libfunc (smul_optab, SImode, 0);
7612 set_optab_libfunc (sdiv_optab, SImode, 0);
7613 set_optab_libfunc (udiv_optab, SImode, 0);
7614 set_optab_libfunc (smod_optab, SImode, 0);
7615 set_optab_libfunc (umod_optab, SImode, 0);
7617 if (SUN_INTEGER_MULTIPLY_64)
7619 set_optab_libfunc (smul_optab, DImode, "__mul64");
7620 set_optab_libfunc (sdiv_optab, DImode, "__div64");
7621 set_optab_libfunc (udiv_optab, DImode, "__udiv64");
7622 set_optab_libfunc (smod_optab, DImode, "__rem64");
7623 set_optab_libfunc (umod_optab, DImode, "__urem64");
7626 if (SUN_CONVERSION_LIBFUNCS)
7628 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftol");
7629 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoul");
7630 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtol");
7631 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoul");
7635 gofast_maybe_init_libfuncs ();
7638 #define def_builtin(NAME, CODE, TYPE) \
7639 lang_hooks.builtin_function((NAME), (TYPE), (CODE), BUILT_IN_MD, NULL, \
7642 /* Implement the TARGET_INIT_BUILTINS target hook.
7643 Create builtin functions for special SPARC instructions. */
7646 sparc_init_builtins (void)
7649 sparc_vis_init_builtins ();
7652 /* Create builtin functions for VIS 1.0 instructions. */
7655 sparc_vis_init_builtins (void)
7657 tree v4qi = build_vector_type (unsigned_intQI_type_node, 4);
7658 tree v8qi = build_vector_type (unsigned_intQI_type_node, 8);
7659 tree v4hi = build_vector_type (intHI_type_node, 4);
7660 tree v2hi = build_vector_type (intHI_type_node, 2);
7661 tree v2si = build_vector_type (intSI_type_node, 2);
7663 tree v4qi_ftype_v4hi = build_function_type_list (v4qi, v4hi, 0);
7664 tree v8qi_ftype_v2si_v8qi = build_function_type_list (v8qi, v2si, v8qi, 0);
7665 tree v2hi_ftype_v2si = build_function_type_list (v2hi, v2si, 0);
7666 tree v4hi_ftype_v4qi = build_function_type_list (v4hi, v4qi, 0);
7667 tree v8qi_ftype_v4qi_v4qi = build_function_type_list (v8qi, v4qi, v4qi, 0);
7668 tree v4hi_ftype_v4qi_v4hi = build_function_type_list (v4hi, v4qi, v4hi, 0);
7669 tree v4hi_ftype_v4qi_v2hi = build_function_type_list (v4hi, v4qi, v2hi, 0);
7670 tree v2si_ftype_v4qi_v2hi = build_function_type_list (v2si, v4qi, v2hi, 0);
7671 tree v4hi_ftype_v8qi_v4hi = build_function_type_list (v4hi, v8qi, v4hi, 0);
7672 tree v4hi_ftype_v4hi_v4hi = build_function_type_list (v4hi, v4hi, v4hi, 0);
7673 tree v2si_ftype_v2si_v2si = build_function_type_list (v2si, v2si, v2si, 0);
7674 tree v8qi_ftype_v8qi_v8qi = build_function_type_list (v8qi, v8qi, v8qi, 0);
7675 tree di_ftype_v8qi_v8qi_di = build_function_type_list (intDI_type_node,
7677 intDI_type_node, 0);
7678 tree di_ftype_di_di = build_function_type_list (intDI_type_node,
7680 intDI_type_node, 0);
7681 tree ptr_ftype_ptr_si = build_function_type_list (ptr_type_node,
7683 intSI_type_node, 0);
7684 tree ptr_ftype_ptr_di = build_function_type_list (ptr_type_node,
7686 intDI_type_node, 0);
7688 /* Packing and expanding vectors. */
7689 def_builtin ("__builtin_vis_fpack16", CODE_FOR_fpack16_vis, v4qi_ftype_v4hi);
7690 def_builtin ("__builtin_vis_fpack32", CODE_FOR_fpack32_vis,
7691 v8qi_ftype_v2si_v8qi);
7692 def_builtin ("__builtin_vis_fpackfix", CODE_FOR_fpackfix_vis,
7694 def_builtin ("__builtin_vis_fexpand", CODE_FOR_fexpand_vis, v4hi_ftype_v4qi);
7695 def_builtin ("__builtin_vis_fpmerge", CODE_FOR_fpmerge_vis,
7696 v8qi_ftype_v4qi_v4qi);
7698 /* Multiplications. */
7699 def_builtin ("__builtin_vis_fmul8x16", CODE_FOR_fmul8x16_vis,
7700 v4hi_ftype_v4qi_v4hi);
7701 def_builtin ("__builtin_vis_fmul8x16au", CODE_FOR_fmul8x16au_vis,
7702 v4hi_ftype_v4qi_v2hi);
7703 def_builtin ("__builtin_vis_fmul8x16al", CODE_FOR_fmul8x16al_vis,
7704 v4hi_ftype_v4qi_v2hi);
7705 def_builtin ("__builtin_vis_fmul8sux16", CODE_FOR_fmul8sux16_vis,
7706 v4hi_ftype_v8qi_v4hi);
7707 def_builtin ("__builtin_vis_fmul8ulx16", CODE_FOR_fmul8ulx16_vis,
7708 v4hi_ftype_v8qi_v4hi);
7709 def_builtin ("__builtin_vis_fmuld8sux16", CODE_FOR_fmuld8sux16_vis,
7710 v2si_ftype_v4qi_v2hi);
7711 def_builtin ("__builtin_vis_fmuld8ulx16", CODE_FOR_fmuld8ulx16_vis,
7712 v2si_ftype_v4qi_v2hi);
7714 /* Data aligning. */
7715 def_builtin ("__builtin_vis_faligndatav4hi", CODE_FOR_faligndatav4hi_vis,
7716 v4hi_ftype_v4hi_v4hi);
7717 def_builtin ("__builtin_vis_faligndatav8qi", CODE_FOR_faligndatav8qi_vis,
7718 v8qi_ftype_v8qi_v8qi);
7719 def_builtin ("__builtin_vis_faligndatav2si", CODE_FOR_faligndatav2si_vis,
7720 v2si_ftype_v2si_v2si);
7721 def_builtin ("__builtin_vis_faligndatadi", CODE_FOR_faligndatadi_vis,
7724 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrdi_vis,
7727 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrsi_vis,
7730 /* Pixel distance. */
7731 def_builtin ("__builtin_vis_pdist", CODE_FOR_pdist_vis,
7732 di_ftype_v8qi_v8qi_di);
7735 /* Handle TARGET_EXPAND_BUILTIN target hook.
7736 Expand builtin functions for sparc instrinsics. */
7739 sparc_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
7740 enum machine_mode tmode, int ignore ATTRIBUTE_UNUSED)
7743 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7744 unsigned int icode = DECL_FUNCTION_CODE (fndecl);
7746 enum machine_mode mode[4];
7749 mode[arg_count] = tmode;
7752 || GET_MODE (target) != tmode
7753 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7754 op[arg_count] = gen_reg_rtx (tmode);
7756 op[arg_count] = target;
7758 for (arglist = TREE_OPERAND (exp, 1); arglist;
7759 arglist = TREE_CHAIN (arglist))
7761 tree arg = TREE_VALUE (arglist);
7764 mode[arg_count] = insn_data[icode].operand[arg_count].mode;
7765 op[arg_count] = expand_expr (arg, NULL_RTX, VOIDmode, 0);
7767 if (! (*insn_data[icode].operand[arg_count].predicate) (op[arg_count],
7769 op[arg_count] = copy_to_mode_reg (mode[arg_count], op[arg_count]);
7775 pat = GEN_FCN (icode) (op[0], op[1]);
7778 pat = GEN_FCN (icode) (op[0], op[1], op[2]);
7781 pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]);
7796 sparc_extra_constraint_check (rtx op, int c, int strict)
7801 && (c == 'T' || c == 'U'))
7807 return fp_sethi_p (op);
7810 return fp_mov_p (op);
7813 return fp_high_losum_p (op);
7817 || (GET_CODE (op) == REG
7818 && (REGNO (op) < FIRST_PSEUDO_REGISTER
7819 || reg_renumber[REGNO (op)] >= 0)))
7820 return register_ok_for_ldd (op);
7829 return const_zero_operand (op, GET_MODE (op));
7835 /* Our memory extra constraints have to emulate the
7836 behavior of 'm' and 'o' in order for reload to work
7838 if (GET_CODE (op) == MEM)
7841 if ((TARGET_ARCH64 || mem_min_alignment (op, 8))
7843 || strict_memory_address_p (Pmode, XEXP (op, 0))))
7848 reload_ok_mem = (reload_in_progress
7849 && GET_CODE (op) == REG
7850 && REGNO (op) >= FIRST_PSEUDO_REGISTER
7851 && reg_renumber [REGNO (op)] < 0);
7854 return reload_ok_mem;
7857 /* ??? This duplicates information provided to the compiler by the
7858 ??? scheduler description. Some day, teach genautomata to output
7859 ??? the latencies and then CSE will just use that. */
7862 sparc_rtx_costs (rtx x, int code, int outer_code, int *total)
7864 enum machine_mode mode = GET_MODE (x);
7865 bool float_mode_p = FLOAT_MODE_P (mode);
7870 if (INTVAL (x) < 0x1000 && INTVAL (x) >= -0x1000)
7888 if (GET_MODE (x) == VOIDmode
7889 && ((CONST_DOUBLE_HIGH (x) == 0
7890 && CONST_DOUBLE_LOW (x) < 0x1000)
7891 || (CONST_DOUBLE_HIGH (x) == -1
7892 && CONST_DOUBLE_LOW (x) < 0
7893 && CONST_DOUBLE_LOW (x) >= -0x1000)))
7900 /* If outer-code was a sign or zero extension, a cost
7901 of COSTS_N_INSNS (1) was already added in. This is
7902 why we are subtracting it back out. */
7903 if (outer_code == ZERO_EXTEND)
7905 *total = sparc_costs->int_zload - COSTS_N_INSNS (1);
7907 else if (outer_code == SIGN_EXTEND)
7909 *total = sparc_costs->int_sload - COSTS_N_INSNS (1);
7911 else if (float_mode_p)
7913 *total = sparc_costs->float_load;
7917 *total = sparc_costs->int_load;
7925 *total = sparc_costs->float_plusminus;
7927 *total = COSTS_N_INSNS (1);
7932 *total = sparc_costs->float_mul;
7933 else if (! TARGET_HARD_MUL)
7934 *total = COSTS_N_INSNS (25);
7940 if (sparc_costs->int_mul_bit_factor)
7944 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
7946 unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
7947 for (nbits = 0; value != 0; value &= value - 1)
7950 else if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
7951 && GET_MODE (XEXP (x, 1)) == VOIDmode)
7953 rtx x1 = XEXP (x, 1);
7954 unsigned HOST_WIDE_INT value1 = CONST_DOUBLE_LOW (x1);
7955 unsigned HOST_WIDE_INT value2 = CONST_DOUBLE_HIGH (x1);
7957 for (nbits = 0; value1 != 0; value1 &= value1 - 1)
7959 for (; value2 != 0; value2 &= value2 - 1)
7967 bit_cost = (nbits - 3) / sparc_costs->int_mul_bit_factor;
7968 bit_cost = COSTS_N_INSNS (bit_cost);
7972 *total = sparc_costs->int_mulX + bit_cost;
7974 *total = sparc_costs->int_mul + bit_cost;
7981 *total = COSTS_N_INSNS (1) + sparc_costs->shift_penalty;
7991 *total = sparc_costs->float_div_df;
7993 *total = sparc_costs->float_div_sf;
7998 *total = sparc_costs->int_divX;
8000 *total = sparc_costs->int_div;
8007 *total = COSTS_N_INSNS (1);
8014 case UNSIGNED_FLOAT:
8018 case FLOAT_TRUNCATE:
8019 *total = sparc_costs->float_move;
8024 *total = sparc_costs->float_sqrt_df;
8026 *total = sparc_costs->float_sqrt_sf;
8031 *total = sparc_costs->float_cmp;
8033 *total = COSTS_N_INSNS (1);
8038 *total = sparc_costs->float_cmove;
8040 *total = sparc_costs->int_cmove;
8044 /* Handle the NAND vector patterns. */
8045 if (sparc_vector_mode_supported_p (GET_MODE (x))
8046 && GET_CODE (XEXP (x, 0)) == NOT
8047 && GET_CODE (XEXP (x, 1)) == NOT)
8049 *total = COSTS_N_INSNS (1);
8060 /* Emit the sequence of insns SEQ while preserving the register REG. */
8063 emit_and_preserve (rtx seq, rtx reg)
8065 rtx slot = gen_rtx_MEM (word_mode,
8066 plus_constant (stack_pointer_rtx, SPARC_STACK_BIAS));
8068 emit_insn (gen_stack_pointer_dec (GEN_INT (STACK_BOUNDARY/BITS_PER_UNIT)));
8069 emit_insn (gen_rtx_SET (VOIDmode, slot, reg));
8071 emit_insn (gen_rtx_SET (VOIDmode, reg, slot));
8072 emit_insn (gen_stack_pointer_inc (GEN_INT (STACK_BOUNDARY/BITS_PER_UNIT)));
8075 /* Output the assembler code for a thunk function. THUNK_DECL is the
8076 declaration for the thunk function itself, FUNCTION is the decl for
8077 the target function. DELTA is an immediate constant offset to be
8078 added to THIS. If VCALL_OFFSET is nonzero, the word at address
8079 (*THIS + VCALL_OFFSET) should be additionally added to THIS. */
8082 sparc_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
8083 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
8086 rtx this, insn, funexp;
8087 unsigned int int_arg_first;
8089 reload_completed = 1;
8090 epilogue_completed = 1;
8092 reset_block_changes ();
8094 emit_note (NOTE_INSN_PROLOGUE_END);
8096 if (flag_delayed_branch)
8098 /* We will emit a regular sibcall below, so we need to instruct
8099 output_sibcall that we are in a leaf function. */
8100 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 1;
8102 /* This will cause final.c to invoke leaf_renumber_regs so we
8103 must behave as if we were in a not-yet-leafified function. */
8104 int_arg_first = SPARC_INCOMING_INT_ARG_FIRST;
8108 /* We will emit the sibcall manually below, so we will need to
8109 manually spill non-leaf registers. */
8110 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 0;
8112 /* We really are in a leaf function. */
8113 int_arg_first = SPARC_OUTGOING_INT_ARG_FIRST;
8116 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
8117 returns a structure, the structure return pointer is there instead. */
8118 if (TARGET_ARCH64 && aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
8119 this = gen_rtx_REG (Pmode, int_arg_first + 1);
8121 this = gen_rtx_REG (Pmode, int_arg_first);
8123 /* Add DELTA. When possible use a plain add, otherwise load it into
8124 a register first. */
8127 rtx delta_rtx = GEN_INT (delta);
8129 if (! SPARC_SIMM13_P (delta))
8131 rtx scratch = gen_rtx_REG (Pmode, 1);
8132 emit_move_insn (scratch, delta_rtx);
8133 delta_rtx = scratch;
8136 /* THIS += DELTA. */
8137 emit_insn (gen_add2_insn (this, delta_rtx));
8140 /* Add the word at address (*THIS + VCALL_OFFSET). */
8143 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
8144 rtx scratch = gen_rtx_REG (Pmode, 1);
8146 gcc_assert (vcall_offset < 0);
8148 /* SCRATCH = *THIS. */
8149 emit_move_insn (scratch, gen_rtx_MEM (Pmode, this));
8151 /* Prepare for adding VCALL_OFFSET. The difficulty is that we
8152 may not have any available scratch register at this point. */
8153 if (SPARC_SIMM13_P (vcall_offset))
8155 /* This is the case if ARCH64 (unless -ffixed-g5 is passed). */
8156 else if (! fixed_regs[5]
8157 /* The below sequence is made up of at least 2 insns,
8158 while the default method may need only one. */
8159 && vcall_offset < -8192)
8161 rtx scratch2 = gen_rtx_REG (Pmode, 5);
8162 emit_move_insn (scratch2, vcall_offset_rtx);
8163 vcall_offset_rtx = scratch2;
8167 rtx increment = GEN_INT (-4096);
8169 /* VCALL_OFFSET is a negative number whose typical range can be
8170 estimated as -32768..0 in 32-bit mode. In almost all cases
8171 it is therefore cheaper to emit multiple add insns than
8172 spilling and loading the constant into a register (at least
8174 while (! SPARC_SIMM13_P (vcall_offset))
8176 emit_insn (gen_add2_insn (scratch, increment));
8177 vcall_offset += 4096;
8179 vcall_offset_rtx = GEN_INT (vcall_offset); /* cannot be 0 */
8182 /* SCRATCH = *(*THIS + VCALL_OFFSET). */
8183 emit_move_insn (scratch, gen_rtx_MEM (Pmode,
8184 gen_rtx_PLUS (Pmode,
8186 vcall_offset_rtx)));
8188 /* THIS += *(*THIS + VCALL_OFFSET). */
8189 emit_insn (gen_add2_insn (this, scratch));
8192 /* Generate a tail call to the target function. */
8193 if (! TREE_USED (function))
8195 assemble_external (function);
8196 TREE_USED (function) = 1;
8198 funexp = XEXP (DECL_RTL (function), 0);
8200 if (flag_delayed_branch)
8202 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
8203 insn = emit_call_insn (gen_sibcall (funexp));
8204 SIBLING_CALL_P (insn) = 1;
8208 /* The hoops we have to jump through in order to generate a sibcall
8209 without using delay slots... */
8210 rtx spill_reg, seq, scratch = gen_rtx_REG (Pmode, 1);
8214 spill_reg = gen_rtx_REG (word_mode, 15); /* %o7 */
8216 /* Delay emitting the PIC helper function because it needs to
8217 change the section and we are emitting assembly code. */
8218 load_pic_register (true); /* clobbers %o7 */
8219 scratch = legitimize_pic_address (funexp, Pmode, scratch);
8222 emit_and_preserve (seq, spill_reg);
8224 else if (TARGET_ARCH32)
8226 emit_insn (gen_rtx_SET (VOIDmode,
8228 gen_rtx_HIGH (SImode, funexp)));
8229 emit_insn (gen_rtx_SET (VOIDmode,
8231 gen_rtx_LO_SUM (SImode, scratch, funexp)));
8233 else /* TARGET_ARCH64 */
8235 switch (sparc_cmodel)
8239 /* The destination can serve as a temporary. */
8240 sparc_emit_set_symbolic_const64 (scratch, funexp, scratch);
8245 /* The destination cannot serve as a temporary. */
8246 spill_reg = gen_rtx_REG (DImode, 15); /* %o7 */
8248 sparc_emit_set_symbolic_const64 (scratch, funexp, spill_reg);
8251 emit_and_preserve (seq, spill_reg);
8259 emit_jump_insn (gen_indirect_jump (scratch));
8264 /* Run just enough of rest_of_compilation to get the insns emitted.
8265 There's not really enough bulk here to make other passes such as
8266 instruction scheduling worth while. Note that use_thunk calls
8267 assemble_start_function and assemble_end_function. */
8268 insn = get_insns ();
8269 insn_locators_initialize ();
8270 shorten_branches (insn);
8271 final_start_function (insn, file, 1);
8272 final (insn, file, 1);
8273 final_end_function ();
8275 reload_completed = 0;
8276 epilogue_completed = 0;
8280 /* Return true if sparc_output_mi_thunk would be able to output the
8281 assembler code for the thunk function specified by the arguments
8282 it is passed, and false otherwise. */
8284 sparc_can_output_mi_thunk (tree thunk_fndecl ATTRIBUTE_UNUSED,
8285 HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
8286 HOST_WIDE_INT vcall_offset,
8287 tree function ATTRIBUTE_UNUSED)
8289 /* Bound the loop used in the default method above. */
8290 return (vcall_offset >= -32768 || ! fixed_regs[5]);
8293 /* How to allocate a 'struct machine_function'. */
8295 static struct machine_function *
8296 sparc_init_machine_status (void)
8298 return ggc_alloc_cleared (sizeof (struct machine_function));
8301 /* Locate some local-dynamic symbol still in use by this function
8302 so that we can print its name in local-dynamic base patterns. */
8305 get_some_local_dynamic_name (void)
8309 if (cfun->machine->some_ld_name)
8310 return cfun->machine->some_ld_name;
8312 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8314 && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
8315 return cfun->machine->some_ld_name;
8321 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
8326 && GET_CODE (x) == SYMBOL_REF
8327 && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8329 cfun->machine->some_ld_name = XSTR (x, 0);
8336 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
8337 This is called from dwarf2out.c to emit call frame instructions
8338 for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
8340 sparc_dwarf_handle_frame_unspec (const char *label,
8341 rtx pattern ATTRIBUTE_UNUSED,
8342 int index ATTRIBUTE_UNUSED)
8344 gcc_assert (index == UNSPECV_SAVEW);
8345 dwarf2out_window_save (label);
8348 /* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
8349 We need to emit DTP-relative relocations. */
8352 sparc_output_dwarf_dtprel (FILE *file, int size, rtx x)
8357 fputs ("\t.word\t%r_tls_dtpoff32(", file);
8360 fputs ("\t.xword\t%r_tls_dtpoff64(", file);
8365 output_addr_const (file, x);
8370 void sparc_file_end (void)
8372 /* If we haven't emitted the special PIC helper function, do so now. */
8373 if (pic_helper_symbol_name[0] && !pic_helper_emitted_p)
8376 if (NEED_INDICATE_EXEC_STACK)
8377 file_end_indicate_exec_stack ();
8380 #include "gt-sparc.h"