1 /* Subroutines for insn-output.c for SPARC.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 64-bit SPARC-V9 support by Michael Tiemann, Jim Wilson, and Doug Evans,
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
27 #include "coretypes.h"
32 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "insn-codes.h"
36 #include "conditions.h"
38 #include "insn-attr.h"
49 #include "target-def.h"
50 #include "cfglayout.h"
51 #include "tree-gimple.h"
52 #include "langhooks.h"
56 struct processor_costs cypress_costs
= {
57 COSTS_N_INSNS (2), /* int load */
58 COSTS_N_INSNS (2), /* int signed load */
59 COSTS_N_INSNS (2), /* int zeroed load */
60 COSTS_N_INSNS (2), /* float load */
61 COSTS_N_INSNS (5), /* fmov, fneg, fabs */
62 COSTS_N_INSNS (5), /* fadd, fsub */
63 COSTS_N_INSNS (1), /* fcmp */
64 COSTS_N_INSNS (1), /* fmov, fmovr */
65 COSTS_N_INSNS (7), /* fmul */
66 COSTS_N_INSNS (37), /* fdivs */
67 COSTS_N_INSNS (37), /* fdivd */
68 COSTS_N_INSNS (63), /* fsqrts */
69 COSTS_N_INSNS (63), /* fsqrtd */
70 COSTS_N_INSNS (1), /* imul */
71 COSTS_N_INSNS (1), /* imulX */
72 0, /* imul bit factor */
73 COSTS_N_INSNS (1), /* idiv */
74 COSTS_N_INSNS (1), /* idivX */
75 COSTS_N_INSNS (1), /* movcc/movr */
76 0, /* shift penalty */
80 struct processor_costs supersparc_costs
= {
81 COSTS_N_INSNS (1), /* int load */
82 COSTS_N_INSNS (1), /* int signed load */
83 COSTS_N_INSNS (1), /* int zeroed load */
84 COSTS_N_INSNS (0), /* float load */
85 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
86 COSTS_N_INSNS (3), /* fadd, fsub */
87 COSTS_N_INSNS (3), /* fcmp */
88 COSTS_N_INSNS (1), /* fmov, fmovr */
89 COSTS_N_INSNS (3), /* fmul */
90 COSTS_N_INSNS (6), /* fdivs */
91 COSTS_N_INSNS (9), /* fdivd */
92 COSTS_N_INSNS (12), /* fsqrts */
93 COSTS_N_INSNS (12), /* fsqrtd */
94 COSTS_N_INSNS (4), /* imul */
95 COSTS_N_INSNS (4), /* imulX */
96 0, /* imul bit factor */
97 COSTS_N_INSNS (4), /* idiv */
98 COSTS_N_INSNS (4), /* idivX */
99 COSTS_N_INSNS (1), /* movcc/movr */
100 1, /* shift penalty */
104 struct processor_costs hypersparc_costs
= {
105 COSTS_N_INSNS (1), /* int load */
106 COSTS_N_INSNS (1), /* int signed load */
107 COSTS_N_INSNS (1), /* int zeroed load */
108 COSTS_N_INSNS (1), /* float load */
109 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
110 COSTS_N_INSNS (1), /* fadd, fsub */
111 COSTS_N_INSNS (1), /* fcmp */
112 COSTS_N_INSNS (1), /* fmov, fmovr */
113 COSTS_N_INSNS (1), /* fmul */
114 COSTS_N_INSNS (8), /* fdivs */
115 COSTS_N_INSNS (12), /* fdivd */
116 COSTS_N_INSNS (17), /* fsqrts */
117 COSTS_N_INSNS (17), /* fsqrtd */
118 COSTS_N_INSNS (17), /* imul */
119 COSTS_N_INSNS (17), /* imulX */
120 0, /* imul bit factor */
121 COSTS_N_INSNS (17), /* idiv */
122 COSTS_N_INSNS (17), /* idivX */
123 COSTS_N_INSNS (1), /* movcc/movr */
124 0, /* shift penalty */
128 struct processor_costs sparclet_costs
= {
129 COSTS_N_INSNS (3), /* int load */
130 COSTS_N_INSNS (3), /* int signed load */
131 COSTS_N_INSNS (1), /* int zeroed load */
132 COSTS_N_INSNS (1), /* float load */
133 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
134 COSTS_N_INSNS (1), /* fadd, fsub */
135 COSTS_N_INSNS (1), /* fcmp */
136 COSTS_N_INSNS (1), /* fmov, fmovr */
137 COSTS_N_INSNS (1), /* fmul */
138 COSTS_N_INSNS (1), /* fdivs */
139 COSTS_N_INSNS (1), /* fdivd */
140 COSTS_N_INSNS (1), /* fsqrts */
141 COSTS_N_INSNS (1), /* fsqrtd */
142 COSTS_N_INSNS (5), /* imul */
143 COSTS_N_INSNS (5), /* imulX */
144 0, /* imul bit factor */
145 COSTS_N_INSNS (5), /* idiv */
146 COSTS_N_INSNS (5), /* idivX */
147 COSTS_N_INSNS (1), /* movcc/movr */
148 0, /* shift penalty */
152 struct processor_costs ultrasparc_costs
= {
153 COSTS_N_INSNS (2), /* int load */
154 COSTS_N_INSNS (3), /* int signed load */
155 COSTS_N_INSNS (2), /* int zeroed load */
156 COSTS_N_INSNS (2), /* float load */
157 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
158 COSTS_N_INSNS (4), /* fadd, fsub */
159 COSTS_N_INSNS (1), /* fcmp */
160 COSTS_N_INSNS (2), /* fmov, fmovr */
161 COSTS_N_INSNS (4), /* fmul */
162 COSTS_N_INSNS (13), /* fdivs */
163 COSTS_N_INSNS (23), /* fdivd */
164 COSTS_N_INSNS (13), /* fsqrts */
165 COSTS_N_INSNS (23), /* fsqrtd */
166 COSTS_N_INSNS (4), /* imul */
167 COSTS_N_INSNS (4), /* imulX */
168 2, /* imul bit factor */
169 COSTS_N_INSNS (37), /* idiv */
170 COSTS_N_INSNS (68), /* idivX */
171 COSTS_N_INSNS (2), /* movcc/movr */
172 2, /* shift penalty */
176 struct processor_costs ultrasparc3_costs
= {
177 COSTS_N_INSNS (2), /* int load */
178 COSTS_N_INSNS (3), /* int signed load */
179 COSTS_N_INSNS (3), /* int zeroed load */
180 COSTS_N_INSNS (2), /* float load */
181 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
182 COSTS_N_INSNS (4), /* fadd, fsub */
183 COSTS_N_INSNS (5), /* fcmp */
184 COSTS_N_INSNS (3), /* fmov, fmovr */
185 COSTS_N_INSNS (4), /* fmul */
186 COSTS_N_INSNS (17), /* fdivs */
187 COSTS_N_INSNS (20), /* fdivd */
188 COSTS_N_INSNS (20), /* fsqrts */
189 COSTS_N_INSNS (29), /* fsqrtd */
190 COSTS_N_INSNS (6), /* imul */
191 COSTS_N_INSNS (6), /* imulX */
192 0, /* imul bit factor */
193 COSTS_N_INSNS (40), /* idiv */
194 COSTS_N_INSNS (71), /* idivX */
195 COSTS_N_INSNS (2), /* movcc/movr */
196 0, /* shift penalty */
199 const struct processor_costs
*sparc_costs
= &cypress_costs
;
201 #ifdef HAVE_AS_RELAX_OPTION
202 /* If 'as' and 'ld' are relaxing tail call insns into branch always, use
203 "or %o7,%g0,X; call Y; or X,%g0,%o7" always, so that it can be optimized.
204 With sethi/jmp, neither 'as' nor 'ld' has an easy way how to find out if
205 somebody does not branch between the sethi and jmp. */
206 #define LEAF_SIBCALL_SLOT_RESERVED_P 1
208 #define LEAF_SIBCALL_SLOT_RESERVED_P \
209 ((TARGET_ARCH64 && !TARGET_CM_MEDLOW) || flag_pic)
212 /* Global variables for machine-dependent things. */
214 /* Size of frame. Need to know this to emit return insns from leaf procedures.
215 ACTUAL_FSIZE is set by sparc_compute_frame_size() which is called during the
216 reload pass. This is important as the value is later used for scheduling
217 (to see what can go in a delay slot).
218 APPARENT_FSIZE is the size of the stack less the register save area and less
219 the outgoing argument area. It is used when saving call preserved regs. */
220 static HOST_WIDE_INT apparent_fsize
;
221 static HOST_WIDE_INT actual_fsize
;
223 /* Number of live general or floating point registers needed to be
224 saved (as 4-byte quantities). */
225 static int num_gfregs
;
227 /* The alias set for prologue/epilogue register save/restore. */
228 static GTY(()) int sparc_sr_alias_set
;
230 /* The alias set for the structure return value. */
231 static GTY(()) int struct_value_alias_set
;
233 /* Save the operands last given to a compare for use when we
234 generate a scc or bcc insn. */
235 rtx sparc_compare_op0
, sparc_compare_op1
;
237 /* Vector to say how input registers are mapped to output registers.
238 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
239 eliminate it. You must use -fomit-frame-pointer to get that. */
240 char leaf_reg_remap
[] =
241 { 0, 1, 2, 3, 4, 5, 6, 7,
242 -1, -1, -1, -1, -1, -1, 14, -1,
243 -1, -1, -1, -1, -1, -1, -1, -1,
244 8, 9, 10, 11, 12, 13, -1, 15,
246 32, 33, 34, 35, 36, 37, 38, 39,
247 40, 41, 42, 43, 44, 45, 46, 47,
248 48, 49, 50, 51, 52, 53, 54, 55,
249 56, 57, 58, 59, 60, 61, 62, 63,
250 64, 65, 66, 67, 68, 69, 70, 71,
251 72, 73, 74, 75, 76, 77, 78, 79,
252 80, 81, 82, 83, 84, 85, 86, 87,
253 88, 89, 90, 91, 92, 93, 94, 95,
254 96, 97, 98, 99, 100};
256 /* Vector, indexed by hard register number, which contains 1
257 for a register that is allowable in a candidate for leaf
258 function treatment. */
259 char sparc_leaf_regs
[] =
260 { 1, 1, 1, 1, 1, 1, 1, 1,
261 0, 0, 0, 0, 0, 0, 1, 0,
262 0, 0, 0, 0, 0, 0, 0, 0,
263 1, 1, 1, 1, 1, 1, 0, 1,
264 1, 1, 1, 1, 1, 1, 1, 1,
265 1, 1, 1, 1, 1, 1, 1, 1,
266 1, 1, 1, 1, 1, 1, 1, 1,
267 1, 1, 1, 1, 1, 1, 1, 1,
268 1, 1, 1, 1, 1, 1, 1, 1,
269 1, 1, 1, 1, 1, 1, 1, 1,
270 1, 1, 1, 1, 1, 1, 1, 1,
271 1, 1, 1, 1, 1, 1, 1, 1,
274 struct machine_function
GTY(())
276 /* Some local-dynamic TLS symbol name. */
277 const char *some_ld_name
;
279 /* True if the current function is leaf and uses only leaf regs,
280 so that the SPARC leaf function optimization can be applied.
281 Private version of current_function_uses_only_leaf_regs, see
282 sparc_expand_prologue for the rationale. */
285 /* True if the data calculated by sparc_expand_prologue are valid. */
286 bool prologue_data_valid_p
;
289 #define sparc_leaf_function_p cfun->machine->leaf_function_p
290 #define sparc_prologue_data_valid_p cfun->machine->prologue_data_valid_p
292 /* Register we pretend to think the frame pointer is allocated to.
293 Normally, this is %fp, but if we are in a leaf procedure, this
294 is %sp+"something". We record "something" separately as it may
295 be too big for reg+constant addressing. */
296 static rtx frame_base_reg
;
297 static HOST_WIDE_INT frame_base_offset
;
299 /* 1 if the next opcode is to be specially indented. */
300 int sparc_indent_opcode
= 0;
302 static bool sparc_handle_option (size_t, const char *, int);
303 static void sparc_init_modes (void);
304 static void scan_record_type (tree
, int *, int *, int *);
305 static int function_arg_slotno (const CUMULATIVE_ARGS
*, enum machine_mode
,
306 tree
, int, int, int *, int *);
308 static int supersparc_adjust_cost (rtx
, rtx
, rtx
, int);
309 static int hypersparc_adjust_cost (rtx
, rtx
, rtx
, int);
311 static void sparc_output_addr_vec (rtx
);
312 static void sparc_output_addr_diff_vec (rtx
);
313 static void sparc_output_deferred_case_vectors (void);
314 static rtx
sparc_builtin_saveregs (void);
315 static int epilogue_renumber (rtx
*, int);
316 static bool sparc_assemble_integer (rtx
, unsigned int, int);
317 static int set_extends (rtx
);
318 static void emit_pic_helper (void);
319 static void load_pic_register (bool);
320 static int save_or_restore_regs (int, int, rtx
, int, int);
321 static void emit_save_regs (void);
322 static void emit_restore_regs (void);
323 static void sparc_asm_function_prologue (FILE *, HOST_WIDE_INT
);
324 static void sparc_asm_function_epilogue (FILE *, HOST_WIDE_INT
);
325 #ifdef OBJECT_FORMAT_ELF
326 static void sparc_elf_asm_named_section (const char *, unsigned int, tree
);
329 static int sparc_adjust_cost (rtx
, rtx
, rtx
, int);
330 static int sparc_issue_rate (void);
331 static void sparc_sched_init (FILE *, int, int);
332 static int sparc_use_sched_lookahead (void);
334 static void emit_soft_tfmode_libcall (const char *, int, rtx
*);
335 static void emit_soft_tfmode_binop (enum rtx_code
, rtx
*);
336 static void emit_soft_tfmode_unop (enum rtx_code
, rtx
*);
337 static void emit_soft_tfmode_cvt (enum rtx_code
, rtx
*);
338 static void emit_hard_tfmode_operation (enum rtx_code
, rtx
*);
340 static bool sparc_function_ok_for_sibcall (tree
, tree
);
341 static void sparc_init_libfuncs (void);
342 static void sparc_init_builtins (void);
343 static void sparc_vis_init_builtins (void);
344 static rtx
sparc_expand_builtin (tree
, rtx
, rtx
, enum machine_mode
, int);
345 static void sparc_output_mi_thunk (FILE *, tree
, HOST_WIDE_INT
,
346 HOST_WIDE_INT
, tree
);
347 static bool sparc_can_output_mi_thunk (tree
, HOST_WIDE_INT
,
348 HOST_WIDE_INT
, tree
);
349 static struct machine_function
* sparc_init_machine_status (void);
350 static bool sparc_cannot_force_const_mem (rtx
);
351 static rtx
sparc_tls_get_addr (void);
352 static rtx
sparc_tls_got (void);
353 static const char *get_some_local_dynamic_name (void);
354 static int get_some_local_dynamic_name_1 (rtx
*, void *);
355 static bool sparc_rtx_costs (rtx
, int, int, int *);
356 static bool sparc_promote_prototypes (tree
);
357 static rtx
sparc_struct_value_rtx (tree
, int);
358 static bool sparc_return_in_memory (tree
, tree
);
359 static bool sparc_strict_argument_naming (CUMULATIVE_ARGS
*);
360 static tree
sparc_gimplify_va_arg (tree
, tree
, tree
*, tree
*);
361 static bool sparc_vector_mode_supported_p (enum machine_mode
);
362 static bool sparc_pass_by_reference (CUMULATIVE_ARGS
*,
363 enum machine_mode
, tree
, bool);
364 static int sparc_arg_partial_bytes (CUMULATIVE_ARGS
*,
365 enum machine_mode
, tree
, bool);
366 static void sparc_dwarf_handle_frame_unspec (const char *, rtx
, int);
367 static void sparc_file_end (void);
368 #ifdef SUBTARGET_ATTRIBUTE_TABLE
369 const struct attribute_spec sparc_attribute_table
[];
372 /* Option handling. */
374 /* Code model option as passed by user. */
375 const char *sparc_cmodel_string
;
378 enum cmodel sparc_cmodel
;
380 char sparc_hard_reg_printed
[8];
382 struct sparc_cpu_select sparc_select
[] =
384 /* switch name, tune arch */
385 { (char *)0, "default", 1, 1 },
386 { (char *)0, "-mcpu=", 1, 1 },
387 { (char *)0, "-mtune=", 1, 0 },
391 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
392 enum processor_type sparc_cpu
;
394 /* Whether\fan FPU option was specified. */
395 static bool fpu_option_set
= false;
397 /* Initialize the GCC target structure. */
399 /* The sparc default is to use .half rather than .short for aligned
400 HI objects. Use .word instead of .long on non-ELF systems. */
401 #undef TARGET_ASM_ALIGNED_HI_OP
402 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
403 #ifndef OBJECT_FORMAT_ELF
404 #undef TARGET_ASM_ALIGNED_SI_OP
405 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
408 #undef TARGET_ASM_UNALIGNED_HI_OP
409 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
410 #undef TARGET_ASM_UNALIGNED_SI_OP
411 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
412 #undef TARGET_ASM_UNALIGNED_DI_OP
413 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
415 /* The target hook has to handle DI-mode values. */
416 #undef TARGET_ASM_INTEGER
417 #define TARGET_ASM_INTEGER sparc_assemble_integer
419 #undef TARGET_ASM_FUNCTION_PROLOGUE
420 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
421 #undef TARGET_ASM_FUNCTION_EPILOGUE
422 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
424 #undef TARGET_SCHED_ADJUST_COST
425 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
426 #undef TARGET_SCHED_ISSUE_RATE
427 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
428 #undef TARGET_SCHED_INIT
429 #define TARGET_SCHED_INIT sparc_sched_init
430 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
431 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
433 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
434 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
436 #undef TARGET_INIT_LIBFUNCS
437 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
438 #undef TARGET_INIT_BUILTINS
439 #define TARGET_INIT_BUILTINS sparc_init_builtins
441 #undef TARGET_EXPAND_BUILTIN
442 #define TARGET_EXPAND_BUILTIN sparc_expand_builtin
445 #undef TARGET_HAVE_TLS
446 #define TARGET_HAVE_TLS true
448 #undef TARGET_CANNOT_FORCE_CONST_MEM
449 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
451 #undef TARGET_ASM_OUTPUT_MI_THUNK
452 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
453 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
454 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
456 #undef TARGET_RTX_COSTS
457 #define TARGET_RTX_COSTS sparc_rtx_costs
458 #undef TARGET_ADDRESS_COST
459 #define TARGET_ADDRESS_COST hook_int_rtx_0
461 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
462 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
463 test for this value. */
464 #undef TARGET_PROMOTE_FUNCTION_ARGS
465 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
467 /* This is only needed for TARGET_ARCH64, but since PROMOTE_FUNCTION_MODE is a
468 no-op for TARGET_ARCH32 this is ok. Otherwise we'd need to add a runtime
469 test for this value. */
470 #undef TARGET_PROMOTE_FUNCTION_RETURN
471 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
473 #undef TARGET_PROMOTE_PROTOTYPES
474 #define TARGET_PROMOTE_PROTOTYPES sparc_promote_prototypes
476 #undef TARGET_STRUCT_VALUE_RTX
477 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
478 #undef TARGET_RETURN_IN_MEMORY
479 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
480 #undef TARGET_MUST_PASS_IN_STACK
481 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
482 #undef TARGET_PASS_BY_REFERENCE
483 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
484 #undef TARGET_ARG_PARTIAL_BYTES
485 #define TARGET_ARG_PARTIAL_BYTES sparc_arg_partial_bytes
487 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
488 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
489 #undef TARGET_STRICT_ARGUMENT_NAMING
490 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
492 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
493 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
495 #undef TARGET_VECTOR_MODE_SUPPORTED_P
496 #define TARGET_VECTOR_MODE_SUPPORTED_P sparc_vector_mode_supported_p
498 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
499 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC sparc_dwarf_handle_frame_unspec
501 #ifdef SUBTARGET_INSERT_ATTRIBUTES
502 #undef TARGET_INSERT_ATTRIBUTES
503 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
506 #ifdef SUBTARGET_ATTRIBUTE_TABLE
507 #undef TARGET_ATTRIBUTE_TABLE
508 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
511 #undef TARGET_RELAXED_ORDERING
512 #define TARGET_RELAXED_ORDERING SPARC_RELAXED_ORDERING
514 #undef TARGET_DEFAULT_TARGET_FLAGS
515 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
516 #undef TARGET_HANDLE_OPTION
517 #define TARGET_HANDLE_OPTION sparc_handle_option
519 #undef TARGET_ASM_FILE_END
520 #define TARGET_ASM_FILE_END sparc_file_end
522 struct gcc_target targetm
= TARGET_INITIALIZER
;
524 /* Implement TARGET_HANDLE_OPTION. */
527 sparc_handle_option (size_t code
, const char *arg
, int value ATTRIBUTE_UNUSED
)
532 case OPT_mhard_float
:
533 case OPT_msoft_float
:
534 fpu_option_set
= true;
538 sparc_select
[1].string
= arg
;
542 sparc_select
[2].string
= arg
;
546 sparc_cmodel_string
= arg
;
553 /* Validate and override various options, and do some machine dependent
557 sparc_override_options (void)
559 static struct code_model
{
560 const char *const name
;
562 } const cmodels
[] = {
564 { "medlow", CM_MEDLOW
},
565 { "medmid", CM_MEDMID
},
566 { "medany", CM_MEDANY
},
567 { "embmedany", CM_EMBMEDANY
},
570 const struct code_model
*cmodel
;
571 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
572 static struct cpu_default
{
574 const char *const name
;
575 } const cpu_default
[] = {
576 /* There must be one entry here for each TARGET_CPU value. */
577 { TARGET_CPU_sparc
, "cypress" },
578 { TARGET_CPU_sparclet
, "tsc701" },
579 { TARGET_CPU_sparclite
, "f930" },
580 { TARGET_CPU_v8
, "v8" },
581 { TARGET_CPU_hypersparc
, "hypersparc" },
582 { TARGET_CPU_sparclite86x
, "sparclite86x" },
583 { TARGET_CPU_supersparc
, "supersparc" },
584 { TARGET_CPU_v9
, "v9" },
585 { TARGET_CPU_ultrasparc
, "ultrasparc" },
586 { TARGET_CPU_ultrasparc3
, "ultrasparc3" },
589 const struct cpu_default
*def
;
590 /* Table of values for -m{cpu,tune}=. */
591 static struct cpu_table
{
592 const char *const name
;
593 const enum processor_type processor
;
596 } const cpu_table
[] = {
597 { "v7", PROCESSOR_V7
, MASK_ISA
, 0 },
598 { "cypress", PROCESSOR_CYPRESS
, MASK_ISA
, 0 },
599 { "v8", PROCESSOR_V8
, MASK_ISA
, MASK_V8
},
600 /* TI TMS390Z55 supersparc */
601 { "supersparc", PROCESSOR_SUPERSPARC
, MASK_ISA
, MASK_V8
},
602 { "sparclite", PROCESSOR_SPARCLITE
, MASK_ISA
, MASK_SPARCLITE
},
603 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
604 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
605 { "f930", PROCESSOR_F930
, MASK_ISA
|MASK_FPU
, MASK_SPARCLITE
},
606 { "f934", PROCESSOR_F934
, MASK_ISA
, MASK_SPARCLITE
|MASK_FPU
},
607 { "hypersparc", PROCESSOR_HYPERSPARC
, MASK_ISA
, MASK_V8
|MASK_FPU
},
608 { "sparclite86x", PROCESSOR_SPARCLITE86X
, MASK_ISA
|MASK_FPU
,
610 { "sparclet", PROCESSOR_SPARCLET
, MASK_ISA
, MASK_SPARCLET
},
612 { "tsc701", PROCESSOR_TSC701
, MASK_ISA
, MASK_SPARCLET
},
613 { "v9", PROCESSOR_V9
, MASK_ISA
, MASK_V9
},
614 /* TI ultrasparc I, II, IIi */
615 { "ultrasparc", PROCESSOR_ULTRASPARC
, MASK_ISA
, MASK_V9
616 /* Although insns using %y are deprecated, it is a clear win on current
618 |MASK_DEPRECATED_V8_INSNS
},
619 /* TI ultrasparc III */
620 /* ??? Check if %y issue still holds true in ultra3. */
621 { "ultrasparc3", PROCESSOR_ULTRASPARC3
, MASK_ISA
, MASK_V9
|MASK_DEPRECATED_V8_INSNS
},
624 const struct cpu_table
*cpu
;
625 const struct sparc_cpu_select
*sel
;
628 #ifndef SPARC_BI_ARCH
629 /* Check for unsupported architecture size. */
630 if (! TARGET_64BIT
!= DEFAULT_ARCH32_P
)
631 error ("%s is not supported by this configuration",
632 DEFAULT_ARCH32_P
? "-m64" : "-m32");
635 /* We force all 64bit archs to use 128 bit long double */
636 if (TARGET_64BIT
&& ! TARGET_LONG_DOUBLE_128
)
638 error ("-mlong-double-64 not allowed with -m64");
639 target_flags
|= MASK_LONG_DOUBLE_128
;
642 /* Code model selection. */
643 sparc_cmodel
= SPARC_DEFAULT_CMODEL
;
647 sparc_cmodel
= CM_32
;
650 if (sparc_cmodel_string
!= NULL
)
654 for (cmodel
= &cmodels
[0]; cmodel
->name
; cmodel
++)
655 if (strcmp (sparc_cmodel_string
, cmodel
->name
) == 0)
657 if (cmodel
->name
== NULL
)
658 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string
);
660 sparc_cmodel
= cmodel
->value
;
663 error ("-mcmodel= is not supported on 32 bit systems");
666 fpu
= TARGET_FPU
; /* save current -mfpu status */
668 /* Set the default CPU. */
669 for (def
= &cpu_default
[0]; def
->name
; ++def
)
670 if (def
->cpu
== TARGET_CPU_DEFAULT
)
672 gcc_assert (def
->name
);
673 sparc_select
[0].string
= def
->name
;
675 for (sel
= &sparc_select
[0]; sel
->name
; ++sel
)
679 for (cpu
= &cpu_table
[0]; cpu
->name
; ++cpu
)
680 if (! strcmp (sel
->string
, cpu
->name
))
683 sparc_cpu
= cpu
->processor
;
687 target_flags
&= ~cpu
->disable
;
688 target_flags
|= cpu
->enable
;
694 error ("bad value (%s) for %s switch", sel
->string
, sel
->name
);
698 /* If -mfpu or -mno-fpu was explicitly used, don't override with
699 the processor default. */
701 target_flags
= (target_flags
& ~MASK_FPU
) | fpu
;
703 /* Don't allow -mvis if FPU is disabled. */
705 target_flags
&= ~MASK_VIS
;
707 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
709 -m64 also implies v9. */
710 if (TARGET_VIS
|| TARGET_ARCH64
)
712 target_flags
|= MASK_V9
;
713 target_flags
&= ~(MASK_V8
| MASK_SPARCLET
| MASK_SPARCLITE
);
716 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
717 if (TARGET_V9
&& TARGET_ARCH32
)
718 target_flags
|= MASK_DEPRECATED_V8_INSNS
;
720 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
721 if (! TARGET_V9
|| TARGET_ARCH64
)
722 target_flags
&= ~MASK_V8PLUS
;
724 /* Don't use stack biasing in 32 bit mode. */
726 target_flags
&= ~MASK_STACK_BIAS
;
728 /* Supply a default value for align_functions. */
729 if (align_functions
== 0
730 && (sparc_cpu
== PROCESSOR_ULTRASPARC
731 || sparc_cpu
== PROCESSOR_ULTRASPARC3
))
732 align_functions
= 32;
734 /* Validate PCC_STRUCT_RETURN. */
735 if (flag_pcc_struct_return
== DEFAULT_PCC_STRUCT_RETURN
)
736 flag_pcc_struct_return
= (TARGET_ARCH64
? 0 : 1);
738 /* Only use .uaxword when compiling for a 64-bit target. */
740 targetm
.asm_out
.unaligned_op
.di
= NULL
;
742 /* Do various machine dependent initializations. */
745 /* Acquire unique alias sets for our private stuff. */
746 sparc_sr_alias_set
= new_alias_set ();
747 struct_value_alias_set
= new_alias_set ();
749 /* Set up function hooks. */
750 init_machine_status
= sparc_init_machine_status
;
755 case PROCESSOR_CYPRESS
:
756 sparc_costs
= &cypress_costs
;
759 case PROCESSOR_SPARCLITE
:
760 case PROCESSOR_SUPERSPARC
:
761 sparc_costs
= &supersparc_costs
;
765 case PROCESSOR_HYPERSPARC
:
766 case PROCESSOR_SPARCLITE86X
:
767 sparc_costs
= &hypersparc_costs
;
769 case PROCESSOR_SPARCLET
:
770 case PROCESSOR_TSC701
:
771 sparc_costs
= &sparclet_costs
;
774 case PROCESSOR_ULTRASPARC
:
775 sparc_costs
= &ultrasparc_costs
;
777 case PROCESSOR_ULTRASPARC3
:
778 sparc_costs
= &ultrasparc3_costs
;
783 #ifdef SUBTARGET_ATTRIBUTE_TABLE
784 /* Table of valid machine attributes. */
785 const struct attribute_spec sparc_attribute_table
[] =
787 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
788 SUBTARGET_ATTRIBUTE_TABLE
,
789 { NULL
, 0, 0, false, false, false, NULL
}
793 /* Miscellaneous utilities. */
795 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
796 or branch on register contents instructions. */
799 v9_regcmp_p (enum rtx_code code
)
801 return (code
== EQ
|| code
== NE
|| code
== GE
|| code
== LT
802 || code
== LE
|| code
== GT
);
806 /* Operand constraints. */
808 /* Nonzero if OP is a floating point constant which can
809 be loaded into an integer register using a single
810 sethi instruction. */
815 if (GET_CODE (op
) == CONST_DOUBLE
)
820 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
821 if (REAL_VALUES_EQUAL (r
, dconst0
) &&
822 ! REAL_VALUE_MINUS_ZERO (r
))
824 REAL_VALUE_TO_TARGET_SINGLE (r
, i
);
825 if (SPARC_SETHI_P (i
))
832 /* Nonzero if OP is a floating point constant which can
833 be loaded into an integer register using a single
839 if (GET_CODE (op
) == CONST_DOUBLE
)
844 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
845 if (REAL_VALUES_EQUAL (r
, dconst0
) &&
846 ! REAL_VALUE_MINUS_ZERO (r
))
848 REAL_VALUE_TO_TARGET_SINGLE (r
, i
);
849 if (SPARC_SIMM13_P (i
))
856 /* Nonzero if OP is a floating point constant which can
857 be loaded into an integer register using a high/losum
858 instruction sequence. */
861 fp_high_losum_p (rtx op
)
863 /* The constraints calling this should only be in
864 SFmode move insns, so any constant which cannot
865 be moved using a single insn will do. */
866 if (GET_CODE (op
) == CONST_DOUBLE
)
871 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
872 if (REAL_VALUES_EQUAL (r
, dconst0
) &&
873 ! REAL_VALUE_MINUS_ZERO (r
))
875 REAL_VALUE_TO_TARGET_SINGLE (r
, i
);
876 if (! SPARC_SETHI_P (i
)
877 && ! SPARC_SIMM13_P (i
))
884 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
885 otherwise return 0. */
888 tls_symbolic_operand (rtx op
)
890 if (GET_CODE (op
) != SYMBOL_REF
)
892 return SYMBOL_REF_TLS_MODEL (op
);
895 /* We know it can't be done in one insn when we get here,
896 the movsi expander guarantees this. */
898 sparc_emit_set_const32 (rtx op0
, rtx op1
)
900 enum machine_mode mode
= GET_MODE (op0
);
903 if (reload_in_progress
|| reload_completed
)
906 temp
= gen_reg_rtx (mode
);
908 if (GET_CODE (op1
) == CONST_INT
)
910 gcc_assert (!small_int_operand (op1
, mode
)
911 && !const_high_operand (op1
, mode
));
913 /* Emit them as real moves instead of a HIGH/LO_SUM,
914 this way CSE can see everything and reuse intermediate
915 values if it wants. */
916 emit_insn (gen_rtx_SET (VOIDmode
, temp
,
917 GEN_INT (INTVAL (op1
)
918 & ~(HOST_WIDE_INT
)0x3ff)));
920 emit_insn (gen_rtx_SET (VOIDmode
,
922 gen_rtx_IOR (mode
, temp
,
923 GEN_INT (INTVAL (op1
) & 0x3ff))));
927 /* A symbol, emit in the traditional way. */
928 emit_insn (gen_rtx_SET (VOIDmode
, temp
,
929 gen_rtx_HIGH (mode
, op1
)));
930 emit_insn (gen_rtx_SET (VOIDmode
,
931 op0
, gen_rtx_LO_SUM (mode
, temp
, op1
)));
936 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
937 If TEMP is nonzero, we are forbidden to use any other scratch
938 registers. Otherwise, we are allowed to generate them as needed.
940 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
941 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
943 sparc_emit_set_symbolic_const64 (rtx op0
, rtx op1
, rtx temp
)
945 rtx temp1
, temp2
, temp3
, temp4
, temp5
;
948 if (temp
&& GET_MODE (temp
) == TImode
)
951 temp
= gen_rtx_REG (DImode
, REGNO (temp
));
954 /* SPARC-V9 code-model support. */
955 switch (sparc_cmodel
)
958 /* The range spanned by all instructions in the object is less
959 than 2^31 bytes (2GB) and the distance from any instruction
960 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
961 than 2^31 bytes (2GB).
963 The executable must be in the low 4TB of the virtual address
966 sethi %hi(symbol), %temp1
967 or %temp1, %lo(symbol), %reg */
969 temp1
= temp
; /* op0 is allowed. */
971 temp1
= gen_reg_rtx (DImode
);
973 emit_insn (gen_rtx_SET (VOIDmode
, temp1
, gen_rtx_HIGH (DImode
, op1
)));
974 emit_insn (gen_rtx_SET (VOIDmode
, op0
, gen_rtx_LO_SUM (DImode
, temp1
, op1
)));
978 /* The range spanned by all instructions in the object is less
979 than 2^31 bytes (2GB) and the distance from any instruction
980 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
981 than 2^31 bytes (2GB).
983 The executable must be in the low 16TB of the virtual address
986 sethi %h44(symbol), %temp1
987 or %temp1, %m44(symbol), %temp2
988 sllx %temp2, 12, %temp3
989 or %temp3, %l44(symbol), %reg */
994 temp3
= temp
; /* op0 is allowed. */
998 temp1
= gen_reg_rtx (DImode
);
999 temp2
= gen_reg_rtx (DImode
);
1000 temp3
= gen_reg_rtx (DImode
);
1003 emit_insn (gen_seth44 (temp1
, op1
));
1004 emit_insn (gen_setm44 (temp2
, temp1
, op1
));
1005 emit_insn (gen_rtx_SET (VOIDmode
, temp3
,
1006 gen_rtx_ASHIFT (DImode
, temp2
, GEN_INT (12))));
1007 emit_insn (gen_setl44 (op0
, temp3
, op1
));
1011 /* The range spanned by all instructions in the object is less
1012 than 2^31 bytes (2GB) and the distance from any instruction
1013 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1014 than 2^31 bytes (2GB).
1016 The executable can be placed anywhere in the virtual address
1019 sethi %hh(symbol), %temp1
1020 sethi %lm(symbol), %temp2
1021 or %temp1, %hm(symbol), %temp3
1022 sllx %temp3, 32, %temp4
1023 or %temp4, %temp2, %temp5
1024 or %temp5, %lo(symbol), %reg */
1027 /* It is possible that one of the registers we got for operands[2]
1028 might coincide with that of operands[0] (which is why we made
1029 it TImode). Pick the other one to use as our scratch. */
1030 if (rtx_equal_p (temp
, op0
))
1032 gcc_assert (ti_temp
);
1033 temp
= gen_rtx_REG (DImode
, REGNO (temp
) + 1);
1036 temp2
= temp
; /* op0 is _not_ allowed, see above. */
1043 temp1
= gen_reg_rtx (DImode
);
1044 temp2
= gen_reg_rtx (DImode
);
1045 temp3
= gen_reg_rtx (DImode
);
1046 temp4
= gen_reg_rtx (DImode
);
1047 temp5
= gen_reg_rtx (DImode
);
1050 emit_insn (gen_sethh (temp1
, op1
));
1051 emit_insn (gen_setlm (temp2
, op1
));
1052 emit_insn (gen_sethm (temp3
, temp1
, op1
));
1053 emit_insn (gen_rtx_SET (VOIDmode
, temp4
,
1054 gen_rtx_ASHIFT (DImode
, temp3
, GEN_INT (32))));
1055 emit_insn (gen_rtx_SET (VOIDmode
, temp5
,
1056 gen_rtx_PLUS (DImode
, temp4
, temp2
)));
1057 emit_insn (gen_setlo (op0
, temp5
, op1
));
1061 /* Old old old backwards compatibility kruft here.
1062 Essentially it is MEDLOW with a fixed 64-bit
1063 virtual base added to all data segment addresses.
1064 Text-segment stuff is computed like MEDANY, we can't
1065 reuse the code above because the relocation knobs
1068 Data segment: sethi %hi(symbol), %temp1
1069 add %temp1, EMBMEDANY_BASE_REG, %temp2
1070 or %temp2, %lo(symbol), %reg */
1071 if (data_segment_operand (op1
, GET_MODE (op1
)))
1075 temp1
= temp
; /* op0 is allowed. */
1080 temp1
= gen_reg_rtx (DImode
);
1081 temp2
= gen_reg_rtx (DImode
);
1084 emit_insn (gen_embmedany_sethi (temp1
, op1
));
1085 emit_insn (gen_embmedany_brsum (temp2
, temp1
));
1086 emit_insn (gen_embmedany_losum (op0
, temp2
, op1
));
1089 /* Text segment: sethi %uhi(symbol), %temp1
1090 sethi %hi(symbol), %temp2
1091 or %temp1, %ulo(symbol), %temp3
1092 sllx %temp3, 32, %temp4
1093 or %temp4, %temp2, %temp5
1094 or %temp5, %lo(symbol), %reg */
1099 /* It is possible that one of the registers we got for operands[2]
1100 might coincide with that of operands[0] (which is why we made
1101 it TImode). Pick the other one to use as our scratch. */
1102 if (rtx_equal_p (temp
, op0
))
1104 gcc_assert (ti_temp
);
1105 temp
= gen_rtx_REG (DImode
, REGNO (temp
) + 1);
1108 temp2
= temp
; /* op0 is _not_ allowed, see above. */
1115 temp1
= gen_reg_rtx (DImode
);
1116 temp2
= gen_reg_rtx (DImode
);
1117 temp3
= gen_reg_rtx (DImode
);
1118 temp4
= gen_reg_rtx (DImode
);
1119 temp5
= gen_reg_rtx (DImode
);
1122 emit_insn (gen_embmedany_textuhi (temp1
, op1
));
1123 emit_insn (gen_embmedany_texthi (temp2
, op1
));
1124 emit_insn (gen_embmedany_textulo (temp3
, temp1
, op1
));
1125 emit_insn (gen_rtx_SET (VOIDmode
, temp4
,
1126 gen_rtx_ASHIFT (DImode
, temp3
, GEN_INT (32))));
1127 emit_insn (gen_rtx_SET (VOIDmode
, temp5
,
1128 gen_rtx_PLUS (DImode
, temp4
, temp2
)));
1129 emit_insn (gen_embmedany_textlo (op0
, temp5
, op1
));
1138 #if HOST_BITS_PER_WIDE_INT == 32
1140 sparc_emit_set_const64 (rtx op0 ATTRIBUTE_UNUSED
, rtx op1 ATTRIBUTE_UNUSED
)
1145 /* These avoid problems when cross compiling. If we do not
1146 go through all this hair then the optimizer will see
1147 invalid REG_EQUAL notes or in some cases none at all. */
1148 static void sparc_emit_set_safe_HIGH64 (rtx
, HOST_WIDE_INT
);
1149 static rtx
gen_safe_SET64 (rtx
, HOST_WIDE_INT
);
1150 static rtx
gen_safe_OR64 (rtx
, HOST_WIDE_INT
);
1151 static rtx
gen_safe_XOR64 (rtx
, HOST_WIDE_INT
);
1153 /* The optimizer is not to assume anything about exactly
1154 which bits are set for a HIGH, they are unspecified.
1155 Unfortunately this leads to many missed optimizations
1156 during CSE. We mask out the non-HIGH bits, and matches
1157 a plain movdi, to alleviate this problem. */
1159 sparc_emit_set_safe_HIGH64 (rtx dest
, HOST_WIDE_INT val
)
1161 emit_insn (gen_rtx_SET (VOIDmode
, dest
, GEN_INT (val
& ~(HOST_WIDE_INT
)0x3ff)));
1165 gen_safe_SET64 (rtx dest
, HOST_WIDE_INT val
)
1167 return gen_rtx_SET (VOIDmode
, dest
, GEN_INT (val
));
1171 gen_safe_OR64 (rtx src
, HOST_WIDE_INT val
)
1173 return gen_rtx_IOR (DImode
, src
, GEN_INT (val
));
1177 gen_safe_XOR64 (rtx src
, HOST_WIDE_INT val
)
1179 return gen_rtx_XOR (DImode
, src
, GEN_INT (val
));
1182 /* Worker routines for 64-bit constant formation on arch64.
1183 One of the key things to be doing in these emissions is
1184 to create as many temp REGs as possible. This makes it
1185 possible for half-built constants to be used later when
1186 such values are similar to something required later on.
1187 Without doing this, the optimizer cannot see such
1190 static void sparc_emit_set_const64_quick1 (rtx
, rtx
,
1191 unsigned HOST_WIDE_INT
, int);
1194 sparc_emit_set_const64_quick1 (rtx op0
, rtx temp
,
1195 unsigned HOST_WIDE_INT low_bits
, int is_neg
)
1197 unsigned HOST_WIDE_INT high_bits
;
1200 high_bits
= (~low_bits
) & 0xffffffff;
1202 high_bits
= low_bits
;
1204 sparc_emit_set_safe_HIGH64 (temp
, high_bits
);
1207 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1208 gen_safe_OR64 (temp
, (high_bits
& 0x3ff))));
1212 /* If we are XOR'ing with -1, then we should emit a one's complement
1213 instead. This way the combiner will notice logical operations
1214 such as ANDN later on and substitute. */
1215 if ((low_bits
& 0x3ff) == 0x3ff)
1217 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1218 gen_rtx_NOT (DImode
, temp
)));
1222 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1223 gen_safe_XOR64 (temp
,
1224 (-(HOST_WIDE_INT
)0x400
1225 | (low_bits
& 0x3ff)))));
1230 static void sparc_emit_set_const64_quick2 (rtx
, rtx
, unsigned HOST_WIDE_INT
,
1231 unsigned HOST_WIDE_INT
, int);
1234 sparc_emit_set_const64_quick2 (rtx op0
, rtx temp
,
1235 unsigned HOST_WIDE_INT high_bits
,
1236 unsigned HOST_WIDE_INT low_immediate
,
1241 if ((high_bits
& 0xfffffc00) != 0)
1243 sparc_emit_set_safe_HIGH64 (temp
, high_bits
);
1244 if ((high_bits
& ~0xfffffc00) != 0)
1245 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1246 gen_safe_OR64 (temp
, (high_bits
& 0x3ff))));
1252 emit_insn (gen_safe_SET64 (temp
, high_bits
));
1256 /* Now shift it up into place. */
1257 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1258 gen_rtx_ASHIFT (DImode
, temp2
,
1259 GEN_INT (shift_count
))));
1261 /* If there is a low immediate part piece, finish up by
1262 putting that in as well. */
1263 if (low_immediate
!= 0)
1264 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1265 gen_safe_OR64 (op0
, low_immediate
)));
1268 static void sparc_emit_set_const64_longway (rtx
, rtx
, unsigned HOST_WIDE_INT
,
1269 unsigned HOST_WIDE_INT
);
1271 /* Full 64-bit constant decomposition. Even though this is the
1272 'worst' case, we still optimize a few things away. */
1274 sparc_emit_set_const64_longway (rtx op0
, rtx temp
,
1275 unsigned HOST_WIDE_INT high_bits
,
1276 unsigned HOST_WIDE_INT low_bits
)
1280 if (reload_in_progress
|| reload_completed
)
1283 sub_temp
= gen_reg_rtx (DImode
);
1285 if ((high_bits
& 0xfffffc00) != 0)
1287 sparc_emit_set_safe_HIGH64 (temp
, high_bits
);
1288 if ((high_bits
& ~0xfffffc00) != 0)
1289 emit_insn (gen_rtx_SET (VOIDmode
,
1291 gen_safe_OR64 (temp
, (high_bits
& 0x3ff))));
1297 emit_insn (gen_safe_SET64 (temp
, high_bits
));
1301 if (!reload_in_progress
&& !reload_completed
)
1303 rtx temp2
= gen_reg_rtx (DImode
);
1304 rtx temp3
= gen_reg_rtx (DImode
);
1305 rtx temp4
= gen_reg_rtx (DImode
);
1307 emit_insn (gen_rtx_SET (VOIDmode
, temp4
,
1308 gen_rtx_ASHIFT (DImode
, sub_temp
,
1311 sparc_emit_set_safe_HIGH64 (temp2
, low_bits
);
1312 if ((low_bits
& ~0xfffffc00) != 0)
1314 emit_insn (gen_rtx_SET (VOIDmode
, temp3
,
1315 gen_safe_OR64 (temp2
, (low_bits
& 0x3ff))));
1316 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1317 gen_rtx_PLUS (DImode
, temp4
, temp3
)));
1321 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1322 gen_rtx_PLUS (DImode
, temp4
, temp2
)));
1327 rtx low1
= GEN_INT ((low_bits
>> (32 - 12)) & 0xfff);
1328 rtx low2
= GEN_INT ((low_bits
>> (32 - 12 - 12)) & 0xfff);
1329 rtx low3
= GEN_INT ((low_bits
>> (32 - 12 - 12 - 8)) & 0x0ff);
1332 /* We are in the middle of reload, so this is really
1333 painful. However we do still make an attempt to
1334 avoid emitting truly stupid code. */
1335 if (low1
!= 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
, low1
)));
1349 if (low2
!= const0_rtx
)
1351 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1352 gen_rtx_ASHIFT (DImode
, sub_temp
,
1353 GEN_INT (to_shift
))));
1354 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1355 gen_rtx_IOR (DImode
, op0
, low2
)));
1363 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1364 gen_rtx_ASHIFT (DImode
, sub_temp
,
1365 GEN_INT (to_shift
))));
1366 if (low3
!= const0_rtx
)
1367 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1368 gen_rtx_IOR (DImode
, op0
, low3
)));
1373 /* Analyze a 64-bit constant for certain properties. */
1374 static void analyze_64bit_constant (unsigned HOST_WIDE_INT
,
1375 unsigned HOST_WIDE_INT
,
1376 int *, int *, int *);
1379 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits
,
1380 unsigned HOST_WIDE_INT low_bits
,
1381 int *hbsp
, int *lbsp
, int *abbasp
)
1383 int lowest_bit_set
, highest_bit_set
, all_bits_between_are_set
;
1386 lowest_bit_set
= highest_bit_set
= -1;
1390 if ((lowest_bit_set
== -1)
1391 && ((low_bits
>> i
) & 1))
1393 if ((highest_bit_set
== -1)
1394 && ((high_bits
>> (32 - i
- 1)) & 1))
1395 highest_bit_set
= (64 - i
- 1);
1398 && ((highest_bit_set
== -1)
1399 || (lowest_bit_set
== -1)));
1405 if ((lowest_bit_set
== -1)
1406 && ((high_bits
>> i
) & 1))
1407 lowest_bit_set
= i
+ 32;
1408 if ((highest_bit_set
== -1)
1409 && ((low_bits
>> (32 - i
- 1)) & 1))
1410 highest_bit_set
= 32 - i
- 1;
1413 && ((highest_bit_set
== -1)
1414 || (lowest_bit_set
== -1)));
1416 /* If there are no bits set this should have gone out
1417 as one instruction! */
1418 gcc_assert (lowest_bit_set
!= -1 && highest_bit_set
!= -1);
1419 all_bits_between_are_set
= 1;
1420 for (i
= lowest_bit_set
; i
<= highest_bit_set
; i
++)
1424 if ((low_bits
& (1 << i
)) != 0)
1429 if ((high_bits
& (1 << (i
- 32))) != 0)
1432 all_bits_between_are_set
= 0;
1435 *hbsp
= highest_bit_set
;
1436 *lbsp
= lowest_bit_set
;
1437 *abbasp
= all_bits_between_are_set
;
1440 static int const64_is_2insns (unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
1443 const64_is_2insns (unsigned HOST_WIDE_INT high_bits
,
1444 unsigned HOST_WIDE_INT low_bits
)
1446 int highest_bit_set
, lowest_bit_set
, all_bits_between_are_set
;
1449 || high_bits
== 0xffffffff)
1452 analyze_64bit_constant (high_bits
, low_bits
,
1453 &highest_bit_set
, &lowest_bit_set
,
1454 &all_bits_between_are_set
);
1456 if ((highest_bit_set
== 63
1457 || lowest_bit_set
== 0)
1458 && all_bits_between_are_set
!= 0)
1461 if ((highest_bit_set
- lowest_bit_set
) < 21)
1467 static unsigned HOST_WIDE_INT
create_simple_focus_bits (unsigned HOST_WIDE_INT
,
1468 unsigned HOST_WIDE_INT
,
1471 static unsigned HOST_WIDE_INT
1472 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits
,
1473 unsigned HOST_WIDE_INT low_bits
,
1474 int lowest_bit_set
, int shift
)
1476 HOST_WIDE_INT hi
, lo
;
1478 if (lowest_bit_set
< 32)
1480 lo
= (low_bits
>> lowest_bit_set
) << shift
;
1481 hi
= ((high_bits
<< (32 - lowest_bit_set
)) << shift
);
1486 hi
= ((high_bits
>> (lowest_bit_set
- 32)) << shift
);
1488 gcc_assert (! (hi
& lo
));
1492 /* Here we are sure to be arch64 and this is an integer constant
1493 being loaded into a register. Emit the most efficient
1494 insn sequence possible. Detection of all the 1-insn cases
1495 has been done already. */
1497 sparc_emit_set_const64 (rtx op0
, rtx op1
)
1499 unsigned HOST_WIDE_INT high_bits
, low_bits
;
1500 int lowest_bit_set
, highest_bit_set
;
1501 int all_bits_between_are_set
;
1504 /* Sanity check that we know what we are working with. */
1505 gcc_assert (TARGET_ARCH64
);
1507 if (GET_CODE (op0
) != SUBREG
)
1509 gcc_assert (GET_CODE (op0
) == REG
1510 && (REGNO (op0
) < SPARC_FIRST_FP_REG
1511 || REGNO (op0
) > SPARC_LAST_V9_FP_REG
));
1514 if (reload_in_progress
|| reload_completed
)
1517 if (GET_CODE (op1
) != CONST_INT
)
1519 sparc_emit_set_symbolic_const64 (op0
, op1
, temp
);
1524 temp
= gen_reg_rtx (DImode
);
1526 high_bits
= ((INTVAL (op1
) >> 32) & 0xffffffff);
1527 low_bits
= (INTVAL (op1
) & 0xffffffff);
1529 /* low_bits bits 0 --> 31
1530 high_bits bits 32 --> 63 */
1532 analyze_64bit_constant (high_bits
, low_bits
,
1533 &highest_bit_set
, &lowest_bit_set
,
1534 &all_bits_between_are_set
);
1536 /* First try for a 2-insn sequence. */
1538 /* These situations are preferred because the optimizer can
1539 * do more things with them:
1541 * sllx %reg, shift, %reg
1543 * srlx %reg, shift, %reg
1544 * 3) mov some_small_const, %reg
1545 * sllx %reg, shift, %reg
1547 if (((highest_bit_set
== 63
1548 || lowest_bit_set
== 0)
1549 && all_bits_between_are_set
!= 0)
1550 || ((highest_bit_set
- lowest_bit_set
) < 12))
1552 HOST_WIDE_INT the_const
= -1;
1553 int shift
= lowest_bit_set
;
1555 if ((highest_bit_set
!= 63
1556 && lowest_bit_set
!= 0)
1557 || all_bits_between_are_set
== 0)
1560 create_simple_focus_bits (high_bits
, low_bits
,
1563 else if (lowest_bit_set
== 0)
1564 shift
= -(63 - highest_bit_set
);
1566 gcc_assert (SPARC_SIMM13_P (the_const
));
1567 gcc_assert (shift
!= 0);
1569 emit_insn (gen_safe_SET64 (temp
, the_const
));
1571 emit_insn (gen_rtx_SET (VOIDmode
,
1573 gen_rtx_ASHIFT (DImode
,
1577 emit_insn (gen_rtx_SET (VOIDmode
,
1579 gen_rtx_LSHIFTRT (DImode
,
1581 GEN_INT (-shift
))));
1585 /* Now a range of 22 or less bits set somewhere.
1586 * 1) sethi %hi(focus_bits), %reg
1587 * sllx %reg, shift, %reg
1588 * 2) sethi %hi(focus_bits), %reg
1589 * srlx %reg, shift, %reg
1591 if ((highest_bit_set
- lowest_bit_set
) < 21)
1593 unsigned HOST_WIDE_INT focus_bits
=
1594 create_simple_focus_bits (high_bits
, low_bits
,
1595 lowest_bit_set
, 10);
1597 gcc_assert (SPARC_SETHI_P (focus_bits
));
1598 gcc_assert (lowest_bit_set
!= 10);
1600 sparc_emit_set_safe_HIGH64 (temp
, focus_bits
);
1602 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
1603 if (lowest_bit_set
< 10)
1604 emit_insn (gen_rtx_SET (VOIDmode
,
1606 gen_rtx_LSHIFTRT (DImode
, temp
,
1607 GEN_INT (10 - lowest_bit_set
))));
1608 else if (lowest_bit_set
> 10)
1609 emit_insn (gen_rtx_SET (VOIDmode
,
1611 gen_rtx_ASHIFT (DImode
, temp
,
1612 GEN_INT (lowest_bit_set
- 10))));
1616 /* 1) sethi %hi(low_bits), %reg
1617 * or %reg, %lo(low_bits), %reg
1618 * 2) sethi %hi(~low_bits), %reg
1619 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
1622 || high_bits
== 0xffffffff)
1624 sparc_emit_set_const64_quick1 (op0
, temp
, low_bits
,
1625 (high_bits
== 0xffffffff));
1629 /* Now, try 3-insn sequences. */
1631 /* 1) sethi %hi(high_bits), %reg
1632 * or %reg, %lo(high_bits), %reg
1633 * sllx %reg, 32, %reg
1637 sparc_emit_set_const64_quick2 (op0
, temp
, high_bits
, 0, 32);
1641 /* We may be able to do something quick
1642 when the constant is negated, so try that. */
1643 if (const64_is_2insns ((~high_bits
) & 0xffffffff,
1644 (~low_bits
) & 0xfffffc00))
1646 /* NOTE: The trailing bits get XOR'd so we need the
1647 non-negated bits, not the negated ones. */
1648 unsigned HOST_WIDE_INT trailing_bits
= low_bits
& 0x3ff;
1650 if ((((~high_bits
) & 0xffffffff) == 0
1651 && ((~low_bits
) & 0x80000000) == 0)
1652 || (((~high_bits
) & 0xffffffff) == 0xffffffff
1653 && ((~low_bits
) & 0x80000000) != 0))
1655 unsigned HOST_WIDE_INT fast_int
= (~low_bits
& 0xffffffff);
1657 if ((SPARC_SETHI_P (fast_int
)
1658 && (~high_bits
& 0xffffffff) == 0)
1659 || SPARC_SIMM13_P (fast_int
))
1660 emit_insn (gen_safe_SET64 (temp
, fast_int
));
1662 sparc_emit_set_const64 (temp
, GEN_INT (fast_int
));
1667 negated_const
= GEN_INT (((~low_bits
) & 0xfffffc00) |
1668 (((HOST_WIDE_INT
)((~high_bits
) & 0xffffffff))<<32));
1669 sparc_emit_set_const64 (temp
, negated_const
);
1672 /* If we are XOR'ing with -1, then we should emit a one's complement
1673 instead. This way the combiner will notice logical operations
1674 such as ANDN later on and substitute. */
1675 if (trailing_bits
== 0x3ff)
1677 emit_insn (gen_rtx_SET (VOIDmode
, op0
,
1678 gen_rtx_NOT (DImode
, temp
)));
1682 emit_insn (gen_rtx_SET (VOIDmode
,
1684 gen_safe_XOR64 (temp
,
1685 (-0x400 | trailing_bits
))));
1690 /* 1) sethi %hi(xxx), %reg
1691 * or %reg, %lo(xxx), %reg
1692 * sllx %reg, yyy, %reg
1694 * ??? This is just a generalized version of the low_bits==0
1695 * thing above, FIXME...
1697 if ((highest_bit_set
- lowest_bit_set
) < 32)
1699 unsigned HOST_WIDE_INT focus_bits
=
1700 create_simple_focus_bits (high_bits
, low_bits
,
1703 /* We can't get here in this state. */
1704 gcc_assert (highest_bit_set
>= 32 && lowest_bit_set
< 32);
1706 /* So what we know is that the set bits straddle the
1707 middle of the 64-bit word. */
1708 sparc_emit_set_const64_quick2 (op0
, temp
,
1714 /* 1) sethi %hi(high_bits), %reg
1715 * or %reg, %lo(high_bits), %reg
1716 * sllx %reg, 32, %reg
1717 * or %reg, low_bits, %reg
1719 if (SPARC_SIMM13_P(low_bits
)
1720 && ((int)low_bits
> 0))
1722 sparc_emit_set_const64_quick2 (op0
, temp
, high_bits
, low_bits
, 32);
1726 /* The easiest way when all else fails, is full decomposition. */
1728 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
1729 high_bits
, low_bits
, ~high_bits
, ~low_bits
);
1731 sparc_emit_set_const64_longway (op0
, temp
, high_bits
, low_bits
);
1733 #endif /* HOST_BITS_PER_WIDE_INT == 32 */
1735 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
1736 return the mode to be used for the comparison. For floating-point,
1737 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
1738 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
1739 processing is needed. */
1742 select_cc_mode (enum rtx_code op
, rtx x
, rtx y ATTRIBUTE_UNUSED
)
1744 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1770 else if (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
1771 || GET_CODE (x
) == NEG
|| GET_CODE (x
) == ASHIFT
)
1773 if (TARGET_ARCH64
&& GET_MODE (x
) == DImode
)
1774 return CCX_NOOVmode
;
1780 if (TARGET_ARCH64
&& GET_MODE (x
) == DImode
)
1787 /* X and Y are two things to compare using CODE. Emit the compare insn and
1788 return the rtx for the cc reg in the proper mode. */
1791 gen_compare_reg (enum rtx_code code
, rtx x
, rtx y
)
1793 enum machine_mode mode
= SELECT_CC_MODE (code
, x
, y
);
1796 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
1797 fcc regs (cse can't tell they're really call clobbered regs and will
1798 remove a duplicate comparison even if there is an intervening function
1799 call - it will then try to reload the cc reg via an int reg which is why
1800 we need the movcc patterns). It is possible to provide the movcc
1801 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
1802 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
1803 to tell cse that CCFPE mode registers (even pseudos) are call
1806 /* ??? This is an experiment. Rather than making changes to cse which may
1807 or may not be easy/clean, we do our own cse. This is possible because
1808 we will generate hard registers. Cse knows they're call clobbered (it
1809 doesn't know the same thing about pseudos). If we guess wrong, no big
1810 deal, but if we win, great! */
1812 if (TARGET_V9
&& GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1813 #if 1 /* experiment */
1816 /* We cycle through the registers to ensure they're all exercised. */
1817 static int next_fcc_reg
= 0;
1818 /* Previous x,y for each fcc reg. */
1819 static rtx prev_args
[4][2];
1821 /* Scan prev_args for x,y. */
1822 for (reg
= 0; reg
< 4; reg
++)
1823 if (prev_args
[reg
][0] == x
&& prev_args
[reg
][1] == y
)
1828 prev_args
[reg
][0] = x
;
1829 prev_args
[reg
][1] = y
;
1830 next_fcc_reg
= (next_fcc_reg
+ 1) & 3;
1832 cc_reg
= gen_rtx_REG (mode
, reg
+ SPARC_FIRST_V9_FCC_REG
);
1835 cc_reg
= gen_reg_rtx (mode
);
1836 #endif /* ! experiment */
1837 else if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1838 cc_reg
= gen_rtx_REG (mode
, SPARC_FCC_REG
);
1840 cc_reg
= gen_rtx_REG (mode
, SPARC_ICC_REG
);
1842 emit_insn (gen_rtx_SET (VOIDmode
, cc_reg
,
1843 gen_rtx_COMPARE (mode
, x
, y
)));
1848 /* This function is used for v9 only.
1849 CODE is the code for an Scc's comparison.
1850 OPERANDS[0] is the target of the Scc insn.
1851 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
1852 been generated yet).
1854 This function is needed to turn
1857 (gt (reg:CCX 100 %icc)
1861 (gt:DI (reg:CCX 100 %icc)
1864 IE: The instruction recognizer needs to see the mode of the comparison to
1865 find the right instruction. We could use "gt:DI" right in the
1866 define_expand, but leaving it out allows us to handle DI, SI, etc.
1868 We refer to the global sparc compare operands sparc_compare_op0 and
1869 sparc_compare_op1. */
1872 gen_v9_scc (enum rtx_code compare_code
, register rtx
*operands
)
1877 && (GET_MODE (sparc_compare_op0
) == DImode
1878 || GET_MODE (operands
[0]) == DImode
))
1881 op0
= sparc_compare_op0
;
1882 op1
= sparc_compare_op1
;
1884 /* Try to use the movrCC insns. */
1886 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
1887 && op1
== const0_rtx
1888 && v9_regcmp_p (compare_code
))
1890 /* Special case for op0 != 0. This can be done with one instruction if
1891 operands[0] == sparc_compare_op0. */
1893 if (compare_code
== NE
1894 && GET_MODE (operands
[0]) == DImode
1895 && rtx_equal_p (op0
, operands
[0]))
1897 emit_insn (gen_rtx_SET (VOIDmode
, operands
[0],
1898 gen_rtx_IF_THEN_ELSE (DImode
,
1899 gen_rtx_fmt_ee (compare_code
, DImode
,
1906 if (reg_overlap_mentioned_p (operands
[0], op0
))
1908 /* Handle the case where operands[0] == sparc_compare_op0.
1909 We "early clobber" the result. */
1910 op0
= gen_reg_rtx (GET_MODE (sparc_compare_op0
));
1911 emit_move_insn (op0
, sparc_compare_op0
);
1914 emit_insn (gen_rtx_SET (VOIDmode
, operands
[0], const0_rtx
));
1915 if (GET_MODE (op0
) != DImode
)
1917 temp
= gen_reg_rtx (DImode
);
1918 convert_move (temp
, op0
, 0);
1922 emit_insn (gen_rtx_SET (VOIDmode
, operands
[0],
1923 gen_rtx_IF_THEN_ELSE (GET_MODE (operands
[0]),
1924 gen_rtx_fmt_ee (compare_code
, DImode
,
1932 operands
[1] = gen_compare_reg (compare_code
, op0
, op1
);
1934 switch (GET_MODE (operands
[1]))
1944 emit_insn (gen_rtx_SET (VOIDmode
, operands
[0], const0_rtx
));
1945 emit_insn (gen_rtx_SET (VOIDmode
, operands
[0],
1946 gen_rtx_IF_THEN_ELSE (GET_MODE (operands
[0]),
1947 gen_rtx_fmt_ee (compare_code
,
1948 GET_MODE (operands
[1]),
1949 operands
[1], const0_rtx
),
1950 const1_rtx
, operands
[0])));
1955 /* Emit a conditional jump insn for the v9 architecture using comparison code
1956 CODE and jump target LABEL.
1957 This function exists to take advantage of the v9 brxx insns. */
1960 emit_v9_brxx_insn (enum rtx_code code
, rtx op0
, rtx label
)
1962 emit_jump_insn (gen_rtx_SET (VOIDmode
,
1964 gen_rtx_IF_THEN_ELSE (VOIDmode
,
1965 gen_rtx_fmt_ee (code
, GET_MODE (op0
),
1967 gen_rtx_LABEL_REF (VOIDmode
, label
),
1971 /* Generate a DFmode part of a hard TFmode register.
1972 REG is the TFmode hard register, LOW is 1 for the
1973 low 64bit of the register and 0 otherwise.
1976 gen_df_reg (rtx reg
, int low
)
1978 int regno
= REGNO (reg
);
1980 if ((WORDS_BIG_ENDIAN
== 0) ^ (low
!= 0))
1981 regno
+= (TARGET_ARCH64
&& regno
< 32) ? 1 : 2;
1982 return gen_rtx_REG (DFmode
, regno
);
1985 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
1986 Unlike normal calls, TFmode operands are passed by reference. It is
1987 assumed that no more than 3 operands are required. */
1990 emit_soft_tfmode_libcall (const char *func_name
, int nargs
, rtx
*operands
)
1992 rtx ret_slot
= NULL
, arg
[3], func_sym
;
1995 /* We only expect to be called for conversions, unary, and binary ops. */
1996 gcc_assert (nargs
== 2 || nargs
== 3);
1998 for (i
= 0; i
< nargs
; ++i
)
2000 rtx this_arg
= operands
[i
];
2003 /* TFmode arguments and return values are passed by reference. */
2004 if (GET_MODE (this_arg
) == TFmode
)
2006 int force_stack_temp
;
2008 force_stack_temp
= 0;
2009 if (TARGET_BUGGY_QP_LIB
&& i
== 0)
2010 force_stack_temp
= 1;
2012 if (GET_CODE (this_arg
) == MEM
2013 && ! force_stack_temp
)
2014 this_arg
= XEXP (this_arg
, 0);
2015 else if (CONSTANT_P (this_arg
)
2016 && ! force_stack_temp
)
2018 this_slot
= force_const_mem (TFmode
, this_arg
);
2019 this_arg
= XEXP (this_slot
, 0);
2023 this_slot
= assign_stack_temp (TFmode
, GET_MODE_SIZE (TFmode
), 0);
2025 /* Operand 0 is the return value. We'll copy it out later. */
2027 emit_move_insn (this_slot
, this_arg
);
2029 ret_slot
= this_slot
;
2031 this_arg
= XEXP (this_slot
, 0);
2038 func_sym
= gen_rtx_SYMBOL_REF (Pmode
, func_name
);
2040 if (GET_MODE (operands
[0]) == TFmode
)
2043 emit_library_call (func_sym
, LCT_NORMAL
, VOIDmode
, 2,
2044 arg
[0], GET_MODE (arg
[0]),
2045 arg
[1], GET_MODE (arg
[1]));
2047 emit_library_call (func_sym
, LCT_NORMAL
, VOIDmode
, 3,
2048 arg
[0], GET_MODE (arg
[0]),
2049 arg
[1], GET_MODE (arg
[1]),
2050 arg
[2], GET_MODE (arg
[2]));
2053 emit_move_insn (operands
[0], ret_slot
);
2059 gcc_assert (nargs
== 2);
2061 ret
= emit_library_call_value (func_sym
, operands
[0], LCT_NORMAL
,
2062 GET_MODE (operands
[0]), 1,
2063 arg
[1], GET_MODE (arg
[1]));
2065 if (ret
!= operands
[0])
2066 emit_move_insn (operands
[0], ret
);
2070 /* Expand soft-float TFmode calls to sparc abi routines. */
2073 emit_soft_tfmode_binop (enum rtx_code code
, rtx
*operands
)
2095 emit_soft_tfmode_libcall (func
, 3, operands
);
2099 emit_soft_tfmode_unop (enum rtx_code code
, rtx
*operands
)
2103 gcc_assert (code
== SQRT
);
2106 emit_soft_tfmode_libcall (func
, 2, operands
);
2110 emit_soft_tfmode_cvt (enum rtx_code code
, rtx
*operands
)
2117 switch (GET_MODE (operands
[1]))
2130 case FLOAT_TRUNCATE
:
2131 switch (GET_MODE (operands
[0]))
2145 switch (GET_MODE (operands
[1]))
2158 case UNSIGNED_FLOAT
:
2159 switch (GET_MODE (operands
[1]))
2173 switch (GET_MODE (operands
[0]))
2187 switch (GET_MODE (operands
[0]))
2204 emit_soft_tfmode_libcall (func
, 2, operands
);
2207 /* Expand a hard-float tfmode operation. All arguments must be in
2211 emit_hard_tfmode_operation (enum rtx_code code
, rtx
*operands
)
2215 if (GET_RTX_CLASS (code
) == RTX_UNARY
)
2217 operands
[1] = force_reg (GET_MODE (operands
[1]), operands
[1]);
2218 op
= gen_rtx_fmt_e (code
, GET_MODE (operands
[0]), operands
[1]);
2222 operands
[1] = force_reg (GET_MODE (operands
[1]), operands
[1]);
2223 operands
[2] = force_reg (GET_MODE (operands
[2]), operands
[2]);
2224 op
= gen_rtx_fmt_ee (code
, GET_MODE (operands
[0]),
2225 operands
[1], operands
[2]);
2228 if (register_operand (operands
[0], VOIDmode
))
2231 dest
= gen_reg_rtx (GET_MODE (operands
[0]));
2233 emit_insn (gen_rtx_SET (VOIDmode
, dest
, op
));
2235 if (dest
!= operands
[0])
2236 emit_move_insn (operands
[0], dest
);
2240 emit_tfmode_binop (enum rtx_code code
, rtx
*operands
)
2242 if (TARGET_HARD_QUAD
)
2243 emit_hard_tfmode_operation (code
, operands
);
2245 emit_soft_tfmode_binop (code
, operands
);
2249 emit_tfmode_unop (enum rtx_code code
, rtx
*operands
)
2251 if (TARGET_HARD_QUAD
)
2252 emit_hard_tfmode_operation (code
, operands
);
2254 emit_soft_tfmode_unop (code
, operands
);
2258 emit_tfmode_cvt (enum rtx_code code
, rtx
*operands
)
2260 if (TARGET_HARD_QUAD
)
2261 emit_hard_tfmode_operation (code
, operands
);
2263 emit_soft_tfmode_cvt (code
, operands
);
2266 /* Return nonzero if a branch/jump/call instruction will be emitting
2267 nop into its delay slot. */
2270 empty_delay_slot (rtx insn
)
2274 /* If no previous instruction (should not happen), return true. */
2275 if (PREV_INSN (insn
) == NULL
)
2278 seq
= NEXT_INSN (PREV_INSN (insn
));
2279 if (GET_CODE (PATTERN (seq
)) == SEQUENCE
)
2285 /* Return nonzero if TRIAL can go into the call delay slot. */
2288 tls_call_delay (rtx trial
)
2293 call __tls_get_addr, %tgd_call (foo)
2294 add %l7, %o0, %o0, %tgd_add (foo)
2295 while Sun as/ld does not. */
2296 if (TARGET_GNU_TLS
|| !TARGET_TLS
)
2299 pat
= PATTERN (trial
);
2300 if (GET_CODE (pat
) != SET
|| GET_CODE (SET_DEST (pat
)) != PLUS
)
2303 unspec
= XEXP (SET_DEST (pat
), 1);
2304 if (GET_CODE (unspec
) != UNSPEC
2305 || (XINT (unspec
, 1) != UNSPEC_TLSGD
2306 && XINT (unspec
, 1) != UNSPEC_TLSLDM
))
2312 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
2313 instruction. RETURN_P is true if the v9 variant 'return' is to be
2314 considered in the test too.
2316 TRIAL must be a SET whose destination is a REG appropriate for the
2317 'restore' instruction or, if RETURN_P is true, for the 'return'
2321 eligible_for_restore_insn (rtx trial
, bool return_p
)
2323 rtx pat
= PATTERN (trial
);
2324 rtx src
= SET_SRC (pat
);
2326 /* The 'restore src,%g0,dest' pattern for word mode and below. */
2327 if (GET_MODE_CLASS (GET_MODE (src
)) != MODE_FLOAT
2328 && arith_operand (src
, GET_MODE (src
)))
2331 return GET_MODE_SIZE (GET_MODE (src
)) <= GET_MODE_SIZE (DImode
);
2333 return GET_MODE_SIZE (GET_MODE (src
)) <= GET_MODE_SIZE (SImode
);
2336 /* The 'restore src,%g0,dest' pattern for double-word mode. */
2337 else if (GET_MODE_CLASS (GET_MODE (src
)) != MODE_FLOAT
2338 && arith_double_operand (src
, GET_MODE (src
)))
2339 return GET_MODE_SIZE (GET_MODE (src
)) <= GET_MODE_SIZE (DImode
);
2341 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
2342 else if (! TARGET_FPU
&& register_operand (src
, SFmode
))
2345 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
2346 else if (! TARGET_FPU
&& TARGET_ARCH64
&& register_operand (src
, DFmode
))
2349 /* If we have the 'return' instruction, anything that does not use
2350 local or output registers and can go into a delay slot wins. */
2351 else if (return_p
&& TARGET_V9
&& ! epilogue_renumber (&pat
, 1)
2352 && (get_attr_in_uncond_branch_delay (trial
)
2353 == IN_UNCOND_BRANCH_DELAY_TRUE
))
2356 /* The 'restore src1,src2,dest' pattern for SImode. */
2357 else if (GET_CODE (src
) == PLUS
2358 && register_operand (XEXP (src
, 0), SImode
)
2359 && arith_operand (XEXP (src
, 1), SImode
))
2362 /* The 'restore src1,src2,dest' pattern for DImode. */
2363 else if (GET_CODE (src
) == PLUS
2364 && register_operand (XEXP (src
, 0), DImode
)
2365 && arith_double_operand (XEXP (src
, 1), DImode
))
2368 /* The 'restore src1,%lo(src2),dest' pattern. */
2369 else if (GET_CODE (src
) == LO_SUM
2370 && ! TARGET_CM_MEDMID
2371 && ((register_operand (XEXP (src
, 0), SImode
)
2372 && immediate_operand (XEXP (src
, 1), SImode
))
2374 && register_operand (XEXP (src
, 0), DImode
)
2375 && immediate_operand (XEXP (src
, 1), DImode
))))
2378 /* The 'restore src,src,dest' pattern. */
2379 else if (GET_CODE (src
) == ASHIFT
2380 && (register_operand (XEXP (src
, 0), SImode
)
2381 || register_operand (XEXP (src
, 0), DImode
))
2382 && XEXP (src
, 1) == const1_rtx
)
2388 /* Return nonzero if TRIAL can go into the function return's
2392 eligible_for_return_delay (rtx trial
)
2396 if (GET_CODE (trial
) != INSN
|| GET_CODE (PATTERN (trial
)) != SET
)
2399 if (get_attr_length (trial
) != 1)
2402 /* If there are any call-saved registers, we should scan TRIAL if it
2403 does not reference them. For now just make it easy. */
2407 /* If the function uses __builtin_eh_return, the eh_return machinery
2408 occupies the delay slot. */
2409 if (current_function_calls_eh_return
)
2412 /* In the case of a true leaf function, anything can go into the slot. */
2413 if (sparc_leaf_function_p
)
2414 return get_attr_in_uncond_branch_delay (trial
)
2415 == IN_UNCOND_BRANCH_DELAY_TRUE
;
2417 pat
= PATTERN (trial
);
2419 /* Otherwise, only operations which can be done in tandem with
2420 a `restore' or `return' insn can go into the delay slot. */
2421 if (GET_CODE (SET_DEST (pat
)) != REG
2422 || (REGNO (SET_DEST (pat
)) >= 8 && REGNO (SET_DEST (pat
)) < 24))
2425 /* If this instruction sets up floating point register and we have a return
2426 instruction, it can probably go in. But restore will not work
2428 if (REGNO (SET_DEST (pat
)) >= 32)
2430 && ! epilogue_renumber (&pat
, 1)
2431 && (get_attr_in_uncond_branch_delay (trial
)
2432 == IN_UNCOND_BRANCH_DELAY_TRUE
));
2434 return eligible_for_restore_insn (trial
, true);
2437 /* Return nonzero if TRIAL can go into the sibling call's
2441 eligible_for_sibcall_delay (rtx trial
)
2445 if (GET_CODE (trial
) != INSN
|| GET_CODE (PATTERN (trial
)) != SET
)
2448 if (get_attr_length (trial
) != 1)
2451 pat
= PATTERN (trial
);
2453 if (sparc_leaf_function_p
)
2455 /* If the tail call is done using the call instruction,
2456 we have to restore %o7 in the delay slot. */
2457 if (LEAF_SIBCALL_SLOT_RESERVED_P
)
2460 /* %g1 is used to build the function address */
2461 if (reg_mentioned_p (gen_rtx_REG (Pmode
, 1), pat
))
2467 /* Otherwise, only operations which can be done in tandem with
2468 a `restore' insn can go into the delay slot. */
2469 if (GET_CODE (SET_DEST (pat
)) != REG
2470 || (REGNO (SET_DEST (pat
)) >= 8 && REGNO (SET_DEST (pat
)) < 24)
2471 || REGNO (SET_DEST (pat
)) >= 32)
2474 /* If it mentions %o7, it can't go in, because sibcall will clobber it
2476 if (reg_mentioned_p (gen_rtx_REG (Pmode
, 15), pat
))
2479 return eligible_for_restore_insn (trial
, false);
2483 short_branch (int uid1
, int uid2
)
2485 int delta
= INSN_ADDRESSES (uid1
) - INSN_ADDRESSES (uid2
);
2487 /* Leave a few words of "slop". */
2488 if (delta
>= -1023 && delta
<= 1022)
2494 /* Return nonzero if REG is not used after INSN.
2495 We assume REG is a reload reg, and therefore does
2496 not live past labels or calls or jumps. */
2498 reg_unused_after (rtx reg
, rtx insn
)
2500 enum rtx_code code
, prev_code
= UNKNOWN
;
2502 while ((insn
= NEXT_INSN (insn
)))
2504 if (prev_code
== CALL_INSN
&& call_used_regs
[REGNO (reg
)])
2507 code
= GET_CODE (insn
);
2508 if (GET_CODE (insn
) == CODE_LABEL
)
2513 rtx set
= single_set (insn
);
2514 int in_src
= set
&& reg_overlap_mentioned_p (reg
, SET_SRC (set
));
2517 if (set
&& reg_overlap_mentioned_p (reg
, SET_DEST (set
)))
2519 if (set
== 0 && reg_overlap_mentioned_p (reg
, PATTERN (insn
)))
2527 /* Determine if it's legal to put X into the constant pool. This
2528 is not possible if X contains the address of a symbol that is
2529 not constant (TLS) or not known at final link time (PIC). */
2532 sparc_cannot_force_const_mem (rtx x
)
2534 switch (GET_CODE (x
))
2539 /* Accept all non-symbolic constants. */
2543 /* Labels are OK iff we are non-PIC. */
2544 return flag_pic
!= 0;
2547 /* 'Naked' TLS symbol references are never OK,
2548 non-TLS symbols are OK iff we are non-PIC. */
2549 if (SYMBOL_REF_TLS_MODEL (x
))
2552 return flag_pic
!= 0;
2555 return sparc_cannot_force_const_mem (XEXP (x
, 0));
2558 return sparc_cannot_force_const_mem (XEXP (x
, 0))
2559 || sparc_cannot_force_const_mem (XEXP (x
, 1));
2568 static GTY(()) char pic_helper_symbol_name
[256];
2569 static GTY(()) rtx pic_helper_symbol
;
2570 static GTY(()) bool pic_helper_emitted_p
= false;
2571 static GTY(()) rtx global_offset_table
;
2573 /* Ensure that we are not using patterns that are not OK with PIC. */
2581 gcc_assert (GET_CODE (recog_data
.operand
[i
]) != SYMBOL_REF
2582 && (GET_CODE (recog_data
.operand
[i
]) != CONST
2583 || (GET_CODE (XEXP (recog_data
.operand
[i
], 0)) == MINUS
2584 && (XEXP (XEXP (recog_data
.operand
[i
], 0), 0)
2585 == global_offset_table
)
2586 && (GET_CODE (XEXP (XEXP (recog_data
.operand
[i
], 0), 1))
2594 /* Return true if X is an address which needs a temporary register when
2595 reloaded while generating PIC code. */
2598 pic_address_needs_scratch (rtx x
)
2600 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
2601 if (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
2602 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
2603 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
2604 && ! SMALL_INT (XEXP (XEXP (x
, 0), 1)))
2610 /* Determine if a given RTX is a valid constant. We already know this
2611 satisfies CONSTANT_P. */
2614 legitimate_constant_p (rtx x
)
2618 switch (GET_CODE (x
))
2621 /* TLS symbols are not constant. */
2622 if (SYMBOL_REF_TLS_MODEL (x
))
2627 inner
= XEXP (x
, 0);
2629 /* Offsets of TLS symbols are never valid.
2630 Discourage CSE from creating them. */
2631 if (GET_CODE (inner
) == PLUS
2632 && tls_symbolic_operand (XEXP (inner
, 0)))
2637 if (GET_MODE (x
) == VOIDmode
)
2640 /* Floating point constants are generally not ok.
2641 The only exception is 0.0 in VIS. */
2643 && (GET_MODE (x
) == SFmode
2644 || GET_MODE (x
) == DFmode
2645 || GET_MODE (x
) == TFmode
)
2646 && const_zero_operand (x
, GET_MODE (x
)))
2658 /* Determine if a given RTX is a valid constant address. */
2661 constant_address_p (rtx x
)
2663 switch (GET_CODE (x
))
2671 if (flag_pic
&& pic_address_needs_scratch (x
))
2673 return legitimate_constant_p (x
);
2676 return !flag_pic
&& legitimate_constant_p (x
);
2683 /* Nonzero if the constant value X is a legitimate general operand
2684 when generating PIC code. It is given that flag_pic is on and
2685 that X satisfies CONSTANT_P or is a CONST_DOUBLE. */
2688 legitimate_pic_operand_p (rtx x
)
2690 if (pic_address_needs_scratch (x
))
2692 if (tls_symbolic_operand (x
)
2693 || (GET_CODE (x
) == CONST
2694 && GET_CODE (XEXP (x
, 0)) == PLUS
2695 && tls_symbolic_operand (XEXP (XEXP (x
, 0), 0))))
2700 /* Return nonzero if ADDR is a valid memory address.
2701 STRICT specifies whether strict register checking applies. */
2704 legitimate_address_p (enum machine_mode mode
, rtx addr
, int strict
)
2706 rtx rs1
= NULL
, rs2
= NULL
, imm1
= NULL
;
2708 if (REG_P (addr
) || GET_CODE (addr
) == SUBREG
)
2710 else if (GET_CODE (addr
) == PLUS
)
2712 rs1
= XEXP (addr
, 0);
2713 rs2
= XEXP (addr
, 1);
2715 /* Canonicalize. REG comes first, if there are no regs,
2716 LO_SUM comes first. */
2718 && GET_CODE (rs1
) != SUBREG
2720 || GET_CODE (rs2
) == SUBREG
2721 || (GET_CODE (rs2
) == LO_SUM
&& GET_CODE (rs1
) != LO_SUM
)))
2723 rs1
= XEXP (addr
, 1);
2724 rs2
= XEXP (addr
, 0);
2728 && rs1
== pic_offset_table_rtx
2730 && GET_CODE (rs2
) != SUBREG
2731 && GET_CODE (rs2
) != LO_SUM
2732 && GET_CODE (rs2
) != MEM
2733 && !tls_symbolic_operand (rs2
)
2734 && (! symbolic_operand (rs2
, VOIDmode
) || mode
== Pmode
)
2735 && (GET_CODE (rs2
) != CONST_INT
|| SMALL_INT (rs2
)))
2737 || GET_CODE (rs1
) == SUBREG
)
2738 && RTX_OK_FOR_OFFSET_P (rs2
)))
2743 else if ((REG_P (rs1
) || GET_CODE (rs1
) == SUBREG
)
2744 && (REG_P (rs2
) || GET_CODE (rs2
) == SUBREG
))
2746 /* We prohibit REG + REG for TFmode when there are no quad move insns
2747 and we consequently need to split. We do this because REG+REG
2748 is not an offsettable address. If we get the situation in reload
2749 where source and destination of a movtf pattern are both MEMs with
2750 REG+REG address, then only one of them gets converted to an
2751 offsettable address. */
2753 && ! (TARGET_FPU
&& TARGET_ARCH64
&& TARGET_HARD_QUAD
))
2756 /* We prohibit REG + REG on ARCH32 if not optimizing for
2757 DFmode/DImode because then mem_min_alignment is likely to be zero
2758 after reload and the forced split would lack a matching splitter
2760 if (TARGET_ARCH32
&& !optimize
2761 && (mode
== DFmode
|| mode
== DImode
))
2764 else if (USE_AS_OFFSETABLE_LO10
2765 && GET_CODE (rs1
) == LO_SUM
2767 && ! TARGET_CM_MEDMID
2768 && RTX_OK_FOR_OLO10_P (rs2
))
2771 imm1
= XEXP (rs1
, 1);
2772 rs1
= XEXP (rs1
, 0);
2773 if (! CONSTANT_P (imm1
) || tls_symbolic_operand (rs1
))
2777 else if (GET_CODE (addr
) == LO_SUM
)
2779 rs1
= XEXP (addr
, 0);
2780 imm1
= XEXP (addr
, 1);
2782 if (! CONSTANT_P (imm1
) || tls_symbolic_operand (rs1
))
2785 /* We can't allow TFmode in 32-bit mode, because an offset greater
2786 than the alignment (8) may cause the LO_SUM to overflow. */
2787 if (mode
== TFmode
&& TARGET_ARCH32
)
2790 else if (GET_CODE (addr
) == CONST_INT
&& SMALL_INT (addr
))
2795 if (GET_CODE (rs1
) == SUBREG
)
2796 rs1
= SUBREG_REG (rs1
);
2802 if (GET_CODE (rs2
) == SUBREG
)
2803 rs2
= SUBREG_REG (rs2
);
2810 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1
))
2811 || (rs2
&& !REGNO_OK_FOR_BASE_P (REGNO (rs2
))))
2816 if ((REGNO (rs1
) >= 32
2817 && REGNO (rs1
) != FRAME_POINTER_REGNUM
2818 && REGNO (rs1
) < FIRST_PSEUDO_REGISTER
)
2820 && (REGNO (rs2
) >= 32
2821 && REGNO (rs2
) != FRAME_POINTER_REGNUM
2822 && REGNO (rs2
) < FIRST_PSEUDO_REGISTER
)))
2828 /* Construct the SYMBOL_REF for the tls_get_offset function. */
2830 static GTY(()) rtx sparc_tls_symbol
;
2832 sparc_tls_get_addr (void)
2834 if (!sparc_tls_symbol
)
2835 sparc_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_addr");
2837 return sparc_tls_symbol
;
2841 sparc_tls_got (void)
2846 current_function_uses_pic_offset_table
= 1;
2847 return pic_offset_table_rtx
;
2850 if (!global_offset_table
)
2851 global_offset_table
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
2852 temp
= gen_reg_rtx (Pmode
);
2853 emit_move_insn (temp
, global_offset_table
);
2858 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2859 this (thread-local) address. */
2862 legitimize_tls_address (rtx addr
)
2864 rtx temp1
, temp2
, temp3
, ret
, o0
, got
, insn
;
2866 gcc_assert (! no_new_pseudos
);
2868 if (GET_CODE (addr
) == SYMBOL_REF
)
2869 switch (SYMBOL_REF_TLS_MODEL (addr
))
2871 case TLS_MODEL_GLOBAL_DYNAMIC
:
2873 temp1
= gen_reg_rtx (SImode
);
2874 temp2
= gen_reg_rtx (SImode
);
2875 ret
= gen_reg_rtx (Pmode
);
2876 o0
= gen_rtx_REG (Pmode
, 8);
2877 got
= sparc_tls_got ();
2878 emit_insn (gen_tgd_hi22 (temp1
, addr
));
2879 emit_insn (gen_tgd_lo10 (temp2
, temp1
, addr
));
2882 emit_insn (gen_tgd_add32 (o0
, got
, temp2
, addr
));
2883 insn
= emit_call_insn (gen_tgd_call32 (o0
, sparc_tls_get_addr (),
2888 emit_insn (gen_tgd_add64 (o0
, got
, temp2
, addr
));
2889 insn
= emit_call_insn (gen_tgd_call64 (o0
, sparc_tls_get_addr (),
2892 CALL_INSN_FUNCTION_USAGE (insn
)
2893 = gen_rtx_EXPR_LIST (VOIDmode
, gen_rtx_USE (VOIDmode
, o0
),
2894 CALL_INSN_FUNCTION_USAGE (insn
));
2895 insn
= get_insns ();
2897 emit_libcall_block (insn
, ret
, o0
, addr
);
2900 case TLS_MODEL_LOCAL_DYNAMIC
:
2902 temp1
= gen_reg_rtx (SImode
);
2903 temp2
= gen_reg_rtx (SImode
);
2904 temp3
= gen_reg_rtx (Pmode
);
2905 ret
= gen_reg_rtx (Pmode
);
2906 o0
= gen_rtx_REG (Pmode
, 8);
2907 got
= sparc_tls_got ();
2908 emit_insn (gen_tldm_hi22 (temp1
));
2909 emit_insn (gen_tldm_lo10 (temp2
, temp1
));
2912 emit_insn (gen_tldm_add32 (o0
, got
, temp2
));
2913 insn
= emit_call_insn (gen_tldm_call32 (o0
, sparc_tls_get_addr (),
2918 emit_insn (gen_tldm_add64 (o0
, got
, temp2
));
2919 insn
= emit_call_insn (gen_tldm_call64 (o0
, sparc_tls_get_addr (),
2922 CALL_INSN_FUNCTION_USAGE (insn
)
2923 = gen_rtx_EXPR_LIST (VOIDmode
, gen_rtx_USE (VOIDmode
, o0
),
2924 CALL_INSN_FUNCTION_USAGE (insn
));
2925 insn
= get_insns ();
2927 emit_libcall_block (insn
, temp3
, o0
,
2928 gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
),
2929 UNSPEC_TLSLD_BASE
));
2930 temp1
= gen_reg_rtx (SImode
);
2931 temp2
= gen_reg_rtx (SImode
);
2932 emit_insn (gen_tldo_hix22 (temp1
, addr
));
2933 emit_insn (gen_tldo_lox10 (temp2
, temp1
, addr
));
2935 emit_insn (gen_tldo_add32 (ret
, temp3
, temp2
, addr
));
2937 emit_insn (gen_tldo_add64 (ret
, temp3
, temp2
, addr
));
2940 case TLS_MODEL_INITIAL_EXEC
:
2941 temp1
= gen_reg_rtx (SImode
);
2942 temp2
= gen_reg_rtx (SImode
);
2943 temp3
= gen_reg_rtx (Pmode
);
2944 got
= sparc_tls_got ();
2945 emit_insn (gen_tie_hi22 (temp1
, addr
));
2946 emit_insn (gen_tie_lo10 (temp2
, temp1
, addr
));
2948 emit_insn (gen_tie_ld32 (temp3
, got
, temp2
, addr
));
2950 emit_insn (gen_tie_ld64 (temp3
, got
, temp2
, addr
));
2953 ret
= gen_reg_rtx (Pmode
);
2955 emit_insn (gen_tie_add32 (ret
, gen_rtx_REG (Pmode
, 7),
2958 emit_insn (gen_tie_add64 (ret
, gen_rtx_REG (Pmode
, 7),
2962 ret
= gen_rtx_PLUS (Pmode
, gen_rtx_REG (Pmode
, 7), temp3
);
2965 case TLS_MODEL_LOCAL_EXEC
:
2966 temp1
= gen_reg_rtx (Pmode
);
2967 temp2
= gen_reg_rtx (Pmode
);
2970 emit_insn (gen_tle_hix22_sp32 (temp1
, addr
));
2971 emit_insn (gen_tle_lox10_sp32 (temp2
, temp1
, addr
));
2975 emit_insn (gen_tle_hix22_sp64 (temp1
, addr
));
2976 emit_insn (gen_tle_lox10_sp64 (temp2
, temp1
, addr
));
2978 ret
= gen_rtx_PLUS (Pmode
, gen_rtx_REG (Pmode
, 7), temp2
);
2986 gcc_unreachable (); /* for now ... */
2992 /* Legitimize PIC addresses. If the address is already position-independent,
2993 we return ORIG. Newly generated position-independent addresses go into a
2994 reg. This is REG if nonzero, otherwise we allocate register(s) as
2998 legitimize_pic_address (rtx orig
, enum machine_mode mode ATTRIBUTE_UNUSED
,
3001 if (GET_CODE (orig
) == SYMBOL_REF
)
3003 rtx pic_ref
, address
;
3008 gcc_assert (! reload_in_progress
&& ! reload_completed
);
3009 reg
= gen_reg_rtx (Pmode
);
3014 /* If not during reload, allocate another temp reg here for loading
3015 in the address, so that these instructions can be optimized
3017 rtx temp_reg
= ((reload_in_progress
|| reload_completed
)
3018 ? reg
: gen_reg_rtx (Pmode
));
3020 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
3021 won't get confused into thinking that these two instructions
3022 are loading in the true address of the symbol. If in the
3023 future a PIC rtx exists, that should be used instead. */
3024 if (Pmode
== SImode
)
3026 emit_insn (gen_movsi_high_pic (temp_reg
, orig
));
3027 emit_insn (gen_movsi_lo_sum_pic (temp_reg
, temp_reg
, orig
));
3031 emit_insn (gen_movdi_high_pic (temp_reg
, orig
));
3032 emit_insn (gen_movdi_lo_sum_pic (temp_reg
, temp_reg
, orig
));
3039 pic_ref
= gen_const_mem (Pmode
,
3040 gen_rtx_PLUS (Pmode
,
3041 pic_offset_table_rtx
, address
));
3042 current_function_uses_pic_offset_table
= 1;
3043 insn
= emit_move_insn (reg
, pic_ref
);
3044 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3046 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_EQUAL
, orig
,
3050 else if (GET_CODE (orig
) == CONST
)
3054 if (GET_CODE (XEXP (orig
, 0)) == PLUS
3055 && XEXP (XEXP (orig
, 0), 0) == pic_offset_table_rtx
)
3060 gcc_assert (! reload_in_progress
&& ! reload_completed
);
3061 reg
= gen_reg_rtx (Pmode
);
3064 gcc_assert (GET_CODE (XEXP (orig
, 0)) == PLUS
);
3065 base
= legitimize_pic_address (XEXP (XEXP (orig
, 0), 0), Pmode
, reg
);
3066 offset
= legitimize_pic_address (XEXP (XEXP (orig
, 0), 1), Pmode
,
3067 base
== reg
? 0 : reg
);
3069 if (GET_CODE (offset
) == CONST_INT
)
3071 if (SMALL_INT (offset
))
3072 return plus_constant (base
, INTVAL (offset
));
3073 else if (! reload_in_progress
&& ! reload_completed
)
3074 offset
= force_reg (Pmode
, offset
);
3076 /* If we reach here, then something is seriously wrong. */
3079 return gen_rtx_PLUS (Pmode
, base
, offset
);
3081 else if (GET_CODE (orig
) == LABEL_REF
)
3082 /* ??? Why do we do this? */
3083 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
3084 the register is live instead, in case it is eliminated. */
3085 current_function_uses_pic_offset_table
= 1;
3090 /* Try machine-dependent ways of modifying an illegitimate address X
3091 to be legitimate. If we find one, return the new, valid address.
3093 OLDX is the address as it was before break_out_memory_refs was called.
3094 In some cases it is useful to look at this to decide what needs to be done.
3096 MODE is the mode of the operand pointed to by X. */
3099 legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
, enum machine_mode mode
)
3103 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 0)) == MULT
)
3104 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 1),
3105 force_operand (XEXP (x
, 0), NULL_RTX
));
3106 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == MULT
)
3107 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0),
3108 force_operand (XEXP (x
, 1), NULL_RTX
));
3109 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 0)) == PLUS
)
3110 x
= gen_rtx_PLUS (Pmode
, force_operand (XEXP (x
, 0), NULL_RTX
),
3112 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == PLUS
)
3113 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0),
3114 force_operand (XEXP (x
, 1), NULL_RTX
));
3116 if (x
!= orig_x
&& legitimate_address_p (mode
, x
, FALSE
))
3119 if (tls_symbolic_operand (x
))
3120 x
= legitimize_tls_address (x
);
3122 x
= legitimize_pic_address (x
, mode
, 0);
3123 else if (GET_CODE (x
) == PLUS
&& CONSTANT_ADDRESS_P (XEXP (x
, 1)))
3124 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0),
3125 copy_to_mode_reg (Pmode
, XEXP (x
, 1)));
3126 else if (GET_CODE (x
) == PLUS
&& CONSTANT_ADDRESS_P (XEXP (x
, 0)))
3127 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 1),
3128 copy_to_mode_reg (Pmode
, XEXP (x
, 0)));
3129 else if (GET_CODE (x
) == SYMBOL_REF
3130 || GET_CODE (x
) == CONST
3131 || GET_CODE (x
) == LABEL_REF
)
3132 x
= copy_to_suggested_reg (x
, NULL_RTX
, Pmode
);
3136 /* Emit the special PIC helper function. */
3139 emit_pic_helper (void)
3141 const char *pic_name
= reg_names
[REGNO (pic_offset_table_rtx
)];
3146 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
3148 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
3149 ASM_OUTPUT_LABEL (asm_out_file
, pic_helper_symbol_name
);
3150 if (flag_delayed_branch
)
3151 fprintf (asm_out_file
, "\tjmp\t%%o7+8\n\t add\t%%o7, %s, %s\n",
3152 pic_name
, pic_name
);
3154 fprintf (asm_out_file
, "\tadd\t%%o7, %s, %s\n\tjmp\t%%o7+8\n\t nop\n",
3155 pic_name
, pic_name
);
3157 pic_helper_emitted_p
= true;
3160 /* Emit code to load the PIC register. */
3163 load_pic_register (bool delay_pic_helper
)
3165 int orig_flag_pic
= flag_pic
;
3167 /* If we haven't initialized the special PIC symbols, do so now. */
3168 if (!pic_helper_symbol_name
[0])
3170 ASM_GENERATE_INTERNAL_LABEL (pic_helper_symbol_name
, "LADDPC", 0);
3171 pic_helper_symbol
= gen_rtx_SYMBOL_REF (Pmode
, pic_helper_symbol_name
);
3172 global_offset_table
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
3175 /* If we haven't emitted the special PIC helper function, do so now unless
3176 we are requested to delay it. */
3177 if (!delay_pic_helper
&& !pic_helper_emitted_p
)
3182 emit_insn (gen_load_pcrel_symdi (pic_offset_table_rtx
, global_offset_table
,
3183 pic_helper_symbol
));
3185 emit_insn (gen_load_pcrel_symsi (pic_offset_table_rtx
, global_offset_table
,
3186 pic_helper_symbol
));
3187 flag_pic
= orig_flag_pic
;
3189 /* Need to emit this whether or not we obey regdecls,
3190 since setjmp/longjmp can cause life info to screw up.
3191 ??? In the case where we don't obey regdecls, this is not sufficient
3192 since we may not fall out the bottom. */
3193 emit_insn (gen_rtx_USE (VOIDmode
, pic_offset_table_rtx
));
3196 /* Return 1 if RTX is a MEM which is known to be aligned to at
3197 least a DESIRED byte boundary. */
3200 mem_min_alignment (rtx mem
, int desired
)
3202 rtx addr
, base
, offset
;
3204 /* If it's not a MEM we can't accept it. */
3205 if (GET_CODE (mem
) != MEM
)
3209 if (MEM_ALIGN (mem
) / BITS_PER_UNIT
>= (unsigned)desired
)
3212 /* ??? The rest of the function predates MEM_ALIGN so
3213 there is probably a bit of redundancy. */
3214 addr
= XEXP (mem
, 0);
3215 base
= offset
= NULL_RTX
;
3216 if (GET_CODE (addr
) == PLUS
)
3218 if (GET_CODE (XEXP (addr
, 0)) == REG
)
3220 base
= XEXP (addr
, 0);
3222 /* What we are saying here is that if the base
3223 REG is aligned properly, the compiler will make
3224 sure any REG based index upon it will be so
3226 if (GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
3227 offset
= XEXP (addr
, 1);
3229 offset
= const0_rtx
;
3232 else if (GET_CODE (addr
) == REG
)
3235 offset
= const0_rtx
;
3238 if (base
!= NULL_RTX
)
3240 int regno
= REGNO (base
);
3242 if (regno
!= HARD_FRAME_POINTER_REGNUM
&& regno
!= STACK_POINTER_REGNUM
)
3244 /* Check if the compiler has recorded some information
3245 about the alignment of the base REG. If reload has
3246 completed, we already matched with proper alignments.
3247 If not running global_alloc, reload might give us
3248 unaligned pointer to local stack though. */
3250 && REGNO_POINTER_ALIGN (regno
) >= desired
* BITS_PER_UNIT
)
3251 || (optimize
&& reload_completed
))
3252 && (INTVAL (offset
) & (desired
- 1)) == 0)
3257 if (((INTVAL (offset
) - SPARC_STACK_BIAS
) & (desired
- 1)) == 0)
3261 else if (! TARGET_UNALIGNED_DOUBLES
3262 || CONSTANT_P (addr
)
3263 || GET_CODE (addr
) == LO_SUM
)
3265 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
3266 is true, in which case we can only assume that an access is aligned if
3267 it is to a constant address, or the address involves a LO_SUM. */
3271 /* An obviously unaligned address. */
3276 /* Vectors to keep interesting information about registers where it can easily
3277 be got. We used to use the actual mode value as the bit number, but there
3278 are more than 32 modes now. Instead we use two tables: one indexed by
3279 hard register number, and one indexed by mode. */
3281 /* The purpose of sparc_mode_class is to shrink the range of modes so that
3282 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
3283 mapped into one sparc_mode_class mode. */
3285 enum sparc_mode_class
{
3286 S_MODE
, D_MODE
, T_MODE
, O_MODE
,
3287 SF_MODE
, DF_MODE
, TF_MODE
, OF_MODE
,
3291 /* Modes for single-word and smaller quantities. */
3292 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
3294 /* Modes for double-word and smaller quantities. */
3295 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
3297 /* Modes for quad-word and smaller quantities. */
3298 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
3300 /* Modes for 8-word and smaller quantities. */
3301 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
3303 /* Modes for single-float quantities. We must allow any single word or
3304 smaller quantity. This is because the fix/float conversion instructions
3305 take integer inputs/outputs from the float registers. */
3306 #define SF_MODES (S_MODES)
3308 /* Modes for double-float and smaller quantities. */
3309 #define DF_MODES (S_MODES | D_MODES)
3311 /* Modes for double-float only quantities. */
3312 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
3314 /* Modes for quad-float only quantities. */
3315 #define TF_ONLY_MODES (1 << (int) TF_MODE)
3317 /* Modes for quad-float and smaller quantities. */
3318 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
3320 /* Modes for quad-float and double-float quantities. */
3321 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
3323 /* Modes for quad-float pair only quantities. */
3324 #define OF_ONLY_MODES (1 << (int) OF_MODE)
3326 /* Modes for quad-float pairs and smaller quantities. */
3327 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
3329 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
3331 /* Modes for condition codes. */
3332 #define CC_MODES (1 << (int) CC_MODE)
3333 #define CCFP_MODES (1 << (int) CCFP_MODE)
3335 /* Value is 1 if register/mode pair is acceptable on sparc.
3336 The funny mixture of D and T modes is because integer operations
3337 do not specially operate on tetra quantities, so non-quad-aligned
3338 registers can hold quadword quantities (except %o4 and %i4 because
3339 they cross fixed registers). */
3341 /* This points to either the 32 bit or the 64 bit version. */
3342 const int *hard_regno_mode_classes
;
3344 static const int hard_32bit_mode_classes
[] = {
3345 S_MODES
, S_MODES
, T_MODES
, S_MODES
, T_MODES
, S_MODES
, D_MODES
, S_MODES
,
3346 T_MODES
, S_MODES
, T_MODES
, S_MODES
, D_MODES
, S_MODES
, D_MODES
, S_MODES
,
3347 T_MODES
, S_MODES
, T_MODES
, S_MODES
, T_MODES
, S_MODES
, D_MODES
, S_MODES
,
3348 T_MODES
, S_MODES
, T_MODES
, S_MODES
, D_MODES
, S_MODES
, D_MODES
, S_MODES
,
3350 OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
, OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
,
3351 OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
, OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
,
3352 OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
, OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
,
3353 OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
, TF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
,
3355 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3356 and none can hold SFmode/SImode values. */
3357 OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0, OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0,
3358 OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0, OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0,
3359 OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0, OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0,
3360 OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0, TF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0,
3363 CCFP_MODES
, CCFP_MODES
, CCFP_MODES
, CCFP_MODES
,
3369 static const int hard_64bit_mode_classes
[] = {
3370 D_MODES
, D_MODES
, T_MODES
, D_MODES
, T_MODES
, D_MODES
, T_MODES
, D_MODES
,
3371 O_MODES
, D_MODES
, T_MODES
, D_MODES
, T_MODES
, D_MODES
, T_MODES
, D_MODES
,
3372 T_MODES
, D_MODES
, T_MODES
, D_MODES
, T_MODES
, D_MODES
, T_MODES
, D_MODES
,
3373 O_MODES
, D_MODES
, T_MODES
, D_MODES
, T_MODES
, D_MODES
, T_MODES
, D_MODES
,
3375 OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
, OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
,
3376 OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
, OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
,
3377 OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
, OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
,
3378 OF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
, TF_MODES
, SF_MODES
, DF_MODES
, SF_MODES
,
3380 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3381 and none can hold SFmode/SImode values. */
3382 OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0, OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0,
3383 OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0, OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0,
3384 OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0, OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0,
3385 OF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0, TF_MODES_NO_S
, 0, DF_MODES_NO_S
, 0,
3388 CCFP_MODES
, CCFP_MODES
, CCFP_MODES
, CCFP_MODES
,
3394 int sparc_mode_class
[NUM_MACHINE_MODES
];
3396 enum reg_class sparc_regno_reg_class
[FIRST_PSEUDO_REGISTER
];
3399 sparc_init_modes (void)
3403 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
3405 switch (GET_MODE_CLASS (i
))
3408 case MODE_PARTIAL_INT
:
3409 case MODE_COMPLEX_INT
:
3410 if (GET_MODE_SIZE (i
) <= 4)
3411 sparc_mode_class
[i
] = 1 << (int) S_MODE
;
3412 else if (GET_MODE_SIZE (i
) == 8)
3413 sparc_mode_class
[i
] = 1 << (int) D_MODE
;
3414 else if (GET_MODE_SIZE (i
) == 16)
3415 sparc_mode_class
[i
] = 1 << (int) T_MODE
;
3416 else if (GET_MODE_SIZE (i
) == 32)
3417 sparc_mode_class
[i
] = 1 << (int) O_MODE
;
3419 sparc_mode_class
[i
] = 0;
3421 case MODE_VECTOR_INT
:
3422 if (GET_MODE_SIZE (i
) <= 4)
3423 sparc_mode_class
[i
] = 1 << (int)SF_MODE
;
3424 else if (GET_MODE_SIZE (i
) == 8)
3425 sparc_mode_class
[i
] = 1 << (int)DF_MODE
;
3428 case MODE_COMPLEX_FLOAT
:
3429 if (GET_MODE_SIZE (i
) <= 4)
3430 sparc_mode_class
[i
] = 1 << (int) SF_MODE
;
3431 else if (GET_MODE_SIZE (i
) == 8)
3432 sparc_mode_class
[i
] = 1 << (int) DF_MODE
;
3433 else if (GET_MODE_SIZE (i
) == 16)
3434 sparc_mode_class
[i
] = 1 << (int) TF_MODE
;
3435 else if (GET_MODE_SIZE (i
) == 32)
3436 sparc_mode_class
[i
] = 1 << (int) OF_MODE
;
3438 sparc_mode_class
[i
] = 0;
3441 if (i
== (int) CCFPmode
|| i
== (int) CCFPEmode
)
3442 sparc_mode_class
[i
] = 1 << (int) CCFP_MODE
;
3444 sparc_mode_class
[i
] = 1 << (int) CC_MODE
;
3447 sparc_mode_class
[i
] = 0;
3453 hard_regno_mode_classes
= hard_64bit_mode_classes
;
3455 hard_regno_mode_classes
= hard_32bit_mode_classes
;
3457 /* Initialize the array used by REGNO_REG_CLASS. */
3458 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3460 if (i
< 16 && TARGET_V8PLUS
)
3461 sparc_regno_reg_class
[i
] = I64_REGS
;
3462 else if (i
< 32 || i
== FRAME_POINTER_REGNUM
)
3463 sparc_regno_reg_class
[i
] = GENERAL_REGS
;
3465 sparc_regno_reg_class
[i
] = FP_REGS
;
3467 sparc_regno_reg_class
[i
] = EXTRA_FP_REGS
;
3469 sparc_regno_reg_class
[i
] = FPCC_REGS
;
3471 sparc_regno_reg_class
[i
] = NO_REGS
;
3475 /* Compute the frame size required by the function. This function is called
3476 during the reload pass and also by sparc_expand_prologue. */
3479 sparc_compute_frame_size (HOST_WIDE_INT size
, int leaf_function_p
)
3481 int outgoing_args_size
= (current_function_outgoing_args_size
3482 + REG_PARM_STACK_SPACE (current_function_decl
));
3483 int n_regs
= 0; /* N_REGS is the number of 4-byte regs saved thus far. */
3488 for (i
= 0; i
< 8; i
++)
3489 if (regs_ever_live
[i
] && ! call_used_regs
[i
])
3494 for (i
= 0; i
< 8; i
+= 2)
3495 if ((regs_ever_live
[i
] && ! call_used_regs
[i
])
3496 || (regs_ever_live
[i
+1] && ! call_used_regs
[i
+1]))
3500 for (i
= 32; i
< (TARGET_V9
? 96 : 64); i
+= 2)
3501 if ((regs_ever_live
[i
] && ! call_used_regs
[i
])
3502 || (regs_ever_live
[i
+1] && ! call_used_regs
[i
+1]))
3505 /* Set up values for use in prologue and epilogue. */
3506 num_gfregs
= n_regs
;
3511 && current_function_outgoing_args_size
== 0)
3512 actual_fsize
= apparent_fsize
= 0;
3515 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
3516 apparent_fsize
= (size
- STARTING_FRAME_OFFSET
+ 7) & -8;
3517 apparent_fsize
+= n_regs
* 4;
3518 actual_fsize
= apparent_fsize
+ ((outgoing_args_size
+ 7) & -8);
3521 /* Make sure nothing can clobber our register windows.
3522 If a SAVE must be done, or there is a stack-local variable,
3523 the register window area must be allocated.
3524 ??? For v8 we apparently need an additional 8 bytes of reserved space. */
3525 if (! leaf_function_p
|| size
> 0)
3526 actual_fsize
+= (16 * UNITS_PER_WORD
) + (TARGET_ARCH64
? 0 : 8);
3528 return SPARC_STACK_ALIGN (actual_fsize
);
3531 /* Output any necessary .register pseudo-ops. */
3534 sparc_output_scratch_registers (FILE *file ATTRIBUTE_UNUSED
)
3536 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
3542 /* Check if %g[2367] were used without
3543 .register being printed for them already. */
3544 for (i
= 2; i
< 8; i
++)
3546 if (regs_ever_live
[i
]
3547 && ! sparc_hard_reg_printed
[i
])
3549 sparc_hard_reg_printed
[i
] = 1;
3550 fprintf (file
, "\t.register\t%%g%d, #scratch\n", i
);
3557 /* Save/restore call-saved registers from LOW to HIGH at BASE+OFFSET
3558 as needed. LOW should be double-word aligned for 32-bit registers.
3559 Return the new OFFSET. */
3562 #define SORR_RESTORE 1
3565 save_or_restore_regs (int low
, int high
, rtx base
, int offset
, int action
)
3570 if (TARGET_ARCH64
&& high
<= 32)
3572 for (i
= low
; i
< high
; i
++)
3574 if (regs_ever_live
[i
] && ! call_used_regs
[i
])
3576 mem
= gen_rtx_MEM (DImode
, plus_constant (base
, offset
));
3577 set_mem_alias_set (mem
, sparc_sr_alias_set
);
3578 if (action
== SORR_SAVE
)
3580 insn
= emit_move_insn (mem
, gen_rtx_REG (DImode
, i
));
3581 RTX_FRAME_RELATED_P (insn
) = 1;
3583 else /* action == SORR_RESTORE */
3584 emit_move_insn (gen_rtx_REG (DImode
, i
), mem
);
3591 for (i
= low
; i
< high
; i
+= 2)
3593 bool reg0
= regs_ever_live
[i
] && ! call_used_regs
[i
];
3594 bool reg1
= regs_ever_live
[i
+1] && ! call_used_regs
[i
+1];
3595 enum machine_mode mode
;
3600 mode
= i
< 32 ? DImode
: DFmode
;
3605 mode
= i
< 32 ? SImode
: SFmode
;
3610 mode
= i
< 32 ? SImode
: SFmode
;
3617 mem
= gen_rtx_MEM (mode
, plus_constant (base
, offset
));
3618 set_mem_alias_set (mem
, sparc_sr_alias_set
);
3619 if (action
== SORR_SAVE
)
3621 insn
= emit_move_insn (mem
, gen_rtx_REG (mode
, regno
));
3622 RTX_FRAME_RELATED_P (insn
) = 1;
3624 else /* action == SORR_RESTORE */
3625 emit_move_insn (gen_rtx_REG (mode
, regno
), mem
);
3627 /* Always preserve double-word alignment. */
3628 offset
= (offset
+ 7) & -8;
3635 /* Emit code to save call-saved registers. */
3638 emit_save_regs (void)
3640 HOST_WIDE_INT offset
;
3643 offset
= frame_base_offset
- apparent_fsize
;
3645 if (offset
< -4096 || offset
+ num_gfregs
* 4 > 4096)
3647 /* ??? This might be optimized a little as %g1 might already have a
3648 value close enough that a single add insn will do. */
3649 /* ??? Although, all of this is probably only a temporary fix
3650 because if %g1 can hold a function result, then
3651 sparc_expand_epilogue will lose (the result will be
3653 base
= gen_rtx_REG (Pmode
, 1);
3654 emit_move_insn (base
, GEN_INT (offset
));
3655 emit_insn (gen_rtx_SET (VOIDmode
,
3657 gen_rtx_PLUS (Pmode
, frame_base_reg
, base
)));
3661 base
= frame_base_reg
;
3663 offset
= save_or_restore_regs (0, 8, base
, offset
, SORR_SAVE
);
3664 save_or_restore_regs (32, TARGET_V9
? 96 : 64, base
, offset
, SORR_SAVE
);
3667 /* Emit code to restore call-saved registers. */
3670 emit_restore_regs (void)
3672 HOST_WIDE_INT offset
;
3675 offset
= frame_base_offset
- apparent_fsize
;
3677 if (offset
< -4096 || offset
+ num_gfregs
* 4 > 4096 - 8 /*double*/)
3679 base
= gen_rtx_REG (Pmode
, 1);
3680 emit_move_insn (base
, GEN_INT (offset
));
3681 emit_insn (gen_rtx_SET (VOIDmode
,
3683 gen_rtx_PLUS (Pmode
, frame_base_reg
, base
)));
3687 base
= frame_base_reg
;
3689 offset
= save_or_restore_regs (0, 8, base
, offset
, SORR_RESTORE
);
3690 save_or_restore_regs (32, TARGET_V9
? 96 : 64, base
, offset
, SORR_RESTORE
);
3693 /* Generate a save_register_window insn. */
3696 gen_save_register_window (rtx increment
)
3699 return gen_save_register_windowdi (increment
);
3701 return gen_save_register_windowsi (increment
);
3704 /* Generate an increment for the stack pointer. */
3707 gen_stack_pointer_inc (rtx increment
)
3710 return gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
, increment
);
3712 return gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, increment
);
3715 /* Generate a decrement for the stack pointer. */
3718 gen_stack_pointer_dec (rtx decrement
)
3721 return gen_subdi3 (stack_pointer_rtx
, stack_pointer_rtx
, decrement
);
3723 return gen_subsi3 (stack_pointer_rtx
, stack_pointer_rtx
, decrement
);
3726 /* Expand the function prologue. The prologue is responsible for reserving
3727 storage for the frame, saving the call-saved registers and loading the
3728 PIC register if needed. */
3731 sparc_expand_prologue (void)
3736 /* Compute a snapshot of current_function_uses_only_leaf_regs. Relying
3737 on the final value of the flag means deferring the prologue/epilogue
3738 expansion until just before the second scheduling pass, which is too
3739 late to emit multiple epilogues or return insns.
3741 Of course we are making the assumption that the value of the flag
3742 will not change between now and its final value. Of the three parts
3743 of the formula, only the last one can reasonably vary. Let's take a
3744 closer look, after assuming that the first two ones are set to true
3745 (otherwise the last value is effectively silenced).
3747 If only_leaf_regs_used returns false, the global predicate will also
3748 be false so the actual frame size calculated below will be positive.
3749 As a consequence, the save_register_window insn will be emitted in
3750 the instruction stream; now this insn explicitly references %fp
3751 which is not a leaf register so only_leaf_regs_used will always
3752 return false subsequently.
3754 If only_leaf_regs_used returns true, we hope that the subsequent
3755 optimization passes won't cause non-leaf registers to pop up. For
3756 example, the regrename pass has special provisions to not rename to
3757 non-leaf registers in a leaf function. */
3758 sparc_leaf_function_p
3759 = optimize
> 0 && leaf_function_p () && only_leaf_regs_used ();
3761 /* Need to use actual_fsize, since we are also allocating
3762 space for our callee (and our own register save area). */
3764 = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p
);
3766 /* Advertise that the data calculated just above are now valid. */
3767 sparc_prologue_data_valid_p
= true;
3769 if (sparc_leaf_function_p
)
3771 frame_base_reg
= stack_pointer_rtx
;
3772 frame_base_offset
= actual_fsize
+ SPARC_STACK_BIAS
;
3776 frame_base_reg
= hard_frame_pointer_rtx
;
3777 frame_base_offset
= SPARC_STACK_BIAS
;
3780 if (actual_fsize
== 0)
3782 else if (sparc_leaf_function_p
)
3784 if (actual_fsize
<= 4096)
3785 insn
= emit_insn (gen_stack_pointer_inc (GEN_INT (-actual_fsize
)));
3786 else if (actual_fsize
<= 8192)
3788 insn
= emit_insn (gen_stack_pointer_inc (GEN_INT (-4096)));
3789 /* %sp is still the CFA register. */
3790 RTX_FRAME_RELATED_P (insn
) = 1;
3792 = emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize
)));
3796 rtx reg
= gen_rtx_REG (Pmode
, 1);
3797 emit_move_insn (reg
, GEN_INT (-actual_fsize
));
3798 insn
= emit_insn (gen_stack_pointer_inc (reg
));
3800 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
3801 PATTERN (gen_stack_pointer_inc (GEN_INT (-actual_fsize
))),
3805 RTX_FRAME_RELATED_P (insn
) = 1;
3809 if (actual_fsize
<= 4096)
3810 insn
= emit_insn (gen_save_register_window (GEN_INT (-actual_fsize
)));
3811 else if (actual_fsize
<= 8192)
3813 insn
= emit_insn (gen_save_register_window (GEN_INT (-4096)));
3814 /* %sp is not the CFA register anymore. */
3815 emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize
)));
3819 rtx reg
= gen_rtx_REG (Pmode
, 1);
3820 emit_move_insn (reg
, GEN_INT (-actual_fsize
));
3821 insn
= emit_insn (gen_save_register_window (reg
));
3824 RTX_FRAME_RELATED_P (insn
) = 1;
3825 for (i
=0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
3826 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn
), 0, i
)) = 1;
3829 /* Call-saved registers are saved just above the outgoing argument area. */
3833 /* Load the PIC register if needed. */
3834 if (flag_pic
&& current_function_uses_pic_offset_table
)
3835 load_pic_register (false);
3838 /* This function generates the assembly code for function entry, which boils
3839 down to emitting the necessary .register directives.
3841 ??? Historical cruft: "On SPARC, move-double insns between fpu and cpu need
3842 an 8-byte block of memory. If any fpu reg is used in the function, we
3843 allocate such a block here, at the bottom of the frame, just in case it's
3844 needed." Could this explain the -8 in emit_restore_regs? */
3847 sparc_asm_function_prologue (FILE *file
, HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
3849 /* Check that the assumption we made in sparc_expand_prologue is valid. */
3850 gcc_assert (sparc_leaf_function_p
== current_function_uses_only_leaf_regs
);
3852 sparc_output_scratch_registers (file
);
3855 /* Expand the function epilogue, either normal or part of a sibcall.
3856 We emit all the instructions except the return or the call. */
3859 sparc_expand_epilogue (void)
3862 emit_restore_regs ();
3864 if (actual_fsize
== 0)
3866 else if (sparc_leaf_function_p
)
3868 if (actual_fsize
<= 4096)
3869 emit_insn (gen_stack_pointer_dec (GEN_INT (- actual_fsize
)));
3870 else if (actual_fsize
<= 8192)
3872 emit_insn (gen_stack_pointer_dec (GEN_INT (-4096)));
3873 emit_insn (gen_stack_pointer_dec (GEN_INT (4096 - actual_fsize
)));
3877 rtx reg
= gen_rtx_REG (Pmode
, 1);
3878 emit_move_insn (reg
, GEN_INT (-actual_fsize
));
3879 emit_insn (gen_stack_pointer_dec (reg
));
3884 /* Return true if it is appropriate to emit `return' instructions in the
3885 body of a function. */
3888 sparc_can_use_return_insn_p (void)
3890 return sparc_prologue_data_valid_p
3891 && (actual_fsize
== 0 || !sparc_leaf_function_p
);
3894 /* This function generates the assembly code for function exit. */
3897 sparc_asm_function_epilogue (FILE *file
, HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
3899 /* If code does not drop into the epilogue, we have to still output
3900 a dummy nop for the sake of sane backtraces. Otherwise, if the
3901 last two instructions of a function were "call foo; dslot;" this
3902 can make the return PC of foo (i.e. address of call instruction
3903 plus 8) point to the first instruction in the next function. */
3905 rtx insn
, last_real_insn
;
3907 insn
= get_last_insn ();
3909 last_real_insn
= prev_real_insn (insn
);
3911 && GET_CODE (last_real_insn
) == INSN
3912 && GET_CODE (PATTERN (last_real_insn
)) == SEQUENCE
)
3913 last_real_insn
= XVECEXP (PATTERN (last_real_insn
), 0, 0);
3915 if (last_real_insn
&& GET_CODE (last_real_insn
) == CALL_INSN
)
3916 fputs("\tnop\n", file
);
3918 sparc_output_deferred_case_vectors ();
3921 /* Output a 'restore' instruction. */
3924 output_restore (rtx pat
)
3930 fputs ("\t restore\n", asm_out_file
);
3934 gcc_assert (GET_CODE (pat
) == SET
);
3936 operands
[0] = SET_DEST (pat
);
3937 pat
= SET_SRC (pat
);
3939 switch (GET_CODE (pat
))
3942 operands
[1] = XEXP (pat
, 0);
3943 operands
[2] = XEXP (pat
, 1);
3944 output_asm_insn (" restore %r1, %2, %Y0", operands
);
3947 operands
[1] = XEXP (pat
, 0);
3948 operands
[2] = XEXP (pat
, 1);
3949 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands
);
3952 operands
[1] = XEXP (pat
, 0);
3953 gcc_assert (XEXP (pat
, 1) == const1_rtx
);
3954 output_asm_insn (" restore %r1, %r1, %Y0", operands
);
3958 output_asm_insn (" restore %%g0, %1, %Y0", operands
);
3963 /* Output a return. */
3966 output_return (rtx insn
)
3968 if (sparc_leaf_function_p
)
3970 /* This is a leaf function so we don't have to bother restoring the
3971 register window, which frees us from dealing with the convoluted
3972 semantics of restore/return. We simply output the jump to the
3973 return address and the insn in the delay slot (if any). */
3975 gcc_assert (! current_function_calls_eh_return
);
3977 return "jmp\t%%o7+%)%#";
3981 /* This is a regular function so we have to restore the register window.
3982 We may have a pending insn for the delay slot, which will be either
3983 combined with the 'restore' instruction or put in the delay slot of
3984 the 'return' instruction. */
3986 if (current_function_calls_eh_return
)
3988 /* If the function uses __builtin_eh_return, the eh_return
3989 machinery occupies the delay slot. */
3990 gcc_assert (! final_sequence
);
3992 if (! flag_delayed_branch
)
3993 fputs ("\tadd\t%fp, %g1, %fp\n", asm_out_file
);
3996 fputs ("\treturn\t%i7+8\n", asm_out_file
);
3998 fputs ("\trestore\n\tjmp\t%o7+8\n", asm_out_file
);
4000 if (flag_delayed_branch
)
4001 fputs ("\t add\t%sp, %g1, %sp\n", asm_out_file
);
4003 fputs ("\t nop\n", asm_out_file
);
4005 else if (final_sequence
)
4009 delay
= NEXT_INSN (insn
);
4012 pat
= PATTERN (delay
);
4014 if (TARGET_V9
&& ! epilogue_renumber (&pat
, 1))
4016 epilogue_renumber (&pat
, 0);
4017 return "return\t%%i7+%)%#";
4021 output_asm_insn ("jmp\t%%i7+%)", NULL
);
4022 output_restore (pat
);
4023 PATTERN (delay
) = gen_blockage ();
4024 INSN_CODE (delay
) = -1;
4029 /* The delay slot is empty. */
4031 return "return\t%%i7+%)\n\t nop";
4032 else if (flag_delayed_branch
)
4033 return "jmp\t%%i7+%)\n\t restore";
4035 return "restore\n\tjmp\t%%o7+%)\n\t nop";
4042 /* Output a sibling call. */
4045 output_sibcall (rtx insn
, rtx call_operand
)
4049 gcc_assert (flag_delayed_branch
);
4051 operands
[0] = call_operand
;
4053 if (sparc_leaf_function_p
)
4055 /* This is a leaf function so we don't have to bother restoring the
4056 register window. We simply output the jump to the function and
4057 the insn in the delay slot (if any). */
4059 gcc_assert (!(LEAF_SIBCALL_SLOT_RESERVED_P
&& final_sequence
));
4062 output_asm_insn ("sethi\t%%hi(%a0), %%g1\n\tjmp\t%%g1 + %%lo(%a0)%#",
4065 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
4066 it into branch if possible. */
4067 output_asm_insn ("or\t%%o7, %%g0, %%g1\n\tcall\t%a0, 0\n\t or\t%%g1, %%g0, %%o7",
4072 /* This is a regular function so we have to restore the register window.
4073 We may have a pending insn for the delay slot, which will be combined
4074 with the 'restore' instruction. */
4076 output_asm_insn ("call\t%a0, 0", operands
);
4080 rtx delay
= NEXT_INSN (insn
);
4083 output_restore (PATTERN (delay
));
4085 PATTERN (delay
) = gen_blockage ();
4086 INSN_CODE (delay
) = -1;
4089 output_restore (NULL_RTX
);
4095 /* Functions for handling argument passing.
4097 For 32-bit, the first 6 args are normally in registers and the rest are
4098 pushed. Any arg that starts within the first 6 words is at least
4099 partially passed in a register unless its data type forbids.
4101 For 64-bit, the argument registers are laid out as an array of 16 elements
4102 and arguments are added sequentially. The first 6 int args and up to the
4103 first 16 fp args (depending on size) are passed in regs.
4105 Slot Stack Integral Float Float in structure Double Long Double
4106 ---- ----- -------- ----- ------------------ ------ -----------
4107 15 [SP+248] %f31 %f30,%f31 %d30
4108 14 [SP+240] %f29 %f28,%f29 %d28 %q28
4109 13 [SP+232] %f27 %f26,%f27 %d26
4110 12 [SP+224] %f25 %f24,%f25 %d24 %q24
4111 11 [SP+216] %f23 %f22,%f23 %d22
4112 10 [SP+208] %f21 %f20,%f21 %d20 %q20
4113 9 [SP+200] %f19 %f18,%f19 %d18
4114 8 [SP+192] %f17 %f16,%f17 %d16 %q16
4115 7 [SP+184] %f15 %f14,%f15 %d14
4116 6 [SP+176] %f13 %f12,%f13 %d12 %q12
4117 5 [SP+168] %o5 %f11 %f10,%f11 %d10
4118 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
4119 3 [SP+152] %o3 %f7 %f6,%f7 %d6
4120 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
4121 1 [SP+136] %o1 %f3 %f2,%f3 %d2
4122 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
4124 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
4126 Integral arguments are always passed as 64-bit quantities appropriately
4129 Passing of floating point values is handled as follows.
4130 If a prototype is in scope:
4131 If the value is in a named argument (i.e. not a stdarg function or a
4132 value not part of the `...') then the value is passed in the appropriate
4134 If the value is part of the `...' and is passed in one of the first 6
4135 slots then the value is passed in the appropriate int reg.
4136 If the value is part of the `...' and is not passed in one of the first 6
4137 slots then the value is passed in memory.
4138 If a prototype is not in scope:
4139 If the value is one of the first 6 arguments the value is passed in the
4140 appropriate integer reg and the appropriate fp reg.
4141 If the value is not one of the first 6 arguments the value is passed in
4142 the appropriate fp reg and in memory.
4145 Summary of the calling conventions implemented by GCC on SPARC:
4148 size argument return value
4150 small integer <4 int. reg. int. reg.
4151 word 4 int. reg. int. reg.
4152 double word 8 int. reg. int. reg.
4154 _Complex small integer <8 int. reg. int. reg.
4155 _Complex word 8 int. reg. int. reg.
4156 _Complex double word 16 memory int. reg.
4158 vector integer <=8 int. reg. FP reg.
4159 vector integer >8 memory memory
4161 float 4 int. reg. FP reg.
4162 double 8 int. reg. FP reg.
4163 long double 16 memory memory
4165 _Complex float 8 memory FP reg.
4166 _Complex double 16 memory FP reg.
4167 _Complex long double 32 memory FP reg.
4169 vector float any memory memory
4171 aggregate any memory memory
4176 size argument return value
4178 small integer <8 int. reg. int. reg.
4179 word 8 int. reg. int. reg.
4180 double word 16 int. reg. int. reg.
4182 _Complex small integer <16 int. reg. int. reg.
4183 _Complex word 16 int. reg. int. reg.
4184 _Complex double word 32 memory int. reg.
4186 vector integer <=16 FP reg. FP reg.
4187 vector integer 16<s<=32 memory FP reg.
4188 vector integer >32 memory memory
4190 float 4 FP reg. FP reg.
4191 double 8 FP reg. FP reg.
4192 long double 16 FP reg. FP reg.
4194 _Complex float 8 FP reg. FP reg.
4195 _Complex double 16 FP reg. FP reg.
4196 _Complex long double 32 memory FP reg.
4198 vector float <=16 FP reg. FP reg.
4199 vector float 16<s<=32 memory FP reg.
4200 vector float >32 memory memory
4202 aggregate <=16 reg. reg.
4203 aggregate 16<s<=32 memory reg.
4204 aggregate >32 memory memory
4208 Note #1: complex floating-point types follow the extended SPARC ABIs as
4209 implemented by the Sun compiler.
4211 Note #2: integral vector types follow the scalar floating-point types
4212 conventions to match what is implemented by the Sun VIS SDK.
4214 Note #3: floating-point vector types follow the aggregate types
4218 /* Maximum number of int regs for args. */
4219 #define SPARC_INT_ARG_MAX 6
4220 /* Maximum number of fp regs for args. */
4221 #define SPARC_FP_ARG_MAX 16
4223 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
4225 /* Handle the INIT_CUMULATIVE_ARGS macro.
4226 Initialize a variable CUM of type CUMULATIVE_ARGS
4227 for a call to a function whose data type is FNTYPE.
4228 For a library call, FNTYPE is 0. */
4231 init_cumulative_args (struct sparc_args
*cum
, tree fntype
,
4232 rtx libname ATTRIBUTE_UNUSED
,
4233 tree fndecl ATTRIBUTE_UNUSED
)
4236 cum
->prototype_p
= fntype
&& TYPE_ARG_TYPES (fntype
);
4237 cum
->libcall_p
= fntype
== 0;
4240 /* Handle the TARGET_PROMOTE_PROTOTYPES target hook.
4241 When a prototype says `char' or `short', really pass an `int'. */
4244 sparc_promote_prototypes (tree fntype ATTRIBUTE_UNUSED
)
4246 return TARGET_ARCH32
? true : false;
4249 /* Handle the TARGET_STRICT_ARGUMENT_NAMING target hook. */
4252 sparc_strict_argument_naming (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
)
4254 return TARGET_ARCH64
? true : false;
4257 /* Scan the record type TYPE and return the following predicates:
4258 - INTREGS_P: the record contains at least one field or sub-field
4259 that is eligible for promotion in integer registers.
4260 - FP_REGS_P: the record contains at least one field or sub-field
4261 that is eligible for promotion in floating-point registers.
4262 - PACKED_P: the record contains at least one field that is packed.
4264 Sub-fields are not taken into account for the PACKED_P predicate. */
4267 scan_record_type (tree type
, int *intregs_p
, int *fpregs_p
, int *packed_p
)
4271 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
4273 if (TREE_CODE (field
) == FIELD_DECL
)
4275 if (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
)
4276 scan_record_type (TREE_TYPE (field
), intregs_p
, fpregs_p
, 0);
4277 else if ((FLOAT_TYPE_P (TREE_TYPE (field
))
4278 || TREE_CODE (TREE_TYPE (field
)) == VECTOR_TYPE
)
4284 if (packed_p
&& DECL_PACKED (field
))
4290 /* Compute the slot number to pass an argument in.
4291 Return the slot number or -1 if passing on the stack.
4293 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4294 the preceding args and about the function being called.
4295 MODE is the argument's machine mode.
4296 TYPE is the data type of the argument (as a tree).
4297 This is null for libcalls where that information may
4299 NAMED is nonzero if this argument is a named parameter
4300 (otherwise it is an extra parameter matching an ellipsis).
4301 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
4302 *PREGNO records the register number to use if scalar type.
4303 *PPADDING records the amount of padding needed in words. */
4306 function_arg_slotno (const struct sparc_args
*cum
, enum machine_mode mode
,
4307 tree type
, int named
, int incoming_p
,
4308 int *pregno
, int *ppadding
)
4310 int regbase
= (incoming_p
4311 ? SPARC_INCOMING_INT_ARG_FIRST
4312 : SPARC_OUTGOING_INT_ARG_FIRST
);
4313 int slotno
= cum
->words
;
4314 enum mode_class mclass
;
4319 if (type
&& TREE_ADDRESSABLE (type
))
4325 && TYPE_ALIGN (type
) % PARM_BOUNDARY
!= 0)
4328 /* For SPARC64, objects requiring 16-byte alignment get it. */
4330 && GET_MODE_ALIGNMENT (mode
) >= 2 * BITS_PER_WORD
4331 && (slotno
& 1) != 0)
4332 slotno
++, *ppadding
= 1;
4334 mclass
= GET_MODE_CLASS (mode
);
4335 if (type
&& TREE_CODE (type
) == VECTOR_TYPE
)
4337 /* Vector types deserve special treatment because they are
4338 polymorphic wrt their mode, depending upon whether VIS
4339 instructions are enabled. */
4340 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
4342 /* The SPARC port defines no floating-point vector modes. */
4343 gcc_assert (mode
== BLKmode
);
4347 /* Integral vector types should either have a vector
4348 mode or an integral mode, because we are guaranteed
4349 by pass_by_reference that their size is not greater
4350 than 16 bytes and TImode is 16-byte wide. */
4351 gcc_assert (mode
!= BLKmode
);
4353 /* Vector integers are handled like floats according to
4355 mclass
= MODE_FLOAT
;
4362 case MODE_COMPLEX_FLOAT
:
4363 if (TARGET_ARCH64
&& TARGET_FPU
&& named
)
4365 if (slotno
>= SPARC_FP_ARG_MAX
)
4367 regno
= SPARC_FP_ARG_FIRST
+ slotno
* 2;
4368 /* Arguments filling only one single FP register are
4369 right-justified in the outer double FP register. */
4370 if (GET_MODE_SIZE (mode
) <= 4)
4377 case MODE_COMPLEX_INT
:
4378 if (slotno
>= SPARC_INT_ARG_MAX
)
4380 regno
= regbase
+ slotno
;
4384 if (mode
== VOIDmode
)
4385 /* MODE is VOIDmode when generating the actual call. */
4388 gcc_assert (mode
== BLKmode
);
4390 /* For SPARC64, objects requiring 16-byte alignment get it. */
4393 && TYPE_ALIGN (type
) >= 2 * BITS_PER_WORD
4394 && (slotno
& 1) != 0)
4395 slotno
++, *ppadding
= 1;
4397 if (TARGET_ARCH32
|| !type
|| (TREE_CODE (type
) == UNION_TYPE
))
4399 if (slotno
>= SPARC_INT_ARG_MAX
)
4401 regno
= regbase
+ slotno
;
4403 else /* TARGET_ARCH64 && type */
4405 int intregs_p
= 0, fpregs_p
= 0, packed_p
= 0;
4407 /* First see what kinds of registers we would need. */
4408 if (TREE_CODE (type
) == VECTOR_TYPE
)
4411 scan_record_type (type
, &intregs_p
, &fpregs_p
, &packed_p
);
4413 /* The ABI obviously doesn't specify how packed structures
4414 are passed. These are defined to be passed in int regs
4415 if possible, otherwise memory. */
4416 if (packed_p
|| !named
)
4417 fpregs_p
= 0, intregs_p
= 1;
4419 /* If all arg slots are filled, then must pass on stack. */
4420 if (fpregs_p
&& slotno
>= SPARC_FP_ARG_MAX
)
4423 /* If there are only int args and all int arg slots are filled,
4424 then must pass on stack. */
4425 if (!fpregs_p
&& intregs_p
&& slotno
>= SPARC_INT_ARG_MAX
)
4428 /* Note that even if all int arg slots are filled, fp members may
4429 still be passed in regs if such regs are available.
4430 *PREGNO isn't set because there may be more than one, it's up
4431 to the caller to compute them. */
4444 /* Handle recursive register counting for structure field layout. */
4446 struct function_arg_record_value_parms
4448 rtx ret
; /* return expression being built. */
4449 int slotno
; /* slot number of the argument. */
4450 int named
; /* whether the argument is named. */
4451 int regbase
; /* regno of the base register. */
4452 int stack
; /* 1 if part of the argument is on the stack. */
4453 int intoffset
; /* offset of the first pending integer field. */
4454 unsigned int nregs
; /* number of words passed in registers. */
4457 static void function_arg_record_value_3
4458 (HOST_WIDE_INT
, struct function_arg_record_value_parms
*);
4459 static void function_arg_record_value_2
4460 (tree
, HOST_WIDE_INT
, struct function_arg_record_value_parms
*, bool);
4461 static void function_arg_record_value_1
4462 (tree
, HOST_WIDE_INT
, struct function_arg_record_value_parms
*, bool);
4463 static rtx
function_arg_record_value (tree
, enum machine_mode
, int, int, int);
4464 static rtx
function_arg_union_value (int, enum machine_mode
, int, int);
4466 /* A subroutine of function_arg_record_value. Traverse the structure
4467 recursively and determine how many registers will be required. */
4470 function_arg_record_value_1 (tree type
, HOST_WIDE_INT startbitpos
,
4471 struct function_arg_record_value_parms
*parms
,
4476 /* We need to compute how many registers are needed so we can
4477 allocate the PARALLEL but before we can do that we need to know
4478 whether there are any packed fields. The ABI obviously doesn't
4479 specify how structures are passed in this case, so they are
4480 defined to be passed in int regs if possible, otherwise memory,
4481 regardless of whether there are fp values present. */
4484 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
4486 if (TREE_CODE (field
) == FIELD_DECL
&& DECL_PACKED (field
))
4493 /* Compute how many registers we need. */
4494 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
4496 if (TREE_CODE (field
) == FIELD_DECL
)
4498 HOST_WIDE_INT bitpos
= startbitpos
;
4500 if (DECL_SIZE (field
) != 0)
4502 if (integer_zerop (DECL_SIZE (field
)))
4505 if (host_integerp (bit_position (field
), 1))
4506 bitpos
+= int_bit_position (field
);
4509 /* ??? FIXME: else assume zero offset. */
4511 if (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
)
4512 function_arg_record_value_1 (TREE_TYPE (field
),
4516 else if ((FLOAT_TYPE_P (TREE_TYPE (field
))
4517 || TREE_CODE (TREE_TYPE (field
)) == VECTOR_TYPE
)
4522 if (parms
->intoffset
!= -1)
4524 unsigned int startbit
, endbit
;
4525 int intslots
, this_slotno
;
4527 startbit
= parms
->intoffset
& -BITS_PER_WORD
;
4528 endbit
= (bitpos
+ BITS_PER_WORD
- 1) & -BITS_PER_WORD
;
4530 intslots
= (endbit
- startbit
) / BITS_PER_WORD
;
4531 this_slotno
= parms
->slotno
+ parms
->intoffset
4534 if (intslots
> 0 && intslots
> SPARC_INT_ARG_MAX
- this_slotno
)
4536 intslots
= MAX (0, SPARC_INT_ARG_MAX
- this_slotno
);
4537 /* We need to pass this field on the stack. */
4541 parms
->nregs
+= intslots
;
4542 parms
->intoffset
= -1;
4545 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
4546 If it wasn't true we wouldn't be here. */
4547 if (TREE_CODE (TREE_TYPE (field
)) == VECTOR_TYPE
4548 && DECL_MODE (field
) == BLKmode
)
4549 parms
->nregs
+= TYPE_VECTOR_SUBPARTS (TREE_TYPE (field
));
4550 else if (TREE_CODE (TREE_TYPE (field
)) == COMPLEX_TYPE
)
4557 if (parms
->intoffset
== -1)
4558 parms
->intoffset
= bitpos
;
4564 /* A subroutine of function_arg_record_value. Assign the bits of the
4565 structure between parms->intoffset and bitpos to integer registers. */
4568 function_arg_record_value_3 (HOST_WIDE_INT bitpos
,
4569 struct function_arg_record_value_parms
*parms
)
4571 enum machine_mode mode
;
4573 unsigned int startbit
, endbit
;
4574 int this_slotno
, intslots
, intoffset
;
4577 if (parms
->intoffset
== -1)
4580 intoffset
= parms
->intoffset
;
4581 parms
->intoffset
= -1;
4583 startbit
= intoffset
& -BITS_PER_WORD
;
4584 endbit
= (bitpos
+ BITS_PER_WORD
- 1) & -BITS_PER_WORD
;
4585 intslots
= (endbit
- startbit
) / BITS_PER_WORD
;
4586 this_slotno
= parms
->slotno
+ intoffset
/ BITS_PER_WORD
;
4588 intslots
= MIN (intslots
, SPARC_INT_ARG_MAX
- this_slotno
);
4592 /* If this is the trailing part of a word, only load that much into
4593 the register. Otherwise load the whole register. Note that in
4594 the latter case we may pick up unwanted bits. It's not a problem
4595 at the moment but may wish to revisit. */
4597 if (intoffset
% BITS_PER_WORD
!= 0)
4598 mode
= smallest_mode_for_size (BITS_PER_WORD
- intoffset
% BITS_PER_WORD
,
4603 intoffset
/= BITS_PER_UNIT
;
4606 regno
= parms
->regbase
+ this_slotno
;
4607 reg
= gen_rtx_REG (mode
, regno
);
4608 XVECEXP (parms
->ret
, 0, parms
->stack
+ parms
->nregs
)
4609 = gen_rtx_EXPR_LIST (VOIDmode
, reg
, GEN_INT (intoffset
));
4612 intoffset
= (intoffset
| (UNITS_PER_WORD
-1)) + 1;
4617 while (intslots
> 0);
4620 /* A subroutine of function_arg_record_value. Traverse the structure
4621 recursively and assign bits to floating point registers. Track which
4622 bits in between need integer registers; invoke function_arg_record_value_3
4623 to make that happen. */
4626 function_arg_record_value_2 (tree type
, HOST_WIDE_INT startbitpos
,
4627 struct function_arg_record_value_parms
*parms
,
4633 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
4635 if (TREE_CODE (field
) == FIELD_DECL
&& DECL_PACKED (field
))
4642 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
4644 if (TREE_CODE (field
) == FIELD_DECL
)
4646 HOST_WIDE_INT bitpos
= startbitpos
;
4648 if (DECL_SIZE (field
) != 0)
4650 if (integer_zerop (DECL_SIZE (field
)))
4653 if (host_integerp (bit_position (field
), 1))
4654 bitpos
+= int_bit_position (field
);
4657 /* ??? FIXME: else assume zero offset. */
4659 if (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
)
4660 function_arg_record_value_2 (TREE_TYPE (field
),
4664 else if ((FLOAT_TYPE_P (TREE_TYPE (field
))
4665 || TREE_CODE (TREE_TYPE (field
)) == VECTOR_TYPE
)
4670 int this_slotno
= parms
->slotno
+ bitpos
/ BITS_PER_WORD
;
4671 int regno
, nregs
, pos
;
4672 enum machine_mode mode
= DECL_MODE (field
);
4675 function_arg_record_value_3 (bitpos
, parms
);
4677 if (TREE_CODE (TREE_TYPE (field
)) == VECTOR_TYPE
4680 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (field
)));
4681 nregs
= TYPE_VECTOR_SUBPARTS (TREE_TYPE (field
));
4683 else if (TREE_CODE (TREE_TYPE (field
)) == COMPLEX_TYPE
)
4685 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (field
)));
4691 regno
= SPARC_FP_ARG_FIRST
+ this_slotno
* 2;
4692 if (GET_MODE_SIZE (mode
) <= 4 && (bitpos
& 32) != 0)
4694 reg
= gen_rtx_REG (mode
, regno
);
4695 pos
= bitpos
/ BITS_PER_UNIT
;
4696 XVECEXP (parms
->ret
, 0, parms
->stack
+ parms
->nregs
)
4697 = gen_rtx_EXPR_LIST (VOIDmode
, reg
, GEN_INT (pos
));
4701 regno
+= GET_MODE_SIZE (mode
) / 4;
4702 reg
= gen_rtx_REG (mode
, regno
);
4703 pos
+= GET_MODE_SIZE (mode
);
4704 XVECEXP (parms
->ret
, 0, parms
->stack
+ parms
->nregs
)
4705 = gen_rtx_EXPR_LIST (VOIDmode
, reg
, GEN_INT (pos
));
4711 if (parms
->intoffset
== -1)
4712 parms
->intoffset
= bitpos
;
4718 /* Used by function_arg and function_value to implement the complex
4719 conventions of the 64-bit ABI for passing and returning structures.
4720 Return an expression valid as a return value for the two macros
4721 FUNCTION_ARG and FUNCTION_VALUE.
4723 TYPE is the data type of the argument (as a tree).
4724 This is null for libcalls where that information may
4726 MODE is the argument's machine mode.
4727 SLOTNO is the index number of the argument's slot in the parameter array.
4728 NAMED is nonzero if this argument is a named parameter
4729 (otherwise it is an extra parameter matching an ellipsis).
4730 REGBASE is the regno of the base register for the parameter array. */
4733 function_arg_record_value (tree type
, enum machine_mode mode
,
4734 int slotno
, int named
, int regbase
)
4736 HOST_WIDE_INT typesize
= int_size_in_bytes (type
);
4737 struct function_arg_record_value_parms parms
;
4740 parms
.ret
= NULL_RTX
;
4741 parms
.slotno
= slotno
;
4742 parms
.named
= named
;
4743 parms
.regbase
= regbase
;
4746 /* Compute how many registers we need. */
4748 parms
.intoffset
= 0;
4749 function_arg_record_value_1 (type
, 0, &parms
, false);
4751 /* Take into account pending integer fields. */
4752 if (parms
.intoffset
!= -1)
4754 unsigned int startbit
, endbit
;
4755 int intslots
, this_slotno
;
4757 startbit
= parms
.intoffset
& -BITS_PER_WORD
;
4758 endbit
= (typesize
*BITS_PER_UNIT
+ BITS_PER_WORD
- 1) & -BITS_PER_WORD
;
4759 intslots
= (endbit
- startbit
) / BITS_PER_WORD
;
4760 this_slotno
= slotno
+ parms
.intoffset
/ BITS_PER_WORD
;
4762 if (intslots
> 0 && intslots
> SPARC_INT_ARG_MAX
- this_slotno
)
4764 intslots
= MAX (0, SPARC_INT_ARG_MAX
- this_slotno
);
4765 /* We need to pass this field on the stack. */
4769 parms
.nregs
+= intslots
;
4771 nregs
= parms
.nregs
;
4773 /* Allocate the vector and handle some annoying special cases. */
4776 /* ??? Empty structure has no value? Duh? */
4779 /* Though there's nothing really to store, return a word register
4780 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
4781 leads to breakage due to the fact that there are zero bytes to
4783 return gen_rtx_REG (mode
, regbase
);
4787 /* ??? C++ has structures with no fields, and yet a size. Give up
4788 for now and pass everything back in integer registers. */
4789 nregs
= (typesize
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
4791 if (nregs
+ slotno
> SPARC_INT_ARG_MAX
)
4792 nregs
= SPARC_INT_ARG_MAX
- slotno
;
4794 gcc_assert (nregs
!= 0);
4796 parms
.ret
= gen_rtx_PARALLEL (mode
, rtvec_alloc (parms
.stack
+ nregs
));
4798 /* If at least one field must be passed on the stack, generate
4799 (parallel [(expr_list (nil) ...) ...]) so that all fields will
4800 also be passed on the stack. We can't do much better because the
4801 semantics of TARGET_ARG_PARTIAL_BYTES doesn't handle the case
4802 of structures for which the fields passed exclusively in registers
4803 are not at the beginning of the structure. */
4805 XVECEXP (parms
.ret
, 0, 0)
4806 = gen_rtx_EXPR_LIST (VOIDmode
, NULL_RTX
, const0_rtx
);
4808 /* Fill in the entries. */
4810 parms
.intoffset
= 0;
4811 function_arg_record_value_2 (type
, 0, &parms
, false);
4812 function_arg_record_value_3 (typesize
* BITS_PER_UNIT
, &parms
);
4814 gcc_assert (parms
.nregs
== nregs
);
4819 /* Used by function_arg and function_value to implement the conventions
4820 of the 64-bit ABI for passing and returning unions.
4821 Return an expression valid as a return value for the two macros
4822 FUNCTION_ARG and FUNCTION_VALUE.
4824 SIZE is the size in bytes of the union.
4825 MODE is the argument's machine mode.
4826 REGNO is the hard register the union will be passed in. */
4829 function_arg_union_value (int size
, enum machine_mode mode
, int slotno
,
4832 int nwords
= ROUND_ADVANCE (size
), i
;
4835 /* See comment in previous function for empty structures. */
4837 return gen_rtx_REG (mode
, regno
);
4839 if (slotno
== SPARC_INT_ARG_MAX
- 1)
4842 regs
= gen_rtx_PARALLEL (mode
, rtvec_alloc (nwords
));
4844 for (i
= 0; i
< nwords
; i
++)
4846 /* Unions are passed left-justified. */
4847 XVECEXP (regs
, 0, i
)
4848 = gen_rtx_EXPR_LIST (VOIDmode
,
4849 gen_rtx_REG (word_mode
, regno
),
4850 GEN_INT (UNITS_PER_WORD
* i
));
4857 /* Used by function_arg and function_value to implement the conventions
4858 for passing and returning large (BLKmode) vectors.
4859 Return an expression valid as a return value for the two macros
4860 FUNCTION_ARG and FUNCTION_VALUE.
4862 SIZE is the size in bytes of the vector.
4863 BASE_MODE is the argument's base machine mode.
4864 REGNO is the FP hard register the vector will be passed in. */
4867 function_arg_vector_value (int size
, enum machine_mode base_mode
, int regno
)
4869 unsigned short base_mode_size
= GET_MODE_SIZE (base_mode
);
4870 int nregs
= size
/ base_mode_size
, i
;
4873 regs
= gen_rtx_PARALLEL (BLKmode
, rtvec_alloc (nregs
));
4875 for (i
= 0; i
< nregs
; i
++)
4877 XVECEXP (regs
, 0, i
)
4878 = gen_rtx_EXPR_LIST (VOIDmode
,
4879 gen_rtx_REG (base_mode
, regno
),
4880 GEN_INT (base_mode_size
* i
));
4881 regno
+= base_mode_size
/ 4;
4887 /* Handle the FUNCTION_ARG macro.
4888 Determine where to put an argument to a function.
4889 Value is zero to push the argument on the stack,
4890 or a hard register in which to store the argument.
4892 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4893 the preceding args and about the function being called.
4894 MODE is the argument's machine mode.
4895 TYPE is the data type of the argument (as a tree).
4896 This is null for libcalls where that information may
4898 NAMED is nonzero if this argument is a named parameter
4899 (otherwise it is an extra parameter matching an ellipsis).
4900 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
4903 function_arg (const struct sparc_args
*cum
, enum machine_mode mode
,
4904 tree type
, int named
, int incoming_p
)
4906 int regbase
= (incoming_p
4907 ? SPARC_INCOMING_INT_ARG_FIRST
4908 : SPARC_OUTGOING_INT_ARG_FIRST
);
4909 int slotno
, regno
, padding
;
4910 enum mode_class mclass
= GET_MODE_CLASS (mode
);
4913 slotno
= function_arg_slotno (cum
, mode
, type
, named
, incoming_p
,
4921 reg
= gen_rtx_REG (mode
, regno
);
4925 if (type
&& TREE_CODE (type
) == RECORD_TYPE
)
4927 /* Structures up to 16 bytes in size are passed in arg slots on the
4928 stack and are promoted to registers where possible. */
4930 gcc_assert (int_size_in_bytes (type
) <= 16);
4932 return function_arg_record_value (type
, mode
, slotno
, named
, regbase
);
4934 else if (type
&& TREE_CODE (type
) == UNION_TYPE
)
4936 HOST_WIDE_INT size
= int_size_in_bytes (type
);
4938 gcc_assert (size
<= 16);
4940 return function_arg_union_value (size
, mode
, slotno
, regno
);
4942 else if (type
&& TREE_CODE (type
) == VECTOR_TYPE
)
4944 /* Vector types deserve special treatment because they are
4945 polymorphic wrt their mode, depending upon whether VIS
4946 instructions are enabled. */
4947 HOST_WIDE_INT size
= int_size_in_bytes (type
);
4949 gcc_assert (size
<= 16);
4951 if (mode
== BLKmode
)
4952 return function_arg_vector_value (size
,
4953 TYPE_MODE (TREE_TYPE (type
)),
4954 SPARC_FP_ARG_FIRST
+ 2*slotno
);
4956 mclass
= MODE_FLOAT
;
4959 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
4960 but also have the slot allocated for them.
4961 If no prototype is in scope fp values in register slots get passed
4962 in two places, either fp regs and int regs or fp regs and memory. */
4963 if ((mclass
== MODE_FLOAT
|| mclass
== MODE_COMPLEX_FLOAT
)
4964 && SPARC_FP_REG_P (regno
))
4966 reg
= gen_rtx_REG (mode
, regno
);
4967 if (cum
->prototype_p
|| cum
->libcall_p
)
4969 /* "* 2" because fp reg numbers are recorded in 4 byte
4972 /* ??? This will cause the value to be passed in the fp reg and
4973 in the stack. When a prototype exists we want to pass the
4974 value in the reg but reserve space on the stack. That's an
4975 optimization, and is deferred [for a bit]. */
4976 if ((regno
- SPARC_FP_ARG_FIRST
) >= SPARC_INT_ARG_MAX
* 2)
4977 return gen_rtx_PARALLEL (mode
,
4979 gen_rtx_EXPR_LIST (VOIDmode
,
4980 NULL_RTX
, const0_rtx
),
4981 gen_rtx_EXPR_LIST (VOIDmode
,
4985 /* ??? It seems that passing back a register even when past
4986 the area declared by REG_PARM_STACK_SPACE will allocate
4987 space appropriately, and will not copy the data onto the
4988 stack, exactly as we desire.
4990 This is due to locate_and_pad_parm being called in
4991 expand_call whenever reg_parm_stack_space > 0, which
4992 while beneficial to our example here, would seem to be
4993 in error from what had been intended. Ho hum... -- r~ */
5001 if ((regno
- SPARC_FP_ARG_FIRST
) < SPARC_INT_ARG_MAX
* 2)
5005 /* On incoming, we don't need to know that the value
5006 is passed in %f0 and %i0, and it confuses other parts
5007 causing needless spillage even on the simplest cases. */
5011 intreg
= (SPARC_OUTGOING_INT_ARG_FIRST
5012 + (regno
- SPARC_FP_ARG_FIRST
) / 2);
5014 v0
= gen_rtx_EXPR_LIST (VOIDmode
, reg
, const0_rtx
);
5015 v1
= gen_rtx_EXPR_LIST (VOIDmode
, gen_rtx_REG (mode
, intreg
),
5017 return gen_rtx_PARALLEL (mode
, gen_rtvec (2, v0
, v1
));
5021 v0
= gen_rtx_EXPR_LIST (VOIDmode
, NULL_RTX
, const0_rtx
);
5022 v1
= gen_rtx_EXPR_LIST (VOIDmode
, reg
, const0_rtx
);
5023 return gen_rtx_PARALLEL (mode
, gen_rtvec (2, v0
, v1
));
5029 /* Scalar or complex int. */
5030 reg
= gen_rtx_REG (mode
, regno
);
5036 /* For an arg passed partly in registers and partly in memory,
5037 this is the number of bytes of registers used.
5038 For args passed entirely in registers or entirely in memory, zero.
5040 Any arg that starts in the first 6 regs but won't entirely fit in them
5041 needs partial registers on v8. On v9, structures with integer
5042 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
5043 values that begin in the last fp reg [where "last fp reg" varies with the
5044 mode] will be split between that reg and memory. */
5047 sparc_arg_partial_bytes (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
5048 tree type
, bool named
)
5050 int slotno
, regno
, padding
;
5052 /* We pass 0 for incoming_p here, it doesn't matter. */
5053 slotno
= function_arg_slotno (cum
, mode
, type
, named
, 0, ®no
, &padding
);
5060 if ((slotno
+ (mode
== BLKmode
5061 ? ROUND_ADVANCE (int_size_in_bytes (type
))
5062 : ROUND_ADVANCE (GET_MODE_SIZE (mode
))))
5063 > SPARC_INT_ARG_MAX
)
5064 return (SPARC_INT_ARG_MAX
- slotno
) * UNITS_PER_WORD
;
5068 /* We are guaranteed by pass_by_reference that the size of the
5069 argument is not greater than 16 bytes, so we only need to return
5070 one word if the argument is partially passed in registers. */
5072 if (type
&& AGGREGATE_TYPE_P (type
))
5074 int size
= int_size_in_bytes (type
);
5076 if (size
> UNITS_PER_WORD
5077 && slotno
== SPARC_INT_ARG_MAX
- 1)
5078 return UNITS_PER_WORD
;
5080 else if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_INT
5081 || (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
5082 && ! (TARGET_FPU
&& named
)))
5084 /* The complex types are passed as packed types. */
5085 if (GET_MODE_SIZE (mode
) > UNITS_PER_WORD
5086 && slotno
== SPARC_INT_ARG_MAX
- 1)
5087 return UNITS_PER_WORD
;
5089 else if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
5091 if ((slotno
+ GET_MODE_SIZE (mode
) / UNITS_PER_WORD
)
5093 return UNITS_PER_WORD
;
5100 /* Handle the TARGET_PASS_BY_REFERENCE target hook.
5101 Specify whether to pass the argument by reference. */
5104 sparc_pass_by_reference (CUMULATIVE_ARGS
*cum ATTRIBUTE_UNUSED
,
5105 enum machine_mode mode
, tree type
,
5106 bool named ATTRIBUTE_UNUSED
)
5110 /* Original SPARC 32-bit ABI says that structures and unions,
5111 and quad-precision floats are passed by reference. For Pascal,
5112 also pass arrays by reference. All other base types are passed
5115 Extended ABI (as implemented by the Sun compiler) says that all
5116 complex floats are passed by reference. Pass complex integers
5117 in registers up to 8 bytes. More generally, enforce the 2-word
5118 cap for passing arguments in registers.
5120 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5121 integers are passed like floats of the same size, that is in
5122 registers up to 8 bytes. Pass all vector floats by reference
5123 like structure and unions. */
5124 return ((type
&& (AGGREGATE_TYPE_P (type
) || VECTOR_FLOAT_TYPE_P (type
)))
5126 /* Catch CDImode, TFmode, DCmode and TCmode. */
5127 || GET_MODE_SIZE (mode
) > 8
5129 && TREE_CODE (type
) == VECTOR_TYPE
5130 && (unsigned HOST_WIDE_INT
) int_size_in_bytes (type
) > 8));
5134 /* Original SPARC 64-bit ABI says that structures and unions
5135 smaller than 16 bytes are passed in registers, as well as
5136 all other base types. For Pascal, pass arrays by reference.
5138 Extended ABI (as implemented by the Sun compiler) says that
5139 complex floats are passed in registers up to 16 bytes. Pass
5140 all complex integers in registers up to 16 bytes. More generally,
5141 enforce the 2-word cap for passing arguments in registers.
5143 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5144 integers are passed like floats of the same size, that is in
5145 registers (up to 16 bytes). Pass all vector floats like structure
5147 return ((type
&& TREE_CODE (type
) == ARRAY_TYPE
)
5149 && (AGGREGATE_TYPE_P (type
) || TREE_CODE (type
) == VECTOR_TYPE
)
5150 && (unsigned HOST_WIDE_INT
) int_size_in_bytes (type
) > 16)
5151 /* Catch CTImode and TCmode. */
5152 || GET_MODE_SIZE (mode
) > 16);
5156 /* Handle the FUNCTION_ARG_ADVANCE macro.
5157 Update the data in CUM to advance over an argument
5158 of mode MODE and data type TYPE.
5159 TYPE is null for libcalls where that information may not be available. */
5162 function_arg_advance (struct sparc_args
*cum
, enum machine_mode mode
,
5163 tree type
, int named
)
5165 int slotno
, regno
, padding
;
5167 /* We pass 0 for incoming_p here, it doesn't matter. */
5168 slotno
= function_arg_slotno (cum
, mode
, type
, named
, 0, ®no
, &padding
);
5170 /* If register required leading padding, add it. */
5172 cum
->words
+= padding
;
5176 cum
->words
+= (mode
!= BLKmode
5177 ? ROUND_ADVANCE (GET_MODE_SIZE (mode
))
5178 : ROUND_ADVANCE (int_size_in_bytes (type
)));
5182 if (type
&& AGGREGATE_TYPE_P (type
))
5184 int size
= int_size_in_bytes (type
);
5188 else if (size
<= 16)
5190 else /* passed by reference */
5195 cum
->words
+= (mode
!= BLKmode
5196 ? ROUND_ADVANCE (GET_MODE_SIZE (mode
))
5197 : ROUND_ADVANCE (int_size_in_bytes (type
)));
5202 /* Handle the FUNCTION_ARG_PADDING macro.
5203 For the 64 bit ABI structs are always stored left shifted in their
5207 function_arg_padding (enum machine_mode mode
, tree type
)
5209 if (TARGET_ARCH64
&& type
!= 0 && AGGREGATE_TYPE_P (type
))
5212 /* Fall back to the default. */
5213 return DEFAULT_FUNCTION_ARG_PADDING (mode
, type
);
5216 /* Handle the TARGET_RETURN_IN_MEMORY target hook.
5217 Specify whether to return the return value in memory. */
5220 sparc_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
5223 /* Original SPARC 32-bit ABI says that structures and unions,
5224 and quad-precision floats are returned in memory. All other
5225 base types are returned in registers.
5227 Extended ABI (as implemented by the Sun compiler) says that
5228 all complex floats are returned in registers (8 FP registers
5229 at most for '_Complex long double'). Return all complex integers
5230 in registers (4 at most for '_Complex long long').
5232 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5233 integers are returned like floats of the same size, that is in
5234 registers up to 8 bytes and in memory otherwise. Return all
5235 vector floats in memory like structure and unions; note that
5236 they always have BLKmode like the latter. */
5237 return (TYPE_MODE (type
) == BLKmode
5238 || TYPE_MODE (type
) == TFmode
5239 || (TREE_CODE (type
) == VECTOR_TYPE
5240 && (unsigned HOST_WIDE_INT
) int_size_in_bytes (type
) > 8));
5242 /* Original SPARC 64-bit ABI says that structures and unions
5243 smaller than 32 bytes are returned in registers, as well as
5244 all other base types.
5246 Extended ABI (as implemented by the Sun compiler) says that all
5247 complex floats are returned in registers (8 FP registers at most
5248 for '_Complex long double'). Return all complex integers in
5249 registers (4 at most for '_Complex TItype').
5251 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5252 integers are returned like floats of the same size, that is in
5253 registers. Return all vector floats like structure and unions;
5254 note that they always have BLKmode like the latter. */
5255 return ((TYPE_MODE (type
) == BLKmode
5256 && (unsigned HOST_WIDE_INT
) int_size_in_bytes (type
) > 32));
5259 /* Handle the TARGET_STRUCT_VALUE target hook.
5260 Return where to find the structure return value address. */
5263 sparc_struct_value_rtx (tree fndecl ATTRIBUTE_UNUSED
, int incoming
)
5272 mem
= gen_rtx_MEM (Pmode
, plus_constant (frame_pointer_rtx
,
5273 STRUCT_VALUE_OFFSET
));
5275 mem
= gen_rtx_MEM (Pmode
, plus_constant (stack_pointer_rtx
,
5276 STRUCT_VALUE_OFFSET
));
5278 set_mem_alias_set (mem
, struct_value_alias_set
);
5283 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
5284 For v9, function return values are subject to the same rules as arguments,
5285 except that up to 32 bytes may be returned in registers. */
5288 function_value (tree type
, enum machine_mode mode
, int incoming_p
)
5290 /* Beware that the two values are swapped here wrt function_arg. */
5291 int regbase
= (incoming_p
5292 ? SPARC_OUTGOING_INT_ARG_FIRST
5293 : SPARC_INCOMING_INT_ARG_FIRST
);
5294 enum mode_class mclass
= GET_MODE_CLASS (mode
);
5297 if (type
&& TREE_CODE (type
) == VECTOR_TYPE
)
5299 /* Vector types deserve special treatment because they are
5300 polymorphic wrt their mode, depending upon whether VIS
5301 instructions are enabled. */
5302 HOST_WIDE_INT size
= int_size_in_bytes (type
);
5304 gcc_assert ((TARGET_ARCH32
&& size
<= 8)
5305 || (TARGET_ARCH64
&& size
<= 32));
5307 if (mode
== BLKmode
)
5308 return function_arg_vector_value (size
,
5309 TYPE_MODE (TREE_TYPE (type
)),
5310 SPARC_FP_ARG_FIRST
);
5312 mclass
= MODE_FLOAT
;
5314 else if (type
&& TARGET_ARCH64
)
5316 if (TREE_CODE (type
) == RECORD_TYPE
)
5318 /* Structures up to 32 bytes in size are passed in registers,
5319 promoted to fp registers where possible. */
5321 gcc_assert (int_size_in_bytes (type
) <= 32);
5323 return function_arg_record_value (type
, mode
, 0, 1, regbase
);
5325 else if (TREE_CODE (type
) == UNION_TYPE
)
5327 HOST_WIDE_INT size
= int_size_in_bytes (type
);
5329 gcc_assert (size
<= 32);
5331 return function_arg_union_value (size
, mode
, 0, regbase
);
5333 else if (AGGREGATE_TYPE_P (type
))
5335 /* All other aggregate types are passed in an integer register
5336 in a mode corresponding to the size of the type. */
5337 HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
5339 gcc_assert (bytes
<= 32);
5341 mode
= mode_for_size (bytes
* BITS_PER_UNIT
, MODE_INT
, 0);
5343 /* ??? We probably should have made the same ABI change in
5344 3.4.0 as the one we made for unions. The latter was
5345 required by the SCD though, while the former is not
5346 specified, so we favored compatibility and efficiency.
5348 Now we're stuck for aggregates larger than 16 bytes,
5349 because OImode vanished in the meantime. Let's not
5350 try to be unduly clever, and simply follow the ABI
5351 for unions in that case. */
5352 if (mode
== BLKmode
)
5353 return function_arg_union_value (bytes
, mode
, 0, regbase
);
5357 else if (mclass
== MODE_INT
5358 && GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
5362 if ((mclass
== MODE_FLOAT
|| mclass
== MODE_COMPLEX_FLOAT
)
5364 regno
= SPARC_FP_ARG_FIRST
;
5368 return gen_rtx_REG (mode
, regno
);
5371 /* Do what is necessary for `va_start'. We look at the current function
5372 to determine if stdarg or varargs is used and return the address of
5373 the first unnamed parameter. */
5376 sparc_builtin_saveregs (void)
5378 int first_reg
= current_function_args_info
.words
;
5382 for (regno
= first_reg
; regno
< SPARC_INT_ARG_MAX
; regno
++)
5383 emit_move_insn (gen_rtx_MEM (word_mode
,
5384 gen_rtx_PLUS (Pmode
,
5386 GEN_INT (FIRST_PARM_OFFSET (0)
5389 gen_rtx_REG (word_mode
,
5390 SPARC_INCOMING_INT_ARG_FIRST
+ regno
));
5392 address
= gen_rtx_PLUS (Pmode
,
5394 GEN_INT (FIRST_PARM_OFFSET (0)
5395 + UNITS_PER_WORD
* first_reg
));
5400 /* Implement `va_start' for stdarg. */
5403 sparc_va_start (tree valist
, rtx nextarg
)
5405 nextarg
= expand_builtin_saveregs ();
5406 std_expand_builtin_va_start (valist
, nextarg
);
5409 /* Implement `va_arg' for stdarg. */
5412 sparc_gimplify_va_arg (tree valist
, tree type
, tree
*pre_p
, tree
*post_p
)
5414 HOST_WIDE_INT size
, rsize
, align
;
5417 tree ptrtype
= build_pointer_type (type
);
5419 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
5422 size
= rsize
= UNITS_PER_WORD
;
5428 size
= int_size_in_bytes (type
);
5429 rsize
= (size
+ UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
;
5434 /* For SPARC64, objects requiring 16-byte alignment get it. */
5435 if (TYPE_ALIGN (type
) >= 2 * (unsigned) BITS_PER_WORD
)
5436 align
= 2 * UNITS_PER_WORD
;
5438 /* SPARC-V9 ABI states that structures up to 16 bytes in size
5439 are left-justified in their slots. */
5440 if (AGGREGATE_TYPE_P (type
))
5443 size
= rsize
= UNITS_PER_WORD
;
5453 incr
= fold (build2 (PLUS_EXPR
, ptr_type_node
, incr
,
5454 ssize_int (align
- 1)));
5455 incr
= fold (build2 (BIT_AND_EXPR
, ptr_type_node
, incr
,
5456 ssize_int (-align
)));
5459 gimplify_expr (&incr
, pre_p
, post_p
, is_gimple_val
, fb_rvalue
);
5462 if (BYTES_BIG_ENDIAN
&& size
< rsize
)
5463 addr
= fold (build2 (PLUS_EXPR
, ptr_type_node
, incr
,
5464 ssize_int (rsize
- size
)));
5468 addr
= fold_convert (build_pointer_type (ptrtype
), addr
);
5469 addr
= build_va_arg_indirect_ref (addr
);
5471 /* If the address isn't aligned properly for the type,
5472 we may need to copy to a temporary.
5473 FIXME: This is inefficient. Usually we can do this
5476 && TYPE_ALIGN (type
) > BITS_PER_WORD
)
5478 tree tmp
= create_tmp_var (type
, "va_arg_tmp");
5479 tree dest_addr
= build_fold_addr_expr (tmp
);
5481 tree copy
= build_function_call_expr
5482 (implicit_built_in_decls
[BUILT_IN_MEMCPY
],
5483 tree_cons (NULL_TREE
, dest_addr
,
5484 tree_cons (NULL_TREE
, addr
,
5485 tree_cons (NULL_TREE
, size_int (rsize
),
5488 gimplify_and_add (copy
, pre_p
);
5492 addr
= fold_convert (ptrtype
, addr
);
5494 incr
= fold (build2 (PLUS_EXPR
, ptr_type_node
, incr
, ssize_int (rsize
)));
5495 incr
= build2 (MODIFY_EXPR
, ptr_type_node
, valist
, incr
);
5496 gimplify_and_add (incr
, post_p
);
5498 return build_va_arg_indirect_ref (addr
);
5501 /* Implement the TARGET_VECTOR_MODE_SUPPORTED_P target hook.
5502 Specify whether the vector mode is supported by the hardware. */
5505 sparc_vector_mode_supported_p (enum machine_mode mode
)
5507 return TARGET_VIS
&& VECTOR_MODE_P (mode
) ? true : false;
5510 /* Return the string to output an unconditional branch to LABEL, which is
5511 the operand number of the label.
5513 DEST is the destination insn (i.e. the label), INSN is the source. */
5516 output_ubranch (rtx dest
, int label
, rtx insn
)
5518 static char string
[64];
5519 bool v9_form
= false;
5522 if (TARGET_V9
&& INSN_ADDRESSES_SET_P ())
5524 int delta
= (INSN_ADDRESSES (INSN_UID (dest
))
5525 - INSN_ADDRESSES (INSN_UID (insn
)));
5526 /* Leave some instructions for "slop". */
5527 if (delta
>= -260000 && delta
< 260000)
5532 strcpy (string
, "ba%*,pt\t%%xcc, ");
5534 strcpy (string
, "b%*\t");
5536 p
= strchr (string
, '\0');
5547 /* Return the string to output a conditional branch to LABEL, which is
5548 the operand number of the label. OP is the conditional expression.
5549 XEXP (OP, 0) is assumed to be a condition code register (integer or
5550 floating point) and its mode specifies what kind of comparison we made.
5552 DEST is the destination insn (i.e. the label), INSN is the source.
5554 REVERSED is nonzero if we should reverse the sense of the comparison.
5556 ANNUL is nonzero if we should generate an annulling branch. */
5559 output_cbranch (rtx op
, rtx dest
, int label
, int reversed
, int annul
,
5562 static char string
[64];
5563 enum rtx_code code
= GET_CODE (op
);
5564 rtx cc_reg
= XEXP (op
, 0);
5565 enum machine_mode mode
= GET_MODE (cc_reg
);
5566 const char *labelno
, *branch
;
5567 int spaces
= 8, far
;
5570 /* v9 branches are limited to +-1MB. If it is too far away,
5583 fbne,a,pn %fcc2, .LC29
5591 far
= TARGET_V9
&& (get_attr_length (insn
) >= 3);
5594 /* Reversal of FP compares takes care -- an ordered compare
5595 becomes an unordered compare and vice versa. */
5596 if (mode
== CCFPmode
|| mode
== CCFPEmode
)
5597 code
= reverse_condition_maybe_unordered (code
);
5599 code
= reverse_condition (code
);
5602 /* Start by writing the branch condition. */
5603 if (mode
== CCFPmode
|| mode
== CCFPEmode
)
5654 /* ??? !v9: FP branches cannot be preceded by another floating point
5655 insn. Because there is currently no concept of pre-delay slots,
5656 we can fix this only by always emitting a nop before a floating
5661 strcpy (string
, "nop\n\t");
5662 strcat (string
, branch
);
5675 if (mode
== CC_NOOVmode
|| mode
== CCX_NOOVmode
)
5687 if (mode
== CC_NOOVmode
|| mode
== CCX_NOOVmode
)
5708 strcpy (string
, branch
);
5710 spaces
-= strlen (branch
);
5711 p
= strchr (string
, '\0');
5713 /* Now add the annulling, the label, and a possible noop. */
5726 if (! far
&& insn
&& INSN_ADDRESSES_SET_P ())
5728 int delta
= (INSN_ADDRESSES (INSN_UID (dest
))
5729 - INSN_ADDRESSES (INSN_UID (insn
)));
5730 /* Leave some instructions for "slop". */
5731 if (delta
< -260000 || delta
>= 260000)
5735 if (mode
== CCFPmode
|| mode
== CCFPEmode
)
5737 static char v9_fcc_labelno
[] = "%%fccX, ";
5738 /* Set the char indicating the number of the fcc reg to use. */
5739 v9_fcc_labelno
[5] = REGNO (cc_reg
) - SPARC_FIRST_V9_FCC_REG
+ '0';
5740 labelno
= v9_fcc_labelno
;
5743 gcc_assert (REGNO (cc_reg
) == SPARC_FCC_REG
);
5747 else if (mode
== CCXmode
|| mode
== CCX_NOOVmode
)
5749 labelno
= "%%xcc, ";
5754 labelno
= "%%icc, ";
5759 if (*labelno
&& insn
&& (note
= find_reg_note (insn
, REG_BR_PROB
, NULL_RTX
)))
5762 ((INTVAL (XEXP (note
, 0)) >= REG_BR_PROB_BASE
/ 2) ^ far
)
5775 strcpy (p
, labelno
);
5776 p
= strchr (p
, '\0');
5779 strcpy (p
, ".+12\n\t nop\n\tb\t");
5780 /* Skip the next insn if requested or
5781 if we know that it will be a nop. */
5782 if (annul
|| ! final_sequence
)
5796 /* Emit a library call comparison between floating point X and Y.
5797 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
5798 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
5799 values as arguments instead of the TFmode registers themselves,
5800 that's why we cannot call emit_float_lib_cmp. */
5802 sparc_emit_float_lib_cmp (rtx x
, rtx y
, enum rtx_code comparison
)
5805 rtx slot0
, slot1
, result
, tem
, tem2
;
5806 enum machine_mode mode
;
5811 qpfunc
= (TARGET_ARCH64
) ? "_Qp_feq" : "_Q_feq";
5815 qpfunc
= (TARGET_ARCH64
) ? "_Qp_fne" : "_Q_fne";
5819 qpfunc
= (TARGET_ARCH64
) ? "_Qp_fgt" : "_Q_fgt";
5823 qpfunc
= (TARGET_ARCH64
) ? "_Qp_fge" : "_Q_fge";
5827 qpfunc
= (TARGET_ARCH64
) ? "_Qp_flt" : "_Q_flt";
5831 qpfunc
= (TARGET_ARCH64
) ? "_Qp_fle" : "_Q_fle";
5842 qpfunc
= (TARGET_ARCH64
) ? "_Qp_cmp" : "_Q_cmp";
5851 if (GET_CODE (x
) != MEM
)
5853 slot0
= assign_stack_temp (TFmode
, GET_MODE_SIZE(TFmode
), 0);
5854 emit_insn (gen_rtx_SET (VOIDmode
, slot0
, x
));
5859 if (GET_CODE (y
) != MEM
)
5861 slot1
= assign_stack_temp (TFmode
, GET_MODE_SIZE(TFmode
), 0);
5862 emit_insn (gen_rtx_SET (VOIDmode
, slot1
, y
));
5867 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, qpfunc
), LCT_NORMAL
,
5869 XEXP (slot0
, 0), Pmode
,
5870 XEXP (slot1
, 0), Pmode
);
5876 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, qpfunc
), LCT_NORMAL
,
5878 x
, TFmode
, y
, TFmode
);
5884 /* Immediately move the result of the libcall into a pseudo
5885 register so reload doesn't clobber the value if it needs
5886 the return register for a spill reg. */
5887 result
= gen_reg_rtx (mode
);
5888 emit_move_insn (result
, hard_libcall_value (mode
));
5893 emit_cmp_insn (result
, const0_rtx
, NE
, NULL_RTX
, mode
, 0);
5897 emit_cmp_insn (result
, GEN_INT(3), comparison
== UNORDERED
? EQ
: NE
,
5902 emit_cmp_insn (result
, const1_rtx
,
5903 comparison
== UNGT
? GT
: NE
, NULL_RTX
, mode
, 0);
5906 emit_cmp_insn (result
, const2_rtx
, NE
, NULL_RTX
, mode
, 0);
5909 tem
= gen_reg_rtx (mode
);
5911 emit_insn (gen_andsi3 (tem
, result
, const1_rtx
));
5913 emit_insn (gen_anddi3 (tem
, result
, const1_rtx
));
5914 emit_cmp_insn (tem
, const0_rtx
, NE
, NULL_RTX
, mode
, 0);
5918 tem
= gen_reg_rtx (mode
);
5920 emit_insn (gen_addsi3 (tem
, result
, const1_rtx
));
5922 emit_insn (gen_adddi3 (tem
, result
, const1_rtx
));
5923 tem2
= gen_reg_rtx (mode
);
5925 emit_insn (gen_andsi3 (tem2
, tem
, const2_rtx
));
5927 emit_insn (gen_anddi3 (tem2
, tem
, const2_rtx
));
5928 emit_cmp_insn (tem2
, const0_rtx
, comparison
== UNEQ
? EQ
: NE
,
5934 /* Generate an unsigned DImode to FP conversion. This is the same code
5935 optabs would emit if we didn't have TFmode patterns. */
5938 sparc_emit_floatunsdi (rtx
*operands
, enum machine_mode mode
)
5940 rtx neglab
, donelab
, i0
, i1
, f0
, in
, out
;
5943 in
= force_reg (DImode
, operands
[1]);
5944 neglab
= gen_label_rtx ();
5945 donelab
= gen_label_rtx ();
5946 i0
= gen_reg_rtx (DImode
);
5947 i1
= gen_reg_rtx (DImode
);
5948 f0
= gen_reg_rtx (mode
);
5950 emit_cmp_and_jump_insns (in
, const0_rtx
, LT
, const0_rtx
, DImode
, 0, neglab
);
5952 emit_insn (gen_rtx_SET (VOIDmode
, out
, gen_rtx_FLOAT (mode
, in
)));
5953 emit_jump_insn (gen_jump (donelab
));
5956 emit_label (neglab
);
5958 emit_insn (gen_lshrdi3 (i0
, in
, const1_rtx
));
5959 emit_insn (gen_anddi3 (i1
, in
, const1_rtx
));
5960 emit_insn (gen_iordi3 (i0
, i0
, i1
));
5961 emit_insn (gen_rtx_SET (VOIDmode
, f0
, gen_rtx_FLOAT (mode
, i0
)));
5962 emit_insn (gen_rtx_SET (VOIDmode
, out
, gen_rtx_PLUS (mode
, f0
, f0
)));
5964 emit_label (donelab
);
5967 /* Generate an FP to unsigned DImode conversion. This is the same code
5968 optabs would emit if we didn't have TFmode patterns. */
5971 sparc_emit_fixunsdi (rtx
*operands
, enum machine_mode mode
)
5973 rtx neglab
, donelab
, i0
, i1
, f0
, in
, out
, limit
;
5976 in
= force_reg (mode
, operands
[1]);
5977 neglab
= gen_label_rtx ();
5978 donelab
= gen_label_rtx ();
5979 i0
= gen_reg_rtx (DImode
);
5980 i1
= gen_reg_rtx (DImode
);
5981 limit
= gen_reg_rtx (mode
);
5982 f0
= gen_reg_rtx (mode
);
5984 emit_move_insn (limit
,
5985 CONST_DOUBLE_FROM_REAL_VALUE (
5986 REAL_VALUE_ATOF ("9223372036854775808.0", mode
), mode
));
5987 emit_cmp_and_jump_insns (in
, limit
, GE
, NULL_RTX
, mode
, 0, neglab
);
5989 emit_insn (gen_rtx_SET (VOIDmode
,
5991 gen_rtx_FIX (DImode
, gen_rtx_FIX (mode
, in
))));
5992 emit_jump_insn (gen_jump (donelab
));
5995 emit_label (neglab
);
5997 emit_insn (gen_rtx_SET (VOIDmode
, f0
, gen_rtx_MINUS (mode
, in
, limit
)));
5998 emit_insn (gen_rtx_SET (VOIDmode
,
6000 gen_rtx_FIX (DImode
, gen_rtx_FIX (mode
, f0
))));
6001 emit_insn (gen_movdi (i1
, const1_rtx
));
6002 emit_insn (gen_ashldi3 (i1
, i1
, GEN_INT (63)));
6003 emit_insn (gen_xordi3 (out
, i0
, i1
));
6005 emit_label (donelab
);
6008 /* Return the string to output a conditional branch to LABEL, testing
6009 register REG. LABEL is the operand number of the label; REG is the
6010 operand number of the reg. OP is the conditional expression. The mode
6011 of REG says what kind of comparison we made.
6013 DEST is the destination insn (i.e. the label), INSN is the source.
6015 REVERSED is nonzero if we should reverse the sense of the comparison.
6017 ANNUL is nonzero if we should generate an annulling branch. */
6020 output_v9branch (rtx op
, rtx dest
, int reg
, int label
, int reversed
,
6021 int annul
, rtx insn
)
6023 static char string
[64];
6024 enum rtx_code code
= GET_CODE (op
);
6025 enum machine_mode mode
= GET_MODE (XEXP (op
, 0));
6030 /* branch on register are limited to +-128KB. If it is too far away,
6043 brgez,a,pn %o1, .LC29
6049 ba,pt %xcc, .LC29 */
6051 far
= get_attr_length (insn
) >= 3;
6053 /* If not floating-point or if EQ or NE, we can just reverse the code. */
6055 code
= reverse_condition (code
);
6057 /* Only 64 bit versions of these instructions exist. */
6058 gcc_assert (mode
== DImode
);
6060 /* Start by writing the branch condition. */
6065 strcpy (string
, "brnz");
6069 strcpy (string
, "brz");
6073 strcpy (string
, "brgez");
6077 strcpy (string
, "brlz");
6081 strcpy (string
, "brlez");
6085 strcpy (string
, "brgz");
6092 p
= strchr (string
, '\0');
6094 /* Now add the annulling, reg, label, and nop. */
6101 if (insn
&& (note
= find_reg_note (insn
, REG_BR_PROB
, NULL_RTX
)))
6104 ((INTVAL (XEXP (note
, 0)) >= REG_BR_PROB_BASE
/ 2) ^ far
)
6109 *p
= p
< string
+ 8 ? '\t' : ' ';
6117 int veryfar
= 1, delta
;
6119 if (INSN_ADDRESSES_SET_P ())
6121 delta
= (INSN_ADDRESSES (INSN_UID (dest
))
6122 - INSN_ADDRESSES (INSN_UID (insn
)));
6123 /* Leave some instructions for "slop". */
6124 if (delta
>= -260000 && delta
< 260000)
6128 strcpy (p
, ".+12\n\t nop\n\t");
6129 /* Skip the next insn if requested or
6130 if we know that it will be a nop. */
6131 if (annul
|| ! final_sequence
)
6141 strcpy (p
, "ba,pt\t%%xcc, ");
6155 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
6156 Such instructions cannot be used in the delay slot of return insn on v9.
6157 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
6161 epilogue_renumber (register rtx
*where
, int test
)
6163 register const char *fmt
;
6165 register enum rtx_code code
;
6170 code
= GET_CODE (*where
);
6175 if (REGNO (*where
) >= 8 && REGNO (*where
) < 24) /* oX or lX */
6177 if (! test
&& REGNO (*where
) >= 24 && REGNO (*where
) < 32)
6178 *where
= gen_rtx_REG (GET_MODE (*where
), OUTGOING_REGNO (REGNO(*where
)));
6186 /* Do not replace the frame pointer with the stack pointer because
6187 it can cause the delayed instruction to load below the stack.
6188 This occurs when instructions like:
6190 (set (reg/i:SI 24 %i0)
6191 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
6192 (const_int -20 [0xffffffec])) 0))
6194 are in the return delayed slot. */
6196 if (GET_CODE (XEXP (*where
, 0)) == REG
6197 && REGNO (XEXP (*where
, 0)) == HARD_FRAME_POINTER_REGNUM
6198 && (GET_CODE (XEXP (*where
, 1)) != CONST_INT
6199 || INTVAL (XEXP (*where
, 1)) < SPARC_STACK_BIAS
))
6204 if (SPARC_STACK_BIAS
6205 && GET_CODE (XEXP (*where
, 0)) == REG
6206 && REGNO (XEXP (*where
, 0)) == HARD_FRAME_POINTER_REGNUM
)
6214 fmt
= GET_RTX_FORMAT (code
);
6216 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
6221 for (j
= XVECLEN (*where
, i
) - 1; j
>= 0; j
--)
6222 if (epilogue_renumber (&(XVECEXP (*where
, i
, j
)), test
))
6225 else if (fmt
[i
] == 'e'
6226 && epilogue_renumber (&(XEXP (*where
, i
)), test
))
6232 /* Leaf functions and non-leaf functions have different needs. */
6235 reg_leaf_alloc_order
[] = REG_LEAF_ALLOC_ORDER
;
6238 reg_nonleaf_alloc_order
[] = REG_ALLOC_ORDER
;
6240 static const int *const reg_alloc_orders
[] = {
6241 reg_leaf_alloc_order
,
6242 reg_nonleaf_alloc_order
};
6245 order_regs_for_local_alloc (void)
6247 static int last_order_nonleaf
= 1;
6249 if (regs_ever_live
[15] != last_order_nonleaf
)
6251 last_order_nonleaf
= !last_order_nonleaf
;
6252 memcpy ((char *) reg_alloc_order
,
6253 (const char *) reg_alloc_orders
[last_order_nonleaf
],
6254 FIRST_PSEUDO_REGISTER
* sizeof (int));
6258 /* Return 1 if REG and MEM are legitimate enough to allow the various
6259 mem<-->reg splits to be run. */
6262 sparc_splitdi_legitimate (rtx reg
, rtx mem
)
6264 /* Punt if we are here by mistake. */
6265 gcc_assert (reload_completed
);
6267 /* We must have an offsettable memory reference. */
6268 if (! offsettable_memref_p (mem
))
6271 /* If we have legitimate args for ldd/std, we do not want
6272 the split to happen. */
6273 if ((REGNO (reg
) % 2) == 0
6274 && mem_min_alignment (mem
, 8))
6281 /* Return 1 if x and y are some kind of REG and they refer to
6282 different hard registers. This test is guaranteed to be
6283 run after reload. */
6286 sparc_absnegfloat_split_legitimate (rtx x
, rtx y
)
6288 if (GET_CODE (x
) != REG
)
6290 if (GET_CODE (y
) != REG
)
6292 if (REGNO (x
) == REGNO (y
))
6297 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
6298 This makes them candidates for using ldd and std insns.
6300 Note reg1 and reg2 *must* be hard registers. */
6303 registers_ok_for_ldd_peep (rtx reg1
, rtx reg2
)
6305 /* We might have been passed a SUBREG. */
6306 if (GET_CODE (reg1
) != REG
|| GET_CODE (reg2
) != REG
)
6309 if (REGNO (reg1
) % 2 != 0)
6312 /* Integer ldd is deprecated in SPARC V9 */
6313 if (TARGET_V9
&& REGNO (reg1
) < 32)
6316 return (REGNO (reg1
) == REGNO (reg2
) - 1);
6319 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
6322 This can only happen when addr1 and addr2, the addresses in mem1
6323 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
6324 addr1 must also be aligned on a 64-bit boundary.
6326 Also iff dependent_reg_rtx is not null it should not be used to
6327 compute the address for mem1, i.e. we cannot optimize a sequence
6339 But, note that the transformation from:
6344 is perfectly fine. Thus, the peephole2 patterns always pass us
6345 the destination register of the first load, never the second one.
6347 For stores we don't have a similar problem, so dependent_reg_rtx is
6351 mems_ok_for_ldd_peep (rtx mem1
, rtx mem2
, rtx dependent_reg_rtx
)
6355 HOST_WIDE_INT offset1
;
6357 /* The mems cannot be volatile. */
6358 if (MEM_VOLATILE_P (mem1
) || MEM_VOLATILE_P (mem2
))
6361 /* MEM1 should be aligned on a 64-bit boundary. */
6362 if (MEM_ALIGN (mem1
) < 64)
6365 addr1
= XEXP (mem1
, 0);
6366 addr2
= XEXP (mem2
, 0);
6368 /* Extract a register number and offset (if used) from the first addr. */
6369 if (GET_CODE (addr1
) == PLUS
)
6371 /* If not a REG, return zero. */
6372 if (GET_CODE (XEXP (addr1
, 0)) != REG
)
6376 reg1
= REGNO (XEXP (addr1
, 0));
6377 /* The offset must be constant! */
6378 if (GET_CODE (XEXP (addr1
, 1)) != CONST_INT
)
6380 offset1
= INTVAL (XEXP (addr1
, 1));
6383 else if (GET_CODE (addr1
) != REG
)
6387 reg1
= REGNO (addr1
);
6388 /* This was a simple (mem (reg)) expression. Offset is 0. */
6392 /* Make sure the second address is a (mem (plus (reg) (const_int). */
6393 if (GET_CODE (addr2
) != PLUS
)
6396 if (GET_CODE (XEXP (addr2
, 0)) != REG
6397 || GET_CODE (XEXP (addr2
, 1)) != CONST_INT
)
6400 if (reg1
!= REGNO (XEXP (addr2
, 0)))
6403 if (dependent_reg_rtx
!= NULL_RTX
&& reg1
== REGNO (dependent_reg_rtx
))
6406 /* The first offset must be evenly divisible by 8 to ensure the
6407 address is 64 bit aligned. */
6408 if (offset1
% 8 != 0)
6411 /* The offset for the second addr must be 4 more than the first addr. */
6412 if (INTVAL (XEXP (addr2
, 1)) != offset1
+ 4)
6415 /* All the tests passed. addr1 and addr2 are valid for ldd and std
6420 /* Return 1 if reg is a pseudo, or is the first register in
6421 a hard register pair. This makes it a candidate for use in
6422 ldd and std insns. */
6425 register_ok_for_ldd (rtx reg
)
6427 /* We might have been passed a SUBREG. */
6428 if (GET_CODE (reg
) != REG
)
6431 if (REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
6432 return (REGNO (reg
) % 2 == 0);
6437 /* Print operand X (an rtx) in assembler syntax to file FILE.
6438 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
6439 For `%' followed by punctuation, CODE is the punctuation and X is null. */
6442 print_operand (FILE *file
, rtx x
, int code
)
6447 /* Output an insn in a delay slot. */
6449 sparc_indent_opcode
= 1;
6451 fputs ("\n\t nop", file
);
6454 /* Output an annul flag if there's nothing for the delay slot and we
6455 are optimizing. This is always used with '(' below.
6456 Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
6457 this is a dbx bug. So, we only do this when optimizing.
6458 On UltraSPARC, a branch in a delay slot causes a pipeline flush.
6459 Always emit a nop in case the next instruction is a branch. */
6460 if (! final_sequence
&& (optimize
&& (int)sparc_cpu
< PROCESSOR_V9
))
6464 /* Output a 'nop' if there's nothing for the delay slot and we are
6465 not optimizing. This is always used with '*' above. */
6466 if (! final_sequence
&& ! (optimize
&& (int)sparc_cpu
< PROCESSOR_V9
))
6467 fputs ("\n\t nop", file
);
6468 else if (final_sequence
)
6469 sparc_indent_opcode
= 1;
6472 /* Output the right displacement from the saved PC on function return.
6473 The caller may have placed an "unimp" insn immediately after the call
6474 so we have to account for it. This insn is used in the 32-bit ABI
6475 when calling a function that returns a non zero-sized structure. The
6476 64-bit ABI doesn't have it. Be careful to have this test be the same
6477 as that used on the call. */
6479 && current_function_returns_struct
6480 && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl
)))
6482 && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl
))))
6488 /* Output the Embedded Medium/Anywhere code model base register. */
6489 fputs (EMBMEDANY_BASE_REG
, file
);
6492 /* Print some local dynamic TLS name. */
6493 assemble_name (file
, get_some_local_dynamic_name ());
6497 /* Adjust the operand to take into account a RESTORE operation. */
6498 if (GET_CODE (x
) == CONST_INT
)
6500 else if (GET_CODE (x
) != REG
)
6501 output_operand_lossage ("invalid %%Y operand");
6502 else if (REGNO (x
) < 8)
6503 fputs (reg_names
[REGNO (x
)], file
);
6504 else if (REGNO (x
) >= 24 && REGNO (x
) < 32)
6505 fputs (reg_names
[REGNO (x
)-16], file
);
6507 output_operand_lossage ("invalid %%Y operand");
6510 /* Print out the low order register name of a register pair. */
6511 if (WORDS_BIG_ENDIAN
)
6512 fputs (reg_names
[REGNO (x
)+1], file
);
6514 fputs (reg_names
[REGNO (x
)], file
);
6517 /* Print out the high order register name of a register pair. */
6518 if (WORDS_BIG_ENDIAN
)
6519 fputs (reg_names
[REGNO (x
)], file
);
6521 fputs (reg_names
[REGNO (x
)+1], file
);
6524 /* Print out the second register name of a register pair or quad.
6525 I.e., R (%o0) => %o1. */
6526 fputs (reg_names
[REGNO (x
)+1], file
);
6529 /* Print out the third register name of a register quad.
6530 I.e., S (%o0) => %o2. */
6531 fputs (reg_names
[REGNO (x
)+2], file
);
6534 /* Print out the fourth register name of a register quad.
6535 I.e., T (%o0) => %o3. */
6536 fputs (reg_names
[REGNO (x
)+3], file
);
6539 /* Print a condition code register. */
6540 if (REGNO (x
) == SPARC_ICC_REG
)
6542 /* We don't handle CC[X]_NOOVmode because they're not supposed
6544 if (GET_MODE (x
) == CCmode
)
6545 fputs ("%icc", file
);
6546 else if (GET_MODE (x
) == CCXmode
)
6547 fputs ("%xcc", file
);
6552 /* %fccN register */
6553 fputs (reg_names
[REGNO (x
)], file
);
6556 /* Print the operand's address only. */
6557 output_address (XEXP (x
, 0));
6560 /* In this case we need a register. Use %g0 if the
6561 operand is const0_rtx. */
6563 || (GET_MODE (x
) != VOIDmode
&& x
== CONST0_RTX (GET_MODE (x
))))
6565 fputs ("%g0", file
);
6572 switch (GET_CODE (x
))
6574 case IOR
: fputs ("or", file
); break;
6575 case AND
: fputs ("and", file
); break;
6576 case XOR
: fputs ("xor", file
); break;
6577 default: output_operand_lossage ("invalid %%A operand");
6582 switch (GET_CODE (x
))
6584 case IOR
: fputs ("orn", file
); break;
6585 case AND
: fputs ("andn", file
); break;
6586 case XOR
: fputs ("xnor", file
); break;
6587 default: output_operand_lossage ("invalid %%B operand");
6591 /* These are used by the conditional move instructions. */
6595 enum rtx_code rc
= GET_CODE (x
);
6599 enum machine_mode mode
= GET_MODE (XEXP (x
, 0));
6600 if (mode
== CCFPmode
|| mode
== CCFPEmode
)
6601 rc
= reverse_condition_maybe_unordered (GET_CODE (x
));
6603 rc
= reverse_condition (GET_CODE (x
));
6607 case NE
: fputs ("ne", file
); break;
6608 case EQ
: fputs ("e", file
); break;
6609 case GE
: fputs ("ge", file
); break;
6610 case GT
: fputs ("g", file
); break;
6611 case LE
: fputs ("le", file
); break;
6612 case LT
: fputs ("l", file
); break;
6613 case GEU
: fputs ("geu", file
); break;
6614 case GTU
: fputs ("gu", file
); break;
6615 case LEU
: fputs ("leu", file
); break;
6616 case LTU
: fputs ("lu", file
); break;
6617 case LTGT
: fputs ("lg", file
); break;
6618 case UNORDERED
: fputs ("u", file
); break;
6619 case ORDERED
: fputs ("o", file
); break;
6620 case UNLT
: fputs ("ul", file
); break;
6621 case UNLE
: fputs ("ule", file
); break;
6622 case UNGT
: fputs ("ug", file
); break;
6623 case UNGE
: fputs ("uge", file
); break;
6624 case UNEQ
: fputs ("ue", file
); break;
6625 default: output_operand_lossage (code
== 'c'
6626 ? "invalid %%c operand"
6627 : "invalid %%C operand");
6632 /* These are used by the movr instruction pattern. */
6636 enum rtx_code rc
= (code
== 'd'
6637 ? reverse_condition (GET_CODE (x
))
6641 case NE
: fputs ("ne", file
); break;
6642 case EQ
: fputs ("e", file
); break;
6643 case GE
: fputs ("gez", file
); break;
6644 case LT
: fputs ("lz", file
); break;
6645 case LE
: fputs ("lez", file
); break;
6646 case GT
: fputs ("gz", file
); break;
6647 default: output_operand_lossage (code
== 'd'
6648 ? "invalid %%d operand"
6649 : "invalid %%D operand");
6656 /* Print a sign-extended character. */
6657 int i
= trunc_int_for_mode (INTVAL (x
), QImode
);
6658 fprintf (file
, "%d", i
);
6663 /* Operand must be a MEM; write its address. */
6664 if (GET_CODE (x
) != MEM
)
6665 output_operand_lossage ("invalid %%f operand");
6666 output_address (XEXP (x
, 0));
6671 /* Print a sign-extended 32-bit value. */
6673 if (GET_CODE(x
) == CONST_INT
)
6675 else if (GET_CODE(x
) == CONST_DOUBLE
)
6676 i
= CONST_DOUBLE_LOW (x
);
6679 output_operand_lossage ("invalid %%s operand");
6682 i
= trunc_int_for_mode (i
, SImode
);
6683 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, i
);
6688 /* Do nothing special. */
6692 /* Undocumented flag. */
6693 output_operand_lossage ("invalid operand output code");
6696 if (GET_CODE (x
) == REG
)
6697 fputs (reg_names
[REGNO (x
)], file
);
6698 else if (GET_CODE (x
) == MEM
)
6701 /* Poor Sun assembler doesn't understand absolute addressing. */
6702 if (CONSTANT_P (XEXP (x
, 0)))
6703 fputs ("%g0+", file
);
6704 output_address (XEXP (x
, 0));
6707 else if (GET_CODE (x
) == HIGH
)
6709 fputs ("%hi(", file
);
6710 output_addr_const (file
, XEXP (x
, 0));
6713 else if (GET_CODE (x
) == LO_SUM
)
6715 print_operand (file
, XEXP (x
, 0), 0);
6716 if (TARGET_CM_MEDMID
)
6717 fputs ("+%l44(", file
);
6719 fputs ("+%lo(", file
);
6720 output_addr_const (file
, XEXP (x
, 1));
6723 else if (GET_CODE (x
) == CONST_DOUBLE
6724 && (GET_MODE (x
) == VOIDmode
6725 || GET_MODE_CLASS (GET_MODE (x
)) == MODE_INT
))
6727 if (CONST_DOUBLE_HIGH (x
) == 0)
6728 fprintf (file
, "%u", (unsigned int) CONST_DOUBLE_LOW (x
));
6729 else if (CONST_DOUBLE_HIGH (x
) == -1
6730 && CONST_DOUBLE_LOW (x
) < 0)
6731 fprintf (file
, "%d", (int) CONST_DOUBLE_LOW (x
));
6733 output_operand_lossage ("long long constant not a valid immediate operand");
6735 else if (GET_CODE (x
) == CONST_DOUBLE
)
6736 output_operand_lossage ("floating point constant not a valid immediate operand");
6737 else { output_addr_const (file
, x
); }
6740 /* Target hook for assembling integer objects. The sparc version has
6741 special handling for aligned DI-mode objects. */
6744 sparc_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
6746 /* ??? We only output .xword's for symbols and only then in environments
6747 where the assembler can handle them. */
6748 if (aligned_p
&& size
== 8
6749 && (GET_CODE (x
) != CONST_INT
&& GET_CODE (x
) != CONST_DOUBLE
))
6753 assemble_integer_with_op ("\t.xword\t", x
);
6758 assemble_aligned_integer (4, const0_rtx
);
6759 assemble_aligned_integer (4, x
);
6763 return default_assemble_integer (x
, size
, aligned_p
);
6766 /* Return the value of a code used in the .proc pseudo-op that says
6767 what kind of result this function returns. For non-C types, we pick
6768 the closest C type. */
6770 #ifndef SHORT_TYPE_SIZE
6771 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
6774 #ifndef INT_TYPE_SIZE
6775 #define INT_TYPE_SIZE BITS_PER_WORD
6778 #ifndef LONG_TYPE_SIZE
6779 #define LONG_TYPE_SIZE BITS_PER_WORD
6782 #ifndef LONG_LONG_TYPE_SIZE
6783 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
6786 #ifndef FLOAT_TYPE_SIZE
6787 #define FLOAT_TYPE_SIZE BITS_PER_WORD
6790 #ifndef DOUBLE_TYPE_SIZE
6791 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6794 #ifndef LONG_DOUBLE_TYPE_SIZE
6795 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6799 sparc_type_code (register tree type
)
6801 register unsigned long qualifiers
= 0;
6802 register unsigned shift
;
6804 /* Only the first 30 bits of the qualifier are valid. We must refrain from
6805 setting more, since some assemblers will give an error for this. Also,
6806 we must be careful to avoid shifts of 32 bits or more to avoid getting
6807 unpredictable results. */
6809 for (shift
= 6; shift
< 30; shift
+= 2, type
= TREE_TYPE (type
))
6811 switch (TREE_CODE (type
))
6817 qualifiers
|= (3 << shift
);
6822 qualifiers
|= (2 << shift
);
6826 case REFERENCE_TYPE
:
6828 qualifiers
|= (1 << shift
);
6832 return (qualifiers
| 8);
6835 case QUAL_UNION_TYPE
:
6836 return (qualifiers
| 9);
6839 return (qualifiers
| 10);
6842 return (qualifiers
| 16);
6845 /* If this is a range type, consider it to be the underlying
6847 if (TREE_TYPE (type
) != 0)
6850 /* Carefully distinguish all the standard types of C,
6851 without messing up if the language is not C. We do this by
6852 testing TYPE_PRECISION and TYPE_UNSIGNED. The old code used to
6853 look at both the names and the above fields, but that's redundant.
6854 Any type whose size is between two C types will be considered
6855 to be the wider of the two types. Also, we do not have a
6856 special code to use for "long long", so anything wider than
6857 long is treated the same. Note that we can't distinguish
6858 between "int" and "long" in this code if they are the same
6859 size, but that's fine, since neither can the assembler. */
6861 if (TYPE_PRECISION (type
) <= CHAR_TYPE_SIZE
)
6862 return (qualifiers
| (TYPE_UNSIGNED (type
) ? 12 : 2));
6864 else if (TYPE_PRECISION (type
) <= SHORT_TYPE_SIZE
)
6865 return (qualifiers
| (TYPE_UNSIGNED (type
) ? 13 : 3));
6867 else if (TYPE_PRECISION (type
) <= INT_TYPE_SIZE
)
6868 return (qualifiers
| (TYPE_UNSIGNED (type
) ? 14 : 4));
6871 return (qualifiers
| (TYPE_UNSIGNED (type
) ? 15 : 5));
6874 /* If this is a range type, consider it to be the underlying
6876 if (TREE_TYPE (type
) != 0)
6879 /* Carefully distinguish all the standard types of C,
6880 without messing up if the language is not C. */
6882 if (TYPE_PRECISION (type
) == FLOAT_TYPE_SIZE
)
6883 return (qualifiers
| 6);
6886 return (qualifiers
| 7);
6888 case COMPLEX_TYPE
: /* GNU Fortran COMPLEX type. */
6889 /* ??? We need to distinguish between double and float complex types,
6890 but I don't know how yet because I can't reach this code from
6891 existing front-ends. */
6892 return (qualifiers
| 7); /* Who knows? */
6895 case CHAR_TYPE
: /* GNU Pascal CHAR type. Not used in C. */
6896 case BOOLEAN_TYPE
: /* GNU Fortran BOOLEAN type. */
6897 case LANG_TYPE
: /* ? */
6901 gcc_unreachable (); /* Not a type! */
6908 /* Nested function support. */
6910 /* Emit RTL insns to initialize the variable parts of a trampoline.
6911 FNADDR is an RTX for the address of the function's pure code.
6912 CXT is an RTX for the static chain value for the function.
6914 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
6915 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
6916 (to store insns). This is a bit excessive. Perhaps a different
6917 mechanism would be better here.
6919 Emit enough FLUSH insns to synchronize the data and instruction caches. */
6922 sparc_initialize_trampoline (rtx tramp
, rtx fnaddr
, rtx cxt
)
6924 /* SPARC 32-bit trampoline:
6927 sethi %hi(static), %g2
6929 or %g2, %lo(static), %g2
6931 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
6932 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
6936 (gen_rtx_MEM (SImode
, plus_constant (tramp
, 0)),
6937 expand_binop (SImode
, ior_optab
,
6938 expand_shift (RSHIFT_EXPR
, SImode
, fnaddr
,
6939 size_int (10), 0, 1),
6940 GEN_INT (trunc_int_for_mode (0x03000000, SImode
)),
6941 NULL_RTX
, 1, OPTAB_DIRECT
));
6944 (gen_rtx_MEM (SImode
, plus_constant (tramp
, 4)),
6945 expand_binop (SImode
, ior_optab
,
6946 expand_shift (RSHIFT_EXPR
, SImode
, cxt
,
6947 size_int (10), 0, 1),
6948 GEN_INT (trunc_int_for_mode (0x05000000, SImode
)),
6949 NULL_RTX
, 1, OPTAB_DIRECT
));
6952 (gen_rtx_MEM (SImode
, plus_constant (tramp
, 8)),
6953 expand_binop (SImode
, ior_optab
,
6954 expand_and (SImode
, fnaddr
, GEN_INT (0x3ff), NULL_RTX
),
6955 GEN_INT (trunc_int_for_mode (0x81c06000, SImode
)),
6956 NULL_RTX
, 1, OPTAB_DIRECT
));
6959 (gen_rtx_MEM (SImode
, plus_constant (tramp
, 12)),
6960 expand_binop (SImode
, ior_optab
,
6961 expand_and (SImode
, cxt
, GEN_INT (0x3ff), NULL_RTX
),
6962 GEN_INT (trunc_int_for_mode (0x8410a000, SImode
)),
6963 NULL_RTX
, 1, OPTAB_DIRECT
));
6965 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
6966 aligned on a 16 byte boundary so one flush clears it all. */
6967 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode
, tramp
))));
6968 if (sparc_cpu
!= PROCESSOR_ULTRASPARC
6969 && sparc_cpu
!= PROCESSOR_ULTRASPARC3
)
6970 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode
,
6971 plus_constant (tramp
, 8)))));
6973 /* Call __enable_execute_stack after writing onto the stack to make sure
6974 the stack address is accessible. */
6975 #ifdef ENABLE_EXECUTE_STACK
6976 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, "__enable_execute_stack"),
6977 LCT_NORMAL
, VOIDmode
, 1, tramp
, Pmode
);
6982 /* The 64-bit version is simpler because it makes more sense to load the
6983 values as "immediate" data out of the trampoline. It's also easier since
6984 we can read the PC without clobbering a register. */
6987 sparc64_initialize_trampoline (rtx tramp
, rtx fnaddr
, rtx cxt
)
6989 /* SPARC 64-bit trampoline:
6998 emit_move_insn (gen_rtx_MEM (SImode
, tramp
),
6999 GEN_INT (trunc_int_for_mode (0x83414000, SImode
)));
7000 emit_move_insn (gen_rtx_MEM (SImode
, plus_constant (tramp
, 4)),
7001 GEN_INT (trunc_int_for_mode (0xca586018, SImode
)));
7002 emit_move_insn (gen_rtx_MEM (SImode
, plus_constant (tramp
, 8)),
7003 GEN_INT (trunc_int_for_mode (0x81c14000, SImode
)));
7004 emit_move_insn (gen_rtx_MEM (SImode
, plus_constant (tramp
, 12)),
7005 GEN_INT (trunc_int_for_mode (0xca586010, SImode
)));
7006 emit_move_insn (gen_rtx_MEM (DImode
, plus_constant (tramp
, 16)), cxt
);
7007 emit_move_insn (gen_rtx_MEM (DImode
, plus_constant (tramp
, 24)), fnaddr
);
7008 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode
, tramp
))));
7010 if (sparc_cpu
!= PROCESSOR_ULTRASPARC
7011 && sparc_cpu
!= PROCESSOR_ULTRASPARC3
)
7012 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode
, plus_constant (tramp
, 8)))));
7014 /* Call __enable_execute_stack after writing onto the stack to make sure
7015 the stack address is accessible. */
7016 #ifdef ENABLE_EXECUTE_STACK
7017 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, "__enable_execute_stack"),
7018 LCT_NORMAL
, VOIDmode
, 1, tramp
, Pmode
);
7022 /* Adjust the cost of a scheduling dependency. Return the new cost of
7023 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7026 supersparc_adjust_cost (rtx insn
, rtx link
, rtx dep_insn
, int cost
)
7028 enum attr_type insn_type
;
7030 if (! recog_memoized (insn
))
7033 insn_type
= get_attr_type (insn
);
7035 if (REG_NOTE_KIND (link
) == 0)
7037 /* Data dependency; DEP_INSN writes a register that INSN reads some
7040 /* if a load, then the dependence must be on the memory address;
7041 add an extra "cycle". Note that the cost could be two cycles
7042 if the reg was written late in an instruction group; we ca not tell
7044 if (insn_type
== TYPE_LOAD
|| insn_type
== TYPE_FPLOAD
)
7047 /* Get the delay only if the address of the store is the dependence. */
7048 if (insn_type
== TYPE_STORE
|| insn_type
== TYPE_FPSTORE
)
7050 rtx pat
= PATTERN(insn
);
7051 rtx dep_pat
= PATTERN (dep_insn
);
7053 if (GET_CODE (pat
) != SET
|| GET_CODE (dep_pat
) != SET
)
7054 return cost
; /* This should not happen! */
7056 /* The dependency between the two instructions was on the data that
7057 is being stored. Assume that this implies that the address of the
7058 store is not dependent. */
7059 if (rtx_equal_p (SET_DEST (dep_pat
), SET_SRC (pat
)))
7062 return cost
+ 3; /* An approximation. */
7065 /* A shift instruction cannot receive its data from an instruction
7066 in the same cycle; add a one cycle penalty. */
7067 if (insn_type
== TYPE_SHIFT
)
7068 return cost
+ 3; /* Split before cascade into shift. */
7072 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7073 INSN writes some cycles later. */
7075 /* These are only significant for the fpu unit; writing a fp reg before
7076 the fpu has finished with it stalls the processor. */
7078 /* Reusing an integer register causes no problems. */
7079 if (insn_type
== TYPE_IALU
|| insn_type
== TYPE_SHIFT
)
7087 hypersparc_adjust_cost (rtx insn
, rtx link
, rtx dep_insn
, int cost
)
7089 enum attr_type insn_type
, dep_type
;
7090 rtx pat
= PATTERN(insn
);
7091 rtx dep_pat
= PATTERN (dep_insn
);
7093 if (recog_memoized (insn
) < 0 || recog_memoized (dep_insn
) < 0)
7096 insn_type
= get_attr_type (insn
);
7097 dep_type
= get_attr_type (dep_insn
);
7099 switch (REG_NOTE_KIND (link
))
7102 /* Data dependency; DEP_INSN writes a register that INSN reads some
7109 /* Get the delay iff the address of the store is the dependence. */
7110 if (GET_CODE (pat
) != SET
|| GET_CODE (dep_pat
) != SET
)
7113 if (rtx_equal_p (SET_DEST (dep_pat
), SET_SRC (pat
)))
7120 /* If a load, then the dependence must be on the memory address. If
7121 the addresses aren't equal, then it might be a false dependency */
7122 if (dep_type
== TYPE_STORE
|| dep_type
== TYPE_FPSTORE
)
7124 if (GET_CODE (pat
) != SET
|| GET_CODE (dep_pat
) != SET
7125 || GET_CODE (SET_DEST (dep_pat
)) != MEM
7126 || GET_CODE (SET_SRC (pat
)) != MEM
7127 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat
), 0),
7128 XEXP (SET_SRC (pat
), 0)))
7136 /* Compare to branch latency is 0. There is no benefit from
7137 separating compare and branch. */
7138 if (dep_type
== TYPE_COMPARE
)
7140 /* Floating point compare to branch latency is less than
7141 compare to conditional move. */
7142 if (dep_type
== TYPE_FPCMP
)
7151 /* Anti-dependencies only penalize the fpu unit. */
7152 if (insn_type
== TYPE_IALU
|| insn_type
== TYPE_SHIFT
)
7164 sparc_adjust_cost(rtx insn
, rtx link
, rtx dep
, int cost
)
7168 case PROCESSOR_SUPERSPARC
:
7169 cost
= supersparc_adjust_cost (insn
, link
, dep
, cost
);
7171 case PROCESSOR_HYPERSPARC
:
7172 case PROCESSOR_SPARCLITE86X
:
7173 cost
= hypersparc_adjust_cost (insn
, link
, dep
, cost
);
7182 sparc_sched_init (FILE *dump ATTRIBUTE_UNUSED
,
7183 int sched_verbose ATTRIBUTE_UNUSED
,
7184 int max_ready ATTRIBUTE_UNUSED
)
7189 sparc_use_sched_lookahead (void)
7191 if (sparc_cpu
== PROCESSOR_ULTRASPARC
7192 || sparc_cpu
== PROCESSOR_ULTRASPARC3
)
7194 if ((1 << sparc_cpu
) &
7195 ((1 << PROCESSOR_SUPERSPARC
) | (1 << PROCESSOR_HYPERSPARC
) |
7196 (1 << PROCESSOR_SPARCLITE86X
)))
7202 sparc_issue_rate (void)
7209 /* Assume V9 processors are capable of at least dual-issue. */
7211 case PROCESSOR_SUPERSPARC
:
7213 case PROCESSOR_HYPERSPARC
:
7214 case PROCESSOR_SPARCLITE86X
:
7216 case PROCESSOR_ULTRASPARC
:
7217 case PROCESSOR_ULTRASPARC3
:
7223 set_extends (rtx insn
)
7225 register rtx pat
= PATTERN (insn
);
7227 switch (GET_CODE (SET_SRC (pat
)))
7229 /* Load and some shift instructions zero extend. */
7232 /* sethi clears the high bits */
7234 /* LO_SUM is used with sethi. sethi cleared the high
7235 bits and the values used with lo_sum are positive */
7237 /* Store flag stores 0 or 1 */
7247 rtx op0
= XEXP (SET_SRC (pat
), 0);
7248 rtx op1
= XEXP (SET_SRC (pat
), 1);
7249 if (GET_CODE (op1
) == CONST_INT
)
7250 return INTVAL (op1
) >= 0;
7251 if (GET_CODE (op0
) != REG
)
7253 if (sparc_check_64 (op0
, insn
) == 1)
7255 return (GET_CODE (op1
) == REG
&& sparc_check_64 (op1
, insn
) == 1);
7260 rtx op0
= XEXP (SET_SRC (pat
), 0);
7261 rtx op1
= XEXP (SET_SRC (pat
), 1);
7262 if (GET_CODE (op0
) != REG
|| sparc_check_64 (op0
, insn
) <= 0)
7264 if (GET_CODE (op1
) == CONST_INT
)
7265 return INTVAL (op1
) >= 0;
7266 return (GET_CODE (op1
) == REG
&& sparc_check_64 (op1
, insn
) == 1);
7269 return GET_MODE (SET_SRC (pat
)) == SImode
;
7270 /* Positive integers leave the high bits zero. */
7272 return ! (CONST_DOUBLE_LOW (SET_SRC (pat
)) & 0x80000000);
7274 return ! (INTVAL (SET_SRC (pat
)) & 0x80000000);
7277 return - (GET_MODE (SET_SRC (pat
)) == SImode
);
7279 return sparc_check_64 (SET_SRC (pat
), insn
);
7285 /* We _ought_ to have only one kind per function, but... */
7286 static GTY(()) rtx sparc_addr_diff_list
;
7287 static GTY(()) rtx sparc_addr_list
;
7290 sparc_defer_case_vector (rtx lab
, rtx vec
, int diff
)
7292 vec
= gen_rtx_EXPR_LIST (VOIDmode
, lab
, vec
);
7294 sparc_addr_diff_list
7295 = gen_rtx_EXPR_LIST (VOIDmode
, vec
, sparc_addr_diff_list
);
7297 sparc_addr_list
= gen_rtx_EXPR_LIST (VOIDmode
, vec
, sparc_addr_list
);
7301 sparc_output_addr_vec (rtx vec
)
7303 rtx lab
= XEXP (vec
, 0), body
= XEXP (vec
, 1);
7304 int idx
, vlen
= XVECLEN (body
, 0);
7306 #ifdef ASM_OUTPUT_ADDR_VEC_START
7307 ASM_OUTPUT_ADDR_VEC_START (asm_out_file
);
7310 #ifdef ASM_OUTPUT_CASE_LABEL
7311 ASM_OUTPUT_CASE_LABEL (asm_out_file
, "L", CODE_LABEL_NUMBER (lab
),
7314 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L", CODE_LABEL_NUMBER (lab
));
7317 for (idx
= 0; idx
< vlen
; idx
++)
7319 ASM_OUTPUT_ADDR_VEC_ELT
7320 (asm_out_file
, CODE_LABEL_NUMBER (XEXP (XVECEXP (body
, 0, idx
), 0)));
7323 #ifdef ASM_OUTPUT_ADDR_VEC_END
7324 ASM_OUTPUT_ADDR_VEC_END (asm_out_file
);
7329 sparc_output_addr_diff_vec (rtx vec
)
7331 rtx lab
= XEXP (vec
, 0), body
= XEXP (vec
, 1);
7332 rtx base
= XEXP (XEXP (body
, 0), 0);
7333 int idx
, vlen
= XVECLEN (body
, 1);
7335 #ifdef ASM_OUTPUT_ADDR_VEC_START
7336 ASM_OUTPUT_ADDR_VEC_START (asm_out_file
);
7339 #ifdef ASM_OUTPUT_CASE_LABEL
7340 ASM_OUTPUT_CASE_LABEL (asm_out_file
, "L", CODE_LABEL_NUMBER (lab
),
7343 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L", CODE_LABEL_NUMBER (lab
));
7346 for (idx
= 0; idx
< vlen
; idx
++)
7348 ASM_OUTPUT_ADDR_DIFF_ELT
7351 CODE_LABEL_NUMBER (XEXP (XVECEXP (body
, 1, idx
), 0)),
7352 CODE_LABEL_NUMBER (base
));
7355 #ifdef ASM_OUTPUT_ADDR_VEC_END
7356 ASM_OUTPUT_ADDR_VEC_END (asm_out_file
);
7361 sparc_output_deferred_case_vectors (void)
7366 if (sparc_addr_list
== NULL_RTX
7367 && sparc_addr_diff_list
== NULL_RTX
)
7370 /* Align to cache line in the function's code section. */
7371 current_function_section (current_function_decl
);
7373 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
7375 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
7377 for (t
= sparc_addr_list
; t
; t
= XEXP (t
, 1))
7378 sparc_output_addr_vec (XEXP (t
, 0));
7379 for (t
= sparc_addr_diff_list
; t
; t
= XEXP (t
, 1))
7380 sparc_output_addr_diff_vec (XEXP (t
, 0));
7382 sparc_addr_list
= sparc_addr_diff_list
= NULL_RTX
;
7385 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
7386 unknown. Return 1 if the high bits are zero, -1 if the register is
7389 sparc_check_64 (rtx x
, rtx insn
)
7391 /* If a register is set only once it is safe to ignore insns this
7392 code does not know how to handle. The loop will either recognize
7393 the single set and return the correct value or fail to recognize
7398 gcc_assert (GET_CODE (x
) == REG
);
7400 if (GET_MODE (x
) == DImode
)
7401 y
= gen_rtx_REG (SImode
, REGNO (x
) + WORDS_BIG_ENDIAN
);
7403 if (flag_expensive_optimizations
7404 && REG_N_SETS (REGNO (y
)) == 1)
7410 insn
= get_last_insn_anywhere ();
7415 while ((insn
= PREV_INSN (insn
)))
7417 switch (GET_CODE (insn
))
7430 rtx pat
= PATTERN (insn
);
7431 if (GET_CODE (pat
) != SET
)
7433 if (rtx_equal_p (x
, SET_DEST (pat
)))
7434 return set_extends (insn
);
7435 if (y
&& rtx_equal_p (y
, SET_DEST (pat
)))
7436 return set_extends (insn
);
7437 if (reg_overlap_mentioned_p (SET_DEST (pat
), y
))
7445 /* Returns assembly code to perform a DImode shift using
7446 a 64-bit global or out register on SPARC-V8+. */
7448 output_v8plus_shift (rtx
*operands
, rtx insn
, const char *opcode
)
7450 static char asm_code
[60];
7452 /* The scratch register is only required when the destination
7453 register is not a 64-bit global or out register. */
7454 if (which_alternative
!= 2)
7455 operands
[3] = operands
[0];
7457 /* We can only shift by constants <= 63. */
7458 if (GET_CODE (operands
[2]) == CONST_INT
)
7459 operands
[2] = GEN_INT (INTVAL (operands
[2]) & 0x3f);
7461 if (GET_CODE (operands
[1]) == CONST_INT
)
7463 output_asm_insn ("mov\t%1, %3", operands
);
7467 output_asm_insn ("sllx\t%H1, 32, %3", operands
);
7468 if (sparc_check_64 (operands
[1], insn
) <= 0)
7469 output_asm_insn ("srl\t%L1, 0, %L1", operands
);
7470 output_asm_insn ("or\t%L1, %3, %3", operands
);
7473 strcpy(asm_code
, opcode
);
7475 if (which_alternative
!= 2)
7476 return strcat (asm_code
, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
7478 return strcat (asm_code
, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
7481 /* Output rtl to increment the profiler label LABELNO
7482 for profiling a function entry. */
7485 sparc_profile_hook (int labelno
)
7490 ASM_GENERATE_INTERNAL_LABEL (buf
, "LP", labelno
);
7491 lab
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (buf
));
7492 fun
= gen_rtx_SYMBOL_REF (Pmode
, MCOUNT_FUNCTION
);
7494 emit_library_call (fun
, LCT_NORMAL
, VOIDmode
, 1, lab
, Pmode
);
7497 #ifdef OBJECT_FORMAT_ELF
7499 sparc_elf_asm_named_section (const char *name
, unsigned int flags
,
7502 if (flags
& SECTION_MERGE
)
7504 /* entsize cannot be expressed in this section attributes
7506 default_elf_asm_named_section (name
, flags
, decl
);
7510 fprintf (asm_out_file
, "\t.section\t\"%s\"", name
);
7512 if (!(flags
& SECTION_DEBUG
))
7513 fputs (",#alloc", asm_out_file
);
7514 if (flags
& SECTION_WRITE
)
7515 fputs (",#write", asm_out_file
);
7516 if (flags
& SECTION_TLS
)
7517 fputs (",#tls", asm_out_file
);
7518 if (flags
& SECTION_CODE
)
7519 fputs (",#execinstr", asm_out_file
);
7521 /* ??? Handle SECTION_BSS. */
7523 fputc ('\n', asm_out_file
);
7525 #endif /* OBJECT_FORMAT_ELF */
7527 /* We do not allow indirect calls to be optimized into sibling calls.
7529 We cannot use sibling calls when delayed branches are disabled
7530 because they will likely require the call delay slot to be filled.
7532 Also, on SPARC 32-bit we cannot emit a sibling call when the
7533 current function returns a structure. This is because the "unimp
7534 after call" convention would cause the callee to return to the
7535 wrong place. The generic code already disallows cases where the
7536 function being called returns a structure.
7538 It may seem strange how this last case could occur. Usually there
7539 is code after the call which jumps to epilogue code which dumps the
7540 return value into the struct return area. That ought to invalidate
7541 the sibling call right? Well, in the C++ case we can end up passing
7542 the pointer to the struct return area to a constructor (which returns
7543 void) and then nothing else happens. Such a sibling call would look
7544 valid without the added check here. */
7546 sparc_function_ok_for_sibcall (tree decl
, tree exp ATTRIBUTE_UNUSED
)
7549 && flag_delayed_branch
7550 && (TARGET_ARCH64
|| ! current_function_returns_struct
));
7553 /* libfunc renaming. */
7554 #include "config/gofast.h"
7557 sparc_init_libfuncs (void)
7561 /* Use the subroutines that Sun's library provides for integer
7562 multiply and divide. The `*' prevents an underscore from
7563 being prepended by the compiler. .umul is a little faster
7565 set_optab_libfunc (smul_optab
, SImode
, "*.umul");
7566 set_optab_libfunc (sdiv_optab
, SImode
, "*.div");
7567 set_optab_libfunc (udiv_optab
, SImode
, "*.udiv");
7568 set_optab_libfunc (smod_optab
, SImode
, "*.rem");
7569 set_optab_libfunc (umod_optab
, SImode
, "*.urem");
7571 /* TFmode arithmetic. These names are part of the SPARC 32bit ABI. */
7572 set_optab_libfunc (add_optab
, TFmode
, "_Q_add");
7573 set_optab_libfunc (sub_optab
, TFmode
, "_Q_sub");
7574 set_optab_libfunc (neg_optab
, TFmode
, "_Q_neg");
7575 set_optab_libfunc (smul_optab
, TFmode
, "_Q_mul");
7576 set_optab_libfunc (sdiv_optab
, TFmode
, "_Q_div");
7578 /* We can define the TFmode sqrt optab only if TARGET_FPU. This
7579 is because with soft-float, the SFmode and DFmode sqrt
7580 instructions will be absent, and the compiler will notice and
7581 try to use the TFmode sqrt instruction for calls to the
7582 builtin function sqrt, but this fails. */
7584 set_optab_libfunc (sqrt_optab
, TFmode
, "_Q_sqrt");
7586 set_optab_libfunc (eq_optab
, TFmode
, "_Q_feq");
7587 set_optab_libfunc (ne_optab
, TFmode
, "_Q_fne");
7588 set_optab_libfunc (gt_optab
, TFmode
, "_Q_fgt");
7589 set_optab_libfunc (ge_optab
, TFmode
, "_Q_fge");
7590 set_optab_libfunc (lt_optab
, TFmode
, "_Q_flt");
7591 set_optab_libfunc (le_optab
, TFmode
, "_Q_fle");
7593 set_conv_libfunc (sext_optab
, TFmode
, SFmode
, "_Q_stoq");
7594 set_conv_libfunc (sext_optab
, TFmode
, DFmode
, "_Q_dtoq");
7595 set_conv_libfunc (trunc_optab
, SFmode
, TFmode
, "_Q_qtos");
7596 set_conv_libfunc (trunc_optab
, DFmode
, TFmode
, "_Q_qtod");
7598 set_conv_libfunc (sfix_optab
, SImode
, TFmode
, "_Q_qtoi");
7599 set_conv_libfunc (ufix_optab
, SImode
, TFmode
, "_Q_qtou");
7600 set_conv_libfunc (sfloat_optab
, TFmode
, SImode
, "_Q_itoq");
7602 if (DITF_CONVERSION_LIBFUNCS
)
7604 set_conv_libfunc (sfix_optab
, DImode
, TFmode
, "_Q_qtoll");
7605 set_conv_libfunc (ufix_optab
, DImode
, TFmode
, "_Q_qtoull");
7606 set_conv_libfunc (sfloat_optab
, TFmode
, DImode
, "_Q_lltoq");
7609 if (SUN_CONVERSION_LIBFUNCS
)
7611 set_conv_libfunc (sfix_optab
, DImode
, SFmode
, "__ftoll");
7612 set_conv_libfunc (ufix_optab
, DImode
, SFmode
, "__ftoull");
7613 set_conv_libfunc (sfix_optab
, DImode
, DFmode
, "__dtoll");
7614 set_conv_libfunc (ufix_optab
, DImode
, DFmode
, "__dtoull");
7619 /* In the SPARC 64bit ABI, SImode multiply and divide functions
7620 do not exist in the library. Make sure the compiler does not
7621 emit calls to them by accident. (It should always use the
7622 hardware instructions.) */
7623 set_optab_libfunc (smul_optab
, SImode
, 0);
7624 set_optab_libfunc (sdiv_optab
, SImode
, 0);
7625 set_optab_libfunc (udiv_optab
, SImode
, 0);
7626 set_optab_libfunc (smod_optab
, SImode
, 0);
7627 set_optab_libfunc (umod_optab
, SImode
, 0);
7629 if (SUN_INTEGER_MULTIPLY_64
)
7631 set_optab_libfunc (smul_optab
, DImode
, "__mul64");
7632 set_optab_libfunc (sdiv_optab
, DImode
, "__div64");
7633 set_optab_libfunc (udiv_optab
, DImode
, "__udiv64");
7634 set_optab_libfunc (smod_optab
, DImode
, "__rem64");
7635 set_optab_libfunc (umod_optab
, DImode
, "__urem64");
7638 if (SUN_CONVERSION_LIBFUNCS
)
7640 set_conv_libfunc (sfix_optab
, DImode
, SFmode
, "__ftol");
7641 set_conv_libfunc (ufix_optab
, DImode
, SFmode
, "__ftoul");
7642 set_conv_libfunc (sfix_optab
, DImode
, DFmode
, "__dtol");
7643 set_conv_libfunc (ufix_optab
, DImode
, DFmode
, "__dtoul");
7647 gofast_maybe_init_libfuncs ();
7650 #define def_builtin(NAME, CODE, TYPE) \
7651 lang_hooks.builtin_function((NAME), (TYPE), (CODE), BUILT_IN_MD, NULL, \
7654 /* Implement the TARGET_INIT_BUILTINS target hook.
7655 Create builtin functions for special SPARC instructions. */
7658 sparc_init_builtins (void)
7661 sparc_vis_init_builtins ();
7664 /* Create builtin functions for VIS 1.0 instructions. */
7667 sparc_vis_init_builtins (void)
7669 tree v4qi
= build_vector_type (unsigned_intQI_type_node
, 4);
7670 tree v8qi
= build_vector_type (unsigned_intQI_type_node
, 8);
7671 tree v4hi
= build_vector_type (intHI_type_node
, 4);
7672 tree v2hi
= build_vector_type (intHI_type_node
, 2);
7673 tree v2si
= build_vector_type (intSI_type_node
, 2);
7675 tree v4qi_ftype_v4hi
= build_function_type_list (v4qi
, v4hi
, 0);
7676 tree v8qi_ftype_v2si_v8qi
= build_function_type_list (v8qi
, v2si
, v8qi
, 0);
7677 tree v2hi_ftype_v2si
= build_function_type_list (v2hi
, v2si
, 0);
7678 tree v4hi_ftype_v4qi
= build_function_type_list (v4hi
, v4qi
, 0);
7679 tree v8qi_ftype_v4qi_v4qi
= build_function_type_list (v8qi
, v4qi
, v4qi
, 0);
7680 tree v4hi_ftype_v4qi_v4hi
= build_function_type_list (v4hi
, v4qi
, v4hi
, 0);
7681 tree v4hi_ftype_v4qi_v2hi
= build_function_type_list (v4hi
, v4qi
, v2hi
, 0);
7682 tree v2si_ftype_v4qi_v2hi
= build_function_type_list (v2si
, v4qi
, v2hi
, 0);
7683 tree v4hi_ftype_v8qi_v4hi
= build_function_type_list (v4hi
, v8qi
, v4hi
, 0);
7684 tree v4hi_ftype_v4hi_v4hi
= build_function_type_list (v4hi
, v4hi
, v4hi
, 0);
7685 tree v2si_ftype_v2si_v2si
= build_function_type_list (v2si
, v2si
, v2si
, 0);
7686 tree v8qi_ftype_v8qi_v8qi
= build_function_type_list (v8qi
, v8qi
, v8qi
, 0);
7687 tree di_ftype_v8qi_v8qi_di
= build_function_type_list (intDI_type_node
,
7689 intDI_type_node
, 0);
7690 tree di_ftype_di_di
= build_function_type_list (intDI_type_node
,
7692 intDI_type_node
, 0);
7693 tree ptr_ftype_ptr_si
= build_function_type_list (ptr_type_node
,
7695 intSI_type_node
, 0);
7696 tree ptr_ftype_ptr_di
= build_function_type_list (ptr_type_node
,
7698 intDI_type_node
, 0);
7700 /* Packing and expanding vectors. */
7701 def_builtin ("__builtin_vis_fpack16", CODE_FOR_fpack16_vis
, v4qi_ftype_v4hi
);
7702 def_builtin ("__builtin_vis_fpack32", CODE_FOR_fpack32_vis
,
7703 v8qi_ftype_v2si_v8qi
);
7704 def_builtin ("__builtin_vis_fpackfix", CODE_FOR_fpackfix_vis
,
7706 def_builtin ("__builtin_vis_fexpand", CODE_FOR_fexpand_vis
, v4hi_ftype_v4qi
);
7707 def_builtin ("__builtin_vis_fpmerge", CODE_FOR_fpmerge_vis
,
7708 v8qi_ftype_v4qi_v4qi
);
7710 /* Multiplications. */
7711 def_builtin ("__builtin_vis_fmul8x16", CODE_FOR_fmul8x16_vis
,
7712 v4hi_ftype_v4qi_v4hi
);
7713 def_builtin ("__builtin_vis_fmul8x16au", CODE_FOR_fmul8x16au_vis
,
7714 v4hi_ftype_v4qi_v2hi
);
7715 def_builtin ("__builtin_vis_fmul8x16al", CODE_FOR_fmul8x16al_vis
,
7716 v4hi_ftype_v4qi_v2hi
);
7717 def_builtin ("__builtin_vis_fmul8sux16", CODE_FOR_fmul8sux16_vis
,
7718 v4hi_ftype_v8qi_v4hi
);
7719 def_builtin ("__builtin_vis_fmul8ulx16", CODE_FOR_fmul8ulx16_vis
,
7720 v4hi_ftype_v8qi_v4hi
);
7721 def_builtin ("__builtin_vis_fmuld8sux16", CODE_FOR_fmuld8sux16_vis
,
7722 v2si_ftype_v4qi_v2hi
);
7723 def_builtin ("__builtin_vis_fmuld8ulx16", CODE_FOR_fmuld8ulx16_vis
,
7724 v2si_ftype_v4qi_v2hi
);
7726 /* Data aligning. */
7727 def_builtin ("__builtin_vis_faligndatav4hi", CODE_FOR_faligndatav4hi_vis
,
7728 v4hi_ftype_v4hi_v4hi
);
7729 def_builtin ("__builtin_vis_faligndatav8qi", CODE_FOR_faligndatav8qi_vis
,
7730 v8qi_ftype_v8qi_v8qi
);
7731 def_builtin ("__builtin_vis_faligndatav2si", CODE_FOR_faligndatav2si_vis
,
7732 v2si_ftype_v2si_v2si
);
7733 def_builtin ("__builtin_vis_faligndatadi", CODE_FOR_faligndatadi_vis
,
7736 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrdi_vis
,
7739 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrsi_vis
,
7742 /* Pixel distance. */
7743 def_builtin ("__builtin_vis_pdist", CODE_FOR_pdist_vis
,
7744 di_ftype_v8qi_v8qi_di
);
7747 /* Handle TARGET_EXPAND_BUILTIN target hook.
7748 Expand builtin functions for sparc instrinsics. */
7751 sparc_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
7752 enum machine_mode tmode
, int ignore ATTRIBUTE_UNUSED
)
7755 tree fndecl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
7756 unsigned int icode
= DECL_FUNCTION_CODE (fndecl
);
7758 enum machine_mode mode
[4];
7761 mode
[arg_count
] = tmode
;
7764 || GET_MODE (target
) != tmode
7765 || ! (*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
7766 op
[arg_count
] = gen_reg_rtx (tmode
);
7768 op
[arg_count
] = target
;
7770 for (arglist
= TREE_OPERAND (exp
, 1); arglist
;
7771 arglist
= TREE_CHAIN (arglist
))
7773 tree arg
= TREE_VALUE (arglist
);
7776 mode
[arg_count
] = insn_data
[icode
].operand
[arg_count
].mode
;
7777 op
[arg_count
] = expand_expr (arg
, NULL_RTX
, VOIDmode
, 0);
7779 if (! (*insn_data
[icode
].operand
[arg_count
].predicate
) (op
[arg_count
],
7781 op
[arg_count
] = copy_to_mode_reg (mode
[arg_count
], op
[arg_count
]);
7787 pat
= GEN_FCN (icode
) (op
[0], op
[1]);
7790 pat
= GEN_FCN (icode
) (op
[0], op
[1], op
[2]);
7793 pat
= GEN_FCN (icode
) (op
[0], op
[1], op
[2], op
[3]);
7808 sparc_extra_constraint_check (rtx op
, int c
, int strict
)
7813 && (c
== 'T' || c
== 'U'))
7819 return fp_sethi_p (op
);
7822 return fp_mov_p (op
);
7825 return fp_high_losum_p (op
);
7829 || (GET_CODE (op
) == REG
7830 && (REGNO (op
) < FIRST_PSEUDO_REGISTER
7831 || reg_renumber
[REGNO (op
)] >= 0)))
7832 return register_ok_for_ldd (op
);
7841 return const_zero_operand (op
, GET_MODE (op
));
7847 /* Our memory extra constraints have to emulate the
7848 behavior of 'm' and 'o' in order for reload to work
7850 if (GET_CODE (op
) == MEM
)
7853 if ((TARGET_ARCH64
|| mem_min_alignment (op
, 8))
7855 || strict_memory_address_p (Pmode
, XEXP (op
, 0))))
7860 reload_ok_mem
= (reload_in_progress
7861 && GET_CODE (op
) == REG
7862 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
7863 && reg_renumber
[REGNO (op
)] < 0);
7866 return reload_ok_mem
;
7869 /* ??? This duplicates information provided to the compiler by the
7870 ??? scheduler description. Some day, teach genautomata to output
7871 ??? the latencies and then CSE will just use that. */
7874 sparc_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
7876 enum machine_mode mode
= GET_MODE (x
);
7877 bool float_mode_p
= FLOAT_MODE_P (mode
);
7882 if (INTVAL (x
) < 0x1000 && INTVAL (x
) >= -0x1000)
7900 if (GET_MODE (x
) == DImode
7901 && ((XINT (x
, 3) == 0
7902 && (unsigned HOST_WIDE_INT
) XINT (x
, 2) < 0x1000)
7903 || (XINT (x
, 3) == -1
7905 && XINT (x
, 2) >= -0x1000)))
7912 /* If outer-code was a sign or zero extension, a cost
7913 of COSTS_N_INSNS (1) was already added in. This is
7914 why we are subtracting it back out. */
7915 if (outer_code
== ZERO_EXTEND
)
7917 *total
= sparc_costs
->int_zload
- COSTS_N_INSNS (1);
7919 else if (outer_code
== SIGN_EXTEND
)
7921 *total
= sparc_costs
->int_sload
- COSTS_N_INSNS (1);
7923 else if (float_mode_p
)
7925 *total
= sparc_costs
->float_load
;
7929 *total
= sparc_costs
->int_load
;
7937 *total
= sparc_costs
->float_plusminus
;
7939 *total
= COSTS_N_INSNS (1);
7944 *total
= sparc_costs
->float_mul
;
7945 else if (! TARGET_HARD_MUL
)
7946 *total
= COSTS_N_INSNS (25);
7952 if (sparc_costs
->int_mul_bit_factor
)
7956 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
7958 unsigned HOST_WIDE_INT value
= INTVAL (XEXP (x
, 1));
7959 for (nbits
= 0; value
!= 0; value
&= value
- 1)
7962 else if (GET_CODE (XEXP (x
, 1)) == CONST_DOUBLE
7963 && GET_MODE (XEXP (x
, 1)) == DImode
)
7965 rtx x1
= XEXP (x
, 1);
7966 unsigned HOST_WIDE_INT value1
= XINT (x1
, 2);
7967 unsigned HOST_WIDE_INT value2
= XINT (x1
, 3);
7969 for (nbits
= 0; value1
!= 0; value1
&= value1
- 1)
7971 for (; value2
!= 0; value2
&= value2
- 1)
7979 bit_cost
= (nbits
- 3) / sparc_costs
->int_mul_bit_factor
;
7980 bit_cost
= COSTS_N_INSNS (bit_cost
);
7984 *total
= sparc_costs
->int_mulX
+ bit_cost
;
7986 *total
= sparc_costs
->int_mul
+ bit_cost
;
7993 *total
= COSTS_N_INSNS (1) + sparc_costs
->shift_penalty
;
8003 *total
= sparc_costs
->float_div_df
;
8005 *total
= sparc_costs
->float_div_sf
;
8010 *total
= sparc_costs
->int_divX
;
8012 *total
= sparc_costs
->int_div
;
8019 *total
= COSTS_N_INSNS (1);
8026 case UNSIGNED_FLOAT
:
8030 case FLOAT_TRUNCATE
:
8031 *total
= sparc_costs
->float_move
;
8036 *total
= sparc_costs
->float_sqrt_df
;
8038 *total
= sparc_costs
->float_sqrt_sf
;
8043 *total
= sparc_costs
->float_cmp
;
8045 *total
= COSTS_N_INSNS (1);
8050 *total
= sparc_costs
->float_cmove
;
8052 *total
= sparc_costs
->int_cmove
;
8056 /* Handle the NAND vector patterns. */
8057 if (sparc_vector_mode_supported_p (GET_MODE (x
))
8058 && GET_CODE (XEXP (x
, 0)) == NOT
8059 && GET_CODE (XEXP (x
, 1)) == NOT
)
8061 *total
= COSTS_N_INSNS (1);
8072 /* Emit the sequence of insns SEQ while preserving the register REG. */
8075 emit_and_preserve (rtx seq
, rtx reg
)
8077 rtx slot
= gen_rtx_MEM (word_mode
,
8078 plus_constant (stack_pointer_rtx
, SPARC_STACK_BIAS
));
8080 emit_insn (gen_stack_pointer_dec (GEN_INT (STACK_BOUNDARY
/BITS_PER_UNIT
)));
8081 emit_insn (gen_rtx_SET (VOIDmode
, slot
, reg
));
8083 emit_insn (gen_rtx_SET (VOIDmode
, reg
, slot
));
8084 emit_insn (gen_stack_pointer_inc (GEN_INT (STACK_BOUNDARY
/BITS_PER_UNIT
)));
8087 /* Output the assembler code for a thunk function. THUNK_DECL is the
8088 declaration for the thunk function itself, FUNCTION is the decl for
8089 the target function. DELTA is an immediate constant offset to be
8090 added to THIS. If VCALL_OFFSET is nonzero, the word at address
8091 (*THIS + VCALL_OFFSET) should be additionally added to THIS. */
8094 sparc_output_mi_thunk (FILE *file
, tree thunk_fndecl ATTRIBUTE_UNUSED
,
8095 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
8098 rtx
this, insn
, funexp
;
8099 unsigned int int_arg_first
;
8101 reload_completed
= 1;
8102 epilogue_completed
= 1;
8104 reset_block_changes ();
8106 emit_note (NOTE_INSN_PROLOGUE_END
);
8108 if (flag_delayed_branch
)
8110 /* We will emit a regular sibcall below, so we need to instruct
8111 output_sibcall that we are in a leaf function. */
8112 sparc_leaf_function_p
= current_function_uses_only_leaf_regs
= 1;
8114 /* This will cause final.c to invoke leaf_renumber_regs so we
8115 must behave as if we were in a not-yet-leafified function. */
8116 int_arg_first
= SPARC_INCOMING_INT_ARG_FIRST
;
8120 /* We will emit the sibcall manually below, so we will need to
8121 manually spill non-leaf registers. */
8122 sparc_leaf_function_p
= current_function_uses_only_leaf_regs
= 0;
8124 /* We really are in a leaf function. */
8125 int_arg_first
= SPARC_OUTGOING_INT_ARG_FIRST
;
8128 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
8129 returns a structure, the structure return pointer is there instead. */
8130 if (TARGET_ARCH64
&& aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
8131 this = gen_rtx_REG (Pmode
, int_arg_first
+ 1);
8133 this = gen_rtx_REG (Pmode
, int_arg_first
);
8135 /* Add DELTA. When possible use a plain add, otherwise load it into
8136 a register first. */
8139 rtx delta_rtx
= GEN_INT (delta
);
8141 if (! SPARC_SIMM13_P (delta
))
8143 rtx scratch
= gen_rtx_REG (Pmode
, 1);
8144 emit_move_insn (scratch
, delta_rtx
);
8145 delta_rtx
= scratch
;
8148 /* THIS += DELTA. */
8149 emit_insn (gen_add2_insn (this, delta_rtx
));
8152 /* Add the word at address (*THIS + VCALL_OFFSET). */
8155 rtx vcall_offset_rtx
= GEN_INT (vcall_offset
);
8156 rtx scratch
= gen_rtx_REG (Pmode
, 1);
8158 gcc_assert (vcall_offset
< 0);
8160 /* SCRATCH = *THIS. */
8161 emit_move_insn (scratch
, gen_rtx_MEM (Pmode
, this));
8163 /* Prepare for adding VCALL_OFFSET. The difficulty is that we
8164 may not have any available scratch register at this point. */
8165 if (SPARC_SIMM13_P (vcall_offset
))
8167 /* This is the case if ARCH64 (unless -ffixed-g5 is passed). */
8168 else if (! fixed_regs
[5]
8169 /* The below sequence is made up of at least 2 insns,
8170 while the default method may need only one. */
8171 && vcall_offset
< -8192)
8173 rtx scratch2
= gen_rtx_REG (Pmode
, 5);
8174 emit_move_insn (scratch2
, vcall_offset_rtx
);
8175 vcall_offset_rtx
= scratch2
;
8179 rtx increment
= GEN_INT (-4096);
8181 /* VCALL_OFFSET is a negative number whose typical range can be
8182 estimated as -32768..0 in 32-bit mode. In almost all cases
8183 it is therefore cheaper to emit multiple add insns than
8184 spilling and loading the constant into a register (at least
8186 while (! SPARC_SIMM13_P (vcall_offset
))
8188 emit_insn (gen_add2_insn (scratch
, increment
));
8189 vcall_offset
+= 4096;
8191 vcall_offset_rtx
= GEN_INT (vcall_offset
); /* cannot be 0 */
8194 /* SCRATCH = *(*THIS + VCALL_OFFSET). */
8195 emit_move_insn (scratch
, gen_rtx_MEM (Pmode
,
8196 gen_rtx_PLUS (Pmode
,
8198 vcall_offset_rtx
)));
8200 /* THIS += *(*THIS + VCALL_OFFSET). */
8201 emit_insn (gen_add2_insn (this, scratch
));
8204 /* Generate a tail call to the target function. */
8205 if (! TREE_USED (function
))
8207 assemble_external (function
);
8208 TREE_USED (function
) = 1;
8210 funexp
= XEXP (DECL_RTL (function
), 0);
8212 if (flag_delayed_branch
)
8214 funexp
= gen_rtx_MEM (FUNCTION_MODE
, funexp
);
8215 insn
= emit_call_insn (gen_sibcall (funexp
));
8216 SIBLING_CALL_P (insn
) = 1;
8220 /* The hoops we have to jump through in order to generate a sibcall
8221 without using delay slots... */
8222 rtx spill_reg
, seq
, scratch
= gen_rtx_REG (Pmode
, 1);
8226 spill_reg
= gen_rtx_REG (word_mode
, 15); /* %o7 */
8228 /* Delay emitting the PIC helper function because it needs to
8229 change the section and we are emitting assembly code. */
8230 load_pic_register (true); /* clobbers %o7 */
8231 scratch
= legitimize_pic_address (funexp
, Pmode
, scratch
);
8234 emit_and_preserve (seq
, spill_reg
);
8236 else if (TARGET_ARCH32
)
8238 emit_insn (gen_rtx_SET (VOIDmode
,
8240 gen_rtx_HIGH (SImode
, funexp
)));
8241 emit_insn (gen_rtx_SET (VOIDmode
,
8243 gen_rtx_LO_SUM (SImode
, scratch
, funexp
)));
8245 else /* TARGET_ARCH64 */
8247 switch (sparc_cmodel
)
8251 /* The destination can serve as a temporary. */
8252 sparc_emit_set_symbolic_const64 (scratch
, funexp
, scratch
);
8257 /* The destination cannot serve as a temporary. */
8258 spill_reg
= gen_rtx_REG (DImode
, 15); /* %o7 */
8260 sparc_emit_set_symbolic_const64 (scratch
, funexp
, spill_reg
);
8263 emit_and_preserve (seq
, spill_reg
);
8271 emit_jump_insn (gen_indirect_jump (scratch
));
8276 /* Run just enough of rest_of_compilation to get the insns emitted.
8277 There's not really enough bulk here to make other passes such as
8278 instruction scheduling worth while. Note that use_thunk calls
8279 assemble_start_function and assemble_end_function. */
8280 insn
= get_insns ();
8281 insn_locators_initialize ();
8282 shorten_branches (insn
);
8283 final_start_function (insn
, file
, 1);
8284 final (insn
, file
, 1);
8285 final_end_function ();
8287 reload_completed
= 0;
8288 epilogue_completed
= 0;
8292 /* Return true if sparc_output_mi_thunk would be able to output the
8293 assembler code for the thunk function specified by the arguments
8294 it is passed, and false otherwise. */
8296 sparc_can_output_mi_thunk (tree thunk_fndecl ATTRIBUTE_UNUSED
,
8297 HOST_WIDE_INT delta ATTRIBUTE_UNUSED
,
8298 HOST_WIDE_INT vcall_offset
,
8299 tree function ATTRIBUTE_UNUSED
)
8301 /* Bound the loop used in the default method above. */
8302 return (vcall_offset
>= -32768 || ! fixed_regs
[5]);
8305 /* How to allocate a 'struct machine_function'. */
8307 static struct machine_function
*
8308 sparc_init_machine_status (void)
8310 return ggc_alloc_cleared (sizeof (struct machine_function
));
8313 /* Locate some local-dynamic symbol still in use by this function
8314 so that we can print its name in local-dynamic base patterns. */
8317 get_some_local_dynamic_name (void)
8321 if (cfun
->machine
->some_ld_name
)
8322 return cfun
->machine
->some_ld_name
;
8324 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
8326 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
8327 return cfun
->machine
->some_ld_name
;
8333 get_some_local_dynamic_name_1 (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
8338 && GET_CODE (x
) == SYMBOL_REF
8339 && SYMBOL_REF_TLS_MODEL (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
8341 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
8348 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
8349 This is called from dwarf2out.c to emit call frame instructions
8350 for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
8352 sparc_dwarf_handle_frame_unspec (const char *label
,
8353 rtx pattern ATTRIBUTE_UNUSED
,
8354 int index ATTRIBUTE_UNUSED
)
8356 gcc_assert (index
== UNSPECV_SAVEW
);
8357 dwarf2out_window_save (label
);
8360 /* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
8361 We need to emit DTP-relative relocations. */
8364 sparc_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
8369 fputs ("\t.word\t%r_tls_dtpoff32(", file
);
8372 fputs ("\t.xword\t%r_tls_dtpoff64(", file
);
8377 output_addr_const (file
, x
);
8382 void sparc_file_end (void)
8384 /* If we haven't emitted the special PIC helper function, do so now. */
8385 if (pic_helper_symbol_name
[0] && !pic_helper_emitted_p
)
8388 if (NEED_INDICATE_EXEC_STACK
)
8389 file_end_indicate_exec_stack ();
8392 #include "gt-sparc.h"