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_or_restore_regs (int);
322 static void sparc_asm_function_prologue (FILE *, HOST_WIDE_INT);
323 static void sparc_asm_function_epilogue (FILE *, HOST_WIDE_INT);
324 #ifdef OBJECT_FORMAT_ELF
325 static void sparc_elf_asm_named_section (const char *, unsigned int, tree);
328 static int sparc_adjust_cost (rtx, rtx, rtx, int);
329 static int sparc_issue_rate (void);
330 static void sparc_sched_init (FILE *, int, int);
331 static int sparc_use_sched_lookahead (void);
333 static void emit_soft_tfmode_libcall (const char *, int, rtx *);
334 static void emit_soft_tfmode_binop (enum rtx_code, rtx *);
335 static void emit_soft_tfmode_unop (enum rtx_code, rtx *);
336 static void emit_soft_tfmode_cvt (enum rtx_code, rtx *);
337 static void emit_hard_tfmode_operation (enum rtx_code, rtx *);
339 static bool sparc_function_ok_for_sibcall (tree, tree);
340 static void sparc_init_libfuncs (void);
341 static void sparc_init_builtins (void);
342 static void sparc_vis_init_builtins (void);
343 static rtx sparc_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
344 static void sparc_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
345 HOST_WIDE_INT, tree);
346 static bool sparc_can_output_mi_thunk (tree, HOST_WIDE_INT,
347 HOST_WIDE_INT, tree);
348 static struct machine_function * sparc_init_machine_status (void);
349 static bool sparc_cannot_force_const_mem (rtx);
350 static rtx sparc_tls_get_addr (void);
351 static rtx sparc_tls_got (void);
352 static const char *get_some_local_dynamic_name (void);
353 static int get_some_local_dynamic_name_1 (rtx *, void *);
354 static bool sparc_rtx_costs (rtx, int, int, int *);
355 static bool sparc_promote_prototypes (tree);
356 static rtx sparc_struct_value_rtx (tree, int);
357 static bool sparc_return_in_memory (tree, tree);
358 static bool sparc_strict_argument_naming (CUMULATIVE_ARGS *);
359 static tree sparc_gimplify_va_arg (tree, tree, tree *, tree *);
360 static bool sparc_vector_mode_supported_p (enum machine_mode);
361 static bool sparc_pass_by_reference (CUMULATIVE_ARGS *,
362 enum machine_mode, tree, bool);
363 static int sparc_arg_partial_bytes (CUMULATIVE_ARGS *,
364 enum machine_mode, tree, bool);
365 static void sparc_dwarf_handle_frame_unspec (const char *, rtx, int);
366 static void sparc_file_end (void);
367 #ifdef SUBTARGET_ATTRIBUTE_TABLE
368 const struct attribute_spec sparc_attribute_table[];
371 /* Option handling. */
373 /* Code model option as passed by user. */
374 const char *sparc_cmodel_string;
377 enum cmodel sparc_cmodel;
379 char sparc_hard_reg_printed[8];
381 struct sparc_cpu_select sparc_select[] =
383 /* switch name, tune arch */
384 { (char *)0, "default", 1, 1 },
385 { (char *)0, "-mcpu=", 1, 1 },
386 { (char *)0, "-mtune=", 1, 0 },
390 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
391 enum processor_type sparc_cpu;
393 /* Whether
\fan FPU option was specified. */
394 static bool fpu_option_set = false;
396 /* Initialize the GCC target structure. */
398 /* The sparc default is to use .half rather than .short for aligned
399 HI objects. Use .word instead of .long on non-ELF systems. */
400 #undef TARGET_ASM_ALIGNED_HI_OP
401 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
402 #ifndef OBJECT_FORMAT_ELF
403 #undef TARGET_ASM_ALIGNED_SI_OP
404 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
407 #undef TARGET_ASM_UNALIGNED_HI_OP
408 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
409 #undef TARGET_ASM_UNALIGNED_SI_OP
410 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
411 #undef TARGET_ASM_UNALIGNED_DI_OP
412 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
414 /* The target hook has to handle DI-mode values. */
415 #undef TARGET_ASM_INTEGER
416 #define TARGET_ASM_INTEGER sparc_assemble_integer
418 #undef TARGET_ASM_FUNCTION_PROLOGUE
419 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
420 #undef TARGET_ASM_FUNCTION_EPILOGUE
421 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
423 #undef TARGET_SCHED_ADJUST_COST
424 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
425 #undef TARGET_SCHED_ISSUE_RATE
426 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
427 #undef TARGET_SCHED_INIT
428 #define TARGET_SCHED_INIT sparc_sched_init
429 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
430 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
432 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
433 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
435 #undef TARGET_INIT_LIBFUNCS
436 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
437 #undef TARGET_INIT_BUILTINS
438 #define TARGET_INIT_BUILTINS sparc_init_builtins
440 #undef TARGET_EXPAND_BUILTIN
441 #define TARGET_EXPAND_BUILTIN sparc_expand_builtin
444 #undef TARGET_HAVE_TLS
445 #define TARGET_HAVE_TLS true
447 #undef TARGET_CANNOT_FORCE_CONST_MEM
448 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
450 #undef TARGET_ASM_OUTPUT_MI_THUNK
451 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
452 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
453 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
455 #undef TARGET_RTX_COSTS
456 #define TARGET_RTX_COSTS sparc_rtx_costs
457 #undef TARGET_ADDRESS_COST
458 #define TARGET_ADDRESS_COST hook_int_rtx_0
460 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
461 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
462 test for this value. */
463 #undef TARGET_PROMOTE_FUNCTION_ARGS
464 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
466 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
467 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
468 test for this value. */
469 #undef TARGET_PROMOTE_FUNCTION_RETURN
470 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
472 #undef TARGET_PROMOTE_PROTOTYPES
473 #define TARGET_PROMOTE_PROTOTYPES sparc_promote_prototypes
475 #undef TARGET_STRUCT_VALUE_RTX
476 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
477 #undef TARGET_RETURN_IN_MEMORY
478 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
479 #undef TARGET_MUST_PASS_IN_STACK
480 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
481 #undef TARGET_PASS_BY_REFERENCE
482 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
483 #undef TARGET_ARG_PARTIAL_BYTES
484 #define TARGET_ARG_PARTIAL_BYTES sparc_arg_partial_bytes
486 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
487 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
488 #undef TARGET_STRICT_ARGUMENT_NAMING
489 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
491 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
492 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
494 #undef TARGET_VECTOR_MODE_SUPPORTED_P
495 #define TARGET_VECTOR_MODE_SUPPORTED_P sparc_vector_mode_supported_p
497 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
498 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC sparc_dwarf_handle_frame_unspec
500 #ifdef SUBTARGET_INSERT_ATTRIBUTES
501 #undef TARGET_INSERT_ATTRIBUTES
502 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
505 #ifdef SUBTARGET_ATTRIBUTE_TABLE
506 #undef TARGET_ATTRIBUTE_TABLE
507 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
510 #undef TARGET_RELAXED_ORDERING
511 #define TARGET_RELAXED_ORDERING SPARC_RELAXED_ORDERING
513 #undef TARGET_DEFAULT_TARGET_FLAGS
514 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
515 #undef TARGET_HANDLE_OPTION
516 #define TARGET_HANDLE_OPTION sparc_handle_option
518 #undef TARGET_ASM_FILE_END
519 #define TARGET_ASM_FILE_END sparc_file_end
521 struct gcc_target targetm = TARGET_INITIALIZER;
523 /* Implement TARGET_HANDLE_OPTION. */
526 sparc_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
531 case OPT_mhard_float:
532 case OPT_msoft_float:
533 fpu_option_set = true;
537 sparc_select[1].string = arg;
541 sparc_select[2].string = arg;
545 sparc_cmodel_string = arg;
552 /* Validate and override various options, and do some machine dependent
556 sparc_override_options (void)
558 static struct code_model {
559 const char *const name;
561 } const cmodels[] = {
563 { "medlow", CM_MEDLOW },
564 { "medmid", CM_MEDMID },
565 { "medany", CM_MEDANY },
566 { "embmedany", CM_EMBMEDANY },
569 const struct code_model *cmodel;
570 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
571 static struct cpu_default {
573 const char *const name;
574 } const cpu_default[] = {
575 /* There must be one entry here for each TARGET_CPU value. */
576 { TARGET_CPU_sparc, "cypress" },
577 { TARGET_CPU_sparclet, "tsc701" },
578 { TARGET_CPU_sparclite, "f930" },
579 { TARGET_CPU_v8, "v8" },
580 { TARGET_CPU_hypersparc, "hypersparc" },
581 { TARGET_CPU_sparclite86x, "sparclite86x" },
582 { TARGET_CPU_supersparc, "supersparc" },
583 { TARGET_CPU_v9, "v9" },
584 { TARGET_CPU_ultrasparc, "ultrasparc" },
585 { TARGET_CPU_ultrasparc3, "ultrasparc3" },
588 const struct cpu_default *def;
589 /* Table of values for -m{cpu,tune}=. */
590 static struct cpu_table {
591 const char *const name;
592 const enum processor_type processor;
595 } const cpu_table[] = {
596 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
597 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
598 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
599 /* TI TMS390Z55 supersparc */
600 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
601 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
602 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
603 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
604 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
605 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
606 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
607 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
609 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
611 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
612 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
613 /* TI ultrasparc I, II, IIi */
614 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
615 /* Although insns using %y are deprecated, it is a clear win on current
617 |MASK_DEPRECATED_V8_INSNS},
618 /* TI ultrasparc III */
619 /* ??? Check if %y issue still holds true in ultra3. */
620 { "ultrasparc3", PROCESSOR_ULTRASPARC3, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
623 const struct cpu_table *cpu;
624 const struct sparc_cpu_select *sel;
627 #ifndef SPARC_BI_ARCH
628 /* Check for unsupported architecture size. */
629 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
630 error ("%s is not supported by this configuration",
631 DEFAULT_ARCH32_P ? "-m64" : "-m32");
634 /* We force all 64bit archs to use 128 bit long double */
635 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
637 error ("-mlong-double-64 not allowed with -m64");
638 target_flags |= MASK_LONG_DOUBLE_128;
641 /* Code model selection. */
642 sparc_cmodel = SPARC_DEFAULT_CMODEL;
646 sparc_cmodel = CM_32;
649 if (sparc_cmodel_string != NULL)
653 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
654 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
656 if (cmodel->name == NULL)
657 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
659 sparc_cmodel = cmodel->value;
662 error ("-mcmodel= is not supported on 32 bit systems");
665 fpu = TARGET_FPU; /* save current -mfpu status */
667 /* Set the default CPU. */
668 for (def = &cpu_default[0]; def->name; ++def)
669 if (def->cpu == TARGET_CPU_DEFAULT)
671 gcc_assert (def->name);
672 sparc_select[0].string = def->name;
674 for (sel = &sparc_select[0]; sel->name; ++sel)
678 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
679 if (! strcmp (sel->string, cpu->name))
682 sparc_cpu = cpu->processor;
686 target_flags &= ~cpu->disable;
687 target_flags |= cpu->enable;
693 error ("bad value (%s) for %s switch", sel->string, sel->name);
697 /* If -mfpu or -mno-fpu was explicitly used, don't override with
698 the processor default. */
700 target_flags = (target_flags & ~MASK_FPU) | fpu;
702 /* Don't allow -mvis if FPU is disabled. */
704 target_flags &= ~MASK_VIS;
706 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
708 -m64 also implies v9. */
709 if (TARGET_VIS || TARGET_ARCH64)
711 target_flags |= MASK_V9;
712 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
715 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
716 if (TARGET_V9 && TARGET_ARCH32)
717 target_flags |= MASK_DEPRECATED_V8_INSNS;
719 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
720 if (! TARGET_V9 || TARGET_ARCH64)
721 target_flags &= ~MASK_V8PLUS;
723 /* Don't use stack biasing in 32 bit mode. */
725 target_flags &= ~MASK_STACK_BIAS;
727 /* Supply a default value for align_functions. */
728 if (align_functions == 0
729 && (sparc_cpu == PROCESSOR_ULTRASPARC
730 || sparc_cpu == PROCESSOR_ULTRASPARC3))
731 align_functions = 32;
733 /* Validate PCC_STRUCT_RETURN. */
734 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
735 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
737 /* Only use .uaxword when compiling for a 64-bit target. */
739 targetm.asm_out.unaligned_op.di = NULL;
741 /* Do various machine dependent initializations. */
744 /* Acquire unique alias sets for our private stuff. */
745 sparc_sr_alias_set = new_alias_set ();
746 struct_value_alias_set = new_alias_set ();
748 /* Set up function hooks. */
749 init_machine_status = sparc_init_machine_status;
754 case PROCESSOR_CYPRESS:
755 sparc_costs = &cypress_costs;
758 case PROCESSOR_SPARCLITE:
759 case PROCESSOR_SUPERSPARC:
760 sparc_costs = &supersparc_costs;
764 case PROCESSOR_HYPERSPARC:
765 case PROCESSOR_SPARCLITE86X:
766 sparc_costs = &hypersparc_costs;
768 case PROCESSOR_SPARCLET:
769 case PROCESSOR_TSC701:
770 sparc_costs = &sparclet_costs;
773 case PROCESSOR_ULTRASPARC:
774 sparc_costs = &ultrasparc_costs;
776 case PROCESSOR_ULTRASPARC3:
777 sparc_costs = &ultrasparc3_costs;
782 #ifdef SUBTARGET_ATTRIBUTE_TABLE
783 /* Table of valid machine attributes. */
784 const struct attribute_spec sparc_attribute_table[] =
786 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
787 SUBTARGET_ATTRIBUTE_TABLE,
788 { NULL, 0, 0, false, false, false, NULL }
792 /* Miscellaneous utilities. */
794 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
795 or branch on register contents instructions. */
798 v9_regcmp_p (enum rtx_code code)
800 return (code == EQ || code == NE || code == GE || code == LT
801 || code == LE || code == GT);
805 /* Operand constraints. */
807 /* Nonzero if OP is a floating point constant which can
808 be loaded into an integer register using a single
809 sethi instruction. */
814 if (GET_CODE (op) == CONST_DOUBLE)
819 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
820 REAL_VALUE_TO_TARGET_SINGLE (r, i);
821 return !SPARC_SIMM13_P (i) && SPARC_SETHI_P (i);
827 /* Nonzero if OP is a floating point constant which can
828 be loaded into an integer register using a single
834 if (GET_CODE (op) == CONST_DOUBLE)
839 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
840 REAL_VALUE_TO_TARGET_SINGLE (r, i);
841 return SPARC_SIMM13_P (i);
847 /* Nonzero if OP is a floating point constant which can
848 be loaded into an integer register using a high/losum
849 instruction sequence. */
852 fp_high_losum_p (rtx op)
854 /* The constraints calling this should only be in
855 SFmode move insns, so any constant which cannot
856 be moved using a single insn will do. */
857 if (GET_CODE (op) == CONST_DOUBLE)
862 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
863 REAL_VALUE_TO_TARGET_SINGLE (r, i);
864 return !SPARC_SIMM13_P (i) && !SPARC_SETHI_P (i);
870 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
871 otherwise return 0. */
874 tls_symbolic_operand (rtx op)
876 if (GET_CODE (op) != SYMBOL_REF)
878 return SYMBOL_REF_TLS_MODEL (op);
881 /* We know it can't be done in one insn when we get here,
882 the movsi expander guarantees this. */
884 sparc_emit_set_const32 (rtx op0, rtx op1)
886 enum machine_mode mode = GET_MODE (op0);
889 if (reload_in_progress || reload_completed)
892 temp = gen_reg_rtx (mode);
894 if (GET_CODE (op1) == CONST_INT)
896 gcc_assert (!small_int_operand (op1, mode)
897 && !const_high_operand (op1, mode));
899 /* Emit them as real moves instead of a HIGH/LO_SUM,
900 this way CSE can see everything and reuse intermediate
901 values if it wants. */
902 emit_insn (gen_rtx_SET (VOIDmode, temp,
903 GEN_INT (INTVAL (op1)
904 & ~(HOST_WIDE_INT)0x3ff)));
906 emit_insn (gen_rtx_SET (VOIDmode,
908 gen_rtx_IOR (mode, temp,
909 GEN_INT (INTVAL (op1) & 0x3ff))));
913 /* A symbol, emit in the traditional way. */
914 emit_insn (gen_rtx_SET (VOIDmode, temp,
915 gen_rtx_HIGH (mode, op1)));
916 emit_insn (gen_rtx_SET (VOIDmode,
917 op0, gen_rtx_LO_SUM (mode, temp, op1)));
922 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
923 If TEMP is nonzero, we are forbidden to use any other scratch
924 registers. Otherwise, we are allowed to generate them as needed.
926 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
927 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
929 sparc_emit_set_symbolic_const64 (rtx op0, rtx op1, rtx temp)
931 rtx temp1, temp2, temp3, temp4, temp5;
934 if (temp && GET_MODE (temp) == TImode)
937 temp = gen_rtx_REG (DImode, REGNO (temp));
940 /* SPARC-V9 code-model support. */
941 switch (sparc_cmodel)
944 /* The range spanned by all instructions in the object is less
945 than 2^31 bytes (2GB) and the distance from any instruction
946 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
947 than 2^31 bytes (2GB).
949 The executable must be in the low 4TB of the virtual address
952 sethi %hi(symbol), %temp1
953 or %temp1, %lo(symbol), %reg */
955 temp1 = temp; /* op0 is allowed. */
957 temp1 = gen_reg_rtx (DImode);
959 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
960 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
964 /* The range spanned by all instructions in the object is less
965 than 2^31 bytes (2GB) and the distance from any instruction
966 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
967 than 2^31 bytes (2GB).
969 The executable must be in the low 16TB of the virtual address
972 sethi %h44(symbol), %temp1
973 or %temp1, %m44(symbol), %temp2
974 sllx %temp2, 12, %temp3
975 or %temp3, %l44(symbol), %reg */
980 temp3 = temp; /* op0 is allowed. */
984 temp1 = gen_reg_rtx (DImode);
985 temp2 = gen_reg_rtx (DImode);
986 temp3 = gen_reg_rtx (DImode);
989 emit_insn (gen_seth44 (temp1, op1));
990 emit_insn (gen_setm44 (temp2, temp1, op1));
991 emit_insn (gen_rtx_SET (VOIDmode, temp3,
992 gen_rtx_ASHIFT (DImode, temp2, GEN_INT (12))));
993 emit_insn (gen_setl44 (op0, temp3, op1));
997 /* The range spanned by all instructions in the object is less
998 than 2^31 bytes (2GB) and the distance from any instruction
999 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1000 than 2^31 bytes (2GB).
1002 The executable can be placed anywhere in the virtual address
1005 sethi %hh(symbol), %temp1
1006 sethi %lm(symbol), %temp2
1007 or %temp1, %hm(symbol), %temp3
1008 sllx %temp3, 32, %temp4
1009 or %temp4, %temp2, %temp5
1010 or %temp5, %lo(symbol), %reg */
1013 /* It is possible that one of the registers we got for operands[2]
1014 might coincide with that of operands[0] (which is why we made
1015 it TImode). Pick the other one to use as our scratch. */
1016 if (rtx_equal_p (temp, op0))
1018 gcc_assert (ti_temp);
1019 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1022 temp2 = temp; /* op0 is _not_ allowed, see above. */
1029 temp1 = gen_reg_rtx (DImode);
1030 temp2 = gen_reg_rtx (DImode);
1031 temp3 = gen_reg_rtx (DImode);
1032 temp4 = gen_reg_rtx (DImode);
1033 temp5 = gen_reg_rtx (DImode);
1036 emit_insn (gen_sethh (temp1, op1));
1037 emit_insn (gen_setlm (temp2, op1));
1038 emit_insn (gen_sethm (temp3, temp1, op1));
1039 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1040 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1041 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1042 gen_rtx_PLUS (DImode, temp4, temp2)));
1043 emit_insn (gen_setlo (op0, temp5, op1));
1047 /* Old old old backwards compatibility kruft here.
1048 Essentially it is MEDLOW with a fixed 64-bit
1049 virtual base added to all data segment addresses.
1050 Text-segment stuff is computed like MEDANY, we can't
1051 reuse the code above because the relocation knobs
1054 Data segment: sethi %hi(symbol), %temp1
1055 add %temp1, EMBMEDANY_BASE_REG, %temp2
1056 or %temp2, %lo(symbol), %reg */
1057 if (data_segment_operand (op1, GET_MODE (op1)))
1061 temp1 = temp; /* op0 is allowed. */
1066 temp1 = gen_reg_rtx (DImode);
1067 temp2 = gen_reg_rtx (DImode);
1070 emit_insn (gen_embmedany_sethi (temp1, op1));
1071 emit_insn (gen_embmedany_brsum (temp2, temp1));
1072 emit_insn (gen_embmedany_losum (op0, temp2, op1));
1075 /* Text segment: sethi %uhi(symbol), %temp1
1076 sethi %hi(symbol), %temp2
1077 or %temp1, %ulo(symbol), %temp3
1078 sllx %temp3, 32, %temp4
1079 or %temp4, %temp2, %temp5
1080 or %temp5, %lo(symbol), %reg */
1085 /* It is possible that one of the registers we got for operands[2]
1086 might coincide with that of operands[0] (which is why we made
1087 it TImode). Pick the other one to use as our scratch. */
1088 if (rtx_equal_p (temp, op0))
1090 gcc_assert (ti_temp);
1091 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1094 temp2 = temp; /* op0 is _not_ allowed, see above. */
1101 temp1 = gen_reg_rtx (DImode);
1102 temp2 = gen_reg_rtx (DImode);
1103 temp3 = gen_reg_rtx (DImode);
1104 temp4 = gen_reg_rtx (DImode);
1105 temp5 = gen_reg_rtx (DImode);
1108 emit_insn (gen_embmedany_textuhi (temp1, op1));
1109 emit_insn (gen_embmedany_texthi (temp2, op1));
1110 emit_insn (gen_embmedany_textulo (temp3, temp1, op1));
1111 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1112 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1113 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1114 gen_rtx_PLUS (DImode, temp4, temp2)));
1115 emit_insn (gen_embmedany_textlo (op0, temp5, op1));
1124 #if HOST_BITS_PER_WIDE_INT == 32
1126 sparc_emit_set_const64 (rtx op0 ATTRIBUTE_UNUSED, rtx op1 ATTRIBUTE_UNUSED)
1131 /* These avoid problems when cross compiling. If we do not
1132 go through all this hair then the optimizer will see
1133 invalid REG_EQUAL notes or in some cases none at all. */
1134 static rtx gen_safe_HIGH64 (rtx, HOST_WIDE_INT);
1135 static rtx gen_safe_SET64 (rtx, HOST_WIDE_INT);
1136 static rtx gen_safe_OR64 (rtx, HOST_WIDE_INT);
1137 static rtx gen_safe_XOR64 (rtx, HOST_WIDE_INT);
1139 /* The optimizer is not to assume anything about exactly
1140 which bits are set for a HIGH, they are unspecified.
1141 Unfortunately this leads to many missed optimizations
1142 during CSE. We mask out the non-HIGH bits, and matches
1143 a plain movdi, to alleviate this problem. */
1145 gen_safe_HIGH64 (rtx dest, HOST_WIDE_INT val)
1147 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val & ~(HOST_WIDE_INT)0x3ff));
1151 gen_safe_SET64 (rtx dest, HOST_WIDE_INT val)
1153 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val));
1157 gen_safe_OR64 (rtx src, HOST_WIDE_INT val)
1159 return gen_rtx_IOR (DImode, src, GEN_INT (val));
1163 gen_safe_XOR64 (rtx src, HOST_WIDE_INT val)
1165 return gen_rtx_XOR (DImode, src, GEN_INT (val));
1168 /* Worker routines for 64-bit constant formation on arch64.
1169 One of the key things to be doing in these emissions is
1170 to create as many temp REGs as possible. This makes it
1171 possible for half-built constants to be used later when
1172 such values are similar to something required later on.
1173 Without doing this, the optimizer cannot see such
1176 static void sparc_emit_set_const64_quick1 (rtx, rtx,
1177 unsigned HOST_WIDE_INT, int);
1180 sparc_emit_set_const64_quick1 (rtx op0, rtx temp,
1181 unsigned HOST_WIDE_INT low_bits, int is_neg)
1183 unsigned HOST_WIDE_INT high_bits;
1186 high_bits = (~low_bits) & 0xffffffff;
1188 high_bits = low_bits;
1190 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1193 emit_insn (gen_rtx_SET (VOIDmode, op0,
1194 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1198 /* If we are XOR'ing with -1, then we should emit a one's complement
1199 instead. This way the combiner will notice logical operations
1200 such as ANDN later on and substitute. */
1201 if ((low_bits & 0x3ff) == 0x3ff)
1203 emit_insn (gen_rtx_SET (VOIDmode, op0,
1204 gen_rtx_NOT (DImode, temp)));
1208 emit_insn (gen_rtx_SET (VOIDmode, op0,
1209 gen_safe_XOR64 (temp,
1210 (-(HOST_WIDE_INT)0x400
1211 | (low_bits & 0x3ff)))));
1216 static void sparc_emit_set_const64_quick2 (rtx, rtx, unsigned HOST_WIDE_INT,
1217 unsigned HOST_WIDE_INT, int);
1220 sparc_emit_set_const64_quick2 (rtx op0, rtx temp,
1221 unsigned HOST_WIDE_INT high_bits,
1222 unsigned HOST_WIDE_INT low_immediate,
1227 if ((high_bits & 0xfffffc00) != 0)
1229 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1230 if ((high_bits & ~0xfffffc00) != 0)
1231 emit_insn (gen_rtx_SET (VOIDmode, op0,
1232 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1238 emit_insn (gen_safe_SET64 (temp, high_bits));
1242 /* Now shift it up into place. */
1243 emit_insn (gen_rtx_SET (VOIDmode, op0,
1244 gen_rtx_ASHIFT (DImode, temp2,
1245 GEN_INT (shift_count))));
1247 /* If there is a low immediate part piece, finish up by
1248 putting that in as well. */
1249 if (low_immediate != 0)
1250 emit_insn (gen_rtx_SET (VOIDmode, op0,
1251 gen_safe_OR64 (op0, low_immediate)));
1254 static void sparc_emit_set_const64_longway (rtx, rtx, unsigned HOST_WIDE_INT,
1255 unsigned HOST_WIDE_INT);
1257 /* Full 64-bit constant decomposition. Even though this is the
1258 'worst' case, we still optimize a few things away. */
1260 sparc_emit_set_const64_longway (rtx op0, rtx temp,
1261 unsigned HOST_WIDE_INT high_bits,
1262 unsigned HOST_WIDE_INT low_bits)
1266 if (reload_in_progress || reload_completed)
1269 sub_temp = gen_reg_rtx (DImode);
1271 if ((high_bits & 0xfffffc00) != 0)
1273 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1274 if ((high_bits & ~0xfffffc00) != 0)
1275 emit_insn (gen_rtx_SET (VOIDmode,
1277 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1283 emit_insn (gen_safe_SET64 (temp, high_bits));
1287 if (!reload_in_progress && !reload_completed)
1289 rtx temp2 = gen_reg_rtx (DImode);
1290 rtx temp3 = gen_reg_rtx (DImode);
1291 rtx temp4 = gen_reg_rtx (DImode);
1293 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1294 gen_rtx_ASHIFT (DImode, sub_temp,
1297 emit_insn (gen_safe_HIGH64 (temp2, low_bits));
1298 if ((low_bits & ~0xfffffc00) != 0)
1300 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1301 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1302 emit_insn (gen_rtx_SET (VOIDmode, op0,
1303 gen_rtx_PLUS (DImode, temp4, temp3)));
1307 emit_insn (gen_rtx_SET (VOIDmode, op0,
1308 gen_rtx_PLUS (DImode, temp4, temp2)));
1313 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1314 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1315 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1318 /* We are in the middle of reload, so this is really
1319 painful. However we do still make an attempt to
1320 avoid emitting truly stupid code. */
1321 if (low1 != const0_rtx)
1323 emit_insn (gen_rtx_SET (VOIDmode, op0,
1324 gen_rtx_ASHIFT (DImode, sub_temp,
1325 GEN_INT (to_shift))));
1326 emit_insn (gen_rtx_SET (VOIDmode, op0,
1327 gen_rtx_IOR (DImode, op0, low1)));
1335 if (low2 != const0_rtx)
1337 emit_insn (gen_rtx_SET (VOIDmode, op0,
1338 gen_rtx_ASHIFT (DImode, sub_temp,
1339 GEN_INT (to_shift))));
1340 emit_insn (gen_rtx_SET (VOIDmode, op0,
1341 gen_rtx_IOR (DImode, op0, low2)));
1349 emit_insn (gen_rtx_SET (VOIDmode, op0,
1350 gen_rtx_ASHIFT (DImode, sub_temp,
1351 GEN_INT (to_shift))));
1352 if (low3 != const0_rtx)
1353 emit_insn (gen_rtx_SET (VOIDmode, op0,
1354 gen_rtx_IOR (DImode, op0, low3)));
1359 /* Analyze a 64-bit constant for certain properties. */
1360 static void analyze_64bit_constant (unsigned HOST_WIDE_INT,
1361 unsigned HOST_WIDE_INT,
1362 int *, int *, int *);
1365 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits,
1366 unsigned HOST_WIDE_INT low_bits,
1367 int *hbsp, int *lbsp, int *abbasp)
1369 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1372 lowest_bit_set = highest_bit_set = -1;
1376 if ((lowest_bit_set == -1)
1377 && ((low_bits >> i) & 1))
1379 if ((highest_bit_set == -1)
1380 && ((high_bits >> (32 - i - 1)) & 1))
1381 highest_bit_set = (64 - i - 1);
1384 && ((highest_bit_set == -1)
1385 || (lowest_bit_set == -1)));
1391 if ((lowest_bit_set == -1)
1392 && ((high_bits >> i) & 1))
1393 lowest_bit_set = i + 32;
1394 if ((highest_bit_set == -1)
1395 && ((low_bits >> (32 - i - 1)) & 1))
1396 highest_bit_set = 32 - i - 1;
1399 && ((highest_bit_set == -1)
1400 || (lowest_bit_set == -1)));
1402 /* If there are no bits set this should have gone out
1403 as one instruction! */
1404 gcc_assert (lowest_bit_set != -1 && highest_bit_set != -1);
1405 all_bits_between_are_set = 1;
1406 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1410 if ((low_bits & (1 << i)) != 0)
1415 if ((high_bits & (1 << (i - 32))) != 0)
1418 all_bits_between_are_set = 0;
1421 *hbsp = highest_bit_set;
1422 *lbsp = lowest_bit_set;
1423 *abbasp = all_bits_between_are_set;
1426 static int const64_is_2insns (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
1429 const64_is_2insns (unsigned HOST_WIDE_INT high_bits,
1430 unsigned HOST_WIDE_INT low_bits)
1432 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1435 || high_bits == 0xffffffff)
1438 analyze_64bit_constant (high_bits, low_bits,
1439 &highest_bit_set, &lowest_bit_set,
1440 &all_bits_between_are_set);
1442 if ((highest_bit_set == 63
1443 || lowest_bit_set == 0)
1444 && all_bits_between_are_set != 0)
1447 if ((highest_bit_set - lowest_bit_set) < 21)
1453 static unsigned HOST_WIDE_INT create_simple_focus_bits (unsigned HOST_WIDE_INT,
1454 unsigned HOST_WIDE_INT,
1457 static unsigned HOST_WIDE_INT
1458 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits,
1459 unsigned HOST_WIDE_INT low_bits,
1460 int lowest_bit_set, int shift)
1462 HOST_WIDE_INT hi, lo;
1464 if (lowest_bit_set < 32)
1466 lo = (low_bits >> lowest_bit_set) << shift;
1467 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
1472 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
1474 gcc_assert (! (hi & lo));
1478 /* Here we are sure to be arch64 and this is an integer constant
1479 being loaded into a register. Emit the most efficient
1480 insn sequence possible. Detection of all the 1-insn cases
1481 has been done already. */
1483 sparc_emit_set_const64 (rtx op0, rtx op1)
1485 unsigned HOST_WIDE_INT high_bits, low_bits;
1486 int lowest_bit_set, highest_bit_set;
1487 int all_bits_between_are_set;
1490 /* Sanity check that we know what we are working with. */
1491 gcc_assert (TARGET_ARCH64);
1493 if (GET_CODE (op0) != SUBREG)
1495 gcc_assert (GET_CODE (op0) == REG
1496 && (REGNO (op0) < SPARC_FIRST_FP_REG
1497 || REGNO (op0) > SPARC_LAST_V9_FP_REG));
1500 if (reload_in_progress || reload_completed)
1503 if (GET_CODE (op1) != CONST_INT)
1505 sparc_emit_set_symbolic_const64 (op0, op1, temp);
1510 temp = gen_reg_rtx (DImode);
1512 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
1513 low_bits = (INTVAL (op1) & 0xffffffff);
1515 /* low_bits bits 0 --> 31
1516 high_bits bits 32 --> 63 */
1518 analyze_64bit_constant (high_bits, low_bits,
1519 &highest_bit_set, &lowest_bit_set,
1520 &all_bits_between_are_set);
1522 /* First try for a 2-insn sequence. */
1524 /* These situations are preferred because the optimizer can
1525 * do more things with them:
1527 * sllx %reg, shift, %reg
1529 * srlx %reg, shift, %reg
1530 * 3) mov some_small_const, %reg
1531 * sllx %reg, shift, %reg
1533 if (((highest_bit_set == 63
1534 || lowest_bit_set == 0)
1535 && all_bits_between_are_set != 0)
1536 || ((highest_bit_set - lowest_bit_set) < 12))
1538 HOST_WIDE_INT the_const = -1;
1539 int shift = lowest_bit_set;
1541 if ((highest_bit_set != 63
1542 && lowest_bit_set != 0)
1543 || all_bits_between_are_set == 0)
1546 create_simple_focus_bits (high_bits, low_bits,
1549 else if (lowest_bit_set == 0)
1550 shift = -(63 - highest_bit_set);
1552 gcc_assert (SPARC_SIMM13_P (the_const));
1553 gcc_assert (shift != 0);
1555 emit_insn (gen_safe_SET64 (temp, the_const));
1557 emit_insn (gen_rtx_SET (VOIDmode,
1559 gen_rtx_ASHIFT (DImode,
1563 emit_insn (gen_rtx_SET (VOIDmode,
1565 gen_rtx_LSHIFTRT (DImode,
1567 GEN_INT (-shift))));
1571 /* Now a range of 22 or less bits set somewhere.
1572 * 1) sethi %hi(focus_bits), %reg
1573 * sllx %reg, shift, %reg
1574 * 2) sethi %hi(focus_bits), %reg
1575 * srlx %reg, shift, %reg
1577 if ((highest_bit_set - lowest_bit_set) < 21)
1579 unsigned HOST_WIDE_INT focus_bits =
1580 create_simple_focus_bits (high_bits, low_bits,
1581 lowest_bit_set, 10);
1583 gcc_assert (SPARC_SETHI_P (focus_bits));
1584 gcc_assert (lowest_bit_set != 10);
1586 emit_insn (gen_safe_HIGH64 (temp, focus_bits));
1588 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
1589 if (lowest_bit_set < 10)
1590 emit_insn (gen_rtx_SET (VOIDmode,
1592 gen_rtx_LSHIFTRT (DImode, temp,
1593 GEN_INT (10 - lowest_bit_set))));
1594 else if (lowest_bit_set > 10)
1595 emit_insn (gen_rtx_SET (VOIDmode,
1597 gen_rtx_ASHIFT (DImode, temp,
1598 GEN_INT (lowest_bit_set - 10))));
1602 /* 1) sethi %hi(low_bits), %reg
1603 * or %reg, %lo(low_bits), %reg
1604 * 2) sethi %hi(~low_bits), %reg
1605 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
1608 || high_bits == 0xffffffff)
1610 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
1611 (high_bits == 0xffffffff));
1615 /* Now, try 3-insn sequences. */
1617 /* 1) sethi %hi(high_bits), %reg
1618 * or %reg, %lo(high_bits), %reg
1619 * sllx %reg, 32, %reg
1623 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
1627 /* We may be able to do something quick
1628 when the constant is negated, so try that. */
1629 if (const64_is_2insns ((~high_bits) & 0xffffffff,
1630 (~low_bits) & 0xfffffc00))
1632 /* NOTE: The trailing bits get XOR'd so we need the
1633 non-negated bits, not the negated ones. */
1634 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
1636 if ((((~high_bits) & 0xffffffff) == 0
1637 && ((~low_bits) & 0x80000000) == 0)
1638 || (((~high_bits) & 0xffffffff) == 0xffffffff
1639 && ((~low_bits) & 0x80000000) != 0))
1641 unsigned HOST_WIDE_INT fast_int = (~low_bits & 0xffffffff);
1643 if ((SPARC_SETHI_P (fast_int)
1644 && (~high_bits & 0xffffffff) == 0)
1645 || SPARC_SIMM13_P (fast_int))
1646 emit_insn (gen_safe_SET64 (temp, fast_int));
1648 sparc_emit_set_const64 (temp, GEN_INT (fast_int));
1653 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
1654 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
1655 sparc_emit_set_const64 (temp, negated_const);
1658 /* If we are XOR'ing with -1, then we should emit a one's complement
1659 instead. This way the combiner will notice logical operations
1660 such as ANDN later on and substitute. */
1661 if (trailing_bits == 0x3ff)
1663 emit_insn (gen_rtx_SET (VOIDmode, op0,
1664 gen_rtx_NOT (DImode, temp)));
1668 emit_insn (gen_rtx_SET (VOIDmode,
1670 gen_safe_XOR64 (temp,
1671 (-0x400 | trailing_bits))));
1676 /* 1) sethi %hi(xxx), %reg
1677 * or %reg, %lo(xxx), %reg
1678 * sllx %reg, yyy, %reg
1680 * ??? This is just a generalized version of the low_bits==0
1681 * thing above, FIXME...
1683 if ((highest_bit_set - lowest_bit_set) < 32)
1685 unsigned HOST_WIDE_INT focus_bits =
1686 create_simple_focus_bits (high_bits, low_bits,
1689 /* We can't get here in this state. */
1690 gcc_assert (highest_bit_set >= 32 && lowest_bit_set < 32);
1692 /* So what we know is that the set bits straddle the
1693 middle of the 64-bit word. */
1694 sparc_emit_set_const64_quick2 (op0, temp,
1700 /* 1) sethi %hi(high_bits), %reg
1701 * or %reg, %lo(high_bits), %reg
1702 * sllx %reg, 32, %reg
1703 * or %reg, low_bits, %reg
1705 if (SPARC_SIMM13_P(low_bits)
1706 && ((int)low_bits > 0))
1708 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
1712 /* The easiest way when all else fails, is full decomposition. */
1714 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
1715 high_bits, low_bits, ~high_bits, ~low_bits);
1717 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
1719 #endif /* HOST_BITS_PER_WIDE_INT == 32 */
1721 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
1722 return the mode to be used for the comparison. For floating-point,
1723 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
1724 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
1725 processing is needed. */
1728 select_cc_mode (enum rtx_code op, rtx x, rtx y ATTRIBUTE_UNUSED)
1730 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1756 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
1757 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
1759 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
1760 return CCX_NOOVmode;
1766 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
1773 /* X and Y are two things to compare using CODE. Emit the compare insn and
1774 return the rtx for the cc reg in the proper mode. */
1777 gen_compare_reg (enum rtx_code code, rtx x, rtx y)
1779 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
1782 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
1783 fcc regs (cse can't tell they're really call clobbered regs and will
1784 remove a duplicate comparison even if there is an intervening function
1785 call - it will then try to reload the cc reg via an int reg which is why
1786 we need the movcc patterns). It is possible to provide the movcc
1787 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
1788 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
1789 to tell cse that CCFPE mode registers (even pseudos) are call
1792 /* ??? This is an experiment. Rather than making changes to cse which may
1793 or may not be easy/clean, we do our own cse. This is possible because
1794 we will generate hard registers. Cse knows they're call clobbered (it
1795 doesn't know the same thing about pseudos). If we guess wrong, no big
1796 deal, but if we win, great! */
1798 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1799 #if 1 /* experiment */
1802 /* We cycle through the registers to ensure they're all exercised. */
1803 static int next_fcc_reg = 0;
1804 /* Previous x,y for each fcc reg. */
1805 static rtx prev_args[4][2];
1807 /* Scan prev_args for x,y. */
1808 for (reg = 0; reg < 4; reg++)
1809 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
1814 prev_args[reg][0] = x;
1815 prev_args[reg][1] = y;
1816 next_fcc_reg = (next_fcc_reg + 1) & 3;
1818 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
1821 cc_reg = gen_reg_rtx (mode);
1822 #endif /* ! experiment */
1823 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1824 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
1826 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
1828 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
1829 gen_rtx_COMPARE (mode, x, y)));
1834 /* This function is used for v9 only.
1835 CODE is the code for an Scc's comparison.
1836 OPERANDS[0] is the target of the Scc insn.
1837 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
1838 been generated yet).
1840 This function is needed to turn
1843 (gt (reg:CCX 100 %icc)
1847 (gt:DI (reg:CCX 100 %icc)
1850 IE: The instruction recognizer needs to see the mode of the comparison to
1851 find the right instruction. We could use "gt:DI" right in the
1852 define_expand, but leaving it out allows us to handle DI, SI, etc.
1854 We refer to the global sparc compare operands sparc_compare_op0 and
1855 sparc_compare_op1. */
1858 gen_v9_scc (enum rtx_code compare_code, register rtx *operands)
1863 && (GET_MODE (sparc_compare_op0) == DImode
1864 || GET_MODE (operands[0]) == DImode))
1867 op0 = sparc_compare_op0;
1868 op1 = sparc_compare_op1;
1870 /* Try to use the movrCC insns. */
1872 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
1873 && op1 == const0_rtx
1874 && v9_regcmp_p (compare_code))
1876 /* Special case for op0 != 0. This can be done with one instruction if
1877 operands[0] == sparc_compare_op0. */
1879 if (compare_code == NE
1880 && GET_MODE (operands[0]) == DImode
1881 && rtx_equal_p (op0, operands[0]))
1883 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
1884 gen_rtx_IF_THEN_ELSE (DImode,
1885 gen_rtx_fmt_ee (compare_code, DImode,
1892 if (reg_overlap_mentioned_p (operands[0], op0))
1894 /* Handle the case where operands[0] == sparc_compare_op0.
1895 We "early clobber" the result. */
1896 op0 = gen_reg_rtx (GET_MODE (sparc_compare_op0));
1897 emit_move_insn (op0, sparc_compare_op0);
1900 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
1901 if (GET_MODE (op0) != DImode)
1903 temp = gen_reg_rtx (DImode);
1904 convert_move (temp, op0, 0);
1908 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
1909 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
1910 gen_rtx_fmt_ee (compare_code, DImode,
1918 operands[1] = gen_compare_reg (compare_code, op0, op1);
1920 switch (GET_MODE (operands[1]))
1930 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
1931 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
1932 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
1933 gen_rtx_fmt_ee (compare_code,
1934 GET_MODE (operands[1]),
1935 operands[1], const0_rtx),
1936 const1_rtx, operands[0])));
1941 /* Emit a conditional jump insn for the v9 architecture using comparison code
1942 CODE and jump target LABEL.
1943 This function exists to take advantage of the v9 brxx insns. */
1946 emit_v9_brxx_insn (enum rtx_code code, rtx op0, rtx label)
1948 emit_jump_insn (gen_rtx_SET (VOIDmode,
1950 gen_rtx_IF_THEN_ELSE (VOIDmode,
1951 gen_rtx_fmt_ee (code, GET_MODE (op0),
1953 gen_rtx_LABEL_REF (VOIDmode, label),
1957 /* Generate a DFmode part of a hard TFmode register.
1958 REG is the TFmode hard register, LOW is 1 for the
1959 low 64bit of the register and 0 otherwise.
1962 gen_df_reg (rtx reg, int low)
1964 int regno = REGNO (reg);
1966 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
1967 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
1968 return gen_rtx_REG (DFmode, regno);
1971 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
1972 Unlike normal calls, TFmode operands are passed by reference. It is
1973 assumed that no more than 3 operands are required. */
1976 emit_soft_tfmode_libcall (const char *func_name, int nargs, rtx *operands)
1978 rtx ret_slot = NULL, arg[3], func_sym;
1981 /* We only expect to be called for conversions, unary, and binary ops. */
1982 gcc_assert (nargs == 2 || nargs == 3);
1984 for (i = 0; i < nargs; ++i)
1986 rtx this_arg = operands[i];
1989 /* TFmode arguments and return values are passed by reference. */
1990 if (GET_MODE (this_arg) == TFmode)
1992 int force_stack_temp;
1994 force_stack_temp = 0;
1995 if (TARGET_BUGGY_QP_LIB && i == 0)
1996 force_stack_temp = 1;
1998 if (GET_CODE (this_arg) == MEM
1999 && ! force_stack_temp)
2000 this_arg = XEXP (this_arg, 0);
2001 else if (CONSTANT_P (this_arg)
2002 && ! force_stack_temp)
2004 this_slot = force_const_mem (TFmode, this_arg);
2005 this_arg = XEXP (this_slot, 0);
2009 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode), 0);
2011 /* Operand 0 is the return value. We'll copy it out later. */
2013 emit_move_insn (this_slot, this_arg);
2015 ret_slot = this_slot;
2017 this_arg = XEXP (this_slot, 0);
2024 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
2026 if (GET_MODE (operands[0]) == TFmode)
2029 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
2030 arg[0], GET_MODE (arg[0]),
2031 arg[1], GET_MODE (arg[1]));
2033 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
2034 arg[0], GET_MODE (arg[0]),
2035 arg[1], GET_MODE (arg[1]),
2036 arg[2], GET_MODE (arg[2]));
2039 emit_move_insn (operands[0], ret_slot);
2045 gcc_assert (nargs == 2);
2047 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
2048 GET_MODE (operands[0]), 1,
2049 arg[1], GET_MODE (arg[1]));
2051 if (ret != operands[0])
2052 emit_move_insn (operands[0], ret);
2056 /* Expand soft-float TFmode calls to sparc abi routines. */
2059 emit_soft_tfmode_binop (enum rtx_code code, rtx *operands)
2081 emit_soft_tfmode_libcall (func, 3, operands);
2085 emit_soft_tfmode_unop (enum rtx_code code, rtx *operands)
2089 gcc_assert (code == SQRT);
2092 emit_soft_tfmode_libcall (func, 2, operands);
2096 emit_soft_tfmode_cvt (enum rtx_code code, rtx *operands)
2103 switch (GET_MODE (operands[1]))
2116 case FLOAT_TRUNCATE:
2117 switch (GET_MODE (operands[0]))
2131 switch (GET_MODE (operands[1]))
2144 case UNSIGNED_FLOAT:
2145 switch (GET_MODE (operands[1]))
2159 switch (GET_MODE (operands[0]))
2173 switch (GET_MODE (operands[0]))
2190 emit_soft_tfmode_libcall (func, 2, operands);
2193 /* Expand a hard-float tfmode operation. All arguments must be in
2197 emit_hard_tfmode_operation (enum rtx_code code, rtx *operands)
2201 if (GET_RTX_CLASS (code) == RTX_UNARY)
2203 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2204 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
2208 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2209 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
2210 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
2211 operands[1], operands[2]);
2214 if (register_operand (operands[0], VOIDmode))
2217 dest = gen_reg_rtx (GET_MODE (operands[0]));
2219 emit_insn (gen_rtx_SET (VOIDmode, dest, op));
2221 if (dest != operands[0])
2222 emit_move_insn (operands[0], dest);
2226 emit_tfmode_binop (enum rtx_code code, rtx *operands)
2228 if (TARGET_HARD_QUAD)
2229 emit_hard_tfmode_operation (code, operands);
2231 emit_soft_tfmode_binop (code, operands);
2235 emit_tfmode_unop (enum rtx_code code, rtx *operands)
2237 if (TARGET_HARD_QUAD)
2238 emit_hard_tfmode_operation (code, operands);
2240 emit_soft_tfmode_unop (code, operands);
2244 emit_tfmode_cvt (enum rtx_code code, rtx *operands)
2246 if (TARGET_HARD_QUAD)
2247 emit_hard_tfmode_operation (code, operands);
2249 emit_soft_tfmode_cvt (code, operands);
2252 /* Return nonzero if a branch/jump/call instruction will be emitting
2253 nop into its delay slot. */
2256 empty_delay_slot (rtx insn)
2260 /* If no previous instruction (should not happen), return true. */
2261 if (PREV_INSN (insn) == NULL)
2264 seq = NEXT_INSN (PREV_INSN (insn));
2265 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
2271 /* Return nonzero if TRIAL can go into the call delay slot. */
2274 tls_call_delay (rtx trial)
2279 call __tls_get_addr, %tgd_call (foo)
2280 add %l7, %o0, %o0, %tgd_add (foo)
2281 while Sun as/ld does not. */
2282 if (TARGET_GNU_TLS || !TARGET_TLS)
2285 pat = PATTERN (trial);
2286 if (GET_CODE (pat) != SET || GET_CODE (SET_DEST (pat)) != PLUS)
2289 unspec = XEXP (SET_DEST (pat), 1);
2290 if (GET_CODE (unspec) != UNSPEC
2291 || (XINT (unspec, 1) != UNSPEC_TLSGD
2292 && XINT (unspec, 1) != UNSPEC_TLSLDM))
2298 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
2299 instruction. RETURN_P is true if the v9 variant 'return' is to be
2300 considered in the test too.
2302 TRIAL must be a SET whose destination is a REG appropriate for the
2303 'restore' instruction or, if RETURN_P is true, for the 'return'
2307 eligible_for_restore_insn (rtx trial, bool return_p)
2309 rtx pat = PATTERN (trial);
2310 rtx src = SET_SRC (pat);
2312 /* The 'restore src,%g0,dest' pattern for word mode and below. */
2313 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2314 && arith_operand (src, GET_MODE (src)))
2317 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2319 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2322 /* The 'restore src,%g0,dest' pattern for double-word mode. */
2323 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2324 && arith_double_operand (src, GET_MODE (src)))
2325 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2327 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
2328 else if (! TARGET_FPU && register_operand (src, SFmode))
2331 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
2332 else if (! TARGET_FPU && TARGET_ARCH64 && register_operand (src, DFmode))
2335 /* If we have the 'return' instruction, anything that does not use
2336 local or output registers and can go into a delay slot wins. */
2337 else if (return_p && TARGET_V9 && ! epilogue_renumber (&pat, 1)
2338 && (get_attr_in_uncond_branch_delay (trial)
2339 == IN_UNCOND_BRANCH_DELAY_TRUE))
2342 /* The 'restore src1,src2,dest' pattern for SImode. */
2343 else if (GET_CODE (src) == PLUS
2344 && register_operand (XEXP (src, 0), SImode)
2345 && arith_operand (XEXP (src, 1), SImode))
2348 /* The 'restore src1,src2,dest' pattern for DImode. */
2349 else if (GET_CODE (src) == PLUS
2350 && register_operand (XEXP (src, 0), DImode)
2351 && arith_double_operand (XEXP (src, 1), DImode))
2354 /* The 'restore src1,%lo(src2),dest' pattern. */
2355 else if (GET_CODE (src) == LO_SUM
2356 && ! TARGET_CM_MEDMID
2357 && ((register_operand (XEXP (src, 0), SImode)
2358 && immediate_operand (XEXP (src, 1), SImode))
2360 && register_operand (XEXP (src, 0), DImode)
2361 && immediate_operand (XEXP (src, 1), DImode))))
2364 /* The 'restore src,src,dest' pattern. */
2365 else if (GET_CODE (src) == ASHIFT
2366 && (register_operand (XEXP (src, 0), SImode)
2367 || register_operand (XEXP (src, 0), DImode))
2368 && XEXP (src, 1) == const1_rtx)
2374 /* Return nonzero if TRIAL can go into the function return's
2378 eligible_for_return_delay (rtx trial)
2382 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2385 if (get_attr_length (trial) != 1)
2388 /* If there are any call-saved registers, we should scan TRIAL if it
2389 does not reference them. For now just make it easy. */
2393 /* If the function uses __builtin_eh_return, the eh_return machinery
2394 occupies the delay slot. */
2395 if (current_function_calls_eh_return)
2398 /* In the case of a true leaf function, anything can go into the slot. */
2399 if (sparc_leaf_function_p)
2400 return get_attr_in_uncond_branch_delay (trial)
2401 == IN_UNCOND_BRANCH_DELAY_TRUE;
2403 pat = PATTERN (trial);
2405 /* Otherwise, only operations which can be done in tandem with
2406 a `restore' or `return' insn can go into the delay slot. */
2407 if (GET_CODE (SET_DEST (pat)) != REG
2408 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24))
2411 /* If this instruction sets up floating point register and we have a return
2412 instruction, it can probably go in. But restore will not work
2414 if (REGNO (SET_DEST (pat)) >= 32)
2416 && ! epilogue_renumber (&pat, 1)
2417 && (get_attr_in_uncond_branch_delay (trial)
2418 == IN_UNCOND_BRANCH_DELAY_TRUE));
2420 return eligible_for_restore_insn (trial, true);
2423 /* Return nonzero if TRIAL can go into the sibling call's
2427 eligible_for_sibcall_delay (rtx trial)
2431 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2434 if (get_attr_length (trial) != 1)
2437 pat = PATTERN (trial);
2439 if (sparc_leaf_function_p)
2441 /* If the tail call is done using the call instruction,
2442 we have to restore %o7 in the delay slot. */
2443 if (LEAF_SIBCALL_SLOT_RESERVED_P)
2446 /* %g1 is used to build the function address */
2447 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
2453 /* Otherwise, only operations which can be done in tandem with
2454 a `restore' insn can go into the delay slot. */
2455 if (GET_CODE (SET_DEST (pat)) != REG
2456 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24)
2457 || REGNO (SET_DEST (pat)) >= 32)
2460 /* If it mentions %o7, it can't go in, because sibcall will clobber it
2462 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
2465 return eligible_for_restore_insn (trial, false);
2469 short_branch (int uid1, int uid2)
2471 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
2473 /* Leave a few words of "slop". */
2474 if (delta >= -1023 && delta <= 1022)
2480 /* Return nonzero if REG is not used after INSN.
2481 We assume REG is a reload reg, and therefore does
2482 not live past labels or calls or jumps. */
2484 reg_unused_after (rtx reg, rtx insn)
2486 enum rtx_code code, prev_code = UNKNOWN;
2488 while ((insn = NEXT_INSN (insn)))
2490 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
2493 code = GET_CODE (insn);
2494 if (GET_CODE (insn) == CODE_LABEL)
2499 rtx set = single_set (insn);
2500 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
2503 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
2505 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
2513 /* Determine if it's legal to put X into the constant pool. This
2514 is not possible if X contains the address of a symbol that is
2515 not constant (TLS) or not known at final link time (PIC). */
2518 sparc_cannot_force_const_mem (rtx x)
2520 switch (GET_CODE (x))
2525 /* Accept all non-symbolic constants. */
2529 /* Labels are OK iff we are non-PIC. */
2530 return flag_pic != 0;
2533 /* 'Naked' TLS symbol references are never OK,
2534 non-TLS symbols are OK iff we are non-PIC. */
2535 if (SYMBOL_REF_TLS_MODEL (x))
2538 return flag_pic != 0;
2541 return sparc_cannot_force_const_mem (XEXP (x, 0));
2544 return sparc_cannot_force_const_mem (XEXP (x, 0))
2545 || sparc_cannot_force_const_mem (XEXP (x, 1));
2554 static GTY(()) char pic_helper_symbol_name[256];
2555 static GTY(()) rtx pic_helper_symbol;
2556 static GTY(()) bool pic_helper_emitted_p = false;
2557 static GTY(()) rtx global_offset_table;
2559 /* Ensure that we are not using patterns that are not OK with PIC. */
2567 gcc_assert (GET_CODE (recog_data.operand[i]) != SYMBOL_REF
2568 && (GET_CODE (recog_data.operand[i]) != CONST
2569 || (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
2570 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
2571 == global_offset_table)
2572 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
2580 /* Return true if X is an address which needs a temporary register when
2581 reloaded while generating PIC code. */
2584 pic_address_needs_scratch (rtx x)
2586 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
2587 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2588 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2589 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2590 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
2596 /* Determine if a given RTX is a valid constant. We already know this
2597 satisfies CONSTANT_P. */
2600 legitimate_constant_p (rtx x)
2604 switch (GET_CODE (x))
2607 /* TLS symbols are not constant. */
2608 if (SYMBOL_REF_TLS_MODEL (x))
2613 inner = XEXP (x, 0);
2615 /* Offsets of TLS symbols are never valid.
2616 Discourage CSE from creating them. */
2617 if (GET_CODE (inner) == PLUS
2618 && tls_symbolic_operand (XEXP (inner, 0)))
2623 if (GET_MODE (x) == VOIDmode)
2626 /* Floating point constants are generally not ok.
2627 The only exception is 0.0 in VIS. */
2629 && (GET_MODE (x) == SFmode
2630 || GET_MODE (x) == DFmode
2631 || GET_MODE (x) == TFmode)
2632 && const_zero_operand (x, GET_MODE (x)))
2644 /* Determine if a given RTX is a valid constant address. */
2647 constant_address_p (rtx x)
2649 switch (GET_CODE (x))
2657 if (flag_pic && pic_address_needs_scratch (x))
2659 return legitimate_constant_p (x);
2662 return !flag_pic && legitimate_constant_p (x);
2669 /* Nonzero if the constant value X is a legitimate general operand
2670 when generating PIC code. It is given that flag_pic is on and
2671 that X satisfies CONSTANT_P or is a CONST_DOUBLE. */
2674 legitimate_pic_operand_p (rtx x)
2676 if (pic_address_needs_scratch (x))
2678 if (tls_symbolic_operand (x)
2679 || (GET_CODE (x) == CONST
2680 && GET_CODE (XEXP (x, 0)) == PLUS
2681 && tls_symbolic_operand (XEXP (XEXP (x, 0), 0))))
2686 /* Return nonzero if ADDR is a valid memory address.
2687 STRICT specifies whether strict register checking applies. */
2690 legitimate_address_p (enum machine_mode mode, rtx addr, int strict)
2692 rtx rs1 = NULL, rs2 = NULL, imm1 = NULL;
2694 if (REG_P (addr) || GET_CODE (addr) == SUBREG)
2696 else if (GET_CODE (addr) == PLUS)
2698 rs1 = XEXP (addr, 0);
2699 rs2 = XEXP (addr, 1);
2701 /* Canonicalize. REG comes first, if there are no regs,
2702 LO_SUM comes first. */
2704 && GET_CODE (rs1) != SUBREG
2706 || GET_CODE (rs2) == SUBREG
2707 || (GET_CODE (rs2) == LO_SUM && GET_CODE (rs1) != LO_SUM)))
2709 rs1 = XEXP (addr, 1);
2710 rs2 = XEXP (addr, 0);
2714 && rs1 == pic_offset_table_rtx
2716 && GET_CODE (rs2) != SUBREG
2717 && GET_CODE (rs2) != LO_SUM
2718 && GET_CODE (rs2) != MEM
2719 && !tls_symbolic_operand (rs2)
2720 && (! symbolic_operand (rs2, VOIDmode) || mode == Pmode)
2721 && (GET_CODE (rs2) != CONST_INT || SMALL_INT (rs2)))
2723 || GET_CODE (rs1) == SUBREG)
2724 && RTX_OK_FOR_OFFSET_P (rs2)))
2729 else if ((REG_P (rs1) || GET_CODE (rs1) == SUBREG)
2730 && (REG_P (rs2) || GET_CODE (rs2) == SUBREG))
2732 /* We prohibit REG + REG for TFmode when there are no quad move insns
2733 and we consequently need to split. We do this because REG+REG
2734 is not an offsettable address. If we get the situation in reload
2735 where source and destination of a movtf pattern are both MEMs with
2736 REG+REG address, then only one of them gets converted to an
2737 offsettable address. */
2739 && ! (TARGET_FPU && TARGET_ARCH64 && TARGET_HARD_QUAD))
2742 /* We prohibit REG + REG on ARCH32 if not optimizing for
2743 DFmode/DImode because then mem_min_alignment is likely to be zero
2744 after reload and the forced split would lack a matching splitter
2746 if (TARGET_ARCH32 && !optimize
2747 && (mode == DFmode || mode == DImode))
2750 else if (USE_AS_OFFSETABLE_LO10
2751 && GET_CODE (rs1) == LO_SUM
2753 && ! TARGET_CM_MEDMID
2754 && RTX_OK_FOR_OLO10_P (rs2))
2757 imm1 = XEXP (rs1, 1);
2758 rs1 = XEXP (rs1, 0);
2759 if (! CONSTANT_P (imm1) || tls_symbolic_operand (rs1))
2763 else if (GET_CODE (addr) == LO_SUM)
2765 rs1 = XEXP (addr, 0);
2766 imm1 = XEXP (addr, 1);
2768 if (! CONSTANT_P (imm1) || tls_symbolic_operand (rs1))
2771 /* We can't allow TFmode in 32-bit mode, because an offset greater
2772 than the alignment (8) may cause the LO_SUM to overflow. */
2773 if (mode == TFmode && TARGET_ARCH32)
2776 else if (GET_CODE (addr) == CONST_INT && SMALL_INT (addr))
2781 if (GET_CODE (rs1) == SUBREG)
2782 rs1 = SUBREG_REG (rs1);
2788 if (GET_CODE (rs2) == SUBREG)
2789 rs2 = SUBREG_REG (rs2);
2796 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1))
2797 || (rs2 && !REGNO_OK_FOR_BASE_P (REGNO (rs2))))
2802 if ((REGNO (rs1) >= 32
2803 && REGNO (rs1) != FRAME_POINTER_REGNUM
2804 && REGNO (rs1) < FIRST_PSEUDO_REGISTER)
2806 && (REGNO (rs2) >= 32
2807 && REGNO (rs2) != FRAME_POINTER_REGNUM
2808 && REGNO (rs2) < FIRST_PSEUDO_REGISTER)))
2814 /* Construct the SYMBOL_REF for the tls_get_offset function. */
2816 static GTY(()) rtx sparc_tls_symbol;
2818 sparc_tls_get_addr (void)
2820 if (!sparc_tls_symbol)
2821 sparc_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_addr");
2823 return sparc_tls_symbol;
2827 sparc_tls_got (void)
2832 current_function_uses_pic_offset_table = 1;
2833 return pic_offset_table_rtx;
2836 if (!global_offset_table)
2837 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2838 temp = gen_reg_rtx (Pmode);
2839 emit_move_insn (temp, global_offset_table);
2844 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2845 this (thread-local) address. */
2848 legitimize_tls_address (rtx addr)
2850 rtx temp1, temp2, temp3, ret, o0, got, insn;
2852 gcc_assert (! no_new_pseudos);
2854 if (GET_CODE (addr) == SYMBOL_REF)
2855 switch (SYMBOL_REF_TLS_MODEL (addr))
2857 case TLS_MODEL_GLOBAL_DYNAMIC:
2859 temp1 = gen_reg_rtx (SImode);
2860 temp2 = gen_reg_rtx (SImode);
2861 ret = gen_reg_rtx (Pmode);
2862 o0 = gen_rtx_REG (Pmode, 8);
2863 got = sparc_tls_got ();
2864 emit_insn (gen_tgd_hi22 (temp1, addr));
2865 emit_insn (gen_tgd_lo10 (temp2, temp1, addr));
2868 emit_insn (gen_tgd_add32 (o0, got, temp2, addr));
2869 insn = emit_call_insn (gen_tgd_call32 (o0, sparc_tls_get_addr (),
2874 emit_insn (gen_tgd_add64 (o0, got, temp2, addr));
2875 insn = emit_call_insn (gen_tgd_call64 (o0, sparc_tls_get_addr (),
2878 CALL_INSN_FUNCTION_USAGE (insn)
2879 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
2880 CALL_INSN_FUNCTION_USAGE (insn));
2881 insn = get_insns ();
2883 emit_libcall_block (insn, ret, o0, addr);
2886 case TLS_MODEL_LOCAL_DYNAMIC:
2888 temp1 = gen_reg_rtx (SImode);
2889 temp2 = gen_reg_rtx (SImode);
2890 temp3 = gen_reg_rtx (Pmode);
2891 ret = gen_reg_rtx (Pmode);
2892 o0 = gen_rtx_REG (Pmode, 8);
2893 got = sparc_tls_got ();
2894 emit_insn (gen_tldm_hi22 (temp1));
2895 emit_insn (gen_tldm_lo10 (temp2, temp1));
2898 emit_insn (gen_tldm_add32 (o0, got, temp2));
2899 insn = emit_call_insn (gen_tldm_call32 (o0, sparc_tls_get_addr (),
2904 emit_insn (gen_tldm_add64 (o0, got, temp2));
2905 insn = emit_call_insn (gen_tldm_call64 (o0, sparc_tls_get_addr (),
2908 CALL_INSN_FUNCTION_USAGE (insn)
2909 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
2910 CALL_INSN_FUNCTION_USAGE (insn));
2911 insn = get_insns ();
2913 emit_libcall_block (insn, temp3, o0,
2914 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2915 UNSPEC_TLSLD_BASE));
2916 temp1 = gen_reg_rtx (SImode);
2917 temp2 = gen_reg_rtx (SImode);
2918 emit_insn (gen_tldo_hix22 (temp1, addr));
2919 emit_insn (gen_tldo_lox10 (temp2, temp1, addr));
2921 emit_insn (gen_tldo_add32 (ret, temp3, temp2, addr));
2923 emit_insn (gen_tldo_add64 (ret, temp3, temp2, addr));
2926 case TLS_MODEL_INITIAL_EXEC:
2927 temp1 = gen_reg_rtx (SImode);
2928 temp2 = gen_reg_rtx (SImode);
2929 temp3 = gen_reg_rtx (Pmode);
2930 got = sparc_tls_got ();
2931 emit_insn (gen_tie_hi22 (temp1, addr));
2932 emit_insn (gen_tie_lo10 (temp2, temp1, addr));
2934 emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
2936 emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
2939 ret = gen_reg_rtx (Pmode);
2941 emit_insn (gen_tie_add32 (ret, gen_rtx_REG (Pmode, 7),
2944 emit_insn (gen_tie_add64 (ret, gen_rtx_REG (Pmode, 7),
2948 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp3);
2951 case TLS_MODEL_LOCAL_EXEC:
2952 temp1 = gen_reg_rtx (Pmode);
2953 temp2 = gen_reg_rtx (Pmode);
2956 emit_insn (gen_tle_hix22_sp32 (temp1, addr));
2957 emit_insn (gen_tle_lox10_sp32 (temp2, temp1, addr));
2961 emit_insn (gen_tle_hix22_sp64 (temp1, addr));
2962 emit_insn (gen_tle_lox10_sp64 (temp2, temp1, addr));
2964 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp2);
2972 gcc_unreachable (); /* for now ... */
2978 /* Legitimize PIC addresses. If the address is already position-independent,
2979 we return ORIG. Newly generated position-independent addresses go into a
2980 reg. This is REG if nonzero, otherwise we allocate register(s) as
2984 legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
2987 if (GET_CODE (orig) == SYMBOL_REF)
2989 rtx pic_ref, address;
2994 gcc_assert (! reload_in_progress && ! reload_completed);
2995 reg = gen_reg_rtx (Pmode);
3000 /* If not during reload, allocate another temp reg here for loading
3001 in the address, so that these instructions can be optimized
3003 rtx temp_reg = ((reload_in_progress || reload_completed)
3004 ? reg : gen_reg_rtx (Pmode));
3006 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
3007 won't get confused into thinking that these two instructions
3008 are loading in the true address of the symbol. If in the
3009 future a PIC rtx exists, that should be used instead. */
3010 if (Pmode == SImode)
3012 emit_insn (gen_movsi_high_pic (temp_reg, orig));
3013 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
3017 emit_insn (gen_movdi_high_pic (temp_reg, orig));
3018 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
3025 pic_ref = gen_const_mem (Pmode,
3026 gen_rtx_PLUS (Pmode,
3027 pic_offset_table_rtx, address));
3028 current_function_uses_pic_offset_table = 1;
3029 insn = emit_move_insn (reg, pic_ref);
3030 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3032 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
3036 else if (GET_CODE (orig) == CONST)
3040 if (GET_CODE (XEXP (orig, 0)) == PLUS
3041 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3046 gcc_assert (! reload_in_progress && ! reload_completed);
3047 reg = gen_reg_rtx (Pmode);
3050 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
3051 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
3052 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
3053 base == reg ? 0 : reg);
3055 if (GET_CODE (offset) == CONST_INT)
3057 if (SMALL_INT (offset))
3058 return plus_constant (base, INTVAL (offset));
3059 else if (! reload_in_progress && ! reload_completed)
3060 offset = force_reg (Pmode, offset);
3062 /* If we reach here, then something is seriously wrong. */
3065 return gen_rtx_PLUS (Pmode, base, offset);
3067 else if (GET_CODE (orig) == LABEL_REF)
3068 /* ??? Why do we do this? */
3069 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
3070 the register is live instead, in case it is eliminated. */
3071 current_function_uses_pic_offset_table = 1;
3076 /* Try machine-dependent ways of modifying an illegitimate address X
3077 to be legitimate. If we find one, return the new, valid address.
3079 OLDX is the address as it was before break_out_memory_refs was called.
3080 In some cases it is useful to look at this to decide what needs to be done.
3082 MODE is the mode of the operand pointed to by X. */
3085 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
3089 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT)
3090 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3091 force_operand (XEXP (x, 0), NULL_RTX));
3092 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == MULT)
3093 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3094 force_operand (XEXP (x, 1), NULL_RTX));
3095 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS)
3096 x = gen_rtx_PLUS (Pmode, force_operand (XEXP (x, 0), NULL_RTX),
3098 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == PLUS)
3099 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3100 force_operand (XEXP (x, 1), NULL_RTX));
3102 if (x != orig_x && legitimate_address_p (mode, x, FALSE))
3105 if (tls_symbolic_operand (x))
3106 x = legitimize_tls_address (x);
3108 x = legitimize_pic_address (x, mode, 0);
3109 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 1)))
3110 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3111 copy_to_mode_reg (Pmode, XEXP (x, 1)));
3112 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 0)))
3113 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3114 copy_to_mode_reg (Pmode, XEXP (x, 0)));
3115 else if (GET_CODE (x) == SYMBOL_REF
3116 || GET_CODE (x) == CONST
3117 || GET_CODE (x) == LABEL_REF)
3118 x = copy_to_suggested_reg (x, NULL_RTX, Pmode);
3122 /* Emit the special PIC helper function. */
3125 emit_pic_helper (void)
3127 const char *pic_name = reg_names[REGNO (pic_offset_table_rtx)];
3132 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
3134 ASM_OUTPUT_ALIGN (asm_out_file, align);
3135 ASM_OUTPUT_LABEL (asm_out_file, pic_helper_symbol_name);
3136 if (flag_delayed_branch)
3137 fprintf (asm_out_file, "\tjmp\t%%o7+8\n\t add\t%%o7, %s, %s\n",
3138 pic_name, pic_name);
3140 fprintf (asm_out_file, "\tadd\t%%o7, %s, %s\n\tjmp\t%%o7+8\n\t nop\n",
3141 pic_name, pic_name);
3143 pic_helper_emitted_p = true;
3146 /* Emit code to load the PIC register. */
3149 load_pic_register (bool delay_pic_helper)
3151 int orig_flag_pic = flag_pic;
3153 /* If we haven't initialized the special PIC symbols, do so now. */
3154 if (!pic_helper_symbol_name[0])
3156 ASM_GENERATE_INTERNAL_LABEL (pic_helper_symbol_name, "LADDPC", 0);
3157 pic_helper_symbol = gen_rtx_SYMBOL_REF (Pmode, pic_helper_symbol_name);
3158 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3161 /* If we haven't emitted the special PIC helper function, do so now unless
3162 we are requested to delay it. */
3163 if (!delay_pic_helper && !pic_helper_emitted_p)
3168 emit_insn (gen_load_pcrel_symdi (pic_offset_table_rtx, global_offset_table,
3169 pic_helper_symbol));
3171 emit_insn (gen_load_pcrel_symsi (pic_offset_table_rtx, global_offset_table,
3172 pic_helper_symbol));
3173 flag_pic = orig_flag_pic;
3175 /* Need to emit this whether or not we obey regdecls,
3176 since setjmp/longjmp can cause life info to screw up.
3177 ??? In the case where we don't obey regdecls, this is not sufficient
3178 since we may not fall out the bottom. */
3179 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3182 /* Return 1 if RTX is a MEM which is known to be aligned to at
3183 least a DESIRED byte boundary. */
3186 mem_min_alignment (rtx mem, int desired)
3188 rtx addr, base, offset;
3190 /* If it's not a MEM we can't accept it. */
3191 if (GET_CODE (mem) != MEM)
3195 if (!TARGET_UNALIGNED_DOUBLES
3196 && MEM_ALIGN (mem) / BITS_PER_UNIT >= (unsigned)desired)
3199 /* ??? The rest of the function predates MEM_ALIGN so
3200 there is probably a bit of redundancy. */
3201 addr = XEXP (mem, 0);
3202 base = offset = NULL_RTX;
3203 if (GET_CODE (addr) == PLUS)
3205 if (GET_CODE (XEXP (addr, 0)) == REG)
3207 base = XEXP (addr, 0);
3209 /* What we are saying here is that if the base
3210 REG is aligned properly, the compiler will make
3211 sure any REG based index upon it will be so
3213 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3214 offset = XEXP (addr, 1);
3216 offset = const0_rtx;
3219 else if (GET_CODE (addr) == REG)
3222 offset = const0_rtx;
3225 if (base != NULL_RTX)
3227 int regno = REGNO (base);
3229 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
3231 /* Check if the compiler has recorded some information
3232 about the alignment of the base REG. If reload has
3233 completed, we already matched with proper alignments.
3234 If not running global_alloc, reload might give us
3235 unaligned pointer to local stack though. */
3237 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
3238 || (optimize && reload_completed))
3239 && (INTVAL (offset) & (desired - 1)) == 0)
3244 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
3248 else if (! TARGET_UNALIGNED_DOUBLES
3249 || CONSTANT_P (addr)
3250 || GET_CODE (addr) == LO_SUM)
3252 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
3253 is true, in which case we can only assume that an access is aligned if
3254 it is to a constant address, or the address involves a LO_SUM. */
3258 /* An obviously unaligned address. */
3263 /* Vectors to keep interesting information about registers where it can easily
3264 be got. We used to use the actual mode value as the bit number, but there
3265 are more than 32 modes now. Instead we use two tables: one indexed by
3266 hard register number, and one indexed by mode. */
3268 /* The purpose of sparc_mode_class is to shrink the range of modes so that
3269 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
3270 mapped into one sparc_mode_class mode. */
3272 enum sparc_mode_class {
3273 S_MODE, D_MODE, T_MODE, O_MODE,
3274 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
3278 /* Modes for single-word and smaller quantities. */
3279 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
3281 /* Modes for double-word and smaller quantities. */
3282 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
3284 /* Modes for quad-word and smaller quantities. */
3285 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
3287 /* Modes for 8-word and smaller quantities. */
3288 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
3290 /* Modes for single-float quantities. We must allow any single word or
3291 smaller quantity. This is because the fix/float conversion instructions
3292 take integer inputs/outputs from the float registers. */
3293 #define SF_MODES (S_MODES)
3295 /* Modes for double-float and smaller quantities. */
3296 #define DF_MODES (S_MODES | D_MODES)
3298 /* Modes for double-float only quantities. */
3299 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
3301 /* Modes for quad-float only quantities. */
3302 #define TF_ONLY_MODES (1 << (int) TF_MODE)
3304 /* Modes for quad-float and smaller quantities. */
3305 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
3307 /* Modes for quad-float and double-float quantities. */
3308 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
3310 /* Modes for quad-float pair only quantities. */
3311 #define OF_ONLY_MODES (1 << (int) OF_MODE)
3313 /* Modes for quad-float pairs and smaller quantities. */
3314 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
3316 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
3318 /* Modes for condition codes. */
3319 #define CC_MODES (1 << (int) CC_MODE)
3320 #define CCFP_MODES (1 << (int) CCFP_MODE)
3322 /* Value is 1 if register/mode pair is acceptable on sparc.
3323 The funny mixture of D and T modes is because integer operations
3324 do not specially operate on tetra quantities, so non-quad-aligned
3325 registers can hold quadword quantities (except %o4 and %i4 because
3326 they cross fixed registers). */
3328 /* This points to either the 32 bit or the 64 bit version. */
3329 const int *hard_regno_mode_classes;
3331 static const int hard_32bit_mode_classes[] = {
3332 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3333 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3334 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3335 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3337 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_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, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3342 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3343 and none can hold SFmode/SImode values. */
3344 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
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, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3350 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3356 static const int hard_64bit_mode_classes[] = {
3357 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3358 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3359 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3360 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3362 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_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, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3367 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3368 and none can hold SFmode/SImode values. */
3369 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
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, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3375 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3381 int sparc_mode_class [NUM_MACHINE_MODES];
3383 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
3386 sparc_init_modes (void)
3390 for (i = 0; i < NUM_MACHINE_MODES; i++)
3392 switch (GET_MODE_CLASS (i))
3395 case MODE_PARTIAL_INT:
3396 case MODE_COMPLEX_INT:
3397 if (GET_MODE_SIZE (i) <= 4)
3398 sparc_mode_class[i] = 1 << (int) S_MODE;
3399 else if (GET_MODE_SIZE (i) == 8)
3400 sparc_mode_class[i] = 1 << (int) D_MODE;
3401 else if (GET_MODE_SIZE (i) == 16)
3402 sparc_mode_class[i] = 1 << (int) T_MODE;
3403 else if (GET_MODE_SIZE (i) == 32)
3404 sparc_mode_class[i] = 1 << (int) O_MODE;
3406 sparc_mode_class[i] = 0;
3408 case MODE_VECTOR_INT:
3409 if (GET_MODE_SIZE (i) <= 4)
3410 sparc_mode_class[i] = 1 << (int)SF_MODE;
3411 else if (GET_MODE_SIZE (i) == 8)
3412 sparc_mode_class[i] = 1 << (int)DF_MODE;
3415 case MODE_COMPLEX_FLOAT:
3416 if (GET_MODE_SIZE (i) <= 4)
3417 sparc_mode_class[i] = 1 << (int) SF_MODE;
3418 else if (GET_MODE_SIZE (i) == 8)
3419 sparc_mode_class[i] = 1 << (int) DF_MODE;
3420 else if (GET_MODE_SIZE (i) == 16)
3421 sparc_mode_class[i] = 1 << (int) TF_MODE;
3422 else if (GET_MODE_SIZE (i) == 32)
3423 sparc_mode_class[i] = 1 << (int) OF_MODE;
3425 sparc_mode_class[i] = 0;
3428 if (i == (int) CCFPmode || i == (int) CCFPEmode)
3429 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
3431 sparc_mode_class[i] = 1 << (int) CC_MODE;
3434 sparc_mode_class[i] = 0;
3440 hard_regno_mode_classes = hard_64bit_mode_classes;
3442 hard_regno_mode_classes = hard_32bit_mode_classes;
3444 /* Initialize the array used by REGNO_REG_CLASS. */
3445 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3447 if (i < 16 && TARGET_V8PLUS)
3448 sparc_regno_reg_class[i] = I64_REGS;
3449 else if (i < 32 || i == FRAME_POINTER_REGNUM)
3450 sparc_regno_reg_class[i] = GENERAL_REGS;
3452 sparc_regno_reg_class[i] = FP_REGS;
3454 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
3456 sparc_regno_reg_class[i] = FPCC_REGS;
3458 sparc_regno_reg_class[i] = NO_REGS;
3462 /* Compute the frame size required by the function. This function is called
3463 during the reload pass and also by sparc_expand_prologue. */
3466 sparc_compute_frame_size (HOST_WIDE_INT size, int leaf_function_p)
3468 int outgoing_args_size = (current_function_outgoing_args_size
3469 + REG_PARM_STACK_SPACE (current_function_decl));
3470 int n_regs = 0; /* N_REGS is the number of 4-byte regs saved thus far. */
3475 for (i = 0; i < 8; i++)
3476 if (regs_ever_live[i] && ! call_used_regs[i])
3481 for (i = 0; i < 8; i += 2)
3482 if ((regs_ever_live[i] && ! call_used_regs[i])
3483 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3487 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
3488 if ((regs_ever_live[i] && ! call_used_regs[i])
3489 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3492 /* Set up values for use in prologue and epilogue. */
3493 num_gfregs = n_regs;
3498 && current_function_outgoing_args_size == 0)
3499 actual_fsize = apparent_fsize = 0;
3502 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
3503 apparent_fsize = (size - STARTING_FRAME_OFFSET + 7) & -8;
3504 apparent_fsize += n_regs * 4;
3505 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
3508 /* Make sure nothing can clobber our register windows.
3509 If a SAVE must be done, or there is a stack-local variable,
3510 the register window area must be allocated. */
3511 if (! leaf_function_p || size > 0)
3512 actual_fsize += FIRST_PARM_OFFSET (current_function_decl);
3514 return SPARC_STACK_ALIGN (actual_fsize);
3517 /* Output any necessary .register pseudo-ops. */
3520 sparc_output_scratch_registers (FILE *file ATTRIBUTE_UNUSED)
3522 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
3528 /* Check if %g[2367] were used without
3529 .register being printed for them already. */
3530 for (i = 2; i < 8; i++)
3532 if (regs_ever_live [i]
3533 && ! sparc_hard_reg_printed [i])
3535 sparc_hard_reg_printed [i] = 1;
3536 fprintf (file, "\t.register\t%%g%d, #scratch\n", i);
3543 /* Save/restore call-saved registers from LOW to HIGH at BASE+OFFSET
3544 as needed. LOW should be double-word aligned for 32-bit registers.
3545 Return the new OFFSET. */
3548 #define SORR_RESTORE 1
3551 save_or_restore_regs (int low, int high, rtx base, int offset, int action)
3556 if (TARGET_ARCH64 && high <= 32)
3558 for (i = low; i < high; i++)
3560 if (regs_ever_live[i] && ! call_used_regs[i])
3562 mem = gen_rtx_MEM (DImode, plus_constant (base, offset));
3563 set_mem_alias_set (mem, sparc_sr_alias_set);
3564 if (action == SORR_SAVE)
3566 insn = emit_move_insn (mem, gen_rtx_REG (DImode, i));
3567 RTX_FRAME_RELATED_P (insn) = 1;
3569 else /* action == SORR_RESTORE */
3570 emit_move_insn (gen_rtx_REG (DImode, i), mem);
3577 for (i = low; i < high; i += 2)
3579 bool reg0 = regs_ever_live[i] && ! call_used_regs[i];
3580 bool reg1 = regs_ever_live[i+1] && ! call_used_regs[i+1];
3581 enum machine_mode mode;
3586 mode = i < 32 ? DImode : DFmode;
3591 mode = i < 32 ? SImode : SFmode;
3596 mode = i < 32 ? SImode : SFmode;
3603 mem = gen_rtx_MEM (mode, plus_constant (base, offset));
3604 set_mem_alias_set (mem, sparc_sr_alias_set);
3605 if (action == SORR_SAVE)
3607 insn = emit_move_insn (mem, gen_rtx_REG (mode, regno));
3608 RTX_FRAME_RELATED_P (insn) = 1;
3610 else /* action == SORR_RESTORE */
3611 emit_move_insn (gen_rtx_REG (mode, regno), mem);
3613 /* Always preserve double-word alignment. */
3614 offset = (offset + 7) & -8;
3621 /* Emit code to save call-saved registers. */
3624 emit_save_or_restore_regs (int action)
3626 HOST_WIDE_INT offset;
3629 offset = frame_base_offset - apparent_fsize;
3631 if (offset < -4096 || offset + num_gfregs * 4 > 4095)
3633 /* ??? This might be optimized a little as %g1 might already have a
3634 value close enough that a single add insn will do. */
3635 /* ??? Although, all of this is probably only a temporary fix
3636 because if %g1 can hold a function result, then
3637 sparc_expand_epilogue will lose (the result will be
3639 base = gen_rtx_REG (Pmode, 1);
3640 emit_move_insn (base, GEN_INT (offset));
3641 emit_insn (gen_rtx_SET (VOIDmode,
3643 gen_rtx_PLUS (Pmode, frame_base_reg, base)));
3647 base = frame_base_reg;
3649 offset = save_or_restore_regs (0, 8, base, offset, action);
3650 save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, action);
3653 /* Generate a save_register_window insn. */
3656 gen_save_register_window (rtx increment)
3659 return gen_save_register_windowdi (increment);
3661 return gen_save_register_windowsi (increment);
3664 /* Generate an increment for the stack pointer. */
3667 gen_stack_pointer_inc (rtx increment)
3670 return gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx, increment);
3672 return gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, increment);
3675 /* Generate a decrement for the stack pointer. */
3678 gen_stack_pointer_dec (rtx decrement)
3681 return gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, decrement);
3683 return gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, decrement);
3686 /* Expand the function prologue. The prologue is responsible for reserving
3687 storage for the frame, saving the call-saved registers and loading the
3688 PIC register if needed. */
3691 sparc_expand_prologue (void)
3696 /* Compute a snapshot of current_function_uses_only_leaf_regs. Relying
3697 on the final value of the flag means deferring the prologue/epilogue
3698 expansion until just before the second scheduling pass, which is too
3699 late to emit multiple epilogues or return insns.
3701 Of course we are making the assumption that the value of the flag
3702 will not change between now and its final value. Of the three parts
3703 of the formula, only the last one can reasonably vary. Let's take a
3704 closer look, after assuming that the first two ones are set to true
3705 (otherwise the last value is effectively silenced).
3707 If only_leaf_regs_used returns false, the global predicate will also
3708 be false so the actual frame size calculated below will be positive.
3709 As a consequence, the save_register_window insn will be emitted in
3710 the instruction stream; now this insn explicitly references %fp
3711 which is not a leaf register so only_leaf_regs_used will always
3712 return false subsequently.
3714 If only_leaf_regs_used returns true, we hope that the subsequent
3715 optimization passes won't cause non-leaf registers to pop up. For
3716 example, the regrename pass has special provisions to not rename to
3717 non-leaf registers in a leaf function. */
3718 sparc_leaf_function_p
3719 = optimize > 0 && leaf_function_p () && only_leaf_regs_used ();
3721 /* Need to use actual_fsize, since we are also allocating
3722 space for our callee (and our own register save area). */
3724 = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p);
3726 /* Advertise that the data calculated just above are now valid. */
3727 sparc_prologue_data_valid_p = true;
3729 if (sparc_leaf_function_p)
3731 frame_base_reg = stack_pointer_rtx;
3732 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
3736 frame_base_reg = hard_frame_pointer_rtx;
3737 frame_base_offset = SPARC_STACK_BIAS;
3740 if (actual_fsize == 0)
3742 else if (sparc_leaf_function_p)
3744 if (actual_fsize <= 4096)
3745 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-actual_fsize)));
3746 else if (actual_fsize <= 8192)
3748 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-4096)));
3749 /* %sp is still the CFA register. */
3750 RTX_FRAME_RELATED_P (insn) = 1;
3752 = emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize)));
3756 rtx reg = gen_rtx_REG (Pmode, 1);
3757 emit_move_insn (reg, GEN_INT (-actual_fsize));
3758 insn = emit_insn (gen_stack_pointer_inc (reg));
3760 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3761 PATTERN (gen_stack_pointer_inc (GEN_INT (-actual_fsize))),
3765 RTX_FRAME_RELATED_P (insn) = 1;
3769 if (actual_fsize <= 4096)
3770 insn = emit_insn (gen_save_register_window (GEN_INT (-actual_fsize)));
3771 else if (actual_fsize <= 8192)
3773 insn = emit_insn (gen_save_register_window (GEN_INT (-4096)));
3774 /* %sp is not the CFA register anymore. */
3775 emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize)));
3779 rtx reg = gen_rtx_REG (Pmode, 1);
3780 emit_move_insn (reg, GEN_INT (-actual_fsize));
3781 insn = emit_insn (gen_save_register_window (reg));
3784 RTX_FRAME_RELATED_P (insn) = 1;
3785 for (i=0; i < XVECLEN (PATTERN (insn), 0); i++)
3786 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, i)) = 1;
3790 emit_save_or_restore_regs (SORR_SAVE);
3792 /* Load the PIC register if needed. */
3793 if (flag_pic && current_function_uses_pic_offset_table)
3794 load_pic_register (false);
3797 /* This function generates the assembly code for function entry, which boils
3798 down to emitting the necessary .register directives. */
3801 sparc_asm_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3803 /* Check that the assumption we made in sparc_expand_prologue is valid. */
3804 gcc_assert (sparc_leaf_function_p == current_function_uses_only_leaf_regs);
3806 sparc_output_scratch_registers (file);
3809 /* Expand the function epilogue, either normal or part of a sibcall.
3810 We emit all the instructions except the return or the call. */
3813 sparc_expand_epilogue (void)
3816 emit_save_or_restore_regs (SORR_RESTORE);
3818 if (actual_fsize == 0)
3820 else if (sparc_leaf_function_p)
3822 if (actual_fsize <= 4096)
3823 emit_insn (gen_stack_pointer_dec (GEN_INT (- actual_fsize)));
3824 else if (actual_fsize <= 8192)
3826 emit_insn (gen_stack_pointer_dec (GEN_INT (-4096)));
3827 emit_insn (gen_stack_pointer_dec (GEN_INT (4096 - actual_fsize)));
3831 rtx reg = gen_rtx_REG (Pmode, 1);
3832 emit_move_insn (reg, GEN_INT (-actual_fsize));
3833 emit_insn (gen_stack_pointer_dec (reg));
3838 /* Return true if it is appropriate to emit `return' instructions in the
3839 body of a function. */
3842 sparc_can_use_return_insn_p (void)
3844 return sparc_prologue_data_valid_p
3845 && (actual_fsize == 0 || !sparc_leaf_function_p);
3848 /* This function generates the assembly code for function exit. */
3851 sparc_asm_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3853 /* If code does not drop into the epilogue, we have to still output
3854 a dummy nop for the sake of sane backtraces. Otherwise, if the
3855 last two instructions of a function were "call foo; dslot;" this
3856 can make the return PC of foo (i.e. address of call instruction
3857 plus 8) point to the first instruction in the next function. */
3859 rtx insn, last_real_insn;
3861 insn = get_last_insn ();
3863 last_real_insn = prev_real_insn (insn);
3865 && GET_CODE (last_real_insn) == INSN
3866 && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE)
3867 last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0);
3869 if (last_real_insn && GET_CODE (last_real_insn) == CALL_INSN)
3870 fputs("\tnop\n", file);
3872 sparc_output_deferred_case_vectors ();
3875 /* Output a 'restore' instruction. */
3878 output_restore (rtx pat)
3884 fputs ("\t restore\n", asm_out_file);
3888 gcc_assert (GET_CODE (pat) == SET);
3890 operands[0] = SET_DEST (pat);
3891 pat = SET_SRC (pat);
3893 switch (GET_CODE (pat))
3896 operands[1] = XEXP (pat, 0);
3897 operands[2] = XEXP (pat, 1);
3898 output_asm_insn (" restore %r1, %2, %Y0", operands);
3901 operands[1] = XEXP (pat, 0);
3902 operands[2] = XEXP (pat, 1);
3903 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
3906 operands[1] = XEXP (pat, 0);
3907 gcc_assert (XEXP (pat, 1) == const1_rtx);
3908 output_asm_insn (" restore %r1, %r1, %Y0", operands);
3912 output_asm_insn (" restore %%g0, %1, %Y0", operands);
3917 /* Output a return. */
3920 output_return (rtx insn)
3922 if (sparc_leaf_function_p)
3924 /* This is a leaf function so we don't have to bother restoring the
3925 register window, which frees us from dealing with the convoluted
3926 semantics of restore/return. We simply output the jump to the
3927 return address and the insn in the delay slot (if any). */
3929 gcc_assert (! current_function_calls_eh_return);
3931 return "jmp\t%%o7+%)%#";
3935 /* This is a regular function so we have to restore the register window.
3936 We may have a pending insn for the delay slot, which will be either
3937 combined with the 'restore' instruction or put in the delay slot of
3938 the 'return' instruction. */
3940 if (current_function_calls_eh_return)
3942 /* If the function uses __builtin_eh_return, the eh_return
3943 machinery occupies the delay slot. */
3944 gcc_assert (! final_sequence);
3946 if (! flag_delayed_branch)
3947 fputs ("\tadd\t%fp, %g1, %fp\n", asm_out_file);
3950 fputs ("\treturn\t%i7+8\n", asm_out_file);
3952 fputs ("\trestore\n\tjmp\t%o7+8\n", asm_out_file);
3954 if (flag_delayed_branch)
3955 fputs ("\t add\t%sp, %g1, %sp\n", asm_out_file);
3957 fputs ("\t nop\n", asm_out_file);
3959 else if (final_sequence)
3963 delay = NEXT_INSN (insn);
3966 pat = PATTERN (delay);
3968 if (TARGET_V9 && ! epilogue_renumber (&pat, 1))
3970 epilogue_renumber (&pat, 0);
3971 return "return\t%%i7+%)%#";
3975 output_asm_insn ("jmp\t%%i7+%)", NULL);
3976 output_restore (pat);
3977 PATTERN (delay) = gen_blockage ();
3978 INSN_CODE (delay) = -1;
3983 /* The delay slot is empty. */
3985 return "return\t%%i7+%)\n\t nop";
3986 else if (flag_delayed_branch)
3987 return "jmp\t%%i7+%)\n\t restore";
3989 return "restore\n\tjmp\t%%o7+%)\n\t nop";
3996 /* Output a sibling call. */
3999 output_sibcall (rtx insn, rtx call_operand)
4003 gcc_assert (flag_delayed_branch);
4005 operands[0] = call_operand;
4007 if (sparc_leaf_function_p)
4009 /* This is a leaf function so we don't have to bother restoring the
4010 register window. We simply output the jump to the function and
4011 the insn in the delay slot (if any). */
4013 gcc_assert (!(LEAF_SIBCALL_SLOT_RESERVED_P && final_sequence));
4016 output_asm_insn ("sethi\t%%hi(%a0), %%g1\n\tjmp\t%%g1 + %%lo(%a0)%#",
4019 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
4020 it into branch if possible. */
4021 output_asm_insn ("or\t%%o7, %%g0, %%g1\n\tcall\t%a0, 0\n\t or\t%%g1, %%g0, %%o7",
4026 /* This is a regular function so we have to restore the register window.
4027 We may have a pending insn for the delay slot, which will be combined
4028 with the 'restore' instruction. */
4030 output_asm_insn ("call\t%a0, 0", operands);
4034 rtx delay = NEXT_INSN (insn);
4037 output_restore (PATTERN (delay));
4039 PATTERN (delay) = gen_blockage ();
4040 INSN_CODE (delay) = -1;
4043 output_restore (NULL_RTX);
4049 /* Functions for handling argument passing.
4051 For 32-bit, the first 6 args are normally in registers and the rest are
4052 pushed. Any arg that starts within the first 6 words is at least
4053 partially passed in a register unless its data type forbids.
4055 For 64-bit, the argument registers are laid out as an array of 16 elements
4056 and arguments are added sequentially. The first 6 int args and up to the
4057 first 16 fp args (depending on size) are passed in regs.
4059 Slot Stack Integral Float Float in structure Double Long Double
4060 ---- ----- -------- ----- ------------------ ------ -----------
4061 15 [SP+248] %f31 %f30,%f31 %d30
4062 14 [SP+240] %f29 %f28,%f29 %d28 %q28
4063 13 [SP+232] %f27 %f26,%f27 %d26
4064 12 [SP+224] %f25 %f24,%f25 %d24 %q24
4065 11 [SP+216] %f23 %f22,%f23 %d22
4066 10 [SP+208] %f21 %f20,%f21 %d20 %q20
4067 9 [SP+200] %f19 %f18,%f19 %d18
4068 8 [SP+192] %f17 %f16,%f17 %d16 %q16
4069 7 [SP+184] %f15 %f14,%f15 %d14
4070 6 [SP+176] %f13 %f12,%f13 %d12 %q12
4071 5 [SP+168] %o5 %f11 %f10,%f11 %d10
4072 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
4073 3 [SP+152] %o3 %f7 %f6,%f7 %d6
4074 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
4075 1 [SP+136] %o1 %f3 %f2,%f3 %d2
4076 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
4078 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
4080 Integral arguments are always passed as 64-bit quantities appropriately
4083 Passing of floating point values is handled as follows.
4084 If a prototype is in scope:
4085 If the value is in a named argument (i.e. not a stdarg function or a
4086 value not part of the `...') then the value is passed in the appropriate
4088 If the value is part of the `...' and is passed in one of the first 6
4089 slots then the value is passed in the appropriate int reg.
4090 If the value is part of the `...' and is not passed in one of the first 6
4091 slots then the value is passed in memory.
4092 If a prototype is not in scope:
4093 If the value is one of the first 6 arguments the value is passed in the
4094 appropriate integer reg and the appropriate fp reg.
4095 If the value is not one of the first 6 arguments the value is passed in
4096 the appropriate fp reg and in memory.
4099 Summary of the calling conventions implemented by GCC on SPARC:
4102 size argument return value
4104 small integer <4 int. reg. int. reg.
4105 word 4 int. reg. int. reg.
4106 double word 8 int. reg. int. reg.
4108 _Complex small integer <8 int. reg. int. reg.
4109 _Complex word 8 int. reg. int. reg.
4110 _Complex double word 16 memory int. reg.
4112 vector integer <=8 int. reg. FP reg.
4113 vector integer >8 memory memory
4115 float 4 int. reg. FP reg.
4116 double 8 int. reg. FP reg.
4117 long double 16 memory memory
4119 _Complex float 8 memory FP reg.
4120 _Complex double 16 memory FP reg.
4121 _Complex long double 32 memory FP reg.
4123 vector float any memory memory
4125 aggregate any memory memory
4130 size argument return value
4132 small integer <8 int. reg. int. reg.
4133 word 8 int. reg. int. reg.
4134 double word 16 int. reg. int. reg.
4136 _Complex small integer <16 int. reg. int. reg.
4137 _Complex word 16 int. reg. int. reg.
4138 _Complex double word 32 memory int. reg.
4140 vector integer <=16 FP reg. FP reg.
4141 vector integer 16<s<=32 memory FP reg.
4142 vector integer >32 memory memory
4144 float 4 FP reg. FP reg.
4145 double 8 FP reg. FP reg.
4146 long double 16 FP reg. FP reg.
4148 _Complex float 8 FP reg. FP reg.
4149 _Complex double 16 FP reg. FP reg.
4150 _Complex long double 32 memory FP reg.
4152 vector float <=16 FP reg. FP reg.
4153 vector float 16<s<=32 memory FP reg.
4154 vector float >32 memory memory
4156 aggregate <=16 reg. reg.
4157 aggregate 16<s<=32 memory reg.
4158 aggregate >32 memory memory
4162 Note #1: complex floating-point types follow the extended SPARC ABIs as
4163 implemented by the Sun compiler.
4165 Note #2: integral vector types follow the scalar floating-point types
4166 conventions to match what is implemented by the Sun VIS SDK.
4168 Note #3: floating-point vector types follow the aggregate types
4172 /* Maximum number of int regs for args. */
4173 #define SPARC_INT_ARG_MAX 6
4174 /* Maximum number of fp regs for args. */
4175 #define SPARC_FP_ARG_MAX 16
4177 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
4179 /* Handle the INIT_CUMULATIVE_ARGS macro.
4180 Initialize a variable CUM of type CUMULATIVE_ARGS
4181 for a call to a function whose data type is FNTYPE.
4182 For a library call, FNTYPE is 0. */
4185 init_cumulative_args (struct sparc_args *cum, tree fntype,
4186 rtx libname ATTRIBUTE_UNUSED,
4187 tree fndecl ATTRIBUTE_UNUSED)
4190 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
4191 cum->libcall_p = fntype == 0;
4194 /* Handle the TARGET_PROMOTE_PROTOTYPES target hook.
4195 When a prototype says `char' or `short', really pass an `int'. */
4198 sparc_promote_prototypes (tree fntype ATTRIBUTE_UNUSED)
4200 return TARGET_ARCH32 ? true : false;
4203 /* Handle the TARGET_STRICT_ARGUMENT_NAMING target hook. */
4206 sparc_strict_argument_naming (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED)
4208 return TARGET_ARCH64 ? true : false;
4211 /* Scan the record type TYPE and return the following predicates:
4212 - INTREGS_P: the record contains at least one field or sub-field
4213 that is eligible for promotion in integer registers.
4214 - FP_REGS_P: the record contains at least one field or sub-field
4215 that is eligible for promotion in floating-point registers.
4216 - PACKED_P: the record contains at least one field that is packed.
4218 Sub-fields are not taken into account for the PACKED_P predicate. */
4221 scan_record_type (tree type, int *intregs_p, int *fpregs_p, int *packed_p)
4225 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4227 if (TREE_CODE (field) == FIELD_DECL)
4229 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4230 scan_record_type (TREE_TYPE (field), intregs_p, fpregs_p, 0);
4231 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
4232 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
4238 if (packed_p && DECL_PACKED (field))
4244 /* Compute the slot number to pass an argument in.
4245 Return the slot number or -1 if passing on the stack.
4247 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4248 the preceding args and about the function being called.
4249 MODE is the argument's machine mode.
4250 TYPE is the data type of the argument (as a tree).
4251 This is null for libcalls where that information may
4253 NAMED is nonzero if this argument is a named parameter
4254 (otherwise it is an extra parameter matching an ellipsis).
4255 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
4256 *PREGNO records the register number to use if scalar type.
4257 *PPADDING records the amount of padding needed in words. */
4260 function_arg_slotno (const struct sparc_args *cum, enum machine_mode mode,
4261 tree type, int named, int incoming_p,
4262 int *pregno, int *ppadding)
4264 int regbase = (incoming_p
4265 ? SPARC_INCOMING_INT_ARG_FIRST
4266 : SPARC_OUTGOING_INT_ARG_FIRST);
4267 int slotno = cum->words;
4268 enum mode_class mclass;
4273 if (type && TREE_ADDRESSABLE (type))
4279 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
4282 /* For SPARC64, objects requiring 16-byte alignment get it. */
4284 && GET_MODE_ALIGNMENT (mode) >= 2 * BITS_PER_WORD
4285 && (slotno & 1) != 0)
4286 slotno++, *ppadding = 1;
4288 mclass = GET_MODE_CLASS (mode);
4289 if (type && TREE_CODE (type) == VECTOR_TYPE)
4291 /* Vector types deserve special treatment because they are
4292 polymorphic wrt their mode, depending upon whether VIS
4293 instructions are enabled. */
4294 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
4296 /* The SPARC port defines no floating-point vector modes. */
4297 gcc_assert (mode == BLKmode);
4301 /* Integral vector types should either have a vector
4302 mode or an integral mode, because we are guaranteed
4303 by pass_by_reference that their size is not greater
4304 than 16 bytes and TImode is 16-byte wide. */
4305 gcc_assert (mode != BLKmode);
4307 /* Vector integers are handled like floats according to
4309 mclass = MODE_FLOAT;
4316 case MODE_COMPLEX_FLOAT:
4317 if (TARGET_ARCH64 && TARGET_FPU && named)
4319 if (slotno >= SPARC_FP_ARG_MAX)
4321 regno = SPARC_FP_ARG_FIRST + slotno * 2;
4322 /* Arguments filling only one single FP register are
4323 right-justified in the outer double FP register. */
4324 if (GET_MODE_SIZE (mode) <= 4)
4331 case MODE_COMPLEX_INT:
4332 if (slotno >= SPARC_INT_ARG_MAX)
4334 regno = regbase + slotno;
4338 if (mode == VOIDmode)
4339 /* MODE is VOIDmode when generating the actual call. */
4342 gcc_assert (mode == BLKmode);
4344 /* For SPARC64, objects requiring 16-byte alignment get it. */
4347 && TYPE_ALIGN (type) >= 2 * BITS_PER_WORD
4348 && (slotno & 1) != 0)
4349 slotno++, *ppadding = 1;
4351 if (TARGET_ARCH32 || !type || (TREE_CODE (type) == UNION_TYPE))
4353 if (slotno >= SPARC_INT_ARG_MAX)
4355 regno = regbase + slotno;
4357 else /* TARGET_ARCH64 && type */
4359 int intregs_p = 0, fpregs_p = 0, packed_p = 0;
4361 /* First see what kinds of registers we would need. */
4362 if (TREE_CODE (type) == VECTOR_TYPE)
4365 scan_record_type (type, &intregs_p, &fpregs_p, &packed_p);
4367 /* The ABI obviously doesn't specify how packed structures
4368 are passed. These are defined to be passed in int regs
4369 if possible, otherwise memory. */
4370 if (packed_p || !named)
4371 fpregs_p = 0, intregs_p = 1;
4373 /* If all arg slots are filled, then must pass on stack. */
4374 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
4377 /* If there are only int args and all int arg slots are filled,
4378 then must pass on stack. */
4379 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
4382 /* Note that even if all int arg slots are filled, fp members may
4383 still be passed in regs if such regs are available.
4384 *PREGNO isn't set because there may be more than one, it's up
4385 to the caller to compute them. */
4398 /* Handle recursive register counting for structure field layout. */
4400 struct function_arg_record_value_parms
4402 rtx ret; /* return expression being built. */
4403 int slotno; /* slot number of the argument. */
4404 int named; /* whether the argument is named. */
4405 int regbase; /* regno of the base register. */
4406 int stack; /* 1 if part of the argument is on the stack. */
4407 int intoffset; /* offset of the first pending integer field. */
4408 unsigned int nregs; /* number of words passed in registers. */
4411 static void function_arg_record_value_3
4412 (HOST_WIDE_INT, struct function_arg_record_value_parms *);
4413 static void function_arg_record_value_2
4414 (tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
4415 static void function_arg_record_value_1
4416 (tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
4417 static rtx function_arg_record_value (tree, enum machine_mode, int, int, int);
4418 static rtx function_arg_union_value (int, enum machine_mode, int, int);
4420 /* A subroutine of function_arg_record_value. Traverse the structure
4421 recursively and determine how many registers will be required. */
4424 function_arg_record_value_1 (tree type, HOST_WIDE_INT startbitpos,
4425 struct function_arg_record_value_parms *parms,
4430 /* We need to compute how many registers are needed so we can
4431 allocate the PARALLEL but before we can do that we need to know
4432 whether there are any packed fields. The ABI obviously doesn't
4433 specify how structures are passed in this case, so they are
4434 defined to be passed in int regs if possible, otherwise memory,
4435 regardless of whether there are fp values present. */
4438 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4440 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4447 /* Compute how many registers we need. */
4448 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4450 if (TREE_CODE (field) == FIELD_DECL)
4452 HOST_WIDE_INT bitpos = startbitpos;
4454 if (DECL_SIZE (field) != 0)
4456 if (integer_zerop (DECL_SIZE (field)))
4459 if (host_integerp (bit_position (field), 1))
4460 bitpos += int_bit_position (field);
4463 /* ??? FIXME: else assume zero offset. */
4465 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4466 function_arg_record_value_1 (TREE_TYPE (field),
4470 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
4471 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
4476 if (parms->intoffset != -1)
4478 unsigned int startbit, endbit;
4479 int intslots, this_slotno;
4481 startbit = parms->intoffset & -BITS_PER_WORD;
4482 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4484 intslots = (endbit - startbit) / BITS_PER_WORD;
4485 this_slotno = parms->slotno + parms->intoffset
4488 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
4490 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
4491 /* We need to pass this field on the stack. */
4495 parms->nregs += intslots;
4496 parms->intoffset = -1;
4499 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
4500 If it wasn't true we wouldn't be here. */
4501 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
4502 && DECL_MODE (field) == BLKmode)
4503 parms->nregs += TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
4504 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
4511 if (parms->intoffset == -1)
4512 parms->intoffset = bitpos;
4518 /* A subroutine of function_arg_record_value. Assign the bits of the
4519 structure between parms->intoffset and bitpos to integer registers. */
4522 function_arg_record_value_3 (HOST_WIDE_INT bitpos,
4523 struct function_arg_record_value_parms *parms)
4525 enum machine_mode mode;
4527 unsigned int startbit, endbit;
4528 int this_slotno, intslots, intoffset;
4531 if (parms->intoffset == -1)
4534 intoffset = parms->intoffset;
4535 parms->intoffset = -1;
4537 startbit = intoffset & -BITS_PER_WORD;
4538 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4539 intslots = (endbit - startbit) / BITS_PER_WORD;
4540 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
4542 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4546 /* If this is the trailing part of a word, only load that much into
4547 the register. Otherwise load the whole register. Note that in
4548 the latter case we may pick up unwanted bits. It's not a problem
4549 at the moment but may wish to revisit. */
4551 if (intoffset % BITS_PER_WORD != 0)
4552 mode = smallest_mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
4557 intoffset /= BITS_PER_UNIT;
4560 regno = parms->regbase + this_slotno;
4561 reg = gen_rtx_REG (mode, regno);
4562 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
4563 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
4566 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
4571 while (intslots > 0);
4574 /* A subroutine of function_arg_record_value. Traverse the structure
4575 recursively and assign bits to floating point registers. Track which
4576 bits in between need integer registers; invoke function_arg_record_value_3
4577 to make that happen. */
4580 function_arg_record_value_2 (tree type, HOST_WIDE_INT startbitpos,
4581 struct function_arg_record_value_parms *parms,
4587 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4589 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4596 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4598 if (TREE_CODE (field) == FIELD_DECL)
4600 HOST_WIDE_INT bitpos = startbitpos;
4602 if (DECL_SIZE (field) != 0)
4604 if (integer_zerop (DECL_SIZE (field)))
4607 if (host_integerp (bit_position (field), 1))
4608 bitpos += int_bit_position (field);
4611 /* ??? FIXME: else assume zero offset. */
4613 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4614 function_arg_record_value_2 (TREE_TYPE (field),
4618 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
4619 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
4624 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
4625 int regno, nregs, pos;
4626 enum machine_mode mode = DECL_MODE (field);
4629 function_arg_record_value_3 (bitpos, parms);
4631 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
4634 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
4635 nregs = TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
4637 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
4639 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
4645 regno = SPARC_FP_ARG_FIRST + this_slotno * 2;
4646 if (GET_MODE_SIZE (mode) <= 4 && (bitpos & 32) != 0)
4648 reg = gen_rtx_REG (mode, regno);
4649 pos = bitpos / BITS_PER_UNIT;
4650 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
4651 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
4655 regno += GET_MODE_SIZE (mode) / 4;
4656 reg = gen_rtx_REG (mode, regno);
4657 pos += GET_MODE_SIZE (mode);
4658 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
4659 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
4665 if (parms->intoffset == -1)
4666 parms->intoffset = bitpos;
4672 /* Used by function_arg and function_value to implement the complex
4673 conventions of the 64-bit ABI for passing and returning structures.
4674 Return an expression valid as a return value for the two macros
4675 FUNCTION_ARG and FUNCTION_VALUE.
4677 TYPE is the data type of the argument (as a tree).
4678 This is null for libcalls where that information may
4680 MODE is the argument's machine mode.
4681 SLOTNO is the index number of the argument's slot in the parameter array.
4682 NAMED is nonzero if this argument is a named parameter
4683 (otherwise it is an extra parameter matching an ellipsis).
4684 REGBASE is the regno of the base register for the parameter array. */
4687 function_arg_record_value (tree type, enum machine_mode mode,
4688 int slotno, int named, int regbase)
4690 HOST_WIDE_INT typesize = int_size_in_bytes (type);
4691 struct function_arg_record_value_parms parms;
4694 parms.ret = NULL_RTX;
4695 parms.slotno = slotno;
4696 parms.named = named;
4697 parms.regbase = regbase;
4700 /* Compute how many registers we need. */
4702 parms.intoffset = 0;
4703 function_arg_record_value_1 (type, 0, &parms, false);
4705 /* Take into account pending integer fields. */
4706 if (parms.intoffset != -1)
4708 unsigned int startbit, endbit;
4709 int intslots, this_slotno;
4711 startbit = parms.intoffset & -BITS_PER_WORD;
4712 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4713 intslots = (endbit - startbit) / BITS_PER_WORD;
4714 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
4716 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
4718 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
4719 /* We need to pass this field on the stack. */
4723 parms.nregs += intslots;
4725 nregs = parms.nregs;
4727 /* Allocate the vector and handle some annoying special cases. */
4730 /* ??? Empty structure has no value? Duh? */
4733 /* Though there's nothing really to store, return a word register
4734 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
4735 leads to breakage due to the fact that there are zero bytes to
4737 return gen_rtx_REG (mode, regbase);
4741 /* ??? C++ has structures with no fields, and yet a size. Give up
4742 for now and pass everything back in integer registers. */
4743 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4745 if (nregs + slotno > SPARC_INT_ARG_MAX)
4746 nregs = SPARC_INT_ARG_MAX - slotno;
4748 gcc_assert (nregs != 0);
4750 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (parms.stack + nregs));
4752 /* If at least one field must be passed on the stack, generate
4753 (parallel [(expr_list (nil) ...) ...]) so that all fields will
4754 also be passed on the stack. We can't do much better because the
4755 semantics of TARGET_ARG_PARTIAL_BYTES doesn't handle the case
4756 of structures for which the fields passed exclusively in registers
4757 are not at the beginning of the structure. */
4759 XVECEXP (parms.ret, 0, 0)
4760 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4762 /* Fill in the entries. */
4764 parms.intoffset = 0;
4765 function_arg_record_value_2 (type, 0, &parms, false);
4766 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
4768 gcc_assert (parms.nregs == nregs);
4773 /* Used by function_arg and function_value to implement the conventions
4774 of the 64-bit ABI for passing and returning unions.
4775 Return an expression valid as a return value for the two macros
4776 FUNCTION_ARG and FUNCTION_VALUE.
4778 SIZE is the size in bytes of the union.
4779 MODE is the argument's machine mode.
4780 REGNO is the hard register the union will be passed in. */
4783 function_arg_union_value (int size, enum machine_mode mode, int slotno,
4786 int nwords = ROUND_ADVANCE (size), i;
4789 /* See comment in previous function for empty structures. */
4791 return gen_rtx_REG (mode, regno);
4793 if (slotno == SPARC_INT_ARG_MAX - 1)
4796 regs = gen_rtx_PARALLEL (mode, rtvec_alloc (nwords));
4798 for (i = 0; i < nwords; i++)
4800 /* Unions are passed left-justified. */
4801 XVECEXP (regs, 0, i)
4802 = gen_rtx_EXPR_LIST (VOIDmode,
4803 gen_rtx_REG (word_mode, regno),
4804 GEN_INT (UNITS_PER_WORD * i));
4811 /* Used by function_arg and function_value to implement the conventions
4812 for passing and returning large (BLKmode) vectors.
4813 Return an expression valid as a return value for the two macros
4814 FUNCTION_ARG and FUNCTION_VALUE.
4816 SIZE is the size in bytes of the vector.
4817 BASE_MODE is the argument's base machine mode.
4818 REGNO is the FP hard register the vector will be passed in. */
4821 function_arg_vector_value (int size, enum machine_mode base_mode, int regno)
4823 unsigned short base_mode_size = GET_MODE_SIZE (base_mode);
4824 int nregs = size / base_mode_size, i;
4827 regs = gen_rtx_PARALLEL (BLKmode, rtvec_alloc (nregs));
4829 for (i = 0; i < nregs; i++)
4831 XVECEXP (regs, 0, i)
4832 = gen_rtx_EXPR_LIST (VOIDmode,
4833 gen_rtx_REG (base_mode, regno),
4834 GEN_INT (base_mode_size * i));
4835 regno += base_mode_size / 4;
4841 /* Handle the FUNCTION_ARG macro.
4842 Determine where to put an argument to a function.
4843 Value is zero to push the argument on the stack,
4844 or a hard register in which to store the argument.
4846 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4847 the preceding args and about the function being called.
4848 MODE is the argument's machine mode.
4849 TYPE is the data type of the argument (as a tree).
4850 This is null for libcalls where that information may
4852 NAMED is nonzero if this argument is a named parameter
4853 (otherwise it is an extra parameter matching an ellipsis).
4854 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
4857 function_arg (const struct sparc_args *cum, enum machine_mode mode,
4858 tree type, int named, int incoming_p)
4860 int regbase = (incoming_p
4861 ? SPARC_INCOMING_INT_ARG_FIRST
4862 : SPARC_OUTGOING_INT_ARG_FIRST);
4863 int slotno, regno, padding;
4864 enum mode_class mclass = GET_MODE_CLASS (mode);
4867 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
4875 reg = gen_rtx_REG (mode, regno);
4879 if (type && TREE_CODE (type) == RECORD_TYPE)
4881 /* Structures up to 16 bytes in size are passed in arg slots on the
4882 stack and are promoted to registers where possible. */
4884 gcc_assert (int_size_in_bytes (type) <= 16);
4886 return function_arg_record_value (type, mode, slotno, named, regbase);
4888 else if (type && TREE_CODE (type) == UNION_TYPE)
4890 HOST_WIDE_INT size = int_size_in_bytes (type);
4892 gcc_assert (size <= 16);
4894 return function_arg_union_value (size, mode, slotno, regno);
4896 else if (type && TREE_CODE (type) == VECTOR_TYPE)
4898 /* Vector types deserve special treatment because they are
4899 polymorphic wrt their mode, depending upon whether VIS
4900 instructions are enabled. */
4901 HOST_WIDE_INT size = int_size_in_bytes (type);
4903 gcc_assert (size <= 16);
4905 if (mode == BLKmode)
4906 return function_arg_vector_value (size,
4907 TYPE_MODE (TREE_TYPE (type)),
4908 SPARC_FP_ARG_FIRST + 2*slotno);
4910 mclass = MODE_FLOAT;
4913 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
4914 but also have the slot allocated for them.
4915 If no prototype is in scope fp values in register slots get passed
4916 in two places, either fp regs and int regs or fp regs and memory. */
4917 if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
4918 && SPARC_FP_REG_P (regno))
4920 reg = gen_rtx_REG (mode, regno);
4921 if (cum->prototype_p || cum->libcall_p)
4923 /* "* 2" because fp reg numbers are recorded in 4 byte
4926 /* ??? This will cause the value to be passed in the fp reg and
4927 in the stack. When a prototype exists we want to pass the
4928 value in the reg but reserve space on the stack. That's an
4929 optimization, and is deferred [for a bit]. */
4930 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
4931 return gen_rtx_PARALLEL (mode,
4933 gen_rtx_EXPR_LIST (VOIDmode,
4934 NULL_RTX, const0_rtx),
4935 gen_rtx_EXPR_LIST (VOIDmode,
4939 /* ??? It seems that passing back a register even when past
4940 the area declared by REG_PARM_STACK_SPACE will allocate
4941 space appropriately, and will not copy the data onto the
4942 stack, exactly as we desire.
4944 This is due to locate_and_pad_parm being called in
4945 expand_call whenever reg_parm_stack_space > 0, which
4946 while beneficial to our example here, would seem to be
4947 in error from what had been intended. Ho hum... -- r~ */
4955 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
4959 /* On incoming, we don't need to know that the value
4960 is passed in %f0 and %i0, and it confuses other parts
4961 causing needless spillage even on the simplest cases. */
4965 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
4966 + (regno - SPARC_FP_ARG_FIRST) / 2);
4968 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4969 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
4971 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4975 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4976 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4977 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4983 /* Scalar or complex int. */
4984 reg = gen_rtx_REG (mode, regno);
4990 /* For an arg passed partly in registers and partly in memory,
4991 this is the number of bytes of registers used.
4992 For args passed entirely in registers or entirely in memory, zero.
4994 Any arg that starts in the first 6 regs but won't entirely fit in them
4995 needs partial registers on v8. On v9, structures with integer
4996 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
4997 values that begin in the last fp reg [where "last fp reg" varies with the
4998 mode] will be split between that reg and memory. */
5001 sparc_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5002 tree type, bool named)
5004 int slotno, regno, padding;
5006 /* We pass 0 for incoming_p here, it doesn't matter. */
5007 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5014 if ((slotno + (mode == BLKmode
5015 ? ROUND_ADVANCE (int_size_in_bytes (type))
5016 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
5017 > SPARC_INT_ARG_MAX)
5018 return (SPARC_INT_ARG_MAX - slotno) * UNITS_PER_WORD;
5022 /* We are guaranteed by pass_by_reference that the size of the
5023 argument is not greater than 16 bytes, so we only need to return
5024 one word if the argument is partially passed in registers. */
5026 if (type && AGGREGATE_TYPE_P (type))
5028 int size = int_size_in_bytes (type);
5030 if (size > UNITS_PER_WORD
5031 && slotno == SPARC_INT_ARG_MAX - 1)
5032 return UNITS_PER_WORD;
5034 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
5035 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5036 && ! (TARGET_FPU && named)))
5038 /* The complex types are passed as packed types. */
5039 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
5040 && slotno == SPARC_INT_ARG_MAX - 1)
5041 return UNITS_PER_WORD;
5043 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
5045 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
5047 return UNITS_PER_WORD;
5054 /* Handle the TARGET_PASS_BY_REFERENCE target hook.
5055 Specify whether to pass the argument by reference. */
5058 sparc_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5059 enum machine_mode mode, tree type,
5060 bool named ATTRIBUTE_UNUSED)
5064 /* Original SPARC 32-bit ABI says that structures and unions,
5065 and quad-precision floats are passed by reference. For Pascal,
5066 also pass arrays by reference. All other base types are passed
5069 Extended ABI (as implemented by the Sun compiler) says that all
5070 complex floats are passed by reference. Pass complex integers
5071 in registers up to 8 bytes. More generally, enforce the 2-word
5072 cap for passing arguments in registers.
5074 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5075 integers are passed like floats of the same size, that is in
5076 registers up to 8 bytes. Pass all vector floats by reference
5077 like structure and unions. */
5078 return ((type && (AGGREGATE_TYPE_P (type) || VECTOR_FLOAT_TYPE_P (type)))
5080 /* Catch CDImode, TFmode, DCmode and TCmode. */
5081 || GET_MODE_SIZE (mode) > 8
5083 && TREE_CODE (type) == VECTOR_TYPE
5084 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
5088 /* Original SPARC 64-bit ABI says that structures and unions
5089 smaller than 16 bytes are passed in registers, as well as
5090 all other base types. For Pascal, pass arrays by reference.
5092 Extended ABI (as implemented by the Sun compiler) says that
5093 complex floats are passed in registers up to 16 bytes. Pass
5094 all complex integers in registers up to 16 bytes. More generally,
5095 enforce the 2-word cap for passing arguments in registers.
5097 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5098 integers are passed like floats of the same size, that is in
5099 registers (up to 16 bytes). Pass all vector floats like structure
5101 return ((type && TREE_CODE (type) == ARRAY_TYPE)
5103 && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == VECTOR_TYPE)
5104 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16)
5105 /* Catch CTImode and TCmode. */
5106 || GET_MODE_SIZE (mode) > 16);
5110 /* Handle the FUNCTION_ARG_ADVANCE macro.
5111 Update the data in CUM to advance over an argument
5112 of mode MODE and data type TYPE.
5113 TYPE is null for libcalls where that information may not be available. */
5116 function_arg_advance (struct sparc_args *cum, enum machine_mode mode,
5117 tree type, int named)
5119 int slotno, regno, padding;
5121 /* We pass 0 for incoming_p here, it doesn't matter. */
5122 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5124 /* If register required leading padding, add it. */
5126 cum->words += padding;
5130 cum->words += (mode != BLKmode
5131 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5132 : ROUND_ADVANCE (int_size_in_bytes (type)));
5136 if (type && AGGREGATE_TYPE_P (type))
5138 int size = int_size_in_bytes (type);
5142 else if (size <= 16)
5144 else /* passed by reference */
5149 cum->words += (mode != BLKmode
5150 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5151 : ROUND_ADVANCE (int_size_in_bytes (type)));
5156 /* Handle the FUNCTION_ARG_PADDING macro.
5157 For the 64 bit ABI structs are always stored left shifted in their
5161 function_arg_padding (enum machine_mode mode, tree type)
5163 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
5166 /* Fall back to the default. */
5167 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
5170 /* Handle the TARGET_RETURN_IN_MEMORY target hook.
5171 Specify whether to return the return value in memory. */
5174 sparc_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
5177 /* Original SPARC 32-bit ABI says that structures and unions,
5178 and quad-precision floats are returned in memory. All other
5179 base types are returned in registers.
5181 Extended ABI (as implemented by the Sun compiler) says that
5182 all complex floats are returned in registers (8 FP registers
5183 at most for '_Complex long double'). Return all complex integers
5184 in registers (4 at most for '_Complex long long').
5186 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5187 integers are returned like floats of the same size, that is in
5188 registers up to 8 bytes and in memory otherwise. Return all
5189 vector floats in memory like structure and unions; note that
5190 they always have BLKmode like the latter. */
5191 return (TYPE_MODE (type) == BLKmode
5192 || TYPE_MODE (type) == TFmode
5193 || (TREE_CODE (type) == VECTOR_TYPE
5194 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
5196 /* Original SPARC 64-bit ABI says that structures and unions
5197 smaller than 32 bytes are returned in registers, as well as
5198 all other base types.
5200 Extended ABI (as implemented by the Sun compiler) says that all
5201 complex floats are returned in registers (8 FP registers at most
5202 for '_Complex long double'). Return all complex integers in
5203 registers (4 at most for '_Complex TItype').
5205 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5206 integers are returned like floats of the same size, that is in
5207 registers. Return all vector floats like structure and unions;
5208 note that they always have BLKmode like the latter. */
5209 return ((TYPE_MODE (type) == BLKmode
5210 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 32));
5213 /* Handle the TARGET_STRUCT_VALUE target hook.
5214 Return where to find the structure return value address. */
5217 sparc_struct_value_rtx (tree fndecl ATTRIBUTE_UNUSED, int incoming)
5226 mem = gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx,
5227 STRUCT_VALUE_OFFSET));
5229 mem = gen_rtx_MEM (Pmode, plus_constant (stack_pointer_rtx,
5230 STRUCT_VALUE_OFFSET));
5232 set_mem_alias_set (mem, struct_value_alias_set);
5237 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
5238 For v9, function return values are subject to the same rules as arguments,
5239 except that up to 32 bytes may be returned in registers. */
5242 function_value (tree type, enum machine_mode mode, int incoming_p)
5244 /* Beware that the two values are swapped here wrt function_arg. */
5245 int regbase = (incoming_p
5246 ? SPARC_OUTGOING_INT_ARG_FIRST
5247 : SPARC_INCOMING_INT_ARG_FIRST);
5248 enum mode_class mclass = GET_MODE_CLASS (mode);
5251 if (type && TREE_CODE (type) == VECTOR_TYPE)
5253 /* Vector types deserve special treatment because they are
5254 polymorphic wrt their mode, depending upon whether VIS
5255 instructions are enabled. */
5256 HOST_WIDE_INT size = int_size_in_bytes (type);
5258 gcc_assert ((TARGET_ARCH32 && size <= 8)
5259 || (TARGET_ARCH64 && size <= 32));
5261 if (mode == BLKmode)
5262 return function_arg_vector_value (size,
5263 TYPE_MODE (TREE_TYPE (type)),
5264 SPARC_FP_ARG_FIRST);
5266 mclass = MODE_FLOAT;
5268 else if (type && TARGET_ARCH64)
5270 if (TREE_CODE (type) == RECORD_TYPE)
5272 /* Structures up to 32 bytes in size are passed in registers,
5273 promoted to fp registers where possible. */
5275 gcc_assert (int_size_in_bytes (type) <= 32);
5277 return function_arg_record_value (type, mode, 0, 1, regbase);
5279 else if (TREE_CODE (type) == UNION_TYPE)
5281 HOST_WIDE_INT size = int_size_in_bytes (type);
5283 gcc_assert (size <= 32);
5285 return function_arg_union_value (size, mode, 0, regbase);
5287 else if (AGGREGATE_TYPE_P (type))
5289 /* All other aggregate types are passed in an integer register
5290 in a mode corresponding to the size of the type. */
5291 HOST_WIDE_INT bytes = int_size_in_bytes (type);
5293 gcc_assert (bytes <= 32);
5295 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
5297 /* ??? We probably should have made the same ABI change in
5298 3.4.0 as the one we made for unions. The latter was
5299 required by the SCD though, while the former is not
5300 specified, so we favored compatibility and efficiency.
5302 Now we're stuck for aggregates larger than 16 bytes,
5303 because OImode vanished in the meantime. Let's not
5304 try to be unduly clever, and simply follow the ABI
5305 for unions in that case. */
5306 if (mode == BLKmode)
5307 return function_arg_union_value (bytes, mode, 0, regbase);
5311 else if (mclass == MODE_INT
5312 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
5316 if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
5318 regno = SPARC_FP_ARG_FIRST;
5322 return gen_rtx_REG (mode, regno);
5325 /* Do what is necessary for `va_start'. We look at the current function
5326 to determine if stdarg or varargs is used and return the address of
5327 the first unnamed parameter. */
5330 sparc_builtin_saveregs (void)
5332 int first_reg = current_function_args_info.words;
5336 for (regno = first_reg; regno < SPARC_INT_ARG_MAX; regno++)
5337 emit_move_insn (gen_rtx_MEM (word_mode,
5338 gen_rtx_PLUS (Pmode,
5340 GEN_INT (FIRST_PARM_OFFSET (0)
5343 gen_rtx_REG (word_mode,
5344 SPARC_INCOMING_INT_ARG_FIRST + regno));
5346 address = gen_rtx_PLUS (Pmode,
5348 GEN_INT (FIRST_PARM_OFFSET (0)
5349 + UNITS_PER_WORD * first_reg));
5354 /* Implement `va_start' for stdarg. */
5357 sparc_va_start (tree valist, rtx nextarg)
5359 nextarg = expand_builtin_saveregs ();
5360 std_expand_builtin_va_start (valist, nextarg);
5363 /* Implement `va_arg' for stdarg. */
5366 sparc_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
5368 HOST_WIDE_INT size, rsize, align;
5371 tree ptrtype = build_pointer_type (type);
5373 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
5376 size = rsize = UNITS_PER_WORD;
5382 size = int_size_in_bytes (type);
5383 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
5388 /* For SPARC64, objects requiring 16-byte alignment get it. */
5389 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
5390 align = 2 * UNITS_PER_WORD;
5392 /* SPARC-V9 ABI states that structures up to 16 bytes in size
5393 are left-justified in their slots. */
5394 if (AGGREGATE_TYPE_P (type))
5397 size = rsize = UNITS_PER_WORD;
5407 incr = fold (build2 (PLUS_EXPR, ptr_type_node, incr,
5408 ssize_int (align - 1)));
5409 incr = fold (build2 (BIT_AND_EXPR, ptr_type_node, incr,
5410 ssize_int (-align)));
5413 gimplify_expr (&incr, pre_p, post_p, is_gimple_val, fb_rvalue);
5416 if (BYTES_BIG_ENDIAN && size < rsize)
5417 addr = fold (build2 (PLUS_EXPR, ptr_type_node, incr,
5418 ssize_int (rsize - size)));
5422 addr = fold_convert (build_pointer_type (ptrtype), addr);
5423 addr = build_va_arg_indirect_ref (addr);
5425 /* If the address isn't aligned properly for the type,
5426 we may need to copy to a temporary.
5427 FIXME: This is inefficient. Usually we can do this
5430 && TYPE_ALIGN (type) > BITS_PER_WORD)
5432 tree tmp = create_tmp_var (type, "va_arg_tmp");
5433 tree dest_addr = build_fold_addr_expr (tmp);
5435 tree copy = build_function_call_expr
5436 (implicit_built_in_decls[BUILT_IN_MEMCPY],
5437 tree_cons (NULL_TREE, dest_addr,
5438 tree_cons (NULL_TREE, addr,
5439 tree_cons (NULL_TREE, size_int (rsize),
5442 gimplify_and_add (copy, pre_p);
5446 addr = fold_convert (ptrtype, addr);
5448 incr = fold (build2 (PLUS_EXPR, ptr_type_node, incr, ssize_int (rsize)));
5449 incr = build2 (MODIFY_EXPR, ptr_type_node, valist, incr);
5450 gimplify_and_add (incr, post_p);
5452 return build_va_arg_indirect_ref (addr);
5455 /* Implement the TARGET_VECTOR_MODE_SUPPORTED_P target hook.
5456 Specify whether the vector mode is supported by the hardware. */
5459 sparc_vector_mode_supported_p (enum machine_mode mode)
5461 return TARGET_VIS && VECTOR_MODE_P (mode) ? true : false;
5464 /* Return the string to output an unconditional branch to LABEL, which is
5465 the operand number of the label.
5467 DEST is the destination insn (i.e. the label), INSN is the source. */
5470 output_ubranch (rtx dest, int label, rtx insn)
5472 static char string[64];
5473 bool v9_form = false;
5476 if (TARGET_V9 && INSN_ADDRESSES_SET_P ())
5478 int delta = (INSN_ADDRESSES (INSN_UID (dest))
5479 - INSN_ADDRESSES (INSN_UID (insn)));
5480 /* Leave some instructions for "slop". */
5481 if (delta >= -260000 && delta < 260000)
5486 strcpy (string, "ba%*,pt\t%%xcc, ");
5488 strcpy (string, "b%*\t");
5490 p = strchr (string, '\0');
5501 /* Return the string to output a conditional branch to LABEL, which is
5502 the operand number of the label. OP is the conditional expression.
5503 XEXP (OP, 0) is assumed to be a condition code register (integer or
5504 floating point) and its mode specifies what kind of comparison we made.
5506 DEST is the destination insn (i.e. the label), INSN is the source.
5508 REVERSED is nonzero if we should reverse the sense of the comparison.
5510 ANNUL is nonzero if we should generate an annulling branch. */
5513 output_cbranch (rtx op, rtx dest, int label, int reversed, int annul,
5516 static char string[64];
5517 enum rtx_code code = GET_CODE (op);
5518 rtx cc_reg = XEXP (op, 0);
5519 enum machine_mode mode = GET_MODE (cc_reg);
5520 const char *labelno, *branch;
5521 int spaces = 8, far;
5524 /* v9 branches are limited to +-1MB. If it is too far away,
5537 fbne,a,pn %fcc2, .LC29
5545 far = TARGET_V9 && (get_attr_length (insn) >= 3);
5548 /* Reversal of FP compares takes care -- an ordered compare
5549 becomes an unordered compare and vice versa. */
5550 if (mode == CCFPmode || mode == CCFPEmode)
5551 code = reverse_condition_maybe_unordered (code);
5553 code = reverse_condition (code);
5556 /* Start by writing the branch condition. */
5557 if (mode == CCFPmode || mode == CCFPEmode)
5608 /* ??? !v9: FP branches cannot be preceded by another floating point
5609 insn. Because there is currently no concept of pre-delay slots,
5610 we can fix this only by always emitting a nop before a floating
5615 strcpy (string, "nop\n\t");
5616 strcat (string, branch);
5629 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5641 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5662 strcpy (string, branch);
5664 spaces -= strlen (branch);
5665 p = strchr (string, '\0');
5667 /* Now add the annulling, the label, and a possible noop. */
5680 if (! far && insn && INSN_ADDRESSES_SET_P ())
5682 int delta = (INSN_ADDRESSES (INSN_UID (dest))
5683 - INSN_ADDRESSES (INSN_UID (insn)));
5684 /* Leave some instructions for "slop". */
5685 if (delta < -260000 || delta >= 260000)
5689 if (mode == CCFPmode || mode == CCFPEmode)
5691 static char v9_fcc_labelno[] = "%%fccX, ";
5692 /* Set the char indicating the number of the fcc reg to use. */
5693 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
5694 labelno = v9_fcc_labelno;
5697 gcc_assert (REGNO (cc_reg) == SPARC_FCC_REG);
5701 else if (mode == CCXmode || mode == CCX_NOOVmode)
5703 labelno = "%%xcc, ";
5708 labelno = "%%icc, ";
5713 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
5716 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
5729 strcpy (p, labelno);
5730 p = strchr (p, '\0');
5733 strcpy (p, ".+12\n\t nop\n\tb\t");
5734 /* Skip the next insn if requested or
5735 if we know that it will be a nop. */
5736 if (annul || ! final_sequence)
5750 /* Emit a library call comparison between floating point X and Y.
5751 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
5752 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
5753 values as arguments instead of the TFmode registers themselves,
5754 that's why we cannot call emit_float_lib_cmp. */
5756 sparc_emit_float_lib_cmp (rtx x, rtx y, enum rtx_code comparison)
5759 rtx slot0, slot1, result, tem, tem2;
5760 enum machine_mode mode;
5765 qpfunc = (TARGET_ARCH64) ? "_Qp_feq" : "_Q_feq";
5769 qpfunc = (TARGET_ARCH64) ? "_Qp_fne" : "_Q_fne";
5773 qpfunc = (TARGET_ARCH64) ? "_Qp_fgt" : "_Q_fgt";
5777 qpfunc = (TARGET_ARCH64) ? "_Qp_fge" : "_Q_fge";
5781 qpfunc = (TARGET_ARCH64) ? "_Qp_flt" : "_Q_flt";
5785 qpfunc = (TARGET_ARCH64) ? "_Qp_fle" : "_Q_fle";
5796 qpfunc = (TARGET_ARCH64) ? "_Qp_cmp" : "_Q_cmp";
5805 if (GET_CODE (x) != MEM)
5807 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5808 emit_insn (gen_rtx_SET (VOIDmode, slot0, x));
5813 if (GET_CODE (y) != MEM)
5815 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5816 emit_insn (gen_rtx_SET (VOIDmode, slot1, y));
5821 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
5823 XEXP (slot0, 0), Pmode,
5824 XEXP (slot1, 0), Pmode);
5830 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
5832 x, TFmode, y, TFmode);
5838 /* Immediately move the result of the libcall into a pseudo
5839 register so reload doesn't clobber the value if it needs
5840 the return register for a spill reg. */
5841 result = gen_reg_rtx (mode);
5842 emit_move_insn (result, hard_libcall_value (mode));
5847 emit_cmp_insn (result, const0_rtx, NE, NULL_RTX, mode, 0);
5851 emit_cmp_insn (result, GEN_INT(3), comparison == UNORDERED ? EQ : NE,
5856 emit_cmp_insn (result, const1_rtx,
5857 comparison == UNGT ? GT : NE, NULL_RTX, mode, 0);
5860 emit_cmp_insn (result, const2_rtx, NE, NULL_RTX, mode, 0);
5863 tem = gen_reg_rtx (mode);
5865 emit_insn (gen_andsi3 (tem, result, const1_rtx));
5867 emit_insn (gen_anddi3 (tem, result, const1_rtx));
5868 emit_cmp_insn (tem, const0_rtx, NE, NULL_RTX, mode, 0);
5872 tem = gen_reg_rtx (mode);
5874 emit_insn (gen_addsi3 (tem, result, const1_rtx));
5876 emit_insn (gen_adddi3 (tem, result, const1_rtx));
5877 tem2 = gen_reg_rtx (mode);
5879 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
5881 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
5882 emit_cmp_insn (tem2, const0_rtx, comparison == UNEQ ? EQ : NE,
5888 /* Generate an unsigned DImode to FP conversion. This is the same code
5889 optabs would emit if we didn't have TFmode patterns. */
5892 sparc_emit_floatunsdi (rtx *operands, enum machine_mode mode)
5894 rtx neglab, donelab, i0, i1, f0, in, out;
5897 in = force_reg (DImode, operands[1]);
5898 neglab = gen_label_rtx ();
5899 donelab = gen_label_rtx ();
5900 i0 = gen_reg_rtx (DImode);
5901 i1 = gen_reg_rtx (DImode);
5902 f0 = gen_reg_rtx (mode);
5904 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
5906 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
5907 emit_jump_insn (gen_jump (donelab));
5910 emit_label (neglab);
5912 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
5913 emit_insn (gen_anddi3 (i1, in, const1_rtx));
5914 emit_insn (gen_iordi3 (i0, i0, i1));
5915 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
5916 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
5918 emit_label (donelab);
5921 /* Generate an FP to unsigned DImode conversion. This is the same code
5922 optabs would emit if we didn't have TFmode patterns. */
5925 sparc_emit_fixunsdi (rtx *operands, enum machine_mode mode)
5927 rtx neglab, donelab, i0, i1, f0, in, out, limit;
5930 in = force_reg (mode, operands[1]);
5931 neglab = gen_label_rtx ();
5932 donelab = gen_label_rtx ();
5933 i0 = gen_reg_rtx (DImode);
5934 i1 = gen_reg_rtx (DImode);
5935 limit = gen_reg_rtx (mode);
5936 f0 = gen_reg_rtx (mode);
5938 emit_move_insn (limit,
5939 CONST_DOUBLE_FROM_REAL_VALUE (
5940 REAL_VALUE_ATOF ("9223372036854775808.0", mode), mode));
5941 emit_cmp_and_jump_insns (in, limit, GE, NULL_RTX, mode, 0, neglab);
5943 emit_insn (gen_rtx_SET (VOIDmode,
5945 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, in))));
5946 emit_jump_insn (gen_jump (donelab));
5949 emit_label (neglab);
5951 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_MINUS (mode, in, limit)));
5952 emit_insn (gen_rtx_SET (VOIDmode,
5954 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, f0))));
5955 emit_insn (gen_movdi (i1, const1_rtx));
5956 emit_insn (gen_ashldi3 (i1, i1, GEN_INT (63)));
5957 emit_insn (gen_xordi3 (out, i0, i1));
5959 emit_label (donelab);
5962 /* Return the string to output a conditional branch to LABEL, testing
5963 register REG. LABEL is the operand number of the label; REG is the
5964 operand number of the reg. OP is the conditional expression. The mode
5965 of REG says what kind of comparison we made.
5967 DEST is the destination insn (i.e. the label), INSN is the source.
5969 REVERSED is nonzero if we should reverse the sense of the comparison.
5971 ANNUL is nonzero if we should generate an annulling branch. */
5974 output_v9branch (rtx op, rtx dest, int reg, int label, int reversed,
5975 int annul, rtx insn)
5977 static char string[64];
5978 enum rtx_code code = GET_CODE (op);
5979 enum machine_mode mode = GET_MODE (XEXP (op, 0));
5984 /* branch on register are limited to +-128KB. If it is too far away,
5997 brgez,a,pn %o1, .LC29
6003 ba,pt %xcc, .LC29 */
6005 far = get_attr_length (insn) >= 3;
6007 /* If not floating-point or if EQ or NE, we can just reverse the code. */
6009 code = reverse_condition (code);
6011 /* Only 64 bit versions of these instructions exist. */
6012 gcc_assert (mode == DImode);
6014 /* Start by writing the branch condition. */
6019 strcpy (string, "brnz");
6023 strcpy (string, "brz");
6027 strcpy (string, "brgez");
6031 strcpy (string, "brlz");
6035 strcpy (string, "brlez");
6039 strcpy (string, "brgz");
6046 p = strchr (string, '\0');
6048 /* Now add the annulling, reg, label, and nop. */
6055 if (insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
6058 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
6063 *p = p < string + 8 ? '\t' : ' ';
6071 int veryfar = 1, delta;
6073 if (INSN_ADDRESSES_SET_P ())
6075 delta = (INSN_ADDRESSES (INSN_UID (dest))
6076 - INSN_ADDRESSES (INSN_UID (insn)));
6077 /* Leave some instructions for "slop". */
6078 if (delta >= -260000 && delta < 260000)
6082 strcpy (p, ".+12\n\t nop\n\t");
6083 /* Skip the next insn if requested or
6084 if we know that it will be a nop. */
6085 if (annul || ! final_sequence)
6095 strcpy (p, "ba,pt\t%%xcc, ");
6109 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
6110 Such instructions cannot be used in the delay slot of return insn on v9.
6111 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
6115 epilogue_renumber (register rtx *where, int test)
6117 register const char *fmt;
6119 register enum rtx_code code;
6124 code = GET_CODE (*where);
6129 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
6131 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
6132 *where = gen_rtx_REG (GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
6140 /* Do not replace the frame pointer with the stack pointer because
6141 it can cause the delayed instruction to load below the stack.
6142 This occurs when instructions like:
6144 (set (reg/i:SI 24 %i0)
6145 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
6146 (const_int -20 [0xffffffec])) 0))
6148 are in the return delayed slot. */
6150 if (GET_CODE (XEXP (*where, 0)) == REG
6151 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
6152 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
6153 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
6158 if (SPARC_STACK_BIAS
6159 && GET_CODE (XEXP (*where, 0)) == REG
6160 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
6168 fmt = GET_RTX_FORMAT (code);
6170 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6175 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
6176 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
6179 else if (fmt[i] == 'e'
6180 && epilogue_renumber (&(XEXP (*where, i)), test))
6186 /* Leaf functions and non-leaf functions have different needs. */
6189 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
6192 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
6194 static const int *const reg_alloc_orders[] = {
6195 reg_leaf_alloc_order,
6196 reg_nonleaf_alloc_order};
6199 order_regs_for_local_alloc (void)
6201 static int last_order_nonleaf = 1;
6203 if (regs_ever_live[15] != last_order_nonleaf)
6205 last_order_nonleaf = !last_order_nonleaf;
6206 memcpy ((char *) reg_alloc_order,
6207 (const char *) reg_alloc_orders[last_order_nonleaf],
6208 FIRST_PSEUDO_REGISTER * sizeof (int));
6212 /* Return 1 if REG and MEM are legitimate enough to allow the various
6213 mem<-->reg splits to be run. */
6216 sparc_splitdi_legitimate (rtx reg, rtx mem)
6218 /* Punt if we are here by mistake. */
6219 gcc_assert (reload_completed);
6221 /* We must have an offsettable memory reference. */
6222 if (! offsettable_memref_p (mem))
6225 /* If we have legitimate args for ldd/std, we do not want
6226 the split to happen. */
6227 if ((REGNO (reg) % 2) == 0
6228 && mem_min_alignment (mem, 8))
6235 /* Return 1 if x and y are some kind of REG and they refer to
6236 different hard registers. This test is guaranteed to be
6237 run after reload. */
6240 sparc_absnegfloat_split_legitimate (rtx x, rtx y)
6242 if (GET_CODE (x) != REG)
6244 if (GET_CODE (y) != REG)
6246 if (REGNO (x) == REGNO (y))
6251 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
6252 This makes them candidates for using ldd and std insns.
6254 Note reg1 and reg2 *must* be hard registers. */
6257 registers_ok_for_ldd_peep (rtx reg1, rtx reg2)
6259 /* We might have been passed a SUBREG. */
6260 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
6263 if (REGNO (reg1) % 2 != 0)
6266 /* Integer ldd is deprecated in SPARC V9 */
6267 if (TARGET_V9 && REGNO (reg1) < 32)
6270 return (REGNO (reg1) == REGNO (reg2) - 1);
6273 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
6276 This can only happen when addr1 and addr2, the addresses in mem1
6277 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
6278 addr1 must also be aligned on a 64-bit boundary.
6280 Also iff dependent_reg_rtx is not null it should not be used to
6281 compute the address for mem1, i.e. we cannot optimize a sequence
6293 But, note that the transformation from:
6298 is perfectly fine. Thus, the peephole2 patterns always pass us
6299 the destination register of the first load, never the second one.
6301 For stores we don't have a similar problem, so dependent_reg_rtx is
6305 mems_ok_for_ldd_peep (rtx mem1, rtx mem2, rtx dependent_reg_rtx)
6309 HOST_WIDE_INT offset1;
6311 /* The mems cannot be volatile. */
6312 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
6315 /* MEM1 should be aligned on a 64-bit boundary. */
6316 if (MEM_ALIGN (mem1) < 64)
6319 addr1 = XEXP (mem1, 0);
6320 addr2 = XEXP (mem2, 0);
6322 /* Extract a register number and offset (if used) from the first addr. */
6323 if (GET_CODE (addr1) == PLUS)
6325 /* If not a REG, return zero. */
6326 if (GET_CODE (XEXP (addr1, 0)) != REG)
6330 reg1 = REGNO (XEXP (addr1, 0));
6331 /* The offset must be constant! */
6332 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
6334 offset1 = INTVAL (XEXP (addr1, 1));
6337 else if (GET_CODE (addr1) != REG)
6341 reg1 = REGNO (addr1);
6342 /* This was a simple (mem (reg)) expression. Offset is 0. */
6346 /* Make sure the second address is a (mem (plus (reg) (const_int). */
6347 if (GET_CODE (addr2) != PLUS)
6350 if (GET_CODE (XEXP (addr2, 0)) != REG
6351 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
6354 if (reg1 != REGNO (XEXP (addr2, 0)))
6357 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
6360 /* The first offset must be evenly divisible by 8 to ensure the
6361 address is 64 bit aligned. */
6362 if (offset1 % 8 != 0)
6365 /* The offset for the second addr must be 4 more than the first addr. */
6366 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
6369 /* All the tests passed. addr1 and addr2 are valid for ldd and std
6374 /* Return 1 if reg is a pseudo, or is the first register in
6375 a hard register pair. This makes it a candidate for use in
6376 ldd and std insns. */
6379 register_ok_for_ldd (rtx reg)
6381 /* We might have been passed a SUBREG. */
6382 if (GET_CODE (reg) != REG)
6385 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
6386 return (REGNO (reg) % 2 == 0);
6391 /* Print operand X (an rtx) in assembler syntax to file FILE.
6392 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
6393 For `%' followed by punctuation, CODE is the punctuation and X is null. */
6396 print_operand (FILE *file, rtx x, int code)
6401 /* Output an insn in a delay slot. */
6403 sparc_indent_opcode = 1;
6405 fputs ("\n\t nop", file);
6408 /* Output an annul flag if there's nothing for the delay slot and we
6409 are optimizing. This is always used with '(' below.
6410 Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
6411 this is a dbx bug. So, we only do this when optimizing.
6412 On UltraSPARC, a branch in a delay slot causes a pipeline flush.
6413 Always emit a nop in case the next instruction is a branch. */
6414 if (! final_sequence && (optimize && (int)sparc_cpu < PROCESSOR_V9))
6418 /* Output a 'nop' if there's nothing for the delay slot and we are
6419 not optimizing. This is always used with '*' above. */
6420 if (! final_sequence && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
6421 fputs ("\n\t nop", file);
6422 else if (final_sequence)
6423 sparc_indent_opcode = 1;
6426 /* Output the right displacement from the saved PC on function return.
6427 The caller may have placed an "unimp" insn immediately after the call
6428 so we have to account for it. This insn is used in the 32-bit ABI
6429 when calling a function that returns a non zero-sized structure. The
6430 64-bit ABI doesn't have it. Be careful to have this test be the same
6431 as that used on the call. */
6433 && current_function_returns_struct
6434 && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl)))
6436 && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))))
6442 /* Output the Embedded Medium/Anywhere code model base register. */
6443 fputs (EMBMEDANY_BASE_REG, file);
6446 /* Print some local dynamic TLS name. */
6447 assemble_name (file, get_some_local_dynamic_name ());
6451 /* Adjust the operand to take into account a RESTORE operation. */
6452 if (GET_CODE (x) == CONST_INT)
6454 else if (GET_CODE (x) != REG)
6455 output_operand_lossage ("invalid %%Y operand");
6456 else if (REGNO (x) < 8)
6457 fputs (reg_names[REGNO (x)], file);
6458 else if (REGNO (x) >= 24 && REGNO (x) < 32)
6459 fputs (reg_names[REGNO (x)-16], file);
6461 output_operand_lossage ("invalid %%Y operand");
6464 /* Print out the low order register name of a register pair. */
6465 if (WORDS_BIG_ENDIAN)
6466 fputs (reg_names[REGNO (x)+1], file);
6468 fputs (reg_names[REGNO (x)], file);
6471 /* Print out the high order register name of a register pair. */
6472 if (WORDS_BIG_ENDIAN)
6473 fputs (reg_names[REGNO (x)], file);
6475 fputs (reg_names[REGNO (x)+1], file);
6478 /* Print out the second register name of a register pair or quad.
6479 I.e., R (%o0) => %o1. */
6480 fputs (reg_names[REGNO (x)+1], file);
6483 /* Print out the third register name of a register quad.
6484 I.e., S (%o0) => %o2. */
6485 fputs (reg_names[REGNO (x)+2], file);
6488 /* Print out the fourth register name of a register quad.
6489 I.e., T (%o0) => %o3. */
6490 fputs (reg_names[REGNO (x)+3], file);
6493 /* Print a condition code register. */
6494 if (REGNO (x) == SPARC_ICC_REG)
6496 /* We don't handle CC[X]_NOOVmode because they're not supposed
6498 if (GET_MODE (x) == CCmode)
6499 fputs ("%icc", file);
6500 else if (GET_MODE (x) == CCXmode)
6501 fputs ("%xcc", file);
6506 /* %fccN register */
6507 fputs (reg_names[REGNO (x)], file);
6510 /* Print the operand's address only. */
6511 output_address (XEXP (x, 0));
6514 /* In this case we need a register. Use %g0 if the
6515 operand is const0_rtx. */
6517 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
6519 fputs ("%g0", file);
6526 switch (GET_CODE (x))
6528 case IOR: fputs ("or", file); break;
6529 case AND: fputs ("and", file); break;
6530 case XOR: fputs ("xor", file); break;
6531 default: output_operand_lossage ("invalid %%A operand");
6536 switch (GET_CODE (x))
6538 case IOR: fputs ("orn", file); break;
6539 case AND: fputs ("andn", file); break;
6540 case XOR: fputs ("xnor", file); break;
6541 default: output_operand_lossage ("invalid %%B operand");
6545 /* These are used by the conditional move instructions. */
6549 enum rtx_code rc = GET_CODE (x);
6553 enum machine_mode mode = GET_MODE (XEXP (x, 0));
6554 if (mode == CCFPmode || mode == CCFPEmode)
6555 rc = reverse_condition_maybe_unordered (GET_CODE (x));
6557 rc = reverse_condition (GET_CODE (x));
6561 case NE: fputs ("ne", file); break;
6562 case EQ: fputs ("e", file); break;
6563 case GE: fputs ("ge", file); break;
6564 case GT: fputs ("g", file); break;
6565 case LE: fputs ("le", file); break;
6566 case LT: fputs ("l", file); break;
6567 case GEU: fputs ("geu", file); break;
6568 case GTU: fputs ("gu", file); break;
6569 case LEU: fputs ("leu", file); break;
6570 case LTU: fputs ("lu", file); break;
6571 case LTGT: fputs ("lg", file); break;
6572 case UNORDERED: fputs ("u", file); break;
6573 case ORDERED: fputs ("o", file); break;
6574 case UNLT: fputs ("ul", file); break;
6575 case UNLE: fputs ("ule", file); break;
6576 case UNGT: fputs ("ug", file); break;
6577 case UNGE: fputs ("uge", file); break;
6578 case UNEQ: fputs ("ue", file); break;
6579 default: output_operand_lossage (code == 'c'
6580 ? "invalid %%c operand"
6581 : "invalid %%C operand");
6586 /* These are used by the movr instruction pattern. */
6590 enum rtx_code rc = (code == 'd'
6591 ? reverse_condition (GET_CODE (x))
6595 case NE: fputs ("ne", file); break;
6596 case EQ: fputs ("e", file); break;
6597 case GE: fputs ("gez", file); break;
6598 case LT: fputs ("lz", file); break;
6599 case LE: fputs ("lez", file); break;
6600 case GT: fputs ("gz", file); break;
6601 default: output_operand_lossage (code == 'd'
6602 ? "invalid %%d operand"
6603 : "invalid %%D operand");
6610 /* Print a sign-extended character. */
6611 int i = trunc_int_for_mode (INTVAL (x), QImode);
6612 fprintf (file, "%d", i);
6617 /* Operand must be a MEM; write its address. */
6618 if (GET_CODE (x) != MEM)
6619 output_operand_lossage ("invalid %%f operand");
6620 output_address (XEXP (x, 0));
6625 /* Print a sign-extended 32-bit value. */
6627 if (GET_CODE(x) == CONST_INT)
6629 else if (GET_CODE(x) == CONST_DOUBLE)
6630 i = CONST_DOUBLE_LOW (x);
6633 output_operand_lossage ("invalid %%s operand");
6636 i = trunc_int_for_mode (i, SImode);
6637 fprintf (file, HOST_WIDE_INT_PRINT_DEC, i);
6642 /* Do nothing special. */
6646 /* Undocumented flag. */
6647 output_operand_lossage ("invalid operand output code");
6650 if (GET_CODE (x) == REG)
6651 fputs (reg_names[REGNO (x)], file);
6652 else if (GET_CODE (x) == MEM)
6655 /* Poor Sun assembler doesn't understand absolute addressing. */
6656 if (CONSTANT_P (XEXP (x, 0)))
6657 fputs ("%g0+", file);
6658 output_address (XEXP (x, 0));
6661 else if (GET_CODE (x) == HIGH)
6663 fputs ("%hi(", file);
6664 output_addr_const (file, XEXP (x, 0));
6667 else if (GET_CODE (x) == LO_SUM)
6669 print_operand (file, XEXP (x, 0), 0);
6670 if (TARGET_CM_MEDMID)
6671 fputs ("+%l44(", file);
6673 fputs ("+%lo(", file);
6674 output_addr_const (file, XEXP (x, 1));
6677 else if (GET_CODE (x) == CONST_DOUBLE
6678 && (GET_MODE (x) == VOIDmode
6679 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
6681 if (CONST_DOUBLE_HIGH (x) == 0)
6682 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
6683 else if (CONST_DOUBLE_HIGH (x) == -1
6684 && CONST_DOUBLE_LOW (x) < 0)
6685 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
6687 output_operand_lossage ("long long constant not a valid immediate operand");
6689 else if (GET_CODE (x) == CONST_DOUBLE)
6690 output_operand_lossage ("floating point constant not a valid immediate operand");
6691 else { output_addr_const (file, x); }
6694 /* Target hook for assembling integer objects. The sparc version has
6695 special handling for aligned DI-mode objects. */
6698 sparc_assemble_integer (rtx x, unsigned int size, int aligned_p)
6700 /* ??? We only output .xword's for symbols and only then in environments
6701 where the assembler can handle them. */
6702 if (aligned_p && size == 8
6703 && (GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE))
6707 assemble_integer_with_op ("\t.xword\t", x);
6712 assemble_aligned_integer (4, const0_rtx);
6713 assemble_aligned_integer (4, x);
6717 return default_assemble_integer (x, size, aligned_p);
6720 /* Return the value of a code used in the .proc pseudo-op that says
6721 what kind of result this function returns. For non-C types, we pick
6722 the closest C type. */
6724 #ifndef SHORT_TYPE_SIZE
6725 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
6728 #ifndef INT_TYPE_SIZE
6729 #define INT_TYPE_SIZE BITS_PER_WORD
6732 #ifndef LONG_TYPE_SIZE
6733 #define LONG_TYPE_SIZE BITS_PER_WORD
6736 #ifndef LONG_LONG_TYPE_SIZE
6737 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
6740 #ifndef FLOAT_TYPE_SIZE
6741 #define FLOAT_TYPE_SIZE BITS_PER_WORD
6744 #ifndef DOUBLE_TYPE_SIZE
6745 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6748 #ifndef LONG_DOUBLE_TYPE_SIZE
6749 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6753 sparc_type_code (register tree type)
6755 register unsigned long qualifiers = 0;
6756 register unsigned shift;
6758 /* Only the first 30 bits of the qualifier are valid. We must refrain from
6759 setting more, since some assemblers will give an error for this. Also,
6760 we must be careful to avoid shifts of 32 bits or more to avoid getting
6761 unpredictable results. */
6763 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
6765 switch (TREE_CODE (type))
6771 qualifiers |= (3 << shift);
6776 qualifiers |= (2 << shift);
6780 case REFERENCE_TYPE:
6782 qualifiers |= (1 << shift);
6786 return (qualifiers | 8);
6789 case QUAL_UNION_TYPE:
6790 return (qualifiers | 9);
6793 return (qualifiers | 10);
6796 return (qualifiers | 16);
6799 /* If this is a range type, consider it to be the underlying
6801 if (TREE_TYPE (type) != 0)
6804 /* Carefully distinguish all the standard types of C,
6805 without messing up if the language is not C. We do this by
6806 testing TYPE_PRECISION and TYPE_UNSIGNED. The old code used to
6807 look at both the names and the above fields, but that's redundant.
6808 Any type whose size is between two C types will be considered
6809 to be the wider of the two types. Also, we do not have a
6810 special code to use for "long long", so anything wider than
6811 long is treated the same. Note that we can't distinguish
6812 between "int" and "long" in this code if they are the same
6813 size, but that's fine, since neither can the assembler. */
6815 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
6816 return (qualifiers | (TYPE_UNSIGNED (type) ? 12 : 2));
6818 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
6819 return (qualifiers | (TYPE_UNSIGNED (type) ? 13 : 3));
6821 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
6822 return (qualifiers | (TYPE_UNSIGNED (type) ? 14 : 4));
6825 return (qualifiers | (TYPE_UNSIGNED (type) ? 15 : 5));
6828 /* If this is a range type, consider it to be the underlying
6830 if (TREE_TYPE (type) != 0)
6833 /* Carefully distinguish all the standard types of C,
6834 without messing up if the language is not C. */
6836 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
6837 return (qualifiers | 6);
6840 return (qualifiers | 7);
6842 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
6843 /* ??? We need to distinguish between double and float complex types,
6844 but I don't know how yet because I can't reach this code from
6845 existing front-ends. */
6846 return (qualifiers | 7); /* Who knows? */
6849 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
6850 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
6851 case LANG_TYPE: /* ? */
6855 gcc_unreachable (); /* Not a type! */
6862 /* Nested function support. */
6864 /* Emit RTL insns to initialize the variable parts of a trampoline.
6865 FNADDR is an RTX for the address of the function's pure code.
6866 CXT is an RTX for the static chain value for the function.
6868 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
6869 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
6870 (to store insns). This is a bit excessive. Perhaps a different
6871 mechanism would be better here.
6873 Emit enough FLUSH insns to synchronize the data and instruction caches. */
6876 sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
6878 /* SPARC 32-bit trampoline:
6881 sethi %hi(static), %g2
6883 or %g2, %lo(static), %g2
6885 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
6886 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
6890 (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
6891 expand_binop (SImode, ior_optab,
6892 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
6893 size_int (10), 0, 1),
6894 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
6895 NULL_RTX, 1, OPTAB_DIRECT));
6898 (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6899 expand_binop (SImode, ior_optab,
6900 expand_shift (RSHIFT_EXPR, SImode, cxt,
6901 size_int (10), 0, 1),
6902 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
6903 NULL_RTX, 1, OPTAB_DIRECT));
6906 (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6907 expand_binop (SImode, ior_optab,
6908 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
6909 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
6910 NULL_RTX, 1, OPTAB_DIRECT));
6913 (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6914 expand_binop (SImode, ior_optab,
6915 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
6916 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
6917 NULL_RTX, 1, OPTAB_DIRECT));
6919 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
6920 aligned on a 16 byte boundary so one flush clears it all. */
6921 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
6922 if (sparc_cpu != PROCESSOR_ULTRASPARC
6923 && sparc_cpu != PROCESSOR_ULTRASPARC3)
6924 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
6925 plus_constant (tramp, 8)))));
6927 /* Call __enable_execute_stack after writing onto the stack to make sure
6928 the stack address is accessible. */
6929 #ifdef ENABLE_EXECUTE_STACK
6930 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
6931 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
6936 /* The 64-bit version is simpler because it makes more sense to load the
6937 values as "immediate" data out of the trampoline. It's also easier since
6938 we can read the PC without clobbering a register. */
6941 sparc64_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
6943 /* SPARC 64-bit trampoline:
6952 emit_move_insn (gen_rtx_MEM (SImode, tramp),
6953 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
6954 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6955 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
6956 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6957 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
6958 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6959 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
6960 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
6961 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
6962 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
6964 if (sparc_cpu != PROCESSOR_ULTRASPARC
6965 && sparc_cpu != PROCESSOR_ULTRASPARC3)
6966 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
6968 /* Call __enable_execute_stack after writing onto the stack to make sure
6969 the stack address is accessible. */
6970 #ifdef ENABLE_EXECUTE_STACK
6971 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
6972 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
6976 /* Adjust the cost of a scheduling dependency. Return the new cost of
6977 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
6980 supersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
6982 enum attr_type insn_type;
6984 if (! recog_memoized (insn))
6987 insn_type = get_attr_type (insn);
6989 if (REG_NOTE_KIND (link) == 0)
6991 /* Data dependency; DEP_INSN writes a register that INSN reads some
6994 /* if a load, then the dependence must be on the memory address;
6995 add an extra "cycle". Note that the cost could be two cycles
6996 if the reg was written late in an instruction group; we ca not tell
6998 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
7001 /* Get the delay only if the address of the store is the dependence. */
7002 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
7004 rtx pat = PATTERN(insn);
7005 rtx dep_pat = PATTERN (dep_insn);
7007 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7008 return cost; /* This should not happen! */
7010 /* The dependency between the two instructions was on the data that
7011 is being stored. Assume that this implies that the address of the
7012 store is not dependent. */
7013 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7016 return cost + 3; /* An approximation. */
7019 /* A shift instruction cannot receive its data from an instruction
7020 in the same cycle; add a one cycle penalty. */
7021 if (insn_type == TYPE_SHIFT)
7022 return cost + 3; /* Split before cascade into shift. */
7026 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7027 INSN writes some cycles later. */
7029 /* These are only significant for the fpu unit; writing a fp reg before
7030 the fpu has finished with it stalls the processor. */
7032 /* Reusing an integer register causes no problems. */
7033 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7041 hypersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
7043 enum attr_type insn_type, dep_type;
7044 rtx pat = PATTERN(insn);
7045 rtx dep_pat = PATTERN (dep_insn);
7047 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7050 insn_type = get_attr_type (insn);
7051 dep_type = get_attr_type (dep_insn);
7053 switch (REG_NOTE_KIND (link))
7056 /* Data dependency; DEP_INSN writes a register that INSN reads some
7063 /* Get the delay iff the address of the store is the dependence. */
7064 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7067 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7074 /* If a load, then the dependence must be on the memory address. If
7075 the addresses aren't equal, then it might be a false dependency */
7076 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7078 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7079 || GET_CODE (SET_DEST (dep_pat)) != MEM
7080 || GET_CODE (SET_SRC (pat)) != MEM
7081 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
7082 XEXP (SET_SRC (pat), 0)))
7090 /* Compare to branch latency is 0. There is no benefit from
7091 separating compare and branch. */
7092 if (dep_type == TYPE_COMPARE)
7094 /* Floating point compare to branch latency is less than
7095 compare to conditional move. */
7096 if (dep_type == TYPE_FPCMP)
7105 /* Anti-dependencies only penalize the fpu unit. */
7106 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7118 sparc_adjust_cost(rtx insn, rtx link, rtx dep, int cost)
7122 case PROCESSOR_SUPERSPARC:
7123 cost = supersparc_adjust_cost (insn, link, dep, cost);
7125 case PROCESSOR_HYPERSPARC:
7126 case PROCESSOR_SPARCLITE86X:
7127 cost = hypersparc_adjust_cost (insn, link, dep, cost);
7136 sparc_sched_init (FILE *dump ATTRIBUTE_UNUSED,
7137 int sched_verbose ATTRIBUTE_UNUSED,
7138 int max_ready ATTRIBUTE_UNUSED)
7143 sparc_use_sched_lookahead (void)
7145 if (sparc_cpu == PROCESSOR_ULTRASPARC
7146 || sparc_cpu == PROCESSOR_ULTRASPARC3)
7148 if ((1 << sparc_cpu) &
7149 ((1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
7150 (1 << PROCESSOR_SPARCLITE86X)))
7156 sparc_issue_rate (void)
7163 /* Assume V9 processors are capable of at least dual-issue. */
7165 case PROCESSOR_SUPERSPARC:
7167 case PROCESSOR_HYPERSPARC:
7168 case PROCESSOR_SPARCLITE86X:
7170 case PROCESSOR_ULTRASPARC:
7171 case PROCESSOR_ULTRASPARC3:
7177 set_extends (rtx insn)
7179 register rtx pat = PATTERN (insn);
7181 switch (GET_CODE (SET_SRC (pat)))
7183 /* Load and some shift instructions zero extend. */
7186 /* sethi clears the high bits */
7188 /* LO_SUM is used with sethi. sethi cleared the high
7189 bits and the values used with lo_sum are positive */
7191 /* Store flag stores 0 or 1 */
7201 rtx op0 = XEXP (SET_SRC (pat), 0);
7202 rtx op1 = XEXP (SET_SRC (pat), 1);
7203 if (GET_CODE (op1) == CONST_INT)
7204 return INTVAL (op1) >= 0;
7205 if (GET_CODE (op0) != REG)
7207 if (sparc_check_64 (op0, insn) == 1)
7209 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7214 rtx op0 = XEXP (SET_SRC (pat), 0);
7215 rtx op1 = XEXP (SET_SRC (pat), 1);
7216 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
7218 if (GET_CODE (op1) == CONST_INT)
7219 return INTVAL (op1) >= 0;
7220 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7223 return GET_MODE (SET_SRC (pat)) == SImode;
7224 /* Positive integers leave the high bits zero. */
7226 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
7228 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
7231 return - (GET_MODE (SET_SRC (pat)) == SImode);
7233 return sparc_check_64 (SET_SRC (pat), insn);
7239 /* We _ought_ to have only one kind per function, but... */
7240 static GTY(()) rtx sparc_addr_diff_list;
7241 static GTY(()) rtx sparc_addr_list;
7244 sparc_defer_case_vector (rtx lab, rtx vec, int diff)
7246 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
7248 sparc_addr_diff_list
7249 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
7251 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
7255 sparc_output_addr_vec (rtx vec)
7257 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7258 int idx, vlen = XVECLEN (body, 0);
7260 #ifdef ASM_OUTPUT_ADDR_VEC_START
7261 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7264 #ifdef ASM_OUTPUT_CASE_LABEL
7265 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7268 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7271 for (idx = 0; idx < vlen; idx++)
7273 ASM_OUTPUT_ADDR_VEC_ELT
7274 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
7277 #ifdef ASM_OUTPUT_ADDR_VEC_END
7278 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7283 sparc_output_addr_diff_vec (rtx vec)
7285 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7286 rtx base = XEXP (XEXP (body, 0), 0);
7287 int idx, vlen = XVECLEN (body, 1);
7289 #ifdef ASM_OUTPUT_ADDR_VEC_START
7290 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7293 #ifdef ASM_OUTPUT_CASE_LABEL
7294 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7297 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7300 for (idx = 0; idx < vlen; idx++)
7302 ASM_OUTPUT_ADDR_DIFF_ELT
7305 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
7306 CODE_LABEL_NUMBER (base));
7309 #ifdef ASM_OUTPUT_ADDR_VEC_END
7310 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7315 sparc_output_deferred_case_vectors (void)
7320 if (sparc_addr_list == NULL_RTX
7321 && sparc_addr_diff_list == NULL_RTX)
7324 /* Align to cache line in the function's code section. */
7325 current_function_section (current_function_decl);
7327 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
7329 ASM_OUTPUT_ALIGN (asm_out_file, align);
7331 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
7332 sparc_output_addr_vec (XEXP (t, 0));
7333 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
7334 sparc_output_addr_diff_vec (XEXP (t, 0));
7336 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
7339 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
7340 unknown. Return 1 if the high bits are zero, -1 if the register is
7343 sparc_check_64 (rtx x, rtx insn)
7345 /* If a register is set only once it is safe to ignore insns this
7346 code does not know how to handle. The loop will either recognize
7347 the single set and return the correct value or fail to recognize
7352 gcc_assert (GET_CODE (x) == REG);
7354 if (GET_MODE (x) == DImode)
7355 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
7357 if (flag_expensive_optimizations
7358 && REG_N_SETS (REGNO (y)) == 1)
7364 insn = get_last_insn_anywhere ();
7369 while ((insn = PREV_INSN (insn)))
7371 switch (GET_CODE (insn))
7384 rtx pat = PATTERN (insn);
7385 if (GET_CODE (pat) != SET)
7387 if (rtx_equal_p (x, SET_DEST (pat)))
7388 return set_extends (insn);
7389 if (y && rtx_equal_p (y, SET_DEST (pat)))
7390 return set_extends (insn);
7391 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
7399 /* Returns assembly code to perform a DImode shift using
7400 a 64-bit global or out register on SPARC-V8+. */
7402 output_v8plus_shift (rtx *operands, rtx insn, const char *opcode)
7404 static char asm_code[60];
7406 /* The scratch register is only required when the destination
7407 register is not a 64-bit global or out register. */
7408 if (which_alternative != 2)
7409 operands[3] = operands[0];
7411 /* We can only shift by constants <= 63. */
7412 if (GET_CODE (operands[2]) == CONST_INT)
7413 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
7415 if (GET_CODE (operands[1]) == CONST_INT)
7417 output_asm_insn ("mov\t%1, %3", operands);
7421 output_asm_insn ("sllx\t%H1, 32, %3", operands);
7422 if (sparc_check_64 (operands[1], insn) <= 0)
7423 output_asm_insn ("srl\t%L1, 0, %L1", operands);
7424 output_asm_insn ("or\t%L1, %3, %3", operands);
7427 strcpy(asm_code, opcode);
7429 if (which_alternative != 2)
7430 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
7432 return strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
7435 /* Output rtl to increment the profiler label LABELNO
7436 for profiling a function entry. */
7439 sparc_profile_hook (int labelno)
7444 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
7445 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
7446 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
7448 emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lab, Pmode);
7451 #ifdef OBJECT_FORMAT_ELF
7453 sparc_elf_asm_named_section (const char *name, unsigned int flags,
7456 if (flags & SECTION_MERGE)
7458 /* entsize cannot be expressed in this section attributes
7460 default_elf_asm_named_section (name, flags, decl);
7464 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
7466 if (!(flags & SECTION_DEBUG))
7467 fputs (",#alloc", asm_out_file);
7468 if (flags & SECTION_WRITE)
7469 fputs (",#write", asm_out_file);
7470 if (flags & SECTION_TLS)
7471 fputs (",#tls", asm_out_file);
7472 if (flags & SECTION_CODE)
7473 fputs (",#execinstr", asm_out_file);
7475 /* ??? Handle SECTION_BSS. */
7477 fputc ('\n', asm_out_file);
7479 #endif /* OBJECT_FORMAT_ELF */
7481 /* We do not allow indirect calls to be optimized into sibling calls.
7483 We cannot use sibling calls when delayed branches are disabled
7484 because they will likely require the call delay slot to be filled.
7486 Also, on SPARC 32-bit we cannot emit a sibling call when the
7487 current function returns a structure. This is because the "unimp
7488 after call" convention would cause the callee to return to the
7489 wrong place. The generic code already disallows cases where the
7490 function being called returns a structure.
7492 It may seem strange how this last case could occur. Usually there
7493 is code after the call which jumps to epilogue code which dumps the
7494 return value into the struct return area. That ought to invalidate
7495 the sibling call right? Well, in the C++ case we can end up passing
7496 the pointer to the struct return area to a constructor (which returns
7497 void) and then nothing else happens. Such a sibling call would look
7498 valid without the added check here. */
7500 sparc_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
7503 && flag_delayed_branch
7504 && (TARGET_ARCH64 || ! current_function_returns_struct));
7507 /* libfunc renaming. */
7508 #include "config/gofast.h"
7511 sparc_init_libfuncs (void)
7515 /* Use the subroutines that Sun's library provides for integer
7516 multiply and divide. The `*' prevents an underscore from
7517 being prepended by the compiler. .umul is a little faster
7519 set_optab_libfunc (smul_optab, SImode, "*.umul");
7520 set_optab_libfunc (sdiv_optab, SImode, "*.div");
7521 set_optab_libfunc (udiv_optab, SImode, "*.udiv");
7522 set_optab_libfunc (smod_optab, SImode, "*.rem");
7523 set_optab_libfunc (umod_optab, SImode, "*.urem");
7525 /* TFmode arithmetic. These names are part of the SPARC 32bit ABI. */
7526 set_optab_libfunc (add_optab, TFmode, "_Q_add");
7527 set_optab_libfunc (sub_optab, TFmode, "_Q_sub");
7528 set_optab_libfunc (neg_optab, TFmode, "_Q_neg");
7529 set_optab_libfunc (smul_optab, TFmode, "_Q_mul");
7530 set_optab_libfunc (sdiv_optab, TFmode, "_Q_div");
7532 /* We can define the TFmode sqrt optab only if TARGET_FPU. This
7533 is because with soft-float, the SFmode and DFmode sqrt
7534 instructions will be absent, and the compiler will notice and
7535 try to use the TFmode sqrt instruction for calls to the
7536 builtin function sqrt, but this fails. */
7538 set_optab_libfunc (sqrt_optab, TFmode, "_Q_sqrt");
7540 set_optab_libfunc (eq_optab, TFmode, "_Q_feq");
7541 set_optab_libfunc (ne_optab, TFmode, "_Q_fne");
7542 set_optab_libfunc (gt_optab, TFmode, "_Q_fgt");
7543 set_optab_libfunc (ge_optab, TFmode, "_Q_fge");
7544 set_optab_libfunc (lt_optab, TFmode, "_Q_flt");
7545 set_optab_libfunc (le_optab, TFmode, "_Q_fle");
7547 set_conv_libfunc (sext_optab, TFmode, SFmode, "_Q_stoq");
7548 set_conv_libfunc (sext_optab, TFmode, DFmode, "_Q_dtoq");
7549 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_Q_qtos");
7550 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_Q_qtod");
7552 set_conv_libfunc (sfix_optab, SImode, TFmode, "_Q_qtoi");
7553 set_conv_libfunc (ufix_optab, SImode, TFmode, "_Q_qtou");
7554 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_Q_itoq");
7556 if (DITF_CONVERSION_LIBFUNCS)
7558 set_conv_libfunc (sfix_optab, DImode, TFmode, "_Q_qtoll");
7559 set_conv_libfunc (ufix_optab, DImode, TFmode, "_Q_qtoull");
7560 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_Q_lltoq");
7563 if (SUN_CONVERSION_LIBFUNCS)
7565 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftoll");
7566 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoull");
7567 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtoll");
7568 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoull");
7573 /* In the SPARC 64bit ABI, SImode multiply and divide functions
7574 do not exist in the library. Make sure the compiler does not
7575 emit calls to them by accident. (It should always use the
7576 hardware instructions.) */
7577 set_optab_libfunc (smul_optab, SImode, 0);
7578 set_optab_libfunc (sdiv_optab, SImode, 0);
7579 set_optab_libfunc (udiv_optab, SImode, 0);
7580 set_optab_libfunc (smod_optab, SImode, 0);
7581 set_optab_libfunc (umod_optab, SImode, 0);
7583 if (SUN_INTEGER_MULTIPLY_64)
7585 set_optab_libfunc (smul_optab, DImode, "__mul64");
7586 set_optab_libfunc (sdiv_optab, DImode, "__div64");
7587 set_optab_libfunc (udiv_optab, DImode, "__udiv64");
7588 set_optab_libfunc (smod_optab, DImode, "__rem64");
7589 set_optab_libfunc (umod_optab, DImode, "__urem64");
7592 if (SUN_CONVERSION_LIBFUNCS)
7594 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftol");
7595 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoul");
7596 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtol");
7597 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoul");
7601 gofast_maybe_init_libfuncs ();
7604 #define def_builtin(NAME, CODE, TYPE) \
7605 lang_hooks.builtin_function((NAME), (TYPE), (CODE), BUILT_IN_MD, NULL, \
7608 /* Implement the TARGET_INIT_BUILTINS target hook.
7609 Create builtin functions for special SPARC instructions. */
7612 sparc_init_builtins (void)
7615 sparc_vis_init_builtins ();
7618 /* Create builtin functions for VIS 1.0 instructions. */
7621 sparc_vis_init_builtins (void)
7623 tree v4qi = build_vector_type (unsigned_intQI_type_node, 4);
7624 tree v8qi = build_vector_type (unsigned_intQI_type_node, 8);
7625 tree v4hi = build_vector_type (intHI_type_node, 4);
7626 tree v2hi = build_vector_type (intHI_type_node, 2);
7627 tree v2si = build_vector_type (intSI_type_node, 2);
7629 tree v4qi_ftype_v4hi = build_function_type_list (v4qi, v4hi, 0);
7630 tree v8qi_ftype_v2si_v8qi = build_function_type_list (v8qi, v2si, v8qi, 0);
7631 tree v2hi_ftype_v2si = build_function_type_list (v2hi, v2si, 0);
7632 tree v4hi_ftype_v4qi = build_function_type_list (v4hi, v4qi, 0);
7633 tree v8qi_ftype_v4qi_v4qi = build_function_type_list (v8qi, v4qi, v4qi, 0);
7634 tree v4hi_ftype_v4qi_v4hi = build_function_type_list (v4hi, v4qi, v4hi, 0);
7635 tree v4hi_ftype_v4qi_v2hi = build_function_type_list (v4hi, v4qi, v2hi, 0);
7636 tree v2si_ftype_v4qi_v2hi = build_function_type_list (v2si, v4qi, v2hi, 0);
7637 tree v4hi_ftype_v8qi_v4hi = build_function_type_list (v4hi, v8qi, v4hi, 0);
7638 tree v4hi_ftype_v4hi_v4hi = build_function_type_list (v4hi, v4hi, v4hi, 0);
7639 tree v2si_ftype_v2si_v2si = build_function_type_list (v2si, v2si, v2si, 0);
7640 tree v8qi_ftype_v8qi_v8qi = build_function_type_list (v8qi, v8qi, v8qi, 0);
7641 tree di_ftype_v8qi_v8qi_di = build_function_type_list (intDI_type_node,
7643 intDI_type_node, 0);
7644 tree di_ftype_di_di = build_function_type_list (intDI_type_node,
7646 intDI_type_node, 0);
7647 tree ptr_ftype_ptr_si = build_function_type_list (ptr_type_node,
7649 intSI_type_node, 0);
7650 tree ptr_ftype_ptr_di = build_function_type_list (ptr_type_node,
7652 intDI_type_node, 0);
7654 /* Packing and expanding vectors. */
7655 def_builtin ("__builtin_vis_fpack16", CODE_FOR_fpack16_vis, v4qi_ftype_v4hi);
7656 def_builtin ("__builtin_vis_fpack32", CODE_FOR_fpack32_vis,
7657 v8qi_ftype_v2si_v8qi);
7658 def_builtin ("__builtin_vis_fpackfix", CODE_FOR_fpackfix_vis,
7660 def_builtin ("__builtin_vis_fexpand", CODE_FOR_fexpand_vis, v4hi_ftype_v4qi);
7661 def_builtin ("__builtin_vis_fpmerge", CODE_FOR_fpmerge_vis,
7662 v8qi_ftype_v4qi_v4qi);
7664 /* Multiplications. */
7665 def_builtin ("__builtin_vis_fmul8x16", CODE_FOR_fmul8x16_vis,
7666 v4hi_ftype_v4qi_v4hi);
7667 def_builtin ("__builtin_vis_fmul8x16au", CODE_FOR_fmul8x16au_vis,
7668 v4hi_ftype_v4qi_v2hi);
7669 def_builtin ("__builtin_vis_fmul8x16al", CODE_FOR_fmul8x16al_vis,
7670 v4hi_ftype_v4qi_v2hi);
7671 def_builtin ("__builtin_vis_fmul8sux16", CODE_FOR_fmul8sux16_vis,
7672 v4hi_ftype_v8qi_v4hi);
7673 def_builtin ("__builtin_vis_fmul8ulx16", CODE_FOR_fmul8ulx16_vis,
7674 v4hi_ftype_v8qi_v4hi);
7675 def_builtin ("__builtin_vis_fmuld8sux16", CODE_FOR_fmuld8sux16_vis,
7676 v2si_ftype_v4qi_v2hi);
7677 def_builtin ("__builtin_vis_fmuld8ulx16", CODE_FOR_fmuld8ulx16_vis,
7678 v2si_ftype_v4qi_v2hi);
7680 /* Data aligning. */
7681 def_builtin ("__builtin_vis_faligndatav4hi", CODE_FOR_faligndatav4hi_vis,
7682 v4hi_ftype_v4hi_v4hi);
7683 def_builtin ("__builtin_vis_faligndatav8qi", CODE_FOR_faligndatav8qi_vis,
7684 v8qi_ftype_v8qi_v8qi);
7685 def_builtin ("__builtin_vis_faligndatav2si", CODE_FOR_faligndatav2si_vis,
7686 v2si_ftype_v2si_v2si);
7687 def_builtin ("__builtin_vis_faligndatadi", CODE_FOR_faligndatadi_vis,
7690 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrdi_vis,
7693 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrsi_vis,
7696 /* Pixel distance. */
7697 def_builtin ("__builtin_vis_pdist", CODE_FOR_pdist_vis,
7698 di_ftype_v8qi_v8qi_di);
7701 /* Handle TARGET_EXPAND_BUILTIN target hook.
7702 Expand builtin functions for sparc instrinsics. */
7705 sparc_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
7706 enum machine_mode tmode, int ignore ATTRIBUTE_UNUSED)
7709 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7710 unsigned int icode = DECL_FUNCTION_CODE (fndecl);
7712 enum machine_mode mode[4];
7715 mode[arg_count] = tmode;
7718 || GET_MODE (target) != tmode
7719 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7720 op[arg_count] = gen_reg_rtx (tmode);
7722 op[arg_count] = target;
7724 for (arglist = TREE_OPERAND (exp, 1); arglist;
7725 arglist = TREE_CHAIN (arglist))
7727 tree arg = TREE_VALUE (arglist);
7730 mode[arg_count] = insn_data[icode].operand[arg_count].mode;
7731 op[arg_count] = expand_expr (arg, NULL_RTX, VOIDmode, 0);
7733 if (! (*insn_data[icode].operand[arg_count].predicate) (op[arg_count],
7735 op[arg_count] = copy_to_mode_reg (mode[arg_count], op[arg_count]);
7741 pat = GEN_FCN (icode) (op[0], op[1]);
7744 pat = GEN_FCN (icode) (op[0], op[1], op[2]);
7747 pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]);
7762 sparc_extra_constraint_check (rtx op, int c, int strict)
7767 && (c == 'T' || c == 'U'))
7773 return fp_sethi_p (op);
7776 return fp_mov_p (op);
7779 return fp_high_losum_p (op);
7783 || (GET_CODE (op) == REG
7784 && (REGNO (op) < FIRST_PSEUDO_REGISTER
7785 || reg_renumber[REGNO (op)] >= 0)))
7786 return register_ok_for_ldd (op);
7795 return const_zero_operand (op, GET_MODE (op));
7801 /* Our memory extra constraints have to emulate the
7802 behavior of 'm' and 'o' in order for reload to work
7804 if (GET_CODE (op) == MEM)
7807 if ((TARGET_ARCH64 || mem_min_alignment (op, 8))
7809 || strict_memory_address_p (Pmode, XEXP (op, 0))))
7814 reload_ok_mem = (reload_in_progress
7815 && GET_CODE (op) == REG
7816 && REGNO (op) >= FIRST_PSEUDO_REGISTER
7817 && reg_renumber [REGNO (op)] < 0);
7820 return reload_ok_mem;
7823 /* ??? This duplicates information provided to the compiler by the
7824 ??? scheduler description. Some day, teach genautomata to output
7825 ??? the latencies and then CSE will just use that. */
7828 sparc_rtx_costs (rtx x, int code, int outer_code, int *total)
7830 enum machine_mode mode = GET_MODE (x);
7831 bool float_mode_p = FLOAT_MODE_P (mode);
7836 if (INTVAL (x) < 0x1000 && INTVAL (x) >= -0x1000)
7854 if (GET_MODE (x) == VOIDmode
7855 && ((CONST_DOUBLE_HIGH (x) == 0
7856 && CONST_DOUBLE_LOW (x) < 0x1000)
7857 || (CONST_DOUBLE_HIGH (x) == -1
7858 && CONST_DOUBLE_LOW (x) < 0
7859 && CONST_DOUBLE_LOW (x) >= -0x1000)))
7866 /* If outer-code was a sign or zero extension, a cost
7867 of COSTS_N_INSNS (1) was already added in. This is
7868 why we are subtracting it back out. */
7869 if (outer_code == ZERO_EXTEND)
7871 *total = sparc_costs->int_zload - COSTS_N_INSNS (1);
7873 else if (outer_code == SIGN_EXTEND)
7875 *total = sparc_costs->int_sload - COSTS_N_INSNS (1);
7877 else if (float_mode_p)
7879 *total = sparc_costs->float_load;
7883 *total = sparc_costs->int_load;
7891 *total = sparc_costs->float_plusminus;
7893 *total = COSTS_N_INSNS (1);
7898 *total = sparc_costs->float_mul;
7899 else if (! TARGET_HARD_MUL)
7900 *total = COSTS_N_INSNS (25);
7906 if (sparc_costs->int_mul_bit_factor)
7910 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
7912 unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
7913 for (nbits = 0; value != 0; value &= value - 1)
7916 else if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
7917 && GET_MODE (XEXP (x, 1)) == VOIDmode)
7919 rtx x1 = XEXP (x, 1);
7920 unsigned HOST_WIDE_INT value1 = CONST_DOUBLE_LOW (x1);
7921 unsigned HOST_WIDE_INT value2 = CONST_DOUBLE_HIGH (x1);
7923 for (nbits = 0; value1 != 0; value1 &= value1 - 1)
7925 for (; value2 != 0; value2 &= value2 - 1)
7933 bit_cost = (nbits - 3) / sparc_costs->int_mul_bit_factor;
7934 bit_cost = COSTS_N_INSNS (bit_cost);
7938 *total = sparc_costs->int_mulX + bit_cost;
7940 *total = sparc_costs->int_mul + bit_cost;
7947 *total = COSTS_N_INSNS (1) + sparc_costs->shift_penalty;
7957 *total = sparc_costs->float_div_df;
7959 *total = sparc_costs->float_div_sf;
7964 *total = sparc_costs->int_divX;
7966 *total = sparc_costs->int_div;
7973 *total = COSTS_N_INSNS (1);
7980 case UNSIGNED_FLOAT:
7984 case FLOAT_TRUNCATE:
7985 *total = sparc_costs->float_move;
7990 *total = sparc_costs->float_sqrt_df;
7992 *total = sparc_costs->float_sqrt_sf;
7997 *total = sparc_costs->float_cmp;
7999 *total = COSTS_N_INSNS (1);
8004 *total = sparc_costs->float_cmove;
8006 *total = sparc_costs->int_cmove;
8010 /* Handle the NAND vector patterns. */
8011 if (sparc_vector_mode_supported_p (GET_MODE (x))
8012 && GET_CODE (XEXP (x, 0)) == NOT
8013 && GET_CODE (XEXP (x, 1)) == NOT)
8015 *total = COSTS_N_INSNS (1);
8026 /* Emit the sequence of insns SEQ while preserving the register REG. */
8029 emit_and_preserve (rtx seq, rtx reg)
8031 rtx slot = gen_rtx_MEM (word_mode,
8032 plus_constant (stack_pointer_rtx, SPARC_STACK_BIAS));
8034 emit_insn (gen_stack_pointer_dec (GEN_INT (STACK_BOUNDARY/BITS_PER_UNIT)));
8035 emit_insn (gen_rtx_SET (VOIDmode, slot, reg));
8037 emit_insn (gen_rtx_SET (VOIDmode, reg, slot));
8038 emit_insn (gen_stack_pointer_inc (GEN_INT (STACK_BOUNDARY/BITS_PER_UNIT)));
8041 /* Output the assembler code for a thunk function. THUNK_DECL is the
8042 declaration for the thunk function itself, FUNCTION is the decl for
8043 the target function. DELTA is an immediate constant offset to be
8044 added to THIS. If VCALL_OFFSET is nonzero, the word at address
8045 (*THIS + VCALL_OFFSET) should be additionally added to THIS. */
8048 sparc_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
8049 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
8052 rtx this, insn, funexp;
8053 unsigned int int_arg_first;
8055 reload_completed = 1;
8056 epilogue_completed = 1;
8058 reset_block_changes ();
8060 emit_note (NOTE_INSN_PROLOGUE_END);
8062 if (flag_delayed_branch)
8064 /* We will emit a regular sibcall below, so we need to instruct
8065 output_sibcall that we are in a leaf function. */
8066 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 1;
8068 /* This will cause final.c to invoke leaf_renumber_regs so we
8069 must behave as if we were in a not-yet-leafified function. */
8070 int_arg_first = SPARC_INCOMING_INT_ARG_FIRST;
8074 /* We will emit the sibcall manually below, so we will need to
8075 manually spill non-leaf registers. */
8076 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 0;
8078 /* We really are in a leaf function. */
8079 int_arg_first = SPARC_OUTGOING_INT_ARG_FIRST;
8082 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
8083 returns a structure, the structure return pointer is there instead. */
8084 if (TARGET_ARCH64 && aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
8085 this = gen_rtx_REG (Pmode, int_arg_first + 1);
8087 this = gen_rtx_REG (Pmode, int_arg_first);
8089 /* Add DELTA. When possible use a plain add, otherwise load it into
8090 a register first. */
8093 rtx delta_rtx = GEN_INT (delta);
8095 if (! SPARC_SIMM13_P (delta))
8097 rtx scratch = gen_rtx_REG (Pmode, 1);
8098 emit_move_insn (scratch, delta_rtx);
8099 delta_rtx = scratch;
8102 /* THIS += DELTA. */
8103 emit_insn (gen_add2_insn (this, delta_rtx));
8106 /* Add the word at address (*THIS + VCALL_OFFSET). */
8109 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
8110 rtx scratch = gen_rtx_REG (Pmode, 1);
8112 gcc_assert (vcall_offset < 0);
8114 /* SCRATCH = *THIS. */
8115 emit_move_insn (scratch, gen_rtx_MEM (Pmode, this));
8117 /* Prepare for adding VCALL_OFFSET. The difficulty is that we
8118 may not have any available scratch register at this point. */
8119 if (SPARC_SIMM13_P (vcall_offset))
8121 /* This is the case if ARCH64 (unless -ffixed-g5 is passed). */
8122 else if (! fixed_regs[5]
8123 /* The below sequence is made up of at least 2 insns,
8124 while the default method may need only one. */
8125 && vcall_offset < -8192)
8127 rtx scratch2 = gen_rtx_REG (Pmode, 5);
8128 emit_move_insn (scratch2, vcall_offset_rtx);
8129 vcall_offset_rtx = scratch2;
8133 rtx increment = GEN_INT (-4096);
8135 /* VCALL_OFFSET is a negative number whose typical range can be
8136 estimated as -32768..0 in 32-bit mode. In almost all cases
8137 it is therefore cheaper to emit multiple add insns than
8138 spilling and loading the constant into a register (at least
8140 while (! SPARC_SIMM13_P (vcall_offset))
8142 emit_insn (gen_add2_insn (scratch, increment));
8143 vcall_offset += 4096;
8145 vcall_offset_rtx = GEN_INT (vcall_offset); /* cannot be 0 */
8148 /* SCRATCH = *(*THIS + VCALL_OFFSET). */
8149 emit_move_insn (scratch, gen_rtx_MEM (Pmode,
8150 gen_rtx_PLUS (Pmode,
8152 vcall_offset_rtx)));
8154 /* THIS += *(*THIS + VCALL_OFFSET). */
8155 emit_insn (gen_add2_insn (this, scratch));
8158 /* Generate a tail call to the target function. */
8159 if (! TREE_USED (function))
8161 assemble_external (function);
8162 TREE_USED (function) = 1;
8164 funexp = XEXP (DECL_RTL (function), 0);
8166 if (flag_delayed_branch)
8168 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
8169 insn = emit_call_insn (gen_sibcall (funexp));
8170 SIBLING_CALL_P (insn) = 1;
8174 /* The hoops we have to jump through in order to generate a sibcall
8175 without using delay slots... */
8176 rtx spill_reg, seq, scratch = gen_rtx_REG (Pmode, 1);
8180 spill_reg = gen_rtx_REG (word_mode, 15); /* %o7 */
8182 /* Delay emitting the PIC helper function because it needs to
8183 change the section and we are emitting assembly code. */
8184 load_pic_register (true); /* clobbers %o7 */
8185 scratch = legitimize_pic_address (funexp, Pmode, scratch);
8188 emit_and_preserve (seq, spill_reg);
8190 else if (TARGET_ARCH32)
8192 emit_insn (gen_rtx_SET (VOIDmode,
8194 gen_rtx_HIGH (SImode, funexp)));
8195 emit_insn (gen_rtx_SET (VOIDmode,
8197 gen_rtx_LO_SUM (SImode, scratch, funexp)));
8199 else /* TARGET_ARCH64 */
8201 switch (sparc_cmodel)
8205 /* The destination can serve as a temporary. */
8206 sparc_emit_set_symbolic_const64 (scratch, funexp, scratch);
8211 /* The destination cannot serve as a temporary. */
8212 spill_reg = gen_rtx_REG (DImode, 15); /* %o7 */
8214 sparc_emit_set_symbolic_const64 (scratch, funexp, spill_reg);
8217 emit_and_preserve (seq, spill_reg);
8225 emit_jump_insn (gen_indirect_jump (scratch));
8230 /* Run just enough of rest_of_compilation to get the insns emitted.
8231 There's not really enough bulk here to make other passes such as
8232 instruction scheduling worth while. Note that use_thunk calls
8233 assemble_start_function and assemble_end_function. */
8234 insn = get_insns ();
8235 insn_locators_initialize ();
8236 shorten_branches (insn);
8237 final_start_function (insn, file, 1);
8238 final (insn, file, 1);
8239 final_end_function ();
8241 reload_completed = 0;
8242 epilogue_completed = 0;
8246 /* Return true if sparc_output_mi_thunk would be able to output the
8247 assembler code for the thunk function specified by the arguments
8248 it is passed, and false otherwise. */
8250 sparc_can_output_mi_thunk (tree thunk_fndecl ATTRIBUTE_UNUSED,
8251 HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
8252 HOST_WIDE_INT vcall_offset,
8253 tree function ATTRIBUTE_UNUSED)
8255 /* Bound the loop used in the default method above. */
8256 return (vcall_offset >= -32768 || ! fixed_regs[5]);
8259 /* How to allocate a 'struct machine_function'. */
8261 static struct machine_function *
8262 sparc_init_machine_status (void)
8264 return ggc_alloc_cleared (sizeof (struct machine_function));
8267 /* Locate some local-dynamic symbol still in use by this function
8268 so that we can print its name in local-dynamic base patterns. */
8271 get_some_local_dynamic_name (void)
8275 if (cfun->machine->some_ld_name)
8276 return cfun->machine->some_ld_name;
8278 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8280 && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
8281 return cfun->machine->some_ld_name;
8287 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
8292 && GET_CODE (x) == SYMBOL_REF
8293 && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8295 cfun->machine->some_ld_name = XSTR (x, 0);
8302 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
8303 This is called from dwarf2out.c to emit call frame instructions
8304 for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
8306 sparc_dwarf_handle_frame_unspec (const char *label,
8307 rtx pattern ATTRIBUTE_UNUSED,
8308 int index ATTRIBUTE_UNUSED)
8310 gcc_assert (index == UNSPECV_SAVEW);
8311 dwarf2out_window_save (label);
8314 /* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
8315 We need to emit DTP-relative relocations. */
8318 sparc_output_dwarf_dtprel (FILE *file, int size, rtx x)
8323 fputs ("\t.word\t%r_tls_dtpoff32(", file);
8326 fputs ("\t.xword\t%r_tls_dtpoff64(", file);
8331 output_addr_const (file, x);
8336 void sparc_file_end (void)
8338 /* If we haven't emitted the special PIC helper function, do so now. */
8339 if (pic_helper_symbol_name[0] && !pic_helper_emitted_p)
8342 if (NEED_INDICATE_EXEC_STACK)
8343 file_end_indicate_exec_stack ();
8346 #include "gt-sparc.h"