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"
49 #include "target-def.h"
50 #include "cfglayout.h"
52 #include "langhooks.h"
56 #include "dwarf2out.h"
60 struct processor_costs cypress_costs = {
61 COSTS_N_INSNS (2), /* int load */
62 COSTS_N_INSNS (2), /* int signed load */
63 COSTS_N_INSNS (2), /* int zeroed load */
64 COSTS_N_INSNS (2), /* float load */
65 COSTS_N_INSNS (5), /* fmov, fneg, fabs */
66 COSTS_N_INSNS (5), /* fadd, fsub */
67 COSTS_N_INSNS (1), /* fcmp */
68 COSTS_N_INSNS (1), /* fmov, fmovr */
69 COSTS_N_INSNS (7), /* fmul */
70 COSTS_N_INSNS (37), /* fdivs */
71 COSTS_N_INSNS (37), /* fdivd */
72 COSTS_N_INSNS (63), /* fsqrts */
73 COSTS_N_INSNS (63), /* fsqrtd */
74 COSTS_N_INSNS (1), /* imul */
75 COSTS_N_INSNS (1), /* imulX */
76 0, /* imul bit factor */
77 COSTS_N_INSNS (1), /* idiv */
78 COSTS_N_INSNS (1), /* idivX */
79 COSTS_N_INSNS (1), /* movcc/movr */
80 0, /* shift penalty */
84 struct processor_costs supersparc_costs = {
85 COSTS_N_INSNS (1), /* int load */
86 COSTS_N_INSNS (1), /* int signed load */
87 COSTS_N_INSNS (1), /* int zeroed load */
88 COSTS_N_INSNS (0), /* float load */
89 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
90 COSTS_N_INSNS (3), /* fadd, fsub */
91 COSTS_N_INSNS (3), /* fcmp */
92 COSTS_N_INSNS (1), /* fmov, fmovr */
93 COSTS_N_INSNS (3), /* fmul */
94 COSTS_N_INSNS (6), /* fdivs */
95 COSTS_N_INSNS (9), /* fdivd */
96 COSTS_N_INSNS (12), /* fsqrts */
97 COSTS_N_INSNS (12), /* fsqrtd */
98 COSTS_N_INSNS (4), /* imul */
99 COSTS_N_INSNS (4), /* imulX */
100 0, /* imul bit factor */
101 COSTS_N_INSNS (4), /* idiv */
102 COSTS_N_INSNS (4), /* idivX */
103 COSTS_N_INSNS (1), /* movcc/movr */
104 1, /* shift penalty */
108 struct processor_costs hypersparc_costs = {
109 COSTS_N_INSNS (1), /* int load */
110 COSTS_N_INSNS (1), /* int signed load */
111 COSTS_N_INSNS (1), /* int zeroed load */
112 COSTS_N_INSNS (1), /* float load */
113 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
114 COSTS_N_INSNS (1), /* fadd, fsub */
115 COSTS_N_INSNS (1), /* fcmp */
116 COSTS_N_INSNS (1), /* fmov, fmovr */
117 COSTS_N_INSNS (1), /* fmul */
118 COSTS_N_INSNS (8), /* fdivs */
119 COSTS_N_INSNS (12), /* fdivd */
120 COSTS_N_INSNS (17), /* fsqrts */
121 COSTS_N_INSNS (17), /* fsqrtd */
122 COSTS_N_INSNS (17), /* imul */
123 COSTS_N_INSNS (17), /* imulX */
124 0, /* imul bit factor */
125 COSTS_N_INSNS (17), /* idiv */
126 COSTS_N_INSNS (17), /* idivX */
127 COSTS_N_INSNS (1), /* movcc/movr */
128 0, /* shift penalty */
132 struct processor_costs sparclet_costs = {
133 COSTS_N_INSNS (3), /* int load */
134 COSTS_N_INSNS (3), /* int signed load */
135 COSTS_N_INSNS (1), /* int zeroed load */
136 COSTS_N_INSNS (1), /* float load */
137 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
138 COSTS_N_INSNS (1), /* fadd, fsub */
139 COSTS_N_INSNS (1), /* fcmp */
140 COSTS_N_INSNS (1), /* fmov, fmovr */
141 COSTS_N_INSNS (1), /* fmul */
142 COSTS_N_INSNS (1), /* fdivs */
143 COSTS_N_INSNS (1), /* fdivd */
144 COSTS_N_INSNS (1), /* fsqrts */
145 COSTS_N_INSNS (1), /* fsqrtd */
146 COSTS_N_INSNS (5), /* imul */
147 COSTS_N_INSNS (5), /* imulX */
148 0, /* imul bit factor */
149 COSTS_N_INSNS (5), /* idiv */
150 COSTS_N_INSNS (5), /* idivX */
151 COSTS_N_INSNS (1), /* movcc/movr */
152 0, /* shift penalty */
156 struct processor_costs ultrasparc_costs = {
157 COSTS_N_INSNS (2), /* int load */
158 COSTS_N_INSNS (3), /* int signed load */
159 COSTS_N_INSNS (2), /* int zeroed load */
160 COSTS_N_INSNS (2), /* float load */
161 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
162 COSTS_N_INSNS (4), /* fadd, fsub */
163 COSTS_N_INSNS (1), /* fcmp */
164 COSTS_N_INSNS (2), /* fmov, fmovr */
165 COSTS_N_INSNS (4), /* fmul */
166 COSTS_N_INSNS (13), /* fdivs */
167 COSTS_N_INSNS (23), /* fdivd */
168 COSTS_N_INSNS (13), /* fsqrts */
169 COSTS_N_INSNS (23), /* fsqrtd */
170 COSTS_N_INSNS (4), /* imul */
171 COSTS_N_INSNS (4), /* imulX */
172 2, /* imul bit factor */
173 COSTS_N_INSNS (37), /* idiv */
174 COSTS_N_INSNS (68), /* idivX */
175 COSTS_N_INSNS (2), /* movcc/movr */
176 2, /* shift penalty */
180 struct processor_costs ultrasparc3_costs = {
181 COSTS_N_INSNS (2), /* int load */
182 COSTS_N_INSNS (3), /* int signed load */
183 COSTS_N_INSNS (3), /* int zeroed load */
184 COSTS_N_INSNS (2), /* float load */
185 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
186 COSTS_N_INSNS (4), /* fadd, fsub */
187 COSTS_N_INSNS (5), /* fcmp */
188 COSTS_N_INSNS (3), /* fmov, fmovr */
189 COSTS_N_INSNS (4), /* fmul */
190 COSTS_N_INSNS (17), /* fdivs */
191 COSTS_N_INSNS (20), /* fdivd */
192 COSTS_N_INSNS (20), /* fsqrts */
193 COSTS_N_INSNS (29), /* fsqrtd */
194 COSTS_N_INSNS (6), /* imul */
195 COSTS_N_INSNS (6), /* imulX */
196 0, /* imul bit factor */
197 COSTS_N_INSNS (40), /* idiv */
198 COSTS_N_INSNS (71), /* idivX */
199 COSTS_N_INSNS (2), /* movcc/movr */
200 0, /* shift penalty */
204 struct processor_costs niagara_costs = {
205 COSTS_N_INSNS (3), /* int load */
206 COSTS_N_INSNS (3), /* int signed load */
207 COSTS_N_INSNS (3), /* int zeroed load */
208 COSTS_N_INSNS (9), /* float load */
209 COSTS_N_INSNS (8), /* fmov, fneg, fabs */
210 COSTS_N_INSNS (8), /* fadd, fsub */
211 COSTS_N_INSNS (26), /* fcmp */
212 COSTS_N_INSNS (8), /* fmov, fmovr */
213 COSTS_N_INSNS (29), /* fmul */
214 COSTS_N_INSNS (54), /* fdivs */
215 COSTS_N_INSNS (83), /* fdivd */
216 COSTS_N_INSNS (100), /* fsqrts - not implemented in hardware */
217 COSTS_N_INSNS (100), /* fsqrtd - not implemented in hardware */
218 COSTS_N_INSNS (11), /* imul */
219 COSTS_N_INSNS (11), /* imulX */
220 0, /* imul bit factor */
221 COSTS_N_INSNS (72), /* idiv */
222 COSTS_N_INSNS (72), /* idivX */
223 COSTS_N_INSNS (1), /* movcc/movr */
224 0, /* shift penalty */
228 struct processor_costs niagara2_costs = {
229 COSTS_N_INSNS (3), /* int load */
230 COSTS_N_INSNS (3), /* int signed load */
231 COSTS_N_INSNS (3), /* int zeroed load */
232 COSTS_N_INSNS (3), /* float load */
233 COSTS_N_INSNS (6), /* fmov, fneg, fabs */
234 COSTS_N_INSNS (6), /* fadd, fsub */
235 COSTS_N_INSNS (6), /* fcmp */
236 COSTS_N_INSNS (6), /* fmov, fmovr */
237 COSTS_N_INSNS (6), /* fmul */
238 COSTS_N_INSNS (19), /* fdivs */
239 COSTS_N_INSNS (33), /* fdivd */
240 COSTS_N_INSNS (19), /* fsqrts */
241 COSTS_N_INSNS (33), /* fsqrtd */
242 COSTS_N_INSNS (5), /* imul */
243 COSTS_N_INSNS (5), /* imulX */
244 0, /* imul bit factor */
245 COSTS_N_INSNS (31), /* idiv, average of 12 - 41 cycle range */
246 COSTS_N_INSNS (31), /* idivX, average of 12 - 41 cycle range */
247 COSTS_N_INSNS (1), /* movcc/movr */
248 0, /* shift penalty */
251 const struct processor_costs *sparc_costs = &cypress_costs;
253 #ifdef HAVE_AS_RELAX_OPTION
254 /* If 'as' and 'ld' are relaxing tail call insns into branch always, use
255 "or %o7,%g0,X; call Y; or X,%g0,%o7" always, so that it can be optimized.
256 With sethi/jmp, neither 'as' nor 'ld' has an easy way how to find out if
257 somebody does not branch between the sethi and jmp. */
258 #define LEAF_SIBCALL_SLOT_RESERVED_P 1
260 #define LEAF_SIBCALL_SLOT_RESERVED_P \
261 ((TARGET_ARCH64 && !TARGET_CM_MEDLOW) || flag_pic)
264 /* Global variables for machine-dependent things. */
266 /* Size of frame. Need to know this to emit return insns from leaf procedures.
267 ACTUAL_FSIZE is set by sparc_compute_frame_size() which is called during the
268 reload pass. This is important as the value is later used for scheduling
269 (to see what can go in a delay slot).
270 APPARENT_FSIZE is the size of the stack less the register save area and less
271 the outgoing argument area. It is used when saving call preserved regs. */
272 static HOST_WIDE_INT apparent_fsize;
273 static HOST_WIDE_INT actual_fsize;
275 /* Number of live general or floating point registers needed to be
276 saved (as 4-byte quantities). */
277 static int num_gfregs;
279 /* The alias set for prologue/epilogue register save/restore. */
280 static GTY(()) alias_set_type sparc_sr_alias_set;
282 /* The alias set for the structure return value. */
283 static GTY(()) alias_set_type struct_value_alias_set;
285 /* Vector to say how input registers are mapped to output registers.
286 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
287 eliminate it. You must use -fomit-frame-pointer to get that. */
288 char leaf_reg_remap[] =
289 { 0, 1, 2, 3, 4, 5, 6, 7,
290 -1, -1, -1, -1, -1, -1, 14, -1,
291 -1, -1, -1, -1, -1, -1, -1, -1,
292 8, 9, 10, 11, 12, 13, -1, 15,
294 32, 33, 34, 35, 36, 37, 38, 39,
295 40, 41, 42, 43, 44, 45, 46, 47,
296 48, 49, 50, 51, 52, 53, 54, 55,
297 56, 57, 58, 59, 60, 61, 62, 63,
298 64, 65, 66, 67, 68, 69, 70, 71,
299 72, 73, 74, 75, 76, 77, 78, 79,
300 80, 81, 82, 83, 84, 85, 86, 87,
301 88, 89, 90, 91, 92, 93, 94, 95,
302 96, 97, 98, 99, 100};
304 /* Vector, indexed by hard register number, which contains 1
305 for a register that is allowable in a candidate for leaf
306 function treatment. */
307 char sparc_leaf_regs[] =
308 { 1, 1, 1, 1, 1, 1, 1, 1,
309 0, 0, 0, 0, 0, 0, 1, 0,
310 0, 0, 0, 0, 0, 0, 0, 0,
311 1, 1, 1, 1, 1, 1, 0, 1,
312 1, 1, 1, 1, 1, 1, 1, 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,
322 struct GTY(()) machine_function
324 /* Some local-dynamic TLS symbol name. */
325 const char *some_ld_name;
327 /* True if the current function is leaf and uses only leaf regs,
328 so that the SPARC leaf function optimization can be applied.
329 Private version of current_function_uses_only_leaf_regs, see
330 sparc_expand_prologue for the rationale. */
333 /* True if the data calculated by sparc_expand_prologue are valid. */
334 bool prologue_data_valid_p;
337 #define sparc_leaf_function_p cfun->machine->leaf_function_p
338 #define sparc_prologue_data_valid_p cfun->machine->prologue_data_valid_p
340 /* Register we pretend to think the frame pointer is allocated to.
341 Normally, this is %fp, but if we are in a leaf procedure, this
342 is %sp+"something". We record "something" separately as it may
343 be too big for reg+constant addressing. */
344 static rtx frame_base_reg;
345 static HOST_WIDE_INT frame_base_offset;
347 /* 1 if the next opcode is to be specially indented. */
348 int sparc_indent_opcode = 0;
350 static bool sparc_handle_option (size_t, const char *, int);
351 static void sparc_option_override (void);
352 static void sparc_init_modes (void);
353 static void scan_record_type (const_tree, int *, int *, int *);
354 static int function_arg_slotno (const CUMULATIVE_ARGS *, enum machine_mode,
355 const_tree, bool, bool, 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 rtx sparc_function_value (const_tree, const_tree, bool);
408 static rtx sparc_libcall_value (enum machine_mode, const_rtx);
409 static bool sparc_function_value_regno_p (const unsigned int);
410 static rtx sparc_struct_value_rtx (tree, int);
411 static enum machine_mode sparc_promote_function_mode (const_tree, enum machine_mode,
412 int *, const_tree, int);
413 static bool sparc_return_in_memory (const_tree, const_tree);
414 static bool sparc_strict_argument_naming (CUMULATIVE_ARGS *);
415 static void sparc_va_start (tree, rtx);
416 static tree sparc_gimplify_va_arg (tree, tree, gimple_seq *, gimple_seq *);
417 static bool sparc_vector_mode_supported_p (enum machine_mode);
418 static bool sparc_tls_referenced_p (rtx);
419 static rtx sparc_legitimize_tls_address (rtx);
420 static rtx sparc_legitimize_pic_address (rtx, rtx);
421 static rtx sparc_legitimize_address (rtx, rtx, enum machine_mode);
422 static rtx sparc_delegitimize_address (rtx);
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 void sparc_function_arg_advance (CUMULATIVE_ARGS *,
427 enum machine_mode, const_tree, bool);
428 static rtx sparc_function_arg_1 (const CUMULATIVE_ARGS *,
429 enum machine_mode, const_tree, bool, bool);
430 static rtx sparc_function_arg (CUMULATIVE_ARGS *,
431 enum machine_mode, const_tree, bool);
432 static rtx sparc_function_incoming_arg (CUMULATIVE_ARGS *,
433 enum machine_mode, const_tree, bool);
434 static unsigned int sparc_function_arg_boundary (enum machine_mode,
436 static int sparc_arg_partial_bytes (CUMULATIVE_ARGS *,
437 enum machine_mode, tree, bool);
438 static void sparc_dwarf_handle_frame_unspec (const char *, rtx, int);
439 static void sparc_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
440 static void sparc_file_end (void);
441 static bool sparc_frame_pointer_required (void);
442 static bool sparc_can_eliminate (const int, const int);
443 static void sparc_conditional_register_usage (void);
444 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
445 static const char *sparc_mangle_type (const_tree);
447 static void sparc_trampoline_init (rtx, tree, rtx);
448 static enum machine_mode sparc_preferred_simd_mode (enum machine_mode);
450 #ifdef SUBTARGET_ATTRIBUTE_TABLE
451 /* Table of valid machine attributes. */
452 static const struct attribute_spec sparc_attribute_table[] =
454 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
455 SUBTARGET_ATTRIBUTE_TABLE,
456 { NULL, 0, 0, false, false, false, NULL }
460 /* Option handling. */
463 enum cmodel sparc_cmodel;
465 char sparc_hard_reg_printed[8];
467 struct sparc_cpu_select sparc_select[] =
469 /* switch name, tune arch */
470 { (char *)0, "default", 1, 1 },
471 { (char *)0, "-mcpu=", 1, 1 },
472 { (char *)0, "-mtune=", 1, 0 },
476 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
477 enum processor_type sparc_cpu;
479 /* Whether
\fan FPU option was specified. */
480 static bool fpu_option_set = false;
482 /* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
483 static const struct default_options sparc_option_optimization_table[] =
485 { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 },
486 { OPT_LEVELS_NONE, 0, NULL, 0 }
489 /* Initialize the GCC target structure. */
491 /* The default is to use .half rather than .short for aligned HI objects. */
492 #undef TARGET_ASM_ALIGNED_HI_OP
493 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
495 #undef TARGET_ASM_UNALIGNED_HI_OP
496 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
497 #undef TARGET_ASM_UNALIGNED_SI_OP
498 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
499 #undef TARGET_ASM_UNALIGNED_DI_OP
500 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
502 /* The target hook has to handle DI-mode values. */
503 #undef TARGET_ASM_INTEGER
504 #define TARGET_ASM_INTEGER sparc_assemble_integer
506 #undef TARGET_ASM_FUNCTION_PROLOGUE
507 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
508 #undef TARGET_ASM_FUNCTION_EPILOGUE
509 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
511 #undef TARGET_SCHED_ADJUST_COST
512 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
513 #undef TARGET_SCHED_ISSUE_RATE
514 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
515 #undef TARGET_SCHED_INIT
516 #define TARGET_SCHED_INIT sparc_sched_init
517 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
518 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
520 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
521 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
523 #undef TARGET_INIT_LIBFUNCS
524 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
525 #undef TARGET_INIT_BUILTINS
526 #define TARGET_INIT_BUILTINS sparc_init_builtins
528 #undef TARGET_LEGITIMIZE_ADDRESS
529 #define TARGET_LEGITIMIZE_ADDRESS sparc_legitimize_address
530 #undef TARGET_DELEGITIMIZE_ADDRESS
531 #define TARGET_DELEGITIMIZE_ADDRESS sparc_delegitimize_address
532 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
533 #define TARGET_MODE_DEPENDENT_ADDRESS_P sparc_mode_dependent_address_p
535 #undef TARGET_EXPAND_BUILTIN
536 #define TARGET_EXPAND_BUILTIN sparc_expand_builtin
537 #undef TARGET_FOLD_BUILTIN
538 #define TARGET_FOLD_BUILTIN sparc_fold_builtin
541 #undef TARGET_HAVE_TLS
542 #define TARGET_HAVE_TLS true
545 #undef TARGET_CANNOT_FORCE_CONST_MEM
546 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
548 #undef TARGET_ASM_OUTPUT_MI_THUNK
549 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
550 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
551 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
553 #undef TARGET_RTX_COSTS
554 #define TARGET_RTX_COSTS sparc_rtx_costs
555 #undef TARGET_ADDRESS_COST
556 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
558 #undef TARGET_PROMOTE_FUNCTION_MODE
559 #define TARGET_PROMOTE_FUNCTION_MODE sparc_promote_function_mode
561 #undef TARGET_FUNCTION_VALUE
562 #define TARGET_FUNCTION_VALUE sparc_function_value
563 #undef TARGET_LIBCALL_VALUE
564 #define TARGET_LIBCALL_VALUE sparc_libcall_value
565 #undef TARGET_FUNCTION_VALUE_REGNO_P
566 #define TARGET_FUNCTION_VALUE_REGNO_P sparc_function_value_regno_p
568 #undef TARGET_STRUCT_VALUE_RTX
569 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
570 #undef TARGET_RETURN_IN_MEMORY
571 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
572 #undef TARGET_MUST_PASS_IN_STACK
573 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
574 #undef TARGET_PASS_BY_REFERENCE
575 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
576 #undef TARGET_ARG_PARTIAL_BYTES
577 #define TARGET_ARG_PARTIAL_BYTES sparc_arg_partial_bytes
578 #undef TARGET_FUNCTION_ARG_ADVANCE
579 #define TARGET_FUNCTION_ARG_ADVANCE sparc_function_arg_advance
580 #undef TARGET_FUNCTION_ARG
581 #define TARGET_FUNCTION_ARG sparc_function_arg
582 #undef TARGET_FUNCTION_INCOMING_ARG
583 #define TARGET_FUNCTION_INCOMING_ARG sparc_function_incoming_arg
584 #undef TARGET_FUNCTION_ARG_BOUNDARY
585 #define TARGET_FUNCTION_ARG_BOUNDARY sparc_function_arg_boundary
587 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
588 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
589 #undef TARGET_STRICT_ARGUMENT_NAMING
590 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
592 #undef TARGET_EXPAND_BUILTIN_VA_START
593 #define TARGET_EXPAND_BUILTIN_VA_START sparc_va_start
594 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
595 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
597 #undef TARGET_VECTOR_MODE_SUPPORTED_P
598 #define TARGET_VECTOR_MODE_SUPPORTED_P sparc_vector_mode_supported_p
600 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
601 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE sparc_preferred_simd_mode
603 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
604 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC sparc_dwarf_handle_frame_unspec
606 #ifdef SUBTARGET_INSERT_ATTRIBUTES
607 #undef TARGET_INSERT_ATTRIBUTES
608 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
611 #ifdef SUBTARGET_ATTRIBUTE_TABLE
612 #undef TARGET_ATTRIBUTE_TABLE
613 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
616 #undef TARGET_RELAXED_ORDERING
617 #define TARGET_RELAXED_ORDERING SPARC_RELAXED_ORDERING
619 #undef TARGET_DEFAULT_TARGET_FLAGS
620 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
621 #undef TARGET_HANDLE_OPTION
622 #define TARGET_HANDLE_OPTION sparc_handle_option
623 #undef TARGET_OPTION_OVERRIDE
624 #define TARGET_OPTION_OVERRIDE sparc_option_override
625 #undef TARGET_OPTION_OPTIMIZATION_TABLE
626 #define TARGET_OPTION_OPTIMIZATION_TABLE sparc_option_optimization_table
628 #if TARGET_GNU_TLS && defined(HAVE_AS_SPARC_UA_PCREL)
629 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
630 #define TARGET_ASM_OUTPUT_DWARF_DTPREL sparc_output_dwarf_dtprel
633 #undef TARGET_ASM_FILE_END
634 #define TARGET_ASM_FILE_END sparc_file_end
636 #undef TARGET_FRAME_POINTER_REQUIRED
637 #define TARGET_FRAME_POINTER_REQUIRED sparc_frame_pointer_required
639 #undef TARGET_CAN_ELIMINATE
640 #define TARGET_CAN_ELIMINATE sparc_can_eliminate
642 #undef TARGET_CONDITIONAL_REGISTER_USAGE
643 #define TARGET_CONDITIONAL_REGISTER_USAGE sparc_conditional_register_usage
645 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
646 #undef TARGET_MANGLE_TYPE
647 #define TARGET_MANGLE_TYPE sparc_mangle_type
650 #undef TARGET_LEGITIMATE_ADDRESS_P
651 #define TARGET_LEGITIMATE_ADDRESS_P sparc_legitimate_address_p
653 #undef TARGET_TRAMPOLINE_INIT
654 #define TARGET_TRAMPOLINE_INIT sparc_trampoline_init
656 struct gcc_target targetm = TARGET_INITIALIZER;
658 /* Implement TARGET_HANDLE_OPTION. */
661 sparc_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
666 case OPT_mhard_float:
667 case OPT_msoft_float:
668 fpu_option_set = true;
672 sparc_select[1].string = arg;
676 sparc_select[2].string = arg;
683 /* Validate and override various options, and do some machine dependent
687 sparc_option_override (void)
689 static struct code_model {
690 const char *const name;
691 const enum cmodel value;
692 } const cmodels[] = {
694 { "medlow", CM_MEDLOW },
695 { "medmid", CM_MEDMID },
696 { "medany", CM_MEDANY },
697 { "embmedany", CM_EMBMEDANY },
698 { NULL, (enum cmodel) 0 }
700 const struct code_model *cmodel;
701 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
702 static struct cpu_default {
704 const char *const name;
705 } const cpu_default[] = {
706 /* There must be one entry here for each TARGET_CPU value. */
707 { TARGET_CPU_sparc, "cypress" },
708 { TARGET_CPU_sparclet, "tsc701" },
709 { TARGET_CPU_sparclite, "f930" },
710 { TARGET_CPU_v8, "v8" },
711 { TARGET_CPU_hypersparc, "hypersparc" },
712 { TARGET_CPU_sparclite86x, "sparclite86x" },
713 { TARGET_CPU_supersparc, "supersparc" },
714 { TARGET_CPU_v9, "v9" },
715 { TARGET_CPU_ultrasparc, "ultrasparc" },
716 { TARGET_CPU_ultrasparc3, "ultrasparc3" },
717 { TARGET_CPU_niagara, "niagara" },
718 { TARGET_CPU_niagara2, "niagara2" },
721 const struct cpu_default *def;
722 /* Table of values for -m{cpu,tune}=. */
723 static struct cpu_table {
724 const char *const name;
725 const enum processor_type processor;
728 } const cpu_table[] = {
729 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
730 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
731 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
732 /* TI TMS390Z55 supersparc */
733 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
734 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
735 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
736 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
737 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
738 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
739 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
740 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
742 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
744 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
745 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
746 /* TI ultrasparc I, II, IIi */
747 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
748 /* Although insns using %y are deprecated, it is a clear win on current
750 |MASK_DEPRECATED_V8_INSNS},
751 /* TI ultrasparc III */
752 /* ??? Check if %y issue still holds true in ultra3. */
753 { "ultrasparc3", PROCESSOR_ULTRASPARC3, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
755 { "niagara", PROCESSOR_NIAGARA, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
756 { "niagara2", PROCESSOR_NIAGARA, MASK_ISA, MASK_V9},
757 { 0, (enum processor_type) 0, 0, 0 }
759 const struct cpu_table *cpu;
760 const struct sparc_cpu_select *sel;
763 #ifdef SUBTARGET_OVERRIDE_OPTIONS
764 SUBTARGET_OVERRIDE_OPTIONS;
767 #ifndef SPARC_BI_ARCH
768 /* Check for unsupported architecture size. */
769 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
770 error ("%s is not supported by this configuration",
771 DEFAULT_ARCH32_P ? "-m64" : "-m32");
774 /* We force all 64bit archs to use 128 bit long double */
775 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
777 error ("-mlong-double-64 not allowed with -m64");
778 target_flags |= MASK_LONG_DOUBLE_128;
781 /* Code model selection. */
782 sparc_cmodel = SPARC_DEFAULT_CMODEL;
786 sparc_cmodel = CM_32;
789 if (sparc_cmodel_string != NULL)
793 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
794 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
796 if (cmodel->name == NULL)
797 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
799 sparc_cmodel = cmodel->value;
802 error ("-mcmodel= is not supported on 32 bit systems");
805 fpu = target_flags & MASK_FPU; /* save current -mfpu status */
807 /* Set the default CPU. */
808 for (def = &cpu_default[0]; def->name; ++def)
809 if (def->cpu == TARGET_CPU_DEFAULT)
811 gcc_assert (def->name);
812 sparc_select[0].string = def->name;
814 for (sel = &sparc_select[0]; sel->name; ++sel)
818 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
819 if (! strcmp (sel->string, cpu->name))
822 sparc_cpu = cpu->processor;
826 target_flags &= ~cpu->disable;
827 target_flags |= cpu->enable;
833 error ("bad value (%s) for %s switch", sel->string, sel->name);
837 /* If -mfpu or -mno-fpu was explicitly used, don't override with
838 the processor default. */
840 target_flags = (target_flags & ~MASK_FPU) | fpu;
842 /* Don't allow -mvis if FPU is disabled. */
844 target_flags &= ~MASK_VIS;
846 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
848 -m64 also implies v9. */
849 if (TARGET_VIS || TARGET_ARCH64)
851 target_flags |= MASK_V9;
852 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
855 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
856 if (TARGET_V9 && TARGET_ARCH32)
857 target_flags |= MASK_DEPRECATED_V8_INSNS;
859 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
860 if (! TARGET_V9 || TARGET_ARCH64)
861 target_flags &= ~MASK_V8PLUS;
863 /* Don't use stack biasing in 32 bit mode. */
865 target_flags &= ~MASK_STACK_BIAS;
867 /* Supply a default value for align_functions. */
868 if (align_functions == 0
869 && (sparc_cpu == PROCESSOR_ULTRASPARC
870 || sparc_cpu == PROCESSOR_ULTRASPARC3
871 || sparc_cpu == PROCESSOR_NIAGARA
872 || sparc_cpu == PROCESSOR_NIAGARA2))
873 align_functions = 32;
875 /* Validate PCC_STRUCT_RETURN. */
876 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
877 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
879 /* Only use .uaxword when compiling for a 64-bit target. */
881 targetm.asm_out.unaligned_op.di = NULL;
883 /* Do various machine dependent initializations. */
886 /* Acquire unique alias sets for our private stuff. */
887 sparc_sr_alias_set = new_alias_set ();
888 struct_value_alias_set = new_alias_set ();
890 /* Set up function hooks. */
891 init_machine_status = sparc_init_machine_status;
896 case PROCESSOR_CYPRESS:
897 sparc_costs = &cypress_costs;
900 case PROCESSOR_SPARCLITE:
901 case PROCESSOR_SUPERSPARC:
902 sparc_costs = &supersparc_costs;
906 case PROCESSOR_HYPERSPARC:
907 case PROCESSOR_SPARCLITE86X:
908 sparc_costs = &hypersparc_costs;
910 case PROCESSOR_SPARCLET:
911 case PROCESSOR_TSC701:
912 sparc_costs = &sparclet_costs;
915 case PROCESSOR_ULTRASPARC:
916 sparc_costs = &ultrasparc_costs;
918 case PROCESSOR_ULTRASPARC3:
919 sparc_costs = &ultrasparc3_costs;
921 case PROCESSOR_NIAGARA:
922 sparc_costs = &niagara_costs;
924 case PROCESSOR_NIAGARA2:
925 sparc_costs = &niagara2_costs;
929 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
930 if (!(target_flags_explicit & MASK_LONG_DOUBLE_128))
931 target_flags |= MASK_LONG_DOUBLE_128;
934 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
935 ((sparc_cpu == PROCESSOR_ULTRASPARC
936 || sparc_cpu == PROCESSOR_NIAGARA
937 || sparc_cpu == PROCESSOR_NIAGARA2)
939 : (sparc_cpu == PROCESSOR_ULTRASPARC3
941 global_options.x_param_values,
942 global_options_set.x_param_values);
943 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
944 ((sparc_cpu == PROCESSOR_ULTRASPARC
945 || sparc_cpu == PROCESSOR_ULTRASPARC3
946 || sparc_cpu == PROCESSOR_NIAGARA
947 || sparc_cpu == PROCESSOR_NIAGARA2)
949 global_options.x_param_values,
950 global_options_set.x_param_values);
953 /* Miscellaneous utilities. */
955 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
956 or branch on register contents instructions. */
959 v9_regcmp_p (enum rtx_code code)
961 return (code == EQ || code == NE || code == GE || code == LT
962 || code == LE || code == GT);
965 /* Nonzero if OP is a floating point constant which can
966 be loaded into an integer register using a single
967 sethi instruction. */
972 if (GET_CODE (op) == CONST_DOUBLE)
977 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
978 REAL_VALUE_TO_TARGET_SINGLE (r, i);
979 return !SPARC_SIMM13_P (i) && SPARC_SETHI_P (i);
985 /* Nonzero if OP is a floating point constant which can
986 be loaded into an integer register using a single
992 if (GET_CODE (op) == CONST_DOUBLE)
997 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
998 REAL_VALUE_TO_TARGET_SINGLE (r, i);
999 return SPARC_SIMM13_P (i);
1005 /* Nonzero if OP is a floating point constant which can
1006 be loaded into an integer register using a high/losum
1007 instruction sequence. */
1010 fp_high_losum_p (rtx op)
1012 /* The constraints calling this should only be in
1013 SFmode move insns, so any constant which cannot
1014 be moved using a single insn will do. */
1015 if (GET_CODE (op) == CONST_DOUBLE)
1020 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
1021 REAL_VALUE_TO_TARGET_SINGLE (r, i);
1022 return !SPARC_SIMM13_P (i) && !SPARC_SETHI_P (i);
1028 /* Return true if the address of LABEL can be loaded by means of the
1029 mov{si,di}_pic_label_ref patterns in PIC mode. */
1032 can_use_mov_pic_label_ref (rtx label)
1034 /* VxWorks does not impose a fixed gap between segments; the run-time
1035 gap can be different from the object-file gap. We therefore can't
1036 assume X - _GLOBAL_OFFSET_TABLE_ is a link-time constant unless we
1037 are absolutely sure that X is in the same segment as the GOT.
1038 Unfortunately, the flexibility of linker scripts means that we
1039 can't be sure of that in general, so assume that GOT-relative
1040 accesses are never valid on VxWorks. */
1041 if (TARGET_VXWORKS_RTP)
1044 /* Similarly, if the label is non-local, it might end up being placed
1045 in a different section than the current one; now mov_pic_label_ref
1046 requires the label and the code to be in the same section. */
1047 if (LABEL_REF_NONLOCAL_P (label))
1050 /* Finally, if we are reordering basic blocks and partition into hot
1051 and cold sections, this might happen for any label. */
1052 if (flag_reorder_blocks_and_partition)
1058 /* Expand a move instruction. Return true if all work is done. */
1061 sparc_expand_move (enum machine_mode mode, rtx *operands)
1063 /* Handle sets of MEM first. */
1064 if (GET_CODE (operands[0]) == MEM)
1066 /* 0 is a register (or a pair of registers) on SPARC. */
1067 if (register_or_zero_operand (operands[1], mode))
1070 if (!reload_in_progress)
1072 operands[0] = validize_mem (operands[0]);
1073 operands[1] = force_reg (mode, operands[1]);
1077 /* Fixup TLS cases. */
1079 && CONSTANT_P (operands[1])
1080 && sparc_tls_referenced_p (operands [1]))
1082 operands[1] = sparc_legitimize_tls_address (operands[1]);
1086 /* Fixup PIC cases. */
1087 if (flag_pic && CONSTANT_P (operands[1]))
1089 if (pic_address_needs_scratch (operands[1]))
1090 operands[1] = sparc_legitimize_pic_address (operands[1], NULL_RTX);
1092 /* We cannot use the mov{si,di}_pic_label_ref patterns in all cases. */
1093 if (GET_CODE (operands[1]) == LABEL_REF
1094 && can_use_mov_pic_label_ref (operands[1]))
1098 emit_insn (gen_movsi_pic_label_ref (operands[0], operands[1]));
1104 gcc_assert (TARGET_ARCH64);
1105 emit_insn (gen_movdi_pic_label_ref (operands[0], operands[1]));
1110 if (symbolic_operand (operands[1], mode))
1113 = sparc_legitimize_pic_address (operands[1],
1115 ? operands[0] : NULL_RTX);
1120 /* If we are trying to toss an integer constant into FP registers,
1121 or loading a FP or vector constant, force it into memory. */
1122 if (CONSTANT_P (operands[1])
1123 && REG_P (operands[0])
1124 && (SPARC_FP_REG_P (REGNO (operands[0]))
1125 || SCALAR_FLOAT_MODE_P (mode)
1126 || VECTOR_MODE_P (mode)))
1128 /* emit_group_store will send such bogosity to us when it is
1129 not storing directly into memory. So fix this up to avoid
1130 crashes in output_constant_pool. */
1131 if (operands [1] == const0_rtx)
1132 operands[1] = CONST0_RTX (mode);
1134 /* We can clear FP registers if TARGET_VIS, and always other regs. */
1135 if ((TARGET_VIS || REGNO (operands[0]) < SPARC_FIRST_FP_REG)
1136 && const_zero_operand (operands[1], mode))
1139 if (REGNO (operands[0]) < SPARC_FIRST_FP_REG
1140 /* We are able to build any SF constant in integer registers
1141 with at most 2 instructions. */
1143 /* And any DF constant in integer registers. */
1145 && (reload_completed || reload_in_progress))))
1148 operands[1] = force_const_mem (mode, operands[1]);
1149 if (!reload_in_progress)
1150 operands[1] = validize_mem (operands[1]);
1154 /* Accept non-constants and valid constants unmodified. */
1155 if (!CONSTANT_P (operands[1])
1156 || GET_CODE (operands[1]) == HIGH
1157 || input_operand (operands[1], mode))
1163 /* All QImode constants require only one insn, so proceed. */
1168 sparc_emit_set_const32 (operands[0], operands[1]);
1172 /* input_operand should have filtered out 32-bit mode. */
1173 sparc_emit_set_const64 (operands[0], operands[1]);
1183 /* Load OP1, a 32-bit constant, into OP0, a register.
1184 We know it can't be done in one insn when we get
1185 here, the move expander guarantees this. */
1188 sparc_emit_set_const32 (rtx op0, rtx op1)
1190 enum machine_mode mode = GET_MODE (op0);
1193 if (reload_in_progress || reload_completed)
1196 temp = gen_reg_rtx (mode);
1198 if (GET_CODE (op1) == CONST_INT)
1200 gcc_assert (!small_int_operand (op1, mode)
1201 && !const_high_operand (op1, mode));
1203 /* Emit them as real moves instead of a HIGH/LO_SUM,
1204 this way CSE can see everything and reuse intermediate
1205 values if it wants. */
1206 emit_insn (gen_rtx_SET (VOIDmode, temp,
1207 GEN_INT (INTVAL (op1)
1208 & ~(HOST_WIDE_INT)0x3ff)));
1210 emit_insn (gen_rtx_SET (VOIDmode,
1212 gen_rtx_IOR (mode, temp,
1213 GEN_INT (INTVAL (op1) & 0x3ff))));
1217 /* A symbol, emit in the traditional way. */
1218 emit_insn (gen_rtx_SET (VOIDmode, temp,
1219 gen_rtx_HIGH (mode, op1)));
1220 emit_insn (gen_rtx_SET (VOIDmode,
1221 op0, gen_rtx_LO_SUM (mode, temp, op1)));
1225 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
1226 If TEMP is nonzero, we are forbidden to use any other scratch
1227 registers. Otherwise, we are allowed to generate them as needed.
1229 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
1230 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
1233 sparc_emit_set_symbolic_const64 (rtx op0, rtx op1, rtx temp)
1235 rtx temp1, temp2, temp3, temp4, temp5;
1238 if (temp && GET_MODE (temp) == TImode)
1241 temp = gen_rtx_REG (DImode, REGNO (temp));
1244 /* SPARC-V9 code-model support. */
1245 switch (sparc_cmodel)
1248 /* The range spanned by all instructions in the object is less
1249 than 2^31 bytes (2GB) and the distance from any instruction
1250 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1251 than 2^31 bytes (2GB).
1253 The executable must be in the low 4TB of the virtual address
1256 sethi %hi(symbol), %temp1
1257 or %temp1, %lo(symbol), %reg */
1259 temp1 = temp; /* op0 is allowed. */
1261 temp1 = gen_reg_rtx (DImode);
1263 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1264 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1268 /* The range spanned by all instructions in the object is less
1269 than 2^31 bytes (2GB) and the distance from any instruction
1270 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1271 than 2^31 bytes (2GB).
1273 The executable must be in the low 16TB of the virtual address
1276 sethi %h44(symbol), %temp1
1277 or %temp1, %m44(symbol), %temp2
1278 sllx %temp2, 12, %temp3
1279 or %temp3, %l44(symbol), %reg */
1284 temp3 = temp; /* op0 is allowed. */
1288 temp1 = gen_reg_rtx (DImode);
1289 temp2 = gen_reg_rtx (DImode);
1290 temp3 = gen_reg_rtx (DImode);
1293 emit_insn (gen_seth44 (temp1, op1));
1294 emit_insn (gen_setm44 (temp2, temp1, op1));
1295 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1296 gen_rtx_ASHIFT (DImode, temp2, GEN_INT (12))));
1297 emit_insn (gen_setl44 (op0, temp3, op1));
1301 /* The range spanned by all instructions in the object is less
1302 than 2^31 bytes (2GB) and the distance from any instruction
1303 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1304 than 2^31 bytes (2GB).
1306 The executable can be placed anywhere in the virtual address
1309 sethi %hh(symbol), %temp1
1310 sethi %lm(symbol), %temp2
1311 or %temp1, %hm(symbol), %temp3
1312 sllx %temp3, 32, %temp4
1313 or %temp4, %temp2, %temp5
1314 or %temp5, %lo(symbol), %reg */
1317 /* It is possible that one of the registers we got for operands[2]
1318 might coincide with that of operands[0] (which is why we made
1319 it TImode). Pick the other one to use as our scratch. */
1320 if (rtx_equal_p (temp, op0))
1322 gcc_assert (ti_temp);
1323 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1326 temp2 = temp; /* op0 is _not_ allowed, see above. */
1333 temp1 = gen_reg_rtx (DImode);
1334 temp2 = gen_reg_rtx (DImode);
1335 temp3 = gen_reg_rtx (DImode);
1336 temp4 = gen_reg_rtx (DImode);
1337 temp5 = gen_reg_rtx (DImode);
1340 emit_insn (gen_sethh (temp1, op1));
1341 emit_insn (gen_setlm (temp2, op1));
1342 emit_insn (gen_sethm (temp3, temp1, op1));
1343 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1344 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1345 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1346 gen_rtx_PLUS (DImode, temp4, temp2)));
1347 emit_insn (gen_setlo (op0, temp5, op1));
1351 /* Old old old backwards compatibility kruft here.
1352 Essentially it is MEDLOW with a fixed 64-bit
1353 virtual base added to all data segment addresses.
1354 Text-segment stuff is computed like MEDANY, we can't
1355 reuse the code above because the relocation knobs
1358 Data segment: sethi %hi(symbol), %temp1
1359 add %temp1, EMBMEDANY_BASE_REG, %temp2
1360 or %temp2, %lo(symbol), %reg */
1361 if (data_segment_operand (op1, GET_MODE (op1)))
1365 temp1 = temp; /* op0 is allowed. */
1370 temp1 = gen_reg_rtx (DImode);
1371 temp2 = gen_reg_rtx (DImode);
1374 emit_insn (gen_embmedany_sethi (temp1, op1));
1375 emit_insn (gen_embmedany_brsum (temp2, temp1));
1376 emit_insn (gen_embmedany_losum (op0, temp2, op1));
1379 /* Text segment: sethi %uhi(symbol), %temp1
1380 sethi %hi(symbol), %temp2
1381 or %temp1, %ulo(symbol), %temp3
1382 sllx %temp3, 32, %temp4
1383 or %temp4, %temp2, %temp5
1384 or %temp5, %lo(symbol), %reg */
1389 /* It is possible that one of the registers we got for operands[2]
1390 might coincide with that of operands[0] (which is why we made
1391 it TImode). Pick the other one to use as our scratch. */
1392 if (rtx_equal_p (temp, op0))
1394 gcc_assert (ti_temp);
1395 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
1398 temp2 = temp; /* op0 is _not_ allowed, see above. */
1405 temp1 = gen_reg_rtx (DImode);
1406 temp2 = gen_reg_rtx (DImode);
1407 temp3 = gen_reg_rtx (DImode);
1408 temp4 = gen_reg_rtx (DImode);
1409 temp5 = gen_reg_rtx (DImode);
1412 emit_insn (gen_embmedany_textuhi (temp1, op1));
1413 emit_insn (gen_embmedany_texthi (temp2, op1));
1414 emit_insn (gen_embmedany_textulo (temp3, temp1, op1));
1415 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1416 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
1417 emit_insn (gen_rtx_SET (VOIDmode, temp5,
1418 gen_rtx_PLUS (DImode, temp4, temp2)));
1419 emit_insn (gen_embmedany_textlo (op0, temp5, op1));
1428 #if HOST_BITS_PER_WIDE_INT == 32
1430 sparc_emit_set_const64 (rtx op0 ATTRIBUTE_UNUSED, rtx op1 ATTRIBUTE_UNUSED)
1435 /* These avoid problems when cross compiling. If we do not
1436 go through all this hair then the optimizer will see
1437 invalid REG_EQUAL notes or in some cases none at all. */
1438 static rtx gen_safe_HIGH64 (rtx, HOST_WIDE_INT);
1439 static rtx gen_safe_SET64 (rtx, HOST_WIDE_INT);
1440 static rtx gen_safe_OR64 (rtx, HOST_WIDE_INT);
1441 static rtx gen_safe_XOR64 (rtx, HOST_WIDE_INT);
1443 /* The optimizer is not to assume anything about exactly
1444 which bits are set for a HIGH, they are unspecified.
1445 Unfortunately this leads to many missed optimizations
1446 during CSE. We mask out the non-HIGH bits, and matches
1447 a plain movdi, to alleviate this problem. */
1449 gen_safe_HIGH64 (rtx dest, HOST_WIDE_INT val)
1451 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val & ~(HOST_WIDE_INT)0x3ff));
1455 gen_safe_SET64 (rtx dest, HOST_WIDE_INT val)
1457 return gen_rtx_SET (VOIDmode, dest, GEN_INT (val));
1461 gen_safe_OR64 (rtx src, HOST_WIDE_INT val)
1463 return gen_rtx_IOR (DImode, src, GEN_INT (val));
1467 gen_safe_XOR64 (rtx src, HOST_WIDE_INT val)
1469 return gen_rtx_XOR (DImode, src, GEN_INT (val));
1472 /* Worker routines for 64-bit constant formation on arch64.
1473 One of the key things to be doing in these emissions is
1474 to create as many temp REGs as possible. This makes it
1475 possible for half-built constants to be used later when
1476 such values are similar to something required later on.
1477 Without doing this, the optimizer cannot see such
1480 static void sparc_emit_set_const64_quick1 (rtx, rtx,
1481 unsigned HOST_WIDE_INT, int);
1484 sparc_emit_set_const64_quick1 (rtx op0, rtx temp,
1485 unsigned HOST_WIDE_INT low_bits, int is_neg)
1487 unsigned HOST_WIDE_INT high_bits;
1490 high_bits = (~low_bits) & 0xffffffff;
1492 high_bits = low_bits;
1494 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1497 emit_insn (gen_rtx_SET (VOIDmode, op0,
1498 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1502 /* If we are XOR'ing with -1, then we should emit a one's complement
1503 instead. This way the combiner will notice logical operations
1504 such as ANDN later on and substitute. */
1505 if ((low_bits & 0x3ff) == 0x3ff)
1507 emit_insn (gen_rtx_SET (VOIDmode, op0,
1508 gen_rtx_NOT (DImode, temp)));
1512 emit_insn (gen_rtx_SET (VOIDmode, op0,
1513 gen_safe_XOR64 (temp,
1514 (-(HOST_WIDE_INT)0x400
1515 | (low_bits & 0x3ff)))));
1520 static void sparc_emit_set_const64_quick2 (rtx, rtx, unsigned HOST_WIDE_INT,
1521 unsigned HOST_WIDE_INT, int);
1524 sparc_emit_set_const64_quick2 (rtx op0, rtx temp,
1525 unsigned HOST_WIDE_INT high_bits,
1526 unsigned HOST_WIDE_INT low_immediate,
1531 if ((high_bits & 0xfffffc00) != 0)
1533 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1534 if ((high_bits & ~0xfffffc00) != 0)
1535 emit_insn (gen_rtx_SET (VOIDmode, op0,
1536 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1542 emit_insn (gen_safe_SET64 (temp, high_bits));
1546 /* Now shift it up into place. */
1547 emit_insn (gen_rtx_SET (VOIDmode, op0,
1548 gen_rtx_ASHIFT (DImode, temp2,
1549 GEN_INT (shift_count))));
1551 /* If there is a low immediate part piece, finish up by
1552 putting that in as well. */
1553 if (low_immediate != 0)
1554 emit_insn (gen_rtx_SET (VOIDmode, op0,
1555 gen_safe_OR64 (op0, low_immediate)));
1558 static void sparc_emit_set_const64_longway (rtx, rtx, unsigned HOST_WIDE_INT,
1559 unsigned HOST_WIDE_INT);
1561 /* Full 64-bit constant decomposition. Even though this is the
1562 'worst' case, we still optimize a few things away. */
1564 sparc_emit_set_const64_longway (rtx op0, rtx temp,
1565 unsigned HOST_WIDE_INT high_bits,
1566 unsigned HOST_WIDE_INT low_bits)
1570 if (reload_in_progress || reload_completed)
1573 sub_temp = gen_reg_rtx (DImode);
1575 if ((high_bits & 0xfffffc00) != 0)
1577 emit_insn (gen_safe_HIGH64 (temp, high_bits));
1578 if ((high_bits & ~0xfffffc00) != 0)
1579 emit_insn (gen_rtx_SET (VOIDmode,
1581 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1587 emit_insn (gen_safe_SET64 (temp, high_bits));
1591 if (!reload_in_progress && !reload_completed)
1593 rtx temp2 = gen_reg_rtx (DImode);
1594 rtx temp3 = gen_reg_rtx (DImode);
1595 rtx temp4 = gen_reg_rtx (DImode);
1597 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1598 gen_rtx_ASHIFT (DImode, sub_temp,
1601 emit_insn (gen_safe_HIGH64 (temp2, low_bits));
1602 if ((low_bits & ~0xfffffc00) != 0)
1604 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1605 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1606 emit_insn (gen_rtx_SET (VOIDmode, op0,
1607 gen_rtx_PLUS (DImode, temp4, temp3)));
1611 emit_insn (gen_rtx_SET (VOIDmode, op0,
1612 gen_rtx_PLUS (DImode, temp4, temp2)));
1617 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1618 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1619 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1622 /* We are in the middle of reload, so this is really
1623 painful. However we do still make an attempt to
1624 avoid emitting truly stupid code. */
1625 if (low1 != const0_rtx)
1627 emit_insn (gen_rtx_SET (VOIDmode, op0,
1628 gen_rtx_ASHIFT (DImode, sub_temp,
1629 GEN_INT (to_shift))));
1630 emit_insn (gen_rtx_SET (VOIDmode, op0,
1631 gen_rtx_IOR (DImode, op0, low1)));
1639 if (low2 != const0_rtx)
1641 emit_insn (gen_rtx_SET (VOIDmode, op0,
1642 gen_rtx_ASHIFT (DImode, sub_temp,
1643 GEN_INT (to_shift))));
1644 emit_insn (gen_rtx_SET (VOIDmode, op0,
1645 gen_rtx_IOR (DImode, op0, low2)));
1653 emit_insn (gen_rtx_SET (VOIDmode, op0,
1654 gen_rtx_ASHIFT (DImode, sub_temp,
1655 GEN_INT (to_shift))));
1656 if (low3 != const0_rtx)
1657 emit_insn (gen_rtx_SET (VOIDmode, op0,
1658 gen_rtx_IOR (DImode, op0, low3)));
1663 /* Analyze a 64-bit constant for certain properties. */
1664 static void analyze_64bit_constant (unsigned HOST_WIDE_INT,
1665 unsigned HOST_WIDE_INT,
1666 int *, int *, int *);
1669 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits,
1670 unsigned HOST_WIDE_INT low_bits,
1671 int *hbsp, int *lbsp, int *abbasp)
1673 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1676 lowest_bit_set = highest_bit_set = -1;
1680 if ((lowest_bit_set == -1)
1681 && ((low_bits >> i) & 1))
1683 if ((highest_bit_set == -1)
1684 && ((high_bits >> (32 - i - 1)) & 1))
1685 highest_bit_set = (64 - i - 1);
1688 && ((highest_bit_set == -1)
1689 || (lowest_bit_set == -1)));
1695 if ((lowest_bit_set == -1)
1696 && ((high_bits >> i) & 1))
1697 lowest_bit_set = i + 32;
1698 if ((highest_bit_set == -1)
1699 && ((low_bits >> (32 - i - 1)) & 1))
1700 highest_bit_set = 32 - i - 1;
1703 && ((highest_bit_set == -1)
1704 || (lowest_bit_set == -1)));
1706 /* If there are no bits set this should have gone out
1707 as one instruction! */
1708 gcc_assert (lowest_bit_set != -1 && highest_bit_set != -1);
1709 all_bits_between_are_set = 1;
1710 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1714 if ((low_bits & (1 << i)) != 0)
1719 if ((high_bits & (1 << (i - 32))) != 0)
1722 all_bits_between_are_set = 0;
1725 *hbsp = highest_bit_set;
1726 *lbsp = lowest_bit_set;
1727 *abbasp = all_bits_between_are_set;
1730 static int const64_is_2insns (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
1733 const64_is_2insns (unsigned HOST_WIDE_INT high_bits,
1734 unsigned HOST_WIDE_INT low_bits)
1736 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1739 || high_bits == 0xffffffff)
1742 analyze_64bit_constant (high_bits, low_bits,
1743 &highest_bit_set, &lowest_bit_set,
1744 &all_bits_between_are_set);
1746 if ((highest_bit_set == 63
1747 || lowest_bit_set == 0)
1748 && all_bits_between_are_set != 0)
1751 if ((highest_bit_set - lowest_bit_set) < 21)
1757 static unsigned HOST_WIDE_INT create_simple_focus_bits (unsigned HOST_WIDE_INT,
1758 unsigned HOST_WIDE_INT,
1761 static unsigned HOST_WIDE_INT
1762 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits,
1763 unsigned HOST_WIDE_INT low_bits,
1764 int lowest_bit_set, int shift)
1766 HOST_WIDE_INT hi, lo;
1768 if (lowest_bit_set < 32)
1770 lo = (low_bits >> lowest_bit_set) << shift;
1771 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
1776 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
1778 gcc_assert (! (hi & lo));
1782 /* Here we are sure to be arch64 and this is an integer constant
1783 being loaded into a register. Emit the most efficient
1784 insn sequence possible. Detection of all the 1-insn cases
1785 has been done already. */
1787 sparc_emit_set_const64 (rtx op0, rtx op1)
1789 unsigned HOST_WIDE_INT high_bits, low_bits;
1790 int lowest_bit_set, highest_bit_set;
1791 int all_bits_between_are_set;
1794 /* Sanity check that we know what we are working with. */
1795 gcc_assert (TARGET_ARCH64
1796 && (GET_CODE (op0) == SUBREG
1797 || (REG_P (op0) && ! SPARC_FP_REG_P (REGNO (op0)))));
1799 if (reload_in_progress || reload_completed)
1802 if (GET_CODE (op1) != CONST_INT)
1804 sparc_emit_set_symbolic_const64 (op0, op1, temp);
1809 temp = gen_reg_rtx (DImode);
1811 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
1812 low_bits = (INTVAL (op1) & 0xffffffff);
1814 /* low_bits bits 0 --> 31
1815 high_bits bits 32 --> 63 */
1817 analyze_64bit_constant (high_bits, low_bits,
1818 &highest_bit_set, &lowest_bit_set,
1819 &all_bits_between_are_set);
1821 /* First try for a 2-insn sequence. */
1823 /* These situations are preferred because the optimizer can
1824 * do more things with them:
1826 * sllx %reg, shift, %reg
1828 * srlx %reg, shift, %reg
1829 * 3) mov some_small_const, %reg
1830 * sllx %reg, shift, %reg
1832 if (((highest_bit_set == 63
1833 || lowest_bit_set == 0)
1834 && all_bits_between_are_set != 0)
1835 || ((highest_bit_set - lowest_bit_set) < 12))
1837 HOST_WIDE_INT the_const = -1;
1838 int shift = lowest_bit_set;
1840 if ((highest_bit_set != 63
1841 && lowest_bit_set != 0)
1842 || all_bits_between_are_set == 0)
1845 create_simple_focus_bits (high_bits, low_bits,
1848 else if (lowest_bit_set == 0)
1849 shift = -(63 - highest_bit_set);
1851 gcc_assert (SPARC_SIMM13_P (the_const));
1852 gcc_assert (shift != 0);
1854 emit_insn (gen_safe_SET64 (temp, the_const));
1856 emit_insn (gen_rtx_SET (VOIDmode,
1858 gen_rtx_ASHIFT (DImode,
1862 emit_insn (gen_rtx_SET (VOIDmode,
1864 gen_rtx_LSHIFTRT (DImode,
1866 GEN_INT (-shift))));
1870 /* Now a range of 22 or less bits set somewhere.
1871 * 1) sethi %hi(focus_bits), %reg
1872 * sllx %reg, shift, %reg
1873 * 2) sethi %hi(focus_bits), %reg
1874 * srlx %reg, shift, %reg
1876 if ((highest_bit_set - lowest_bit_set) < 21)
1878 unsigned HOST_WIDE_INT focus_bits =
1879 create_simple_focus_bits (high_bits, low_bits,
1880 lowest_bit_set, 10);
1882 gcc_assert (SPARC_SETHI_P (focus_bits));
1883 gcc_assert (lowest_bit_set != 10);
1885 emit_insn (gen_safe_HIGH64 (temp, focus_bits));
1887 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
1888 if (lowest_bit_set < 10)
1889 emit_insn (gen_rtx_SET (VOIDmode,
1891 gen_rtx_LSHIFTRT (DImode, temp,
1892 GEN_INT (10 - lowest_bit_set))));
1893 else if (lowest_bit_set > 10)
1894 emit_insn (gen_rtx_SET (VOIDmode,
1896 gen_rtx_ASHIFT (DImode, temp,
1897 GEN_INT (lowest_bit_set - 10))));
1901 /* 1) sethi %hi(low_bits), %reg
1902 * or %reg, %lo(low_bits), %reg
1903 * 2) sethi %hi(~low_bits), %reg
1904 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
1907 || high_bits == 0xffffffff)
1909 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
1910 (high_bits == 0xffffffff));
1914 /* Now, try 3-insn sequences. */
1916 /* 1) sethi %hi(high_bits), %reg
1917 * or %reg, %lo(high_bits), %reg
1918 * sllx %reg, 32, %reg
1922 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
1926 /* We may be able to do something quick
1927 when the constant is negated, so try that. */
1928 if (const64_is_2insns ((~high_bits) & 0xffffffff,
1929 (~low_bits) & 0xfffffc00))
1931 /* NOTE: The trailing bits get XOR'd so we need the
1932 non-negated bits, not the negated ones. */
1933 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
1935 if ((((~high_bits) & 0xffffffff) == 0
1936 && ((~low_bits) & 0x80000000) == 0)
1937 || (((~high_bits) & 0xffffffff) == 0xffffffff
1938 && ((~low_bits) & 0x80000000) != 0))
1940 unsigned HOST_WIDE_INT fast_int = (~low_bits & 0xffffffff);
1942 if ((SPARC_SETHI_P (fast_int)
1943 && (~high_bits & 0xffffffff) == 0)
1944 || SPARC_SIMM13_P (fast_int))
1945 emit_insn (gen_safe_SET64 (temp, fast_int));
1947 sparc_emit_set_const64 (temp, GEN_INT (fast_int));
1952 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
1953 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
1954 sparc_emit_set_const64 (temp, negated_const);
1957 /* If we are XOR'ing with -1, then we should emit a one's complement
1958 instead. This way the combiner will notice logical operations
1959 such as ANDN later on and substitute. */
1960 if (trailing_bits == 0x3ff)
1962 emit_insn (gen_rtx_SET (VOIDmode, op0,
1963 gen_rtx_NOT (DImode, temp)));
1967 emit_insn (gen_rtx_SET (VOIDmode,
1969 gen_safe_XOR64 (temp,
1970 (-0x400 | trailing_bits))));
1975 /* 1) sethi %hi(xxx), %reg
1976 * or %reg, %lo(xxx), %reg
1977 * sllx %reg, yyy, %reg
1979 * ??? This is just a generalized version of the low_bits==0
1980 * thing above, FIXME...
1982 if ((highest_bit_set - lowest_bit_set) < 32)
1984 unsigned HOST_WIDE_INT focus_bits =
1985 create_simple_focus_bits (high_bits, low_bits,
1988 /* We can't get here in this state. */
1989 gcc_assert (highest_bit_set >= 32 && lowest_bit_set < 32);
1991 /* So what we know is that the set bits straddle the
1992 middle of the 64-bit word. */
1993 sparc_emit_set_const64_quick2 (op0, temp,
1999 /* 1) sethi %hi(high_bits), %reg
2000 * or %reg, %lo(high_bits), %reg
2001 * sllx %reg, 32, %reg
2002 * or %reg, low_bits, %reg
2004 if (SPARC_SIMM13_P(low_bits)
2005 && ((int)low_bits > 0))
2007 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2011 /* The easiest way when all else fails, is full decomposition. */
2012 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2014 #endif /* HOST_BITS_PER_WIDE_INT == 32 */
2016 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2017 return the mode to be used for the comparison. For floating-point,
2018 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2019 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2020 processing is needed. */
2023 select_cc_mode (enum rtx_code op, rtx x, rtx y ATTRIBUTE_UNUSED)
2025 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2051 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2052 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2054 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2055 return CCX_NOOVmode;
2061 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2068 /* Emit the compare insn and return the CC reg for a CODE comparison
2069 with operands X and Y. */
2072 gen_compare_reg_1 (enum rtx_code code, rtx x, rtx y)
2074 enum machine_mode mode;
2077 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
2080 mode = SELECT_CC_MODE (code, x, y);
2082 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2083 fcc regs (cse can't tell they're really call clobbered regs and will
2084 remove a duplicate comparison even if there is an intervening function
2085 call - it will then try to reload the cc reg via an int reg which is why
2086 we need the movcc patterns). It is possible to provide the movcc
2087 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2088 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2089 to tell cse that CCFPE mode registers (even pseudos) are call
2092 /* ??? This is an experiment. Rather than making changes to cse which may
2093 or may not be easy/clean, we do our own cse. This is possible because
2094 we will generate hard registers. Cse knows they're call clobbered (it
2095 doesn't know the same thing about pseudos). If we guess wrong, no big
2096 deal, but if we win, great! */
2098 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2099 #if 1 /* experiment */
2102 /* We cycle through the registers to ensure they're all exercised. */
2103 static int next_fcc_reg = 0;
2104 /* Previous x,y for each fcc reg. */
2105 static rtx prev_args[4][2];
2107 /* Scan prev_args for x,y. */
2108 for (reg = 0; reg < 4; reg++)
2109 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2114 prev_args[reg][0] = x;
2115 prev_args[reg][1] = y;
2116 next_fcc_reg = (next_fcc_reg + 1) & 3;
2118 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2121 cc_reg = gen_reg_rtx (mode);
2122 #endif /* ! experiment */
2123 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2124 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2126 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2128 /* We shouldn't get there for TFmode if !TARGET_HARD_QUAD. If we do, this
2129 will only result in an unrecognizable insn so no point in asserting. */
2130 emit_insn (gen_rtx_SET (VOIDmode, cc_reg, gen_rtx_COMPARE (mode, x, y)));
2136 /* Emit the compare insn and return the CC reg for the comparison in CMP. */
2139 gen_compare_reg (rtx cmp)
2141 return gen_compare_reg_1 (GET_CODE (cmp), XEXP (cmp, 0), XEXP (cmp, 1));
2144 /* This function is used for v9 only.
2145 DEST is the target of the Scc insn.
2146 CODE is the code for an Scc's comparison.
2147 X and Y are the values we compare.
2149 This function is needed to turn
2152 (gt (reg:CCX 100 %icc)
2156 (gt:DI (reg:CCX 100 %icc)
2159 IE: The instruction recognizer needs to see the mode of the comparison to
2160 find the right instruction. We could use "gt:DI" right in the
2161 define_expand, but leaving it out allows us to handle DI, SI, etc. */
2164 gen_v9_scc (rtx dest, enum rtx_code compare_code, rtx x, rtx y)
2167 && (GET_MODE (x) == DImode
2168 || GET_MODE (dest) == DImode))
2171 /* Try to use the movrCC insns. */
2173 && GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2175 && v9_regcmp_p (compare_code))
2180 /* Special case for op0 != 0. This can be done with one instruction if
2183 if (compare_code == NE
2184 && GET_MODE (dest) == DImode
2185 && rtx_equal_p (op0, dest))
2187 emit_insn (gen_rtx_SET (VOIDmode, dest,
2188 gen_rtx_IF_THEN_ELSE (DImode,
2189 gen_rtx_fmt_ee (compare_code, DImode,
2196 if (reg_overlap_mentioned_p (dest, op0))
2198 /* Handle the case where dest == x.
2199 We "early clobber" the result. */
2200 op0 = gen_reg_rtx (GET_MODE (x));
2201 emit_move_insn (op0, x);
2204 emit_insn (gen_rtx_SET (VOIDmode, dest, const0_rtx));
2205 if (GET_MODE (op0) != DImode)
2207 temp = gen_reg_rtx (DImode);
2208 convert_move (temp, op0, 0);
2212 emit_insn (gen_rtx_SET (VOIDmode, dest,
2213 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2214 gen_rtx_fmt_ee (compare_code, DImode,
2222 x = gen_compare_reg_1 (compare_code, x, y);
2225 gcc_assert (GET_MODE (x) != CC_NOOVmode
2226 && GET_MODE (x) != CCX_NOOVmode);
2228 emit_insn (gen_rtx_SET (VOIDmode, dest, const0_rtx));
2229 emit_insn (gen_rtx_SET (VOIDmode, dest,
2230 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2231 gen_rtx_fmt_ee (compare_code,
2232 GET_MODE (x), x, y),
2233 const1_rtx, dest)));
2239 /* Emit an scc insn. For seq, sne, sgeu, and sltu, we can do this
2240 without jumps using the addx/subx instructions. */
2243 emit_scc_insn (rtx operands[])
2250 /* The quad-word fp compare library routines all return nonzero to indicate
2251 true, which is different from the equivalent libgcc routines, so we must
2252 handle them specially here. */
2253 if (GET_MODE (operands[2]) == TFmode && ! TARGET_HARD_QUAD)
2255 operands[1] = sparc_emit_float_lib_cmp (operands[2], operands[3],
2256 GET_CODE (operands[1]));
2257 operands[2] = XEXP (operands[1], 0);
2258 operands[3] = XEXP (operands[1], 1);
2261 code = GET_CODE (operands[1]);
2265 /* For seq/sne on v9 we use the same code as v8 (the addx/subx method has
2266 more applications). The exception to this is "reg != 0" which can
2267 be done in one instruction on v9 (so we do it). */
2270 if (GET_MODE (x) == SImode)
2272 rtx pat = gen_seqsi_special (operands[0], x, y);
2276 else if (GET_MODE (x) == DImode)
2278 rtx pat = gen_seqdi_special (operands[0], x, y);
2286 if (GET_MODE (x) == SImode)
2288 rtx pat = gen_snesi_special (operands[0], x, y);
2292 else if (GET_MODE (x) == DImode)
2294 rtx pat = gen_snedi_special (operands[0], x, y);
2300 /* For the rest, on v9 we can use conditional moves. */
2304 if (gen_v9_scc (operands[0], code, x, y))
2308 /* We can do LTU and GEU using the addx/subx instructions too. And
2309 for GTU/LEU, if both operands are registers swap them and fall
2310 back to the easy case. */
2311 if (code == GTU || code == LEU)
2313 if ((GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
2314 && (GET_CODE (y) == REG || GET_CODE (y) == SUBREG))
2319 code = swap_condition (code);
2323 if (code == LTU || code == GEU)
2325 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2326 gen_rtx_fmt_ee (code, SImode,
2327 gen_compare_reg_1 (code, x, y),
2332 /* Nope, do branches. */
2336 /* Emit a conditional jump insn for the v9 architecture using comparison code
2337 CODE and jump target LABEL.
2338 This function exists to take advantage of the v9 brxx insns. */
2341 emit_v9_brxx_insn (enum rtx_code code, rtx op0, rtx label)
2343 emit_jump_insn (gen_rtx_SET (VOIDmode,
2345 gen_rtx_IF_THEN_ELSE (VOIDmode,
2346 gen_rtx_fmt_ee (code, GET_MODE (op0),
2348 gen_rtx_LABEL_REF (VOIDmode, label),
2353 emit_conditional_branch_insn (rtx operands[])
2355 /* The quad-word fp compare library routines all return nonzero to indicate
2356 true, which is different from the equivalent libgcc routines, so we must
2357 handle them specially here. */
2358 if (GET_MODE (operands[1]) == TFmode && ! TARGET_HARD_QUAD)
2360 operands[0] = sparc_emit_float_lib_cmp (operands[1], operands[2],
2361 GET_CODE (operands[0]));
2362 operands[1] = XEXP (operands[0], 0);
2363 operands[2] = XEXP (operands[0], 1);
2366 if (TARGET_ARCH64 && operands[2] == const0_rtx
2367 && GET_CODE (operands[1]) == REG
2368 && GET_MODE (operands[1]) == DImode)
2370 emit_v9_brxx_insn (GET_CODE (operands[0]), operands[1], operands[3]);
2374 operands[1] = gen_compare_reg (operands[0]);
2375 operands[2] = const0_rtx;
2376 operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]), VOIDmode,
2377 operands[1], operands[2]);
2378 emit_jump_insn (gen_cbranchcc4 (operands[0], operands[1], operands[2],
2383 /* Generate a DFmode part of a hard TFmode register.
2384 REG is the TFmode hard register, LOW is 1 for the
2385 low 64bit of the register and 0 otherwise.
2388 gen_df_reg (rtx reg, int low)
2390 int regno = REGNO (reg);
2392 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2393 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
2394 return gen_rtx_REG (DFmode, regno);
2397 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
2398 Unlike normal calls, TFmode operands are passed by reference. It is
2399 assumed that no more than 3 operands are required. */
2402 emit_soft_tfmode_libcall (const char *func_name, int nargs, rtx *operands)
2404 rtx ret_slot = NULL, arg[3], func_sym;
2407 /* We only expect to be called for conversions, unary, and binary ops. */
2408 gcc_assert (nargs == 2 || nargs == 3);
2410 for (i = 0; i < nargs; ++i)
2412 rtx this_arg = operands[i];
2415 /* TFmode arguments and return values are passed by reference. */
2416 if (GET_MODE (this_arg) == TFmode)
2418 int force_stack_temp;
2420 force_stack_temp = 0;
2421 if (TARGET_BUGGY_QP_LIB && i == 0)
2422 force_stack_temp = 1;
2424 if (GET_CODE (this_arg) == MEM
2425 && ! force_stack_temp)
2426 this_arg = XEXP (this_arg, 0);
2427 else if (CONSTANT_P (this_arg)
2428 && ! force_stack_temp)
2430 this_slot = force_const_mem (TFmode, this_arg);
2431 this_arg = XEXP (this_slot, 0);
2435 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode), 0);
2437 /* Operand 0 is the return value. We'll copy it out later. */
2439 emit_move_insn (this_slot, this_arg);
2441 ret_slot = this_slot;
2443 this_arg = XEXP (this_slot, 0);
2450 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
2452 if (GET_MODE (operands[0]) == TFmode)
2455 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
2456 arg[0], GET_MODE (arg[0]),
2457 arg[1], GET_MODE (arg[1]));
2459 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
2460 arg[0], GET_MODE (arg[0]),
2461 arg[1], GET_MODE (arg[1]),
2462 arg[2], GET_MODE (arg[2]));
2465 emit_move_insn (operands[0], ret_slot);
2471 gcc_assert (nargs == 2);
2473 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
2474 GET_MODE (operands[0]), 1,
2475 arg[1], GET_MODE (arg[1]));
2477 if (ret != operands[0])
2478 emit_move_insn (operands[0], ret);
2482 /* Expand soft-float TFmode calls to sparc abi routines. */
2485 emit_soft_tfmode_binop (enum rtx_code code, rtx *operands)
2507 emit_soft_tfmode_libcall (func, 3, operands);
2511 emit_soft_tfmode_unop (enum rtx_code code, rtx *operands)
2515 gcc_assert (code == SQRT);
2518 emit_soft_tfmode_libcall (func, 2, operands);
2522 emit_soft_tfmode_cvt (enum rtx_code code, rtx *operands)
2529 switch (GET_MODE (operands[1]))
2542 case FLOAT_TRUNCATE:
2543 switch (GET_MODE (operands[0]))
2557 switch (GET_MODE (operands[1]))
2562 operands[1] = gen_rtx_SIGN_EXTEND (DImode, operands[1]);
2572 case UNSIGNED_FLOAT:
2573 switch (GET_MODE (operands[1]))
2578 operands[1] = gen_rtx_ZERO_EXTEND (DImode, operands[1]);
2589 switch (GET_MODE (operands[0]))
2603 switch (GET_MODE (operands[0]))
2620 emit_soft_tfmode_libcall (func, 2, operands);
2623 /* Expand a hard-float tfmode operation. All arguments must be in
2627 emit_hard_tfmode_operation (enum rtx_code code, rtx *operands)
2631 if (GET_RTX_CLASS (code) == RTX_UNARY)
2633 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2634 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
2638 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2639 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
2640 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
2641 operands[1], operands[2]);
2644 if (register_operand (operands[0], VOIDmode))
2647 dest = gen_reg_rtx (GET_MODE (operands[0]));
2649 emit_insn (gen_rtx_SET (VOIDmode, dest, op));
2651 if (dest != operands[0])
2652 emit_move_insn (operands[0], dest);
2656 emit_tfmode_binop (enum rtx_code code, rtx *operands)
2658 if (TARGET_HARD_QUAD)
2659 emit_hard_tfmode_operation (code, operands);
2661 emit_soft_tfmode_binop (code, operands);
2665 emit_tfmode_unop (enum rtx_code code, rtx *operands)
2667 if (TARGET_HARD_QUAD)
2668 emit_hard_tfmode_operation (code, operands);
2670 emit_soft_tfmode_unop (code, operands);
2674 emit_tfmode_cvt (enum rtx_code code, rtx *operands)
2676 if (TARGET_HARD_QUAD)
2677 emit_hard_tfmode_operation (code, operands);
2679 emit_soft_tfmode_cvt (code, operands);
2682 /* Return nonzero if a branch/jump/call instruction will be emitting
2683 nop into its delay slot. */
2686 empty_delay_slot (rtx insn)
2690 /* If no previous instruction (should not happen), return true. */
2691 if (PREV_INSN (insn) == NULL)
2694 seq = NEXT_INSN (PREV_INSN (insn));
2695 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
2701 /* Return nonzero if TRIAL can go into the call delay slot. */
2704 tls_call_delay (rtx trial)
2709 call __tls_get_addr, %tgd_call (foo)
2710 add %l7, %o0, %o0, %tgd_add (foo)
2711 while Sun as/ld does not. */
2712 if (TARGET_GNU_TLS || !TARGET_TLS)
2715 pat = PATTERN (trial);
2717 /* We must reject tgd_add{32|64}, i.e.
2718 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSGD)))
2719 and tldm_add{32|64}, i.e.
2720 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSLDM)))
2722 if (GET_CODE (pat) == SET
2723 && GET_CODE (SET_SRC (pat)) == PLUS)
2725 rtx unspec = XEXP (SET_SRC (pat), 1);
2727 if (GET_CODE (unspec) == UNSPEC
2728 && (XINT (unspec, 1) == UNSPEC_TLSGD
2729 || XINT (unspec, 1) == UNSPEC_TLSLDM))
2736 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
2737 instruction. RETURN_P is true if the v9 variant 'return' is to be
2738 considered in the test too.
2740 TRIAL must be a SET whose destination is a REG appropriate for the
2741 'restore' instruction or, if RETURN_P is true, for the 'return'
2745 eligible_for_restore_insn (rtx trial, bool return_p)
2747 rtx pat = PATTERN (trial);
2748 rtx src = SET_SRC (pat);
2750 /* The 'restore src,%g0,dest' pattern for word mode and below. */
2751 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2752 && arith_operand (src, GET_MODE (src)))
2755 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2757 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2760 /* The 'restore src,%g0,dest' pattern for double-word mode. */
2761 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2762 && arith_double_operand (src, GET_MODE (src)))
2763 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2765 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
2766 else if (! TARGET_FPU && register_operand (src, SFmode))
2769 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
2770 else if (! TARGET_FPU && TARGET_ARCH64 && register_operand (src, DFmode))
2773 /* If we have the 'return' instruction, anything that does not use
2774 local or output registers and can go into a delay slot wins. */
2775 else if (return_p && TARGET_V9 && ! epilogue_renumber (&pat, 1)
2776 && (get_attr_in_uncond_branch_delay (trial)
2777 == IN_UNCOND_BRANCH_DELAY_TRUE))
2780 /* The 'restore src1,src2,dest' pattern for SImode. */
2781 else if (GET_CODE (src) == PLUS
2782 && register_operand (XEXP (src, 0), SImode)
2783 && arith_operand (XEXP (src, 1), SImode))
2786 /* The 'restore src1,src2,dest' pattern for DImode. */
2787 else if (GET_CODE (src) == PLUS
2788 && register_operand (XEXP (src, 0), DImode)
2789 && arith_double_operand (XEXP (src, 1), DImode))
2792 /* The 'restore src1,%lo(src2),dest' pattern. */
2793 else if (GET_CODE (src) == LO_SUM
2794 && ! TARGET_CM_MEDMID
2795 && ((register_operand (XEXP (src, 0), SImode)
2796 && immediate_operand (XEXP (src, 1), SImode))
2798 && register_operand (XEXP (src, 0), DImode)
2799 && immediate_operand (XEXP (src, 1), DImode))))
2802 /* The 'restore src,src,dest' pattern. */
2803 else if (GET_CODE (src) == ASHIFT
2804 && (register_operand (XEXP (src, 0), SImode)
2805 || register_operand (XEXP (src, 0), DImode))
2806 && XEXP (src, 1) == const1_rtx)
2812 /* Return nonzero if TRIAL can go into the function return's
2816 eligible_for_return_delay (rtx trial)
2820 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2823 if (get_attr_length (trial) != 1)
2826 /* If there are any call-saved registers, we should scan TRIAL if it
2827 does not reference them. For now just make it easy. */
2831 /* If the function uses __builtin_eh_return, the eh_return machinery
2832 occupies the delay slot. */
2833 if (crtl->calls_eh_return)
2836 /* In the case of a true leaf function, anything can go into the slot. */
2837 if (sparc_leaf_function_p)
2838 return get_attr_in_uncond_branch_delay (trial)
2839 == IN_UNCOND_BRANCH_DELAY_TRUE;
2841 pat = PATTERN (trial);
2843 /* Otherwise, only operations which can be done in tandem with
2844 a `restore' or `return' insn can go into the delay slot. */
2845 if (GET_CODE (SET_DEST (pat)) != REG
2846 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24))
2849 /* If this instruction sets up floating point register and we have a return
2850 instruction, it can probably go in. But restore will not work
2852 if (REGNO (SET_DEST (pat)) >= 32)
2854 && ! epilogue_renumber (&pat, 1)
2855 && (get_attr_in_uncond_branch_delay (trial)
2856 == IN_UNCOND_BRANCH_DELAY_TRUE));
2858 return eligible_for_restore_insn (trial, true);
2861 /* Return nonzero if TRIAL can go into the sibling call's
2865 eligible_for_sibcall_delay (rtx trial)
2869 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2872 if (get_attr_length (trial) != 1)
2875 pat = PATTERN (trial);
2877 if (sparc_leaf_function_p)
2879 /* If the tail call is done using the call instruction,
2880 we have to restore %o7 in the delay slot. */
2881 if (LEAF_SIBCALL_SLOT_RESERVED_P)
2884 /* %g1 is used to build the function address */
2885 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
2891 /* Otherwise, only operations which can be done in tandem with
2892 a `restore' insn can go into the delay slot. */
2893 if (GET_CODE (SET_DEST (pat)) != REG
2894 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24)
2895 || REGNO (SET_DEST (pat)) >= 32)
2898 /* If it mentions %o7, it can't go in, because sibcall will clobber it
2900 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
2903 return eligible_for_restore_insn (trial, false);
2907 short_branch (int uid1, int uid2)
2909 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
2911 /* Leave a few words of "slop". */
2912 if (delta >= -1023 && delta <= 1022)
2918 /* Return nonzero if REG is not used after INSN.
2919 We assume REG is a reload reg, and therefore does
2920 not live past labels or calls or jumps. */
2922 reg_unused_after (rtx reg, rtx insn)
2924 enum rtx_code code, prev_code = UNKNOWN;
2926 while ((insn = NEXT_INSN (insn)))
2928 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
2931 code = GET_CODE (insn);
2932 if (GET_CODE (insn) == CODE_LABEL)
2937 rtx set = single_set (insn);
2938 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
2941 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
2943 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
2951 /* Determine if it's legal to put X into the constant pool. This
2952 is not possible if X contains the address of a symbol that is
2953 not constant (TLS) or not known at final link time (PIC). */
2956 sparc_cannot_force_const_mem (rtx x)
2958 switch (GET_CODE (x))
2963 /* Accept all non-symbolic constants. */
2967 /* Labels are OK iff we are non-PIC. */
2968 return flag_pic != 0;
2971 /* 'Naked' TLS symbol references are never OK,
2972 non-TLS symbols are OK iff we are non-PIC. */
2973 if (SYMBOL_REF_TLS_MODEL (x))
2976 return flag_pic != 0;
2979 return sparc_cannot_force_const_mem (XEXP (x, 0));
2982 return sparc_cannot_force_const_mem (XEXP (x, 0))
2983 || sparc_cannot_force_const_mem (XEXP (x, 1));
2992 static GTY(()) bool pic_helper_needed = false;
2993 static GTY(()) rtx pic_helper_symbol;
2994 static GTY(()) rtx global_offset_table;
2996 /* Ensure that we are not using patterns that are not OK with PIC. */
3004 gcc_assert (GET_CODE (recog_data.operand[i]) != SYMBOL_REF
3005 && (GET_CODE (recog_data.operand[i]) != CONST
3006 || (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
3007 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
3008 == global_offset_table)
3009 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
3017 /* Return true if X is an address which needs a temporary register when
3018 reloaded while generating PIC code. */
3021 pic_address_needs_scratch (rtx x)
3023 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
3024 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3025 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
3026 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3027 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
3033 /* Determine if a given RTX is a valid constant. We already know this
3034 satisfies CONSTANT_P. */
3037 legitimate_constant_p (rtx x)
3039 switch (GET_CODE (x))
3043 if (sparc_tls_referenced_p (x))
3048 if (GET_MODE (x) == VOIDmode)
3051 /* Floating point constants are generally not ok.
3052 The only exception is 0.0 in VIS. */
3054 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3055 && const_zero_operand (x, GET_MODE (x)))
3061 /* Vector constants are generally not ok.
3062 The only exception is 0 in VIS. */
3064 && const_zero_operand (x, GET_MODE (x)))
3076 /* Determine if a given RTX is a valid constant address. */
3079 constant_address_p (rtx x)
3081 switch (GET_CODE (x))
3089 if (flag_pic && pic_address_needs_scratch (x))
3091 return legitimate_constant_p (x);
3094 return !flag_pic && legitimate_constant_p (x);
3101 /* Nonzero if the constant value X is a legitimate general operand
3102 when generating PIC code. It is given that flag_pic is on and
3103 that X satisfies CONSTANT_P or is a CONST_DOUBLE. */
3106 legitimate_pic_operand_p (rtx x)
3108 if (pic_address_needs_scratch (x))
3110 if (sparc_tls_referenced_p (x))
3115 /* Return nonzero if ADDR is a valid memory address.
3116 STRICT specifies whether strict register checking applies. */
3119 sparc_legitimate_address_p (enum machine_mode mode, rtx addr, bool strict)
3121 rtx rs1 = NULL, rs2 = NULL, imm1 = NULL;
3123 if (REG_P (addr) || GET_CODE (addr) == SUBREG)
3125 else if (GET_CODE (addr) == PLUS)
3127 rs1 = XEXP (addr, 0);
3128 rs2 = XEXP (addr, 1);
3130 /* Canonicalize. REG comes first, if there are no regs,
3131 LO_SUM comes first. */
3133 && GET_CODE (rs1) != SUBREG
3135 || GET_CODE (rs2) == SUBREG
3136 || (GET_CODE (rs2) == LO_SUM && GET_CODE (rs1) != LO_SUM)))
3138 rs1 = XEXP (addr, 1);
3139 rs2 = XEXP (addr, 0);
3143 && rs1 == pic_offset_table_rtx
3145 && GET_CODE (rs2) != SUBREG
3146 && GET_CODE (rs2) != LO_SUM
3147 && GET_CODE (rs2) != MEM
3148 && !(GET_CODE (rs2) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs2))
3149 && (! symbolic_operand (rs2, VOIDmode) || mode == Pmode)
3150 && (GET_CODE (rs2) != CONST_INT || SMALL_INT (rs2)))
3152 || GET_CODE (rs1) == SUBREG)
3153 && RTX_OK_FOR_OFFSET_P (rs2)))
3158 else if ((REG_P (rs1) || GET_CODE (rs1) == SUBREG)
3159 && (REG_P (rs2) || GET_CODE (rs2) == SUBREG))
3161 /* We prohibit REG + REG for TFmode when there are no quad move insns
3162 and we consequently need to split. We do this because REG+REG
3163 is not an offsettable address. If we get the situation in reload
3164 where source and destination of a movtf pattern are both MEMs with
3165 REG+REG address, then only one of them gets converted to an
3166 offsettable address. */
3168 && ! (TARGET_FPU && TARGET_ARCH64 && TARGET_HARD_QUAD))
3171 /* We prohibit REG + REG on ARCH32 if not optimizing for
3172 DFmode/DImode because then mem_min_alignment is likely to be zero
3173 after reload and the forced split would lack a matching splitter
3175 if (TARGET_ARCH32 && !optimize
3176 && (mode == DFmode || mode == DImode))
3179 else if (USE_AS_OFFSETABLE_LO10
3180 && GET_CODE (rs1) == LO_SUM
3182 && ! TARGET_CM_MEDMID
3183 && RTX_OK_FOR_OLO10_P (rs2))
3186 imm1 = XEXP (rs1, 1);
3187 rs1 = XEXP (rs1, 0);
3188 if (!CONSTANT_P (imm1)
3189 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
3193 else if (GET_CODE (addr) == LO_SUM)
3195 rs1 = XEXP (addr, 0);
3196 imm1 = XEXP (addr, 1);
3198 if (!CONSTANT_P (imm1)
3199 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
3202 /* We can't allow TFmode in 32-bit mode, because an offset greater
3203 than the alignment (8) may cause the LO_SUM to overflow. */
3204 if (mode == TFmode && TARGET_ARCH32)
3207 else if (GET_CODE (addr) == CONST_INT && SMALL_INT (addr))
3212 if (GET_CODE (rs1) == SUBREG)
3213 rs1 = SUBREG_REG (rs1);
3219 if (GET_CODE (rs2) == SUBREG)
3220 rs2 = SUBREG_REG (rs2);
3227 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1))
3228 || (rs2 && !REGNO_OK_FOR_BASE_P (REGNO (rs2))))
3233 if ((REGNO (rs1) >= 32
3234 && REGNO (rs1) != FRAME_POINTER_REGNUM
3235 && REGNO (rs1) < FIRST_PSEUDO_REGISTER)
3237 && (REGNO (rs2) >= 32
3238 && REGNO (rs2) != FRAME_POINTER_REGNUM
3239 && REGNO (rs2) < FIRST_PSEUDO_REGISTER)))
3245 /* Construct the SYMBOL_REF for the tls_get_offset function. */
3247 static GTY(()) rtx sparc_tls_symbol;
3250 sparc_tls_get_addr (void)
3252 if (!sparc_tls_symbol)
3253 sparc_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_addr");
3255 return sparc_tls_symbol;
3259 sparc_tls_got (void)
3264 crtl->uses_pic_offset_table = 1;
3265 return pic_offset_table_rtx;
3268 if (!global_offset_table)
3269 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3270 temp = gen_reg_rtx (Pmode);
3271 emit_move_insn (temp, global_offset_table);
3275 /* Return true if X contains a thread-local symbol. */
3278 sparc_tls_referenced_p (rtx x)
3280 if (!TARGET_HAVE_TLS)
3283 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
3284 x = XEXP (XEXP (x, 0), 0);
3286 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x))
3289 /* That's all we handle in sparc_legitimize_tls_address for now. */
3293 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3294 this (thread-local) address. */
3297 sparc_legitimize_tls_address (rtx addr)
3299 rtx temp1, temp2, temp3, ret, o0, got, insn;
3301 gcc_assert (can_create_pseudo_p ());
3303 if (GET_CODE (addr) == SYMBOL_REF)
3304 switch (SYMBOL_REF_TLS_MODEL (addr))
3306 case TLS_MODEL_GLOBAL_DYNAMIC:
3308 temp1 = gen_reg_rtx (SImode);
3309 temp2 = gen_reg_rtx (SImode);
3310 ret = gen_reg_rtx (Pmode);
3311 o0 = gen_rtx_REG (Pmode, 8);
3312 got = sparc_tls_got ();
3313 emit_insn (gen_tgd_hi22 (temp1, addr));
3314 emit_insn (gen_tgd_lo10 (temp2, temp1, addr));
3317 emit_insn (gen_tgd_add32 (o0, got, temp2, addr));
3318 insn = emit_call_insn (gen_tgd_call32 (o0, sparc_tls_get_addr (),
3323 emit_insn (gen_tgd_add64 (o0, got, temp2, addr));
3324 insn = emit_call_insn (gen_tgd_call64 (o0, sparc_tls_get_addr (),
3327 CALL_INSN_FUNCTION_USAGE (insn)
3328 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
3329 CALL_INSN_FUNCTION_USAGE (insn));
3330 insn = get_insns ();
3332 emit_libcall_block (insn, ret, o0, addr);
3335 case TLS_MODEL_LOCAL_DYNAMIC:
3337 temp1 = gen_reg_rtx (SImode);
3338 temp2 = gen_reg_rtx (SImode);
3339 temp3 = gen_reg_rtx (Pmode);
3340 ret = gen_reg_rtx (Pmode);
3341 o0 = gen_rtx_REG (Pmode, 8);
3342 got = sparc_tls_got ();
3343 emit_insn (gen_tldm_hi22 (temp1));
3344 emit_insn (gen_tldm_lo10 (temp2, temp1));
3347 emit_insn (gen_tldm_add32 (o0, got, temp2));
3348 insn = emit_call_insn (gen_tldm_call32 (o0, sparc_tls_get_addr (),
3353 emit_insn (gen_tldm_add64 (o0, got, temp2));
3354 insn = emit_call_insn (gen_tldm_call64 (o0, sparc_tls_get_addr (),
3357 CALL_INSN_FUNCTION_USAGE (insn)
3358 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, o0),
3359 CALL_INSN_FUNCTION_USAGE (insn));
3360 insn = get_insns ();
3362 emit_libcall_block (insn, temp3, o0,
3363 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3364 UNSPEC_TLSLD_BASE));
3365 temp1 = gen_reg_rtx (SImode);
3366 temp2 = gen_reg_rtx (SImode);
3367 emit_insn (gen_tldo_hix22 (temp1, addr));
3368 emit_insn (gen_tldo_lox10 (temp2, temp1, addr));
3370 emit_insn (gen_tldo_add32 (ret, temp3, temp2, addr));
3372 emit_insn (gen_tldo_add64 (ret, temp3, temp2, addr));
3375 case TLS_MODEL_INITIAL_EXEC:
3376 temp1 = gen_reg_rtx (SImode);
3377 temp2 = gen_reg_rtx (SImode);
3378 temp3 = gen_reg_rtx (Pmode);
3379 got = sparc_tls_got ();
3380 emit_insn (gen_tie_hi22 (temp1, addr));
3381 emit_insn (gen_tie_lo10 (temp2, temp1, addr));
3383 emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
3385 emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
3388 ret = gen_reg_rtx (Pmode);
3390 emit_insn (gen_tie_add32 (ret, gen_rtx_REG (Pmode, 7),
3393 emit_insn (gen_tie_add64 (ret, gen_rtx_REG (Pmode, 7),
3397 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp3);
3400 case TLS_MODEL_LOCAL_EXEC:
3401 temp1 = gen_reg_rtx (Pmode);
3402 temp2 = gen_reg_rtx (Pmode);
3405 emit_insn (gen_tle_hix22_sp32 (temp1, addr));
3406 emit_insn (gen_tle_lox10_sp32 (temp2, temp1, addr));
3410 emit_insn (gen_tle_hix22_sp64 (temp1, addr));
3411 emit_insn (gen_tle_lox10_sp64 (temp2, temp1, addr));
3413 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp2);
3420 else if (GET_CODE (addr) == CONST)
3424 gcc_assert (GET_CODE (XEXP (addr, 0)) == PLUS);
3426 base = sparc_legitimize_tls_address (XEXP (XEXP (addr, 0), 0));
3427 offset = XEXP (XEXP (addr, 0), 1);
3429 base = force_operand (base, NULL_RTX);
3430 if (!(GET_CODE (offset) == CONST_INT && SMALL_INT (offset)))
3431 offset = force_reg (Pmode, offset);
3432 ret = gen_rtx_PLUS (Pmode, base, offset);
3436 gcc_unreachable (); /* for now ... */
3441 /* Legitimize PIC addresses. If the address is already position-independent,
3442 we return ORIG. Newly generated position-independent addresses go into a
3443 reg. This is REG if nonzero, otherwise we allocate register(s) as
3447 sparc_legitimize_pic_address (rtx orig, rtx reg)
3449 bool gotdata_op = false;
3451 if (GET_CODE (orig) == SYMBOL_REF
3452 /* See the comment&nbs