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, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 64-bit SPARC-V9 support by Michael Tiemann, Jim Wilson, and Doug Evans,
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3, or (at your option)
16 GCC is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
32 #include "hard-reg-set.h"
33 #include "insn-config.h"
34 #include "insn-codes.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
44 #include "diagnostic-core.h"
50 #include "target-def.h"
51 #include "cfglayout.h"
53 #include "langhooks.h"
57 #include "dwarf2out.h"
61 struct processor_costs cypress_costs = {
62 COSTS_N_INSNS (2), /* int load */
63 COSTS_N_INSNS (2), /* int signed load */
64 COSTS_N_INSNS (2), /* int zeroed load */
65 COSTS_N_INSNS (2), /* float load */
66 COSTS_N_INSNS (5), /* fmov, fneg, fabs */
67 COSTS_N_INSNS (5), /* fadd, fsub */
68 COSTS_N_INSNS (1), /* fcmp */
69 COSTS_N_INSNS (1), /* fmov, fmovr */
70 COSTS_N_INSNS (7), /* fmul */
71 COSTS_N_INSNS (37), /* fdivs */
72 COSTS_N_INSNS (37), /* fdivd */
73 COSTS_N_INSNS (63), /* fsqrts */
74 COSTS_N_INSNS (63), /* fsqrtd */
75 COSTS_N_INSNS (1), /* imul */
76 COSTS_N_INSNS (1), /* imulX */
77 0, /* imul bit factor */
78 COSTS_N_INSNS (1), /* idiv */
79 COSTS_N_INSNS (1), /* idivX */
80 COSTS_N_INSNS (1), /* movcc/movr */
81 0, /* shift penalty */
85 struct processor_costs supersparc_costs = {
86 COSTS_N_INSNS (1), /* int load */
87 COSTS_N_INSNS (1), /* int signed load */
88 COSTS_N_INSNS (1), /* int zeroed load */
89 COSTS_N_INSNS (0), /* float load */
90 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
91 COSTS_N_INSNS (3), /* fadd, fsub */
92 COSTS_N_INSNS (3), /* fcmp */
93 COSTS_N_INSNS (1), /* fmov, fmovr */
94 COSTS_N_INSNS (3), /* fmul */
95 COSTS_N_INSNS (6), /* fdivs */
96 COSTS_N_INSNS (9), /* fdivd */
97 COSTS_N_INSNS (12), /* fsqrts */
98 COSTS_N_INSNS (12), /* fsqrtd */
99 COSTS_N_INSNS (4), /* imul */
100 COSTS_N_INSNS (4), /* imulX */
101 0, /* imul bit factor */
102 COSTS_N_INSNS (4), /* idiv */
103 COSTS_N_INSNS (4), /* idivX */
104 COSTS_N_INSNS (1), /* movcc/movr */
105 1, /* shift penalty */
109 struct processor_costs hypersparc_costs = {
110 COSTS_N_INSNS (1), /* int load */
111 COSTS_N_INSNS (1), /* int signed load */
112 COSTS_N_INSNS (1), /* int zeroed load */
113 COSTS_N_INSNS (1), /* float load */
114 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
115 COSTS_N_INSNS (1), /* fadd, fsub */
116 COSTS_N_INSNS (1), /* fcmp */
117 COSTS_N_INSNS (1), /* fmov, fmovr */
118 COSTS_N_INSNS (1), /* fmul */
119 COSTS_N_INSNS (8), /* fdivs */
120 COSTS_N_INSNS (12), /* fdivd */
121 COSTS_N_INSNS (17), /* fsqrts */
122 COSTS_N_INSNS (17), /* fsqrtd */
123 COSTS_N_INSNS (17), /* imul */
124 COSTS_N_INSNS (17), /* imulX */
125 0, /* imul bit factor */
126 COSTS_N_INSNS (17), /* idiv */
127 COSTS_N_INSNS (17), /* idivX */
128 COSTS_N_INSNS (1), /* movcc/movr */
129 0, /* shift penalty */
133 struct processor_costs sparclet_costs = {
134 COSTS_N_INSNS (3), /* int load */
135 COSTS_N_INSNS (3), /* int signed load */
136 COSTS_N_INSNS (1), /* int zeroed load */
137 COSTS_N_INSNS (1), /* float load */
138 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
139 COSTS_N_INSNS (1), /* fadd, fsub */
140 COSTS_N_INSNS (1), /* fcmp */
141 COSTS_N_INSNS (1), /* fmov, fmovr */
142 COSTS_N_INSNS (1), /* fmul */
143 COSTS_N_INSNS (1), /* fdivs */
144 COSTS_N_INSNS (1), /* fdivd */
145 COSTS_N_INSNS (1), /* fsqrts */
146 COSTS_N_INSNS (1), /* fsqrtd */
147 COSTS_N_INSNS (5), /* imul */
148 COSTS_N_INSNS (5), /* imulX */
149 0, /* imul bit factor */
150 COSTS_N_INSNS (5), /* idiv */
151 COSTS_N_INSNS (5), /* idivX */
152 COSTS_N_INSNS (1), /* movcc/movr */
153 0, /* shift penalty */
157 struct processor_costs ultrasparc_costs = {
158 COSTS_N_INSNS (2), /* int load */
159 COSTS_N_INSNS (3), /* int signed load */
160 COSTS_N_INSNS (2), /* int zeroed load */
161 COSTS_N_INSNS (2), /* float load */
162 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
163 COSTS_N_INSNS (4), /* fadd, fsub */
164 COSTS_N_INSNS (1), /* fcmp */
165 COSTS_N_INSNS (2), /* fmov, fmovr */
166 COSTS_N_INSNS (4), /* fmul */
167 COSTS_N_INSNS (13), /* fdivs */
168 COSTS_N_INSNS (23), /* fdivd */
169 COSTS_N_INSNS (13), /* fsqrts */
170 COSTS_N_INSNS (23), /* fsqrtd */
171 COSTS_N_INSNS (4), /* imul */
172 COSTS_N_INSNS (4), /* imulX */
173 2, /* imul bit factor */
174 COSTS_N_INSNS (37), /* idiv */
175 COSTS_N_INSNS (68), /* idivX */
176 COSTS_N_INSNS (2), /* movcc/movr */
177 2, /* shift penalty */
181 struct processor_costs ultrasparc3_costs = {
182 COSTS_N_INSNS (2), /* int load */
183 COSTS_N_INSNS (3), /* int signed load */
184 COSTS_N_INSNS (3), /* int zeroed load */
185 COSTS_N_INSNS (2), /* float load */
186 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
187 COSTS_N_INSNS (4), /* fadd, fsub */
188 COSTS_N_INSNS (5), /* fcmp */
189 COSTS_N_INSNS (3), /* fmov, fmovr */
190 COSTS_N_INSNS (4), /* fmul */
191 COSTS_N_INSNS (17), /* fdivs */
192 COSTS_N_INSNS (20), /* fdivd */
193 COSTS_N_INSNS (20), /* fsqrts */
194 COSTS_N_INSNS (29), /* fsqrtd */
195 COSTS_N_INSNS (6), /* imul */
196 COSTS_N_INSNS (6), /* imulX */
197 0, /* imul bit factor */
198 COSTS_N_INSNS (40), /* idiv */
199 COSTS_N_INSNS (71), /* idivX */
200 COSTS_N_INSNS (2), /* movcc/movr */
201 0, /* shift penalty */
205 struct processor_costs niagara_costs = {
206 COSTS_N_INSNS (3), /* int load */
207 COSTS_N_INSNS (3), /* int signed load */
208 COSTS_N_INSNS (3), /* int zeroed load */
209 COSTS_N_INSNS (9), /* float load */
210 COSTS_N_INSNS (8), /* fmov, fneg, fabs */
211 COSTS_N_INSNS (8), /* fadd, fsub */
212 COSTS_N_INSNS (26), /* fcmp */
213 COSTS_N_INSNS (8), /* fmov, fmovr */
214 COSTS_N_INSNS (29), /* fmul */
215 COSTS_N_INSNS (54), /* fdivs */
216 COSTS_N_INSNS (83), /* fdivd */
217 COSTS_N_INSNS (100), /* fsqrts - not implemented in hardware */
218 COSTS_N_INSNS (100), /* fsqrtd - not implemented in hardware */
219 COSTS_N_INSNS (11), /* imul */
220 COSTS_N_INSNS (11), /* imulX */
221 0, /* imul bit factor */
222 COSTS_N_INSNS (72), /* idiv */
223 COSTS_N_INSNS (72), /* idivX */
224 COSTS_N_INSNS (1), /* movcc/movr */
225 0, /* shift penalty */
229 struct processor_costs niagara2_costs = {
230 COSTS_N_INSNS (3), /* int load */
231 COSTS_N_INSNS (3), /* int signed load */
232 COSTS_N_INSNS (3), /* int zeroed load */
233 COSTS_N_INSNS (3), /* float load */
234 COSTS_N_INSNS (6), /* fmov, fneg, fabs */
235 COSTS_N_INSNS (6), /* fadd, fsub */
236 COSTS_N_INSNS (6), /* fcmp */
237 COSTS_N_INSNS (6), /* fmov, fmovr */
238 COSTS_N_INSNS (6), /* fmul */
239 COSTS_N_INSNS (19), /* fdivs */
240 COSTS_N_INSNS (33), /* fdivd */
241 COSTS_N_INSNS (19), /* fsqrts */
242 COSTS_N_INSNS (33), /* fsqrtd */
243 COSTS_N_INSNS (5), /* imul */
244 COSTS_N_INSNS (5), /* imulX */
245 0, /* imul bit factor */
246 COSTS_N_INSNS (31), /* idiv, average of 12 - 41 cycle range */
247 COSTS_N_INSNS (31), /* idivX, average of 12 - 41 cycle range */
248 COSTS_N_INSNS (1), /* movcc/movr */
249 0, /* shift penalty */
252 const struct processor_costs *sparc_costs = &cypress_costs;
254 #ifdef HAVE_AS_RELAX_OPTION
255 /* If 'as' and 'ld' are relaxing tail call insns into branch always, use
256 "or %o7,%g0,X; call Y; or X,%g0,%o7" always, so that it can be optimized.
257 With sethi/jmp, neither 'as' nor 'ld' has an easy way how to find out if
258 somebody does not branch between the sethi and jmp. */
259 #define LEAF_SIBCALL_SLOT_RESERVED_P 1
261 #define LEAF_SIBCALL_SLOT_RESERVED_P \
262 ((TARGET_ARCH64 && !TARGET_CM_MEDLOW) || flag_pic)
265 /* Global variables for machine-dependent things. */
267 /* Size of frame. Need to know this to emit return insns from leaf procedures.
268 ACTUAL_FSIZE is set by sparc_compute_frame_size() which is called during the
269 reload pass. This is important as the value is later used for scheduling
270 (to see what can go in a delay slot).
271 APPARENT_FSIZE is the size of the stack less the register save area and less
272 the outgoing argument area. It is used when saving call preserved regs. */
273 static HOST_WIDE_INT apparent_fsize;
274 static HOST_WIDE_INT actual_fsize;
276 /* Number of live general or floating point registers needed to be
277 saved (as 4-byte quantities). */
278 static int num_gfregs;
280 /* The alias set for prologue/epilogue register save/restore. */
281 static GTY(()) alias_set_type sparc_sr_alias_set;
283 /* The alias set for the structure return value. */
284 static GTY(()) alias_set_type struct_value_alias_set;
286 /* Vector to say how input registers are mapped to output registers.
287 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
288 eliminate it. You must use -fomit-frame-pointer to get that. */
289 char leaf_reg_remap[] =
290 { 0, 1, 2, 3, 4, 5, 6, 7,
291 -1, -1, -1, -1, -1, -1, 14, -1,
292 -1, -1, -1, -1, -1, -1, -1, -1,
293 8, 9, 10, 11, 12, 13, -1, 15,
295 32, 33, 34, 35, 36, 37, 38, 39,
296 40, 41, 42, 43, 44, 45, 46, 47,
297 48, 49, 50, 51, 52, 53, 54, 55,
298 56, 57, 58, 59, 60, 61, 62, 63,
299 64, 65, 66, 67, 68, 69, 70, 71,
300 72, 73, 74, 75, 76, 77, 78, 79,
301 80, 81, 82, 83, 84, 85, 86, 87,
302 88, 89, 90, 91, 92, 93, 94, 95,
303 96, 97, 98, 99, 100};
305 /* Vector, indexed by hard register number, which contains 1
306 for a register that is allowable in a candidate for leaf
307 function treatment. */
308 char sparc_leaf_regs[] =
309 { 1, 1, 1, 1, 1, 1, 1, 1,
310 0, 0, 0, 0, 0, 0, 1, 0,
311 0, 0, 0, 0, 0, 0, 0, 0,
312 1, 1, 1, 1, 1, 1, 0, 1,
313 1, 1, 1, 1, 1, 1, 1, 1,
314 1, 1, 1, 1, 1, 1, 1, 1,
315 1, 1, 1, 1, 1, 1, 1, 1,
316 1, 1, 1, 1, 1, 1, 1, 1,
317 1, 1, 1, 1, 1, 1, 1, 1,
318 1, 1, 1, 1, 1, 1, 1, 1,
319 1, 1, 1, 1, 1, 1, 1, 1,
320 1, 1, 1, 1, 1, 1, 1, 1,
323 struct GTY(()) machine_function
325 /* Some local-dynamic TLS symbol name. */
326 const char *some_ld_name;
328 /* True if the current function is leaf and uses only leaf regs,
329 so that the SPARC leaf function optimization can be applied.
330 Private version of current_function_uses_only_leaf_regs, see
331 sparc_expand_prologue for the rationale. */
334 /* True if the data calculated by sparc_expand_prologue are valid. */
335 bool prologue_data_valid_p;
338 #define sparc_leaf_function_p cfun->machine->leaf_function_p
339 #define sparc_prologue_data_valid_p cfun->machine->prologue_data_valid_p
341 /* Register we pretend to think the frame pointer is allocated to.
342 Normally, this is %fp, but if we are in a leaf procedure, this
343 is %sp+"something". We record "something" separately as it may
344 be too big for reg+constant addressing. */
345 static rtx frame_base_reg;
346 static HOST_WIDE_INT frame_base_offset;
348 /* 1 if the next opcode is to be specially indented. */
349 int sparc_indent_opcode = 0;
351 static bool sparc_handle_option (size_t, const char *, int);
352 static void sparc_init_modes (void);
353 static void scan_record_type (tree, int *, int *, int *);
354 static int function_arg_slotno (const CUMULATIVE_ARGS *, enum machine_mode,
355 tree, int, int, int *, int *);
357 static int supersparc_adjust_cost (rtx, rtx, rtx, int);
358 static int hypersparc_adjust_cost (rtx, rtx, rtx, int);
360 static void sparc_emit_set_const32 (rtx, rtx);
361 static void sparc_emit_set_const64 (rtx, rtx);
362 static void sparc_output_addr_vec (rtx);
363 static void sparc_output_addr_diff_vec (rtx);
364 static void sparc_output_deferred_case_vectors (void);
365 static bool sparc_legitimate_address_p (enum machine_mode, rtx, bool);
366 static rtx sparc_builtin_saveregs (void);
367 static int epilogue_renumber (rtx *, int);
368 static bool sparc_assemble_integer (rtx, unsigned int, int);
369 static int set_extends (rtx);
370 static void load_pic_register (void);
371 static int save_or_restore_regs (int, int, rtx, int, int);
372 static void emit_save_or_restore_regs (int);
373 static void sparc_asm_function_prologue (FILE *, HOST_WIDE_INT);
374 static void sparc_asm_function_epilogue (FILE *, HOST_WIDE_INT);
375 static void sparc_solaris_elf_asm_named_section (const char *, unsigned int,
376 tree) ATTRIBUTE_UNUSED;
377 static int sparc_adjust_cost (rtx, rtx, rtx, int);
378 static int sparc_issue_rate (void);
379 static void sparc_sched_init (FILE *, int, int);
380 static int sparc_use_sched_lookahead (void);
382 static void emit_soft_tfmode_libcall (const char *, int, rtx *);
383 static void emit_soft_tfmode_binop (enum rtx_code, rtx *);
384 static void emit_soft_tfmode_unop (enum rtx_code, rtx *);
385 static void emit_soft_tfmode_cvt (enum rtx_code, rtx *);
386 static void emit_hard_tfmode_operation (enum rtx_code, rtx *);
388 static bool sparc_function_ok_for_sibcall (tree, tree);
389 static void sparc_init_libfuncs (void);
390 static void sparc_init_builtins (void);
391 static void sparc_vis_init_builtins (void);
392 static rtx sparc_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
393 static tree sparc_fold_builtin (tree, int, tree *, bool);
394 static int sparc_vis_mul8x16 (int, int);
395 static tree sparc_handle_vis_mul8x16 (int, tree, tree, tree);
396 static void sparc_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
397 HOST_WIDE_INT, tree);
398 static bool sparc_can_output_mi_thunk (const_tree, HOST_WIDE_INT,
399 HOST_WIDE_INT, const_tree);
400 static struct machine_function * sparc_init_machine_status (void);
401 static bool sparc_cannot_force_const_mem (rtx);
402 static rtx sparc_tls_get_addr (void);
403 static rtx sparc_tls_got (void);
404 static const char *get_some_local_dynamic_name (void);
405 static int get_some_local_dynamic_name_1 (rtx *, void *);
406 static bool sparc_rtx_costs (rtx, int, int, int *, bool);
407 static bool sparc_promote_prototypes (const_tree);
408 static rtx sparc_function_value (const_tree, const_tree, bool);
409 static rtx sparc_libcall_value (enum machine_mode, const_rtx);
410 static bool sparc_function_value_regno_p (const unsigned int);
411 static rtx sparc_struct_value_rtx (tree, int);
412 static enum machine_mode sparc_promote_function_mode (const_tree, enum machine_mode,
413 int *, const_tree, int);
414 static bool sparc_return_in_memory (const_tree, const_tree);
415 static bool sparc_strict_argument_naming (CUMULATIVE_ARGS *);
416 static void sparc_va_start (tree, rtx);
417 static tree sparc_gimplify_va_arg (tree, tree, gimple_seq *, gimple_seq *);
418 static bool sparc_vector_mode_supported_p (enum machine_mode);
419 static bool sparc_tls_referenced_p (rtx);
420 static rtx sparc_legitimize_tls_address (rtx);
421 static rtx sparc_legitimize_pic_address (rtx, rtx);
422 static rtx sparc_legitimize_address (rtx, rtx, enum machine_mode);
423 static bool sparc_mode_dependent_address_p (const_rtx);
424 static bool sparc_pass_by_reference (CUMULATIVE_ARGS *,
425 enum machine_mode, const_tree, bool);
426 static int sparc_arg_partial_bytes (CUMULATIVE_ARGS *,
427 enum machine_mode, tree, bool);
428 static void sparc_dwarf_handle_frame_unspec (const char *, rtx, int);
429 static void sparc_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
430 static void sparc_file_end (void);
431 static bool sparc_frame_pointer_required (void);
432 static bool sparc_can_eliminate (const int, const int);
433 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
434 static const char *sparc_mangle_type (const_tree);
436 static void sparc_trampoline_init (rtx, tree, rtx);
437 static bool sparc_units_per_simd_word (enum machine_mode);
439 #ifdef SUBTARGET_ATTRIBUTE_TABLE
440 /* Table of valid machine attributes. */
441 static const struct attribute_spec sparc_attribute_table[] =
443 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
444 SUBTARGET_ATTRIBUTE_TABLE,
445 { NULL, 0, 0, false, false, false, NULL }
449 /* Option handling. */
452 enum cmodel sparc_cmodel;
454 char sparc_hard_reg_printed[8];
456 struct sparc_cpu_select sparc_select[] =
458 /* switch name, tune arch */
459 { (char *)0, "default", 1, 1 },
460 { (char *)0, "-mcpu=", 1, 1 },
461 { (char *)0, "-mtune=", 1, 0 },
465 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
466 enum processor_type sparc_cpu;
468 /* Whether
\fan FPU option was specified. */
469 static bool fpu_option_set = false;
471 /* Initialize the GCC target structure. */
473 /* The default is to use .half rather than .short for aligned HI objects. */
474 #undef TARGET_ASM_ALIGNED_HI_OP
475 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
477 #undef TARGET_ASM_UNALIGNED_HI_OP
478 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
479 #undef TARGET_ASM_UNALIGNED_SI_OP
480 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
481 #undef TARGET_ASM_UNALIGNED_DI_OP
482 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
484 /* The target hook has to handle DI-mode values. */
485 #undef TARGET_ASM_INTEGER
486 #define TARGET_ASM_INTEGER sparc_assemble_integer
488 #undef TARGET_ASM_FUNCTION_PROLOGUE
489 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
490 #undef TARGET_ASM_FUNCTION_EPILOGUE
491 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
493 #undef TARGET_SCHED_ADJUST_COST
494 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
495 #undef TARGET_SCHED_ISSUE_RATE
496 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
497 #undef TARGET_SCHED_INIT
498 #define TARGET_SCHED_INIT sparc_sched_init
499 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
500 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
502 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
503 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
505 #undef TARGET_INIT_LIBFUNCS
506 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
507 #undef TARGET_INIT_BUILTINS
508 #define TARGET_INIT_BUILTINS sparc_init_builtins
510 #undef TARGET_LEGITIMIZE_ADDRESS
511 #define TARGET_LEGITIMIZE_ADDRESS sparc_legitimize_address
512 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
513 #define TARGET_MODE_DEPENDENT_ADDRESS_P sparc_mode_dependent_address_p
515 #undef TARGET_EXPAND_BUILTIN
516 #define TARGET_EXPAND_BUILTIN sparc_expand_builtin
517 #undef TARGET_FOLD_BUILTIN
518 #define TARGET_FOLD_BUILTIN sparc_fold_builtin
521 #undef TARGET_HAVE_TLS
522 #define TARGET_HAVE_TLS true
525 #undef TARGET_CANNOT_FORCE_CONST_MEM
526 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
528 #undef TARGET_ASM_OUTPUT_MI_THUNK
529 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
530 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
531 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
533 #undef TARGET_RTX_COSTS
534 #define TARGET_RTX_COSTS sparc_rtx_costs
535 #undef TARGET_ADDRESS_COST
536 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
538 #undef TARGET_PROMOTE_FUNCTION_MODE
539 #define TARGET_PROMOTE_FUNCTION_MODE sparc_promote_function_mode
541 #undef TARGET_PROMOTE_PROTOTYPES
542 #define TARGET_PROMOTE_PROTOTYPES sparc_promote_prototypes
544 #undef TARGET_FUNCTION_VALUE
545 #define TARGET_FUNCTION_VALUE sparc_function_value
546 #undef TARGET_LIBCALL_VALUE
547 #define TARGET_LIBCALL_VALUE sparc_libcall_value
548 #undef TARGET_FUNCTION_VALUE_REGNO_P
549 #define TARGET_FUNCTION_VALUE_REGNO_P sparc_function_value_regno_p
551 #undef TARGET_STRUCT_VALUE_RTX
552 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
553 #undef TARGET_RETURN_IN_MEMORY
554 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
555 #undef TARGET_MUST_PASS_IN_STACK
556 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
557 #undef TARGET_PASS_BY_REFERENCE
558 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
559 #undef TARGET_ARG_PARTIAL_BYTES
560 #define TARGET_ARG_PARTIAL_BYTES sparc_arg_partial_bytes
562 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
563 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
564 #undef TARGET_STRICT_ARGUMENT_NAMING
565 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
567 #undef TARGET_EXPAND_BUILTIN_VA_START
568 #define TARGET_EXPAND_BUILTIN_VA_START sparc_va_start
569 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
570 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
572 #undef TARGET_VECTOR_MODE_SUPPORTED_P
573 #define TARGET_VECTOR_MODE_SUPPORTED_P sparc_vector_mode_supported_p
575 #undef TARGET_VECTORIZE_UNITS_PER_SIMD_WORD
576 #define TARGET_VECTORIZE_UNITS_PER_SIMD_WORD sparc_units_per_simd_word
578 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
579 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC sparc_dwarf_handle_frame_unspec
581 #ifdef SUBTARGET_INSERT_ATTRIBUTES
582 #undef TARGET_INSERT_ATTRIBUTES
583 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
586 #ifdef SUBTARGET_ATTRIBUTE_TABLE
587 #undef TARGET_ATTRIBUTE_TABLE
588 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
591 #undef TARGET_RELAXED_ORDERING
592 #define TARGET_RELAXED_ORDERING SPARC_RELAXED_ORDERING
594 #undef TARGET_DEFAULT_TARGET_FLAGS
595 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
596 #undef TARGET_HANDLE_OPTION
597 #define TARGET_HANDLE_OPTION sparc_handle_option
599 #if TARGET_GNU_TLS && defined(HAVE_AS_SPARC_UA_PCREL)
600 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
601 #define TARGET_ASM_OUTPUT_DWARF_DTPREL sparc_output_dwarf_dtprel
604 #undef TARGET_ASM_FILE_END
605 #define TARGET_ASM_FILE_END sparc_file_end
607 #undef TARGET_FRAME_POINTER_REQUIRED
608 #define TARGET_FRAME_POINTER_REQUIRED sparc_frame_pointer_required
610 #undef TARGET_CAN_ELIMINATE
611 #define TARGET_CAN_ELIMINATE sparc_can_eliminate
613 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
614 #undef TARGET_MANGLE_TYPE
615 #define TARGET_MANGLE_TYPE sparc_mangle_type
618 #undef TARGET_LEGITIMATE_ADDRESS_P
619 #define TARGET_LEGITIMATE_ADDRESS_P sparc_legitimate_address_p
621 #undef TARGET_TRAMPOLINE_INIT
622 #define TARGET_TRAMPOLINE_INIT sparc_trampoline_init
624 struct gcc_target targetm = TARGET_INITIALIZER;
626 /* Implement TARGET_HANDLE_OPTION. */
629 sparc_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
634 case OPT_mhard_float:
635 case OPT_msoft_float:
636 fpu_option_set = true;
640 sparc_select[1].string = arg;
644 sparc_select[2].string = arg;
651 /* Validate and override various options, and do some machine dependent
655 sparc_override_options (void)
657 static struct code_model {
658 const char *const name;
659 const enum cmodel value;
660 } const cmodels[] = {
662 { "medlow", CM_MEDLOW },
663 { "medmid", CM_MEDMID },
664 { "medany", CM_MEDANY },
665 { "embmedany", CM_EMBMEDANY },
666 { NULL, (enum cmodel) 0 }
668 const struct code_model *cmodel;
669 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
670 static struct cpu_default {
672 const char *const name;
673 } const cpu_default[] = {
674 /* There must be one entry here for each TARGET_CPU value. */
675 { TARGET_CPU_sparc, "cypress" },
676 { TARGET_CPU_sparclet, "tsc701" },
677 { TARGET_CPU_sparclite, "f930" },
678 { TARGET_CPU_v8, "v8" },
679 { TARGET_CPU_hypersparc, "hypersparc" },
680 { TARGET_CPU_sparclite86x, "sparclite86x" },
681 { TARGET_CPU_supersparc, "supersparc" },
682 { TARGET_CPU_v9, "v9" },
683 { TARGET_CPU_ultrasparc, "ultrasparc" },
684 { TARGET_CPU_ultrasparc3, "ultrasparc3" },
685 { TARGET_CPU_niagara, "niagara" },
686 { TARGET_CPU_niagara2, "niagara2" },
689 const struct cpu_default *def;
690 /* Table of values for -m{cpu,tune}=. */
691 static struct cpu_table {
692 const char *const name;
693 const enum processor_type processor;
696 } const cpu_table[] = {
697 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
698 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
699 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
700 /* TI TMS390Z55 supersparc */
701 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
702 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
703 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
704 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
705 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
706 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
707 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
708 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
710 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
712 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
713 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
714 /* TI ultrasparc I, II, IIi */
715 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
716 /* Although insns using %y are deprecated, it is a clear win on current
718 |MASK_DEPRECATED_V8_INSNS},
719 /* TI ultrasparc III */
720 /* ??? Check if %y issue still holds true in ultra3. */
721 { "ultrasparc3", PROCESSOR_ULTRASPARC3, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
723 { "niagara", PROCESSOR_NIAGARA, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
724 { "niagara2", PROCESSOR_NIAGARA, MASK_ISA, MASK_V9},
725 { 0, (enum processor_type) 0, 0, 0 }
727 const struct cpu_table *cpu;
728 const struct sparc_cpu_select *sel;
731 #ifndef SPARC_BI_ARCH
732 /* Check for unsupported architecture size. */
733 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
734 error ("%s is not supported by this configuration",
735 DEFAULT_ARCH32_P ? "-m64" : "-m32");
738 /* We force all 64bit archs to use 128 bit long double */
739 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
741 error ("-mlong-double-64 not allowed with -m64");
742 target_flags |= MASK_LONG_DOUBLE_128;
745 /* Code model selection. */
746 sparc_cmodel = SPARC_DEFAULT_CMODEL;
750 sparc_cmodel = CM_32;
753 if (sparc_cmodel_string != NULL)
757 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
758 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
760 if (cmodel->name == NULL)
761 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
763 sparc_cmodel = cmodel->value;
766 error ("-mcmodel= is not supported on 32 bit systems");
769 fpu = target_flags & MASK_FPU; /* save current -mfpu status */
771 /* Set the default CPU. */
772 for (def = &cpu_default[0]; def->name; ++def)
773 if (def->cpu == TARGET_CPU_DEFAULT)
775 gcc_assert (def->name);
776 sparc_select[0].string = def->name;
778 for (sel = &sparc_select[0]; sel->name; ++sel)
782 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
783 if (! strcmp (sel->string, cpu->name))
786 sparc_cpu = cpu->processor;
790 target_flags &= ~cpu->disable;
791 target_flags |= cpu->enable;
797 error ("bad value (%s) for %s switch", sel->string, sel->name);
801 /* If -mfpu or -mno-fpu was explicitly used, don't override with
802 the processor default. */
804 target_flags = (target_flags & ~MASK_FPU) | fpu;
806 /* Don't allow -mvis if FPU is disabled. */
808 target_flags &= ~MASK_VIS;
810 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
812 -m64 also implies v9. */
813 if (TARGET_VIS || TARGET_ARCH64)
815 target_flags |= MASK_V9;
816 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
819 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
820 if (TARGET_V9 && TARGET_ARCH32)
821 target_flags |= MASK_DEPRECATED_V8_INSNS;
823 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
824 if (! TARGET_V9 || TARGET_ARCH64)
825 target_flags &= ~MASK_V8PLUS;
827 /* Don't use stack biasing in 32 bit mode. */
829 target_flags &= ~MASK_STACK_BIAS;
831 /* Supply a default value for align_functions. */
832 if (align_functions == 0
833 && (sparc_cpu == PROCESSOR_ULTRASPARC
834 || sparc_cpu == PROCESSOR_ULTRASPARC3
835 || sparc_cpu == PROCESSOR_NIAGARA
836 || sparc_cpu == PROCESSOR_NIAGARA2))
837 align_functions = 32;
839 /* Validate PCC_STRUCT_RETURN. */
840 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
841 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
843 /* Only use .uaxword when compiling for a 64-bit target. */
845 targetm.asm_out.unaligned_op.di = NULL;
847 /* Do various machine dependent initializations. */
850 /* Acquire unique alias sets for our private stuff. */
851 sparc_sr_alias_set = new_alias_set ();
852 struct_value_alias_set = new_alias_set ();
854 /* Set up function hooks. */
855 init_machine_status = sparc_init_machine_status;
860 case PROCESSOR_CYPRESS:
861 sparc_costs = &cypress_costs;
864 case PROCESSOR_SPARCLITE:
865 case PROCESSOR_SUPERSPARC:
866 sparc_costs = &supersparc_costs;
870 case PROCESSOR_HYPERSPARC:
871 case PROCESSOR_SPARCLITE86X:
872 sparc_costs = &hypersparc_costs;
874 case PROCESSOR_SPARCLET:
875 case PROCESSOR_TSC701:
876 sparc_costs = &sparclet_costs;
879 case PROCESSOR_ULTRASPARC:
880 sparc_costs = &ultrasparc_costs;
882 case PROCESSOR_ULTRASPARC3:
883 sparc_costs = &ultrasparc3_costs;
885 case PROCESSOR_NIAGARA:
886 sparc_costs = &niagara_costs;
888 case PROCESSOR_NIAGARA2:
889 sparc_costs = &niagara2_costs;
893 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
894 if (!(target_flags_explicit & MASK_LONG_DOUBLE_128))
895 target_flags |= MASK_LONG_DOUBLE_128;
898 if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
899 set_param_value ("simultaneous-prefetches",
900 ((sparc_cpu == PROCESSOR_ULTRASPARC
901 || sparc_cpu == PROCESSOR_NIAGARA
902 || sparc_cpu == PROCESSOR_NIAGARA2)
904 : (sparc_cpu == PROCESSOR_ULTRASPARC3
906 if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
907 set_param_value ("l1-cache-line-size",
908 ((sparc_cpu == PROCESSOR_ULTRASPARC
909 || sparc_cpu == PROCESSOR_ULTRASPARC3
910 || sparc_cpu == PROCESSOR_NIAGARA
911 || sparc_cpu == PROCESSOR_NIAGARA2)
915 /* Miscellaneous utilities. */
917 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
918 or branch on register contents instructions. */
921 v9_regcmp_p (enum rtx_code code)
923 return (code == EQ || code == NE || code == GE || code == LT
924 || code == LE || code == GT);
927 /* Nonzero if OP is a floating point constant which can
928 be loaded into an integer register using a single
929 sethi instruction. */
934 if (GET_CODE (op) == CONST_DOUBLE)
939 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
940 REAL_VALUE_TO_TARGET_SINGLE (r, i);
941 return !SPARC_SIMM13_P (i) && SPARC_SETHI_P (i);
947 /* Nonzero if OP is a floating point constant which can
948 be loaded into an integer register using a single
954 if (GET_CODE (op) == CONST_DOUBLE)
959 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
960 REAL_VALUE_TO_TARGET_SINGLE (r, i);
961 return SPARC_SIMM13_P (i);
967 /* Nonzero if OP is a floating point constant which can
968 be loaded into an integer register using a high/losum
969 instruction sequence. */
972 fp_high_losum_p (rtx op)
974 /* The constraints calling this should only be in
975 SFmode move insns, so any constant which cannot
976 be moved using a single insn will do. */
977 if (GET_CODE (op) == CONST_DOUBLE)
982 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
983 REAL_VALUE_TO_TARGET_SINGLE (r, i);
984 return !SPARC_SIMM13_P (i) && !SPARC_SETHI_P (i);
990 /* Expand a move instruction. Return true if all work is done. */
993 sparc_expand_move (enum machine_mode mode, rtx *operands)
995 /* Handle sets of MEM first. */
996 if (GET_CODE (operands[0]) == MEM)
998 /* 0 is a register (or a pair of registers) on SPARC. */
999 if (register_or_zero_operand (operands[1], mode))
1002 if (!reload_in_progress)
1004 operands[0] = validize_mem (operands[0]);
1005 operands[1] = force_reg (mode, operands[1]);
1009 /* Fixup TLS cases. */
1011 && CONSTANT_P (operands[1])
1012 && sparc_tls_referenced_p (operands [1]))
1014 operands[1] = sparc_legitimize_tls_address (operands[1]);
1018 /* Fixup PIC cases. */
1019 if (flag_pic && CONSTANT_P (operands[1]))
1021 if (pic_address_needs_scratch (operands[1]))
1022 operands[1] = sparc_legitimize_pic_address (operands[1], NULL_RTX);
1024 /* VxWorks does not impose a fixed gap between segments; the run-time
1025 gap can be different from the object-file gap. We therefore can't
1026 assume X - _GLOBAL_OFFSET_TABLE_ is a link-time constant unless we
1027 are absolutely sure that X is in the same segment as the GOT.
1028 Unfortunately, the flexibility of linker scripts means that we
1029 can't be sure of that in general, so assume that _G_O_T_-relative
1030 accesses are never valid on VxWorks. */
1031 if (GET_CODE (operands[1]) == LABEL_REF && !TARGET_VXWORKS_RTP)
1035 emit_insn (gen_movsi_pic_label_ref (operands[0], operands[1]));
1041 gcc_assert (TARGET_ARCH64);
1042 emit_insn (gen_movdi_pic_label_ref (operands[0], operands[1]));
1047 if (symbolic_operand (operands[1], mode))
1050 = sparc_legitimize_pic_address (operands[1],
1052 ? operands[0] : NULL_RTX);
1057 /* If we are trying to toss an integer constant into FP registers,
1058 or loading a FP or vector constant, force it into memory. */
1059 if (CONSTANT_P (operands[1])
1060 && REG_P (operands[0])
1061 && (SPARC_FP_REG_P (REGNO (operands[0]))
1062 || SCALAR_FLOAT_MODE_P (mode)
1063 || VECTOR_MODE_P (mode)))
1065 /* emit_group_store will send such bogosity to us when it is
1066 not storing directly into memory. So fix this up to avoid
1067 crashes in output_constant_pool. */
1068 if (operands [1] == const0_rtx)
1069 operands[1] = CONST0_RTX (mode);
1071 /* We can clear FP registers if TARGET_VIS, and always other regs. */
1072 if ((TARGET_VIS || REGNO (operands[0]) < SPARC_FIRST_FP_REG)
1073 && const_zero_operand (operands[1], mode))
1076 if (REGNO (operands[0]) < SPARC_FIRST_FP_REG
1077 /* We are able to build any SF constant in integer registers
1078 with at most 2 instructions. */
1080 /* And any DF constant in integer registers. */
1082 && (reload_completed || reload_in_progress))))
1085 operands[1] = force_const_mem (mode, operands[1]);
1086 if (!reload_in_progress)
1087 operands[1] = validize_mem (operands[1]);
1091 /* Accept non-constants and valid constants unmodified. */
1092 if (!CONSTANT_P (operands[1])
1093 || GET_CODE (operands[1]) == HIGH
1094 || input_operand (operands[1], mode))
1100 /* All QImode constants require only one insn, so proceed. */
1105 sparc_emit_set_const32 (operands[0], operands[1]);
1109 /* input_operand should have filtered out 32-bit mode. */
1110 sparc_emit_set_const64 (operands[0], operands[1]);
1120 /* Load OP1, a 32-bit constant, into OP0, a register.
1121 We know it can't be done in one insn when we get
1122 here, the move expander guarantees this. */
1125 sparc_emit_set_const32 (rtx op0, rtx op1)
1127 enum machine_mode mode = GET_MODE (op0);
1130 if (reload_in_progress || reload_completed)
1133 temp = gen_reg_rtx (mode);
1135 if (GET_CODE (op1) == CONST_INT)
1137 gcc_assert (!small_int_operand (op1, mode)
1138 && !const_high_operand (op1, mode));
1140 /* Emit them as real moves instead of a HIGH/LO_SUM,
1141 this way CSE can see everything and reuse intermediate
1142 values if it wants. */
1143 emit_insn (gen_rtx_SET (VOIDmode, temp,
1144 GEN_INT (INTVAL (op1)
1145 & ~(HOST_WIDE_INT)0x3ff)));
1147 emit_insn (gen_rtx_SET (VOIDmode,
1149 gen_rtx_IOR (mode, temp,
1150 GEN_INT (INTVAL (op1) & 0x3ff))));
1154 /* A symbol, emit in the traditional way. */
1155 emit_insn (gen_rtx_SET (VOIDmode, temp,
1156 gen_rtx_HIGH (mode, op1)));
1157 emit_insn (gen_rtx_SET (VOIDmode,
1158 op0, gen_rtx_LO_SUM (mode, temp, op1)));
1162 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
1163 If TEMP is nonzero, we are forbidden to use any other scratch
1164 registers. Otherwise, we are allowed to generate them as needed.
1166 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
1167 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
1170 sparc_emit_set_symbolic_const64 (rtx op0, rtx op1, rtx temp)
1172 rtx temp1, temp2, temp3, temp4, temp5;
1175 if (temp && GET_MODE (temp) == TImode)
1178 temp = gen_rtx_REG (DImode, REGNO (temp));
1181 /* SPARC-V9 code-model support. */
1182 switch (sparc_cmodel)
1185 /* The range spanned by all instructions in the object is less
1186 than 2^31 bytes (2GB) and the distance from any instruction
1187 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1188 than 2^31 bytes (2GB).
1190 The executable must be in the low 4TB of the virtual address
1193 sethi %hi(symbol), %temp1
1194 or %temp1, %lo(symbol), %reg */
1196 temp1 = temp; /* op0 is allowed. */
1198 temp1 = gen_reg_rtx (DImode);
1200 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1201 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1205 /* The range spanned by all instructions in the object is less
1206 than 2^31 bytes (2GB) and the distance from any instruction
1207 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1208 than 2^31 bytes (2GB).
1210 The executable must be in the low 16TB of the virtual address
1213 sethi %h44(symbol), %temp1
1214 or %temp1, %m44(symbol), %temp2
1215 sllx %temp2, 12, %temp3
1216 or %temp3, %l44(symbol), %reg */
1221 temp3 = temp; /* op0 is allowed. */
1225 temp1 = gen_reg_rtx (DImode);
1226 temp2 = gen_reg_rtx (DImode);
1227 temp3 = gen_reg_rtx (DImode);
1230 emit_insn (gen_seth44 (temp1, op1));
1231 emit_insn (gen_setm44 (temp2, temp1, op1));
1232 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1233 gen_rtx_ASHIFT (DImode, temp2, GEN_INT (12))));
1234 emit_insn (gen_setl44 (op0, temp3, op1));
1238 /* The range spanned by all instructions in the object is less
1239 than 2^31 bytes (2GB) and the distance from any instruction
1240 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1241 than 2^31 bytes (2GB).
1243 The executable can be placed anywhere in the virtual address
1246 sethi %hh(symbol), %temp1
1247 sethi %lm(symbol), %temp2
1248 or %temp1, %hm(symbol), %temp3
1249 sllx %temp3, 32, %temp4
1250 or %temp4, %temp2, %temp5
1251 or %temp5, %lo(symbol), %reg */
1254 /* It is possible that one of the registers we got for operands[2]
1255 might coincide with that of operands[0] (which is why we made
1256 it TImode). Pick the other one to use as our scratch. */
1257 if (rtx_equal_p (temp, op0))
1259 gcc_assert (ti_temp);
1260 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1263 temp2 = temp; /* op0 is _not_ allowed, see above. */
1270 temp1 = gen_reg_rtx (DImode);
1271 temp2 = gen_reg_rtx (DImode);
1272 temp3 = gen_reg_rtx (DImode);
1273 temp4 = gen_reg_rtx (DImode);
1274 temp5 = gen_reg_rtx (DImode);
1277 emit_insn (gen_sethh (temp1, op1));
1278 emit_insn (gen_setlm (temp2, op1));
1279 emit_insn (gen_sethm (temp3, temp1, op1));
1280 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1281 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1282 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1283 gen_rtx_PLUS (DImode, temp4, temp2)));
1284 emit_insn (gen_setlo (op0, temp5, op1));
1288 /* Old old old backwards compatibility kruft here.
1289 Essentially it is MEDLOW with a fixed 64-bit
1290 virtual base added to all data segment addresses.
1291 Text-segment stuff is computed like MEDANY, we can't
1292 reuse the code above because the relocation knobs
1295 Data segment: sethi %hi(symbol), %temp1
1296 add %temp1, EMBMEDANY_BASE_REG, %temp2
1297 or %temp2, %lo(symbol), %reg */
1298 if (data_segment_operand (op1, GET_MODE (op1)))
1302 temp1 = temp; /* op0 is allowed. */
1307 temp1 = gen_reg_rtx (DImode);
1308 temp2 = gen_reg_rtx (DImode);
1311 emit_insn (gen_embmedany_sethi (temp1, op1));
1312 emit_insn (gen_embmedany_brsum (temp2, temp1));
1313 emit_insn (gen_embmedany_losum (op0, temp2, op1));
1316 /* Text segment: sethi %uhi(symbol), %temp1
1317 sethi %hi(symbol), %temp2
1318 or %temp1, %ulo(symbol), %temp3
1319 sllx %temp3, 32, %temp4
1320 or %temp4, %temp2, %temp5
1321 or %temp5, %lo(symbol), %reg */
1326 /* It is possible that one of the registers we got for operands[2]
1327 might coincide with that of operands[0] (which is why we made
1328 it TImode). Pick the other one to use as our scratch. */
1329 if (rtx_equal_p (temp, op0))
1331 gcc_assert (ti_temp);
1332 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1335 temp2 = temp; /* op0 is _not_ allowed, see above. */
1342 temp1 = gen_reg_rtx (DImode);
1343 temp2 = gen_reg_rtx (DImode);
1344 temp3 = gen_reg_rtx (DImode);
1345 temp4 = gen_reg_rtx (DImode);
1346 temp5 = gen_reg_rtx (DImode);
1349 emit_insn (gen_embmedany_textuhi (temp1, op1));
1350 emit_insn (gen_embmedany_texthi (temp2, op1));
1351 emit_insn (gen_embmedany_textulo (temp3, temp1, op1));
1352 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1353 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1354 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1355 gen_rtx_PLUS (DImode, temp4, temp2)));
1356 emit_insn (gen_embmedany_textlo (op0, temp5, op1));
1365 #if HOST_BITS_PER_WIDE_INT == 32
1367 sparc_emit_set_const64 (rtx op0 ATTRIBUTE_UNUSED, rtx op1 ATTRIBUTE_UNUSED)
1372 /* These avoid problems when cross compiling. If we do not
1373 go through all this hair then the optimizer will see
1374 invalid REG_EQUAL notes or in some cases none at all. */
1375 static rtx gen_safe_HIGH64 (rtx, HOST_WIDE_INT);
1376 static rtx gen_safe_SET64 (rtx, HOST_WIDE_INT);
1377 static rtx gen_safe_OR64 (rtx, HOST_WIDE_INT);
1378 static rtx gen_safe_XOR64 (rtx, HOST_WIDE_INT);
1380 /* The optimizer is not to assume anything about exactly
1381 which bits are set for a HIGH, they are unspecified.
1382 Unfortunately this leads to many missed optimizations
1383 during CSE. We mask out the non-HIGH bits, and matches
1384 a plain movdi, to alleviate this problem. */
1386 gen_safe_HIGH64 (rtx dest, HOST_WIDE_INT val)
1388 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val & ~(HOST_WIDE_INT)0x3ff));
1392 gen_safe_SET64 (rtx dest, HOST_WIDE_INT val)
1394 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val));
1398 gen_safe_OR64 (rtx src, HOST_WIDE_INT val)
1400 return gen_rtx_IOR (DImode, src, GEN_INT (val));
1404 gen_safe_XOR64 (rtx src, HOST_WIDE_INT val)
1406 return gen_rtx_XOR (DImode, src, GEN_INT (val));
1409 /* Worker routines for 64-bit constant formation on arch64.
1410 One of the key things to be doing in these emissions is
1411 to create as many temp REGs as possible. This makes it
1412 possible for half-built constants to be used later when
1413 such values are similar to something required later on.
1414 Without doing this, the optimizer cannot see such
1417 static void sparc_emit_set_const64_quick1 (rtx, rtx,
1418 unsigned HOST_WIDE_INT, int);
1421 sparc_emit_set_const64_quick1 (rtx op0, rtx temp,
1422 unsigned HOST_WIDE_INT low_bits, int is_neg)
1424 unsigned HOST_WIDE_INT high_bits;
1427 high_bits = (~low_bits) & 0xffffffff;
1429 high_bits = low_bits;
1431 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1434 emit_insn (gen_rtx_SET (VOIDmode, op0,
1435 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1439 /* If we are XOR'ing with -1, then we should emit a one's complement
1440 instead. This way the combiner will notice logical operations
1441 such as ANDN later on and substitute. */
1442 if ((low_bits & 0x3ff) == 0x3ff)
1444 emit_insn (gen_rtx_SET (VOIDmode, op0,
1445 gen_rtx_NOT (DImode, temp)));
1449 emit_insn (gen_rtx_SET (VOIDmode, op0,
1450 gen_safe_XOR64 (temp,
1451 (-(HOST_WIDE_INT)0x400
1452 | (low_bits & 0x3ff)))));
1457 static void sparc_emit_set_const64_quick2 (rtx, rtx, unsigned HOST_WIDE_INT,
1458 unsigned HOST_WIDE_INT, int);
1461 sparc_emit_set_const64_quick2 (rtx op0, rtx temp,
1462 unsigned HOST_WIDE_INT high_bits,
1463 unsigned HOST_WIDE_INT low_immediate,
1468 if ((high_bits & 0xfffffc00) != 0)
1470 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1471 if ((high_bits & ~0xfffffc00) != 0)
1472 emit_insn (gen_rtx_SET (VOIDmode, op0,
1473 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1479 emit_insn (gen_safe_SET64 (temp, high_bits));
1483 /* Now shift it up into place. */
1484 emit_insn (gen_rtx_SET (VOIDmode, op0,
1485 gen_rtx_ASHIFT (DImode, temp2,
1486 GEN_INT (shift_count))));
1488 /* If there is a low immediate part piece, finish up by
1489 putting that in as well. */
1490 if (low_immediate != 0)
1491 emit_insn (gen_rtx_SET (VOIDmode, op0,
1492 gen_safe_OR64 (op0, low_immediate)));
1495 static void sparc_emit_set_const64_longway (rtx, rtx, unsigned HOST_WIDE_INT,
1496 unsigned HOST_WIDE_INT);
1498 /* Full 64-bit constant decomposition. Even though this is the
1499 'worst' case, we still optimize a few things away. */
1501 sparc_emit_set_const64_longway (rtx op0, rtx temp,
1502 unsigned HOST_WIDE_INT high_bits,
1503 unsigned HOST_WIDE_INT low_bits)
1507 if (reload_in_progress || reload_completed)
1510 sub_temp = gen_reg_rtx (DImode);
1512 if ((high_bits & 0xfffffc00) != 0)
1514 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1515 if ((high_bits & ~0xfffffc00) != 0)
1516 emit_insn (gen_rtx_SET (VOIDmode,
1518 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1524 emit_insn (gen_safe_SET64 (temp, high_bits));
1528 if (!reload_in_progress && !reload_completed)
1530 rtx temp2 = gen_reg_rtx (DImode);
1531 rtx temp3 = gen_reg_rtx (DImode);
1532 rtx temp4 = gen_reg_rtx (DImode);
1534 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1535 gen_rtx_ASHIFT (DImode, sub_temp,
1538 emit_insn (gen_safe_HIGH64 (temp2, low_bits));
1539 if ((low_bits & ~0xfffffc00) != 0)
1541 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1542 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1543 emit_insn (gen_rtx_SET (VOIDmode, op0,
1544 gen_rtx_PLUS (DImode, temp4, temp3)));
1548 emit_insn (gen_rtx_SET (VOIDmode, op0,
1549 gen_rtx_PLUS (DImode, temp4, temp2)));
1554 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1555 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1556 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1559 /* We are in the middle of reload, so this is really
1560 painful. However we do still make an attempt to
1561 avoid emitting truly stupid code. */
1562 if (low1 != const0_rtx)
1564 emit_insn (gen_rtx_SET (VOIDmode, op0,
1565 gen_rtx_ASHIFT (DImode, sub_temp,
1566 GEN_INT (to_shift))));
1567 emit_insn (gen_rtx_SET (VOIDmode, op0,
1568 gen_rtx_IOR (DImode, op0, low1)));
1576 if (low2 != const0_rtx)
1578 emit_insn (gen_rtx_SET (VOIDmode, op0,
1579 gen_rtx_ASHIFT (DImode, sub_temp,
1580 GEN_INT (to_shift))));
1581 emit_insn (gen_rtx_SET (VOIDmode, op0,
1582 gen_rtx_IOR (DImode, op0, low2)));
1590 emit_insn (gen_rtx_SET (VOIDmode, op0,
1591 gen_rtx_ASHIFT (DImode, sub_temp,
1592 GEN_INT (to_shift))));
1593 if (low3 != const0_rtx)
1594 emit_insn (gen_rtx_SET (VOIDmode, op0,
1595 gen_rtx_IOR (DImode, op0, low3)));
1600 /* Analyze a 64-bit constant for certain properties. */
1601 static void analyze_64bit_constant (unsigned HOST_WIDE_INT,
1602 unsigned HOST_WIDE_INT,
1603 int *, int *, int *);
1606 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits,
1607 unsigned HOST_WIDE_INT low_bits,
1608 int *hbsp, int *lbsp, int *abbasp)
1610 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1613 lowest_bit_set = highest_bit_set = -1;
1617 if ((lowest_bit_set == -1)
1618 && ((low_bits >> i) & 1))
1620 if ((highest_bit_set == -1)
1621 && ((high_bits >> (32 - i - 1)) & 1))
1622 highest_bit_set = (64 - i - 1);
1625 && ((highest_bit_set == -1)
1626 || (lowest_bit_set == -1)));
1632 if ((lowest_bit_set == -1)
1633 && ((high_bits >> i) & 1))
1634 lowest_bit_set = i + 32;
1635 if ((highest_bit_set == -1)
1636 && ((low_bits >> (32 - i - 1)) & 1))
1637 highest_bit_set = 32 - i - 1;
1640 && ((highest_bit_set == -1)
1641 || (lowest_bit_set == -1)));
1643 /* If there are no bits set this should have gone out
1644 as one instruction! */
1645 gcc_assert (lowest_bit_set != -1 && highest_bit_set != -1);
1646 all_bits_between_are_set = 1;
1647 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1651 if ((low_bits & (1 << i)) != 0)
1656 if ((high_bits & (1 << (i - 32))) != 0)
1659 all_bits_between_are_set = 0;
1662 *hbsp = highest_bit_set;
1663 *lbsp = lowest_bit_set;
1664 *abbasp = all_bits_between_are_set;
1667 static int const64_is_2insns (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
1670 const64_is_2insns (unsigned HOST_WIDE_INT high_bits,
1671 unsigned HOST_WIDE_INT low_bits)
1673 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1676 || high_bits == 0xffffffff)
1679 analyze_64bit_constant (high_bits, low_bits,
1680 &highest_bit_set, &lowest_bit_set,
1681 &all_bits_between_are_set);
1683 if ((highest_bit_set == 63
1684 || lowest_bit_set == 0)
1685 && all_bits_between_are_set != 0)
1688 if ((highest_bit_set - lowest_bit_set) < 21)
1694 static unsigned HOST_WIDE_INT create_simple_focus_bits (unsigned HOST_WIDE_INT,
1695 unsigned HOST_WIDE_INT,
1698 static unsigned HOST_WIDE_INT
1699 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits,
1700 unsigned HOST_WIDE_INT low_bits,
1701 int lowest_bit_set, int shift)
1703 HOST_WIDE_INT hi, lo;
1705 if (lowest_bit_set < 32)
1707 lo = (low_bits >> lowest_bit_set) << shift;
1708 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
1713 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
1715 gcc_assert (! (hi & lo));
1719 /* Here we are sure to be arch64 and this is an integer constant
1720 being loaded into a register. Emit the most efficient
1721 insn sequence possible. Detection of all the 1-insn cases
1722 has been done already. */
1724 sparc_emit_set_const64 (rtx op0, rtx op1)
1726 unsigned HOST_WIDE_INT high_bits, low_bits;
1727 int lowest_bit_set, highest_bit_set;
1728 int all_bits_between_are_set;
1731 /* Sanity check that we know what we are working with. */
1732 gcc_assert (TARGET_ARCH64
1733 && (GET_CODE (op0) == SUBREG
1734 || (REG_P (op0) && ! SPARC_FP_REG_P (REGNO (op0)))));
1736 if (reload_in_progress || reload_completed)
1739 if (GET_CODE (op1) != CONST_INT)
1741 sparc_emit_set_symbolic_const64 (op0, op1, temp);
1746 temp = gen_reg_rtx (DImode);
1748 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
1749 low_bits = (INTVAL (op1) & 0xffffffff);
1751 /* low_bits bits 0 --> 31
1752 high_bits bits 32 --> 63 */
1754 analyze_64bit_constant (high_bits, low_bits,
1755 &highest_bit_set, &lowest_bit_set,
1756 &all_bits_between_are_set);
1758 /* First try for a 2-insn sequence. */
1760 /* These situations are preferred because the optimizer can
1761 * do more things with them:
1763 * sllx %reg, shift, %reg
1765 * srlx %reg, shift, %reg
1766 * 3) mov some_small_const, %reg
1767 * sllx %reg, shift, %reg
1769 if (((highest_bit_set == 63
1770 || lowest_bit_set == 0)
1771 && all_bits_between_are_set != 0)
1772 || ((highest_bit_set - lowest_bit_set) < 12))
1774 HOST_WIDE_INT the_const = -1;
1775 int shift = lowest_bit_set;
1777 if ((highest_bit_set != 63
1778 && lowest_bit_set != 0)
1779 || all_bits_between_are_set == 0)
1782 create_simple_focus_bits (high_bits, low_bits,
1785 else if (lowest_bit_set == 0)
1786 shift = -(63 - highest_bit_set);
1788 gcc_assert (SPARC_SIMM13_P (the_const));
1789 gcc_assert (shift != 0);
1791 emit_insn (gen_safe_SET64 (temp, the_const));
1793 emit_insn (gen_rtx_SET (VOIDmode,
1795 gen_rtx_ASHIFT (DImode,
1799 emit_insn (gen_rtx_SET (VOIDmode,
1801 gen_rtx_LSHIFTRT (DImode,
1803 GEN_INT (-shift))));
1807 /* Now a range of 22 or less bits set somewhere.
1808 * 1) sethi %hi(focus_bits), %reg
1809 * sllx %reg, shift, %reg
1810 * 2) sethi %hi(focus_bits), %reg
1811 * srlx %reg, shift, %reg
1813 if ((highest_bit_set - lowest_bit_set) < 21)
1815 unsigned HOST_WIDE_INT focus_bits =
1816 create_simple_focus_bits (high_bits, low_bits,
1817 lowest_bit_set, 10);
1819 gcc_assert (SPARC_SETHI_P (focus_bits));
1820 gcc_assert (lowest_bit_set != 10);
1822 emit_insn (gen_safe_HIGH64 (temp, focus_bits));
1824 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
1825 if (lowest_bit_set < 10)
1826 emit_insn (gen_rtx_SET (VOIDmode,
1828 gen_rtx_LSHIFTRT (DImode, temp,
1829 GEN_INT (10 - lowest_bit_set))));
1830 else if (lowest_bit_set > 10)
1831 emit_insn (gen_rtx_SET (VOIDmode,
1833 gen_rtx_ASHIFT (DImode, temp,
1834 GEN_INT (lowest_bit_set - 10))));
1838 /* 1) sethi %hi(low_bits), %reg
1839 * or %reg, %lo(low_bits), %reg
1840 * 2) sethi %hi(~low_bits), %reg
1841 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
1844 || high_bits == 0xffffffff)
1846 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
1847 (high_bits == 0xffffffff));
1851 /* Now, try 3-insn sequences. */
1853 /* 1) sethi %hi(high_bits), %reg
1854 * or %reg, %lo(high_bits), %reg
1855 * sllx %reg, 32, %reg
1859 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
1863 /* We may be able to do something quick
1864 when the constant is negated, so try that. */
1865 if (const64_is_2insns ((~high_bits) & 0xffffffff,
1866 (~low_bits) & 0xfffffc00))
1868 /* NOTE: The trailing bits get XOR'd so we need the
1869 non-negated bits, not the negated ones. */
1870 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
1872 if ((((~high_bits) & 0xffffffff) == 0
1873 && ((~low_bits) & 0x80000000) == 0)
1874 || (((~high_bits) & 0xffffffff) == 0xffffffff
1875 && ((~low_bits) & 0x80000000) != 0))
1877 unsigned HOST_WIDE_INT fast_int = (~low_bits & 0xffffffff);
1879 if ((SPARC_SETHI_P (fast_int)
1880 && (~high_bits & 0xffffffff) == 0)
1881 || SPARC_SIMM13_P (fast_int))
1882 emit_insn (gen_safe_SET64 (temp, fast_int));
1884 sparc_emit_set_const64 (temp, GEN_INT (fast_int));
1889 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
1890 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
1891 sparc_emit_set_const64 (temp, negated_const);
1894 /* If we are XOR'ing with -1, then we should emit a one's complement
1895 instead. This way the combiner will notice logical operations
1896 such as ANDN later on and substitute. */
1897 if (trailing_bits == 0x3ff)
1899 emit_insn (gen_rtx_SET (VOIDmode, op0,
1900 gen_rtx_NOT (DImode, temp)));
1904 emit_insn (gen_rtx_SET (VOIDmode,
1906 gen_safe_XOR64 (temp,
1907 (-0x400 | trailing_bits))));
1912 /* 1) sethi %hi(xxx), %reg
1913 * or %reg, %lo(xxx), %reg
1914 * sllx %reg, yyy, %reg
1916 * ??? This is just a generalized version of the low_bits==0
1917 * thing above, FIXME...
1919 if ((highest_bit_set - lowest_bit_set) < 32)
1921 unsigned HOST_WIDE_INT focus_bits =
1922 create_simple_focus_bits (high_bits, low_bits,
1925 /* We can't get here in this state. */
1926 gcc_assert (highest_bit_set >= 32 && lowest_bit_set < 32);
1928 /* So what we know is that the set bits straddle the
1929 middle of the 64-bit word. */
1930 sparc_emit_set_const64_quick2 (op0, temp,
1936 /* 1) sethi %hi(high_bits), %reg
1937 * or %reg, %lo(high_bits), %reg
1938 * sllx %reg, 32, %reg
1939 * or %reg, low_bits, %reg
1941 if (SPARC_SIMM13_P(low_bits)
1942 && ((int)low_bits > 0))
1944 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
1948 /* The easiest way when all else fails, is full decomposition. */
1949 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
1951 #endif /* HOST_BITS_PER_WIDE_INT == 32 */
1953 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
1954 return the mode to be used for the comparison. For floating-point,
1955 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
1956 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
1957 processing is needed. */
1960 select_cc_mode (enum rtx_code op, rtx x, rtx y ATTRIBUTE_UNUSED)
1962 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1988 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
1989 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
1991 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
1992 return CCX_NOOVmode;
1998 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2005 /* Emit the compare insn and return the CC reg for a CODE comparison
2006 with operands X and Y. */
2009 gen_compare_reg_1 (enum rtx_code code, rtx x, rtx y)
2011 enum machine_mode mode;
2014 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
2017 mode = SELECT_CC_MODE (code, x, y);
2019 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2020 fcc regs (cse can't tell they're really call clobbered regs and will
2021 remove a duplicate comparison even if there is an intervening function
2022 call - it will then try to reload the cc reg via an int reg which is why
2023 we need the movcc patterns). It is possible to provide the movcc
2024 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2025 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2026 to tell cse that CCFPE mode registers (even pseudos) are call
2029 /* ??? This is an experiment. Rather than making changes to cse which may
2030 or may not be easy/clean, we do our own cse. This is possible because
2031 we will generate hard registers. Cse knows they're call clobbered (it
2032 doesn't know the same thing about pseudos). If we guess wrong, no big
2033 deal, but if we win, great! */
2035 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2036 #if 1 /* experiment */
2039 /* We cycle through the registers to ensure they're all exercised. */
2040 static int next_fcc_reg = 0;
2041 /* Previous x,y for each fcc reg. */
2042 static rtx prev_args[4][2];
2044 /* Scan prev_args for x,y. */
2045 for (reg = 0; reg < 4; reg++)
2046 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2051 prev_args[reg][0] = x;
2052 prev_args[reg][1] = y;
2053 next_fcc_reg = (next_fcc_reg + 1) & 3;
2055 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2058 cc_reg = gen_reg_rtx (mode);
2059 #endif /* ! experiment */
2060 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2061 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2063 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2065 /* We shouldn't get there for TFmode if !TARGET_HARD_QUAD. If we do, this
2066 will only result in an unrecognizable insn so no point in asserting. */
2067 emit_insn (gen_rtx_SET (VOIDmode, cc_reg, gen_rtx_COMPARE (mode, x, y)));
2073 /* Emit the compare insn and return the CC reg for the comparison in CMP. */
2076 gen_compare_reg (rtx cmp)
2078 return gen_compare_reg_1 (GET_CODE (cmp), XEXP (cmp, 0), XEXP (cmp, 1));
2081 /* This function is used for v9 only.
2082 DEST is the target of the Scc insn.
2083 CODE is the code for an Scc's comparison.
2084 X and Y are the values we compare.
2086 This function is needed to turn
2089 (gt (reg:CCX 100 %icc)
2093 (gt:DI (reg:CCX 100 %icc)
2096 IE: The instruction recognizer needs to see the mode of the comparison to
2097 find the right instruction. We could use "gt:DI" right in the
2098 define_expand, but leaving it out allows us to handle DI, SI, etc. */
2101 gen_v9_scc (rtx dest, enum rtx_code compare_code, rtx x, rtx y)
2104 && (GET_MODE (x) == DImode
2105 || GET_MODE (dest) == DImode))
2108 /* Try to use the movrCC insns. */
2110 && GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2112 && v9_regcmp_p (compare_code))
2117 /* Special case for op0 != 0. This can be done with one instruction if
2120 if (compare_code == NE
2121 && GET_MODE (dest) == DImode
2122 && rtx_equal_p (op0, dest))
2124 emit_insn (gen_rtx_SET (VOIDmode, dest,
2125 gen_rtx_IF_THEN_ELSE (DImode,
2126 gen_rtx_fmt_ee (compare_code, DImode,
2133 if (reg_overlap_mentioned_p (dest, op0))
2135 /* Handle the case where dest == x.
2136 We "early clobber" the result. */
2137 op0 = gen_reg_rtx (GET_MODE (x));
2138 emit_move_insn (op0, x);
2141 emit_insn (gen_rtx_SET (VOIDmode, dest, const0_rtx));
2142 if (GET_MODE (op0) != DImode)
2144 temp = gen_reg_rtx (DImode);
2145 convert_move (temp, op0, 0);
2149 emit_insn (gen_rtx_SET (VOIDmode, dest,
2150 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2151 gen_rtx_fmt_ee (compare_code, DImode,
2159 x = gen_compare_reg_1 (compare_code, x, y);
2162 gcc_assert (GET_MODE (x) != CC_NOOVmode
2163 && GET_MODE (x) != CCX_NOOVmode);
2165 emit_insn (gen_rtx_SET (VOIDmode, dest, const0_rtx));
2166 emit_insn (gen_rtx_SET (VOIDmode, dest,
2167 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2168 gen_rtx_fmt_ee (compare_code,
2169 GET_MODE (x), x, y),
2170 const1_rtx, dest)));
2176 /* Emit an scc insn. For seq, sne, sgeu, and sltu, we can do this
2177 without jumps using the addx/subx instructions. */
2180 emit_scc_insn (rtx operands[])
2187 /* The quad-word fp compare library routines all return nonzero to indicate
2188 true, which is different from the equivalent libgcc routines, so we must
2189 handle them specially here. */
2190 if (GET_MODE (operands[2]) == TFmode && ! TARGET_HARD_QUAD)
2192 operands[1] = sparc_emit_float_lib_cmp (operands[2], operands[3],
2193 GET_CODE (operands[1]));
2194 operands[2] = XEXP (operands[1], 0);
2195 operands[3] = XEXP (operands[1], 1);
2198 code = GET_CODE (operands[1]);
2202 /* For seq/sne on v9 we use the same code as v8 (the addx/subx method has
2203 more applications). The exception to this is "reg != 0" which can
2204 be done in one instruction on v9 (so we do it). */
2207 if (GET_MODE (x) == SImode)
2209 rtx pat = gen_seqsi_special (operands[0], x, y);
2213 else if (GET_MODE (x) == DImode)
2215 rtx pat = gen_seqdi_special (operands[0], x, y);
2223 if (GET_MODE (x) == SImode)
2225 rtx pat = gen_snesi_special (operands[0], x, y);
2229 else if (GET_MODE (x) == DImode)
2231 rtx pat = gen_snedi_special (operands[0], x, y);
2237 /* For the rest, on v9 we can use conditional moves. */
2241 if (gen_v9_scc (operands[0], code, x, y))
2245 /* We can do LTU and GEU using the addx/subx instructions too. And
2246 for GTU/LEU, if both operands are registers swap them and fall
2247 back to the easy case. */
2248 if (code == GTU || code == LEU)
2250 if ((GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
2251 && (GET_CODE (y) == REG || GET_CODE (y) == SUBREG))
2256 code = swap_condition (code);
2260 if (code == LTU || code == GEU)
2262 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2263 gen_rtx_fmt_ee (code, SImode,
2264 gen_compare_reg_1 (code, x, y),
2269 /* Nope, do branches. */
2273 /* Emit a conditional jump insn for the v9 architecture using comparison code
2274 CODE and jump target LABEL.
2275 This function exists to take advantage of the v9 brxx insns. */
2278 emit_v9_brxx_insn (enum rtx_code code, rtx op0, rtx label)
2280 emit_jump_insn (gen_rtx_SET (VOIDmode,
2282 gen_rtx_IF_THEN_ELSE (VOIDmode,
2283 gen_rtx_fmt_ee (code, GET_MODE (op0),
2285 gen_rtx_LABEL_REF (VOIDmode, label),
2290 emit_conditional_branch_insn (rtx operands[])
2292 /* The quad-word fp compare library routines all return nonzero to indicate
2293 true, which is different from the equivalent libgcc routines, so we must
2294 handle them specially here. */
2295 if (GET_MODE (operands[1]) == TFmode && ! TARGET_HARD_QUAD)
2297 operands[0] = sparc_emit_float_lib_cmp (operands[1], operands[2],
2298 GET_CODE (operands[0]));
2299 operands[1] = XEXP (operands[0], 0);
2300 operands[2] = XEXP (operands[0], 1);
2303 if (TARGET_ARCH64 && operands[2] == const0_rtx
2304 && GET_CODE (operands[1]) == REG
2305 && GET_MODE (operands[1]) == DImode)
2307 emit_v9_brxx_insn (GET_CODE (operands[0]), operands[1], operands[3]);
2311 operands[1] = gen_compare_reg (operands[0]);
2312 operands[2] = const0_rtx;
2313 operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]), VOIDmode,
2314 operands[1], operands[2]);
2315 emit_jump_insn (gen_cbranchcc4 (operands[0], operands[1], operands[2],
2320 /* Generate a DFmode part of a hard TFmode register.
2321 REG is the TFmode hard register, LOW is 1 for the
2322 low 64bit of the register and 0 otherwise.
2325 gen_df_reg (rtx reg, int low)
2327 int regno = REGNO (reg);
2329 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2330 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
2331 return gen_rtx_REG (DFmode, regno);
2334 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
2335 Unlike normal calls, TFmode operands are passed by reference. It is
2336 assumed that no more than 3 operands are required. */
2339 emit_soft_tfmode_libcall (const char *func_name, int nargs, rtx *operands)
2341 rtx ret_slot = NULL, arg[3], func_sym;
2344 /* We only expect to be called for conversions, unary, and binary ops. */
2345 gcc_assert (nargs == 2 || nargs == 3);
2347 for (i = 0; i < nargs; ++i)
2349 rtx this_arg = operands[i];
2352 /* TFmode arguments and return values are passed by reference. */
2353 if (GET_MODE (this_arg) == TFmode)
2355 int force_stack_temp;
2357 force_stack_temp = 0;
2358 if (TARGET_BUGGY_QP_LIB && i == 0)
2359 force_stack_temp = 1;
2361 if (GET_CODE (this_arg) == MEM
2362 && ! force_stack_temp)
2363 this_arg = XEXP (this_arg, 0);
2364 else if (CONSTANT_P (this_arg)
2365 && ! force_stack_temp)
2367 this_slot = force_const_mem (TFmode, this_arg);
2368 this_arg = XEXP (this_slot, 0);
2372 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode), 0);
2374 /* Operand 0 is the return value. We'll copy it out later. */
2376 emit_move_insn (this_slot, this_arg);
2378 ret_slot = this_slot;
2380 this_arg = XEXP (this_slot, 0);
2387 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
2389 if (GET_MODE (operands[0]) == TFmode)
2392 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
2393 arg[0], GET_MODE (arg[0]),
2394 arg[1], GET_MODE (arg[1]));
2396 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
2397 arg[0], GET_MODE (arg[0]),
2398 arg[1], GET_MODE (arg[1]),
2399 arg[2], GET_MODE (arg[2]));
2402 emit_move_insn (operands[0], ret_slot);
2408 gcc_assert (nargs == 2);
2410 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
2411 GET_MODE (operands[0]), 1,
2412 arg[1], GET_MODE (arg[1]));
2414 if (ret != operands[0])
2415 emit_move_insn (operands[0], ret);
2419 /* Expand soft-float TFmode calls to sparc abi routines. */
2422 emit_soft_tfmode_binop (enum rtx_code code, rtx *operands)
2444 emit_soft_tfmode_libcall (func, 3, operands);
2448 emit_soft_tfmode_unop (enum rtx_code code, rtx *operands)
2452 gcc_assert (code == SQRT);
2455 emit_soft_tfmode_libcall (func, 2, operands);
2459 emit_soft_tfmode_cvt (enum rtx_code code, rtx *operands)
2466 switch (GET_MODE (operands[1]))
2479 case FLOAT_TRUNCATE:
2480 switch (GET_MODE (operands[0]))
2494 switch (GET_MODE (operands[1]))
2499 operands[1] = gen_rtx_SIGN_EXTEND (DImode, operands[1]);
2509 case UNSIGNED_FLOAT:
2510 switch (GET_MODE (operands[1]))
2515 operands[1] = gen_rtx_ZERO_EXTEND (DImode, operands[1]);
2526 switch (GET_MODE (operands[0]))
2540 switch (GET_MODE (operands[0]))
2557 emit_soft_tfmode_libcall (func, 2, operands);
2560 /* Expand a hard-float tfmode operation. All arguments must be in
2564 emit_hard_tfmode_operation (enum rtx_code code, rtx *operands)
2568 if (GET_RTX_CLASS (code) == RTX_UNARY)
2570 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2571 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
2575 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2576 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
2577 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
2578 operands[1], operands[2]);
2581 if (register_operand (operands[0], VOIDmode))
2584 dest = gen_reg_rtx (GET_MODE (operands[0]));
2586 emit_insn (gen_rtx_SET (VOIDmode, dest, op));
2588 if (dest != operands[0])
2589 emit_move_insn (operands[0], dest);
2593 emit_tfmode_binop (enum rtx_code code, rtx *operands)
2595 if (TARGET_HARD_QUAD)
2596 emit_hard_tfmode_operation (code, operands);
2598 emit_soft_tfmode_binop (code, operands);
2602 emit_tfmode_unop (enum rtx_code code, rtx *operands)
2604 if (TARGET_HARD_QUAD)
2605 emit_hard_tfmode_operation (code, operands);
2607 emit_soft_tfmode_unop (code, operands);
2611 emit_tfmode_cvt (enum rtx_code code, rtx *operands)
2613 if (TARGET_HARD_QUAD)
2614 emit_hard_tfmode_operation (code, operands);
2616 emit_soft_tfmode_cvt (code, operands);
2619 /* Return nonzero if a branch/jump/call instruction will be emitting
2620 nop into its delay slot. */
2623 empty_delay_slot (rtx insn)
2627 /* If no previous instruction (should not happen), return true. */
2628 if (PREV_INSN (insn) == NULL)
2631 seq = NEXT_INSN (PREV_INSN (insn));
2632 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
2638 /* Return nonzero if TRIAL can go into the call delay slot. */
2641 tls_call_delay (rtx trial)
2646 call __tls_get_addr, %tgd_call (foo)
2647 add %l7, %o0, %o0, %tgd_add (foo)
2648 while Sun as/ld does not. */
2649 if (TARGET_GNU_TLS || !TARGET_TLS)
2652 pat = PATTERN (trial);
2654 /* We must reject tgd_add{32|64}, i.e.
2655 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSGD)))
2656 and tldm_add{32|64}, i.e.
2657 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSLDM)))
2659 if (GET_CODE (pat) == SET
2660 && GET_CODE (SET_SRC (pat)) == PLUS)
2662 rtx unspec = XEXP (SET_SRC (pat), 1);
2664 if (GET_CODE (unspec) == UNSPEC
2665 && (XINT (unspec, 1) == UNSPEC_TLSGD
2666 || XINT (unspec, 1) == UNSPEC_TLSLDM))
2673 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
2674 instruction. RETURN_P is true if the v9 variant 'return' is to be
2675 considered in the test too.
2677 TRIAL must be a SET whose destination is a REG appropriate for the
2678 'restore' instruction or, if RETURN_P is true, for the 'return'
2682 eligible_for_restore_insn (rtx trial, bool return_p)
2684 rtx pat = PATTERN (trial);
2685 rtx src = SET_SRC (pat);
2687 /* The 'restore src,%g0,dest' pattern for word mode and below. */
2688 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2689 && arith_operand (src, GET_MODE (src)))
2692 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2694 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2697 /* The 'restore src,%g0,dest' pattern for double-word mode. */
2698 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2699 && arith_double_operand (src, GET_MODE (src)))
2700 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2702 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
2703 else if (! TARGET_FPU && register_operand (src, SFmode))
2706 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
2707 else if (! TARGET_FPU && TARGET_ARCH64 && register_operand (src, DFmode))
2710 /* If we have the 'return' instruction, anything that does not use
2711 local or output registers and can go into a delay slot wins. */
2712 else if (return_p && TARGET_V9 && ! epilogue_renumber (&pat, 1)
2713 && (get_attr_in_uncond_branch_delay (trial)
2714 == IN_UNCOND_BRANCH_DELAY_TRUE))
2717 /* The 'restore src1,src2,dest' pattern for SImode. */
2718 else if (GET_CODE (src) == PLUS
2719 && register_operand (XEXP (src, 0), SImode)
2720 && arith_operand (XEXP (src, 1), SImode))
2723 /* The 'restore src1,src2,dest' pattern for DImode. */
2724 else if (GET_CODE (src) == PLUS
2725 && register_operand (XEXP (src, 0), DImode)
2726 && arith_double_operand (XEXP (src, 1), DImode))
2729 /* The 'restore src1,%lo(src2),dest' pattern. */
2730 else if (GET_CODE (src) == LO_SUM
2731 && ! TARGET_CM_MEDMID
2732 && ((register_operand (XEXP (src, 0), SImode)
2733 && immediate_operand (XEXP (src, 1), SImode))
2735 && register_operand (XEXP (src, 0), DImode)
2736 && immediate_operand (XEXP (src, 1), DImode))))
2739 /* The 'restore src,src,dest' pattern. */
2740 else if (GET_CODE (src) == ASHIFT
2741 && (register_operand (XEXP (src, 0), SImode)
2742 || register_operand (XEXP (src, 0), DImode))
2743 && XEXP (src, 1) == const1_rtx)
2749 /* Return nonzero if TRIAL can go into the function return's
2753 eligible_for_return_delay (rtx trial)
2757 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2760 if (get_attr_length (trial) != 1)
2763 /* If there are any call-saved registers, we should scan TRIAL if it
2764 does not reference them. For now just make it easy. */
2768 /* If the function uses __builtin_eh_return, the eh_return machinery
2769 occupies the delay slot. */
2770 if (crtl->calls_eh_return)
2773 /* In the case of a true leaf function, anything can go into the slot. */
2774 if (sparc_leaf_function_p)
2775 return get_attr_in_uncond_branch_delay (trial)
2776 == IN_UNCOND_BRANCH_DELAY_TRUE;
2778 pat = PATTERN (trial);
2780 /* Otherwise, only operations which can be done in tandem with
2781 a `restore' or `return' insn can go into the delay slot. */
2782 if (GET_CODE (SET_DEST (pat)) != REG
2783 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24))
2786 /* If this instruction sets up floating point register and we have a return
2787 instruction, it can probably go in. But restore will not work
2789 if (REGNO (SET_DEST (pat)) >= 32)
2791 && ! epilogue_renumber (&pat, 1)
2792 && (get_attr_in_uncond_branch_delay (trial)
2793 == IN_UNCOND_BRANCH_DELAY_TRUE));
2795 return eligible_for_restore_insn (trial, true);
2798 /* Return nonzero if TRIAL can go into the sibling call's
2802 eligible_for_sibcall_delay (rtx trial)
2806 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2809 if (get_attr_length (trial) != 1)
2812 pat = PATTERN (trial);
2814 if (sparc_leaf_function_p)
2816 /* If the tail call is done using the call instruction,
2817 we have to restore %o7 in the delay slot. */
2818 if (LEAF_SIBCALL_SLOT_RESERVED_P)
2821 /* %g1 is used to build the function address */
2822 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
2828 /* Otherwise, only operations which can be done in tandem with
2829 a `restore' insn can go into the delay slot. */
2830 if (GET_CODE (SET_DEST (pat)) != REG
2831 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24)
2832 || REGNO (SET_DEST (pat)) >= 32)
2835 /* If it mentions %o7, it can't go in, because sibcall will clobber it
2837 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
2840 return eligible_for_restore_insn (trial, false);
2844 short_branch (int uid1, int uid2)
2846 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
2848 /* Leave a few words of "slop". */
2849 if (delta >= -1023 && delta <= 1022)
2855 /* Return nonzero if REG is not used after INSN.
2856 We assume REG is a reload reg, and therefore does
2857 not live past labels or calls or jumps. */
2859 reg_unused_after (rtx reg, rtx insn)
2861 enum rtx_code code, prev_code = UNKNOWN;
2863 while ((insn = NEXT_INSN (insn)))
2865 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
2868 code = GET_CODE (insn);
2869 if (GET_CODE (insn) == CODE_LABEL)
2874 rtx set = single_set (insn);
2875 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
2878 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
2880 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
2888 /* Determine if it's legal to put X into the constant pool. This
2889 is not possible if X contains the address of a symbol that is
2890 not constant (TLS) or not known at final link time (PIC). */
2893 sparc_cannot_force_const_mem (rtx x)
2895 switch (GET_CODE (x))
2900 /* Accept all non-symbolic constants. */
2904 /* Labels are OK iff we are non-PIC. */
2905 return flag_pic != 0;
2908 /* 'Naked' TLS symbol references are never OK,
2909 non-TLS symbols are OK iff we are non-PIC. */
2910 if (SYMBOL_REF_TLS_MODEL (x))
2913 return flag_pic != 0;
2916 return sparc_cannot_force_const_mem (XEXP (x, 0));
2919 return sparc_cannot_force_const_mem (XEXP (x, 0))
2920 || sparc_cannot_force_const_mem (XEXP (x, 1));
2929 static GTY(()) bool pic_helper_needed = false;
2930 static GTY(()) rtx pic_helper_symbol;
2931 static GTY(()) rtx global_offset_table;
2933 /* Ensure that we are not using patterns that are not OK with PIC. */
2941 gcc_assert (GET_CODE (recog_data.operand[i]) != SYMBOL_REF
2942 && (GET_CODE (recog_data.operand[i]) != CONST
2943 || (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
2944 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
2945 == global_offset_table)
2946 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
2954 /* Return true if X is an address which needs a temporary register when
2955 reloaded while generating PIC code. */
2958 pic_address_needs_scratch (rtx x)
2960 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
2961 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2962 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2963 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2964 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
2970 /* Determine if a given RTX is a valid constant. We already know this
2971 satisfies CONSTANT_P. */
2974 legitimate_constant_p (rtx x)
2976 switch (GET_CODE (x))
2980 if (sparc_tls_referenced_p (x))
2985 if (GET_MODE (x) == VOIDmode)
2988 /* Floating point constants are generally not ok.
2989 The only exception is 0.0 in VIS. */
2991 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
2992 && const_zero_operand (x, GET_MODE (x)))
2998 /* Vector constants are generally not ok.
2999 The only exception is 0 in VIS. */
3001 && const_zero_operand (x, GET_MODE (x)))
3013 /* Determine if a given RTX is a valid constant address. */
3016 constant_address_p (rtx x)
3018 switch (GET_CODE (x))
3026 if (flag_pic && pic_address_needs_scratch (x))
3028 return legitimate_constant_p (x);
3031 return !flag_pic && legitimate_constant_p (x);
3038 /* Nonzero if the constant value X is a legitimate general operand
3039 when generating PIC code. It is given that flag_pic is on and
3040 that X satisfies CONSTANT_P or is a CONST_DOUBLE. */
3043 legitimate_pic_operand_p (rtx x)
3045 if (pic_address_needs_scratch (x))
3047 if (sparc_tls_referenced_p (x))
3052 /* Return nonzero if ADDR is a valid memory address.
3053 STRICT specifies whether strict register checking applies. */
3056 sparc_legitimate_address_p (enum machine_mode mode, rtx addr, bool strict)
3058 rtx rs1 = NULL, rs2 = NULL, imm1 = NULL;
3060 if (REG_P (addr) || GET_CODE (addr) == SUBREG)
3062 else if (GET_CODE (addr) == PLUS)
3064 rs1 = XEXP (addr, 0);
3065 rs2 = XEXP (addr, 1);
3067 /* Canonicalize. REG comes first, if there are no regs,
3068 LO_SUM comes first. */
3070 && GET_CODE (rs1) != SUBREG
3072 || GET_CODE (rs2) == SUBREG
3073 || (GET_CODE (rs2) == LO_SUM && GET_CODE (rs1) != LO_SUM)))
3075 rs1 = XEXP (addr, 1);
3076 rs2 = XEXP (addr, 0);
3080 && rs1 == pic_offset_table_rtx
3082 && GET_CODE (rs2) != SUBREG
3083 && GET_CODE (rs2) != LO_SUM
3084 && GET_CODE (rs2) != MEM
3085 && !(GET_CODE (rs2) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs2))
3086 && (! symbolic_operand (rs2, VOIDmode) || mode == Pmode)
3087 && (GET_CODE (rs2) != CONST_INT || SMALL_INT (rs2)))
3089 || GET_CODE (rs1) == SUBREG)
3090 && RTX_OK_FOR_OFFSET_P (rs2)))
3095 else if ((REG_P (rs1) || GET_CODE (rs1) == SUBREG)
3096 && (REG_P (rs2) || GET_CODE (rs2) == SUBREG))
3098 /* We prohibit REG + REG for TFmode when there are no quad move insns
3099 and we consequently need to split. We do this because REG+REG
3100 is not an offsettable address. If we get the situation in reload
3101 where source and destination of a movtf pattern are both MEMs with
3102 REG+REG address, then only one of them gets converted to an
3103 offsettable address. */
3105 && ! (TARGET_FPU && TARGET_ARCH64 && TARGET_HARD_QUAD))
3108 /* We prohibit REG + REG on ARCH32 if not optimizing for
3109 DFmode/DImode because then mem_min_alignment is likely to be zero
3110 after reload and the forced split would lack a matching splitter
3112 if (TARGET_ARCH32 && !optimize
3113 && (mode == DFmode || mode == DImode))
3116 else if (USE_AS_OFFSETABLE_LO10
3117 && GET_CODE (rs1) == LO_SUM
3119 && ! TARGET_CM_MEDMID
3120 && RTX_OK_FOR_OLO10_P (rs2))
3123 imm1 = XEXP (rs1, 1);
3124 rs1 = XEXP (rs1, 0);
3125 if (!CONSTANT_P (imm1)
3126 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
3130 else if (GET_CODE (addr) == LO_SUM)
3132 rs1 = XEXP (addr, 0);
3133 imm1 = XEXP (addr, 1);
3135 if (!CONSTANT_P (imm1)
3136 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
3139 /* We can't allow TFmode in 32-bit mode, because an offset greater
3140 than the alignment (8) may cause the LO_SUM to overflow. */
3141 if (mode == TFmode && TARGET_ARCH32)
3144 else if (GET_CODE (addr) == CONST_INT && SMALL_INT (addr))
3149 if (GET_CODE (rs1) == SUBREG)
3150 rs1 = SUBREG_REG (rs1);
3156 if (GET_CODE (rs2) == SUBREG)
3157 rs2 = SUBREG_REG (rs2);
3164 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1))
3165 || (rs2 && !REGNO_OK_FOR_BASE_P (REGNO (rs2))))
3170 if ((REGNO (rs1) >= 32
3171 && REGNO (rs1) != FRAME_POINTER_REGNUM
3172 && REGNO (rs1) < FIRST_PSEUDO_REGISTER)
3174 && (REGNO (rs2) >= 32
3175 && REGNO (rs2) != FRAME_POINTER_REGNUM
3176 && REGNO (rs2) < FIRST_PSEUDO_REGISTER)))
3182 /* Construct the SYMBOL_REF for the tls_get_offset function. */
3184 static GTY(()) rtx sparc_tls_symbol;
3187 sparc_tls_get_addr (void)
3189 if (!sparc_tls_symbol)
3190 sparc_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_addr");
3192 return sparc_tls_symbol;
3196 sparc_tls_got (void)
3201 crtl->uses_pic_offset_table = 1;
3202 return pic_offset_table_rtx;
3205 if (!global_offset_table)
3206 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3207 temp = gen_reg_rtx (Pmode);
3208 emit_move_insn (temp, global_offset_table);
3212 /* Return true if X contains a thread-local symbol. */
3215 sparc_tls_referenced_p (rtx x)
3217 if (!TARGET_HAVE_TLS)
3220 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
3221 x = XEXP (XEXP (x, 0), 0);
3223 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x))
3226 /* That's all we handle in sparc_legitimize_tls_address for now. */
3230 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3231 this (thread-local) address. */
3234 sparc_legitimize_tls_address (rtx addr)
3236 rtx temp1, temp2, temp3, ret, o0, got, insn;
3238 gcc_assert (can_create_pseudo_p ());
3240 if (GET_CODE (addr) == SYMBOL_REF)
3241 switch (SYMBOL_REF_TLS_MODEL (addr))
3243 case TLS_MODEL_GLOBAL_DYNAMIC:
3245 temp1 = gen_reg_rtx (SImode);
3246 temp2 = gen_reg_rtx (SImode);
3247 ret = gen_reg_rtx (Pmode);
3248 o0 = gen_rtx_REG (Pmode, 8);
3249 got = sparc_tls_got ();
3250 emit_insn (gen_tgd_hi22 (temp1, addr));
3251 emit_insn (gen_tgd_lo10 (temp2, temp1, addr));
3254 emit_insn (gen_tgd_add32 (o0, got, temp2, addr));
3255 insn = emit_call_insn (gen_tgd_call32 (o0, sparc_tls_get_addr (),
3260 emit_insn (gen_tgd_add64 (o0, got, temp2, addr));
3261 insn = emit_call_insn (gen_tgd_call64 (o0, sparc_tls_get_addr (),
3264 CALL_INSN_FUNCTION_USAGE (insn)
3265 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
3266 CALL_INSN_FUNCTION_USAGE (insn));
3267 insn = get_insns ();
3269 emit_libcall_block (insn, ret, o0, addr);
3272 case TLS_MODEL_LOCAL_DYNAMIC:
3274 temp1 = gen_reg_rtx (SImode);
3275 temp2 = gen_reg_rtx (SImode);
3276 temp3 = gen_reg_rtx (Pmode);
3277 ret = gen_reg_rtx (Pmode);
3278 o0 = gen_rtx_REG (Pmode, 8);
3279 got = sparc_tls_got ();
3280 emit_insn (gen_tldm_hi22 (temp1));
3281 emit_insn (gen_tldm_lo10 (temp2, temp1));
3284 emit_insn (gen_tldm_add32 (o0, got, temp2));
3285 insn = emit_call_insn (gen_tldm_call32 (o0, sparc_tls_get_addr (),
3290 emit_insn (gen_tldm_add64 (o0, got, temp2));
3291 insn = emit_call_insn (gen_tldm_call64 (o0, sparc_tls_get_addr (),
3294 CALL_INSN_FUNCTION_USAGE (insn)
3295 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
3296 CALL_INSN_FUNCTION_USAGE (insn));
3297 insn = get_insns ();
3299 emit_libcall_block (insn, temp3, o0,
3300 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3301 UNSPEC_TLSLD_BASE));
3302 temp1 = gen_reg_rtx (SImode);
3303 temp2 = gen_reg_rtx (SImode);
3304 emit_insn (gen_tldo_hix22 (temp1, addr));
3305 emit_insn (gen_tldo_lox10 (temp2, temp1, addr));
3307 emit_insn (gen_tldo_add32 (ret, temp3, temp2, addr));
3309 emit_insn (gen_tldo_add64 (ret, temp3, temp2, addr));
3312 case TLS_MODEL_INITIAL_EXEC:
3313 temp1 = gen_reg_rtx (SImode);
3314 temp2 = gen_reg_rtx (SImode);
3315 temp3 = gen_reg_rtx (Pmode);
3316 got = sparc_tls_got ();
3317 emit_insn (gen_tie_hi22 (temp1, addr));
3318 emit_insn (gen_tie_lo10 (temp2, temp1, addr));
3320 emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
3322 emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
3325 ret = gen_reg_rtx (Pmode);
3327 emit_insn (gen_tie_add32 (ret, gen_rtx_REG (Pmode, 7),
3330 emit_insn (gen_tie_add64 (ret, gen_rtx_REG (Pmode, 7),
3334 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp3);
3337 case TLS_MODEL_LOCAL_EXEC:
3338 temp1 = gen_reg_rtx (Pmode);
3339 temp2 = gen_reg_rtx (Pmode);
3342 emit_insn (gen_tle_hix22_sp32 (temp1, addr));
3343 emit_insn (gen_tle_lox10_sp32 (temp2, temp1, addr));
3347 emit_insn (gen_tle_hix22_sp64 (temp1, addr));
3348 emit_insn (gen_tle_lox10_sp64 (temp2, temp1, addr));
3350 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp2);
3357 else if (GET_CODE (addr) == CONST)
3361 gcc_assert (GET_CODE (XEXP (addr, 0)) == PLUS);
3363 base = sparc_legitimize_tls_address (XEXP (XEXP (addr, 0), 0));
3364 offset = XEXP (XEXP (addr, 0), 1);
3366 base = force_operand (base, NULL_RTX);
3367 if (!(GET_CODE (offset) == CONST_INT && SMALL_INT (offset)))
3368 offset = force_reg (Pmode, offset);
3369 ret = gen_rtx_PLUS (Pmode, base, offset);
3373 gcc_unreachable (); /* for now ... */
3378 /* Legitimize PIC addresses. If the address is already position-independent,
3379 we return ORIG. Newly generated position-independent addresses go into a
3380 reg. This is REG if nonzero, otherwise we allocate register(s) as
3384 sparc_legitimize_pic_address (rtx orig, rtx reg)
3386 bool gotdata_op = false;
3388 if (GET_CODE (orig) == SYMBOL_REF
3389 /* See the comment in sparc_expand_move. */
3390 || (TARGET_VXWORKS_RTP && GET_CODE (orig) == LABEL_REF))
3392 rtx pic_ref, address;
3397 gcc_assert (! reload_in_progress && ! reload_completed);
3398 reg = gen_reg_rtx (Pmode);
3403 /* If not during reload, allocate another temp reg here for loading
3404 in the address, so that these instructions can be optimized
3406 rtx temp_reg = ((reload_in_progress || reload_completed)
3407 ? reg : gen_reg_rtx (Pmode));
3409 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
3410 won't get confused into thinking that these two instructions
3411 are loading in the true address of the symbol. If in the
3412 future a PIC rtx exists, that should be used instead. */
3415 emit_insn (gen_movdi_high_pic (temp_reg, orig));
3416 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
3420 emit_insn (gen_movsi_high_pic (temp_reg, orig));
3421 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
3429 crtl->uses_pic_offset_table = 1;
3433 insn = emit_insn (gen_movdi_pic_gotdata_op (reg,
3434 pic_offset_table_rtx,
3437 insn = emit_insn (gen_movsi_pic_gotdata_op (reg,
3438 pic_offset_table_rtx,
3443 pic_ref = gen_const_mem (Pmode,
3444 gen_rtx_PLUS (Pmode,
3445 pic_offset_table_rtx, address));
3446 insn = emit_move_insn (reg, pic_ref);
3448 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3450 set_unique_reg_note (insn, REG_EQUAL, orig);
3453 else if (GET_CODE (orig) == CONST)
3457 if (GET_CODE (XEXP (orig, 0)) == PLUS
3458 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3463 gcc_assert (! reload_in_progress && ! reload_completed);
3464 reg = gen_reg_rtx (Pmode);
3467 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
3468 base = sparc_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), reg);
3469 offset = sparc_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
3470 base == reg ? NULL_RTX : reg);
3472 if (GET_CODE (offset) == CONST_INT)
3474 if (SMALL_INT (offset))
3475 return plus_constant (base, INTVAL (offset));
3476 else if (! reload_in_progress && ! reload_completed)
3477 offset = force_reg (Pmode, offset);
3479 /* If we reach here, then something is seriously wrong. */
3482 return gen_rtx_PLUS (Pmode, base, offset);
3484 else if (GET_CODE (orig) == LABEL_REF)
3485 /* ??? Why do we do this? */
3486 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
3487 the register is live instead, in case it is eliminated. */
3488 crtl->uses_pic_offset_table = 1;
3493 /* Try machine-dependent ways of modifying an illegitimate address X
3494 to be legitimate. If we find one, return the new, valid address.
3496 OLDX is the address as it was before break_out_memory_refs was called.
3497 In some cases it is useful to look at this to decide what needs to be done.
3499 MODE is the mode of the operand pointed to by X.
3501 On SPARC, change REG+N into REG+REG, and REG+(X*Y) into REG+REG. */
3504 sparc_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
3505 enum machine_mode mode)
3509 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT)
3510 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3511 force_operand (XEXP (x, 0), NULL_RTX));
3512 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == MULT)
3513 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3514 force_operand (XEXP (x, 1), NULL_RTX));
3515 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS)
3516 x = gen_rtx_PLUS (Pmode, force_operand (XEXP (x, 0), NULL_RTX),
3518 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == PLUS)
3519 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3520 force_operand (XEXP (x, 1), NULL_RTX));
3522 if (x != orig_x && sparc_legitimate_address_p (mode, x, FALSE))
3525 if (sparc_tls_referenced_p (x))
3526 x = sparc_legitimize_tls_address (x);
3528 x = sparc_legitimize_pic_address (x, NULL_RTX);
3529 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 1)))
3530 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
3531 copy_to_mode_reg (Pmode, XEXP (x, 1)));
3532 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 0)))
3533 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
3534 copy_to_mode_reg (Pmode, XEXP (x, 0)));
3535 else if (GET_CODE (x) == SYMBOL_REF
3536 || GET_CODE (x) == CONST
3537 || GET_CODE (x) == LABEL_REF)
3538 x = copy_to_suggested_reg (x, NULL_RTX, Pmode);
3543 /* SPARC implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3544 replace the input X, or the original X if no replacement is called for.
3545 The output parameter *WIN is 1 if the calling macro should goto WIN,
3548 For SPARC, we wish to handle addresses by splitting them into
3549 HIGH+LO_SUM pairs, retaining the LO_SUM in the memory reference.
3550 This cuts the number of extra insns by one.
3552 Do nothing when generating PIC code and the address is a symbolic
3553 operand or requires a scratch register. */
3556 sparc_legitimize_reload_address (rtx x, enum machine_mode mode,
3557 int opnum, int type,
3558 int ind_levels ATTRIBUTE_UNUSED, int *win)
3560 /* Decompose SImode constants into HIGH+LO_SUM. */
3562 && (mode != TFmode || TARGET_ARCH64)
3563 && GET_MODE (x) == SImode
3564 && GET_CODE (x) != LO_SUM
3565 && GET_CODE (x) != HIGH
3566 && sparc_cmodel <= CM_MEDLOW
3568 && (symbolic_operand (x, Pmode) || pic_address_needs_scratch (x))))
3570 x = gen_rtx_LO_SUM (GET_MODE (x), gen_rtx_HIGH (GET_MODE (x), x), x);
3571 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3572 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3573 opnum, (enum reload_type)type);
3578 /* We have to recognize what we have already generated above. */
3579 if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == HIGH)
3581 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3582 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3583 opnum, (enum reload_type)type);
3592 /* Return true if ADDR (a legitimate address expression)
3593 has an effect that depends on the machine mode it is used for.
3599 is not equivalent to
3601 (mem:QI [%l7+a]) (mem:QI [%l7+a+1])
3603 because [%l7+a+1] is interpreted as the address of (a+1). */
3607 sparc_mode_dependent_address_p (const_rtx addr)
3609 if (flag_pic && GET_CODE (addr) == PLUS)
3611 rtx op0 = XEXP (addr, 0);
3612 rtx op1 = XEXP (addr, 1);
3613 if (op0 == pic_offset_table_rtx
3614 && SYMBOLIC_CONST (op1))
3621 #ifdef HAVE_GAS_HIDDEN
3622 # define USE_HIDDEN_LINKONCE 1
3624 # define USE_HIDDEN_LINKONCE 0
3628 get_pc_thunk_name (char name[32], unsigned int regno)
3630 const char *pic_name = reg_names[regno];
3632 /* Skip the leading '%' as that cannot be used in a
3636 if (USE_HIDDEN_LINKONCE)
3637 sprintf (name, "__sparc_get_pc_thunk.%s", pic_name);
3639 ASM_GENERATE_INTERNAL_LABEL (name, "LADDPC", regno);
3642 /* Emit code to load the PIC register. */
3645 load_pic_register (void)
3647 int orig_flag_pic = flag_pic;
3649 if (TARGET_VXWORKS_RTP)
3651 emit_insn (gen_vxworks_load_got ());
3652 emit_use (pic_offset_table_rtx);
3656 /* If we haven't initialized the special PIC symbols, do so now. */
3657 if (!pic_helper_needed)
3661 pic_helper_needed = true;
3663 get_pc_thunk_name (name, REGNO (pic_offset_table_rtx));
3664 pic_helper_symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
3666 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3671 emit_insn (gen_load_pcrel_symdi (pic_offset_table_rtx, global_offset_table,
3672 pic_helper_symbol));
3674 emit_insn (gen_load_pcrel_symsi (pic_offset_table_rtx, global_offset_table,
3675 pic_helper_symbol));
3676 flag_pic = orig_flag_pic;
3678 /* Need to emit this whether or not we obey regdecls,
3679 since setjmp/longjmp can cause life info to screw up.
3680 ??? In the case where we don't obey regdecls, this is not sufficient
3681 since we may not fall out the bottom. */
3682 emit_use (pic_offset_table_rtx);
3685 /* Emit a call instruction with the pattern given by PAT. ADDR is the
3686 address of the call target. */
3689 sparc_emit_call_insn (rtx pat, rtx addr)
3693 insn = emit_call_insn (pat);
3695 /* The PIC register is live on entry to VxWorks PIC PLT entries. */
3696 if (TARGET_VXWORKS_RTP
3698 && GET_CODE (addr) == SYMBOL_REF
3699 && (SYMBOL_REF_DECL (addr)
3700 ? !targetm.binds_local_p (SYMBOL_REF_DECL (addr))
3701 : !SYMBOL_REF_LOCAL_P (addr)))
3703 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
3704 crtl->uses_pic_offset_table = 1;
3708 /* Return 1 if RTX is a MEM which is known to be aligned to at
3709 least a DESIRED byte boundary. */
3712 mem_min_alignment (rtx mem, int desired)
3714 rtx addr, base, offset;
3716 /* If it's not a MEM we can't accept it. */
3717 if (GET_CODE (mem) != MEM)
3721 if (!TARGET_UNALIGNED_DOUBLES
3722 && MEM_ALIGN (mem) / BITS_PER_UNIT >= (unsigned)desired)
3725 /* ??? The rest of the function predates MEM_ALIGN so
3726 there is probably a bit of redundancy. */
3727 addr = XEXP (mem, 0);
3728 base = offset = NULL_RTX;
3729 if (GET_CODE (addr) == PLUS)
3731 if (GET_CODE (XEXP (addr, 0)) == REG)
3733 base = XEXP (addr, 0);
3735 /* What we are saying here is that if the base
3736 REG is aligned properly, the compiler will make
3737 sure any REG based index upon it will be so
3739 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3740 offset = XEXP (addr, 1);
3742 offset = const0_rtx;
3745 else if (GET_CODE (addr) == REG)
3748 offset = const0_rtx;
3751 if (base != NULL_RTX)
3753 int regno = REGNO (base);
3755 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
3757 /* Check if the compiler has recorded some information
3758 about the alignment of the base REG. If reload has
3759 completed, we already matched with proper alignments.
3760 If not running global_alloc, reload might give us
3761 unaligned pointer to local stack though. */
3763 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
3764 || (optimize && reload_completed))
3765 && (INTVAL (offset) & (desired - 1)) == 0)
3770 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
3774 else if (! TARGET_UNALIGNED_DOUBLES
3775 || CONSTANT_P (addr)
3776 || GET_CODE (addr) == LO_SUM)
3778 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
3779 is true, in which case we can only assume that an access is aligned if
3780 it is to a constant address, or the address involves a LO_SUM. */
3784 /* An obviously unaligned address. */
3789 /* Vectors to keep interesting information about registers where it can easily
3790 be got. We used to use the actual mode value as the bit number, but there
3791 are more than 32 modes now. Instead we use two tables: one indexed by
3792 hard register number, and one indexed by mode. */
3794 /* The purpose of sparc_mode_class is to shrink the range of modes so that
3795 they all fit (as bit numbers) in a 32-bit word (again). Each real mode is
3796 mapped into one sparc_mode_class mode. */
3798 enum sparc_mode_class {
3799 S_MODE, D_MODE, T_MODE, O_MODE,
3800 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
3804 /* Modes for single-word and smaller quantities. */
3805 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
3807 /* Modes for double-word and smaller quantities. */
3808 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
3810 /* Modes for quad-word and smaller quantities. */
3811 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
3813 /* Modes for 8-word and smaller quantities. */
3814 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
3816 /* Modes for single-float quantities. We must allow any single word or
3817 smaller quantity. This is because the fix/float conversion instructions
3818 take integer inputs/outputs from the float registers. */
3819 #define SF_MODES (S_MODES)
3821 /* Modes for double-float and smaller quantities. */
3822 #define DF_MODES (D_MODES)
3824 /* Modes for quad-float and smaller quantities. */
3825 #define TF_MODES (DF_MODES | (1 << (int) TF_MODE))
3827 /* Modes for quad-float pairs and smaller quantities. */
3828 #define OF_MODES (TF_MODES | (1 << (int) OF_MODE))
3830 /* Modes for double-float only quantities. */
3831 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
3833 /* Modes for quad-float and double-float only quantities. */
3834 #define TF_MODES_NO_S (DF_MODES_NO_S | (1 << (int) TF_MODE))
3836 /* Modes for quad-float pairs and double-float only quantities. */
3837 #define OF_MODES_NO_S (TF_MODES_NO_S | (1 << (int) OF_MODE))
3839 /* Modes for condition codes. */
3840 #define CC_MODES (1 << (int) CC_MODE)
3841 #define CCFP_MODES (1 << (int) CCFP_MODE)
3843 /* Value is 1 if register/mode pair is acceptable on sparc.
3844 The funny mixture of D and T modes is because integer operations
3845 do not specially operate on tetra quantities, so non-quad-aligned
3846 registers can hold quadword quantities (except %o4 and %i4 because
3847 they cross fixed registers). */
3849 /* This points to either the 32 bit or the 64 bit version. */
3850 const int *hard_regno_mode_classes;
3852 static const int hard_32bit_mode_classes[] = {
3853 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3854 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3855 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3856 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3858 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3859 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3860 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3861 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3863 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3864 and none can hold SFmode/SImode values. */
3865 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3866 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3867 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3868 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3871 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3877 static const int hard_64bit_mode_classes[] = {
3878 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3879 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3880 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3881 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3883 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3884 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3885 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3886 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3888 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3889 and none can hold SFmode/SImode values. */
3890 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3891 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3892 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3893 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3896 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3902 int sparc_mode_class [NUM_MACHINE_MODES];
3904 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
3907 sparc_init_modes (void)
3911 for (i = 0; i < NUM_MACHINE_MODES; i++)
3913 switch (GET_MODE_CLASS (i))
3916 case MODE_PARTIAL_INT:
3917 case MODE_COMPLEX_INT:
3918 if (GET_MODE_SIZE (i) <= 4)
3919 sparc_mode_class[i] = 1 << (int) S_MODE;
3920 else if (GET_MODE_SIZE (i) == 8)
3921 sparc_mode_class[i] = 1 << (int) D_MODE;
3922 else if (GET_MODE_SIZE (i) == 16)
3923 sparc_mode_class[i] = 1 << (int) T_MODE;
3924 else if (GET_MODE_SIZE (i) == 32)
3925 sparc_mode_class[i] = 1 << (int) O_MODE;
3927 sparc_mode_class[i] = 0;
3929 case MODE_VECTOR_INT:
3930 if (GET_MODE_SIZE (i) <= 4)
3931 sparc_mode_class[i] = 1 << (int)SF_MODE;
3932 else if (GET_MODE_SIZE (i) == 8)
3933 sparc_mode_class[i] = 1 << (int)DF_MODE;
3936 case MODE_COMPLEX_FLOAT:
3937 if (GET_MODE_SIZE (i) <= 4)
3938 sparc_mode_class[i] = 1 << (int) SF_MODE;
3939 else if (GET_MODE_SIZE (i) == 8)
3940 sparc_mode_class[i] = 1 << (int) DF_MODE;
3941 else if (GET_MODE_SIZE (i) == 16)
3942 sparc_mode_class[i] = 1 << (int) TF_MODE;
3943 else if (GET_MODE_SIZE (i) == 32)
3944 sparc_mode_class[i] = 1 << (int) OF_MODE;
3946 sparc_mode_class[i] = 0;
3949 if (i == (int) CCFPmode || i == (int) CCFPEmode)
3950 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
3952 sparc_mode_class[i] = 1 << (int) CC_MODE;
3955 sparc_mode_class[i] = 0;
3961 hard_regno_mode_classes = hard_64bit_mode_classes;
3963 hard_regno_mode_classes = hard_32bit_mode_classes;
3965 /* Initialize the array used by REGNO_REG_CLASS. */
3966 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3968 if (i < 16 && TARGET_V8PLUS)
3969 sparc_regno_reg_class[i] = I64_REGS;
3970 else if (i < 32 || i == FRAME_POINTER_REGNUM)
3971 sparc_regno_reg_class[i] = GENERAL_REGS;
3973 sparc_regno_reg_class[i] = FP_REGS;
3975 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
3977 sparc_regno_reg_class[i] = FPCC_REGS;
3979 sparc_regno_reg_class[i] = NO_REGS;
3983 /* Compute the frame size required by the function. This function is called
3984 during the reload pass and also by sparc_expand_prologue. */
3987 sparc_compute_frame_size (HOST_WIDE_INT size, int leaf_function_p)
3989 int outgoing_args_size = (crtl->outgoing_args_size
3990 + REG_PARM_STACK_SPACE (current_function_decl));
3991 int n_regs = 0; /* N_REGS is the number of 4-byte regs saved thus far. */
3996 for (i = 0; i < 8; i++)
3997 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
4002 for (i = 0; i < 8; i += 2)
4003 if ((df_regs_ever_live_p (i) && ! call_used_regs[i])
4004 || (df_regs_ever_live_p (i+1) && ! call_used_regs[i+1]))
4008 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
4009 if ((df_regs_ever_live_p (i) && ! call_used_regs[i])
4010 || (df_regs_ever_live_p (i+1) && ! call_used_regs[i+1]))
4013 /* Set up values for use in prologue and epilogue. */
4014 num_gfregs = n_regs;
4019 && crtl->outgoing_args_size == 0)
4020 actual_fsize = apparent_fsize = 0;
4023 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
4024 apparent_fsize = (size - STARTING_FRAME_OFFSET + 7) & -8;
4025 apparent_fsize += n_regs * 4;
4026 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
4029 /* Make sure nothing can clobber our register windows.
4030 If a SAVE must be done, or there is a stack-local variable,
4031 the register window area must be allocated. */
4032 if (! leaf_function_p || size > 0)
4033 actual_fsize += FIRST_PARM_OFFSET (current_function_decl);
4035 return SPARC_STACK_ALIGN (actual_fsize);
4038 /* Output any necessary .register pseudo-ops. */
4041 sparc_output_scratch_registers (FILE *file ATTRIBUTE_UNUSED)
4043 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
4049 /* Check if %g[2367] were used without
4050 .register being printed for them already. */
4051 for (i = 2; i < 8; i++)
4053 if (df_regs_ever_live_p (i)
4054 && ! sparc_hard_reg_printed [i])
4056 sparc_hard_reg_printed [i] = 1;
4057 /* %g7 is used as TLS base register, use #ignore
4058 for it instead of #scratch. */
4059 fprintf (file, "\t.register\t%%g%d, #%s\n", i,
4060 i == 7 ? "ignore" : "scratch");
4067 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
4069 #if PROBE_INTERVAL > 4096
4070 #error Cannot use indexed addressing mode for stack probing
4073 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
4074 inclusive. These are offsets from the current stack pointer.
4076 Note that we don't use the REG+REG addressing mode for the probes because
4077 of the stack bias in 64-bit mode. And it doesn't really buy us anything
4078 so the advantages of having a single code win here. */
4081 sparc_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
4083 rtx g1 = gen_rtx_REG (Pmode, 1);
4085 /* See if we have a constant small number of probes to generate. If so,
4086 that's the easy case. */
4087 if (size <= PROBE_INTERVAL)
4089 emit_move_insn (g1, GEN_INT (first));
4090 emit_insn (gen_rtx_SET (VOIDmode, g1,
4091 gen_rtx_MINUS (Pmode, stack_pointer_rtx, g1)));
4092 emit_stack_probe (plus_constant (g1, -size));
4095 /* The run-time loop is made up of 10 insns in the generic case while the
4096 compile-time loop is made up of 4+2*(n-2) insns for n # of intervals. */
4097 else if (size <= 5 * PROBE_INTERVAL)
4101 emit_move_insn (g1, GEN_INT (first + PROBE_INTERVAL));
4102 emit_insn (gen_rtx_SET (VOIDmode, g1,
4103 gen_rtx_MINUS (Pmode, stack_pointer_rtx, g1)));
4104 emit_stack_probe (g1);
4106 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 2 until
4107 it exceeds SIZE. If only two probes are needed, this will not
4108 generate any code. Then probe at FIRST + SIZE. */
4109 for (i = 2 * PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
4111 emit_insn (gen_rtx_SET (VOIDmode, g1,
4112 plus_constant (g1, -PROBE_INTERVAL)));
4113 emit_stack_probe (g1);
4116 emit_stack_probe (plus_constant (g1, (i - PROBE_INTERVAL) - size));
4119 /* Otherwise, do the same as above, but in a loop. Note that we must be
4120 extra careful with variables wrapping around because we might be at
4121 the very top (or the very bottom) of the address space and we have
4122 to be able to handle this case properly; in particular, we use an
4123 equality test for the loop condition. */
4126 HOST_WIDE_INT rounded_size;
4127 rtx g4 = gen_rtx_REG (Pmode, 4);
4129 emit_move_insn (g1, GEN_INT (first));
4132 /* Step 1: round SIZE to the previous multiple of the interval. */
4134 rounded_size = size & -PROBE_INTERVAL;
4135 emit_move_insn (g4, GEN_INT (rounded_size));
4138 /* Step 2: compute initial and final value of the loop counter. */
4140 /* TEST_ADDR = SP + FIRST. */
4141 emit_insn (gen_rtx_SET (VOIDmode, g1,
4142 gen_rtx_MINUS (Pmode, stack_pointer_rtx, g1)));
4144 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
4145 emit_insn (gen_rtx_SET (VOIDmode, g4, gen_rtx_MINUS (Pmode, g1, g4)));
4150 while (TEST_ADDR != LAST_ADDR)
4152 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
4156 probes at FIRST + N * PROBE_INTERVAL for values of N from 1
4157 until it is equal to ROUNDED_SIZE. */
4160 emit_insn (gen_probe_stack_rangedi (g1, g1, g4));
4162 emit_insn (gen_probe_stack_rangesi (g1, g1, g4));
4165 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
4166 that SIZE is equal to ROUNDED_SIZE. */
4168 if (size != rounded_size)
4169 emit_stack_probe (plus_constant (g4, rounded_size - size));
4172 /* Make sure nothing is scheduled before we are done. */
4173 emit_insn (gen_blockage ());
4176 /* Probe a range of stack addresses from REG1 to REG2 inclusive. These are
4177 absolute addresses. */
4180 output_probe_stack_range (rtx reg1, rtx reg2)
4182 static int labelno = 0;
4183 char loop_lab[32], end_lab[32];
4186 ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
4187 ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
4189 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
4191 /* Jump to END_LAB if TEST_ADDR == LAST_ADDR. */
4194 output_asm_insn ("cmp\t%0, %1", xops);
4196 fputs ("\tbe,pn\t%xcc,", asm_out_file);
4198 fputs ("\tbe\t", asm_out_file);
4199 assemble_name_raw (asm_out_file, end_lab);
4200 fputc ('\n', asm_out_file);
4202 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
4203 xops[1] = GEN_INT (-PROBE_INTERVAL);
4204 output_asm_insn (" add\t%0, %1, %0", xops);
4206 /* Probe at TEST_ADDR and branch. */
4208 fputs ("\tba,pt\t%xcc,", asm_out_file);
4210 fputs ("\tba\t", asm_out_file);
4211 assemble_name_raw (asm_out_file, loop_lab);
4212 fputc ('\n', asm_out_file);
4213 xops[1] = GEN_INT (SPARC_STACK_BIAS);
4214 output_asm_insn (" st\t%%g0, [%0+%1]", xops);
4216 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
4221 /* Save/restore call-saved registers from LOW to HIGH at BASE+OFFSET
4222 as needed. LOW should be double-word aligned for 32-bit registers.
4223 Return the new OFFSET. */
4226 #define SORR_RESTORE 1
4229 save_or_restore_regs (int low, int high, rtx base, int offset, int action)
4234 if (TARGET_ARCH64 && high <= 32)
4236 for (i = low; i < high; i++)
4238 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
4240 mem = gen_rtx_MEM (DImode, plus_constant (base, offset));
4241 set_mem_alias_set (mem, sparc_sr_alias_set);
4242 if (action == SORR_SAVE)
4244 insn = emit_move_insn (mem, gen_rtx_REG (DImode, i));
4245 RTX_FRAME_RELATED_P (insn) = 1;
4247 else /* action == SORR_RESTORE */
4248 emit_move_insn (gen_rtx_REG (DImode, i), mem);
4255 for (i = low; i < high; i += 2)
4257 bool reg0 = df_regs_ever_live_p (i) && ! call_used_regs[i];
4258 bool reg1 = df_regs_ever_live_p (i+1) && ! call_used_regs[i+1];
4259 enum machine_mode mode;
4264 mode = i < 32 ? DImode : DFmode;
4269 mode = i < 32 ? SImode : SFmode;
4274 mode = i < 32 ? SImode : SFmode;
4281 mem = gen_rtx_MEM (mode, plus_constant (base, offset));
4282 set_mem_alias_set (mem, sparc_sr_alias_set);
4283 if (action == SORR_SAVE)
4285 insn = emit_move_insn (mem, gen_rtx_REG (mode, regno));
4286 RTX_FRAME_RELATED_P (insn) = 1;
4288 else /* action == SORR_RESTORE */
4289 emit_move_insn (gen_rtx_REG (mode, regno), mem);
4291 /* Always preserve double-word alignment. */
4292 offset = (offset + 7) & -8;
4299 /* Emit code to save call-saved registers. */
4302 emit_save_or_restore_regs (int action)
4304 HOST_WIDE_INT offset;
4307 offset = frame_base_offset - apparent_fsize;
4309 if (offset < -4096 || offset + num_gfregs * 4 > 4095)
4311 /* ??? This might be optimized a little as %g1 might already have a
4312 value close enough that a single add insn will do. */
4313 /* ??? Although, all of this is probably only a temporary fix
4314 because if %g1 can hold a function result, then
4315 sparc_expand_epilogue will lose (the result will be
4317 base = gen_rtx_REG (Pmode, 1);
4318 emit_move_insn (base, GEN_INT (offset));
4319 emit_insn (gen_rtx_SET (VOIDmode,
4321 gen_rtx_PLUS (Pmode, frame_base_reg, base)));
4325 base = frame_base_reg;
4327 offset = save_or_restore_regs (0, 8, base, offset, action);
4328 save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, action);
4331 /* Generate a save_register_window insn. */
4334 gen_save_register_window (rtx increment)
4337 return gen_save_register_windowdi (increment);
4339 return gen_save_register_windowsi (increment);
4342 /* Generate an increment for the stack pointer. */
4345 gen_stack_pointer_inc (rtx increment)
4347 return gen_rtx_SET (VOIDmode,
4349 gen_rtx_PLUS (Pmode,
4354 /* Generate a decrement for the stack pointer. */
4357 gen_stack_pointer_dec (rtx decrement)
4359 return gen_rtx_SET (VOIDmode,
4361 gen_rtx_MINUS (Pmode,
4366 /* Expand the function prologue. The prologue is responsible for reserving
4367 storage for the frame, saving the call-saved registers and loading the
4368 PIC register if needed. */
4371 sparc_expand_prologue (void)
4376 /* Compute a snapshot of current_function_uses_only_leaf_regs. Relying
4377 on the final value of the flag means deferring the prologue/epilogue
4378 expansion until just before the second scheduling pass, which is too
4379 late to emit multiple epilogues or return insns.
4381 Of course we are making the assumption that the value of the flag
4382 will not change between now and its final value. Of the three parts
4383 of the formula, only the last one can reasonably vary. Let's take a
4384 closer look, after assuming that the first two ones are set to true
4385 (otherwise the last value is effectively silenced).
4387 If only_leaf_regs_used returns false, the global predicate will also
4388 be false so the actual frame size calculated below will be positive.
4389 As a consequence, the save_register_window insn will be emitted in
4390 the instruction stream; now this insn explicitly references %fp
4391 which is not a leaf register so only_leaf_regs_used will always
4392 return false subsequently.
4394 If only_leaf_regs_used returns true, we hope that the subsequent
4395 optimization passes won't cause non-leaf registers to pop up. For
4396 example, the regrename pass has special provisions to not rename to
4397 non-leaf registers in a leaf function. */
4398 sparc_leaf_function_p
4399 = optimize > 0 && leaf_function_p () && only_leaf_regs_used ();
4401 /* Need to use actual_fsize, since we are also allocating
4402 space for our callee (and our own register save area). */
4404 = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p);
4406 /* Advertise that the data calculated just above are now valid. */
4407 sparc_prologue_data_valid_p = true;
4409 if (flag_stack_usage)
4410 current_function_static_stack_size = actual_fsize;
4412 if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK && actual_fsize)
4413 sparc_emit_probe_stack_range (STACK_CHECK_PROTECT, actual_fsize);
4415 if (sparc_leaf_function_p)
4417 frame_base_reg = stack_pointer_rtx;
4418 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
4422 frame_base_reg = hard_frame_pointer_rtx;
4423 frame_base_offset = SPARC_STACK_BIAS;
4426 if (actual_fsize == 0)
4428 else if (sparc_leaf_function_p)
4430 if (actual_fsize <= 4096)
4431 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-actual_fsize)));
4432 else if (actual_fsize <= 8192)
4434 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-4096)));
4435 /* %sp is still the CFA register. */
4436 RTX_FRAME_RELATED_P (insn) = 1;
4438 = emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize)));
4442 rtx reg = gen_rtx_REG (Pmode, 1);
4443 emit_move_insn (reg, GEN_INT (-actual_fsize));
4444 insn = emit_insn (gen_stack_pointer_inc (reg));
4445 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
4446 gen_stack_pointer_inc (GEN_INT (-actual_fsize)));
4449 RTX_FRAME_RELATED_P (insn) = 1;
4453 if (actual_fsize <= 4096)
4454 insn = emit_insn (gen_save_register_window (GEN_INT (-actual_fsize)));
4455 else if (actual_fsize <= 8192)
4457 insn = emit_insn (gen_save_register_window (GEN_INT (-4096)));
4458 /* %sp is not the CFA register anymore. */
4459 emit_insn (gen_stack_pointer_inc (GEN_INT (4096-actual_fsize)));
4463 rtx reg = gen_rtx_REG (Pmode, 1);
4464 emit_move_insn (reg, GEN_INT (-actual_fsize));
4465 insn = emit_insn (gen_save_register_window (reg));
4468 RTX_FRAME_RELATED_P (insn) = 1;
4469 for (i=0; i < XVECLEN (PATTERN (insn), 0); i++)
4470 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, i)) = 1;
4474 emit_save_or_restore_regs (SORR_SAVE);
4476 /* Load the PIC register if needed. */
4477 if (flag_pic && crtl->uses_pic_offset_table)
4478 load_pic_register ();
4481 /* This function generates the assembly code for function entry, which boils
4482 down to emitting the necessary .register directives. */
4485 sparc_asm_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4487 /* Check that the assumption we made in sparc_expand_prologue is valid. */
4488 gcc_assert (sparc_leaf_function_p == current_function_uses_only_leaf_regs);
4490 sparc_output_scratch_registers (file);
4493 /* Expand the function epilogue, either normal or part of a sibcall.
4494 We emit all the instructions except the return or the call. */
4497 sparc_expand_epilogue (void)
4500 emit_save_or_restore_regs (SORR_RESTORE);
4502 if (actual_fsize == 0)
4504 else if (sparc_leaf_function_p)
4506 if (actual_fsize <= 4096)
4507 emit_insn (gen_stack_pointer_dec (GEN_INT (- actual_fsize)));
4508 else if (actual_fsize <= 8192)
4510 emit_insn (gen_stack_pointer_dec (GEN_INT (-4096)));
4511 emit_insn (gen_stack_pointer_dec (GEN_INT (4096 - actual_fsize)));
4515 rtx reg = gen_rtx_REG (Pmode, 1);
4516 emit_move_insn (reg, GEN_INT (-actual_fsize));
4517 emit_insn (gen_stack_pointer_dec (reg));
4522 /* Return true if it is appropriate to emit `return' instructions in the
4523 body of a function. */
4526 sparc_can_use_return_insn_p (void)
4528 return sparc_prologue_data_valid_p
4529 && (actual_fsize == 0 || !sparc_leaf_function_p);
4532 /* This function generates the assembly code for function exit. */
4535 sparc_asm_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4537 /* If the last two instructions of a function are "call foo; dslot;"
4538 the return address might point to the first instruction in the next
4539 function and we have to output a dummy nop for the sake of sane
4540 backtraces in such cases. This is pointless for sibling calls since
4541 the return address is explicitly adjusted. */
4543 rtx insn, last_real_insn;
4545 insn = get_last_insn ();
4547 last_real_insn = prev_real_insn (insn);
4549 && GET_CODE (last_real_insn) == INSN
4550 && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE)
4551 last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0);
4554 && CALL_P (last_real_insn)
4555 && !SIBLING_CALL_P (last_real_insn))
4556 fputs("\tnop\n", file);
4558 sparc_output_deferred_case_vectors ();
4561 /* Output a 'restore' instruction. */
4564 output_restore (rtx pat)
4570 fputs ("\t restore\n", asm_out_file);
4574 gcc_assert (GET_CODE (pat) == SET);
4576 operands[0] = SET_DEST (pat);
4577 pat = SET_SRC (pat);
4579 switch (GET_CODE (pat))
4582 operands[1] = XEXP (pat, 0);
4583 operands[2] = XEXP (pat, 1);
4584 output_asm_insn (" restore %r1, %2, %Y0", operands);
4587 operands[1] = XEXP (pat, 0);
4588 operands[2] = XEXP (pat, 1);
4589 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
4592 operands[1] = XEXP (pat, 0);
4593 gcc_assert (XEXP (pat, 1) == const1_rtx);
4594 output_asm_insn (" restore %r1, %r1, %Y0", operands);
4598 output_asm_insn (" restore %%g0, %1, %Y0", operands);
4603 /* Output a return. */
4606 output_return (rtx insn)
4608 if (sparc_leaf_function_p)
4610 /* This is a leaf function so we don't have to bother restoring the
4611 register window, which frees us from dealing with the convoluted
4612 semantics of restore/return. We simply output the jump to the
4613 return address and the insn in the delay slot (if any). */
4615 gcc_assert (! crtl->calls_eh_return);
4617 return "jmp\t%%o7+%)%#";
4621 /* This is a regular function so we have to restore the register window.
4622 We may have a pending insn for the delay slot, which will be either
4623 combined with the 'restore' instruction or put in the delay slot of
4624 the 'return' instruction. */
4626 if (crtl->calls_eh_return)
4628 /* If the function uses __builtin_eh_return, the eh_return
4629 machinery occupies the delay slot. */
4630 gcc_assert (! final_sequence);
4632 if (! flag_delayed_branch)
4633 fputs ("\tadd\t%fp, %g1, %fp\n", asm_out_file);
4636 fputs ("\treturn\t%i7+8\n", asm_out_file);
4638 fputs ("\trestore\n\tjmp\t%o7+8\n", asm_out_file);
4640 if (flag_delayed_branch)
4641 fputs ("\t add\t%sp, %g1, %sp\n", asm_out_file);
4643 fputs ("\t nop\n", asm_out_file);
4645 else if (final_sequence)
4649 delay = NEXT_INSN (insn);
4652 pat = PATTERN (delay);
4654 if (TARGET_V9 && ! epilogue_renumber (&pat, 1))
4656 epilogue_renumber (&pat, 0);
4657 return "return\t%%i7+%)%#";
4661 output_asm_insn ("jmp\t%%i7+%)", NULL);
4662 output_restore (pat);
4663 PATTERN (delay) = gen_blockage ();
4664 INSN_CODE (delay) = -1;
4669 /* The delay slot is empty. */
4671 return "return\t%%i7+%)\n\t nop";
4672 else if (flag_delayed_branch)
4673 return "jmp\t%%i7+%)\n\t restore";
4675 return "restore\n\tjmp\t%%o7+%)\n\t nop";
4682 /* Output a sibling call. */
4685 output_sibcall (rtx insn, rtx call_operand)
4689 gcc_assert (flag_delayed_branch);
4691 operands[0] = call_operand;
4693 if (sparc_leaf_function_p)
4695 /* This is a leaf function so we don't have to bother restoring the
4696 register window. We simply output the jump to the function and
4697 the insn in the delay slot (if any). */
4699 gcc_assert (!(LEAF_SIBCALL_SLOT_RESERVED_P && final_sequence));
4702 output_asm_insn ("sethi\t%%hi(%a0), %%g1\n\tjmp\t%%g1 + %%lo(%a0)%#",
4705 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
4706 it into branch if possible. */
4707 output_asm_insn ("or\t%%o7, %%g0, %%g1\n\tcall\t%a0, 0\n\t or\t%%g1, %%g0, %%o7",
4712 /* This is a regular function so we have to restore the register window.
4713 We may have a pending insn for the delay slot, which will be combined
4714 with the 'restore' instruction. */
4716 output_asm_insn ("call\t%a0, 0", operands);
4720 rtx delay = NEXT_INSN (insn);
4723 output_restore (PATTERN (delay));
4725 PATTERN (delay) = gen_blockage ();
4726 INSN_CODE (delay) = -1;
4729 output_restore (NULL_RTX);
4735 /* Functions for handling argument passing.
4737 For 32-bit, the first 6 args are normally in registers and the rest are
4738 pushed. Any arg that starts within the first 6 words is at least
4739 partially passed in a register unless its data type forbids.
4741 For 64-bit, the argument registers are laid out as an array of 16 elements
4742 and arguments are added sequentially. The first 6 int args and up to the
4743 first 16 fp args (depending on size) are passed in regs.
4745 Slot Stack Integral Float Float in structure Double Long Double
4746 ---- ----- -------- ----- ------------------ ------ -----------
4747 15 [SP+248] %f31 %f30,%f31 %d30
4748 14 [SP+240] %f29 %f28,%f29 %d28 %q28
4749 13 [SP+232] %f27 %f26,%f27 %d26
4750 12 [SP+224] %f25 %f24,%f25 %d24 %q24
4751 11 [SP+216] %f23 %f22,%f23 %d22
4752 10 [SP+208] %f21 %f20,%f21 %d20 %q20
4753 9 [SP+200] %f19 %f18,%f19 %d18
4754 8 [SP+192] %f17 %f16,%f17 %d16 %q16
4755 7 [SP+184] %f15 %f14,%f15 %d14
4756 6 [SP+176] %f13 %f12,%f13 %d12 %q12
4757 5 [SP+168] %o5 %f11 %f10,%f11 %d10
4758 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
4759 3 [SP+152] %o3 %f7 %f6,%f7 %d6
4760 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
4761 1 [SP+136] %o1 %f3 %f2,%f3 %d2
4762 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
4764 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
4766 Integral arguments are always passed as 64-bit quantities appropriately
4769 Passing of floating point values is handled as follows.
4770 If a prototype is in scope:
4771 If the value is in a named argument (i.e. not a stdarg function or a
4772 value not part of the `...') then the value is passed in the appropriate
4774 If the value is part of the `...' and is passed in one of the first 6
4775 slots then the value is passed in the appropriate int reg.
4776 If the value is part of the `...' and is not passed in one of the first 6
4777 slots then the value is passed in memory.
4778 If a prototype is not in scope:
4779 If the value is one of the first 6 arguments the value is passed in the
4780 appropriate integer reg and the appropriate fp reg.
4781 If the value is not one of the first 6 arguments the value is passed in
4782 the appropriate fp reg and in memory.
4785 Summary of the calling conventions implemented by GCC on the SPARC:
4788 size argument return value
4790 small integer <4 int. reg. int. reg.
4791 word 4 int. reg. int. reg.
4792 double word 8 int. reg. int. reg.
4794 _Complex small integer <8 int. reg. int. reg.
4795 _Complex word 8 int. reg. int. reg.
4796 _Complex double word 16 memory int. reg.
4798 vector integer <=8 int. reg. FP reg.
4799 vector integer >8 memory memory
4801 float 4 int. reg. FP reg.
4802 double 8 int. reg. FP reg.
4803 long double 16 memory memory
4805 _Complex float 8 memory FP reg.
4806 _Complex double 16 memory FP reg.
4807 _Complex long double 32 memory FP reg.
4809 vector float any memory memory
4811 aggregate any memory memory
4816 size argument return value
4818 small integer <8 int. reg. int. reg.
4819 word 8 int. reg. int. reg.
4820 double word 16 int. reg. int. reg.
4822 _Complex small integer <16 int. reg. int. reg.
4823 _Complex word 16 int. reg. int. reg.
4824 _Complex double word 32 memory int. reg.
4826 vector integer <=16 FP reg. FP reg.
4827 vector integer 16<s<=32 memory FP reg.
4828 vector integer >32 memory memory
4830 float 4 FP reg. FP reg.
4831 double 8 FP reg. FP reg.
4832 long double 16 FP reg. FP reg.
4834 _Complex float 8 FP reg. FP reg.
4835 _Complex double 16 FP reg. FP reg.
4836 _Complex long double 32 memory FP reg.
4838 vector float <=16 FP reg. FP reg.
4839 vector float 16<s<=32 memory FP reg.
4840 vector float >32 memory memory
4842 aggregate <=16 reg. reg.
4843 aggregate 16<s<=32 memory reg.
4844 aggregate >32 memory memory
4848 Note #1: complex floating-point types follow the extended SPARC ABIs as
4849 implemented by the Sun compiler.
4851 Note #2: integral vector types follow the scalar floating-point types
4852 conventions to match what is implemented by the Sun VIS SDK.
4854 Note #3: floating-point vector types follow the aggregate types
4858 /* Maximum number of int regs for args. */
4859 #define SPARC_INT_ARG_MAX 6
4860 /* Maximum number of fp regs for args. */
4861 #define SPARC_FP_ARG_MAX 16
4863 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
4865 /* Handle the INIT_CUMULATIVE_ARGS macro.
4866 Initialize a variable CUM of type CUMULATIVE_ARGS
4867 for a call to a function whose data type is FNTYPE.
4868 For a library call, FNTYPE is 0. */
4871 init_cumulative_args (struct sparc_args *cum, tree fntype,
4872 rtx libname ATTRIBUTE_UNUSED,
4873 tree fndecl ATTRIBUTE_UNUSED)
4876 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
4877 cum->libcall_p = fntype == 0;
4880 /* Handle the TARGET_PROMOTE_PROTOTYPES target hook.
4881 When a prototype says `char' or `short', really pass an `int'. */
4884 sparc_promote_prototypes (const_tree fntype ATTRIBUTE_UNUSED)
4886 return TARGET_ARCH32 ? true : false;
4889 /* Handle promotion of pointer and integer arguments. */
4891 static enum machine_mode
4892 sparc_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
4893 enum machine_mode mode,
4894 int *punsignedp ATTRIBUTE_UNUSED,
4895 const_tree fntype ATTRIBUTE_UNUSED,
4896 int for_return ATTRIBUTE_UNUSED)
4898 if (POINTER_TYPE_P (type))
4900 *punsignedp = POINTERS_EXTEND_UNSIGNED;
4904 /* For TARGET_ARCH64 we need this, as we don't have instructions
4905 for arithmetic operations which do zero/sign extension at the same time,
4906 so without this we end up with a srl/sra after every assignment to an
4907 user variable, which means very very bad code. */
4909 && GET_MODE_CLASS (mode) == MODE_INT
4910 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
4916 /* Handle the TARGET_STRICT_ARGUMENT_NAMING target hook. */
4919 sparc_strict_argument_naming (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED)
4921 return TARGET_ARCH64 ? true : false;
4924 /* Scan the record type TYPE and return the following predicates:
4925 - INTREGS_P: the record contains at least one field or sub-field
4926 that is eligible for promotion in integer registers.
4927 - FP_REGS_P: the record contains at least one field or sub-field
4928 that is eligible for promotion in floating-point registers.
4929 - PACKED_P: the record contains at least one field that is packed.
4931 Sub-fields are not taken into account for the PACKED_P predicate. */
4934 scan_record_type (tree type, int *intregs_p, int *fpregs_p, int *packed_p)
4938 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4940 if (TREE_CODE (field) == FIELD_DECL)
4942 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4943 scan_record_type (TREE_TYPE (field), intregs_p, fpregs_p, 0);
4944 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
4945 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
4951 if (packed_p && DECL_PACKED (field))
4957 /* Compute the slot number to pass an argument in.
4958 Return the slot number or -1 if passing on the stack.
4960 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4961 the preceding args and about the function being called.
4962 MODE is the argument's machine mode.
4963 TYPE is the data type of the argument (as a tree).
4964 This is null for libcalls where that information may
4966 NAMED is nonzero if this argument is a named parameter
4967 (otherwise it is an extra parameter matching an ellipsis).
4968 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
4969 *PREGNO records the register number to use if scalar type.
4970 *PPADDING records the amount of padding needed in words. */
4973 function_arg_slotno (const struct sparc_args *cum, enum machine_mode mode,
4974 tree type, int named, int incoming_p,
4975 int *pregno, int *ppadding)
4977 int regbase = (incoming_p
4978 ? SPARC_INCOMING_INT_ARG_FIRST
4979 : SPARC_OUTGOING_INT_ARG_FIRST);
4980 int slotno = cum->words;
4981 enum mode_class mclass;
4986 if (type && TREE_ADDRESSABLE (type))
4992 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
4995 /* For SPARC64, objects requiring 16-byte alignment get it. */
4997 && (type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode)) >= 128
4998 && (slotno & 1) != 0)
4999 slotno++, *ppadding = 1;
5001 mclass = GET_MODE_CLASS (mode);
5002 if (type && TREE_CODE (type) == VECTOR_TYPE)
5004 /* Vector types deserve special treatment because they are
5005 polymorphic wrt their mode, depending upon whether VIS
5006 instructions are enabled. */
5007 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
5009 /* The SPARC port defines no floating-point vector modes. */
5010 gcc_assert (mode == BLKmode);
5014 /* Integral vector types should either have a vector
5015 mode or an integral mode, because we are guaranteed
5016 by pass_by_reference that their size is not greater
5017 than 16 bytes and TImode is 16-byte wide. */
5018 gcc_assert (mode != BLKmode);
5020 /* Vector integers are handled like floats according to
5022 mclass = MODE_FLOAT;
5029 case MODE_COMPLEX_FLOAT:
5030 case MODE_VECTOR_INT:
5031 if (TARGET_ARCH64 && TARGET_FPU && named)
5033 if (slotno >= SPARC_FP_ARG_MAX)
5035 regno = SPARC_FP_ARG_FIRST + slotno * 2;
5036 /* Arguments filling only one single FP register are
5037 right-justified in the outer double FP register. */
5038 if (GET_MODE_SIZE (mode) <= 4)
5045 case MODE_COMPLEX_INT:
5046 if (slotno >= SPARC_INT_ARG_MAX)
5048 regno = regbase + slotno;
5052 if (mode == VOIDmode)
5053 /* MODE is VOIDmode when generating the actual call. */
5056 gcc_assert (mode == BLKmode);
5060 || (TREE_CODE (type) != VECTOR_TYPE
5061 && TREE_CODE (type) != RECORD_TYPE))
5063 if (slotno >= SPARC_INT_ARG_MAX)
5065 regno = regbase + slotno;
5067 else /* TARGET_ARCH64 && type */
5069 int intregs_p = 0, fpregs_p = 0, packed_p = 0;
5071 /* First see what kinds of registers we would need. */
5072 if (TREE_CODE (type) == VECTOR_TYPE)
5075 scan_record_type (type, &intregs_p, &fpregs_p, &packed_p);
5077 /* The ABI obviously doesn't specify how packed structures
5078 are passed. These are defined to be passed in int regs
5079 if possible, otherwise memory. */
5080 if (packed_p || !named)
5081 fpregs_p = 0, intregs_p = 1;
5083 /* If all arg slots are filled, then must pass on stack. */
5084 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
5087 /* If there are only int args and all int arg slots are filled,
5088 then must pass on stack. */
5089 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
5092 /* Note that even if all int arg slots are filled, fp members may
5093 still be passed in regs if such regs are available.
5094 *PREGNO isn't set because there may be more than one, it's up
5095 to the caller to compute them. */
5108 /* Handle recursive register counting for structure field layout. */
5110 struct function_arg_record_value_parms
5112 rtx ret; /* return expression being built. */
5113 int slotno; /* slot number of the argument. */
5114 int named; /* whether the argument is named. */
5115 int regbase; /* regno of the base register. */
5116 int stack; /* 1 if part of the argument is on the stack. */
5117 int intoffset; /* offset of the first pending integer field. */
5118 unsigned int nregs; /* number of words passed in registers. */
5121 static void function_arg_record_value_3
5122 (HOST_WIDE_INT, struct function_arg_record_value_parms *);
5123 static void function_arg_record_value_2
5124 (const_tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
5125 static void function_arg_record_value_1
5126 (const_tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
5127 static rtx function_arg_record_value (const_tree, enum machine_mode, int, int, int);
5128 static rtx function_arg_union_value (int, enum machine_mode, int, int);
5130 /* A subroutine of function_arg_record_value. Traverse the structure
5131 recursively and determine how many registers will be required. */
5134 function_arg_record_value_1 (const_tree type, HOST_WIDE_INT startbitpos,
5135 struct function_arg_record_value_parms *parms,
5140 /* We need to compute how many registers are needed so we can
5141 allocate the PARALLEL but before we can do that we need to know
5142 whether there are any packed fields. The ABI obviously doesn't
5143 specify how structures are passed in this case, so they are
5144 defined to be passed in int regs if possible, otherwise memory,
5145 regardless of whether there are fp values present. */
5148 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5150 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
5157 /* Compute how many registers we need. */
5158 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
5160 if (TREE_CODE (field) == FIELD_DECL)
5162 HOST_WIDE_INT bitpos = startbitpos;
5164 if (DECL_SIZE (field) != 0)
5166 if (integer_zerop (DECL_SIZE (field)))
5169 if (host_integerp (bit_position (field), 1))
5170 bitpos += int_bit_position (field);
5173 /* ??? FIXME: else assume zero offset. */
5175 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
5176 function_arg_record_value_1 (TREE_TYPE (field),
5180 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
5181 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
5186 if (parms->intoffset != -1)
5188 unsigned int startbit, endbit;
5189 int intslots, this_slotno;
5191 startbit = parms->intoffset & -BITS_PER_WORD;
5192 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
5194 intslots = (endbit - startbit) / BITS_PER_WORD;
5195 this_slotno = parms->slotno + parms->intoffset
5198 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
5200 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
5201 /* We need to pass this field on the stack. */
5205 parms->nregs += intslots;
5206 parms->intoffset = -1;
5209 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
5210 If it wasn't true we wouldn't be here. */
5211 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
5212 && DECL_MODE (field) == BLKmode)
5213 parms->nregs += TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
5214 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
5221 if (parms->intoffset == -1)
5222 parms->intoffset = bitpos;
5228 /* A subroutine of function_arg_record_value. Assign the bits of the
5229 structure between parms->intoffset and bitpos to integer registers. */
5232 function_arg_record_value_3 (HOST_WIDE_INT bitpos,
5233 struct function_arg_record_value_parms *parms)
5235 enum machine_mode mode;
5237 unsigned int startbit, endbit;
5238 int this_slotno, intslots, intoffset;
5241 if (parms->intoffset == -1)
5244 intoffset = parms->intoffset;
5245 parms->intoffset = -1;
5247 startbit = intoffset & -BITS_PER_WORD;
5248 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
5249 intslots = (endbit - startbit) / BITS_PER_WORD;
5250 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
5252 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
5256 /* If this is the trailing part of a word, only load that much into
5257 the register. Otherwise load the whole register. Note that in
5258 the latter case we may pick up unwanted bits. It's not a problem
5259 at the moment but may wish to revisit. */
5261 if (intoffset % BITS_PER_WORD != 0)
5262 mode = smallest_mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
5267 intoffset /= BITS_PER_UNIT;
5270 regno = parms->regbase + this_slotno;
5271 reg = gen_rtx_REG (mode, regno);
5272 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
5273 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
5276 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
5281 while (intslots > 0);
5284 /* A subroutine of function_arg_record_value. Traverse the structure
5285 recursively and assign bits to floating point registers. Track which
5286 bits in between need integer registers; invoke function_arg_record_value_3
5287 to make that happen. */
5290 function_arg_record_value_2 (const_tree type, HOST_WIDE_INT startbitpos,
5291 struct function_arg_record_value_parms *parms,
5297 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
5299 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
5306 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
5308 if (TREE_CODE (field) == FIELD_DECL)
5310 HOST_WIDE_INT bitpos = startbitpos;
5312 if (DECL_SIZE (field) != 0)
5314 if (integer_zerop (DECL_SIZE (field)))
5317 if (host_integerp (bit_position (field), 1))
5318 bitpos += int_bit_position (field);
5321 /* ??? FIXME: else assume zero offset. */
5323 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
5324 function_arg_record_value_2 (TREE_TYPE (field),
5328 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
5329 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
5334 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
5335 int regno, nregs, pos;
5336 enum machine_mode mode = DECL_MODE (field);
5339 function_arg_record_value_3 (bitpos, parms);
5341 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
5344 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
5345 nregs = TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
5347 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
5349 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
5355 regno = SPARC_FP_ARG_FIRST + this_slotno * 2;
5356 if (GET_MODE_SIZE (mode) <= 4 && (bitpos & 32) != 0)
5358 reg = gen_rtx_REG (mode, regno);
5359 pos = bitpos / BITS_PER_UNIT;
5360 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
5361 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
5365 regno += GET_MODE_SIZE (mode) / 4;
5366 reg = gen_rtx_REG (mode, regno);
5367 pos += GET_MODE_SIZE (mode);
5368 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
5369 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
5375 if (parms->intoffset == -1)
5376 parms->intoffset = bitpos;
5382 /* Used by function_arg and sparc_function_value_1 to implement the complex
5383 conventions of the 64-bit ABI for passing and returning structures.
5384 Return an expression valid as a return value for the FUNCTION_ARG
5385 and TARGET_FUNCTION_VALUE.
5387 TYPE is the data type of the argument (as a tree).
5388 This is null for libcalls where that information may
5390 MODE is the argument's machine mode.
5391 SLOTNO is the index number of the argument's slot in the parameter array.
5392 NAMED is nonzero if this argument is a named parameter
5393 (otherwise it is an extra parameter matching an ellipsis).
5394 REGBASE is the regno of the base register for the parameter array. */
5397 function_arg_record_value (const_tree type, enum machine_mode mode,
5398 int slotno, int named, int regbase)
5400 HOST_WIDE_INT typesize = int_size_in_bytes (type);
5401 struct function_arg_record_value_parms parms;
5404 parms.ret = NULL_RTX;
5405 parms.slotno = slotno;
5406 parms.named = named;
5407 parms.regbase = regbase;
5410 /* Compute how many registers we need. */
5412 parms.intoffset = 0;
5413 function_arg_record_value_1 (type, 0, &parms, false);
5415 /* Take into account pending integer fields. */
5416 if (parms.intoffset != -1)
5418 unsigned int startbit, endbit;
5419 int intslots, this_slotno;
5421 startbit = parms.intoffset & -BITS_PER_WORD;
5422 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
5423 intslots = (endbit - startbit) / BITS_PER_WORD;
5424 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
5426 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
5428 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
5429 /* We need to pass this field on the stack. */
5433 parms.nregs += intslots;
5435 nregs = parms.nregs;
5437 /* Allocate the vector and handle some annoying special cases. */
5440 /* ??? Empty structure has no value? Duh? */
5443 /* Though there's nothing really to store, return a word register
5444 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
5445 leads to breakage due to the fact that there are zero bytes to
5447 return gen_rtx_REG (mode, regbase);
5451 /* ??? C++ has structures with no fields, and yet a size. Give up
5452 for now and pass everything back in integer registers. */
5453 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5455 if (nregs + slotno > SPARC_INT_ARG_MAX)
5456 nregs = SPARC_INT_ARG_MAX - slotno;
5458 gcc_assert (nregs != 0);
5460 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (parms.stack + nregs));
5462 /* If at least one field must be passed on the stack, generate
5463 (parallel [(expr_list (nil) ...) ...]) so that all fields will
5464 also be passed on the stack. We can't do much better because the
5465 semantics of TARGET_ARG_PARTIAL_BYTES doesn't handle the case
5466 of structures for which the fields passed exclusively in registers
5467 are not at the beginning of the structure. */
5469 XVECEXP (parms.ret, 0, 0)
5470 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
5472 /* Fill in the entries. */
5474 parms.intoffset = 0;
5475 function_arg_record_value_2 (type, 0, &parms, false);
5476 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
5478 gcc_assert (parms.nregs == nregs);
5483 /* Used by function_arg and sparc_function_value_1 to implement the conventions
5484 of the 64-bit ABI for passing and returning unions.
5485 Return an expression valid as a return value for the FUNCTION_ARG
5486 and TARGET_FUNCTION_VALUE.
5488 SIZE is the size in bytes of the union.
5489 MODE is the argument's machine mode.
5490 REGNO is the hard register the union will be passed in. */
5493 function_arg_union_value (int size, enum machine_mode mode, int slotno,
5496 int nwords = ROUND_ADVANCE (size), i;
5499 /* See comment in previous function for empty structures. */
5501 return gen_rtx_REG (mode, regno);
5503 if (slotno == SPARC_INT_ARG_MAX - 1)
5506 regs = gen_rtx_PARALLEL (mode, rtvec_alloc (nwords));
5508 for (i = 0; i < nwords; i++)
5510 /* Unions are passed left-justified. */
5511 XVECEXP (regs, 0, i)
5512 = gen_rtx_EXPR_LIST (VOIDmode,
5513 gen_rtx_REG (word_mode, regno),
5514 GEN_INT (UNITS_PER_WORD * i));
5521 /* Used by function_arg and sparc_function_value_1 to implement the conventions
5522 for passing and returning large (BLKmode) vectors.
5523 Return an expression valid as a return value for the FUNCTION_ARG
5524 and TARGET_FUNCTION_VALUE.
5526 SIZE is the size in bytes of the vector (at least 8 bytes).
5527 REGNO is the FP hard register the vector will be passed in. */
5530 function_arg_vector_value (int size, int regno)
5532 int i, nregs = size / 8;
5535 regs = gen_rtx_PARALLEL (BLKmode, rtvec_alloc (nregs));
5537 for (i = 0; i < nregs; i++)
5539 XVECEXP (regs, 0, i)
5540 = gen_rtx_EXPR_LIST (VOIDmode,
5541 gen_rtx_REG (DImode, regno + 2*i),
5548 /* Handle the FUNCTION_ARG macro.
5549 Determine where to put an argument to a function.
5550 Value is zero to push the argument on the stack,
5551 or a hard register in which to store the argument.
5553 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5554 the preceding args and about the function being called.
5555 MODE is the argument's machine mode.
5556 TYPE is the data type of the argument (as a tree).
5557 This is null for libcalls where that information may
5559 NAMED is nonzero if this argument is a named parameter
5560 (otherwise it is an extra parameter matching an ellipsis).
5561 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
5564 function_arg (const struct sparc_args *cum, enum machine_mode mode,
5565 tree type, int named, int incoming_p)
5567 int regbase = (incoming_p
5568 ? SPARC_INCOMING_INT_ARG_FIRST
5569 : SPARC_OUTGOING_INT_ARG_FIRST);
5570 int slotno, regno, padding;
5571 enum mode_class mclass = GET_MODE_CLASS (mode);
5573 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
5578 /* Vector types deserve special treatment because they are polymorphic wrt
5579 their mode, depending upon whether VIS instructions are enabled. */
5580 if (type && TREE_CODE (type) == VECTOR_TYPE)
5582 HOST_WIDE_INT size = int_size_in_bytes (type);
5583 gcc_assert ((TARGET_ARCH32 && size <= 8)
5584 || (TARGET_ARCH64 && size <= 16));
5586 if (mode == BLKmode)
5587 return function_arg_vector_value (size,
5588 SPARC_FP_ARG_FIRST + 2*slotno);
5590 mclass = MODE_FLOAT;
5594 return gen_rtx_REG (mode, regno);
5596 /* Structures up to 16 bytes in size are passed in arg slots on the stack
5597 and are promoted to registers if possible. */
5598 if (type && TREE_CODE (type) == RECORD_TYPE)
5600 HOST_WIDE_INT size = int_size_in_bytes (type);
5601 gcc_assert (size <= 16);
5603 return function_arg_record_value (type, mode, slotno, named, regbase);
5606 /* Unions up to 16 bytes in size are passed in integer registers. */
5607 else if (type && TREE_CODE (type) == UNION_TYPE)
5609 HOST_WIDE_INT size = int_size_in_bytes (type);
5610 gcc_assert (size <= 16);
5612 return function_arg_union_value (size, mode, slotno, regno);
5615 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
5616 but also have the slot allocated for them.
5617 If no prototype is in scope fp values in register slots get passed
5618 in two places, either fp regs and int regs or fp regs and memory. */
5619 else if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
5620 && SPARC_FP_REG_P (regno))
5622 rtx reg = gen_rtx_REG (mode, regno);
5623 if (cum->prototype_p || cum->libcall_p)
5625 /* "* 2" because fp reg numbers are recorded in 4 byte
5628 /* ??? This will cause the value to be passed in the fp reg and
5629 in the stack. When a prototype exists we want to pass the
5630 value in the reg but reserve space on the stack. That's an
5631 optimization, and is deferred [for a bit]. */
5632 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
5633 return gen_rtx_PARALLEL (mode,
5635 gen_rtx_EXPR_LIST (VOIDmode,
5636 NULL_RTX, const0_rtx),
5637 gen_rtx_EXPR_LIST (VOIDmode,
5641 /* ??? It seems that passing back a register even when past
5642 the area declared by REG_PARM_STACK_SPACE will allocate
5643 space appropriately, and will not copy the data onto the
5644 stack, exactly as we desire.
5646 This is due to locate_and_pad_parm being called in
5647 expand_call whenever reg_parm_stack_space > 0, which
5648 while beneficial to our example here, would seem to be
5649 in error from what had been intended. Ho hum... -- r~ */
5657 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
5661 /* On incoming, we don't need to know that the value
5662 is passed in %f0 and %i0, and it confuses other parts
5663 causing needless spillage even on the simplest cases. */
5667 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
5668 + (regno - SPARC_FP_ARG_FIRST) / 2);
5670 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5671 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
5673 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5677 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
5678 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5679 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5684 /* All other aggregate types are passed in an integer register in a mode
5685 corresponding to the size of the type. */
5686 else if (type && AGGREGATE_TYPE_P (type))
5688 HOST_WIDE_INT size = int_size_in_bytes (type);
5689 gcc_assert (size <= 16);
5691 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
5694 return gen_rtx_REG (mode, regno);
5697 /* For an arg passed partly in registers and partly in memory,
5698 this is the number of bytes of registers used.
5699 For args passed entirely in registers or entirely in memory, zero.
5701 Any arg that starts in the first 6 regs but won't entirely fit in them
5702 needs partial registers on v8. On v9, structures with integer
5703 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
5704 values that begin in the last fp reg [where "last fp reg" varies with the
5705 mode] will be split between that reg and memory. */
5708 sparc_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5709 tree type, bool named)
5711 int slotno, regno, padding;
5713 /* We pass 0 for incoming_p here, it doesn't matter. */
5714 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5721 if ((slotno + (mode == BLKmode
5722 ? ROUND_ADVANCE (int_size_in_bytes (type))
5723 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
5724 > SPARC_INT_ARG_MAX)
5725 return (SPARC_INT_ARG_MAX - slotno) * UNITS_PER_WORD;
5729 /* We are guaranteed by pass_by_reference that the size of the
5730 argument is not greater than 16 bytes, so we only need to return
5731 one word if the argument is partially passed in registers. */
5733 if (type && AGGREGATE_TYPE_P (type))
5735 int size = int_size_in_bytes (type);
5737 if (size > UNITS_PER_WORD
5738 && slotno == SPARC_INT_ARG_MAX - 1)
5739 return UNITS_PER_WORD;
5741 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
5742 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5743 && ! (TARGET_FPU && named)))
5745 /* The complex types are passed as packed types. */
5746 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
5747 && slotno == SPARC_INT_ARG_MAX - 1)
5748 return UNITS_PER_WORD;
5750 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
5752 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
5754 return UNITS_PER_WORD;
5761 /* Handle the TARGET_PASS_BY_REFERENCE target hook.
5762 Specify whether to pass the argument by reference. */
5765 sparc_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5766 enum machine_mode mode, const_tree type,
5767 bool named ATTRIBUTE_UNUSED)
5770 /* Original SPARC 32-bit ABI says that structures and unions,
5771 and quad-precision floats are passed by reference. For Pascal,
5772 also pass arrays by reference. All other base types are passed
5775 Extended ABI (as implemented by the Sun compiler) says that all
5776 complex floats are passed by reference. Pass complex integers
5777 in registers up to 8 bytes. More generally, enforce the 2-word
5778 cap for passing arguments in registers.
5780 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5781 integers are passed like floats of the same size, that is in
5782 registers up to 8 bytes. Pass all vector floats by reference
5783 like structure and unions. */
5784 return ((type && (AGGREGATE_TYPE_P (type) || VECTOR_FLOAT_TYPE_P (type)))
5786 /* Catch CDImode, TFmode, DCmode and TCmode. */
5787 || GET_MODE_SIZE (mode) > 8
5789 && TREE_CODE (type) == VECTOR_TYPE
5790 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
5792 /* Original SPARC 64-bit ABI says that structures and unions
5793 smaller than 16 bytes are passed in registers, as well as
5794 all other base types.
5796 Extended ABI (as implemented by the Sun compiler) says that
5797 complex floats are passed in registers up to 16 bytes. Pass
5798 all complex integers in registers up to 16 bytes. More generally,
5799 enforce the 2-word cap for passing arguments in registers.
5801 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5802 integers are passed like floats of the same size, that is in
5803 registers (up to 16 bytes). Pass all vector floats like structure
5806 && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == VECTOR_TYPE)
5807 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16)
5808 /* Catch CTImode and TCmode. */
5809 || GET_MODE_SIZE (mode) > 16);
5812 /* Handle the FUNCTION_ARG_ADVANCE macro.
5813 Update the data in CUM to advance over an argument
5814 of mode MODE and data type TYPE.
5815 TYPE is null for libcalls where that information may not be available. */
5818 function_arg_advance (struct sparc_args *cum, enum machine_mode mode,
5819 tree type, int named)
5823 /* We pass 0 for incoming_p here, it doesn't matter. */
5824 function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5826 /* If argument requires leading padding, add it. */
5827 cum->words += padding;
5831 cum->words += (mode != BLKmode
5832 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5833 : ROUND_ADVANCE (int_size_in_bytes (type)));
5837 if (type && AGGREGATE_TYPE_P (type))
5839 int size = int_size_in_bytes (type);
5843 else if (size <= 16)
5845 else /* passed by reference */
5850 cum->words += (mode != BLKmode
5851 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5852 : ROUND_ADVANCE (int_size_in_bytes (type)));
5857 /* Handle the FUNCTION_ARG_PADDING macro.
5858 For the 64 bit ABI structs are always stored left shifted in their
5862 function_arg_padding (enum machine_mode mode, const_tree type)
5864 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
5867 /* Fall back to the default. */
5868 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
5871 /* Handle the TARGET_RETURN_IN_MEMORY target hook.
5872 Specify whether to return the return value in memory. */
5875 sparc_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
5878 /* Original SPARC 32-bit ABI says that structures and unions,
5879 and quad-precision floats are returned in memory. All other
5880 base types are returned in registers.
5882 Extended ABI (as implemented by the Sun compiler) says that
5883 all complex floats are returned in registers (8 FP registers
5884 at most for '_Complex long double'). Return all complex integers
5885 in registers (4 at most for '_Complex long long').
5887 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5888 integers are returned like floats of the same size, that is in
5889 registers up to 8 bytes and in memory otherwise. Return all
5890 vector floats in memory like structure and unions; note that
5891 they always have BLKmode like the latter. */
5892 return (TYPE_MODE (type) == BLKmode
5893 || TYPE_MODE (type) == TFmode
5894 || (TREE_CODE (type) == VECTOR_TYPE
5895 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
5897 /* Original SPARC 64-bit ABI says that structures and unions
5898 smaller than 32 bytes are returned in registers, as well as
5899 all other base types.
5901 Extended ABI (as implemented by the Sun compiler) says that all
5902 complex floats are returned in registers (8 FP registers at most
5903 for '_Complex long double'). Return all complex integers in
5904 registers (4 at most for '_Complex TItype').
5906 Vector ABI (as implemented by the Sun VIS SDK) says that vector
5907 integers are returned like floats of the same size, that is in
5908 registers. Return all vector floats like structure and unions;
5909 note that they always have BLKmode like the latter. */
5910 return ((TYPE_MODE (type) == BLKmode
5911 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 32));
5914 /* Handle the TARGET_STRUCT_VALUE target hook.
5915 Return where to find the structure return value address. */
5918 sparc_struct_value_rtx (tree fndecl, int incoming)
5927 mem = gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx,
5928 STRUCT_VALUE_OFFSET));
5930 mem = gen_rtx_MEM (Pmode, plus_constant (stack_pointer_rtx,
5931 STRUCT_VALUE_OFFSET));
5933 /* Only follow the SPARC ABI for fixed-size structure returns.
5934 Variable size structure returns are handled per the normal
5935 procedures in GCC. This is enabled by -mstd-struct-return */
5937 && sparc_std_struct_return
5938 && TYPE_SIZE_UNIT (TREE_TYPE (fndecl))
5939 && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (fndecl))) == INTEGER_CST)
5941 /* We must check and adjust the return address, as it is
5942 optional as to whether the return object is really
5944 rtx ret_rtx = gen_rtx_REG (Pmode, 31);
5945 rtx scratch = gen_reg_rtx (SImode);
5946 rtx endlab = gen_label_rtx ();
5948 /* Calculate the return object size */
5949 tree size = TYPE_SIZE_UNIT (TREE_TYPE (fndecl));
5950 rtx size_rtx = GEN_INT (TREE_INT_CST_LOW (size) & 0xfff);
5951 /* Construct a temporary return value */
5952 rtx temp_val = assign_stack_local (Pmode, TREE_INT_CST_LOW (size), 0);
5954 /* Implement SPARC 32-bit psABI callee returns struck checking
5957 Fetch the instruction where we will return to and see if
5958 it's an unimp instruction (the most significant 10 bits
5960 emit_move_insn (scratch, gen_rtx_MEM (SImode,
5961 plus_constant (ret_rtx, 8)));
5962 /* Assume the size is valid and pre-adjust */
5963 emit_insn (gen_add3_insn (ret_rtx, ret_rtx, GEN_INT (4)));
5964 emit_cmp_and_jump_insns (scratch, size_rtx, EQ, const0_rtx, SImode, 0, endlab);
5965 emit_insn (gen_sub3_insn (ret_rtx, ret_rtx, GEN_INT (4)));
5966 /* Assign stack temp:
5967 Write the address of the memory pointed to by temp_val into
5968 the memory pointed to by mem */
5969 emit_move_insn (mem, XEXP (temp_val, 0));
5970 emit_label (endlab);
5973 set_mem_alias_set (mem, struct_value_alias_set);
5978 /* Handle TARGET_FUNCTION_VALUE, and TARGET_LIBCALL_VALUE target hook.
5979 For v9, function return values are subject to the same rules as arguments,
5980 except that up to 32 bytes may be returned in registers. */
5983 sparc_function_value_1 (const_tree type, enum machine_mode mode,
5986 /* Beware that the two values are swapped here wrt function_arg. */
5987 int regbase = (outgoing
5988 ? SPARC_INCOMING_INT_ARG_FIRST
5989 : SPARC_OUTGOING_INT_ARG_FIRST);
5990 enum mode_class mclass = GET_MODE_CLASS (mode);
5993 /* Vector types deserve special treatment because they are polymorphic wrt
5994 their mode, depending upon whether VIS instructions are enabled. */
5995 if (type && TREE_CODE (type) == VECTOR_TYPE)
5997 HOST_WIDE_INT size = int_size_in_bytes (type);
5998 gcc_assert ((TARGET_ARCH32 && size <= 8)
5999 || (TARGET_ARCH64 && size <= 32));
6001 if (mode == BLKmode)
6002 return function_arg_vector_value (size,
6003 SPARC_FP_ARG_FIRST);
6005 mclass = MODE_FLOAT;
6008 if (TARGET_ARCH64 && type)
6010 /* Structures up to 32 bytes in size are returned in registers. */
6011 if (TREE_CODE (type) == RECORD_TYPE)
6013 HOST_WIDE_INT size = int_size_in_bytes (type);
6014 gcc_assert (size <= 32);
6016 return function_arg_record_value (type, mode, 0, 1, regbase);
6019 /* Unions up to 32 bytes in size are returned in integer registers. */
6020 else if (TREE_CODE (type) == UNION_TYPE)
6022 HOST_WIDE_INT size = int_size_in_bytes (type);
6023 gcc_assert (size <= 32);
6025 return function_arg_union_value (size, mode, 0, regbase);
6028 /* Objects that require it are returned in FP registers. */
6029 else if (mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
6032 /* All other aggregate types are returned in an integer register in a
6033 mode corresponding to the size of the type. */
6034 else if (AGGREGATE_TYPE_P (type))
6036 /* All other aggregate types are passed in an integer register
6037 in a mode corresponding to the size of the type. */
6038 HOST_WIDE_INT size = int_size_in_bytes (type);
6039 gcc_assert (size <= 32);
6041 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
6043 /* ??? We probably should have made the same ABI change in
6044 3.4.0 as the one we made for unions. The latter was
6045 required by the SCD though, while the former is not
6046 specified, so we favored compatibility and efficiency.
6048 Now we're stuck for aggregates larger than 16 bytes,
6049 because OImode vanished in the meantime. Let's not
6050 try to be unduly clever, and simply follow the ABI
6051 for unions in that case. */
6052 if (mode == BLKmode)
6053 return function_arg_union_value (size, mode, 0, regbase);
6058 /* This must match sparc_promote_function_mode.
6059 ??? Maybe 32-bit pointers should actually remain in Pmode? */
6060 else if (mclass == MODE_INT && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
6064 if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT) && TARGET_FPU)
6065 regno = SPARC_FP_ARG_FIRST;
6069 return gen_rtx_REG (mode, regno);
6072 /* Handle TARGET_FUNCTION_VALUE.
6074 On SPARC the value is found in the first "output" register, but the called
6075 function leaves it in the first "input" register. */
6078 sparc_function_value (const_tree valtype,
6079 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
6082 return sparc_function_value_1 (valtype, TYPE_MODE (valtype), outgoing);
6085 /* Handle TARGET_LIBCALL_VALUE. */
6088 sparc_libcall_value (enum machine_mode mode,
6089 const_rtx fun ATTRIBUTE_UNUSED)
6091 return sparc_function_value_1 (NULL_TREE, mode, false);
6094 /* Handle FUNCTION_VALUE_REGNO_P.
6095 On SPARC, the first "output" reg is used for integer values, and
6096 the first floating point register is used for floating point values. */
6099 sparc_function_value_regno_p (const unsigned int regno)
6101 return (regno == 8 || regno == 32);
6104 /* Do what is necessary for `va_start'. We look at the current function
6105 to determine if stdarg or varargs is used and return the address of
6106 the first unnamed parameter. */
6109 sparc_builtin_saveregs (void)
6111 int first_reg = crtl->args.info.words;
6115 for (regno = first_reg; regno < SPARC_INT_ARG_MAX; regno++)
6116 emit_move_insn (gen_rtx_MEM (word_mode,
6117 gen_rtx_PLUS (Pmode,
6119 GEN_INT (FIRST_PARM_OFFSET (0)
6122 gen_rtx_REG (word_mode,
6123 SPARC_INCOMING_INT_ARG_FIRST + regno));
6125 address = gen_rtx_PLUS (Pmode,
6127 GEN_INT (FIRST_PARM_OFFSET (0)
6128 + UNITS_PER_WORD * first_reg));
6133 /* Implement `va_start' for stdarg. */
6136 sparc_va_start (tree valist, rtx nextarg)
6138 nextarg = expand_builtin_saveregs ();
6139 std_expand_builtin_va_start (valist, nextarg);
6142 /* Implement `va_arg' for stdarg. */
6145 sparc_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
6148 HOST_WIDE_INT size, rsize, align;
6151 tree ptrtype = build_pointer_type (type);
6153 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
6156 size = rsize = UNITS_PER_WORD;
6162 size = int_size_in_bytes (type);
6163 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
6168 /* For SPARC64, objects requiring 16-byte alignment get it. */
6169 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
6170 align = 2 * UNITS_PER_WORD;
6172 /* SPARC-V9 ABI states that structures up to 16 bytes in size
6173 are left-justified in their slots. */
6174 if (AGGREGATE_TYPE_P (type))
6177 size = rsize = UNITS_PER_WORD;
6187 incr = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node, incr,
6188 size_int (align - 1));
6189 incr = fold_convert (sizetype, incr);
6190 incr = fold_build2 (BIT_AND_EXPR, sizetype, incr,
6192 incr = fold_convert (ptr_type_node, incr);
6195 gimplify_expr (&incr, pre_p, post_p, is_gimple_val, fb_rvalue);
6198 if (BYTES_BIG_ENDIAN && size < rsize)
6199 addr = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node, incr,
6200 size_int (rsize - size));
6204 addr = fold_convert (build_pointer_type (ptrtype), addr);
6205 addr = build_va_arg_indirect_ref (addr);
6208 /* If the address isn't aligned properly for the type, we need a temporary.
6209 FIXME: This is inefficient, usually we can do this in registers. */
6210 else if (align == 0 && TYPE_ALIGN (type) > BITS_PER_WORD)
6212 tree tmp = create_tmp_var (type, "va_arg_tmp");
6213 tree dest_addr = build_fold_addr_expr (tmp);
6214 tree copy = build_call_expr (implicit_built_in_decls[BUILT_IN_MEMCPY],
6215 3, dest_addr, addr, size_int (rsize));
6216 TREE_ADDRESSABLE (tmp) = 1;
6217 gimplify_and_add (copy, pre_p);
6222 addr = fold_convert (ptrtype, addr);
6225 = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node, incr, size_int (rsize));
6226 gimplify_assign (valist, incr, post_p);
6228 return build_va_arg_indirect_ref (addr);
6231 /* Implement the TARGET_VECTOR_MODE_SUPPORTED_P target hook.
6232 Specify whether the vector mode is supported by the hardware. */
6235 sparc_vector_mode_supported_p (enum machine_mode mode)
6237 return TARGET_VIS && VECTOR_MODE_P (mode) ? true : false;
6240 /* Implement the TARGET_VECTORIZE_UNITS_PER_SIMD_WORD target hook. */
6243 sparc_units_per_simd_word (enum machine_mode mode ATTRIBUTE_UNUSED)
6245 return TARGET_VIS ? 8 : UNITS_PER_WORD;
6248 /* Return the string to output an unconditional branch to LABEL, which is
6249 the operand number of the label.
6251 DEST is the destination insn (i.e. the label), INSN is the source. */
6254 output_ubranch (rtx dest, int label, rtx insn)
6256 static char string[64];
6257 bool v9_form = false;
6260 if (TARGET_V9 && INSN_ADDRESSES_SET_P ())
6262 int delta = (INSN_ADDRESSES (INSN_UID (dest))
6263 - INSN_ADDRESSES (INSN_UID (insn)));
6264 /* Leave some instructions for "slop". */
6265 if (delta >= -260000 && delta < 260000)
6270 strcpy (string, "ba%*,pt\t%%xcc, ");
6272 strcpy (string, "b%*\t");
6274 p = strchr (string, '\0');
6285 /* Return the string to output a conditional branch to LABEL, which is
6286 the operand number of the label. OP is the conditional expression.
6287 XEXP (OP, 0) is assumed to be a condition code register (integer or
6288 floating point) and its mode specifies what kind of comparison we made.
6290 DEST is the destination insn (i.e. the label), INSN is the source.
6292 REVERSED is nonzero if we should reverse the sense of the comparison.
6294 ANNUL is nonzero if we should generate an annulling branch. */
6297 output_cbranch (rtx op, rtx dest, int label, int reversed, int annul,
6300 static char string[64];
6301 enum rtx_code code = GET_CODE (op);
6302 rtx cc_reg = XEXP (op, 0);
6303 enum machine_mode mode = GET_MODE (cc_reg);
6304 const char *labelno, *branch;
6305 int spaces = 8, far;
6308 /* v9 branches are limited to +-1MB. If it is too far away,
6321 fbne,a,pn %fcc2, .LC29
6329 far = TARGET_V9 && (get_attr_length (insn) >= 3);
6332 /* Reversal of FP compares takes care -- an ordered compare
6333 becomes an unordered compare and vice versa. */
6334 if (mode == CCFPmode || mode == CCFPEmode)
6335 code = reverse_condition_maybe_unordered (code);
6337 code = reverse_condition (code);
6340 /* Start by writing the branch condition. */
6341 if (mode == CCFPmode || mode == CCFPEmode)
6392 /* ??? !v9: FP branches cannot be preceded by another floating point
6393 insn. Because there is currently no concept of pre-delay slots,
6394 we can fix this only by always emitting a nop before a floating
6399 strcpy (string, "nop\n\t");
6400 strcat (string, branch);
6413 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
6425 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
6446 strcpy (string, branch);
6448 spaces -= strlen (branch);
6449 p = strchr (string, '\0');
6451 /* Now add the annulling, the label, and a possible noop. */
6464 if (! far && insn && INSN_ADDRESSES_SET_P ())
6466 int delta = (INSN_ADDRESSES (INSN_UID (dest))
6467 - INSN_ADDRESSES (INSN_UID (insn)));
6468 /* Leave some instructions for "slop". */
6469 if (delta < -260000 || delta >= 260000)
6473 if (mode == CCFPmode || mode == CCFPEmode)
6475 static char v9_fcc_labelno[] = "%%fccX, ";
6476 /* Set the char indicating the number of the fcc reg to use. */
6477 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
6478 labelno = v9_fcc_labelno;
6481 gcc_assert (REGNO (cc_reg) == SPARC_FCC_REG);
6485 else if (mode == CCXmode || mode == CCX_NOOVmode)
6487 labelno = "%%xcc, ";
6492 labelno = "%%icc, ";
6497 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
6500 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
6513 strcpy (p, labelno);
6514 p = strchr (p, '\0');
6517 strcpy (p, ".+12\n\t nop\n\tb\t");
6518 /* Skip the next insn if requested or
6519 if we know that it will be a nop. */
6520 if (annul || ! final_sequence)
6534 /* Emit a library call comparison between floating point X and Y.
6535 COMPARISON is the operator to compare with (EQ, NE, GT, etc).
6536 Return the new operator to be used in the comparison sequence.
6538 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
6539 values as arguments instead of the TFmode registers themselves,
6540 that's why we cannot call emit_float_lib_cmp. */
6543 sparc_emit_float_lib_cmp (rtx x, rtx y, enum rtx_code comparison)
6546 rtx slot0, slot1, result, tem, tem2, libfunc;
6547 enum machine_mode mode;
6548 enum rtx_code new_comparison;
6553 qpfunc = (TARGET_ARCH64 ? "_Qp_feq" : "_Q_feq");
6557 qpfunc = (TARGET_ARCH64 ? "_Qp_fne" : "_Q_fne");
6561 qpfunc = (TARGET_ARCH64 ? "_Qp_fgt" : "_Q_fgt");
6565 qpfunc = (TARGET_ARCH64 ? "_Qp_fge" : "_Q_fge");
6569 qpfunc = (TARGET_ARCH64 ? "_Qp_flt" : "_Q_flt");
6573 qpfunc = (TARGET_ARCH64 ? "_Qp_fle" : "_Q_fle");
6584 qpfunc = (TARGET_ARCH64 ? "_Qp_cmp" : "_Q_cmp");
6597 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
6598 emit_move_insn (slot0, x);
6605 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
6606 emit_move_insn (slot1, y);
6609 libfunc = gen_rtx_SYMBOL_REF (Pmode, qpfunc);
6610 emit_library_call (libfunc, LCT_NORMAL,
6612 XEXP (slot0, 0), Pmode,
6613 XEXP (slot1, 0), Pmode);
6618 libfunc = gen_rtx_SYMBOL_REF (Pmode, qpfunc);
6619 emit_library_call (libfunc, LCT_NORMAL,
6621 x, TFmode, y, TFmode);
6626 /* Immediately move the result of the libcall into a pseudo
6627 register so reload doesn't clobber the value if it needs
6628 the return register for a spill reg. */
6629 result = gen_reg_rtx (mode);
6630 emit_move_insn (result, hard_libcall_value (mode, libfunc));
6635 return gen_rtx_NE (VOIDmode, result, const0_rtx);
6638 new_comparison = (comparison == UNORDERED ? EQ : NE);
6639 return gen_rtx_fmt_ee (new_comparison, VOIDmode, result, GEN_INT(3));
6642 new_comparison = (comparison == UNGT ? GT : NE);
6643 return gen_rtx_fmt_ee (new_comparison, VOIDmode, result, const1_rtx);
6645 return gen_rtx_NE (VOIDmode, result, const2_rtx);
6647 tem = gen_reg_rtx (mode);
6649 emit_insn (gen_andsi3 (tem, result, const1_rtx));
6651 emit_insn (gen_anddi3 (tem, result, const1_rtx));
6652 return gen_rtx_NE (VOIDmode, tem, const0_rtx);
6655 tem = gen_reg_rtx (mode);
6657 emit_insn (gen_addsi3 (tem, result, const1_rtx));
6659 emit_insn (gen_adddi3 (tem, result, const1_rtx));
6660 tem2 = gen_reg_rtx (mode);
6662 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
6664 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
6665 new_comparison = (comparison == UNEQ ? EQ : NE);
6666 return gen_rtx_fmt_ee (new_comparison, VOIDmode, tem2, const0_rtx);
6672 /* Generate an unsigned DImode to FP conversion. This is the same code
6673 optabs would emit if we didn't have TFmode patterns. */
6676 sparc_emit_floatunsdi (rtx *operands, enum machine_mode mode)
6678 rtx neglab, donelab, i0, i1, f0, in, out;
6681 in = force_reg (DImode, operands[1]);
6682 neglab = gen_label_rtx ();
6683 donelab = gen_label_rtx ();
6684 i0 = gen_reg_rtx (DImode);
6685 i1 = gen_reg_rtx (DImode);
6686 f0 = gen_reg_rtx (mode);
6688 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
6690 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
6691 emit_jump_insn (gen_jump (donelab));
6694 emit_label (neglab);
6696 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
6697 emit_insn (gen_anddi3 (i1, in, const1_rtx));
6698 emit_insn (gen_iordi3 (i0, i0, i1));
6699 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
6700 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
6702 emit_label (donelab);
6705 /* Generate an FP to unsigned DImode conversion. This is the same code
6706 optabs would emit if we didn't have TFmode patterns. */
6709 sparc_emit_fixunsdi (rtx *operands, enum machine_mode mode)
6711 rtx neglab, donelab, i0, i1, f0, in, out, limit;
6714 in = force_reg (mode, operands[1]);
6715 neglab = gen_label_rtx ();
6716 donelab = gen_label_rtx ();
6717 i0 = gen_reg_rtx (DImode);
6718 i1 = gen_reg_rtx (DImode);
6719 limit = gen_reg_rtx (mode);
6720 f0 = gen_reg_rtx (mode);
6722 emit_move_insn (limit,
6723 CONST_DOUBLE_FROM_REAL_VALUE (
6724 REAL_VALUE_ATOF ("9223372036854775808.0", mode), mode));
6725 emit_cmp_and_jump_insns (in, limit, GE, NULL_RTX, mode, 0, neglab);
6727 emit_insn (gen_rtx_SET (VOIDmode,
6729 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, in))));
6730 emit_jump_insn (gen_jump (donelab));
6733 emit_label (neglab);
6735 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_MINUS (mode, in, limit)));
6736 emit_insn (gen_rtx_SET (VOIDmode,
6738 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, f0))));
6739 emit_insn (gen_movdi (i1, const1_rtx));
6740 emit_insn (gen_ashldi3 (i1, i1, GEN_INT (63)));
6741 emit_insn (gen_xordi3 (out, i0, i1));
6743 emit_label (donelab);
6746 /* Return the string to output a conditional branch to LABEL, testing
6747 register REG. LABEL is the operand number of the label; REG is the
6748 operand number of the reg. OP is the conditional expression. The mode
6749 of REG says what kind of comparison we made.
6751 DEST is the destination insn (i.e. the label), INSN is the source.
6753 REVERSED is nonzero if we should reverse the sense of the comparison.
6755 ANNUL is nonzero if we should generate an annulling branch. */
6758 output_v9branch (rtx op, rtx dest, int reg, int label, int reversed,
6759 int annul, rtx insn)
6761 static char string[64];
6762 enum rtx_code code = GET_CODE (op);
6763 enum machine_mode mode = GET_MODE (XEXP (op, 0));
6768 /* branch on register are limited to +-128KB. If it is too far away,
6781 brgez,a,pn %o1, .LC29
6787 ba,pt %xcc, .LC29 */
6789 far = get_attr_length (insn) >= 3;
6791 /* If not floating-point or if EQ or NE, we can just reverse the code. */
6793 code = reverse_condition (code);
6795 /* Only 64 bit versions of these instructions exist. */
6796 gcc_assert (mode == DImode);
6798 /* Start by writing the branch condition. */
6803 strcpy (string, "brnz");
6807 strcpy (string, "brz");
6811 strcpy (string, "brgez");
6815 strcpy (string, "brlz");
6819 strcpy (string, "brlez");
6823 strcpy (string, "brgz");
6830 p = strchr (string, '\0');
6832 /* Now add the annulling, reg, label, and nop. */
6839 if (insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
6842 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
6847 *p = p < string + 8 ? '\t' : ' ';
6855 int veryfar = 1, delta;
6857 if (INSN_ADDRESSES_SET_P ())
6859 delta = (INSN_ADDRESSES (INSN_UID (dest))
6860 - INSN_ADDRESSES (INSN_UID (insn)));
6861 /* Leave some instructions for "slop". */
6862 if (delta >= -260000 && delta < 260000)
6866 strcpy (p, ".+12\n\t nop\n\t");
6867 /* Skip the next insn if requested or
6868 if we know that it will be a nop. */
6869 if (annul || ! final_sequence)
6879 strcpy (p, "ba,pt\t%%xcc, ");
6893 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
6894 Such instructions cannot be used in the delay slot of return insn on v9.
6895 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
6899 epilogue_renumber (register rtx *where, int test)
6901 register const char *fmt;
6903 register enum rtx_code code;
6908 code = GET_CODE (*where);
6913 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
6915 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
6916 *where = gen_rtx_REG (GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
6924 /* Do not replace the frame pointer with the stack pointer because
6925 it can cause the delayed instruction to load below the stack.
6926 This occurs when instructions like:
6928 (set (reg/i:SI 24 %i0)
6929 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
6930 (const_int -20 [0xffffffec])) 0))
6932 are in the return delayed slot. */
6934 if (GET_CODE (XEXP (*where, 0)) == REG
6935 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
6936 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
6937 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
6942 if (SPARC_STACK_BIAS
6943 && GET_CODE (XEXP (*where, 0)) == REG
6944 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
6952 fmt = GET_RTX_FORMAT (code);
6954 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6959 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
6960 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
6963 else if (fmt[i] == 'e'
6964 && epilogue_renumber (&(XEXP (*where, i)), test))
6970 /* Leaf functions and non-leaf functions have different needs. */
6973 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
6976 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
6978 static const int *const reg_alloc_orders[] = {
6979 reg_leaf_alloc_order,
6980 reg_nonleaf_alloc_order};
6983 order_regs_for_local_alloc (void)
6985 static int last_order_nonleaf = 1;
6987 if (df_regs_ever_live_p (15) != last_order_nonleaf)
6989 last_order_nonleaf = !last_order_nonleaf;
6990 memcpy ((char *) reg_alloc_order,
6991 (const char *) reg_alloc_orders[last_order_nonleaf],
6992 FIRST_PSEUDO_REGISTER * sizeof (int));
6996 /* Return 1 if REG and MEM are legitimate enough to allow the various
6997 mem<-->reg splits to be run. */
7000 sparc_splitdi_legitimate (rtx reg, rtx mem)
7002 /* Punt if we are here by mistake. */
7003 gcc_assert (reload_completed);
7005 /* We must have an offsettable memory reference. */
7006 if (! offsettable_memref_p (mem))
7009 /* If we have legitimate args for ldd/std, we do not want
7010 the split to happen. */
7011 if ((REGNO (reg) % 2) == 0
7012 && mem_min_alignment (mem, 8))
7019 /* Return 1 if x and y are some kind of REG and they refer to
7020 different hard registers. This test is guaranteed to be
7021 run after reload. */
7024 sparc_absnegfloat_split_legitimate (rtx x, rtx y)
7026 if (GET_CODE (x) != REG)
7028 if (GET_CODE (y) != REG)
7030 if (REGNO (x) == REGNO (y))
7035 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
7036 This makes them candidates for using ldd and std insns.
7038 Note reg1 and reg2 *must* be hard registers. */
7041 registers_ok_for_ldd_peep (rtx reg1, rtx reg2)
7043 /* We might have been passed a SUBREG. */
7044 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
7047 if (REGNO (reg1) % 2 != 0)
7050 /* Integer ldd is deprecated in SPARC V9 */
7051 if (TARGET_V9 && REGNO (reg1) < 32)
7054 return (REGNO (reg1) == REGNO (reg2) - 1);
7057 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
7060 This can only happen when addr1 and addr2, the addresses in mem1
7061 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
7062 addr1 must also be aligned on a 64-bit boundary.
7064 Also iff dependent_reg_rtx is not null it should not be used to
7065 compute the address for mem1, i.e. we cannot optimize a sequence
7077 But, note that the transformation from:
7082 is perfectly fine. Thus, the peephole2 patterns always pass us
7083 the destination register of the first load, never the second one.
7085 For stores we don't have a similar problem, so dependent_reg_rtx is
7089 mems_ok_for_ldd_peep (rtx mem1, rtx mem2, rtx dependent_reg_rtx)
7093 HOST_WIDE_INT offset1;
7095 /* The mems cannot be volatile. */
7096 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
7099 /* MEM1 should be aligned on a 64-bit boundary. */
7100 if (MEM_ALIGN (mem1) < 64)
7103 addr1 = XEXP (mem1, 0);
7104 addr2 = XEXP (mem2, 0);
7106 /* Extract a register number and offset (if used) from the first addr. */
7107 if (GET_CODE (addr1) == PLUS)
7109 /* If not a REG, return zero. */
7110 if (GET_CODE (XEXP (addr1, 0)) != REG)
7114 reg1 = REGNO (XEXP (addr1, 0));
7115 /* The offset must be constant! */
7116 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
7118 offset1 = INTVAL (XEXP (addr1, 1));
7121 else if (GET_CODE (addr1) != REG)
7125 reg1 = REGNO (addr1);
7126 /* This was a simple (mem (reg)) expression. Offset is 0. */
7130 /* Make sure the second address is a (mem (plus (reg) (const_int). */
7131 if (GET_CODE (addr2) != PLUS)
7134 if (GET_CODE (XEXP (addr2, 0)) != REG
7135 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
7138 if (reg1 != REGNO (XEXP (addr2, 0)))
7141 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
7144 /* The first offset must be evenly divisible by 8 to ensure the
7145 address is 64 bit aligned. */
7146 if (offset1 % 8 != 0)
7149 /* The offset for the second addr must be 4 more than the first addr. */
7150 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
7153 /* All the tests passed. addr1 and addr2 are valid for ldd and std
7158 /* Return 1 if reg is a pseudo, or is the first register in
7159 a hard register pair. This makes it suitable for use in
7160 ldd and std insns. */
7163 register_ok_for_ldd (rtx reg)
7165 /* We might have been passed a SUBREG. */
7169 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
7170 return (REGNO (reg) % 2 == 0);
7175 /* Return 1 if OP is a memory whose address is known to be
7176 aligned to 8-byte boundary, or a pseudo during reload.
7177 This makes it suitable for use in ldd and std insns. */
7180 memory_ok_for_ldd (rtx op)
7184 /* In 64-bit mode, we assume that the address is word-aligned. */
7185 if (TARGET_ARCH32 && !mem_min_alignment (op, 8))
7188 if ((reload_in_progress || reload_completed)
7189 && !strict_memory_address_p (Pmode, XEXP (op, 0)))
7192 else if (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER)
7194 if (!(reload_in_progress && reg_renumber [REGNO (op)] < 0))
7203 /* Print operand X (an rtx) in assembler syntax to file FILE.
7204 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
7205 For `%' followed by punctuation, CODE is the punctuation and X is null. */
7208 print_operand (FILE *file, rtx x, int code)
7213 /* Output an insn in a delay slot. */
7215 sparc_indent_opcode = 1;
7217 fputs ("\n\t nop", file);
7220 /* Output an annul flag if there's nothing for the delay slot and we
7221 are optimizing. This is always used with '(' below.
7222 Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
7223 this is a dbx bug. So, we only do this when optimizing.
7224 On UltraSPARC, a branch in a delay slot causes a pipeline flush.
7225 Always emit a nop in case the next instruction is a branch. */
7226 if (! final_sequence && (optimize && (int)sparc_cpu < PROCESSOR_V9))
7230 /* Output a 'nop' if there's nothing for the delay slot and we are
7231 not optimizing. This is always used with '*' above. */
7232 if (! final_sequence && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
7233 fputs ("\n\t nop", file);
7234 else if (final_sequence)
7235 sparc_indent_opcode = 1;
7238 /* Output the right displacement from the saved PC on function return.
7239 The caller may have placed an "unimp" insn immediately after the call
7240 so we have to account for it. This insn is used in the 32-bit ABI
7241 when calling a function that returns a non zero-sized structure. The
7242 64-bit ABI doesn't have it. Be careful to have this test be the same
7243 as that for the call. The exception is when sparc_std_struct_return
7244 is enabled, the psABI is followed exactly and the adjustment is made
7245 by the code in sparc_struct_value_rtx. The call emitted is the same
7246 when sparc_std_struct_return is enabled. */
7248 && cfun->returns_struct
7249 && !sparc_std_struct_return
7250 && DECL_SIZE (DECL_RESULT (current_function_decl))
7251 && TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl)))
7253 && !integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))))
7259 /* Output the Embedded Medium/Anywhere code model base register. */
7260 fputs (EMBMEDANY_BASE_REG, file);
7263 /* Print some local dynamic TLS name. */
7264 assemble_name (file, get_some_local_dynamic_name ());
7268 /* Adjust the operand to take into account a RESTORE operation. */
7269 if (GET_CODE (x) == CONST_INT)
7271 else if (GET_CODE (x) != REG)
7272 output_operand_lossage ("invalid %%Y operand");
7273 else if (REGNO (x) < 8)
7274 fputs (reg_names[REGNO (x)], file);
7275 else if (REGNO (x) >= 24 && REGNO (x) < 32)
7276 fputs (reg_names[REGNO (x)-16], file);
7278 output_operand_lossage ("invalid %%Y operand");
7281 /* Print out the low order register name of a register pair. */
7282 if (WORDS_BIG_ENDIAN)
7283 fputs (reg_names[REGNO (x)+1], file);
7285 fputs (reg_names[REGNO (x)], file);
7288 /* Print out the high order register name of a register pair. */
7289 if (WORDS_BIG_ENDIAN)
7290 fputs (reg_names[REGNO (x)], file);
7292 fputs (reg_names[REGNO (x)+1], file);
7295 /* Print out the second register name of a register pair or quad.
7296 I.e., R (%o0) => %o1. */
7297 fputs (reg_names[REGNO (x)+1], file);
7300 /* Print out the third register name of a register quad.
7301 I.e., S (%o0) => %o2. */
7302 fputs (reg_names[REGNO (x)+2], file);
7305 /* Print out the fourth register name of a register quad.
7306 I.e., T (%o0) => %o3. */
7307 fputs (reg_names[REGNO (x)+3], file);
7310 /* Print a condition code register. */
7311 if (REGNO (x) == SPARC_ICC_REG)
7313 /* We don't handle CC[X]_NOOVmode because they're not supposed
7315 if (GET_MODE (x) == CCmode)
7316 fputs ("%icc", file);
7317 else if (GET_MODE (x) == CCXmode)
7318 fputs ("%xcc", file);
7323 /* %fccN register */
7324 fputs (reg_names[REGNO (x)], file);
7327 /* Print the operand's address only. */
7328 output_address (XEXP (x, 0));
7331 /* In this case we need a register. Use %g0 if the
7332 operand is const0_rtx. */
7334 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
7336 fputs ("%g0", file);
7343 switch (GET_CODE (x))
7345 case IOR: fputs ("or", file); break;
7346 case AND: fputs ("and", file); break;
7347 case XOR: fputs ("xor", file); break;
7348 default: output_operand_lossage ("invalid %%A operand");
7353 switch (GET_CODE (x))
7355 case IOR: fputs ("orn", file); break;
7356 case AND: fputs ("andn", file); break;
7357 case XOR: fputs ("xnor", file); break;
7358 default: output_operand_lossage ("invalid %%B operand");
7362 /* These are used by the conditional move instructions. */
7366 enum rtx_code rc = GET_CODE (x);
7370 enum machine_mode mode = GET_MODE (XEXP (x, 0));
7371 if (mode == CCFPmode || mode == CCFPEmode)
7372 rc = reverse_condition_maybe_unordered (GET_CODE (x));
7374 rc = reverse_condition (GET_CODE (x));
7378 case NE: fputs ("ne", file); break;
7379 case EQ: fputs ("e", file); break;
7380 case GE: fputs ("ge", file); break;
7381 case GT: fputs ("g", file); break;
7382 case LE: fputs ("le", file); break;
7383 case LT: fputs ("l", file); break;
7384 case GEU: fputs ("geu", file); break;
7385 case GTU: fputs ("gu", file); break;
7386 case LEU: fputs ("leu", file); break;
7387 case LTU: fputs ("lu", file); break;
7388 case LTGT: fputs ("lg", file); break;
7389 case UNORDERED: fputs ("u", file); break;
7390 case ORDERED: fputs ("o", file); break;
7391 case UNLT: fputs ("ul", file); break;
7392 case UNLE: fputs ("ule", file); break;
7393 case UNGT: fputs ("ug", file); break;
7394 case UNGE: fputs ("uge", file); break;
7395 case UNEQ: fputs ("ue", file); break;
7396 default: output_operand_lossage (code == 'c'
7397 ? "invalid %%c operand"
7398 : "invalid %%C operand");
7403 /* These are used by the movr instruction pattern. */
7407 enum rtx_code rc = (code == 'd'
7408 ? reverse_condition (GET_CODE (x))
7412 case NE: fputs ("ne", file); break;
7413 case EQ: fputs ("e", file); break;
7414 case GE: fputs ("gez", file); break;
7415 case LT: fputs ("lz", file); break;
7416 case LE: fputs ("lez", file); break;
7417 case GT: fputs ("gz", file); break;
7418 default: output_operand_lossage (code == 'd'
7419 ? "invalid %%d operand"
7420 : "invalid %%D operand");
7427 /* Print a sign-extended character. */
7428 int i = trunc_int_for_mode (INTVAL (x), QImode);
7429 fprintf (file, "%d", i);
7434 /* Operand must be a MEM; write its address. */
7435 if (GET_CODE (x) != MEM)
7436 output_operand_lossage ("invalid %%f operand");
7437 output_address (XEXP (x, 0));
7442 /* Print a sign-extended 32-bit value. */
7444 if (GET_CODE(x) == CONST_INT)
7446 else if (GET_CODE(x) == CONST_DOUBLE)
7447 i = CONST_DOUBLE_LOW (x);
7450 output_operand_lossage ("invalid %%s operand");
7453 i = trunc_int_for_mode (i, SImode);
7454 fprintf (file, HOST_WIDE_INT_PRINT_DEC, i);
7459 /* Do nothing special. */
7463 /* Undocumented flag. */
7464 output_operand_lossage ("invalid operand output code");
7467 if (GET_CODE (x) == REG)
7468 fputs (reg_names[REGNO (x)], file);
7469 else if (GET_CODE (x) == MEM)
7472 /* Poor Sun assembler doesn't understand absolute addressing. */
7473 if (CONSTANT_P (XEXP (x, 0)))
7474 fputs ("%g0+", file);
7475 output_address (XEXP (x, 0));
7478 else if (GET_CODE (x) == HIGH)
7480 fputs ("%hi(", file);
7481 output_addr_const (file, XEXP (x, 0));
7484 else if (GET_CODE (x) == LO_SUM)
7486 print_operand (file, XEXP (x, 0), 0);
7487 if (TARGET_CM_MEDMID)
7488 fputs ("+%l44(", file);
7490 fputs ("+%lo(", file);
7491 output_addr_const (file, XEXP (x, 1));
7494 else if (GET_CODE (x) == CONST_DOUBLE
7495 && (GET_MODE (x) == VOIDmode
7496 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
7498 if (CONST_DOUBLE_HIGH (x) == 0)
7499 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
7500 else if (CONST_DOUBLE_HIGH (x) == -1
7501 && CONST_DOUBLE_LOW (x) < 0)
7502 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
7504 output_operand_lossage ("long long constant not a valid immediate operand");
7506 else if (GET_CODE (x) == CONST_DOUBLE)
7507 output_operand_lossage ("floating point constant not a valid immediate operand");
7508 else { output_addr_const (file, x); }
7511 /* Target hook for assembling integer objects. The sparc version has
7512 special handling for aligned DI-mode objects. */
7515 sparc_assemble_integer (rtx x, unsigned int size, int aligned_p)
7517 /* ??? We only output .xword's for symbols and only then in environments
7518 where the assembler can handle them. */
7519 if (aligned_p && size == 8
7520 && (GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE))
7524 assemble_integer_with_op ("\t.xword\t", x);
7529 assemble_aligned_integer (4, const0_rtx);
7530 assemble_aligned_integer (4, x);
7534 return default_assemble_integer (x, size, aligned_p);
7537 /* Return the value of a code used in the .proc pseudo-op that says
7538 what kind of result this function returns. For non-C types, we pick
7539 the closest C type. */
7541 #ifndef SHORT_TYPE_SIZE
7542 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
7545 #ifndef INT_TYPE_SIZE
7546 #define INT_TYPE_SIZE BITS_PER_WORD
7549 #ifndef LONG_TYPE_SIZE
7550 #define LONG_TYPE_SIZE BITS_PER_WORD
7553 #ifndef LONG_LONG_TYPE_SIZE
7554 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
7557 #ifndef FLOAT_TYPE_SIZE
7558 #define FLOAT_TYPE_SIZE BITS_PER_WORD
7561 #ifndef DOUBLE_TYPE_SIZE
7562 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
7565 #ifndef LONG_DOUBLE_TYPE_SIZE
7566 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
7570 sparc_type_code (register tree type)
7572 register unsigned long qualifiers = 0;
7573 register unsigned shift;
7575 /* Only the first 30 bits of the qualifier are valid. We must refrain from
7576 setting more, since some assemblers will give an error for this. Also,
7577 we must be careful to avoid shifts of 32 bits or more to avoid getting
7578 unpredictable results. */
7580 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
7582 switch (TREE_CODE (type))
7588 qualifiers |= (3 << shift);
7593 qualifiers |= (2 << shift);
7597 case REFERENCE_TYPE:
7599 qualifiers |= (1 << shift);
7603 return (qualifiers | 8);
7606 case QUAL_UNION_TYPE:
7607 return (qualifiers | 9);
7610 return (qualifiers | 10);
7613 return (qualifiers | 16);
7616 /* If this is a range type, consider it to be the underlying
7618 if (TREE_TYPE (type) != 0)
7621 /* Carefully distinguish all the standard types of C,
7622 without messing up if the language is not C. We do this by
7623 testing TYPE_PRECISION and TYPE_UNSIGNED. The old code used to
7624 look at both the names and the above fields, but that's redundant.
7625 Any type whose size is between two C types will be considered
7626 to be the wider of the two types. Also, we do not have a
7627 special code to use for "long long", so anything wider than
7628 long is treated the same. Note that we can't distinguish
7629 between "int" and "long" in this code if they are the same
7630 size, but that's fine, since neither can the assembler. */
7632 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
7633 return (qualifiers | (TYPE_UNSIGNED (type) ? 12 : 2));
7635 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
7636 return (qualifiers | (TYPE_UNSIGNED (type) ? 13 : 3));
7638 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
7639 return (qualifiers | (TYPE_UNSIGNED (type) ? 14 : 4));
7642 return (qualifiers | (TYPE_UNSIGNED (type) ? 15 : 5));
7645 /* If this is a range type, consider it to be the underlying
7647 if (TREE_TYPE (type) != 0)
7650 /* Carefully distinguish all the standard types of C,
7651 without messing up if the language is not C. */
7653 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
7654 return (qualifiers | 6);
7657 return (qualifiers | 7);
7659 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
7660 /* ??? We need to distinguish between double and float complex types,
7661 but I don't know how yet because I can't reach this code from
7662 existing front-ends. */
7663 return (qualifiers | 7); /* Who knows? */
7666 case BOOLEAN_TYPE: /* Boolean truth value type. */
7667 case LANG_TYPE: /* ? */
7671 gcc_unreachable (); /* Not a type! */
7678 /* Nested function support. */
7680 /* Emit RTL insns to initialize the variable parts of a trampoline.
7681 FNADDR is an RTX for the address of the function's pure code.
7682 CXT is an RTX for the static chain value for the function.
7684 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
7685 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
7686 (to store insns). This is a bit excessive. Perhaps a different
7687 mechanism would be better here.
7689 Emit enough FLUSH insns to synchronize the data and instruction caches. */
7692 sparc32_initialize_trampoline (rtx m_tramp, rtx fnaddr, rtx cxt)
7694 /* SPARC 32-bit trampoline:
7697 sethi %hi(static), %g2
7699 or %g2, %lo(static), %g2
7701 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
7702 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
7706 (adjust_address (m_tramp, SImode, 0),
7707 expand_binop (SImode, ior_optab,
7708 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
7709 size_int (10), 0, 1),
7710 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
7711 NULL_RTX, 1, OPTAB_DIRECT));
7714 (adjust_address (m_tramp, SImode, 4),
7715 expand_binop (SImode, ior_optab,
7716 expand_shift (RSHIFT_EXPR, SImode, cxt,
7717 size_int (10), 0, 1),
7718 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
7719 NULL_RTX, 1, OPTAB_DIRECT));
7722 (adjust_address (m_tramp, SImode, 8),
7723 expand_binop (SImode, ior_optab,
7724 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
7725 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
7726 NULL_RTX, 1, OPTAB_DIRECT));
7729 (adjust_address (m_tramp, SImode, 12),
7730 expand_binop (SImode, ior_optab,
7731 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
7732 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
7733 NULL_RTX, 1, OPTAB_DIRECT));
7735 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
7736 aligned on a 16 byte boundary so one flush clears it all. */
7737 emit_insn (gen_flush (validize_mem (adjust_address (m_tramp, SImode, 0))));
7738 if (sparc_cpu != PROCESSOR_ULTRASPARC
7739 && sparc_cpu != PROCESSOR_ULTRASPARC3
7740 && sparc_cpu != PROCESSOR_NIAGARA
7741 && sparc_cpu != PROCESSOR_NIAGARA2)
7742 emit_insn (gen_flush (validize_mem (adjust_address (m_tramp, SImode, 8))));
7744 /* Call __enable_execute_stack after writing onto the stack to make sure
7745 the stack address is accessible. */
7746 #ifdef ENABLE_EXECUTE_STACK
7747 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
7748 LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
7753 /* The 64-bit version is simpler because it makes more sense to load the
7754 values as "immediate" data out of the trampoline. It's also easier since
7755 we can read the PC without clobbering a register. */
7758 sparc64_initialize_trampoline (rtx m_tramp, rtx fnaddr, rtx cxt)
7760 /* SPARC 64-bit trampoline:
7769 emit_move_insn (adjust_address (m_tramp, SImode, 0),
7770 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
7771 emit_move_insn (adjust_address (m_tramp, SImode, 4),
7772 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
7773 emit_move_insn (adjust_address (m_tramp, SImode, 8),
7774 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
7775 emit_move_insn (adjust_address (m_tramp, SImode, 12),
7776 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
7777 emit_move_insn (adjust_address (m_tramp, DImode, 16), cxt);
7778 emit_move_insn (adjust_address (m_tramp, DImode, 24), fnaddr);
7779 emit_insn (gen_flushdi (validize_mem (adjust_address (m_tramp, DImode, 0))));
7781 if (sparc_cpu != PROCESSOR_ULTRASPARC
7782 && sparc_cpu != PROCESSOR_ULTRASPARC3
7783 && sparc_cpu != PROCESSOR_NIAGARA
7784 && sparc_cpu != PROCESSOR_NIAGARA2)
7785 emit_insn (gen_flushdi (validize_mem (adjust_address (m_tramp, DImode, 8))));
7787 /* Call __enable_execute_stack after writing onto the stack to make sure
7788 the stack address is accessible. */
7789 #ifdef ENABLE_EXECUTE_STACK
7790 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
7791 LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
7795 /* Worker for TARGET_TRAMPOLINE_INIT. */
7798 sparc_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
7800 rtx fnaddr = force_reg (Pmode, XEXP (DECL_RTL (fndecl), 0));
7801 cxt = force_reg (Pmode, cxt);
7803 sparc64_initialize_trampoline (m_tramp, fnaddr, cxt);
7805 sparc32_initialize_trampoline (m_tramp, fnaddr, cxt);
7808 /* Adjust the cost of a scheduling dependency. Return the new cost of
7809 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7812 supersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
7814 enum attr_type insn_type;
7816 if (! recog_memoized (insn))
7819 insn_type = get_attr_type (insn);
7821 if (REG_NOTE_KIND (link) == 0)
7823 /* Data dependency; DEP_INSN writes a register that INSN reads some
7826 /* if a load, then the dependence must be on the memory address;
7827 add an extra "cycle". Note that the cost could be two cycles
7828 if the reg was written late in an instruction group; we ca not tell
7830 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
7833 /* Get the delay only if the address of the store is the dependence. */
7834 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
7836 rtx pat = PATTERN(insn);
7837 rtx dep_pat = PATTERN (dep_insn);
7839 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7840 return cost; /* This should not happen! */
7842 /* The dependency between the two instructions was on the data that
7843 is being stored. Assume that this implies that the address of the
7844 store is not dependent. */
7845 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7848 return cost + 3; /* An approximation. */
7851 /* A shift instruction cannot receive its data from an instruction
7852 in the same cycle; add a one cycle penalty. */
7853 if (insn_type == TYPE_SHIFT)
7854 return cost + 3; /* Split before cascade into shift. */
7858 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7859 INSN writes some cycles later. */
7861 /* These are only significant for the fpu unit; writing a fp reg before
7862 the fpu has finished with it stalls the processor. */
7864 /* Reusing an integer register causes no problems. */
7865 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7873 hypersparc_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
7875 enum attr_type insn_type, dep_type;
7876 rtx pat = PATTERN(insn);
7877 rtx dep_pat = PATTERN (dep_insn);
7879 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7882 insn_type = get_attr_type (insn);
7883 dep_type = get_attr_type (dep_insn);
7885 switch (REG_NOTE_KIND (link))
7888 /* Data dependency; DEP_INSN writes a register that INSN reads some
7895 /* Get the delay iff the address of the store is the dependence. */
7896 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7899 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7906 /* If a load, then the dependence must be on the memory address. If
7907 the addresses aren't equal, then it might be a false dependency */
7908 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7910 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7911 || GET_CODE (SET_DEST (dep_pat)) != MEM
7912 || GET_CODE (SET_SRC (pat)) != MEM
7913 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
7914 XEXP (SET_SRC (pat), 0)))
7922 /* Compare to branch latency is 0. There is no benefit from
7923 separating compare and branch. */
7924 if (dep_type == TYPE_COMPARE)
7926 /* Floating point compare to branch latency is less than
7927 compare to conditional move. */
7928 if (dep_type == TYPE_FPCMP)
7937 /* Anti-dependencies only penalize the fpu unit. */
7938 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7950 sparc_adjust_cost(rtx insn, rtx link, rtx dep, int cost)
7954 case PROCESSOR_SUPERSPARC:
7955 cost = supersparc_adjust_cost (insn, link, dep, cost);
7957 case PROCESSOR_HYPERSPARC:
7958 case PROCESSOR_SPARCLITE86X:
7959 cost = hypersparc_adjust_cost (insn, link, dep, cost);
7968 sparc_sched_init (FILE *dump ATTRIBUTE_UNUSED,
7969 int sched_verbose ATTRIBUTE_UNUSED,
7970 int max_ready ATTRIBUTE_UNUSED)
7974 sparc_use_sched_lookahead (void)
7976 if (sparc_cpu == PROCESSOR_NIAGARA
7977 || sparc_cpu == PROCESSOR_NIAGARA2)
7979 if (sparc_cpu == PROCESSOR_ULTRASPARC
7980 || sparc_cpu == PROCESSOR_ULTRASPARC3)
7982 if ((1 << sparc_cpu) &
7983 ((1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
7984 (1 << PROCESSOR_SPARCLITE86X)))
7990 sparc_issue_rate (void)
7994 case PROCESSOR_NIAGARA:
7995 case PROCESSOR_NIAGARA2:
7999 /* Assume V9 processors are capable of at least dual-issue. */
8001 case PROCESSOR_SUPERSPARC:
8003 case PROCESSOR_HYPERSPARC:
8004 case PROCESSOR_SPARCLITE86X:
8006 case PROCESSOR_ULTRASPARC:
8007 case PROCESSOR_ULTRASPARC3:
8013 set_extends (rtx insn)
8015 register rtx pat = PATTERN (insn);
8017 switch (GET_CODE (SET_SRC (pat)))
8019 /* Load and some shift instructions zero extend. */
8022 /* sethi clears the high bits */
8024 /* LO_SUM is used with sethi. sethi cleared the high
8025 bits and the values used with lo_sum are positive */
8027 /* Store flag stores 0 or 1 */
8037 rtx op0 = XEXP (SET_SRC (pat), 0);
8038 rtx op1 = XEXP (SET_SRC (pat), 1);
8039 if (GET_CODE (op1) == CONST_INT)
8040 return INTVAL (op1) >= 0;
8041 if (GET_CODE (op0) != REG)
8043 if (sparc_check_64 (op0, insn) == 1)
8045 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
8050 rtx op0 = XEXP (SET_SRC (pat), 0);
8051 rtx op1 = XEXP (SET_SRC (pat), 1);
8052 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
8054 if (GET_CODE (op1) == CONST_INT)
8055 return INTVAL (op1) >= 0;
8056 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
8059 return GET_MODE (SET_SRC (pat)) == SImode;
8060 /* Positive integers leave the high bits zero. */
8062 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
8064 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
8067 return - (GET_MODE (SET_SRC (pat)) == SImode);
8069 return sparc_check_64 (SET_SRC (pat), insn);
8075 /* We _ought_ to have only one kind per function, but... */
8076 static GTY(()) rtx sparc_addr_diff_list;
8077 static GTY(()) rtx sparc_addr_list;
8080 sparc_defer_case_vector (rtx lab, rtx vec, int diff)
8082 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
8084 sparc_addr_diff_list
8085 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
8087 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
8091 sparc_output_addr_vec (rtx vec)
8093 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8094 int idx, vlen = XVECLEN (body, 0);
8096 #ifdef ASM_OUTPUT_ADDR_VEC_START
8097 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8100 #ifdef ASM_OUTPUT_CASE_LABEL
8101 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8104 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8107 for (idx = 0; idx < vlen; idx++)
8109 ASM_OUTPUT_ADDR_VEC_ELT
8110 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
8113 #ifdef ASM_OUTPUT_ADDR_VEC_END
8114 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8119 sparc_output_addr_diff_vec (rtx vec)
8121 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8122 rtx base = XEXP (XEXP (body, 0), 0);
8123 int idx, vlen = XVECLEN (body, 1);
8125 #ifdef ASM_OUTPUT_ADDR_VEC_START
8126 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8129 #ifdef ASM_OUTPUT_CASE_LABEL
8130 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8133 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8136 for (idx = 0; idx < vlen; idx++)
8138 ASM_OUTPUT_ADDR_DIFF_ELT
8141 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
8142 CODE_LABEL_NUMBER (base));
8145 #ifdef ASM_OUTPUT_ADDR_VEC_END
8146 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8151 sparc_output_deferred_case_vectors (void)
8156 if (sparc_addr_list == NULL_RTX
8157 && sparc_addr_diff_list == NULL_RTX)
8160 /* Align to cache line in the function's code section. */
8161 switch_to_section (current_function_section ());
8163 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
8165 ASM_OUTPUT_ALIGN (asm_out_file, align);
8167 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
8168 sparc_output_addr_vec (XEXP (t, 0));
8169 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
8170 sparc_output_addr_diff_vec (XEXP (t, 0));
8172 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
8175 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
8176 unknown. Return 1 if the high bits are zero, -1 if the register is
8179 sparc_check_64 (rtx x, rtx insn)
8181 /* If a register is set only once it is safe to ignore insns this
8182 code does not know how to handle. The loop will either recognize
8183 the single set and return the correct value or fail to recognize
8188 gcc_assert (GET_CODE (x) == REG);
8190 if (GET_MODE (x) == DImode)
8191 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
8193 if (flag_expensive_optimizations
8194 && df && DF_REG_DEF_COUNT (REGNO (y)) == 1)
8200 insn = get_last_insn_anywhere ();
8205 while ((insn = PREV_INSN (insn)))
8207 switch (GET_CODE (insn))
8220 rtx pat = PATTERN (insn);
8221 if (GET_CODE (pat) != SET)
8223 if (rtx_equal_p (x, SET_DEST (pat)))
8224 return set_extends (insn);
8225 if (y && rtx_equal_p (y, SET_DEST (pat)))
8226 return set_extends (insn);
8227 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
8235 /* Returns assembly code to perform a DImode shift using
8236 a 64-bit global or out register on SPARC-V8+. */
8238 output_v8plus_shift (rtx *operands, rtx insn, const char *opcode)
8240 static char asm_code[60];
8242 /* The scratch register is only required when the destination
8243 register is not a 64-bit global or out register. */
8244 if (which_alternative != 2)
8245 operands[3] = operands[0];
8247 /* We can only shift by constants <= 63. */
8248 if (GET_CODE (operands[2]) == CONST_INT)
8249 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
8251 if (GET_CODE (operands[1]) == CONST_INT)
8253 output_asm_insn ("mov\t%1, %3", operands);
8257 output_asm_insn ("sllx\t%H1, 32, %3", operands);
8258 if (sparc_check_64 (operands[1], insn) <= 0)
8259 output_asm_insn ("srl\t%L1, 0, %L1", operands);
8260 output_asm_insn ("or\t%L1, %3, %3", operands);
8263 strcpy(asm_code, opcode);
8265 if (which_alternative != 2)
8266 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
8268 return strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
8271 /* Output rtl to increment the profiler label LABELNO
8272 for profiling a function entry. */
8275 sparc_profile_hook (int labelno)
8280 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
8281 if (NO_PROFILE_COUNTERS)
8283 emit_library_call (fun, LCT_NORMAL, VOIDmode, 0);
8287 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
8288 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
8289 emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lab, Pmode);
8293 /* Solaris implementation of TARGET_ASM_NAMED_SECTION. */
8296 sparc_solaris_elf_asm_named_section (const char *name, unsigned int flags,
8297 tree decl ATTRIBUTE_UNUSED)
8299 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
8301 if (!(flags & SECTION_DEBUG))
8302 fputs (",#alloc", asm_out_file);
8303 if (flags & SECTION_WRITE)
8304 fputs (",#write", asm_out_file);
8305 if (flags & SECTION_TLS)
8306 fputs (",#tls", asm_out_file);
8307 if (flags & SECTION_CODE)
8308 fputs (",#execinstr", asm_out_file);
8310 /* ??? Handle SECTION_BSS. */
8312 fputc ('\n', asm_out_file);
8315 /* We do not allow indirect calls to be optimized into sibling calls.
8317 We cannot use sibling calls when delayed branches are disabled
8318 because they will likely require the call delay slot to be filled.
8320 Also, on SPARC 32-bit we cannot emit a sibling call when the
8321 current function returns a structure. This is because the "unimp
8322 after call" convention would cause the callee to return to the
8323 wrong place. The generic code already disallows cases where the
8324 function being called returns a structure.
8326 It may seem strange how this last case could occur. Usually there
8327 is code after the call which jumps to epilogue code which dumps the
8328 return value into the struct return area. That ought to invalidate
8329 the sibling call right? Well, in the C++ case we can end up passing
8330 the pointer to the struct return area to a constructor (which returns
8331 void) and then nothing else happens. Such a sibling call would look
8332 valid without the added check here.
8334 VxWorks PIC PLT entries require the global pointer to be initialized
8335 on entry. We therefore can't emit sibling calls to them. */
8337 sparc_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
8340 && flag_delayed_branch
8341 && (TARGET_ARCH64 || ! cfun->returns_struct)
8342 && !(TARGET_VXWORKS_RTP
8344 && !targetm.binds_local_p (decl)));
8347 /* libfunc renaming. */
8348 #include "config/gofast.h"
8351 sparc_init_libfuncs (void)
8355 /* Use the subroutines that Sun's library provides for integer
8356 multiply and divide. The `*' prevents an underscore from
8357 being prepended by the compiler. .umul is a little faster
8359 set_optab_libfunc (smul_optab, SImode, "*.umul");
8360 set_optab_libfunc (sdiv_optab, SImode, "*.div");
8361 set_optab_libfunc (udiv_optab, SImode, "*.udiv");
8362 set_optab_libfunc (smod_optab, SImode, "*.rem");
8363 set_optab_libfunc (umod_optab, SImode, "*.urem");
8365 /* TFmode arithmetic. These names are part of the SPARC 32bit ABI. */
8366 set_optab_libfunc (add_optab, TFmode, "_Q_add");
8367 set_optab_libfunc (sub_optab, TFmode, "_Q_sub");
8368 set_optab_libfunc (neg_optab, TFmode, "_Q_neg");
8369 set_optab_libfunc (smul_optab, TFmode, "_Q_mul");
8370 set_optab_libfunc (sdiv_optab, TFmode, "_Q_div");
8372 /* We can define the TFmode sqrt optab only if TARGET_FPU. This
8373 is because with soft-float, the SFmode and DFmode sqrt
8374 instructions will be absent, and the compiler will notice and
8375 try to use the TFmode sqrt instruction for calls to the
8376 builtin function sqrt, but this fails. */
8378 set_optab_libfunc (sqrt_optab, TFmode, "_Q_sqrt");
8380 set_optab_libfunc (eq_optab, TFmode, "_Q_feq");
8381 set_optab_libfunc (ne_optab, TFmode, "_Q_fne");
8382 set_optab_libfunc (gt_optab, TFmode, "_Q_fgt");
8383 set_optab_libfunc (ge_optab, TFmode, "_Q_fge");
8384 set_optab_libfunc (lt_optab, TFmode, "_Q_flt");
8385 set_optab_libfunc (le_optab, TFmode, "_Q_fle");
8387 set_conv_libfunc (sext_optab, TFmode, SFmode, "_Q_stoq");
8388 set_conv_libfunc (sext_optab, TFmode, DFmode, "_Q_dtoq");
8389 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_Q_qtos");
8390 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_Q_qtod");
8392 set_conv_libfunc (sfix_optab, SImode, TFmode, "_Q_qtoi");
8393 set_conv_libfunc (ufix_optab, SImode, TFmode, "_Q_qtou");
8394 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_Q_itoq");
8395 set_conv_libfunc (ufloat_optab, TFmode, SImode, "_Q_utoq");
8397 if (DITF_CONVERSION_LIBFUNCS)
8399 set_conv_libfunc (sfix_optab, DImode, TFmode, "_Q_qtoll");
8400 set_conv_libfunc (ufix_optab, DImode, TFmode, "_Q_qtoull");
8401 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_Q_lltoq");
8402 set_conv_libfunc (ufloat_optab, TFmode, DImode, "_Q_ulltoq");
8405 if (SUN_CONVERSION_LIBFUNCS)
8407 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftoll");
8408 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoull");
8409 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtoll");
8410 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoull");
8415 /* In the SPARC 64bit ABI, SImode multiply and divide functions
8416 do not exist in the library. Make sure the compiler does not
8417 emit calls to them by accident. (It should always use the
8418 hardware instructions.) */
8419 set_optab_libfunc (smul_optab, SImode, 0);
8420 set_optab_libfunc (sdiv_optab, SImode, 0);
8421 set_optab_libfunc (udiv_optab, SImode, 0);
8422 set_optab_libfunc (smod_optab, SImode, 0);
8423 set_optab_libfunc (umod_optab, SImode, 0);
8425 if (SUN_INTEGER_MULTIPLY_64)
8427 set_optab_libfunc (smul_optab, DImode, "__mul64");
8428 set_optab_libfunc (sdiv_optab, DImode, "__div64");
8429 set_optab_libfunc (udiv_optab, DImode, "__udiv64");
8430 set_optab_libfunc (smod_optab, DImode, "__rem64");
8431 set_optab_libfunc (umod_optab, DImode, "__urem64");
8434 if (SUN_CONVERSION_LIBFUNCS)
8436 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftol");
8437 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoul");
8438 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtol");
8439 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoul");
8443 gofast_maybe_init_libfuncs ();
8446 #define def_builtin(NAME, CODE, TYPE) \
8447 add_builtin_function((NAME), (TYPE), (CODE), BUILT_IN_MD, NULL, \
8450 /* Implement the TARGET_INIT_BUILTINS target hook.
8451 Create builtin functions for special SPARC instructions. */
8454 sparc_init_builtins (void)
8457 sparc_vis_init_builtins ();
8460 /* Create builtin functions for VIS 1.0 instructions. */
8463 sparc_vis_init_builtins (void)
8465 tree v4qi = build_vector_type (unsigned_intQI_type_node, 4);
8466 tree v8qi = build_vector_type (unsigned_intQI_type_node, 8);
8467 tree v4hi = build_vector_type (intHI_type_node, 4);
8468 tree v2hi = build_vector_type (intHI_type_node, 2);
8469 tree v2si = build_vector_type (intSI_type_node, 2);
8471 tree v4qi_ftype_v4hi = build_function_type_list (v4qi, v4hi, 0);
8472 tree v8qi_ftype_v2si_v8qi = build_function_type_list (v8qi, v2si, v8qi, 0);
8473 tree v2hi_ftype_v2si = build_function_type_list (v2hi, v2si, 0);
8474 tree v4hi_ftype_v4qi = build_function_type_list (v4hi, v4qi, 0);
8475 tree v8qi_ftype_v4qi_v4qi = build_function_type_list (v8qi, v4qi, v4qi, 0);
8476 tree v4hi_ftype_v4qi_v4hi = build_function_type_list (v4hi, v4qi, v4hi, 0);
8477 tree v4hi_ftype_v4qi_v2hi = build_function_type_list (v4hi, v4qi, v2hi, 0);
8478 tree v2si_ftype_v4qi_v2hi = build_function_type_list (v2si, v4qi, v2hi, 0);
8479 tree v4hi_ftype_v8qi_v4hi = build_function_type_list (v4hi, v8qi, v4hi, 0);
8480 tree v4hi_ftype_v4hi_v4hi = build_function_type_list (v4hi, v4hi, v4hi, 0);
8481 tree v2si_ftype_v2si_v2si = build_function_type_list (v2si, v2si, v2si, 0);
8482 tree v8qi_ftype_v8qi_v8qi = build_function_type_list (v8qi, v8qi, v8qi, 0);
8483 tree di_ftype_v8qi_v8qi_di = build_function_type_list (intDI_type_node,
8485 intDI_type_node, 0);
8486 tree di_ftype_di_di = build_function_type_list (intDI_type_node,
8488 intDI_type_node, 0);
8489 tree ptr_ftype_ptr_si = build_function_type_list (ptr_type_node,
8491 intSI_type_node, 0);
8492 tree ptr_ftype_ptr_di = build_function_type_list (ptr_type_node,
8494 intDI_type_node, 0);
8496 /* Packing and expanding vectors. */
8497 def_builtin ("__builtin_vis_fpack16", CODE_FOR_fpack16_vis, v4qi_ftype_v4hi);
8498 def_builtin ("__builtin_vis_fpack32", CODE_FOR_fpack32_vis,
8499 v8qi_ftype_v2si_v8qi);
8500 def_builtin ("__builtin_vis_fpackfix", CODE_FOR_fpackfix_vis,
8502 def_builtin ("__builtin_vis_fexpand", CODE_FOR_fexpand_vis, v4hi_ftype_v4qi);
8503 def_builtin ("__builtin_vis_fpmerge", CODE_FOR_fpmerge_vis,
8504 v8qi_ftype_v4qi_v4qi);
8506 /* Multiplications. */
8507 def_builtin ("__builtin_vis_fmul8x16", CODE_FOR_fmul8x16_vis,
8508 v4hi_ftype_v4qi_v4hi);
8509 def_builtin ("__builtin_vis_fmul8x16au", CODE_FOR_fmul8x16au_vis,
8510 v4hi_ftype_v4qi_v2hi);
8511 def_builtin ("__builtin_vis_fmul8x16al", CODE_FOR_fmul8x16al_vis,
8512 v4hi_ftype_v4qi_v2hi);
8513 def_builtin ("__builtin_vis_fmul8sux16", CODE_FOR_fmul8sux16_vis,
8514 v4hi_ftype_v8qi_v4hi);
8515 def_builtin ("__builtin_vis_fmul8ulx16", CODE_FOR_fmul8ulx16_vis,
8516 v4hi_ftype_v8qi_v4hi);
8517 def_builtin ("__builtin_vis_fmuld8sux16", CODE_FOR_fmuld8sux16_vis,
8518 v2si_ftype_v4qi_v2hi);
8519 def_builtin ("__builtin_vis_fmuld8ulx16", CODE_FOR_fmuld8ulx16_vis,
8520 v2si_ftype_v4qi_v2hi);
8522 /* Data aligning. */
8523 def_builtin ("__builtin_vis_faligndatav4hi", CODE_FOR_faligndatav4hi_vis,
8524 v4hi_ftype_v4hi_v4hi);
8525 def_builtin ("__builtin_vis_faligndatav8qi", CODE_FOR_faligndatav8qi_vis,
8526 v8qi_ftype_v8qi_v8qi);
8527 def_builtin ("__builtin_vis_faligndatav2si", CODE_FOR_faligndatav2si_vis,
8528 v2si_ftype_v2si_v2si);
8529 def_builtin ("__builtin_vis_faligndatadi", CODE_FOR_faligndatadi_vis,
8532 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrdi_vis,
8535 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrsi_vis,
8538 /* Pixel distance. */
8539 def_builtin ("__builtin_vis_pdist", CODE_FOR_pdist_vis,
8540 di_ftype_v8qi_v8qi_di);
8543 /* Handle TARGET_EXPAND_BUILTIN target hook.
8544 Expand builtin functions for sparc intrinsics. */
8547 sparc_expand_builtin (tree exp, rtx target,
8548 rtx subtarget ATTRIBUTE_UNUSED,
8549 enum machine_mode tmode ATTRIBUTE_UNUSED,
8550 int ignore ATTRIBUTE_UNUSED)
8553 call_expr_arg_iterator iter;
8554 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
8555 unsigned int icode = DECL_FUNCTION_CODE (fndecl);
8557 enum machine_mode mode[4];
8560 mode[0] = insn_data[icode].operand[0].mode;
8562 || GET_MODE (target) != mode[0]
8563 || ! (*insn_data[icode].operand[0].predicate) (target, mode[0]))
8564 op[0] = gen_reg_rtx (mode[0]);
8568 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
8571 mode[arg_count] = insn_data[icode].operand[arg_count].mode;
8572 op[arg_count] = expand_normal (arg);
8574 if (! (*insn_data[icode].operand[arg_count].predicate) (op[arg_count],
8576 op[arg_count] = copy_to_mode_reg (mode[arg_count], op[arg_count]);
8582 pat = GEN_FCN (icode) (op[0], op[1]);
8585 pat = GEN_FCN (icode) (op[0], op[1], op[2]);
8588 pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]);
8603 sparc_vis_mul8x16 (int e8, int e16)
8605 return (e8 * e16 + 128) / 256;
8608 /* Multiply the vector elements in ELTS0 to the elements in ELTS1 as specified
8609 by FNCODE. All of the elements in ELTS0 and ELTS1 lists must be integer
8610 constants. A tree list with the results of the multiplications is returned,
8611 and each element in the list is of INNER_TYPE. */
8614 sparc_handle_vis_mul8x16 (int fncode, tree inner_type, tree elts0, tree elts1)
8616 tree n_elts = NULL_TREE;
8621 case CODE_FOR_fmul8x16_vis:
8622 for (; elts0 && elts1;
8623 elts0 = TREE_CHAIN (elts0), elts1 = TREE_CHAIN (elts1))
8626 = sparc_vis_mul8x16 (TREE_INT_CST_LOW (TREE_VALUE (elts0)),
8627 TREE_INT_CST_LOW (TREE_VALUE (elts1)));
8628 n_elts = tree_cons (NULL_TREE,
8629 build_int_cst (inner_type, val),
8634 case CODE_FOR_fmul8x16au_vis:
8635 scale = TREE_INT_CST_LOW (TREE_VALUE (elts1));
8637 for (; elts0; elts0 = TREE_CHAIN (elts0))
8640 = sparc_vis_mul8x16 (TREE_INT_CST_LOW (TREE_VALUE (elts0)),
8642 n_elts = tree_cons (NULL_TREE,
8643 build_int_cst (inner_type, val),
8648 case CODE_FOR_fmul8x16al_vis:
8649 scale = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (elts1)));
8651 for (; elts0; elts0 = TREE_CHAIN (elts0))
8654 = sparc_vis_mul8x16 (TREE_INT_CST_LOW (TREE_VALUE (elts0)),
8656 n_elts = tree_cons (NULL_TREE,
8657 build_int_cst (inner_type, val),
8666 return nreverse (n_elts);
8669 /* Handle TARGET_FOLD_BUILTIN target hook.
8670 Fold builtin functions for SPARC intrinsics. If IGNORE is true the
8671 result of the function call is ignored. NULL_TREE is returned if the
8672 function could not be folded. */
8675 sparc_fold_builtin (tree fndecl, int n_args ATTRIBUTE_UNUSED,
8676 tree *args, bool ignore)
8678 tree arg0, arg1, arg2;
8679 tree rtype = TREE_TYPE (TREE_TYPE (fndecl));
8680 enum insn_code icode = (enum insn_code) DECL_FUNCTION_CODE (fndecl);
8683 && icode != CODE_FOR_alignaddrsi_vis
8684 && icode != CODE_FOR_alignaddrdi_vis)
8685 return fold_convert (rtype, integer_zero_node);
8689 case CODE_FOR_fexpand_vis:
8693 if (TREE_CODE (arg0) == VECTOR_CST)
8695 tree inner_type = TREE_TYPE (rtype);
8696 tree elts = TREE_VECTOR_CST_ELTS (arg0);
8697 tree n_elts = NULL_TREE;
8699 for (; elts; elts = TREE_CHAIN (elts))
8701 unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (elts)) << 4;
8702 n_elts = tree_cons (NULL_TREE,
8703 build_int_cst (inner_type, val),
8706 return build_vector (rtype, nreverse (n_elts));
8710 case CODE_FOR_fmul8x16_vis:
8711 case CODE_FOR_fmul8x16au_vis:
8712 case CODE_FOR_fmul8x16al_vis:
8718 if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)
8720 tree inner_type = TREE_TYPE (rtype);
8721 tree elts0 = TREE_VECTOR_CST_ELTS (arg0);
8722 tree elts1 = TREE_VECTOR_CST_ELTS (arg1);
8723 tree n_elts = sparc_handle_vis_mul8x16 (icode, inner_type, elts0,
8726 return build_vector (rtype, n_elts);
8730 case CODE_FOR_fpmerge_vis:
8736 if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)
8738 tree elts0 = TREE_VECTOR_CST_ELTS (arg0);
8739 tree elts1 = TREE_VECTOR_CST_ELTS (arg1);
8740 tree n_elts = NULL_TREE;
8742 for (; elts0 && elts1;
8743 elts0 = TREE_CHAIN (elts0), elts1 = TREE_CHAIN (elts1))
8745 n_elts = tree_cons (NULL_TREE, TREE_VALUE (elts0), n_elts);
8746 n_elts = tree_cons (NULL_TREE, TREE_VALUE (elts1), n_elts);
8749 return build_vector (rtype, nreverse (n_elts));
8753 case CODE_FOR_pdist_vis:
8761 if (TREE_CODE (arg0) == VECTOR_CST
8762 && TREE_CODE (arg1) == VECTOR_CST
8763 && TREE_CODE (arg2) == INTEGER_CST)
8766 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (arg2);
8767 HOST_WIDE_INT high = TREE_INT_CST_HIGH (arg2);
8768 tree elts0 = TREE_VECTOR_CST_ELTS (arg0);
8769 tree elts1 = TREE_VECTOR_CST_ELTS (arg1);
8771 for (; elts0 && elts1;
8772 elts0 = TREE_CHAIN (elts0), elts1 = TREE_CHAIN (elts1))
8774 unsigned HOST_WIDE_INT
8775 low0 = TREE_INT_CST_LOW (TREE_VALUE (elts0)),
8776 low1 = TREE_INT_CST_LOW (TREE_VALUE (elts1));
8777 HOST_WIDE_INT high0 = TREE_INT_CST_HIGH (TREE_VALUE (elts0));
8778 HOST_WIDE_INT high1 = TREE_INT_CST_HIGH (TREE_VALUE (elts1));
8780 unsigned HOST_WIDE_INT l;
8783 overflow |= neg_double (low1, high1, &l, &h);
8784 overflow |= add_double (low0, high0, l, h, &l, &h);
8786 overflow |= neg_double (l, h, &l, &h);
8788 overflow |= add_double (low, high, l, h, &low, &high);
8791 gcc_assert (overflow == 0);
8793 return build_int_cst_wide (rtype, low, high);
8803 /* ??? This duplicates information provided to the compiler by the
8804 ??? scheduler description. Some day, teach genautomata to output
8805 ??? the latencies and then CSE will just use that. */
8808 sparc_rtx_costs (rtx x, int code, int outer_code, int *total,
8809 bool speed ATTRIBUTE_UNUSED)
8811 enum machine_mode mode = GET_MODE (x);
8812 bool float_mode_p = FLOAT_MODE_P (mode);
8817 if (INTVAL (x) < 0x1000 && INTVAL (x) >= -0x1000)
8835 if (GET_MODE (x) == VOIDmode
8836 && ((CONST_DOUBLE_HIGH (x) == 0
8837 && CONST_DOUBLE_LOW (x) < 0x1000)
8838 || (CONST_DOUBLE_HIGH (x) == -1
8839 && CONST_DOUBLE_LOW (x) < 0
8840 && CONST_DOUBLE_LOW (x) >= -0x1000)))
8847 /* If outer-code was a sign or zero extension, a cost
8848 of COSTS_N_INSNS (1) was already added in. This is
8849 why we are subtracting it back out. */
8850 if (outer_code == ZERO_EXTEND)
8852 *total = sparc_costs->int_zload - COSTS_N_INSNS (1);
8854 else if (outer_code == SIGN_EXTEND)
8856 *total = sparc_costs->int_sload - COSTS_N_INSNS (1);
8858 else if (float_mode_p)
8860 *total = sparc_costs->float_load;
8864 *total = sparc_costs->int_load;
8872 *total = sparc_costs->float_plusminus;
8874 *total = COSTS_N_INSNS (1);
8879 *total = sparc_costs->float_mul;
8880 else if (! TARGET_HARD_MUL)
8881 *total = COSTS_N_INSNS (25);
8887 if (sparc_costs->int_mul_bit_factor)
8891 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
8893 unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
8894 for (nbits = 0; value != 0; value &= value - 1)
8897 else if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
8898 && GET_MODE (XEXP (x, 1)) == VOIDmode)
8900 rtx x1 = XEXP (x, 1);
8901 unsigned HOST_WIDE_INT value1 = CONST_DOUBLE_LOW (x1);
8902 unsigned HOST_WIDE_INT value2 = CONST_DOUBLE_HIGH (x1);
8904 for (nbits = 0; value1 != 0; value1 &= value1 - 1)
8906 for (; value2 != 0; value2 &= value2 - 1)
8914 bit_cost = (nbits - 3) / sparc_costs->int_mul_bit_factor;
8915 bit_cost = COSTS_N_INSNS (bit_cost);
8919 *total = sparc_costs->int_mulX + bit_cost;
8921 *total = sparc_costs->int_mul + bit_cost;
8928 *total = COSTS_N_INSNS (1) + sparc_costs->shift_penalty;
8938 *total = sparc_costs->float_div_df;
8940 *total = sparc_costs->float_div_sf;
8945 *total = sparc_costs->int_divX;
8947 *total = sparc_costs->int_div;
8954 *total = COSTS_N_INSNS (1);
8961 case UNSIGNED_FLOAT:
8965 case FLOAT_TRUNCATE:
8966 *total = sparc_costs->float_move;
8971 *total = sparc_costs->float_sqrt_df;
8973 *total = sparc_costs->float_sqrt_sf;
8978 *total = sparc_costs->float_cmp;
8980 *total = COSTS_N_INSNS (1);
8985 *total = sparc_costs->float_cmove;
8987 *total = sparc_costs->int_cmove;
8991 /* Handle the NAND vector patterns. */
8992 if (sparc_vector_mode_supported_p (GET_MODE (x))
8993 && GET_CODE (XEXP (x, 0)) == NOT
8994 && GET_CODE (XEXP (x, 1)) == NOT)
8996 *total = COSTS_N_INSNS (1);
9007 /* Emit the sequence of insns SEQ while preserving the registers REG and REG2.
9008 This is achieved by means of a manual dynamic stack space allocation in
9009 the current frame. We make the assumption that SEQ doesn't contain any
9010 function calls, with the possible exception of calls to the PIC helper. */
9013 emit_and_preserve (rtx seq, rtx reg, rtx reg2)
9015 /* We must preserve the lowest 16 words for the register save area. */
9016 HOST_WIDE_INT offset = 16*UNITS_PER_WORD;
9017 /* We really need only 2 words of fresh stack space. */
9018 HOST_WIDE_INT size = SPARC_STACK_ALIGN (offset + 2*UNITS_PER_WORD);
9021 = gen_rtx_MEM (word_mode, plus_constant (stack_pointer_rtx,
9022 SPARC_STACK_BIAS + offset));
9024 emit_insn (gen_stack_pointer_dec (GEN_INT (size)));
9025 emit_insn (gen_rtx_SET (VOIDmode, slot, reg));
9027 emit_insn (gen_rtx_SET (VOIDmode,
9028 adjust_address (slot, word_mode, UNITS_PER_WORD),
9032 emit_insn (gen_rtx_SET (VOIDmode,
9034 adjust_address (slot, word_mode, UNITS_PER_WORD)));
9035 emit_insn (gen_rtx_SET (VOIDmode, reg, slot));
9036 emit_insn (gen_stack_pointer_inc (GEN_INT (size)));
9039 /* Output the assembler code for a thunk function. THUNK_DECL is the
9040 declaration for the thunk function itself, FUNCTION is the decl for
9041 the target function. DELTA is an immediate constant offset to be
9042 added to THIS. If VCALL_OFFSET is nonzero, the word at address
9043 (*THIS + VCALL_OFFSET) should be additionally added to THIS. */
9046 sparc_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
9047 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
9050 rtx this_rtx, insn, funexp;
9051 unsigned int int_arg_first;
9053 reload_completed = 1;
9054 epilogue_completed = 1;
9056 emit_note (NOTE_INSN_PROLOGUE_END);
9058 if (flag_delayed_branch)
9060 /* We will emit a regular sibcall below, so we need to instruct
9061 output_sibcall that we are in a leaf function. */
9062 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 1;
9064 /* This will cause final.c to invoke leaf_renumber_regs so we
9065 must behave as if we were in a not-yet-leafified function. */
9066 int_arg_first = SPARC_INCOMING_INT_ARG_FIRST;
9070 /* We will emit the sibcall manually below, so we will need to
9071 manually spill non-leaf registers. */
9072 sparc_leaf_function_p = current_function_uses_only_leaf_regs = 0;
9074 /* We really are in a leaf function. */
9075 int_arg_first = SPARC_OUTGOING_INT_ARG_FIRST;
9078 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
9079 returns a structure, the structure return pointer is there instead. */
9081 && aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
9082 this_rtx = gen_rtx_REG (Pmode, int_arg_first + 1);
9084 this_rtx = gen_rtx_REG (Pmode, int_arg_first);
9086 /* Add DELTA. When possible use a plain add, otherwise load it into
9087 a register first. */
9090 rtx delta_rtx = GEN_INT (delta);
9092 if (! SPARC_SIMM13_P (delta))
9094 rtx scratch = gen_rtx_REG (Pmode, 1);
9095 emit_move_insn (scratch, delta_rtx);
9096 delta_rtx = scratch;
9099 /* THIS_RTX += DELTA. */
9100 emit_insn (gen_add2_insn (this_rtx, delta_rtx));
9103 /* Add the word at address (*THIS_RTX + VCALL_OFFSET). */
9106 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
9107 rtx scratch = gen_rtx_REG (Pmode, 1);
9109 gcc_assert (vcall_offset < 0);
9111 /* SCRATCH = *THIS_RTX. */
9112 emit_move_insn (scratch, gen_rtx_MEM (Pmode, this_rtx));
9114 /* Prepare for adding VCALL_OFFSET. The difficulty is that we
9115 may not have any available scratch register at this point. */
9116 if (SPARC_SIMM13_P (vcall_offset))
9118 /* This is the case if ARCH64 (unless -ffixed-g5 is passed). */
9119 else if (! fixed_regs[5]
9120 /* The below sequence is made up of at least 2 insns,
9121 while the default method may need only one. */
9122 && vcall_offset < -8192)
9124 rtx scratch2 = gen_rtx_REG (Pmode, 5);
9125 emit_move_insn (scratch2, vcall_offset_rtx);
9126 vcall_offset_rtx = scratch2;
9130 rtx increment = GEN_INT (-4096);
9132 /* VCALL_OFFSET is a negative number whose typical range can be
9133 estimated as -32768..0 in 32-bit mode. In almost all cases
9134 it is therefore cheaper to emit multiple add insns than
9135 spilling and loading the constant into a register (at least
9137 while (! SPARC_SIMM13_P (vcall_offset))
9139 emit_insn (gen_add2_insn (scratch, increment));
9140 vcall_offset += 4096;
9142 vcall_offset_rtx = GEN_INT (vcall_offset); /* cannot be 0 */
9145 /* SCRATCH = *(*THIS_RTX + VCALL_OFFSET). */
9146 emit_move_insn (scratch, gen_rtx_MEM (Pmode,
9147 gen_rtx_PLUS (Pmode,
9149 vcall_offset_rtx)));
9151 /* THIS_RTX += *(*THIS_RTX + VCALL_OFFSET). */
9152 emit_insn (gen_add2_insn (this_rtx, scratch));
9155 /* Generate a tail call to the target function. */
9156 if (! TREE_USED (function))
9158 assemble_external (function);
9159 TREE_USED (function) = 1;
9161 funexp = XEXP (DECL_RTL (function), 0);
9163 if (flag_delayed_branch)
9165 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
9166 insn = emit_call_insn (gen_sibcall (funexp));
9167 SIBLING_CALL_P (insn) = 1;
9171 /* The hoops we have to jump through in order to generate a sibcall
9172 without using delay slots... */
9173 rtx spill_reg, spill_reg2, seq, scratch = gen_rtx_REG (Pmode, 1);
9177 spill_reg = gen_rtx_REG (word_mode, 15); /* %o7 */
9178 spill_reg2 = gen_rtx_REG (word_mode, PIC_OFFSET_TABLE_REGNUM);
9180 /* Delay emitting the PIC helper function because it needs to
9181 change the section and we are emitting assembly code. */
9182 load_pic_register (); /* clobbers %o7 */
9183 scratch = sparc_legitimize_pic_address (funexp, scratch);
9186 emit_and_preserve (seq, spill_reg, spill_reg2);
9188 else if (TARGET_ARCH32)
9190 emit_insn (gen_rtx_SET (VOIDmode,
9192 gen_rtx_HIGH (SImode, funexp)));
9193 emit_insn (gen_rtx_SET (VOIDmode,
9195 gen_rtx_LO_SUM (SImode, scratch, funexp)));
9197 else /* TARGET_ARCH64 */
9199 switch (sparc_cmodel)
9203 /* The destination can serve as a temporary. */
9204 sparc_emit_set_symbolic_const64 (scratch, funexp, scratch);
9209 /* The destination cannot serve as a temporary. */
9210 spill_reg = gen_rtx_REG (DImode, 15); /* %o7 */
9212 sparc_emit_set_symbolic_const64 (scratch, funexp, spill_reg);
9215 emit_and_preserve (seq, spill_reg, 0);
9223 emit_jump_insn (gen_indirect_jump (scratch));
9228 /* Run just enough of rest_of_compilation to get the insns emitted.
9229 There's not really enough bulk here to make other passes such as
9230 instruction scheduling worth while. Note that use_thunk calls
9231 assemble_start_function and assemble_end_function. */
9232 insn = get_insns ();
9233 insn_locators_alloc ();
9234 shorten_branches (insn);
9235 final_start_function (insn, file, 1);
9236 final (insn, file, 1);
9237 final_end_function ();
9239 reload_completed = 0;
9240 epilogue_completed = 0;
9243 /* Return true if sparc_output_mi_thunk would be able to output the
9244 assembler code for the thunk function specified by the arguments
9245 it is passed, and false otherwise. */
9247 sparc_can_output_mi_thunk (const_tree thunk_fndecl ATTRIBUTE_UNUSED,
9248 HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
9249 HOST_WIDE_INT vcall_offset,
9250 const_tree function ATTRIBUTE_UNUSED)
9252 /* Bound the loop used in the default method above. */
9253 return (vcall_offset >= -32768 || ! fixed_regs[5]);
9256 /* How to allocate a 'struct machine_function'. */
9258 static struct machine_function *
9259 sparc_init_machine_status (void)
9261 return ggc_alloc_cleared_machine_function ();
9264 /* Locate some local-dynamic symbol still in use by this function
9265 so that we can print its name in local-dynamic base patterns. */
9268 get_some_local_dynamic_name (void)
9272 if (cfun->machine->some_ld_name)
9273 return cfun->machine->some_ld_name;
9275 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
9277 && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
9278 return cfun->machine->some_ld_name;
9284 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
9289 && GET_CODE (x) == SYMBOL_REF
9290 && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
9292 cfun->machine->some_ld_name = XSTR (x, 0);
9299 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
9300 This is called from dwarf2out.c to emit call frame instructions
9301 for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
9303 sparc_dwarf_handle_frame_unspec (const char *label,
9304 rtx pattern ATTRIBUTE_UNUSED,
9305 int index ATTRIBUTE_UNUSED)
9307 gcc_assert (index == UNSPECV_SAVEW);
9308 dwarf2out_window_save (label);
9311 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
9312 We need to emit DTP-relative relocations. */
9315 sparc_output_dwarf_dtprel (FILE *file, int size, rtx x)
9320 fputs ("\t.word\t%r_tls_dtpoff32(", file);
9323 fputs ("\t.xword\t%r_tls_dtpoff64(", file);
9328 output_addr_const (file, x);
9332 /* Do whatever processing is required at the end of a file. */
9335 sparc_file_end (void)
9337 /* If need to emit the special PIC helper function, do so now. */
9338 if (pic_helper_needed)
9340 unsigned int regno = REGNO (pic_offset_table_rtx);
9341 const char *pic_name = reg_names[regno];
9343 #ifdef DWARF2_UNWIND_INFO
9347 get_pc_thunk_name (name, regno);
9348 if (USE_HIDDEN_LINKONCE)
9350 tree decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
9351 get_identifier (name),
9352 build_function_type (void_type_node,
9354 DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
9355 NULL_TREE, void_type_node);
9356 TREE_STATIC (decl) = 1;
9357 make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
9358 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
9359 DECL_VISIBILITY_SPECIFIED (decl) = 1;
9360 allocate_struct_function (decl, true);
9361 current_function_decl = decl;
9362 init_varasm_status ();
9363 assemble_start_function (decl, name);
9367 const int align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
9368 switch_to_section (text_section);
9370 ASM_OUTPUT_ALIGN (asm_out_file, align);
9371 ASM_OUTPUT_LABEL (asm_out_file, name);
9374 #ifdef DWARF2_UNWIND_INFO
9375 do_cfi = dwarf2out_do_cfi_asm ();
9377 fprintf (asm_out_file, "\t.cfi_startproc\n");
9379 if (flag_delayed_branch)
9380 fprintf (asm_out_file, "\tjmp\t%%o7+8\n\t add\t%%o7, %s, %s\n",
9381 pic_name, pic_name);
9383 fprintf (asm_out_file, "\tadd\t%%o7, %s, %s\n\tjmp\t%%o7+8\n\t nop\n",
9384 pic_name, pic_name);
9385 #ifdef DWARF2_UNWIND_INFO
9387 fprintf (asm_out_file, "\t.cfi_endproc\n");
9391 if (NEED_INDICATE_EXEC_STACK)
9392 file_end_indicate_exec_stack ();
9395 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
9396 /* Implement TARGET_MANGLE_TYPE. */
9399 sparc_mangle_type (const_tree type)
9402 && TYPE_MAIN_VARIANT (type) == long_double_type_node
9403 && TARGET_LONG_DOUBLE_128)
9406 /* For all other types, use normal C++ mangling. */
9411 /* Expand code to perform a 8 or 16-bit compare and swap by doing 32-bit
9412 compare and swap on the word containing the byte or half-word. */
9415 sparc_expand_compare_and_swap_12 (rtx result, rtx mem, rtx oldval, rtx newval)
9417 rtx addr1 = force_reg (Pmode, XEXP (mem, 0));
9418 rtx addr = gen_reg_rtx (Pmode);
9419 rtx off = gen_reg_rtx (SImode);
9420 rtx oldv = gen_reg_rtx (SImode);
9421 rtx newv = gen_reg_rtx (SImode);
9422 rtx oldvalue = gen_reg_rtx (SImode);
9423 rtx newvalue = gen_reg_rtx (SImode);
9424 rtx res = gen_reg_rtx (SImode);
9425 rtx resv = gen_reg_rtx (SImode);
9426 rtx memsi, val, mask, end_label, loop_label, cc;
9428 emit_insn (gen_rtx_SET (VOIDmode, addr,
9429 gen_rtx_AND (Pmode, addr1, GEN_INT (-4))));
9431 if (Pmode != SImode)
9432 addr1 = gen_lowpart (SImode, addr1);
9433 emit_insn (gen_rtx_SET (VOIDmode, off,
9434 gen_rtx_AND (SImode, addr1, GEN_INT (3))));
9436 memsi = gen_rtx_MEM (SImode, addr);
9437 set_mem_alias_set (memsi, ALIAS_SET_MEMORY_BARRIER);
9438 MEM_VOLATILE_P (memsi) = MEM_VOLATILE_P (mem);
9440 val = force_reg (SImode, memsi);
9442 emit_insn (gen_rtx_SET (VOIDmode, off,
9443 gen_rtx_XOR (SImode, off,
9444 GEN_INT (GET_MODE (mem) == QImode
9447 emit_insn (gen_rtx_SET (VOIDmode, off,
9448 gen_rtx_ASHIFT (SImode, off, GEN_INT (3))));
9450 if (GET_MODE (mem) == QImode)
9451 mask = force_reg (SImode, GEN_INT (0xff));
9453 mask = force_reg (SImode, GEN_INT (0xffff));
9455 emit_insn (gen_rtx_SET (VOIDmode, mask,
9456 gen_rtx_ASHIFT (SImode, mask, off)));
9458 emit_insn (gen_rtx_SET (VOIDmode, val,
9459 gen_rtx_AND (SImode, gen_rtx_NOT (SImode, mask),
9462 oldval = gen_lowpart (SImode, oldval);
9463 emit_insn (gen_rtx_SET (VOIDmode, oldv,
9464 gen_rtx_ASHIFT (SImode, oldval, off)));
9466 newval = gen_lowpart_common (SImode, newval);
9467 emit_insn (gen_rtx_SET (VOIDmode, newv,
9468 gen_rtx_ASHIFT (SImode, newval, off)));
9470 emit_insn (gen_rtx_SET (VOIDmode, oldv,
9471 gen_rtx_AND (SImode, oldv, mask)));
9473 emit_insn (gen_rtx_SET (VOIDmode, newv,
9474 gen_rtx_AND (SImode, newv, mask)));
9476 end_label = gen_label_rtx ();
9477 loop_label = gen_label_rtx ();
9478 emit_label (loop_label);
9480 emit_insn (gen_rtx_SET (VOIDmode, oldvalue,
9481 gen_rtx_IOR (SImode, oldv, val)));
9483 emit_insn (gen_rtx_SET (VOIDmode, newvalue,
9484 gen_rtx_IOR (SImode, newv, val)));
9486 emit_insn (gen_sync_compare_and_swapsi (res, memsi, oldvalue, newvalue));
9488 emit_cmp_and_jump_insns (res, oldvalue, EQ, NULL, SImode, 0, end_label);
9490 emit_insn (gen_rtx_SET (VOIDmode, resv,
9491 gen_rtx_AND (SImode, gen_rtx_NOT (SImode, mask),
9494 cc = gen_compare_reg_1 (NE, resv, val);
9495 emit_insn (gen_rtx_SET (VOIDmode, val, resv));
9497 /* Use cbranchcc4 to separate the compare and branch! */
9498 emit_jump_insn (gen_cbranchcc4 (gen_rtx_NE (VOIDmode, cc, const0_rtx),
9499 cc, const0_rtx, loop_label));
9501 emit_label (end_label);
9503 emit_insn (gen_rtx_SET (VOIDmode, res,
9504 gen_rtx_AND (SImode, res, mask)));
9506 emit_insn (gen_rtx_SET (VOIDmode, res,
9507 gen_rtx_LSHIFTRT (SImode, res, off)));
9509 emit_move_insn (result, gen_lowpart (GET_MODE (result), res));
9512 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
9515 sparc_frame_pointer_required (void)
9517 return !(leaf_function_p () && only_leaf_regs_used ());
9520 /* The way this is structured, we can't eliminate SFP in favor of SP
9521 if the frame pointer is required: we want to use the SFP->HFP elimination
9522 in that case. But the test in update_eliminables doesn't know we are
9523 assuming below that we only do the former elimination. */
9526 sparc_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
9528 return (to == HARD_FRAME_POINTER_REGNUM
9529 || !targetm.frame_pointer_required ());
9532 #include "gt-sparc.h"