1 /* Subroutines for insn-output.c for Sun SPARC.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 64 bit SPARC V9 support by Michael Tiemann, Jim Wilson, and Doug Evans,
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
47 #include "target-def.h"
49 /* 1 if the caller has placed an "unimp" insn immediately after the call.
50 This is used in v8 code when calling a function that returns a structure.
51 v9 doesn't have this. Be careful to have this test be the same as that
54 #define SKIP_CALLERS_UNIMP_P \
55 (!TARGET_ARCH64 && current_function_returns_struct \
56 && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))) \
57 && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl))) \
60 /* Global variables for machine-dependent things. */
62 /* Size of frame. Need to know this to emit return insns from leaf procedures.
63 ACTUAL_FSIZE is set by compute_frame_size() which is called during the
64 reload pass. This is important as the value is later used in insn
65 scheduling (to see what can go in a delay slot).
66 APPARENT_FSIZE is the size of the stack less the register save area and less
67 the outgoing argument area. It is used when saving call preserved regs. */
68 static int apparent_fsize;
69 static int actual_fsize;
71 /* Number of live general or floating point registers needed to be
72 saved (as 4-byte quantities). */
73 static int num_gfregs;
75 /* Save the operands last given to a compare for use when we
76 generate a scc or bcc insn. */
77 rtx sparc_compare_op0, sparc_compare_op1;
79 /* Coordinate with the md file wrt special insns created by
80 sparc_nonflat_function_epilogue. */
81 bool sparc_emitting_epilogue;
85 /* Vector to say how input registers are mapped to output registers.
86 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
87 eliminate it. You must use -fomit-frame-pointer to get that. */
88 const char leaf_reg_remap[] =
89 { 0, 1, 2, 3, 4, 5, 6, 7,
90 -1, -1, -1, -1, -1, -1, 14, -1,
91 -1, -1, -1, -1, -1, -1, -1, -1,
92 8, 9, 10, 11, 12, 13, -1, 15,
94 32, 33, 34, 35, 36, 37, 38, 39,
95 40, 41, 42, 43, 44, 45, 46, 47,
96 48, 49, 50, 51, 52, 53, 54, 55,
97 56, 57, 58, 59, 60, 61, 62, 63,
98 64, 65, 66, 67, 68, 69, 70, 71,
99 72, 73, 74, 75, 76, 77, 78, 79,
100 80, 81, 82, 83, 84, 85, 86, 87,
101 88, 89, 90, 91, 92, 93, 94, 95,
102 96, 97, 98, 99, 100};
104 /* Vector, indexed by hard register number, which contains 1
105 for a register that is allowable in a candidate for leaf
106 function treatment. */
107 char sparc_leaf_regs[] =
108 { 1, 1, 1, 1, 1, 1, 1, 1,
109 0, 0, 0, 0, 0, 0, 1, 0,
110 0, 0, 0, 0, 0, 0, 0, 0,
111 1, 1, 1, 1, 1, 1, 0, 1,
112 1, 1, 1, 1, 1, 1, 1, 1,
113 1, 1, 1, 1, 1, 1, 1, 1,
114 1, 1, 1, 1, 1, 1, 1, 1,
115 1, 1, 1, 1, 1, 1, 1, 1,
116 1, 1, 1, 1, 1, 1, 1, 1,
117 1, 1, 1, 1, 1, 1, 1, 1,
118 1, 1, 1, 1, 1, 1, 1, 1,
119 1, 1, 1, 1, 1, 1, 1, 1,
124 /* Name of where we pretend to think the frame pointer points.
125 Normally, this is "%fp", but if we are in a leaf procedure,
126 this is "%sp+something". We record "something" separately as it may be
127 too big for reg+constant addressing. */
129 static const char *frame_base_name;
130 static int frame_base_offset;
132 static void sparc_init_modes PARAMS ((void));
133 static int save_regs PARAMS ((FILE *, int, int, const char *,
135 static int restore_regs PARAMS ((FILE *, int, int, const char *, int, int));
136 static void build_big_number PARAMS ((FILE *, int, const char *));
137 static int function_arg_slotno PARAMS ((const CUMULATIVE_ARGS *,
138 enum machine_mode, tree, int, int,
141 static int supersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
142 static int hypersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
143 static int ultrasparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
145 static void sparc_output_addr_vec PARAMS ((rtx));
146 static void sparc_output_addr_diff_vec PARAMS ((rtx));
147 static void sparc_output_deferred_case_vectors PARAMS ((void));
148 static void sparc_add_gc_roots PARAMS ((void));
149 static void mark_ultrasparc_pipeline_state PARAMS ((void *));
150 static int check_return_regs PARAMS ((rtx));
151 static int epilogue_renumber PARAMS ((rtx *, int));
152 static bool sparc_assemble_integer PARAMS ((rtx, unsigned int, int));
153 static int ultra_cmove_results_ready_p PARAMS ((rtx));
154 static int ultra_fpmode_conflict_exists PARAMS ((enum machine_mode));
155 static rtx *ultra_find_type PARAMS ((int, rtx *, int));
156 static void ultra_build_types_avail PARAMS ((rtx *, int));
157 static void ultra_flush_pipeline PARAMS ((void));
158 static void ultra_rescan_pipeline_state PARAMS ((rtx *, int));
159 static int set_extends PARAMS ((rtx));
160 static void output_restore_regs PARAMS ((FILE *, int));
161 static void sparc_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
162 static void sparc_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
163 static void sparc_flat_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
164 static void sparc_flat_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
165 static void sparc_nonflat_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT,
167 static void sparc_nonflat_function_prologue PARAMS ((FILE *, HOST_WIDE_INT,
169 #ifdef OBJECT_FORMAT_ELF
170 static void sparc_elf_asm_named_section PARAMS ((const char *, unsigned int));
172 static void ultrasparc_sched_reorder PARAMS ((FILE *, int, rtx *, int));
173 static int ultrasparc_variable_issue PARAMS ((rtx));
174 static void ultrasparc_sched_init PARAMS ((void));
176 static int sparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
177 static int sparc_issue_rate PARAMS ((void));
178 static int sparc_variable_issue PARAMS ((FILE *, int, rtx, int));
179 static void sparc_sched_init PARAMS ((FILE *, int, int));
180 static int sparc_sched_reorder PARAMS ((FILE *, int, rtx *, int *, int));
182 /* Option handling. */
184 /* Code model option as passed by user. */
185 const char *sparc_cmodel_string;
187 enum cmodel sparc_cmodel;
189 char sparc_hard_reg_printed[8];
191 struct sparc_cpu_select sparc_select[] =
193 /* switch name, tune arch */
194 { (char *)0, "default", 1, 1 },
195 { (char *)0, "-mcpu=", 1, 1 },
196 { (char *)0, "-mtune=", 1, 0 },
200 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
201 enum processor_type sparc_cpu;
203 /* Initialize the GCC target structure. */
205 /* The sparc default is to use .half rather than .short for aligned
206 HI objects. Use .word instead of .long on non-ELF systems. */
207 #undef TARGET_ASM_ALIGNED_HI_OP
208 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
209 #ifndef OBJECT_FORMAT_ELF
210 #undef TARGET_ASM_ALIGNED_SI_OP
211 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
214 #undef TARGET_ASM_UNALIGNED_HI_OP
215 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
216 #undef TARGET_ASM_UNALIGNED_SI_OP
217 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
218 #undef TARGET_ASM_UNALIGNED_DI_OP
219 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
221 /* The target hook has to handle DI-mode values. */
222 #undef TARGET_ASM_INTEGER
223 #define TARGET_ASM_INTEGER sparc_assemble_integer
225 #undef TARGET_ASM_FUNCTION_PROLOGUE
226 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_output_function_prologue
227 #undef TARGET_ASM_FUNCTION_EPILOGUE
228 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_output_function_epilogue
230 #undef TARGET_SCHED_ADJUST_COST
231 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
232 #undef TARGET_SCHED_ISSUE_RATE
233 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
234 #undef TARGET_SCHED_VARIABLE_ISSUE
235 #define TARGET_SCHED_VARIABLE_ISSUE sparc_variable_issue
236 #undef TARGET_SCHED_INIT
237 #define TARGET_SCHED_INIT sparc_sched_init
238 #undef TARGET_SCHED_REORDER
239 #define TARGET_SCHED_REORDER sparc_sched_reorder
241 struct gcc_target targetm = TARGET_INITIALIZER;
243 /* Validate and override various options, and do some machine dependent
247 sparc_override_options ()
249 static struct code_model {
250 const char *const name;
252 } const cmodels[] = {
254 { "medlow", CM_MEDLOW },
255 { "medmid", CM_MEDMID },
256 { "medany", CM_MEDANY },
257 { "embmedany", CM_EMBMEDANY },
260 const struct code_model *cmodel;
261 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
262 static struct cpu_default {
264 const char *const name;
265 } const cpu_default[] = {
266 /* There must be one entry here for each TARGET_CPU value. */
267 { TARGET_CPU_sparc, "cypress" },
268 { TARGET_CPU_sparclet, "tsc701" },
269 { TARGET_CPU_sparclite, "f930" },
270 { TARGET_CPU_v8, "v8" },
271 { TARGET_CPU_hypersparc, "hypersparc" },
272 { TARGET_CPU_sparclite86x, "sparclite86x" },
273 { TARGET_CPU_supersparc, "supersparc" },
274 { TARGET_CPU_v9, "v9" },
275 { TARGET_CPU_ultrasparc, "ultrasparc" },
278 const struct cpu_default *def;
279 /* Table of values for -m{cpu,tune}=. */
280 static struct cpu_table {
281 const char *const name;
282 const enum processor_type processor;
285 } const cpu_table[] = {
286 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
287 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
288 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
289 /* TI TMS390Z55 supersparc */
290 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
291 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
292 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
293 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
294 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
295 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
296 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
297 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
299 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
301 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
302 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
303 /* TI ultrasparc I, II, IIi */
304 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
305 /* Although insns using %y are deprecated, it is a clear win on current
307 |MASK_DEPRECATED_V8_INSNS},
310 const struct cpu_table *cpu;
311 const struct sparc_cpu_select *sel;
314 #ifndef SPARC_BI_ARCH
315 /* Check for unsupported architecture size. */
316 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
317 error ("%s is not supported by this configuration",
318 DEFAULT_ARCH32_P ? "-m64" : "-m32");
321 /* We force all 64bit archs to use 128 bit long double */
322 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
324 error ("-mlong-double-64 not allowed with -m64");
325 target_flags |= MASK_LONG_DOUBLE_128;
328 /* Code model selection. */
329 sparc_cmodel = SPARC_DEFAULT_CMODEL;
333 sparc_cmodel = CM_32;
336 if (sparc_cmodel_string != NULL)
340 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
341 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
343 if (cmodel->name == NULL)
344 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
346 sparc_cmodel = cmodel->value;
349 error ("-mcmodel= is not supported on 32 bit systems");
352 fpu = TARGET_FPU; /* save current -mfpu status */
354 /* Set the default CPU. */
355 for (def = &cpu_default[0]; def->name; ++def)
356 if (def->cpu == TARGET_CPU_DEFAULT)
360 sparc_select[0].string = def->name;
362 for (sel = &sparc_select[0]; sel->name; ++sel)
366 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
367 if (! strcmp (sel->string, cpu->name))
370 sparc_cpu = cpu->processor;
374 target_flags &= ~cpu->disable;
375 target_flags |= cpu->enable;
381 error ("bad value (%s) for %s switch", sel->string, sel->name);
385 /* If -mfpu or -mno-fpu was explicitly used, don't override with
386 the processor default. Clear MASK_FPU_SET to avoid confusing
387 the reverse mapping from switch values to names. */
390 target_flags = (target_flags & ~MASK_FPU) | fpu;
391 target_flags &= ~MASK_FPU_SET;
394 /* Don't allow -mvis if FPU is disabled. */
396 target_flags &= ~MASK_VIS;
398 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
400 -m64 also implies v9. */
401 if (TARGET_VIS || TARGET_ARCH64)
403 target_flags |= MASK_V9;
404 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
407 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
408 if (TARGET_V9 && TARGET_ARCH32)
409 target_flags |= MASK_DEPRECATED_V8_INSNS;
411 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
412 if (! TARGET_V9 || TARGET_ARCH64)
413 target_flags &= ~MASK_V8PLUS;
415 /* Don't use stack biasing in 32 bit mode. */
417 target_flags &= ~MASK_STACK_BIAS;
419 /* Supply a default value for align_functions. */
420 if (align_functions == 0 && sparc_cpu == PROCESSOR_ULTRASPARC)
421 align_functions = 32;
423 /* Validate PCC_STRUCT_RETURN. */
424 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
425 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
427 /* Only use .uaxword when compiling for a 64-bit target. */
429 targetm.asm_out.unaligned_op.di = NULL;
431 /* Do various machine dependent initializations. */
434 /* Register global variables with the garbage collector. */
435 sparc_add_gc_roots ();
438 /* Miscellaneous utilities. */
440 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
441 or branch on register contents instructions. */
447 return (code == EQ || code == NE || code == GE || code == LT
448 || code == LE || code == GT);
452 /* Operand constraints. */
454 /* Return non-zero only if OP is a register of mode MODE,
458 reg_or_0_operand (op, mode)
460 enum machine_mode mode;
462 if (register_operand (op, mode))
464 if (op == const0_rtx)
466 if (GET_MODE (op) == VOIDmode && GET_CODE (op) == CONST_DOUBLE
467 && CONST_DOUBLE_HIGH (op) == 0
468 && CONST_DOUBLE_LOW (op) == 0)
470 if (fp_zero_operand (op, mode))
475 /* Nonzero if OP is a floating point value with value 0.0. */
478 fp_zero_operand (op, mode)
480 enum machine_mode mode;
482 if (GET_MODE_CLASS (GET_MODE (op)) != MODE_FLOAT)
484 return op == CONST0_RTX (mode);
487 /* Nonzero if OP is a floating point constant which can
488 be loaded into an integer register using a single
489 sethi instruction. */
495 if (GET_CODE (op) == CONST_DOUBLE)
500 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
501 if (REAL_VALUES_EQUAL (r, dconst0) &&
502 ! REAL_VALUE_MINUS_ZERO (r))
504 REAL_VALUE_TO_TARGET_SINGLE (r, i);
505 if (SPARC_SETHI_P (i))
512 /* Nonzero if OP is a floating point constant which can
513 be loaded into an integer register using a single
520 if (GET_CODE (op) == CONST_DOUBLE)
525 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
526 if (REAL_VALUES_EQUAL (r, dconst0) &&
527 ! REAL_VALUE_MINUS_ZERO (r))
529 REAL_VALUE_TO_TARGET_SINGLE (r, i);
530 if (SPARC_SIMM13_P (i))
537 /* Nonzero if OP is a floating point constant which can
538 be loaded into an integer register using a high/losum
539 instruction sequence. */
545 /* The constraints calling this should only be in
546 SFmode move insns, so any constant which cannot
547 be moved using a single insn will do. */
548 if (GET_CODE (op) == CONST_DOUBLE)
553 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
554 if (REAL_VALUES_EQUAL (r, dconst0) &&
555 ! REAL_VALUE_MINUS_ZERO (r))
557 REAL_VALUE_TO_TARGET_SINGLE (r, i);
558 if (! SPARC_SETHI_P (i)
559 && ! SPARC_SIMM13_P (i))
566 /* Nonzero if OP is an integer register. */
569 intreg_operand (op, mode)
571 enum machine_mode mode ATTRIBUTE_UNUSED;
573 return (register_operand (op, SImode)
574 || (TARGET_ARCH64 && register_operand (op, DImode)));
577 /* Nonzero if OP is a floating point condition code register. */
580 fcc_reg_operand (op, mode)
582 enum machine_mode mode;
584 /* This can happen when recog is called from combine. Op may be a MEM.
585 Fail instead of calling abort in this case. */
586 if (GET_CODE (op) != REG)
589 if (mode != VOIDmode && mode != GET_MODE (op))
592 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
595 #if 0 /* ??? ==> 1 when %fcc0-3 are pseudos first. See gen_compare_reg(). */
596 if (reg_renumber == 0)
597 return REGNO (op) >= FIRST_PSEUDO_REGISTER;
598 return REGNO_OK_FOR_CCFP_P (REGNO (op));
600 return (unsigned) REGNO (op) - SPARC_FIRST_V9_FCC_REG < 4;
604 /* Nonzero if OP is a floating point condition code fcc0 register. */
607 fcc0_reg_operand (op, mode)
609 enum machine_mode mode;
611 /* This can happen when recog is called from combine. Op may be a MEM.
612 Fail instead of calling abort in this case. */
613 if (GET_CODE (op) != REG)
616 if (mode != VOIDmode && mode != GET_MODE (op))
619 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
622 return REGNO (op) == SPARC_FCC_REG;
625 /* Nonzero if OP is an integer or floating point condition code register. */
628 icc_or_fcc_reg_operand (op, mode)
630 enum machine_mode mode;
632 if (GET_CODE (op) == REG && REGNO (op) == SPARC_ICC_REG)
634 if (mode != VOIDmode && mode != GET_MODE (op))
637 && GET_MODE (op) != CCmode && GET_MODE (op) != CCXmode)
642 return fcc_reg_operand (op, mode);
645 /* Nonzero if OP can appear as the dest of a RESTORE insn. */
647 restore_operand (op, mode)
649 enum machine_mode mode;
651 return (GET_CODE (op) == REG && GET_MODE (op) == mode
652 && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32)));
655 /* Call insn on SPARC can take a PC-relative constant address, or any regular
659 call_operand (op, mode)
661 enum machine_mode mode;
663 if (GET_CODE (op) != MEM)
666 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
670 call_operand_address (op, mode)
672 enum machine_mode mode;
674 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
677 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
678 reference and a constant. */
681 symbolic_operand (op, mode)
683 enum machine_mode mode;
685 enum machine_mode omode = GET_MODE (op);
687 if (omode != mode && omode != VOIDmode && mode != VOIDmode)
690 switch (GET_CODE (op))
698 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
699 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
700 && GET_CODE (XEXP (op, 1)) == CONST_INT);
707 /* Return truth value of statement that OP is a symbolic memory
708 operand of mode MODE. */
711 symbolic_memory_operand (op, mode)
713 enum machine_mode mode ATTRIBUTE_UNUSED;
715 if (GET_CODE (op) == SUBREG)
716 op = SUBREG_REG (op);
717 if (GET_CODE (op) != MEM)
720 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
721 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
724 /* Return truth value of statement that OP is a LABEL_REF of mode MODE. */
727 label_ref_operand (op, mode)
729 enum machine_mode mode;
731 if (GET_CODE (op) != LABEL_REF)
733 if (GET_MODE (op) != mode)
738 /* Return 1 if the operand is an argument used in generating pic references
739 in either the medium/low or medium/anywhere code models of sparc64. */
742 sp64_medium_pic_operand (op, mode)
744 enum machine_mode mode ATTRIBUTE_UNUSED;
746 /* Check for (const (minus (symbol_ref:GOT)
747 (const (minus (label) (pc))))). */
748 if (GET_CODE (op) != CONST)
751 if (GET_CODE (op) != MINUS)
753 if (GET_CODE (XEXP (op, 0)) != SYMBOL_REF)
755 /* ??? Ensure symbol is GOT. */
756 if (GET_CODE (XEXP (op, 1)) != CONST)
758 if (GET_CODE (XEXP (XEXP (op, 1), 0)) != MINUS)
763 /* Return 1 if the operand is a data segment reference. This includes
764 the readonly data segment, or in other words anything but the text segment.
765 This is needed in the medium/anywhere code model on v9. These values
766 are accessed with EMBMEDANY_BASE_REG. */
769 data_segment_operand (op, mode)
771 enum machine_mode mode ATTRIBUTE_UNUSED;
773 switch (GET_CODE (op))
776 return ! SYMBOL_REF_FLAG (op);
778 /* Assume canonical format of symbol + constant.
781 return data_segment_operand (XEXP (op, 0), VOIDmode);
787 /* Return 1 if the operand is a text segment reference.
788 This is needed in the medium/anywhere code model on v9. */
791 text_segment_operand (op, mode)
793 enum machine_mode mode ATTRIBUTE_UNUSED;
795 switch (GET_CODE (op))
800 return SYMBOL_REF_FLAG (op);
802 /* Assume canonical format of symbol + constant.
805 return text_segment_operand (XEXP (op, 0), VOIDmode);
811 /* Return 1 if the operand is either a register or a memory operand that is
815 reg_or_nonsymb_mem_operand (op, mode)
817 enum machine_mode mode;
819 if (register_operand (op, mode))
822 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
829 splittable_symbolic_memory_operand (op, mode)
831 enum machine_mode mode ATTRIBUTE_UNUSED;
833 if (GET_CODE (op) != MEM)
835 if (! symbolic_operand (XEXP (op, 0), Pmode))
841 splittable_immediate_memory_operand (op, mode)
843 enum machine_mode mode ATTRIBUTE_UNUSED;
845 if (GET_CODE (op) != MEM)
847 if (! immediate_operand (XEXP (op, 0), Pmode))
852 /* Return truth value of whether OP is EQ or NE. */
857 enum machine_mode mode ATTRIBUTE_UNUSED;
859 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
862 /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
863 or LTU for non-floating-point. We handle those specially. */
866 normal_comp_operator (op, mode)
868 enum machine_mode mode ATTRIBUTE_UNUSED;
870 enum rtx_code code = GET_CODE (op);
872 if (GET_RTX_CLASS (code) != '<')
875 if (GET_MODE (XEXP (op, 0)) == CCFPmode
876 || GET_MODE (XEXP (op, 0)) == CCFPEmode)
879 return (code != NE && code != EQ && code != GEU && code != LTU);
882 /* Return 1 if this is a comparison operator. This allows the use of
883 MATCH_OPERATOR to recognize all the branch insns. */
886 noov_compare_op (op, mode)
888 enum machine_mode mode ATTRIBUTE_UNUSED;
890 enum rtx_code code = GET_CODE (op);
892 if (GET_RTX_CLASS (code) != '<')
895 if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode
896 || GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
897 /* These are the only branches which work with CC_NOOVmode. */
898 return (code == EQ || code == NE || code == GE || code == LT);
902 /* Return 1 if this is a 64-bit comparison operator. This allows the use of
903 MATCH_OPERATOR to recognize all the branch insns. */
906 noov_compare64_op (op, mode)
908 enum machine_mode mode ATTRIBUTE_UNUSED;
910 enum rtx_code code = GET_CODE (op);
915 if (GET_RTX_CLASS (code) != '<')
918 if (GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
919 /* These are the only branches which work with CCX_NOOVmode. */
920 return (code == EQ || code == NE || code == GE || code == LT);
921 return (GET_MODE (XEXP (op, 0)) == CCXmode);
924 /* Nonzero if OP is a comparison operator suitable for use in v9
925 conditional move or branch on register contents instructions. */
928 v9_regcmp_op (op, mode)
930 enum machine_mode mode ATTRIBUTE_UNUSED;
932 enum rtx_code code = GET_CODE (op);
934 if (GET_RTX_CLASS (code) != '<')
937 return v9_regcmp_p (code);
940 /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */
945 enum machine_mode mode ATTRIBUTE_UNUSED;
947 return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
950 /* Return nonzero if OP is an operator of mode MODE which can set
951 the condition codes explicitly. We do not include PLUS and MINUS
952 because these require CC_NOOVmode, which we handle explicitly. */
955 cc_arithop (op, mode)
957 enum machine_mode mode ATTRIBUTE_UNUSED;
959 if (GET_CODE (op) == AND
960 || GET_CODE (op) == IOR
961 || GET_CODE (op) == XOR)
967 /* Return nonzero if OP is an operator of mode MODE which can bitwise
968 complement its second operand and set the condition codes explicitly. */
971 cc_arithopn (op, mode)
973 enum machine_mode mode ATTRIBUTE_UNUSED;
975 /* XOR is not here because combine canonicalizes (xor (not ...) ...)
976 and (xor ... (not ...)) to (not (xor ...)). */
977 return (GET_CODE (op) == AND
978 || GET_CODE (op) == IOR);
981 /* Return true if OP is a register, or is a CONST_INT that can fit in a
982 signed 13 bit immediate field. This is an acceptable SImode operand for
983 most 3 address instructions. */
986 arith_operand (op, mode)
988 enum machine_mode mode;
990 if (register_operand (op, mode))
992 if (GET_CODE (op) != CONST_INT)
994 return SMALL_INT32 (op);
997 /* Return true if OP is a constant 4096 */
1000 arith_4096_operand (op, mode)
1002 enum machine_mode mode ATTRIBUTE_UNUSED;
1004 if (GET_CODE (op) != CONST_INT)
1007 return INTVAL (op) == 4096;
1010 /* Return true if OP is suitable as second operand for add/sub */
1013 arith_add_operand (op, mode)
1015 enum machine_mode mode;
1017 return arith_operand (op, mode) || arith_4096_operand (op, mode);
1020 /* Return true if OP is a CONST_INT or a CONST_DOUBLE which can fit in the
1021 immediate field of OR and XOR instructions. Used for 64-bit
1022 constant formation patterns. */
1024 const64_operand (op, mode)
1026 enum machine_mode mode ATTRIBUTE_UNUSED;
1028 return ((GET_CODE (op) == CONST_INT
1029 && SPARC_SIMM13_P (INTVAL (op)))
1030 #if HOST_BITS_PER_WIDE_INT != 64
1031 || (GET_CODE (op) == CONST_DOUBLE
1032 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1033 && (CONST_DOUBLE_HIGH (op) ==
1034 ((CONST_DOUBLE_LOW (op) & 0x80000000) != 0 ?
1035 (HOST_WIDE_INT)-1 : 0)))
1040 /* The same, but only for sethi instructions. */
1042 const64_high_operand (op, mode)
1044 enum machine_mode mode;
1046 return ((GET_CODE (op) == CONST_INT
1047 && (INTVAL (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1048 && SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1050 || (GET_CODE (op) == CONST_DOUBLE
1051 && CONST_DOUBLE_HIGH (op) == 0
1052 && (CONST_DOUBLE_LOW (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1053 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op))));
1056 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1057 signed 11 bit immediate field. This is an acceptable SImode operand for
1058 the movcc instructions. */
1061 arith11_operand (op, mode)
1063 enum machine_mode mode;
1065 return (register_operand (op, mode)
1066 || (GET_CODE (op) == CONST_INT && SPARC_SIMM11_P (INTVAL (op))));
1069 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1070 signed 10 bit immediate field. This is an acceptable SImode operand for
1071 the movrcc instructions. */
1074 arith10_operand (op, mode)
1076 enum machine_mode mode;
1078 return (register_operand (op, mode)
1079 || (GET_CODE (op) == CONST_INT && SPARC_SIMM10_P (INTVAL (op))));
1082 /* Return true if OP is a register, is a CONST_INT that fits in a 13 bit
1083 immediate field, or is a CONST_DOUBLE whose both parts fit in a 13 bit
1085 v9: Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1086 can fit in a 13 bit immediate field. This is an acceptable DImode operand
1087 for most 3 address instructions. */
1090 arith_double_operand (op, mode)
1092 enum machine_mode mode;
1094 return (register_operand (op, mode)
1095 || (GET_CODE (op) == CONST_INT && SMALL_INT (op))
1097 && GET_CODE (op) == CONST_DOUBLE
1098 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1099 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_HIGH (op) + 0x1000) < 0x2000)
1101 && GET_CODE (op) == CONST_DOUBLE
1102 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1103 && ((CONST_DOUBLE_HIGH (op) == -1
1104 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
1105 || (CONST_DOUBLE_HIGH (op) == 0
1106 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
1109 /* Return true if OP is a constant 4096 for DImode on ARCH64 */
1112 arith_double_4096_operand (op, mode)
1114 enum machine_mode mode ATTRIBUTE_UNUSED;
1116 return (TARGET_ARCH64 &&
1117 ((GET_CODE (op) == CONST_INT && INTVAL (op) == 4096) ||
1118 (GET_CODE (op) == CONST_DOUBLE &&
1119 CONST_DOUBLE_LOW (op) == 4096 &&
1120 CONST_DOUBLE_HIGH (op) == 0)));
1123 /* Return true if OP is suitable as second operand for add/sub in DImode */
1126 arith_double_add_operand (op, mode)
1128 enum machine_mode mode;
1130 return arith_double_operand (op, mode) || arith_double_4096_operand (op, mode);
1133 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1134 can fit in an 11 bit immediate field. This is an acceptable DImode
1135 operand for the movcc instructions. */
1136 /* ??? Replace with arith11_operand? */
1139 arith11_double_operand (op, mode)
1141 enum machine_mode mode;
1143 return (register_operand (op, mode)
1144 || (GET_CODE (op) == CONST_DOUBLE
1145 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1146 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x400) < 0x800
1147 && ((CONST_DOUBLE_HIGH (op) == -1
1148 && (CONST_DOUBLE_LOW (op) & 0x400) == 0x400)
1149 || (CONST_DOUBLE_HIGH (op) == 0
1150 && (CONST_DOUBLE_LOW (op) & 0x400) == 0)))
1151 || (GET_CODE (op) == CONST_INT
1152 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1153 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x400) < 0x800));
1156 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1157 can fit in an 10 bit immediate field. This is an acceptable DImode
1158 operand for the movrcc instructions. */
1159 /* ??? Replace with arith10_operand? */
1162 arith10_double_operand (op, mode)
1164 enum machine_mode mode;
1166 return (register_operand (op, mode)
1167 || (GET_CODE (op) == CONST_DOUBLE
1168 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1169 && (unsigned) (CONST_DOUBLE_LOW (op) + 0x200) < 0x400
1170 && ((CONST_DOUBLE_HIGH (op) == -1
1171 && (CONST_DOUBLE_LOW (op) & 0x200) == 0x200)
1172 || (CONST_DOUBLE_HIGH (op) == 0
1173 && (CONST_DOUBLE_LOW (op) & 0x200) == 0)))
1174 || (GET_CODE (op) == CONST_INT
1175 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1176 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x200) < 0x400));
1179 /* Return truth value of whether OP is an integer which fits the
1180 range constraining immediate operands in most three-address insns,
1181 which have a 13 bit immediate field. */
1184 small_int (op, mode)
1186 enum machine_mode mode ATTRIBUTE_UNUSED;
1188 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
1192 small_int_or_double (op, mode)
1194 enum machine_mode mode ATTRIBUTE_UNUSED;
1196 return ((GET_CODE (op) == CONST_INT && SMALL_INT (op))
1197 || (GET_CODE (op) == CONST_DOUBLE
1198 && CONST_DOUBLE_HIGH (op) == 0
1199 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))));
1202 /* Recognize operand values for the umul instruction. That instruction sign
1203 extends immediate values just like all other sparc instructions, but
1204 interprets the extended result as an unsigned number. */
1207 uns_small_int (op, mode)
1209 enum machine_mode mode ATTRIBUTE_UNUSED;
1211 #if HOST_BITS_PER_WIDE_INT > 32
1212 /* All allowed constants will fit a CONST_INT. */
1213 return (GET_CODE (op) == CONST_INT
1214 && ((INTVAL (op) >= 0 && INTVAL (op) < 0x1000)
1215 || (INTVAL (op) >= 0xFFFFF000
1216 && INTVAL (op) <= 0xFFFFFFFF)));
1218 return ((GET_CODE (op) == CONST_INT && (unsigned) INTVAL (op) < 0x1000)
1219 || (GET_CODE (op) == CONST_DOUBLE
1220 && CONST_DOUBLE_HIGH (op) == 0
1221 && (unsigned) CONST_DOUBLE_LOW (op) - 0xFFFFF000 < 0x1000));
1226 uns_arith_operand (op, mode)
1228 enum machine_mode mode;
1230 return register_operand (op, mode) || uns_small_int (op, mode);
1233 /* Return truth value of statement that OP is a call-clobbered register. */
1235 clobbered_register (op, mode)
1237 enum machine_mode mode ATTRIBUTE_UNUSED;
1239 return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
1242 /* Return 1 if OP is a valid operand for the source of a move insn. */
1245 input_operand (op, mode)
1247 enum machine_mode mode;
1249 /* If both modes are non-void they must be the same. */
1250 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1253 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1254 if (GET_CODE (op) == CONST && GET_CODE (XEXP (op, 0)) == CONSTANT_P_RTX)
1257 /* Allow any one instruction integer constant, and all CONST_INT
1258 variants when we are working in DImode and !arch64. */
1259 if (GET_MODE_CLASS (mode) == MODE_INT
1260 && ((GET_CODE (op) == CONST_INT
1261 && (SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1262 || SPARC_SIMM13_P (INTVAL (op))
1264 && ! TARGET_ARCH64)))
1266 && GET_CODE (op) == CONST_DOUBLE
1267 && ((CONST_DOUBLE_HIGH (op) == 0
1268 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op)))
1270 #if HOST_BITS_PER_WIDE_INT == 64
1271 (CONST_DOUBLE_HIGH (op) == 0
1272 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op)))
1274 (SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1275 && (((CONST_DOUBLE_LOW (op) & 0x80000000) == 0
1276 && CONST_DOUBLE_HIGH (op) == 0)
1277 || (CONST_DOUBLE_HIGH (op) == -1
1278 && CONST_DOUBLE_LOW (op) & 0x80000000) != 0))
1283 /* If !arch64 and this is a DImode const, allow it so that
1284 the splits can be generated. */
1287 && GET_CODE (op) == CONST_DOUBLE)
1290 if (register_operand (op, mode))
1293 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1294 && GET_CODE (op) == CONST_DOUBLE)
1297 /* If this is a SUBREG, look inside so that we handle
1298 paradoxical ones. */
1299 if (GET_CODE (op) == SUBREG)
1300 op = SUBREG_REG (op);
1302 /* Check for valid MEM forms. */
1303 if (GET_CODE (op) == MEM)
1305 rtx inside = XEXP (op, 0);
1307 if (GET_CODE (inside) == LO_SUM)
1309 /* We can't allow these because all of the splits
1310 (eventually as they trickle down into DFmode
1311 splits) require offsettable memory references. */
1313 && GET_MODE (op) == TFmode)
1316 return (register_operand (XEXP (inside, 0), Pmode)
1317 && CONSTANT_P (XEXP (inside, 1)));
1319 return memory_address_p (mode, inside);
1326 /* We know it can't be done in one insn when we get here,
1327 the movsi expander guarentees this. */
1329 sparc_emit_set_const32 (op0, op1)
1333 enum machine_mode mode = GET_MODE (op0);
1336 if (GET_CODE (op1) == CONST_INT)
1338 HOST_WIDE_INT value = INTVAL (op1);
1340 if (SPARC_SETHI_P (value & GET_MODE_MASK (mode))
1341 || SPARC_SIMM13_P (value))
1345 /* Full 2-insn decomposition is needed. */
1346 if (reload_in_progress || reload_completed)
1349 temp = gen_reg_rtx (mode);
1351 if (GET_CODE (op1) == CONST_INT)
1353 /* Emit them as real moves instead of a HIGH/LO_SUM,
1354 this way CSE can see everything and reuse intermediate
1355 values if it wants. */
1357 && HOST_BITS_PER_WIDE_INT != 64
1358 && (INTVAL (op1) & 0x80000000) != 0)
1359 emit_insn (gen_rtx_SET
1361 gen_rtx_CONST_DOUBLE (VOIDmode,
1362 INTVAL (op1) & ~(HOST_WIDE_INT)0x3ff,
1365 emit_insn (gen_rtx_SET (VOIDmode, temp,
1366 GEN_INT (INTVAL (op1)
1367 & ~(HOST_WIDE_INT)0x3ff)));
1369 emit_insn (gen_rtx_SET (VOIDmode,
1371 gen_rtx_IOR (mode, temp,
1372 GEN_INT (INTVAL (op1) & 0x3ff))));
1376 /* A symbol, emit in the traditional way. */
1377 emit_insn (gen_rtx_SET (VOIDmode, temp,
1378 gen_rtx_HIGH (mode, op1)));
1379 emit_insn (gen_rtx_SET (VOIDmode,
1380 op0, gen_rtx_LO_SUM (mode, temp, op1)));
1386 /* Sparc-v9 code-model support. */
1388 sparc_emit_set_symbolic_const64 (op0, op1, temp1)
1395 if (temp1 && GET_MODE (temp1) == TImode)
1398 temp1 = gen_rtx_REG (DImode, REGNO (temp1));
1401 switch (sparc_cmodel)
1404 /* The range spanned by all instructions in the object is less
1405 than 2^31 bytes (2GB) and the distance from any instruction
1406 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1407 than 2^31 bytes (2GB).
1409 The executable must be in the low 4TB of the virtual address
1412 sethi %hi(symbol), %temp
1413 or %temp, %lo(symbol), %reg */
1414 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1415 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1419 /* The range spanned by all instructions in the object is less
1420 than 2^31 bytes (2GB) and the distance from any instruction
1421 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1422 than 2^31 bytes (2GB).
1424 The executable must be in the low 16TB of the virtual address
1427 sethi %h44(symbol), %temp1
1428 or %temp1, %m44(symbol), %temp2
1429 sllx %temp2, 12, %temp3
1430 or %temp3, %l44(symbol), %reg */
1431 emit_insn (gen_seth44 (op0, op1));
1432 emit_insn (gen_setm44 (op0, op0, op1));
1433 emit_insn (gen_rtx_SET (VOIDmode, temp1,
1434 gen_rtx_ASHIFT (DImode, op0, GEN_INT (12))));
1435 emit_insn (gen_setl44 (op0, temp1, op1));
1439 /* The range spanned by all instructions in the object is less
1440 than 2^31 bytes (2GB) and the distance from any instruction
1441 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1442 than 2^31 bytes (2GB).
1444 The executable can be placed anywhere in the virtual address
1447 sethi %hh(symbol), %temp1
1448 sethi %lm(symbol), %temp2
1449 or %temp1, %hm(symbol), %temp3
1450 or %temp2, %lo(symbol), %temp4
1451 sllx %temp3, 32, %temp5
1452 or %temp4, %temp5, %reg */
1454 /* It is possible that one of the registers we got for operands[2]
1455 might coincide with that of operands[0] (which is why we made
1456 it TImode). Pick the other one to use as our scratch. */
1457 if (rtx_equal_p (temp1, op0))
1460 temp1 = gen_rtx_REG (DImode, REGNO (temp1) + 1);
1465 emit_insn (gen_sethh (op0, op1));
1466 emit_insn (gen_setlm (temp1, op1));
1467 emit_insn (gen_sethm (op0, op0, op1));
1468 emit_insn (gen_rtx_SET (VOIDmode, op0,
1469 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1470 emit_insn (gen_rtx_SET (VOIDmode, op0,
1471 gen_rtx_PLUS (DImode, op0, temp1)));
1472 emit_insn (gen_setlo (op0, op0, op1));
1476 /* Old old old backwards compatibility kruft here.
1477 Essentially it is MEDLOW with a fixed 64-bit
1478 virtual base added to all data segment addresses.
1479 Text-segment stuff is computed like MEDANY, we can't
1480 reuse the code above because the relocation knobs
1483 Data segment: sethi %hi(symbol), %temp1
1484 or %temp1, %lo(symbol), %temp2
1485 add %temp2, EMBMEDANY_BASE_REG, %reg
1487 Text segment: sethi %uhi(symbol), %temp1
1488 sethi %hi(symbol), %temp2
1489 or %temp1, %ulo(symbol), %temp3
1490 or %temp2, %lo(symbol), %temp4
1491 sllx %temp3, 32, %temp5
1492 or %temp4, %temp5, %reg */
1493 if (data_segment_operand (op1, GET_MODE (op1)))
1495 emit_insn (gen_embmedany_sethi (temp1, op1));
1496 emit_insn (gen_embmedany_brsum (op0, temp1));
1497 emit_insn (gen_embmedany_losum (op0, op0, op1));
1501 /* It is possible that one of the registers we got for operands[2]
1502 might coincide with that of operands[0] (which is why we made
1503 it TImode). Pick the other one to use as our scratch. */
1504 if (rtx_equal_p (temp1, op0))
1507 temp1 = gen_rtx_REG (DImode, REGNO (temp1) + 1);
1512 emit_insn (gen_embmedany_textuhi (op0, op1));
1513 emit_insn (gen_embmedany_texthi (temp1, op1));
1514 emit_insn (gen_embmedany_textulo (op0, op0, op1));
1515 emit_insn (gen_rtx_SET (VOIDmode, op0,
1516 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1517 emit_insn (gen_rtx_SET (VOIDmode, op0,
1518 gen_rtx_PLUS (DImode, op0, temp1)));
1519 emit_insn (gen_embmedany_textlo (op0, op0, op1));
1528 /* These avoid problems when cross compiling. If we do not
1529 go through all this hair then the optimizer will see
1530 invalid REG_EQUAL notes or in some cases none at all. */
1531 static void sparc_emit_set_safe_HIGH64 PARAMS ((rtx, HOST_WIDE_INT));
1532 static rtx gen_safe_SET64 PARAMS ((rtx, HOST_WIDE_INT));
1533 static rtx gen_safe_OR64 PARAMS ((rtx, HOST_WIDE_INT));
1534 static rtx gen_safe_XOR64 PARAMS ((rtx, HOST_WIDE_INT));
1536 #if HOST_BITS_PER_WIDE_INT == 64
1537 #define GEN_HIGHINT64(__x) GEN_INT ((__x) & ~(HOST_WIDE_INT)0x3ff)
1538 #define GEN_INT64(__x) GEN_INT (__x)
1540 #define GEN_HIGHINT64(__x) \
1541 gen_rtx_CONST_DOUBLE (VOIDmode, (__x) & ~(HOST_WIDE_INT)0x3ff, 0)
1542 #define GEN_INT64(__x) \
1543 gen_rtx_CONST_DOUBLE (VOIDmode, (__x) & 0xffffffff, \
1544 ((__x) & 0x80000000 \
1548 /* The optimizer is not to assume anything about exactly
1549 which bits are set for a HIGH, they are unspecified.
1550 Unfortunately this leads to many missed optimizations
1551 during CSE. We mask out the non-HIGH bits, and matches
1552 a plain movdi, to alleviate this problem. */
1554 sparc_emit_set_safe_HIGH64 (dest, val)
1558 emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_HIGHINT64 (val)));
1562 gen_safe_SET64 (dest, val)
1566 return gen_rtx_SET (VOIDmode, dest, GEN_INT64 (val));
1570 gen_safe_OR64 (src, val)
1574 return gen_rtx_IOR (DImode, src, GEN_INT64 (val));
1578 gen_safe_XOR64 (src, val)
1582 return gen_rtx_XOR (DImode, src, GEN_INT64 (val));
1585 /* Worker routines for 64-bit constant formation on arch64.
1586 One of the key things to be doing in these emissions is
1587 to create as many temp REGs as possible. This makes it
1588 possible for half-built constants to be used later when
1589 such values are similar to something required later on.
1590 Without doing this, the optimizer cannot see such
1593 static void sparc_emit_set_const64_quick1
1594 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, int));
1597 sparc_emit_set_const64_quick1 (op0, temp, low_bits, is_neg)
1600 unsigned HOST_WIDE_INT low_bits;
1603 unsigned HOST_WIDE_INT high_bits;
1606 high_bits = (~low_bits) & 0xffffffff;
1608 high_bits = low_bits;
1610 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1613 emit_insn (gen_rtx_SET (VOIDmode, op0,
1614 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1618 /* If we are XOR'ing with -1, then we should emit a one's complement
1619 instead. This way the combiner will notice logical operations
1620 such as ANDN later on and substitute. */
1621 if ((low_bits & 0x3ff) == 0x3ff)
1623 emit_insn (gen_rtx_SET (VOIDmode, op0,
1624 gen_rtx_NOT (DImode, temp)));
1628 emit_insn (gen_rtx_SET (VOIDmode, op0,
1629 gen_safe_XOR64 (temp,
1630 (-(HOST_WIDE_INT)0x400
1631 | (low_bits & 0x3ff)))));
1636 static void sparc_emit_set_const64_quick2
1637 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT,
1638 unsigned HOST_WIDE_INT, int));
1641 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_immediate, shift_count)
1644 unsigned HOST_WIDE_INT high_bits;
1645 unsigned HOST_WIDE_INT low_immediate;
1650 if ((high_bits & 0xfffffc00) != 0)
1652 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1653 if ((high_bits & ~0xfffffc00) != 0)
1654 emit_insn (gen_rtx_SET (VOIDmode, op0,
1655 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1661 emit_insn (gen_safe_SET64 (temp, high_bits));
1665 /* Now shift it up into place. */
1666 emit_insn (gen_rtx_SET (VOIDmode, op0,
1667 gen_rtx_ASHIFT (DImode, temp2,
1668 GEN_INT (shift_count))));
1670 /* If there is a low immediate part piece, finish up by
1671 putting that in as well. */
1672 if (low_immediate != 0)
1673 emit_insn (gen_rtx_SET (VOIDmode, op0,
1674 gen_safe_OR64 (op0, low_immediate)));
1677 static void sparc_emit_set_const64_longway
1678 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1680 /* Full 64-bit constant decomposition. Even though this is the
1681 'worst' case, we still optimize a few things away. */
1683 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits)
1686 unsigned HOST_WIDE_INT high_bits;
1687 unsigned HOST_WIDE_INT low_bits;
1691 if (reload_in_progress || reload_completed)
1694 sub_temp = gen_reg_rtx (DImode);
1696 if ((high_bits & 0xfffffc00) != 0)
1698 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1699 if ((high_bits & ~0xfffffc00) != 0)
1700 emit_insn (gen_rtx_SET (VOIDmode,
1702 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1708 emit_insn (gen_safe_SET64 (temp, high_bits));
1712 if (!reload_in_progress && !reload_completed)
1714 rtx temp2 = gen_reg_rtx (DImode);
1715 rtx temp3 = gen_reg_rtx (DImode);
1716 rtx temp4 = gen_reg_rtx (DImode);
1718 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1719 gen_rtx_ASHIFT (DImode, sub_temp,
1722 sparc_emit_set_safe_HIGH64 (temp2, low_bits);
1723 if ((low_bits & ~0xfffffc00) != 0)
1725 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1726 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1727 emit_insn (gen_rtx_SET (VOIDmode, op0,
1728 gen_rtx_PLUS (DImode, temp4, temp3)));
1732 emit_insn (gen_rtx_SET (VOIDmode, op0,
1733 gen_rtx_PLUS (DImode, temp4, temp2)));
1738 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1739 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1740 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1743 /* We are in the middle of reload, so this is really
1744 painful. However we do still make an attempt to
1745 avoid emitting truly stupid code. */
1746 if (low1 != const0_rtx)
1748 emit_insn (gen_rtx_SET (VOIDmode, op0,
1749 gen_rtx_ASHIFT (DImode, sub_temp,
1750 GEN_INT (to_shift))));
1751 emit_insn (gen_rtx_SET (VOIDmode, op0,
1752 gen_rtx_IOR (DImode, op0, low1)));
1760 if (low2 != const0_rtx)
1762 emit_insn (gen_rtx_SET (VOIDmode, op0,
1763 gen_rtx_ASHIFT (DImode, sub_temp,
1764 GEN_INT (to_shift))));
1765 emit_insn (gen_rtx_SET (VOIDmode, op0,
1766 gen_rtx_IOR (DImode, op0, low2)));
1774 emit_insn (gen_rtx_SET (VOIDmode, op0,
1775 gen_rtx_ASHIFT (DImode, sub_temp,
1776 GEN_INT (to_shift))));
1777 if (low3 != const0_rtx)
1778 emit_insn (gen_rtx_SET (VOIDmode, op0,
1779 gen_rtx_IOR (DImode, op0, low3)));
1784 /* Analyze a 64-bit constant for certain properties. */
1785 static void analyze_64bit_constant
1786 PARAMS ((unsigned HOST_WIDE_INT,
1787 unsigned HOST_WIDE_INT,
1788 int *, int *, int *));
1791 analyze_64bit_constant (high_bits, low_bits, hbsp, lbsp, abbasp)
1792 unsigned HOST_WIDE_INT high_bits, low_bits;
1793 int *hbsp, *lbsp, *abbasp;
1795 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1798 lowest_bit_set = highest_bit_set = -1;
1802 if ((lowest_bit_set == -1)
1803 && ((low_bits >> i) & 1))
1805 if ((highest_bit_set == -1)
1806 && ((high_bits >> (32 - i - 1)) & 1))
1807 highest_bit_set = (64 - i - 1);
1810 && ((highest_bit_set == -1)
1811 || (lowest_bit_set == -1)));
1817 if ((lowest_bit_set == -1)
1818 && ((high_bits >> i) & 1))
1819 lowest_bit_set = i + 32;
1820 if ((highest_bit_set == -1)
1821 && ((low_bits >> (32 - i - 1)) & 1))
1822 highest_bit_set = 32 - i - 1;
1825 && ((highest_bit_set == -1)
1826 || (lowest_bit_set == -1)));
1828 /* If there are no bits set this should have gone out
1829 as one instruction! */
1830 if (lowest_bit_set == -1
1831 || highest_bit_set == -1)
1833 all_bits_between_are_set = 1;
1834 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1838 if ((low_bits & (1 << i)) != 0)
1843 if ((high_bits & (1 << (i - 32))) != 0)
1846 all_bits_between_are_set = 0;
1849 *hbsp = highest_bit_set;
1850 *lbsp = lowest_bit_set;
1851 *abbasp = all_bits_between_are_set;
1854 static int const64_is_2insns
1855 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1858 const64_is_2insns (high_bits, low_bits)
1859 unsigned HOST_WIDE_INT high_bits, low_bits;
1861 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1867 analyze_64bit_constant (high_bits, low_bits,
1868 &highest_bit_set, &lowest_bit_set,
1869 &all_bits_between_are_set);
1871 if ((highest_bit_set == 63
1872 || lowest_bit_set == 0)
1873 && all_bits_between_are_set != 0)
1876 if ((highest_bit_set - lowest_bit_set) < 21)
1882 static unsigned HOST_WIDE_INT create_simple_focus_bits
1883 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
1886 static unsigned HOST_WIDE_INT
1887 create_simple_focus_bits (high_bits, low_bits, lowest_bit_set, shift)
1888 unsigned HOST_WIDE_INT high_bits, low_bits;
1889 int lowest_bit_set, shift;
1891 HOST_WIDE_INT hi, lo;
1893 if (lowest_bit_set < 32)
1895 lo = (low_bits >> lowest_bit_set) << shift;
1896 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
1901 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
1908 /* Here we are sure to be arch64 and this is an integer constant
1909 being loaded into a register. Emit the most efficient
1910 insn sequence possible. Detection of all the 1-insn cases
1911 has been done already. */
1913 sparc_emit_set_const64 (op0, op1)
1917 unsigned HOST_WIDE_INT high_bits, low_bits;
1918 int lowest_bit_set, highest_bit_set;
1919 int all_bits_between_are_set;
1922 /* Sanity check that we know what we are working with. */
1923 if (! TARGET_ARCH64)
1926 if (GET_CODE (op0) != SUBREG)
1928 if (GET_CODE (op0) != REG
1929 || (REGNO (op0) >= SPARC_FIRST_FP_REG
1930 && REGNO (op0) <= SPARC_LAST_V9_FP_REG))
1934 if (reload_in_progress || reload_completed)
1937 temp = gen_reg_rtx (DImode);
1939 if (GET_CODE (op1) != CONST_DOUBLE
1940 && GET_CODE (op1) != CONST_INT)
1942 sparc_emit_set_symbolic_const64 (op0, op1, temp);
1946 if (GET_CODE (op1) == CONST_DOUBLE)
1948 #if HOST_BITS_PER_WIDE_INT == 64
1949 high_bits = (CONST_DOUBLE_LOW (op1) >> 32) & 0xffffffff;
1950 low_bits = CONST_DOUBLE_LOW (op1) & 0xffffffff;
1952 high_bits = CONST_DOUBLE_HIGH (op1);
1953 low_bits = CONST_DOUBLE_LOW (op1);
1958 #if HOST_BITS_PER_WIDE_INT == 64
1959 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
1960 low_bits = (INTVAL (op1) & 0xffffffff);
1962 high_bits = ((INTVAL (op1) < 0) ?
1965 low_bits = INTVAL (op1);
1969 /* low_bits bits 0 --> 31
1970 high_bits bits 32 --> 63 */
1972 analyze_64bit_constant (high_bits, low_bits,
1973 &highest_bit_set, &lowest_bit_set,
1974 &all_bits_between_are_set);
1976 /* First try for a 2-insn sequence. */
1978 /* These situations are preferred because the optimizer can
1979 * do more things with them:
1981 * sllx %reg, shift, %reg
1983 * srlx %reg, shift, %reg
1984 * 3) mov some_small_const, %reg
1985 * sllx %reg, shift, %reg
1987 if (((highest_bit_set == 63
1988 || lowest_bit_set == 0)
1989 && all_bits_between_are_set != 0)
1990 || ((highest_bit_set - lowest_bit_set) < 12))
1992 HOST_WIDE_INT the_const = -1;
1993 int shift = lowest_bit_set;
1995 if ((highest_bit_set != 63
1996 && lowest_bit_set != 0)
1997 || all_bits_between_are_set == 0)
2000 create_simple_focus_bits (high_bits, low_bits,
2003 else if (lowest_bit_set == 0)
2004 shift = -(63 - highest_bit_set);
2006 if (! SPARC_SIMM13_P (the_const))
2009 emit_insn (gen_safe_SET64 (temp, the_const));
2011 emit_insn (gen_rtx_SET (VOIDmode,
2013 gen_rtx_ASHIFT (DImode,
2017 emit_insn (gen_rtx_SET (VOIDmode,
2019 gen_rtx_LSHIFTRT (DImode,
2021 GEN_INT (-shift))));
2027 /* Now a range of 22 or less bits set somewhere.
2028 * 1) sethi %hi(focus_bits), %reg
2029 * sllx %reg, shift, %reg
2030 * 2) sethi %hi(focus_bits), %reg
2031 * srlx %reg, shift, %reg
2033 if ((highest_bit_set - lowest_bit_set) < 21)
2035 unsigned HOST_WIDE_INT focus_bits =
2036 create_simple_focus_bits (high_bits, low_bits,
2037 lowest_bit_set, 10);
2039 if (! SPARC_SETHI_P (focus_bits))
2042 sparc_emit_set_safe_HIGH64 (temp, focus_bits);
2044 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
2045 if (lowest_bit_set < 10)
2046 emit_insn (gen_rtx_SET (VOIDmode,
2048 gen_rtx_LSHIFTRT (DImode, temp,
2049 GEN_INT (10 - lowest_bit_set))));
2050 else if (lowest_bit_set > 10)
2051 emit_insn (gen_rtx_SET (VOIDmode,
2053 gen_rtx_ASHIFT (DImode, temp,
2054 GEN_INT (lowest_bit_set - 10))));
2060 /* 1) sethi %hi(low_bits), %reg
2061 * or %reg, %lo(low_bits), %reg
2062 * 2) sethi %hi(~low_bits), %reg
2063 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
2066 || high_bits == 0xffffffff)
2068 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
2069 (high_bits == 0xffffffff));
2073 /* Now, try 3-insn sequences. */
2075 /* 1) sethi %hi(high_bits), %reg
2076 * or %reg, %lo(high_bits), %reg
2077 * sllx %reg, 32, %reg
2081 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
2085 /* We may be able to do something quick
2086 when the constant is negated, so try that. */
2087 if (const64_is_2insns ((~high_bits) & 0xffffffff,
2088 (~low_bits) & 0xfffffc00))
2090 /* NOTE: The trailing bits get XOR'd so we need the
2091 non-negated bits, not the negated ones. */
2092 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
2094 if ((((~high_bits) & 0xffffffff) == 0
2095 && ((~low_bits) & 0x80000000) == 0)
2096 || (((~high_bits) & 0xffffffff) == 0xffffffff
2097 && ((~low_bits) & 0x80000000) != 0))
2099 int fast_int = (~low_bits & 0xffffffff);
2101 if ((SPARC_SETHI_P (fast_int)
2102 && (~high_bits & 0xffffffff) == 0)
2103 || SPARC_SIMM13_P (fast_int))
2104 emit_insn (gen_safe_SET64 (temp, fast_int));
2106 sparc_emit_set_const64 (temp, GEN_INT64 (fast_int));
2111 #if HOST_BITS_PER_WIDE_INT == 64
2112 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2113 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2115 negated_const = gen_rtx_CONST_DOUBLE (DImode,
2116 (~low_bits) & 0xfffffc00,
2117 (~high_bits) & 0xffffffff);
2119 sparc_emit_set_const64 (temp, negated_const);
2122 /* If we are XOR'ing with -1, then we should emit a one's complement
2123 instead. This way the combiner will notice logical operations
2124 such as ANDN later on and substitute. */
2125 if (trailing_bits == 0x3ff)
2127 emit_insn (gen_rtx_SET (VOIDmode, op0,
2128 gen_rtx_NOT (DImode, temp)));
2132 emit_insn (gen_rtx_SET (VOIDmode,
2134 gen_safe_XOR64 (temp,
2135 (-0x400 | trailing_bits))));
2140 /* 1) sethi %hi(xxx), %reg
2141 * or %reg, %lo(xxx), %reg
2142 * sllx %reg, yyy, %reg
2144 * ??? This is just a generalized version of the low_bits==0
2145 * thing above, FIXME...
2147 if ((highest_bit_set - lowest_bit_set) < 32)
2149 unsigned HOST_WIDE_INT focus_bits =
2150 create_simple_focus_bits (high_bits, low_bits,
2153 /* We can't get here in this state. */
2154 if (highest_bit_set < 32
2155 || lowest_bit_set >= 32)
2158 /* So what we know is that the set bits straddle the
2159 middle of the 64-bit word. */
2160 sparc_emit_set_const64_quick2 (op0, temp,
2166 /* 1) sethi %hi(high_bits), %reg
2167 * or %reg, %lo(high_bits), %reg
2168 * sllx %reg, 32, %reg
2169 * or %reg, low_bits, %reg
2171 if (SPARC_SIMM13_P(low_bits)
2172 && ((int)low_bits > 0))
2174 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2178 /* The easiest way when all else fails, is full decomposition. */
2180 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
2181 high_bits, low_bits, ~high_bits, ~low_bits);
2183 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2186 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2187 return the mode to be used for the comparison. For floating-point,
2188 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2189 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2190 processing is needed. */
2193 select_cc_mode (op, x, y)
2196 rtx y ATTRIBUTE_UNUSED;
2198 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2224 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2225 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2227 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2228 return CCX_NOOVmode;
2234 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2241 /* X and Y are two things to compare using CODE. Emit the compare insn and
2242 return the rtx for the cc reg in the proper mode. */
2245 gen_compare_reg (code, x, y)
2249 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
2252 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2253 fcc regs (cse can't tell they're really call clobbered regs and will
2254 remove a duplicate comparison even if there is an intervening function
2255 call - it will then try to reload the cc reg via an int reg which is why
2256 we need the movcc patterns). It is possible to provide the movcc
2257 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2258 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2259 to tell cse that CCFPE mode registers (even pseudos) are call
2262 /* ??? This is an experiment. Rather than making changes to cse which may
2263 or may not be easy/clean, we do our own cse. This is possible because
2264 we will generate hard registers. Cse knows they're call clobbered (it
2265 doesn't know the same thing about pseudos). If we guess wrong, no big
2266 deal, but if we win, great! */
2268 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2269 #if 1 /* experiment */
2272 /* We cycle through the registers to ensure they're all exercised. */
2273 static int next_fcc_reg = 0;
2274 /* Previous x,y for each fcc reg. */
2275 static rtx prev_args[4][2];
2277 /* Scan prev_args for x,y. */
2278 for (reg = 0; reg < 4; reg++)
2279 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2284 prev_args[reg][0] = x;
2285 prev_args[reg][1] = y;
2286 next_fcc_reg = (next_fcc_reg + 1) & 3;
2288 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2291 cc_reg = gen_reg_rtx (mode);
2292 #endif /* ! experiment */
2293 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2294 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2296 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2298 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2299 gen_rtx_COMPARE (mode, x, y)));
2304 /* This function is used for v9 only.
2305 CODE is the code for an Scc's comparison.
2306 OPERANDS[0] is the target of the Scc insn.
2307 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
2308 been generated yet).
2310 This function is needed to turn
2313 (gt (reg:CCX 100 %icc)
2317 (gt:DI (reg:CCX 100 %icc)
2320 IE: The instruction recognizer needs to see the mode of the comparison to
2321 find the right instruction. We could use "gt:DI" right in the
2322 define_expand, but leaving it out allows us to handle DI, SI, etc.
2324 We refer to the global sparc compare operands sparc_compare_op0 and
2325 sparc_compare_op1. */
2328 gen_v9_scc (compare_code, operands)
2329 enum rtx_code compare_code;
2330 register rtx *operands;
2335 && (GET_MODE (sparc_compare_op0) == DImode
2336 || GET_MODE (operands[0]) == DImode))
2339 op0 = sparc_compare_op0;
2340 op1 = sparc_compare_op1;
2342 /* Try to use the movrCC insns. */
2344 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
2345 && op1 == const0_rtx
2346 && v9_regcmp_p (compare_code))
2348 /* Special case for op0 != 0. This can be done with one instruction if
2349 operands[0] == sparc_compare_op0. */
2351 if (compare_code == NE
2352 && GET_MODE (operands[0]) == DImode
2353 && rtx_equal_p (op0, operands[0]))
2355 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2356 gen_rtx_IF_THEN_ELSE (DImode,
2357 gen_rtx_fmt_ee (compare_code, DImode,
2364 if (reg_overlap_mentioned_p (operands[0], op0))
2366 /* Handle the case where operands[0] == sparc_compare_op0.
2367 We "early clobber" the result. */
2368 op0 = gen_reg_rtx (GET_MODE (sparc_compare_op0));
2369 emit_move_insn (op0, sparc_compare_op0);
2372 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2373 if (GET_MODE (op0) != DImode)
2375 temp = gen_reg_rtx (DImode);
2376 convert_move (temp, op0, 0);
2380 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2381 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2382 gen_rtx_fmt_ee (compare_code, DImode,
2390 operands[1] = gen_compare_reg (compare_code, op0, op1);
2392 switch (GET_MODE (operands[1]))
2402 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2403 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2404 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2405 gen_rtx_fmt_ee (compare_code,
2406 GET_MODE (operands[1]),
2407 operands[1], const0_rtx),
2408 const1_rtx, operands[0])));
2413 /* Emit a conditional jump insn for the v9 architecture using comparison code
2414 CODE and jump target LABEL.
2415 This function exists to take advantage of the v9 brxx insns. */
2418 emit_v9_brxx_insn (code, op0, label)
2422 emit_jump_insn (gen_rtx_SET (VOIDmode,
2424 gen_rtx_IF_THEN_ELSE (VOIDmode,
2425 gen_rtx_fmt_ee (code, GET_MODE (op0),
2427 gen_rtx_LABEL_REF (VOIDmode, label),
2431 /* Generate a DFmode part of a hard TFmode register.
2432 REG is the TFmode hard register, LOW is 1 for the
2433 low 64bit of the register and 0 otherwise.
2436 gen_df_reg (reg, low)
2440 int regno = REGNO (reg);
2442 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2443 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
2444 return gen_rtx_REG (DFmode, regno);
2447 /* Return nonzero if a return peephole merging return with
2448 setting of output register is ok. */
2450 leaf_return_peephole_ok ()
2452 return (actual_fsize == 0);
2455 /* Return nonzero if a branch/jump/call instruction will be emitting
2456 nop into its delay slot. */
2459 empty_delay_slot (insn)
2464 /* If no previous instruction (should not happen), return true. */
2465 if (PREV_INSN (insn) == NULL)
2468 seq = NEXT_INSN (PREV_INSN (insn));
2469 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
2475 /* Return nonzero if TRIAL can go into the function epilogue's
2476 delay slot. SLOT is the slot we are trying to fill. */
2479 eligible_for_epilogue_delay (trial, slot)
2488 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2491 if (get_attr_length (trial) != 1)
2494 /* If there are any call-saved registers, we should scan TRIAL if it
2495 does not reference them. For now just make it easy. */
2499 /* If the function uses __builtin_eh_return, the eh_return machinery
2500 occupies the delay slot. */
2501 if (current_function_calls_eh_return)
2504 /* In the case of a true leaf function, anything can go into the delay slot.
2505 A delay slot only exists however if the frame size is zero, otherwise
2506 we will put an insn to adjust the stack after the return. */
2507 if (current_function_uses_only_leaf_regs)
2509 if (leaf_return_peephole_ok ())
2510 return ((get_attr_in_uncond_branch_delay (trial)
2511 == IN_BRANCH_DELAY_TRUE));
2515 pat = PATTERN (trial);
2517 /* Otherwise, only operations which can be done in tandem with
2518 a `restore' or `return' insn can go into the delay slot. */
2519 if (GET_CODE (SET_DEST (pat)) != REG
2520 || REGNO (SET_DEST (pat)) < 24)
2523 /* If this instruction sets up floating point register and we have a return
2524 instruction, it can probably go in. But restore will not work
2526 if (REGNO (SET_DEST (pat)) >= 32)
2528 if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2529 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2534 /* The set of insns matched here must agree precisely with the set of
2535 patterns paired with a RETURN in sparc.md. */
2537 src = SET_SRC (pat);
2539 /* This matches "*return_[qhs]i" or even "*return_di" on TARGET_ARCH64. */
2540 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2541 && arith_operand (src, GET_MODE (src)))
2544 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2546 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2549 /* This matches "*return_di". */
2550 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2551 && arith_double_operand (src, GET_MODE (src)))
2552 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2554 /* This matches "*return_sf_no_fpu". */
2555 else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode)
2556 && register_operand (src, SFmode))
2559 /* If we have return instruction, anything that does not use
2560 local or output registers and can go into a delay slot wins. */
2561 else if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2562 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2565 /* This matches "*return_addsi". */
2566 else if (GET_CODE (src) == PLUS
2567 && arith_operand (XEXP (src, 0), SImode)
2568 && arith_operand (XEXP (src, 1), SImode)
2569 && (register_operand (XEXP (src, 0), SImode)
2570 || register_operand (XEXP (src, 1), SImode)))
2573 /* This matches "*return_adddi". */
2574 else if (GET_CODE (src) == PLUS
2575 && arith_double_operand (XEXP (src, 0), DImode)
2576 && arith_double_operand (XEXP (src, 1), DImode)
2577 && (register_operand (XEXP (src, 0), DImode)
2578 || register_operand (XEXP (src, 1), DImode)))
2581 /* This can match "*return_losum_[sd]i".
2582 Catch only some cases, so that return_losum* don't have
2584 else if (GET_CODE (src) == LO_SUM
2585 && ! TARGET_CM_MEDMID
2586 && ((register_operand (XEXP (src, 0), SImode)
2587 && immediate_operand (XEXP (src, 1), SImode))
2589 && register_operand (XEXP (src, 0), DImode)
2590 && immediate_operand (XEXP (src, 1), DImode))))
2593 /* sll{,x} reg,1,reg2 is add reg,reg,reg2 as well. */
2594 else if (GET_CODE (src) == ASHIFT
2595 && (register_operand (XEXP (src, 0), SImode)
2596 || register_operand (XEXP (src, 0), DImode))
2597 && XEXP (src, 1) == const1_rtx)
2603 /* Return nonzero if TRIAL can go into the sibling call
2607 eligible_for_sibcall_delay (trial)
2612 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2615 if (get_attr_length (trial) != 1)
2618 pat = PATTERN (trial);
2620 if (current_function_uses_only_leaf_regs)
2622 /* If the tail call is done using the call instruction,
2623 we have to restore %o7 in the delay slot. */
2624 if ((TARGET_ARCH64 && ! TARGET_CM_MEDLOW) || flag_pic)
2627 /* %g1 is used to build the function address */
2628 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
2634 /* Otherwise, only operations which can be done in tandem with
2635 a `restore' insn can go into the delay slot. */
2636 if (GET_CODE (SET_DEST (pat)) != REG
2637 || REGNO (SET_DEST (pat)) < 24
2638 || REGNO (SET_DEST (pat)) >= 32)
2641 /* If it mentions %o7, it can't go in, because sibcall will clobber it
2643 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
2646 src = SET_SRC (pat);
2648 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2649 && arith_operand (src, GET_MODE (src)))
2652 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2654 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2657 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2658 && arith_double_operand (src, GET_MODE (src)))
2659 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2661 else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode)
2662 && register_operand (src, SFmode))
2665 else if (GET_CODE (src) == PLUS
2666 && arith_operand (XEXP (src, 0), SImode)
2667 && arith_operand (XEXP (src, 1), SImode)
2668 && (register_operand (XEXP (src, 0), SImode)
2669 || register_operand (XEXP (src, 1), SImode)))
2672 else if (GET_CODE (src) == PLUS
2673 && arith_double_operand (XEXP (src, 0), DImode)
2674 && arith_double_operand (XEXP (src, 1), DImode)
2675 && (register_operand (XEXP (src, 0), DImode)
2676 || register_operand (XEXP (src, 1), DImode)))
2679 else if (GET_CODE (src) == LO_SUM
2680 && ! TARGET_CM_MEDMID
2681 && ((register_operand (XEXP (src, 0), SImode)
2682 && immediate_operand (XEXP (src, 1), SImode))
2684 && register_operand (XEXP (src, 0), DImode)
2685 && immediate_operand (XEXP (src, 1), DImode))))
2688 else if (GET_CODE (src) == ASHIFT
2689 && (register_operand (XEXP (src, 0), SImode)
2690 || register_operand (XEXP (src, 0), DImode))
2691 && XEXP (src, 1) == const1_rtx)
2698 check_return_regs (x)
2701 switch (GET_CODE (x))
2704 return IN_OR_GLOBAL_P (x);
2719 if (check_return_regs (XEXP (x, 1)) == 0)
2724 return check_return_regs (XEXP (x, 0));
2732 /* Return 1 if TRIAL references only in and global registers. */
2734 eligible_for_return_delay (trial)
2737 if (GET_CODE (PATTERN (trial)) != SET)
2740 return check_return_regs (PATTERN (trial));
2744 short_branch (uid1, uid2)
2747 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
2749 /* Leave a few words of "slop". */
2750 if (delta >= -1023 && delta <= 1022)
2756 /* Return non-zero if REG is not used after INSN.
2757 We assume REG is a reload reg, and therefore does
2758 not live past labels or calls or jumps. */
2760 reg_unused_after (reg, insn)
2764 enum rtx_code code, prev_code = UNKNOWN;
2766 while ((insn = NEXT_INSN (insn)))
2768 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
2771 code = GET_CODE (insn);
2772 if (GET_CODE (insn) == CODE_LABEL)
2775 if (GET_RTX_CLASS (code) == 'i')
2777 rtx set = single_set (insn);
2778 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
2781 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
2783 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
2791 /* The table we use to reference PIC data. */
2792 static rtx global_offset_table;
2794 /* The function we use to get at it. */
2795 static rtx get_pc_symbol;
2796 static char get_pc_symbol_name[256];
2798 /* Ensure that we are not using patterns that are not OK with PIC. */
2807 if (GET_CODE (recog_data.operand[i]) == SYMBOL_REF
2808 || (GET_CODE (recog_data.operand[i]) == CONST
2809 && ! (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
2810 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
2811 == global_offset_table)
2812 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
2821 /* Return true if X is an address which needs a temporary register when
2822 reloaded while generating PIC code. */
2825 pic_address_needs_scratch (x)
2828 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
2829 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2830 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2831 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2832 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
2838 /* Legitimize PIC addresses. If the address is already position-independent,
2839 we return ORIG. Newly generated position-independent addresses go into a
2840 reg. This is REG if non zero, otherwise we allocate register(s) as
2844 legitimize_pic_address (orig, mode, reg)
2846 enum machine_mode mode ATTRIBUTE_UNUSED;
2849 if (GET_CODE (orig) == SYMBOL_REF)
2851 rtx pic_ref, address;
2856 if (reload_in_progress || reload_completed)
2859 reg = gen_reg_rtx (Pmode);
2864 /* If not during reload, allocate another temp reg here for loading
2865 in the address, so that these instructions can be optimized
2867 rtx temp_reg = ((reload_in_progress || reload_completed)
2868 ? reg : gen_reg_rtx (Pmode));
2870 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
2871 won't get confused into thinking that these two instructions
2872 are loading in the true address of the symbol. If in the
2873 future a PIC rtx exists, that should be used instead. */
2874 if (Pmode == SImode)
2876 emit_insn (gen_movsi_high_pic (temp_reg, orig));
2877 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
2881 emit_insn (gen_movdi_high_pic (temp_reg, orig));
2882 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
2889 pic_ref = gen_rtx_MEM (Pmode,
2890 gen_rtx_PLUS (Pmode,
2891 pic_offset_table_rtx, address));
2892 current_function_uses_pic_offset_table = 1;
2893 RTX_UNCHANGING_P (pic_ref) = 1;
2894 insn = emit_move_insn (reg, pic_ref);
2895 /* Put a REG_EQUAL note on this insn, so that it can be optimized
2897 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
2901 else if (GET_CODE (orig) == CONST)
2905 if (GET_CODE (XEXP (orig, 0)) == PLUS
2906 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
2911 if (reload_in_progress || reload_completed)
2914 reg = gen_reg_rtx (Pmode);
2917 if (GET_CODE (XEXP (orig, 0)) == PLUS)
2919 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
2920 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
2921 base == reg ? 0 : reg);
2926 if (GET_CODE (offset) == CONST_INT)
2928 if (SMALL_INT (offset))
2929 return plus_constant (base, INTVAL (offset));
2930 else if (! reload_in_progress && ! reload_completed)
2931 offset = force_reg (Pmode, offset);
2933 /* If we reach here, then something is seriously wrong. */
2936 return gen_rtx_PLUS (Pmode, base, offset);
2938 else if (GET_CODE (orig) == LABEL_REF)
2939 /* ??? Why do we do this? */
2940 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
2941 the register is live instead, in case it is eliminated. */
2942 current_function_uses_pic_offset_table = 1;
2947 /* Emit special PIC prologues. */
2950 load_pic_register ()
2952 /* Labels to get the PC in the prologue of this function. */
2953 int orig_flag_pic = flag_pic;
2958 /* If we haven't emitted the special get_pc helper function, do so now. */
2959 if (get_pc_symbol_name[0] == 0)
2963 ASM_GENERATE_INTERNAL_LABEL (get_pc_symbol_name, "LGETPC", 0);
2966 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
2968 ASM_OUTPUT_ALIGN (asm_out_file, align);
2969 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LGETPC", 0);
2970 fputs ("\tretl\n\tadd\t%o7, %l7, %l7\n", asm_out_file);
2973 /* Initialize every time through, since we can't easily
2974 know this to be permanent. */
2975 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2976 get_pc_symbol = gen_rtx_SYMBOL_REF (Pmode, get_pc_symbol_name);
2979 emit_insn (gen_get_pc (pic_offset_table_rtx, global_offset_table,
2982 flag_pic = orig_flag_pic;
2984 /* Need to emit this whether or not we obey regdecls,
2985 since setjmp/longjmp can cause life info to screw up.
2986 ??? In the case where we don't obey regdecls, this is not sufficient
2987 since we may not fall out the bottom. */
2988 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
2991 /* Return 1 if RTX is a MEM which is known to be aligned to at
2992 least an 8 byte boundary. */
2995 mem_min_alignment (mem, desired)
2999 rtx addr, base, offset;
3001 /* If it's not a MEM we can't accept it. */
3002 if (GET_CODE (mem) != MEM)
3005 addr = XEXP (mem, 0);
3006 base = offset = NULL_RTX;
3007 if (GET_CODE (addr) == PLUS)
3009 if (GET_CODE (XEXP (addr, 0)) == REG)
3011 base = XEXP (addr, 0);
3013 /* What we are saying here is that if the base
3014 REG is aligned properly, the compiler will make
3015 sure any REG based index upon it will be so
3017 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3018 offset = XEXP (addr, 1);
3020 offset = const0_rtx;
3023 else if (GET_CODE (addr) == REG)
3026 offset = const0_rtx;
3029 if (base != NULL_RTX)
3031 int regno = REGNO (base);
3033 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
3035 /* Check if the compiler has recorded some information
3036 about the alignment of the base REG. If reload has
3037 completed, we already matched with proper alignments.
3038 If not running global_alloc, reload might give us
3039 unaligned pointer to local stack though. */
3041 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
3042 || (optimize && reload_completed))
3043 && (INTVAL (offset) & (desired - 1)) == 0)
3048 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
3052 else if (! TARGET_UNALIGNED_DOUBLES
3053 || CONSTANT_P (addr)
3054 || GET_CODE (addr) == LO_SUM)
3056 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
3057 is true, in which case we can only assume that an access is aligned if
3058 it is to a constant address, or the address involves a LO_SUM. */
3062 /* An obviously unaligned address. */
3067 /* Vectors to keep interesting information about registers where it can easily
3068 be got. We use to use the actual mode value as the bit number, but there
3069 are more than 32 modes now. Instead we use two tables: one indexed by
3070 hard register number, and one indexed by mode. */
3072 /* The purpose of sparc_mode_class is to shrink the range of modes so that
3073 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
3074 mapped into one sparc_mode_class mode. */
3076 enum sparc_mode_class {
3077 S_MODE, D_MODE, T_MODE, O_MODE,
3078 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
3082 /* Modes for single-word and smaller quantities. */
3083 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
3085 /* Modes for double-word and smaller quantities. */
3086 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
3088 /* Modes for quad-word and smaller quantities. */
3089 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
3091 /* Modes for 8-word and smaller quantities. */
3092 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
3094 /* Modes for single-float quantities. We must allow any single word or
3095 smaller quantity. This is because the fix/float conversion instructions
3096 take integer inputs/outputs from the float registers. */
3097 #define SF_MODES (S_MODES)
3099 /* Modes for double-float and smaller quantities. */
3100 #define DF_MODES (S_MODES | D_MODES)
3102 /* Modes for double-float only quantities. */
3103 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
3105 /* Modes for quad-float only quantities. */
3106 #define TF_ONLY_MODES (1 << (int) TF_MODE)
3108 /* Modes for quad-float and smaller quantities. */
3109 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
3111 /* Modes for quad-float and double-float quantities. */
3112 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
3114 /* Modes for quad-float pair only quantities. */
3115 #define OF_ONLY_MODES (1 << (int) OF_MODE)
3117 /* Modes for quad-float pairs and smaller quantities. */
3118 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
3120 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
3122 /* Modes for condition codes. */
3123 #define CC_MODES (1 << (int) CC_MODE)
3124 #define CCFP_MODES (1 << (int) CCFP_MODE)
3126 /* Value is 1 if register/mode pair is acceptable on sparc.
3127 The funny mixture of D and T modes is because integer operations
3128 do not specially operate on tetra quantities, so non-quad-aligned
3129 registers can hold quadword quantities (except %o4 and %i4 because
3130 they cross fixed registers). */
3132 /* This points to either the 32 bit or the 64 bit version. */
3133 const int *hard_regno_mode_classes;
3135 static const int hard_32bit_mode_classes[] = {
3136 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3137 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3138 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3139 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3141 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3142 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3143 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3144 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3146 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3147 and none can hold SFmode/SImode values. */
3148 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3149 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3150 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3151 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3154 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3160 static const int hard_64bit_mode_classes[] = {
3161 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3162 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3163 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3164 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3166 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3167 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3168 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3169 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3171 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3172 and none can hold SFmode/SImode values. */
3173 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3174 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3175 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3176 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3179 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3185 int sparc_mode_class [NUM_MACHINE_MODES];
3187 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
3194 for (i = 0; i < NUM_MACHINE_MODES; i++)
3196 switch (GET_MODE_CLASS (i))
3199 case MODE_PARTIAL_INT:
3200 case MODE_COMPLEX_INT:
3201 if (GET_MODE_SIZE (i) <= 4)
3202 sparc_mode_class[i] = 1 << (int) S_MODE;
3203 else if (GET_MODE_SIZE (i) == 8)
3204 sparc_mode_class[i] = 1 << (int) D_MODE;
3205 else if (GET_MODE_SIZE (i) == 16)
3206 sparc_mode_class[i] = 1 << (int) T_MODE;
3207 else if (GET_MODE_SIZE (i) == 32)
3208 sparc_mode_class[i] = 1 << (int) O_MODE;
3210 sparc_mode_class[i] = 0;
3213 case MODE_COMPLEX_FLOAT:
3214 if (GET_MODE_SIZE (i) <= 4)
3215 sparc_mode_class[i] = 1 << (int) SF_MODE;
3216 else if (GET_MODE_SIZE (i) == 8)
3217 sparc_mode_class[i] = 1 << (int) DF_MODE;
3218 else if (GET_MODE_SIZE (i) == 16)
3219 sparc_mode_class[i] = 1 << (int) TF_MODE;
3220 else if (GET_MODE_SIZE (i) == 32)
3221 sparc_mode_class[i] = 1 << (int) OF_MODE;
3223 sparc_mode_class[i] = 0;
3227 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
3228 we must explicitly check for them here. */
3229 if (i == (int) CCFPmode || i == (int) CCFPEmode)
3230 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
3231 else if (i == (int) CCmode || i == (int) CC_NOOVmode
3232 || i == (int) CCXmode || i == (int) CCX_NOOVmode)
3233 sparc_mode_class[i] = 1 << (int) CC_MODE;
3235 sparc_mode_class[i] = 0;
3241 hard_regno_mode_classes = hard_64bit_mode_classes;
3243 hard_regno_mode_classes = hard_32bit_mode_classes;
3245 /* Initialize the array used by REGNO_REG_CLASS. */
3246 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3248 if (i < 16 && TARGET_V8PLUS)
3249 sparc_regno_reg_class[i] = I64_REGS;
3250 else if (i < 32 || i == FRAME_POINTER_REGNUM)
3251 sparc_regno_reg_class[i] = GENERAL_REGS;
3253 sparc_regno_reg_class[i] = FP_REGS;
3255 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
3257 sparc_regno_reg_class[i] = FPCC_REGS;
3259 sparc_regno_reg_class[i] = NO_REGS;
3263 /* Save non call used registers from LOW to HIGH at BASE+OFFSET.
3264 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3265 v9 int regs as it simplifies the code. */
3268 save_regs (file, low, high, base, offset, n_regs, real_offset)
3278 if (TARGET_ARCH64 && high <= 32)
3280 for (i = low; i < high; i++)
3282 if (regs_ever_live[i] && ! call_used_regs[i])
3284 fprintf (file, "\tstx\t%s, [%s+%d]\n",
3285 reg_names[i], base, offset + 4 * n_regs);
3286 if (dwarf2out_do_frame ())
3287 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3294 for (i = low; i < high; i += 2)
3296 if (regs_ever_live[i] && ! call_used_regs[i])
3298 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3300 fprintf (file, "\tstd\t%s, [%s+%d]\n",
3301 reg_names[i], base, offset + 4 * n_regs);
3302 if (dwarf2out_do_frame ())
3304 char *l = dwarf2out_cfi_label ();
3305 dwarf2out_reg_save (l, i, real_offset + 4 * n_regs);
3306 dwarf2out_reg_save (l, i+1, real_offset + 4 * n_regs + 4);
3312 fprintf (file, "\tst\t%s, [%s+%d]\n",
3313 reg_names[i], base, offset + 4 * n_regs);
3314 if (dwarf2out_do_frame ())
3315 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3321 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3323 fprintf (file, "\tst\t%s, [%s+%d]\n",
3324 reg_names[i+1], base, offset + 4 * n_regs + 4);
3325 if (dwarf2out_do_frame ())
3326 dwarf2out_reg_save ("", i + 1, real_offset + 4 * n_regs + 4);
3335 /* Restore non call used registers from LOW to HIGH at BASE+OFFSET.
3337 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3338 v9 int regs as it simplifies the code. */
3341 restore_regs (file, low, high, base, offset, n_regs)
3350 if (TARGET_ARCH64 && high <= 32)
3352 for (i = low; i < high; i++)
3354 if (regs_ever_live[i] && ! call_used_regs[i])
3355 fprintf (file, "\tldx\t[%s+%d], %s\n",
3356 base, offset + 4 * n_regs, reg_names[i]),
3362 for (i = low; i < high; i += 2)
3364 if (regs_ever_live[i] && ! call_used_regs[i])
3365 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3366 fprintf (file, "\tldd\t[%s+%d], %s\n",
3367 base, offset + 4 * n_regs, reg_names[i]),
3370 fprintf (file, "\tld\t[%s+%d], %s\n",
3371 base, offset + 4 * n_regs, reg_names[i]),
3373 else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3374 fprintf (file, "\tld\t[%s+%d], %s\n",
3375 base, offset + 4 * n_regs + 4, reg_names[i+1]),
3382 /* Compute the frame size required by the function. This function is called
3383 during the reload pass and also by output_function_prologue(). */
3386 compute_frame_size (size, leaf_function)
3391 int outgoing_args_size = (current_function_outgoing_args_size
3392 + REG_PARM_STACK_SPACE (current_function_decl));
3394 /* N_REGS is the number of 4-byte regs saved thus far. This applies
3395 even to v9 int regs to be consistent with save_regs/restore_regs. */
3399 for (i = 0; i < 8; i++)
3400 if (regs_ever_live[i] && ! call_used_regs[i])
3405 for (i = 0; i < 8; i += 2)
3406 if ((regs_ever_live[i] && ! call_used_regs[i])
3407 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3411 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
3412 if ((regs_ever_live[i] && ! call_used_regs[i])
3413 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3416 /* Set up values for use in `function_epilogue'. */
3417 num_gfregs = n_regs;
3419 if (leaf_function && n_regs == 0
3420 && size == 0 && current_function_outgoing_args_size == 0)
3422 actual_fsize = apparent_fsize = 0;
3426 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
3427 apparent_fsize = (size - STARTING_FRAME_OFFSET + 7) & -8;
3428 apparent_fsize += n_regs * 4;
3429 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
3432 /* Make sure nothing can clobber our register windows.
3433 If a SAVE must be done, or there is a stack-local variable,
3434 the register window area must be allocated.
3435 ??? For v8 we apparently need an additional 8 bytes of reserved space. */
3436 if (leaf_function == 0 || size > 0)
3437 actual_fsize += (16 * UNITS_PER_WORD) + (TARGET_ARCH64 ? 0 : 8);
3439 return SPARC_STACK_ALIGN (actual_fsize);
3442 /* Build a (32 bit) big number in a register. */
3443 /* ??? We may be able to use the set macro here too. */
3446 build_big_number (file, num, reg)
3451 if (num >= 0 || ! TARGET_ARCH64)
3453 fprintf (file, "\tsethi\t%%hi(%d), %s\n", num, reg);
3454 if ((num & 0x3ff) != 0)
3455 fprintf (file, "\tor\t%s, %%lo(%d), %s\n", reg, num, reg);
3457 else /* num < 0 && TARGET_ARCH64 */
3459 /* Sethi does not sign extend, so we must use a little trickery
3460 to use it for negative numbers. Invert the constant before
3461 loading it in, then use xor immediate to invert the loaded bits
3462 (along with the upper 32 bits) to the desired constant. This
3463 works because the sethi and immediate fields overlap. */
3466 int low = -0x400 + (asize & 0x3FF);
3468 fprintf (file, "\tsethi\t%%hi(%d), %s\n\txor\t%s, %d, %s\n",
3469 inv, reg, reg, low, reg);
3473 /* Output any necessary .register pseudo-ops. */
3475 sparc_output_scratch_registers (file)
3476 FILE *file ATTRIBUTE_UNUSED;
3478 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
3484 /* Check if %g[2367] were used without
3485 .register being printed for them already. */
3486 for (i = 2; i < 8; i++)
3488 if (regs_ever_live [i]
3489 && ! sparc_hard_reg_printed [i])
3491 sparc_hard_reg_printed [i] = 1;
3492 fprintf (file, "\t.register\t%%g%d, #scratch\n", i);
3499 /* This function generates the assembly code for function entry.
3500 FILE is a stdio stream to output the code to.
3501 SIZE is an int: how many units of temporary storage to allocate.
3502 Refer to the array `regs_ever_live' to determine which registers
3503 to save; `regs_ever_live[I]' is nonzero if register number I
3504 is ever used in the function. This macro is responsible for
3505 knowing which registers should not be saved even if used. */
3507 /* On SPARC, move-double insns between fpu and cpu need an 8-byte block
3508 of memory. If any fpu reg is used in the function, we allocate
3509 such a block here, at the bottom of the frame, just in case it's needed.
3511 If this function is a leaf procedure, then we may choose not
3512 to do a "save" insn. The decision about whether or not
3513 to do this is made in regclass.c. */
3516 sparc_output_function_prologue (file, size)
3521 sparc_flat_function_prologue (file, size);
3523 sparc_nonflat_function_prologue (file, size,
3524 current_function_uses_only_leaf_regs);
3527 /* Output code for the function prologue. */
3530 sparc_nonflat_function_prologue (file, size, leaf_function)
3535 sparc_output_scratch_registers (file);
3537 /* Need to use actual_fsize, since we are also allocating
3538 space for our callee (and our own register save area). */
3539 actual_fsize = compute_frame_size (size, leaf_function);
3543 frame_base_name = "%sp";
3544 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
3548 frame_base_name = "%fp";
3549 frame_base_offset = SPARC_STACK_BIAS;
3552 /* This is only for the human reader. */
3553 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
3555 if (actual_fsize == 0)
3557 else if (! leaf_function)
3559 if (actual_fsize <= 4096)
3560 fprintf (file, "\tsave\t%%sp, -%d, %%sp\n", actual_fsize);
3561 else if (actual_fsize <= 8192)
3563 fprintf (file, "\tsave\t%%sp, -4096, %%sp\n");
3564 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3568 build_big_number (file, -actual_fsize, "%g1");
3569 fprintf (file, "\tsave\t%%sp, %%g1, %%sp\n");
3572 else /* leaf function */
3574 if (actual_fsize <= 4096)
3575 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize);
3576 else if (actual_fsize <= 8192)
3578 fprintf (file, "\tadd\t%%sp, -4096, %%sp\n");
3579 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3583 build_big_number (file, -actual_fsize, "%g1");
3584 fprintf (file, "\tadd\t%%sp, %%g1, %%sp\n");
3588 if (dwarf2out_do_frame () && actual_fsize)
3590 char *label = dwarf2out_cfi_label ();
3592 /* The canonical frame address refers to the top of the frame. */
3593 dwarf2out_def_cfa (label, (leaf_function ? STACK_POINTER_REGNUM
3594 : HARD_FRAME_POINTER_REGNUM),
3597 if (! leaf_function)
3599 /* Note the register window save. This tells the unwinder that
3600 it needs to restore the window registers from the previous
3601 frame's window save area at 0(cfa). */
3602 dwarf2out_window_save (label);
3604 /* The return address (-8) is now in %i7. */
3605 dwarf2out_return_reg (label, 31);
3609 /* If doing anything with PIC, do it now. */
3611 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
3613 /* Call saved registers are saved just above the outgoing argument area. */
3616 int offset, real_offset, n_regs;
3619 real_offset = -apparent_fsize;
3620 offset = -apparent_fsize + frame_base_offset;
3621 if (offset < -4096 || offset + num_gfregs * 4 > 4096)
3623 /* ??? This might be optimized a little as %g1 might already have a
3624 value close enough that a single add insn will do. */
3625 /* ??? Although, all of this is probably only a temporary fix
3626 because if %g1 can hold a function result, then
3627 output_function_epilogue will lose (the result will get
3629 build_big_number (file, offset, "%g1");
3630 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
3636 base = frame_base_name;
3639 n_regs = save_regs (file, 0, 8, base, offset, 0, real_offset);
3640 save_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs,
3645 /* Output code to restore any call saved registers. */
3648 output_restore_regs (file, leaf_function)
3655 offset = -apparent_fsize + frame_base_offset;
3656 if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/)
3658 build_big_number (file, offset, "%g1");
3659 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
3665 base = frame_base_name;
3668 n_regs = restore_regs (file, 0, 8, base, offset, 0);
3669 restore_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs);
3672 /* This function generates the assembly code for function exit,
3673 on machines that need it.
3675 The function epilogue should not depend on the current stack pointer!
3676 It should use the frame pointer only. This is mandatory because
3677 of alloca; we also take advantage of it to omit stack adjustments
3678 before returning. */
3681 sparc_output_function_epilogue (file, size)
3686 sparc_flat_function_epilogue (file, size);
3688 sparc_nonflat_function_epilogue (file, size,
3689 current_function_uses_only_leaf_regs);
3692 /* Output code for the function epilogue. */
3695 sparc_nonflat_function_epilogue (file, size, leaf_function)
3697 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
3702 if (current_function_epilogue_delay_list == 0)
3704 /* If code does not drop into the epilogue, we need
3705 do nothing except output pending case vectors. */
3706 rtx insn = get_last_insn ();
3707 if (GET_CODE (insn) == NOTE)
3708 insn = prev_nonnote_insn (insn);
3709 if (insn && GET_CODE (insn) == BARRIER)
3710 goto output_vectors;
3714 output_restore_regs (file, leaf_function);
3716 /* Work out how to skip the caller's unimp instruction if required. */
3718 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%o7+12" : "retl");
3720 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%i7+12" : "ret");
3722 if (! leaf_function)
3724 if (current_function_calls_eh_return)
3726 if (current_function_epilogue_delay_list)
3728 if (SKIP_CALLERS_UNIMP_P)
3731 fputs ("\trestore\n\tretl\n\tadd\t%sp, %g1, %sp\n", file);
3733 /* If we wound up with things in our delay slot, flush them here. */
3734 else if (current_function_epilogue_delay_list)
3736 rtx delay = PATTERN (XEXP (current_function_epilogue_delay_list, 0));
3738 if (TARGET_V9 && ! epilogue_renumber (&delay, 1))
3740 epilogue_renumber (&delay, 0);
3741 fputs (SKIP_CALLERS_UNIMP_P
3742 ? "\treturn\t%i7+12\n"
3743 : "\treturn\t%i7+8\n", file);
3744 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
3751 if (GET_CODE (delay) != SET)
3754 src = SET_SRC (delay);
3755 if (GET_CODE (src) == ASHIFT)
3757 if (XEXP (src, 1) != const1_rtx)
3760 = gen_rtx_PLUS (GET_MODE (src), XEXP (src, 0),
3764 insn = gen_rtx_PARALLEL (VOIDmode,
3765 gen_rtvec (2, delay,
3766 gen_rtx_RETURN (VOIDmode)));
3767 insn = emit_jump_insn (insn);
3769 sparc_emitting_epilogue = true;
3770 final_scan_insn (insn, file, 1, 0, 1);
3771 sparc_emitting_epilogue = false;
3774 else if (TARGET_V9 && ! SKIP_CALLERS_UNIMP_P)
3775 fputs ("\treturn\t%i7+8\n\tnop\n", file);
3777 fprintf (file, "\t%s\n\trestore\n", ret);
3779 /* All of the following cases are for leaf functions. */
3780 else if (current_function_calls_eh_return)
3782 else if (current_function_epilogue_delay_list)
3784 /* eligible_for_epilogue_delay_slot ensures that if this is a
3785 leaf function, then we will only have insn in the delay slot
3786 if the frame size is zero, thus no adjust for the stack is
3788 if (actual_fsize != 0)
3790 fprintf (file, "\t%s\n", ret);
3791 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
3794 /* Output 'nop' instead of 'sub %sp,-0,%sp' when no frame, so as to
3795 avoid generating confusing assembly language output. */
3796 else if (actual_fsize == 0)
3797 fprintf (file, "\t%s\n\tnop\n", ret);
3798 else if (actual_fsize <= 4096)
3799 fprintf (file, "\t%s\n\tsub\t%%sp, -%d, %%sp\n", ret, actual_fsize);
3800 else if (actual_fsize <= 8192)
3801 fprintf (file, "\tsub\t%%sp, -4096, %%sp\n\t%s\n\tsub\t%%sp, -%d, %%sp\n",
3802 ret, actual_fsize - 4096);
3803 else if ((actual_fsize & 0x3ff) == 0)
3804 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
3807 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\tor\t%%g1, %%lo(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
3808 actual_fsize, actual_fsize, ret);
3811 sparc_output_deferred_case_vectors ();
3814 /* Output a sibling call. */
3817 output_sibcall (insn, call_operand)
3818 rtx insn, call_operand;
3820 int leaf_regs = current_function_uses_only_leaf_regs;
3822 int delay_slot = dbr_sequence_length () > 0;
3826 /* Call to restore global regs might clobber
3827 the delay slot. Instead of checking for this
3828 output the delay slot now. */
3831 rtx delay = NEXT_INSN (insn);
3836 final_scan_insn (delay, asm_out_file, 1, 0, 1);
3837 PATTERN (delay) = gen_blockage ();
3838 INSN_CODE (delay) = -1;
3841 output_restore_regs (asm_out_file, leaf_regs);
3844 operands[0] = call_operand;
3848 #ifdef HAVE_AS_RELAX_OPTION
3849 /* If as and ld are relaxing tail call insns into branch always,
3850 use or %o7,%g0,X; call Y; or X,%g0,%o7 always, so that it can
3851 be optimized. With sethi/jmpl as nor ld has no easy way how to
3852 find out if somebody does not branch between the sethi and jmpl. */
3855 int spare_slot = ((TARGET_ARCH32 || TARGET_CM_MEDLOW) && ! flag_pic);
3859 if ((actual_fsize || ! spare_slot) && delay_slot)
3861 rtx delay = NEXT_INSN (insn);
3866 final_scan_insn (delay, asm_out_file, 1, 0, 1);
3867 PATTERN (delay) = gen_blockage ();
3868 INSN_CODE (delay) = -1;
3873 if (actual_fsize <= 4096)
3874 size = actual_fsize;
3875 else if (actual_fsize <= 8192)
3877 fputs ("\tsub\t%sp, -4096, %sp\n", asm_out_file);
3878 size = actual_fsize - 4096;
3880 else if ((actual_fsize & 0x3ff) == 0)
3881 fprintf (asm_out_file,
3882 "\tsethi\t%%hi(%d), %%g1\n\tadd\t%%sp, %%g1, %%sp\n",
3886 fprintf (asm_out_file,
3887 "\tsethi\t%%hi(%d), %%g1\n\tor\t%%g1, %%lo(%d), %%g1\n",
3888 actual_fsize, actual_fsize);
3889 fputs ("\tadd\t%%sp, %%g1, %%sp\n", asm_out_file);
3894 output_asm_insn ("sethi\t%%hi(%a0), %%g1", operands);
3895 output_asm_insn ("jmpl\t%%g1 + %%lo(%a0), %%g0", operands);
3897 fprintf (asm_out_file, "\t sub\t%%sp, -%d, %%sp\n", size);
3898 else if (! delay_slot)
3899 fputs ("\t nop\n", asm_out_file);
3904 fprintf (asm_out_file, "\tsub\t%%sp, -%d, %%sp\n", size);
3905 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
3906 it into branch if possible. */
3907 output_asm_insn ("or\t%%o7, %%g0, %%g1", operands);
3908 output_asm_insn ("call\t%a0, 0", operands);
3909 output_asm_insn (" or\t%%g1, %%g0, %%o7", operands);
3914 output_asm_insn ("call\t%a0, 0", operands);
3917 rtx delay = NEXT_INSN (insn), pat;
3922 pat = PATTERN (delay);
3923 if (GET_CODE (pat) != SET)
3926 operands[0] = SET_DEST (pat);
3927 pat = SET_SRC (pat);
3928 switch (GET_CODE (pat))
3931 operands[1] = XEXP (pat, 0);
3932 operands[2] = XEXP (pat, 1);
3933 output_asm_insn (" restore %r1, %2, %Y0", operands);
3936 operands[1] = XEXP (pat, 0);
3937 operands[2] = XEXP (pat, 1);
3938 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
3941 operands[1] = XEXP (pat, 0);
3942 output_asm_insn (" restore %r1, %r1, %Y0", operands);
3946 output_asm_insn (" restore %%g0, %1, %Y0", operands);
3949 PATTERN (delay) = gen_blockage ();
3950 INSN_CODE (delay) = -1;
3953 fputs ("\t restore\n", asm_out_file);
3957 /* Functions for handling argument passing.
3959 For v8 the first six args are normally in registers and the rest are
3960 pushed. Any arg that starts within the first 6 words is at least
3961 partially passed in a register unless its data type forbids.
3963 For v9, the argument registers are laid out as an array of 16 elements
3964 and arguments are added sequentially. The first 6 int args and up to the
3965 first 16 fp args (depending on size) are passed in regs.
3967 Slot Stack Integral Float Float in structure Double Long Double
3968 ---- ----- -------- ----- ------------------ ------ -----------
3969 15 [SP+248] %f31 %f30,%f31 %d30
3970 14 [SP+240] %f29 %f28,%f29 %d28 %q28
3971 13 [SP+232] %f27 %f26,%f27 %d26
3972 12 [SP+224] %f25 %f24,%f25 %d24 %q24
3973 11 [SP+216] %f23 %f22,%f23 %d22
3974 10 [SP+208] %f21 %f20,%f21 %d20 %q20
3975 9 [SP+200] %f19 %f18,%f19 %d18
3976 8 [SP+192] %f17 %f16,%f17 %d16 %q16
3977 7 [SP+184] %f15 %f14,%f15 %d14
3978 6 [SP+176] %f13 %f12,%f13 %d12 %q12
3979 5 [SP+168] %o5 %f11 %f10,%f11 %d10
3980 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
3981 3 [SP+152] %o3 %f7 %f6,%f7 %d6
3982 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
3983 1 [SP+136] %o1 %f3 %f2,%f3 %d2
3984 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
3986 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
3988 Integral arguments are always passed as 64 bit quantities appropriately
3991 Passing of floating point values is handled as follows.
3992 If a prototype is in scope:
3993 If the value is in a named argument (i.e. not a stdarg function or a
3994 value not part of the `...') then the value is passed in the appropriate
3996 If the value is part of the `...' and is passed in one of the first 6
3997 slots then the value is passed in the appropriate int reg.
3998 If the value is part of the `...' and is not passed in one of the first 6
3999 slots then the value is passed in memory.
4000 If a prototype is not in scope:
4001 If the value is one of the first 6 arguments the value is passed in the
4002 appropriate integer reg and the appropriate fp reg.
4003 If the value is not one of the first 6 arguments the value is passed in
4004 the appropriate fp reg and in memory.
4007 /* Maximum number of int regs for args. */
4008 #define SPARC_INT_ARG_MAX 6
4009 /* Maximum number of fp regs for args. */
4010 #define SPARC_FP_ARG_MAX 16
4012 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
4014 /* Handle the INIT_CUMULATIVE_ARGS macro.
4015 Initialize a variable CUM of type CUMULATIVE_ARGS
4016 for a call to a function whose data type is FNTYPE.
4017 For a library call, FNTYPE is 0. */
4020 init_cumulative_args (cum, fntype, libname, indirect)
4021 CUMULATIVE_ARGS *cum;
4023 rtx libname ATTRIBUTE_UNUSED;
4024 int indirect ATTRIBUTE_UNUSED;
4027 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
4028 cum->libcall_p = fntype == 0;
4031 /* Compute the slot number to pass an argument in.
4032 Returns the slot number or -1 if passing on the stack.
4034 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4035 the preceding args and about the function being called.
4036 MODE is the argument's machine mode.
4037 TYPE is the data type of the argument (as a tree).
4038 This is null for libcalls where that information may
4040 NAMED is nonzero if this argument is a named parameter
4041 (otherwise it is an extra parameter matching an ellipsis).
4042 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
4043 *PREGNO records the register number to use if scalar type.
4044 *PPADDING records the amount of padding needed in words. */
4047 function_arg_slotno (cum, mode, type, named, incoming_p, pregno, ppadding)
4048 const CUMULATIVE_ARGS *cum;
4049 enum machine_mode mode;
4056 int regbase = (incoming_p
4057 ? SPARC_INCOMING_INT_ARG_FIRST
4058 : SPARC_OUTGOING_INT_ARG_FIRST);
4059 int slotno = cum->words;
4064 if (type != 0 && TREE_ADDRESSABLE (type))
4067 && type != 0 && mode == BLKmode
4068 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
4074 /* MODE is VOIDmode when generating the actual call.
4078 case QImode : case CQImode :
4079 case HImode : case CHImode :
4080 case SImode : case CSImode :
4081 case DImode : case CDImode :
4082 case TImode : case CTImode :
4083 if (slotno >= SPARC_INT_ARG_MAX)
4085 regno = regbase + slotno;
4088 case SFmode : case SCmode :
4089 case DFmode : case DCmode :
4090 case TFmode : case TCmode :
4093 if (slotno >= SPARC_INT_ARG_MAX)
4095 regno = regbase + slotno;
4099 if ((mode == TFmode || mode == TCmode)
4100 && (slotno & 1) != 0)
4101 slotno++, *ppadding = 1;
4102 if (TARGET_FPU && named)
4104 if (slotno >= SPARC_FP_ARG_MAX)
4106 regno = SPARC_FP_ARG_FIRST + slotno * 2;
4112 if (slotno >= SPARC_INT_ARG_MAX)
4114 regno = regbase + slotno;
4120 /* For sparc64, objects requiring 16 byte alignment get it. */
4123 if (type && TYPE_ALIGN (type) == 128 && (slotno & 1) != 0)
4124 slotno++, *ppadding = 1;
4128 || (type && TREE_CODE (type) == UNION_TYPE))
4130 if (slotno >= SPARC_INT_ARG_MAX)
4132 regno = regbase + slotno;
4137 int intregs_p = 0, fpregs_p = 0;
4138 /* The ABI obviously doesn't specify how packed
4139 structures are passed. These are defined to be passed
4140 in int regs if possible, otherwise memory. */
4143 /* First see what kinds of registers we need. */
4144 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4146 if (TREE_CODE (field) == FIELD_DECL)
4148 if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4153 if (DECL_PACKED (field))
4157 if (packed_p || !named)
4158 fpregs_p = 0, intregs_p = 1;
4160 /* If all arg slots are filled, then must pass on stack. */
4161 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
4163 /* If there are only int args and all int arg slots are filled,
4164 then must pass on stack. */
4165 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
4167 /* Note that even if all int arg slots are filled, fp members may
4168 still be passed in regs if such regs are available.
4169 *PREGNO isn't set because there may be more than one, it's up
4170 to the caller to compute them. */
4183 /* Handle recursive register counting for structure field layout. */
4185 struct function_arg_record_value_parms
4188 int slotno, named, regbase;
4193 static void function_arg_record_value_3
4194 PARAMS ((HOST_WIDE_INT, struct function_arg_record_value_parms *));
4195 static void function_arg_record_value_2
4196 PARAMS ((tree, HOST_WIDE_INT,
4197 struct function_arg_record_value_parms *));
4198 static void function_arg_record_value_1
4199 PARAMS ((tree, HOST_WIDE_INT,
4200 struct function_arg_record_value_parms *));
4201 static rtx function_arg_record_value
4202 PARAMS ((tree, enum machine_mode, int, int, int));
4204 /* A subroutine of function_arg_record_value. Traverse the structure
4205 recusively and determine how many registers will be required. */
4208 function_arg_record_value_1 (type, startbitpos, parms)
4210 HOST_WIDE_INT startbitpos;
4211 struct function_arg_record_value_parms *parms;
4215 /* The ABI obviously doesn't specify how packed structures are
4216 passed. These are defined to be passed in int regs if possible,
4217 otherwise memory. */
4220 /* We need to compute how many registers are needed so we can
4221 allocate the PARALLEL but before we can do that we need to know
4222 whether there are any packed fields. If there are, int regs are
4223 used regardless of whether there are fp values present. */
4224 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4226 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4233 /* Compute how many registers we need. */
4234 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4236 if (TREE_CODE (field) == FIELD_DECL)
4238 HOST_WIDE_INT bitpos = startbitpos;
4240 if (DECL_SIZE (field) != 0
4241 && host_integerp (bit_position (field), 1))
4242 bitpos += int_bit_position (field);
4244 /* ??? FIXME: else assume zero offset. */
4246 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4247 function_arg_record_value_1 (TREE_TYPE (field), bitpos, parms);
4248 else if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4253 if (parms->intoffset != -1)
4255 int intslots, this_slotno;
4257 intslots = (bitpos - parms->intoffset + BITS_PER_WORD - 1)
4259 this_slotno = parms->slotno + parms->intoffset
4262 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4263 intslots = MAX (intslots, 0);
4264 parms->nregs += intslots;
4265 parms->intoffset = -1;
4268 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
4269 If it wasn't true we wouldn't be here. */
4274 if (parms->intoffset == -1)
4275 parms->intoffset = bitpos;
4281 /* A subroutine of function_arg_record_value. Assign the bits of the
4282 structure between parms->intoffset and bitpos to integer registers. */
4285 function_arg_record_value_3 (bitpos, parms)
4286 HOST_WIDE_INT bitpos;
4287 struct function_arg_record_value_parms *parms;
4289 enum machine_mode mode;
4291 unsigned int startbit, endbit;
4292 int this_slotno, intslots, intoffset;
4295 if (parms->intoffset == -1)
4298 intoffset = parms->intoffset;
4299 parms->intoffset = -1;
4301 startbit = intoffset & -BITS_PER_WORD;
4302 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4303 intslots = (endbit - startbit) / BITS_PER_WORD;
4304 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
4306 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4310 /* If this is the trailing part of a word, only load that much into
4311 the register. Otherwise load the whole register. Note that in
4312 the latter case we may pick up unwanted bits. It's not a problem
4313 at the moment but may wish to revisit. */
4315 if (intoffset % BITS_PER_WORD != 0)
4316 mode = mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
4321 intoffset /= BITS_PER_UNIT;
4324 regno = parms->regbase + this_slotno;
4325 reg = gen_rtx_REG (mode, regno);
4326 XVECEXP (parms->ret, 0, parms->nregs)
4327 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
4330 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
4334 while (intslots > 0);
4337 /* A subroutine of function_arg_record_value. Traverse the structure
4338 recursively and assign bits to floating point registers. Track which
4339 bits in between need integer registers; invoke function_arg_record_value_3
4340 to make that happen. */
4343 function_arg_record_value_2 (type, startbitpos, parms)
4345 HOST_WIDE_INT startbitpos;
4346 struct function_arg_record_value_parms *parms;
4351 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4353 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4360 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4362 if (TREE_CODE (field) == FIELD_DECL)
4364 HOST_WIDE_INT bitpos = startbitpos;
4366 if (DECL_SIZE (field) != 0
4367 && host_integerp (bit_position (field), 1))
4368 bitpos += int_bit_position (field);
4370 /* ??? FIXME: else assume zero offset. */
4372 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4373 function_arg_record_value_2 (TREE_TYPE (field), bitpos, parms);
4374 else if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4379 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
4382 function_arg_record_value_3 (bitpos, parms);
4384 reg = gen_rtx_REG (DECL_MODE (field),
4385 (SPARC_FP_ARG_FIRST + this_slotno * 2
4386 + (DECL_MODE (field) == SFmode
4387 && (bitpos & 32) != 0)));
4388 XVECEXP (parms->ret, 0, parms->nregs)
4389 = gen_rtx_EXPR_LIST (VOIDmode, reg,
4390 GEN_INT (bitpos / BITS_PER_UNIT));
4395 if (parms->intoffset == -1)
4396 parms->intoffset = bitpos;
4402 /* Used by function_arg and function_value to implement the complex
4403 Sparc64 structure calling conventions. */
4406 function_arg_record_value (type, mode, slotno, named, regbase)
4408 enum machine_mode mode;
4409 int slotno, named, regbase;
4411 HOST_WIDE_INT typesize = int_size_in_bytes (type);
4412 struct function_arg_record_value_parms parms;
4415 parms.ret = NULL_RTX;
4416 parms.slotno = slotno;
4417 parms.named = named;
4418 parms.regbase = regbase;
4420 /* Compute how many registers we need. */
4422 parms.intoffset = 0;
4423 function_arg_record_value_1 (type, 0, &parms);
4425 if (parms.intoffset != -1)
4427 unsigned int startbit, endbit;
4428 int intslots, this_slotno;
4430 startbit = parms.intoffset & -BITS_PER_WORD;
4431 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4432 intslots = (endbit - startbit) / BITS_PER_WORD;
4433 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
4435 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4436 intslots = MAX (intslots, 0);
4438 parms.nregs += intslots;
4440 nregs = parms.nregs;
4442 /* Allocate the vector and handle some annoying special cases. */
4445 /* ??? Empty structure has no value? Duh? */
4448 /* Though there's nothing really to store, return a word register
4449 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
4450 leads to breakage due to the fact that there are zero bytes to
4452 return gen_rtx_REG (mode, regbase);
4456 /* ??? C++ has structures with no fields, and yet a size. Give up
4457 for now and pass everything back in integer registers. */
4458 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4460 if (nregs + slotno > SPARC_INT_ARG_MAX)
4461 nregs = SPARC_INT_ARG_MAX - slotno;
4466 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (nregs));
4468 /* Fill in the entries. */
4470 parms.intoffset = 0;
4471 function_arg_record_value_2 (type, 0, &parms);
4472 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
4474 if (parms.nregs != nregs)
4480 /* Handle the FUNCTION_ARG macro.
4481 Determine where to put an argument to a function.
4482 Value is zero to push the argument on the stack,
4483 or a hard register in which to store the argument.
4485 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4486 the preceding args and about the function being called.
4487 MODE is the argument's machine mode.
4488 TYPE is the data type of the argument (as a tree).
4489 This is null for libcalls where that information may
4491 NAMED is nonzero if this argument is a named parameter
4492 (otherwise it is an extra parameter matching an ellipsis).
4493 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
4496 function_arg (cum, mode, type, named, incoming_p)
4497 const CUMULATIVE_ARGS *cum;
4498 enum machine_mode mode;
4503 int regbase = (incoming_p
4504 ? SPARC_INCOMING_INT_ARG_FIRST
4505 : SPARC_OUTGOING_INT_ARG_FIRST);
4506 int slotno, regno, padding;
4509 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
4517 reg = gen_rtx_REG (mode, regno);
4521 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
4522 but also have the slot allocated for them.
4523 If no prototype is in scope fp values in register slots get passed
4524 in two places, either fp regs and int regs or fp regs and memory. */
4525 if ((GET_MODE_CLASS (mode) == MODE_FLOAT
4526 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4527 && SPARC_FP_REG_P (regno))
4529 reg = gen_rtx_REG (mode, regno);
4530 if (cum->prototype_p || cum->libcall_p)
4532 /* "* 2" because fp reg numbers are recorded in 4 byte
4535 /* ??? This will cause the value to be passed in the fp reg and
4536 in the stack. When a prototype exists we want to pass the
4537 value in the reg but reserve space on the stack. That's an
4538 optimization, and is deferred [for a bit]. */
4539 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
4540 return gen_rtx_PARALLEL (mode,
4542 gen_rtx_EXPR_LIST (VOIDmode,
4543 NULL_RTX, const0_rtx),
4544 gen_rtx_EXPR_LIST (VOIDmode,
4548 /* ??? It seems that passing back a register even when past
4549 the area declared by REG_PARM_STACK_SPACE will allocate
4550 space appropriately, and will not copy the data onto the
4551 stack, exactly as we desire.
4553 This is due to locate_and_pad_parm being called in
4554 expand_call whenever reg_parm_stack_space > 0, which
4555 while benefical to our example here, would seem to be
4556 in error from what had been intended. Ho hum... -- r~ */
4564 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
4568 /* On incoming, we don't need to know that the value
4569 is passed in %f0 and %i0, and it confuses other parts
4570 causing needless spillage even on the simplest cases. */
4574 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
4575 + (regno - SPARC_FP_ARG_FIRST) / 2);
4577 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4578 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
4580 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4584 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4585 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4586 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4590 else if (type && TREE_CODE (type) == RECORD_TYPE)
4592 /* Structures up to 16 bytes in size are passed in arg slots on the
4593 stack and are promoted to registers where possible. */
4595 if (int_size_in_bytes (type) > 16)
4596 abort (); /* shouldn't get here */
4598 return function_arg_record_value (type, mode, slotno, named, regbase);
4600 else if (type && TREE_CODE (type) == UNION_TYPE)
4602 enum machine_mode mode;
4603 int bytes = int_size_in_bytes (type);
4608 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
4609 reg = gen_rtx_REG (mode, regno);
4613 /* Scalar or complex int. */
4614 reg = gen_rtx_REG (mode, regno);
4620 /* Handle the FUNCTION_ARG_PARTIAL_NREGS macro.
4621 For an arg passed partly in registers and partly in memory,
4622 this is the number of registers used.
4623 For args passed entirely in registers or entirely in memory, zero.
4625 Any arg that starts in the first 6 regs but won't entirely fit in them
4626 needs partial registers on v8. On v9, structures with integer
4627 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
4628 values that begin in the last fp reg [where "last fp reg" varies with the
4629 mode] will be split between that reg and memory. */
4632 function_arg_partial_nregs (cum, mode, type, named)
4633 const CUMULATIVE_ARGS *cum;
4634 enum machine_mode mode;
4638 int slotno, regno, padding;
4640 /* We pass 0 for incoming_p here, it doesn't matter. */
4641 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
4648 if ((slotno + (mode == BLKmode
4649 ? ROUND_ADVANCE (int_size_in_bytes (type))
4650 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
4651 > NPARM_REGS (SImode))
4652 return NPARM_REGS (SImode) - slotno;
4657 if (type && AGGREGATE_TYPE_P (type))
4659 int size = int_size_in_bytes (type);
4660 int align = TYPE_ALIGN (type);
4663 slotno += slotno & 1;
4664 if (size > 8 && size <= 16
4665 && slotno == SPARC_INT_ARG_MAX - 1)
4668 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
4669 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
4672 if (GET_MODE_ALIGNMENT (mode) == 128)
4674 slotno += slotno & 1;
4675 if (slotno == SPARC_INT_ARG_MAX - 2)
4680 if (slotno == SPARC_INT_ARG_MAX - 1)
4684 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4686 if (GET_MODE_ALIGNMENT (mode) == 128)
4687 slotno += slotno & 1;
4688 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
4696 /* Handle the FUNCTION_ARG_PASS_BY_REFERENCE macro.
4697 !v9: The SPARC ABI stipulates passing struct arguments (of any size) and
4698 quad-precision floats by invisible reference.
4699 v9: Aggregates greater than 16 bytes are passed by reference.
4700 For Pascal, also pass arrays by reference. */
4703 function_arg_pass_by_reference (cum, mode, type, named)
4704 const CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
4705 enum machine_mode mode;
4707 int named ATTRIBUTE_UNUSED;
4711 return ((type && AGGREGATE_TYPE_P (type))
4712 || mode == TFmode || mode == TCmode);
4716 return ((type && TREE_CODE (type) == ARRAY_TYPE)
4717 /* Consider complex values as aggregates, so care for TCmode. */
4718 || GET_MODE_SIZE (mode) > 16
4720 && AGGREGATE_TYPE_P (type)
4721 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16));
4725 /* Handle the FUNCTION_ARG_ADVANCE macro.
4726 Update the data in CUM to advance over an argument
4727 of mode MODE and data type TYPE.
4728 TYPE is null for libcalls where that information may not be available. */
4731 function_arg_advance (cum, mode, type, named)
4732 CUMULATIVE_ARGS *cum;
4733 enum machine_mode mode;
4737 int slotno, regno, padding;
4739 /* We pass 0 for incoming_p here, it doesn't matter. */
4740 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
4742 /* If register required leading padding, add it. */
4744 cum->words += padding;
4748 cum->words += (mode != BLKmode
4749 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
4750 : ROUND_ADVANCE (int_size_in_bytes (type)));
4754 if (type && AGGREGATE_TYPE_P (type))
4756 int size = int_size_in_bytes (type);
4760 else if (size <= 16)
4762 else /* passed by reference */
4765 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
4769 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4771 cum->words += GET_MODE_SIZE (mode) / UNITS_PER_WORD;
4775 cum->words += (mode != BLKmode
4776 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
4777 : ROUND_ADVANCE (int_size_in_bytes (type)));
4782 /* Handle the FUNCTION_ARG_PADDING macro.
4783 For the 64 bit ABI structs are always stored left shifted in their
4787 function_arg_padding (mode, type)
4788 enum machine_mode mode;
4791 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
4794 /* This is the default definition. */
4795 return (! BYTES_BIG_ENDIAN
4798 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
4799 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
4800 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
4801 ? downward : upward));
4804 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
4805 For v9, function return values are subject to the same rules as arguments,
4806 except that up to 32-bytes may be returned in registers. */
4809 function_value (type, mode, incoming_p)
4811 enum machine_mode mode;
4815 int regbase = (incoming_p
4816 ? SPARC_OUTGOING_INT_ARG_FIRST
4817 : SPARC_INCOMING_INT_ARG_FIRST);
4819 if (TARGET_ARCH64 && type)
4821 if (TREE_CODE (type) == RECORD_TYPE)
4823 /* Structures up to 32 bytes in size are passed in registers,
4824 promoted to fp registers where possible. */
4826 if (int_size_in_bytes (type) > 32)
4827 abort (); /* shouldn't get here */
4829 return function_arg_record_value (type, mode, 0, 1, regbase);
4831 else if (AGGREGATE_TYPE_P (type))
4833 /* All other aggregate types are passed in an integer register
4834 in a mode corresponding to the size of the type. */
4835 HOST_WIDE_INT bytes = int_size_in_bytes (type);
4840 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
4845 && GET_MODE_CLASS (mode) == MODE_INT
4846 && GET_MODE_SIZE (mode) < UNITS_PER_WORD
4847 && type && ! AGGREGATE_TYPE_P (type))
4851 regno = BASE_RETURN_VALUE_REG (mode);
4853 regno = BASE_OUTGOING_VALUE_REG (mode);
4855 return gen_rtx_REG (mode, regno);
4858 /* Do what is necessary for `va_start'. We look at the current function
4859 to determine if stdarg or varargs is used and return the address of
4860 the first unnamed parameter. */
4863 sparc_builtin_saveregs ()
4865 int first_reg = current_function_args_info.words;
4869 for (regno = first_reg; regno < NPARM_REGS (word_mode); regno++)
4870 emit_move_insn (gen_rtx_MEM (word_mode,
4871 gen_rtx_PLUS (Pmode,
4873 GEN_INT (FIRST_PARM_OFFSET (0)
4876 gen_rtx_REG (word_mode,
4877 BASE_INCOMING_ARG_REG (word_mode) + regno));
4879 address = gen_rtx_PLUS (Pmode,
4881 GEN_INT (FIRST_PARM_OFFSET (0)
4882 + UNITS_PER_WORD * first_reg));
4887 /* Implement `va_start' for varargs and stdarg. */
4890 sparc_va_start (stdarg_p, valist, nextarg)
4891 int stdarg_p ATTRIBUTE_UNUSED;
4895 nextarg = expand_builtin_saveregs ();
4896 std_expand_builtin_va_start (1, valist, nextarg);
4899 /* Implement `va_arg'. */
4902 sparc_va_arg (valist, type)
4905 HOST_WIDE_INT size, rsize, align;
4910 /* Round up sizeof(type) to a word. */
4911 size = int_size_in_bytes (type);
4912 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
4917 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
4918 align = 2 * UNITS_PER_WORD;
4920 if (AGGREGATE_TYPE_P (type))
4922 if ((unsigned HOST_WIDE_INT) size > 16)
4925 size = rsize = UNITS_PER_WORD;
4933 if (AGGREGATE_TYPE_P (type)
4934 || TYPE_MODE (type) == TFmode
4935 || TYPE_MODE (type) == TCmode)
4938 size = rsize = UNITS_PER_WORD;
4945 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
4946 build_int_2 (align - 1, 0)));
4947 incr = fold (build (BIT_AND_EXPR, ptr_type_node, incr,
4948 build_int_2 (-align, -1)));
4951 addr = incr = save_expr (incr);
4952 if (BYTES_BIG_ENDIAN && size < rsize)
4954 addr = fold (build (PLUS_EXPR, ptr_type_node, incr,
4955 build_int_2 (rsize - size, 0)));
4957 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
4958 build_int_2 (rsize, 0)));
4960 incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
4961 TREE_SIDE_EFFECTS (incr) = 1;
4962 expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
4964 addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
4966 /* If the address isn't aligned properly for the type,
4967 we may need to copy to a temporary.
4968 FIXME: This is inefficient. Usually we can do this
4971 && TYPE_ALIGN (type) > BITS_PER_WORD
4974 /* FIXME: We really need to specify that the temporary is live
4975 for the whole function because expand_builtin_va_arg wants
4976 the alias set to be get_varargs_alias_set (), but in this
4977 case the alias set is that for TYPE and if the memory gets
4978 reused it will be reused with alias set TYPE. */
4979 rtx tmp = assign_temp (type, 0, 1, 0);
4982 addr_rtx = force_reg (Pmode, addr_rtx);
4983 addr_rtx = gen_rtx_MEM (BLKmode, addr_rtx);
4984 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
4985 set_mem_align (addr_rtx, BITS_PER_WORD);
4986 tmp = shallow_copy_rtx (tmp);
4987 PUT_MODE (tmp, BLKmode);
4988 set_mem_alias_set (tmp, 0);
4990 dest_addr = emit_block_move (tmp, addr_rtx, GEN_INT (rsize));
4991 if (dest_addr != NULL_RTX)
4992 addr_rtx = dest_addr;
4994 addr_rtx = XCEXP (tmp, 0, MEM);
4999 addr_rtx = force_reg (Pmode, addr_rtx);
5000 addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
5001 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
5007 /* Return the string to output a conditional branch to LABEL, which is
5008 the operand number of the label. OP is the conditional expression.
5009 XEXP (OP, 0) is assumed to be a condition code register (integer or
5010 floating point) and its mode specifies what kind of comparison we made.
5012 REVERSED is non-zero if we should reverse the sense of the comparison.
5014 ANNUL is non-zero if we should generate an annulling branch.
5016 NOOP is non-zero if we have to follow this branch by a noop.
5018 INSN, if set, is the insn. */
5021 output_cbranch (op, dest, label, reversed, annul, noop, insn)
5024 int reversed, annul, noop;
5027 static char string[50];
5028 enum rtx_code code = GET_CODE (op);
5029 rtx cc_reg = XEXP (op, 0);
5030 enum machine_mode mode = GET_MODE (cc_reg);
5031 const char *labelno, *branch;
5032 int spaces = 8, far;
5035 /* v9 branches are limited to +-1MB. If it is too far away,
5048 fbne,a,pn %fcc2, .LC29
5056 far = get_attr_length (insn) >= 3;
5059 /* Reversal of FP compares takes care -- an ordered compare
5060 becomes an unordered compare and vice versa. */
5061 if (mode == CCFPmode || mode == CCFPEmode)
5062 code = reverse_condition_maybe_unordered (code);
5064 code = reverse_condition (code);
5067 /* Start by writing the branch condition. */
5068 if (mode == CCFPmode || mode == CCFPEmode)
5119 /* ??? !v9: FP branches cannot be preceded by another floating point
5120 insn. Because there is currently no concept of pre-delay slots,
5121 we can fix this only by always emitting a nop before a floating
5126 strcpy (string, "nop\n\t");
5127 strcat (string, branch);
5140 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5152 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5173 strcpy (string, branch);
5175 spaces -= strlen (branch);
5176 p = strchr (string, '\0');
5178 /* Now add the annulling, the label, and a possible noop. */
5193 if (! far && insn && INSN_ADDRESSES_SET_P ())
5195 int delta = (INSN_ADDRESSES (INSN_UID (dest))
5196 - INSN_ADDRESSES (INSN_UID (insn)));
5197 /* Leave some instructions for "slop". */
5198 if (delta < -260000 || delta >= 260000)
5202 if (mode == CCFPmode || mode == CCFPEmode)
5204 static char v9_fcc_labelno[] = "%%fccX, ";
5205 /* Set the char indicating the number of the fcc reg to use. */
5206 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
5207 labelno = v9_fcc_labelno;
5210 if (REGNO (cc_reg) == SPARC_FCC_REG)
5216 else if (mode == CCXmode || mode == CCX_NOOVmode)
5218 labelno = "%%xcc, ";
5224 labelno = "%%icc, ";
5229 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PRED, NULL_RTX)))
5232 (((INTVAL (XEXP (note, 0)) & ATTR_FLAG_likely) != 0) ^ far)
5242 strcpy (p, labelno);
5243 p = strchr (p, '\0');
5246 strcpy (p, ".+12\n\tnop\n\tb\t");
5253 /* Set the char indicating the number of the operand containing the
5258 strcpy (p, "\n\tnop");
5263 /* Emit a library call comparison between floating point X and Y.
5264 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
5265 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
5266 values as arguments instead of the TFmode registers themselves,
5267 that's why we cannot call emit_float_lib_cmp. */
5269 sparc_emit_float_lib_cmp (x, y, comparison)
5271 enum rtx_code comparison;
5274 rtx slot0, slot1, result, tem, tem2;
5275 enum machine_mode mode;
5280 qpfunc = (TARGET_ARCH64) ? "_Qp_feq" : "_Q_feq";
5284 qpfunc = (TARGET_ARCH64) ? "_Qp_fne" : "_Q_fne";
5288 qpfunc = (TARGET_ARCH64) ? "_Qp_fgt" : "_Q_fgt";
5292 qpfunc = (TARGET_ARCH64) ? "_Qp_fge" : "_Q_fge";
5296 qpfunc = (TARGET_ARCH64) ? "_Qp_flt" : "_Q_flt";
5300 qpfunc = (TARGET_ARCH64) ? "_Qp_fle" : "_Q_fle";
5311 qpfunc = (TARGET_ARCH64) ? "_Qp_cmp" : "_Q_cmp";
5321 if (GET_CODE (x) != MEM)
5323 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5324 emit_insn (gen_rtx_SET (VOIDmode, slot0, x));
5329 if (GET_CODE (y) != MEM)
5331 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5332 emit_insn (gen_rtx_SET (VOIDmode, slot1, y));
5337 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), 1,
5339 XEXP (slot0, 0), Pmode,
5340 XEXP (slot1, 0), Pmode);
5346 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), 1,
5348 x, TFmode, y, TFmode);
5354 /* Immediately move the result of the libcall into a pseudo
5355 register so reload doesn't clobber the value if it needs
5356 the return register for a spill reg. */
5357 result = gen_reg_rtx (mode);
5358 emit_move_insn (result, hard_libcall_value (mode));
5363 emit_cmp_insn (result, const0_rtx, NE, NULL_RTX, mode, 0);
5367 emit_cmp_insn (result, GEN_INT(3), comparison == UNORDERED ? EQ : NE,
5372 emit_cmp_insn (result, const1_rtx,
5373 comparison == UNGT ? GT : NE, NULL_RTX, mode, 0);
5376 emit_cmp_insn (result, const2_rtx, NE, NULL_RTX, mode, 0);
5379 tem = gen_reg_rtx (mode);
5381 emit_insn (gen_andsi3 (tem, result, const1_rtx));
5383 emit_insn (gen_anddi3 (tem, result, const1_rtx));
5384 emit_cmp_insn (tem, const0_rtx, NE, NULL_RTX, mode, 0);
5388 tem = gen_reg_rtx (mode);
5390 emit_insn (gen_addsi3 (tem, result, const1_rtx));
5392 emit_insn (gen_adddi3 (tem, result, const1_rtx));
5393 tem2 = gen_reg_rtx (mode);
5395 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
5397 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
5398 emit_cmp_insn (tem2, const0_rtx, comparison == UNEQ ? EQ : NE,
5404 /* Generate an unsigned DImode to FP conversion. This is the same code
5405 optabs would emit if we didn't have TFmode patterns. */
5408 sparc_emit_floatunsdi (operands)
5411 rtx neglab, donelab, i0, i1, f0, in, out;
5412 enum machine_mode mode;
5415 in = force_reg (DImode, operands[1]);
5416 mode = GET_MODE (out);
5417 neglab = gen_label_rtx ();
5418 donelab = gen_label_rtx ();
5419 i0 = gen_reg_rtx (DImode);
5420 i1 = gen_reg_rtx (DImode);
5421 f0 = gen_reg_rtx (mode);
5423 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
5425 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
5426 emit_jump_insn (gen_jump (donelab));
5429 emit_label (neglab);
5431 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
5432 emit_insn (gen_anddi3 (i1, in, const1_rtx));
5433 emit_insn (gen_iordi3 (i0, i0, i1));
5434 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
5435 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
5437 emit_label (donelab);
5440 /* Return the string to output a conditional branch to LABEL, testing
5441 register REG. LABEL is the operand number of the label; REG is the
5442 operand number of the reg. OP is the conditional expression. The mode
5443 of REG says what kind of comparison we made.
5445 REVERSED is non-zero if we should reverse the sense of the comparison.
5447 ANNUL is non-zero if we should generate an annulling branch.
5449 NOOP is non-zero if we have to follow this branch by a noop. */
5452 output_v9branch (op, dest, reg, label, reversed, annul, noop, insn)
5455 int reversed, annul, noop;
5458 static char string[50];
5459 enum rtx_code code = GET_CODE (op);
5460 enum machine_mode mode = GET_MODE (XEXP (op, 0));
5465 /* branch on register are limited to +-128KB. If it is too far away,
5478 brgez,a,pn %o1, .LC29
5484 ba,pt %xcc, .LC29 */
5486 far = get_attr_length (insn) >= 3;
5488 /* If not floating-point or if EQ or NE, we can just reverse the code. */
5490 code = reverse_condition (code);
5492 /* Only 64 bit versions of these instructions exist. */
5496 /* Start by writing the branch condition. */
5501 strcpy (string, "brnz");
5505 strcpy (string, "brz");
5509 strcpy (string, "brgez");
5513 strcpy (string, "brlz");
5517 strcpy (string, "brlez");
5521 strcpy (string, "brgz");
5528 p = strchr (string, '\0');
5530 /* Now add the annulling, reg, label, and nop. */
5537 if (insn && (note = find_reg_note (insn, REG_BR_PRED, NULL_RTX)))
5540 (((INTVAL (XEXP (note, 0)) & ATTR_FLAG_likely) != 0) ^ far)
5545 *p = p < string + 8 ? '\t' : ' ';
5553 int veryfar = 1, delta;
5555 if (INSN_ADDRESSES_SET_P ())
5557 delta = (INSN_ADDRESSES (INSN_UID (dest))
5558 - INSN_ADDRESSES (INSN_UID (insn)));
5559 /* Leave some instructions for "slop". */
5560 if (delta >= -260000 && delta < 260000)
5564 strcpy (p, ".+12\n\tnop\n\t");
5575 strcpy (p, "ba,pt\t%%xcc, ");
5585 strcpy (p, "\n\tnop");
5590 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
5591 Such instructions cannot be used in the delay slot of return insn on v9.
5592 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
5596 epilogue_renumber (where, test)
5597 register rtx *where;
5600 register const char *fmt;
5602 register enum rtx_code code;
5607 code = GET_CODE (*where);
5612 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
5614 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
5615 *where = gen_rtx (REG, GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
5623 /* Do not replace the frame pointer with the stack pointer because
5624 it can cause the delayed instruction to load below the stack.
5625 This occurs when instructions like:
5627 (set (reg/i:SI 24 %i0)
5628 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
5629 (const_int -20 [0xffffffec])) 0))
5631 are in the return delayed slot. */
5633 if (GET_CODE (XEXP (*where, 0)) == REG
5634 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
5635 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
5636 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
5641 if (SPARC_STACK_BIAS
5642 && GET_CODE (XEXP (*where, 0)) == REG
5643 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
5651 fmt = GET_RTX_FORMAT (code);
5653 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5658 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
5659 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
5662 else if (fmt[i] == 'e'
5663 && epilogue_renumber (&(XEXP (*where, i)), test))
5669 /* Leaf functions and non-leaf functions have different needs. */
5672 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
5675 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
5677 static const int *const reg_alloc_orders[] = {
5678 reg_leaf_alloc_order,
5679 reg_nonleaf_alloc_order};
5682 order_regs_for_local_alloc ()
5684 static int last_order_nonleaf = 1;
5686 if (regs_ever_live[15] != last_order_nonleaf)
5688 last_order_nonleaf = !last_order_nonleaf;
5689 memcpy ((char *) reg_alloc_order,
5690 (const char *) reg_alloc_orders[last_order_nonleaf],
5691 FIRST_PSEUDO_REGISTER * sizeof (int));
5695 /* Return 1 if REG and MEM are legitimate enough to allow the various
5696 mem<-->reg splits to be run. */
5699 sparc_splitdi_legitimate (reg, mem)
5703 /* Punt if we are here by mistake. */
5704 if (! reload_completed)
5707 /* We must have an offsettable memory reference. */
5708 if (! offsettable_memref_p (mem))
5711 /* If we have legitimate args for ldd/std, we do not want
5712 the split to happen. */
5713 if ((REGNO (reg) % 2) == 0
5714 && mem_min_alignment (mem, 8))
5721 /* Return 1 if x and y are some kind of REG and they refer to
5722 different hard registers. This test is guarenteed to be
5723 run after reload. */
5726 sparc_absnegfloat_split_legitimate (x, y)
5729 if (GET_CODE (x) != REG)
5731 if (GET_CODE (y) != REG)
5733 if (REGNO (x) == REGNO (y))
5738 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
5739 This makes them candidates for using ldd and std insns.
5741 Note reg1 and reg2 *must* be hard registers. */
5744 registers_ok_for_ldd_peep (reg1, reg2)
5747 /* We might have been passed a SUBREG. */
5748 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
5751 if (REGNO (reg1) % 2 != 0)
5754 /* Integer ldd is deprecated in SPARC V9 */
5755 if (TARGET_V9 && REGNO (reg1) < 32)
5758 return (REGNO (reg1) == REGNO (reg2) - 1);
5761 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
5764 This can only happen when addr1 and addr2, the addresses in mem1
5765 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
5766 addr1 must also be aligned on a 64-bit boundary.
5768 Also iff dependent_reg_rtx is not null it should not be used to
5769 compute the address for mem1, i.e. we cannot optimize a sequence
5775 For stores we don't have a similar problem, so dependent_reg_rtx is
5779 mems_ok_for_ldd_peep (mem1, mem2, dependent_reg_rtx)
5780 rtx mem1, mem2, dependent_reg_rtx;
5786 /* The mems cannot be volatile. */
5787 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
5790 /* MEM1 should be aligned on a 64-bit boundary. */
5791 if (MEM_ALIGN (mem1) < 64)
5794 addr1 = XEXP (mem1, 0);
5795 addr2 = XEXP (mem2, 0);
5797 /* Extract a register number and offset (if used) from the first addr. */
5798 if (GET_CODE (addr1) == PLUS)
5800 /* If not a REG, return zero. */
5801 if (GET_CODE (XEXP (addr1, 0)) != REG)
5805 reg1 = REGNO (XEXP (addr1, 0));
5806 /* The offset must be constant! */
5807 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
5809 offset1 = INTVAL (XEXP (addr1, 1));
5812 else if (GET_CODE (addr1) != REG)
5816 reg1 = REGNO (addr1);
5817 /* This was a simple (mem (reg)) expression. Offset is 0. */
5821 /* Make sure the second address is a (mem (plus (reg) (const_int). */
5822 if (GET_CODE (addr2) != PLUS)
5825 if (GET_CODE (XEXP (addr2, 0)) != REG
5826 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
5829 if (reg1 != REGNO (XEXP (addr2, 0)))
5832 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
5835 /* The first offset must be evenly divisible by 8 to ensure the
5836 address is 64 bit aligned. */
5837 if (offset1 % 8 != 0)
5840 /* The offset for the second addr must be 4 more than the first addr. */
5841 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
5844 /* All the tests passed. addr1 and addr2 are valid for ldd and std
5849 /* Return 1 if reg is a pseudo, or is the first register in
5850 a hard register pair. This makes it a candidate for use in
5851 ldd and std insns. */
5854 register_ok_for_ldd (reg)
5857 /* We might have been passed a SUBREG. */
5858 if (GET_CODE (reg) != REG)
5861 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
5862 return (REGNO (reg) % 2 == 0);
5867 /* Print operand X (an rtx) in assembler syntax to file FILE.
5868 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
5869 For `%' followed by punctuation, CODE is the punctuation and X is null. */
5872 print_operand (file, x, code)
5880 /* Output a 'nop' if there's nothing for the delay slot. */
5881 if (dbr_sequence_length () == 0)
5882 fputs ("\n\t nop", file);
5885 /* Output an annul flag if there's nothing for the delay slot and we
5886 are optimizing. This is always used with '(' below. */
5887 /* Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
5888 this is a dbx bug. So, we only do this when optimizing. */
5889 /* On UltraSPARC, a branch in a delay slot causes a pipeline flush.
5890 Always emit a nop in case the next instruction is a branch. */
5891 if (dbr_sequence_length () == 0
5892 && (optimize && (int)sparc_cpu < PROCESSOR_V9))
5896 /* Output a 'nop' if there's nothing for the delay slot and we are
5897 not optimizing. This is always used with '*' above. */
5898 if (dbr_sequence_length () == 0
5899 && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
5900 fputs ("\n\t nop", file);
5903 /* Output the Embedded Medium/Anywhere code model base register. */
5904 fputs (EMBMEDANY_BASE_REG, file);
5907 /* Print out what we are using as the frame pointer. This might
5908 be %fp, or might be %sp+offset. */
5909 /* ??? What if offset is too big? Perhaps the caller knows it isn't? */
5910 fprintf (file, "%s+%d", frame_base_name, frame_base_offset);
5913 /* Adjust the operand to take into account a RESTORE operation. */
5914 if (GET_CODE (x) == CONST_INT)
5916 else if (GET_CODE (x) != REG)
5917 output_operand_lossage ("invalid %%Y operand");
5918 else if (REGNO (x) < 8)
5919 fputs (reg_names[REGNO (x)], file);
5920 else if (REGNO (x) >= 24 && REGNO (x) < 32)
5921 fputs (reg_names[REGNO (x)-16], file);
5923 output_operand_lossage ("invalid %%Y operand");
5926 /* Print out the low order register name of a register pair. */
5927 if (WORDS_BIG_ENDIAN)
5928 fputs (reg_names[REGNO (x)+1], file);
5930 fputs (reg_names[REGNO (x)], file);
5933 /* Print out the high order register name of a register pair. */
5934 if (WORDS_BIG_ENDIAN)
5935 fputs (reg_names[REGNO (x)], file);
5937 fputs (reg_names[REGNO (x)+1], file);
5940 /* Print out the second register name of a register pair or quad.
5941 I.e., R (%o0) => %o1. */
5942 fputs (reg_names[REGNO (x)+1], file);
5945 /* Print out the third register name of a register quad.
5946 I.e., S (%o0) => %o2. */
5947 fputs (reg_names[REGNO (x)+2], file);
5950 /* Print out the fourth register name of a register quad.
5951 I.e., T (%o0) => %o3. */
5952 fputs (reg_names[REGNO (x)+3], file);
5955 /* Print a condition code register. */
5956 if (REGNO (x) == SPARC_ICC_REG)
5958 /* We don't handle CC[X]_NOOVmode because they're not supposed
5960 if (GET_MODE (x) == CCmode)
5961 fputs ("%icc", file);
5962 else if (GET_MODE (x) == CCXmode)
5963 fputs ("%xcc", file);
5968 /* %fccN register */
5969 fputs (reg_names[REGNO (x)], file);
5972 /* Print the operand's address only. */
5973 output_address (XEXP (x, 0));
5976 /* In this case we need a register. Use %g0 if the
5977 operand is const0_rtx. */
5979 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
5981 fputs ("%g0", file);
5988 switch (GET_CODE (x))
5990 case IOR: fputs ("or", file); break;
5991 case AND: fputs ("and", file); break;
5992 case XOR: fputs ("xor", file); break;
5993 default: output_operand_lossage ("invalid %%A operand");
5998 switch (GET_CODE (x))
6000 case IOR: fputs ("orn", file); break;
6001 case AND: fputs ("andn", file); break;
6002 case XOR: fputs ("xnor", file); break;
6003 default: output_operand_lossage ("invalid %%B operand");
6007 /* These are used by the conditional move instructions. */
6011 enum rtx_code rc = GET_CODE (x);
6015 enum machine_mode mode = GET_MODE (XEXP (x, 0));
6016 if (mode == CCFPmode || mode == CCFPEmode)
6017 rc = reverse_condition_maybe_unordered (GET_CODE (x));
6019 rc = reverse_condition (GET_CODE (x));
6023 case NE: fputs ("ne", file); break;
6024 case EQ: fputs ("e", file); break;
6025 case GE: fputs ("ge", file); break;
6026 case GT: fputs ("g", file); break;
6027 case LE: fputs ("le", file); break;
6028 case LT: fputs ("l", file); break;
6029 case GEU: fputs ("geu", file); break;
6030 case GTU: fputs ("gu", file); break;
6031 case LEU: fputs ("leu", file); break;
6032 case LTU: fputs ("lu", file); break;
6033 case LTGT: fputs ("lg", file); break;
6034 case UNORDERED: fputs ("u", file); break;
6035 case ORDERED: fputs ("o", file); break;
6036 case UNLT: fputs ("ul", file); break;
6037 case UNLE: fputs ("ule", file); break;
6038 case UNGT: fputs ("ug", file); break;
6039 case UNGE: fputs ("uge", file); break;
6040 case UNEQ: fputs ("ue", file); break;
6041 default: output_operand_lossage (code == 'c'
6042 ? "invalid %%c operand"
6043 : "invalid %%C operand");
6048 /* These are used by the movr instruction pattern. */
6052 enum rtx_code rc = (code == 'd'
6053 ? reverse_condition (GET_CODE (x))
6057 case NE: fputs ("ne", file); break;
6058 case EQ: fputs ("e", file); break;
6059 case GE: fputs ("gez", file); break;
6060 case LT: fputs ("lz", file); break;
6061 case LE: fputs ("lez", file); break;
6062 case GT: fputs ("gz", file); break;
6063 default: output_operand_lossage (code == 'd'
6064 ? "invalid %%d operand"
6065 : "invalid %%D operand");
6072 /* Print a sign-extended character. */
6073 int i = trunc_int_for_mode (INTVAL (x), QImode);
6074 fprintf (file, "%d", i);
6079 /* Operand must be a MEM; write its address. */
6080 if (GET_CODE (x) != MEM)
6081 output_operand_lossage ("invalid %%f operand");
6082 output_address (XEXP (x, 0));
6086 /* Do nothing special. */
6090 /* Undocumented flag. */
6091 output_operand_lossage ("invalid operand output code");
6094 if (GET_CODE (x) == REG)
6095 fputs (reg_names[REGNO (x)], file);
6096 else if (GET_CODE (x) == MEM)
6099 /* Poor Sun assembler doesn't understand absolute addressing. */
6100 if (CONSTANT_P (XEXP (x, 0)))
6101 fputs ("%g0+", file);
6102 output_address (XEXP (x, 0));
6105 else if (GET_CODE (x) == HIGH)
6107 fputs ("%hi(", file);
6108 output_addr_const (file, XEXP (x, 0));
6111 else if (GET_CODE (x) == LO_SUM)
6113 print_operand (file, XEXP (x, 0), 0);
6114 if (TARGET_CM_MEDMID)
6115 fputs ("+%l44(", file);
6117 fputs ("+%lo(", file);
6118 output_addr_const (file, XEXP (x, 1));
6121 else if (GET_CODE (x) == CONST_DOUBLE
6122 && (GET_MODE (x) == VOIDmode
6123 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
6125 if (CONST_DOUBLE_HIGH (x) == 0)
6126 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
6127 else if (CONST_DOUBLE_HIGH (x) == -1
6128 && CONST_DOUBLE_LOW (x) < 0)
6129 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
6131 output_operand_lossage ("long long constant not a valid immediate operand");
6133 else if (GET_CODE (x) == CONST_DOUBLE)
6134 output_operand_lossage ("floating point constant not a valid immediate operand");
6135 else { output_addr_const (file, x); }
6138 /* Target hook for assembling integer objects. The sparc version has
6139 special handling for aligned DI-mode objects. */
6142 sparc_assemble_integer (x, size, aligned_p)
6147 /* ??? We only output .xword's for symbols and only then in environments
6148 where the assembler can handle them. */
6149 if (aligned_p && size == 8
6150 && (GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE))
6154 assemble_integer_with_op ("\t.xword\t", x);
6159 assemble_aligned_integer (4, const0_rtx);
6160 assemble_aligned_integer (4, x);
6164 return default_assemble_integer (x, size, aligned_p);
6167 /* Return the value of a code used in the .proc pseudo-op that says
6168 what kind of result this function returns. For non-C types, we pick
6169 the closest C type. */
6171 #ifndef SHORT_TYPE_SIZE
6172 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
6175 #ifndef INT_TYPE_SIZE
6176 #define INT_TYPE_SIZE BITS_PER_WORD
6179 #ifndef LONG_TYPE_SIZE
6180 #define LONG_TYPE_SIZE BITS_PER_WORD
6183 #ifndef LONG_LONG_TYPE_SIZE
6184 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
6187 #ifndef FLOAT_TYPE_SIZE
6188 #define FLOAT_TYPE_SIZE BITS_PER_WORD
6191 #ifndef DOUBLE_TYPE_SIZE
6192 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6195 #ifndef LONG_DOUBLE_TYPE_SIZE
6196 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6200 sparc_type_code (type)
6203 register unsigned long qualifiers = 0;
6204 register unsigned shift;
6206 /* Only the first 30 bits of the qualifier are valid. We must refrain from
6207 setting more, since some assemblers will give an error for this. Also,
6208 we must be careful to avoid shifts of 32 bits or more to avoid getting
6209 unpredictable results. */
6211 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
6213 switch (TREE_CODE (type))
6219 qualifiers |= (3 << shift);
6224 qualifiers |= (2 << shift);
6228 case REFERENCE_TYPE:
6230 qualifiers |= (1 << shift);
6234 return (qualifiers | 8);
6237 case QUAL_UNION_TYPE:
6238 return (qualifiers | 9);
6241 return (qualifiers | 10);
6244 return (qualifiers | 16);
6247 /* If this is a range type, consider it to be the underlying
6249 if (TREE_TYPE (type) != 0)
6252 /* Carefully distinguish all the standard types of C,
6253 without messing up if the language is not C. We do this by
6254 testing TYPE_PRECISION and TREE_UNSIGNED. The old code used to
6255 look at both the names and the above fields, but that's redundant.
6256 Any type whose size is between two C types will be considered
6257 to be the wider of the two types. Also, we do not have a
6258 special code to use for "long long", so anything wider than
6259 long is treated the same. Note that we can't distinguish
6260 between "int" and "long" in this code if they are the same
6261 size, but that's fine, since neither can the assembler. */
6263 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
6264 return (qualifiers | (TREE_UNSIGNED (type) ? 12 : 2));
6266 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
6267 return (qualifiers | (TREE_UNSIGNED (type) ? 13 : 3));
6269 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
6270 return (qualifiers | (TREE_UNSIGNED (type) ? 14 : 4));
6273 return (qualifiers | (TREE_UNSIGNED (type) ? 15 : 5));
6276 /* If this is a range type, consider it to be the underlying
6278 if (TREE_TYPE (type) != 0)
6281 /* Carefully distinguish all the standard types of C,
6282 without messing up if the language is not C. */
6284 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
6285 return (qualifiers | 6);
6288 return (qualifiers | 7);
6290 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
6291 /* ??? We need to distinguish between double and float complex types,
6292 but I don't know how yet because I can't reach this code from
6293 existing front-ends. */
6294 return (qualifiers | 7); /* Who knows? */
6296 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
6297 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
6298 case FILE_TYPE: /* GNU Pascal FILE type. */
6299 case SET_TYPE: /* GNU Pascal SET type. */
6300 case LANG_TYPE: /* ? */
6304 abort (); /* Not a type! */
6311 /* Nested function support. */
6313 /* Emit RTL insns to initialize the variable parts of a trampoline.
6314 FNADDR is an RTX for the address of the function's pure code.
6315 CXT is an RTX for the static chain value for the function.
6317 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
6318 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
6319 (to store insns). This is a bit excessive. Perhaps a different
6320 mechanism would be better here.
6322 Emit enough FLUSH insns to synchronize the data and instruction caches. */
6325 sparc_initialize_trampoline (tramp, fnaddr, cxt)
6326 rtx tramp, fnaddr, cxt;
6328 /* SPARC 32 bit trampoline:
6331 sethi %hi(static), %g2
6333 or %g2, %lo(static), %g2
6335 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
6336 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
6338 #ifdef TRANSFER_FROM_TRAMPOLINE
6339 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
6340 0, VOIDmode, 1, tramp, Pmode);
6344 (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
6345 expand_binop (SImode, ior_optab,
6346 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
6347 size_int (10), 0, 1),
6348 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
6349 NULL_RTX, 1, OPTAB_DIRECT));
6352 (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6353 expand_binop (SImode, ior_optab,
6354 expand_shift (RSHIFT_EXPR, SImode, cxt,
6355 size_int (10), 0, 1),
6356 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
6357 NULL_RTX, 1, OPTAB_DIRECT));
6360 (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6361 expand_binop (SImode, ior_optab,
6362 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
6363 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
6364 NULL_RTX, 1, OPTAB_DIRECT));
6367 (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6368 expand_binop (SImode, ior_optab,
6369 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
6370 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
6371 NULL_RTX, 1, OPTAB_DIRECT));
6373 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
6374 aligned on a 16 byte boundary so one flush clears it all. */
6375 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
6376 if (sparc_cpu != PROCESSOR_ULTRASPARC)
6377 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
6378 plus_constant (tramp, 8)))));
6381 /* The 64 bit version is simpler because it makes more sense to load the
6382 values as "immediate" data out of the trampoline. It's also easier since
6383 we can read the PC without clobbering a register. */
6386 sparc64_initialize_trampoline (tramp, fnaddr, cxt)
6387 rtx tramp, fnaddr, cxt;
6389 #ifdef TRANSFER_FROM_TRAMPOLINE
6390 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
6391 0, VOIDmode, 1, tramp, Pmode);
6402 emit_move_insn (gen_rtx_MEM (SImode, tramp),
6403 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
6404 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6405 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
6406 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6407 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
6408 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6409 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
6410 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
6411 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
6412 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
6414 if (sparc_cpu != PROCESSOR_ULTRASPARC)
6415 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
6418 /* Subroutines to support a flat (single) register window calling
6421 /* Single-register window sparc stack frames look like:
6423 Before call After call
6424 +-----------------------+ +-----------------------+
6426 mem | caller's temps. | | caller's temps. |
6428 +-----------------------+ +-----------------------+
6430 | arguments on stack. | | arguments on stack. |
6432 +-----------------------+FP+92->+-----------------------+
6433 | 6 words to save | | 6 words to save |
6434 | arguments passed | | arguments passed |
6435 | in registers, even | | in registers, even |
6436 | if not passed. | | if not passed. |
6437 SP+68->+-----------------------+FP+68->+-----------------------+
6438 | 1 word struct addr | | 1 word struct addr |
6439 +-----------------------+FP+64->+-----------------------+
6441 | 16 word reg save area | | 16 word reg save area |
6443 SP->+-----------------------+ FP->+-----------------------+
6445 | fp/alu reg moves |
6446 FP-16->+-----------------------+
6450 +-----------------------+
6452 | fp register save |
6454 +-----------------------+
6456 | gp register save |
6458 +-----------------------+
6460 | alloca allocations |
6462 +-----------------------+
6464 | arguments on stack |
6466 SP+92->+-----------------------+
6468 | arguments passed |
6469 | in registers, even |
6470 low | if not passed. |
6471 memory SP+68->+-----------------------+
6472 | 1 word struct addr |
6473 SP+64->+-----------------------+
6475 I 16 word reg save area |
6477 SP->+-----------------------+ */
6479 /* Structure to be filled in by sparc_flat_compute_frame_size with register
6480 save masks, and offsets for the current function. */
6482 struct sparc_frame_info
6484 unsigned long total_size; /* # bytes that the entire frame takes up. */
6485 unsigned long var_size; /* # bytes that variables take up. */
6486 unsigned long args_size; /* # bytes that outgoing arguments take up. */
6487 unsigned long extra_size; /* # bytes of extra gunk. */
6488 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
6489 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
6490 unsigned long gmask; /* Mask of saved gp registers. */
6491 unsigned long fmask; /* Mask of saved fp registers. */
6492 unsigned long reg_offset; /* Offset from new sp to store regs. */
6493 int initialized; /* Nonzero if frame size already calculated. */
6496 /* Current frame information calculated by sparc_flat_compute_frame_size. */
6497 struct sparc_frame_info current_frame_info;
6499 /* Zero structure to initialize current_frame_info. */
6500 struct sparc_frame_info zero_frame_info;
6502 /* Tell prologue and epilogue if register REGNO should be saved / restored. */
6504 #define RETURN_ADDR_REGNUM 15
6505 #define HARD_FRAME_POINTER_MASK (1 << (HARD_FRAME_POINTER_REGNUM))
6506 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
6508 #define MUST_SAVE_REGISTER(regno) \
6509 ((regs_ever_live[regno] && !call_used_regs[regno]) \
6510 || (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed) \
6511 || (regno == RETURN_ADDR_REGNUM && regs_ever_live[RETURN_ADDR_REGNUM]))
6513 /* Return the bytes needed to compute the frame pointer from the current
6517 sparc_flat_compute_frame_size (size)
6518 int size; /* # of var. bytes allocated. */
6521 unsigned long total_size; /* # bytes that the entire frame takes up. */
6522 unsigned long var_size; /* # bytes that variables take up. */
6523 unsigned long args_size; /* # bytes that outgoing arguments take up. */
6524 unsigned long extra_size; /* # extra bytes. */
6525 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
6526 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
6527 unsigned long gmask; /* Mask of saved gp registers. */
6528 unsigned long fmask; /* Mask of saved fp registers. */
6529 unsigned long reg_offset; /* Offset to register save area. */
6530 int need_aligned_p; /* 1 if need the save area 8 byte aligned. */
6532 /* This is the size of the 16 word reg save area, 1 word struct addr
6533 area, and 4 word fp/alu register copy area. */
6534 extra_size = -STARTING_FRAME_OFFSET + FIRST_PARM_OFFSET(0);
6544 if (!leaf_function_p ())
6546 /* Also include the size needed for the 6 parameter registers. */
6547 args_size = current_function_outgoing_args_size + 24;
6549 total_size = var_size + args_size;
6551 /* Calculate space needed for gp registers. */
6552 for (regno = 1; regno <= 31; regno++)
6554 if (MUST_SAVE_REGISTER (regno))
6556 /* If we need to save two regs in a row, ensure there's room to bump
6557 up the address to align it to a doubleword boundary. */
6558 if ((regno & 0x1) == 0 && MUST_SAVE_REGISTER (regno+1))
6560 if (gp_reg_size % 8 != 0)
6562 gp_reg_size += 2 * UNITS_PER_WORD;
6563 gmask |= 3 << regno;
6569 gp_reg_size += UNITS_PER_WORD;
6570 gmask |= 1 << regno;
6575 /* Calculate space needed for fp registers. */
6576 for (regno = 32; regno <= 63; regno++)
6578 if (regs_ever_live[regno] && !call_used_regs[regno])
6580 fp_reg_size += UNITS_PER_WORD;
6581 fmask |= 1 << (regno - 32);
6588 reg_offset = FIRST_PARM_OFFSET(0) + args_size;
6589 /* Ensure save area is 8 byte aligned if we need it. */
6591 if (need_aligned_p && n != 0)
6593 total_size += 8 - n;
6594 reg_offset += 8 - n;
6596 total_size += gp_reg_size + fp_reg_size;
6599 /* If we must allocate a stack frame at all, we must also allocate
6600 room for register window spillage, so as to be binary compatible
6601 with libraries and operating systems that do not use -mflat. */
6603 total_size += extra_size;
6607 total_size = SPARC_STACK_ALIGN (total_size);
6609 /* Save other computed information. */
6610 current_frame_info.total_size = total_size;
6611 current_frame_info.var_size = var_size;
6612 current_frame_info.args_size = args_size;
6613 current_frame_info.extra_size = extra_size;
6614 current_frame_info.gp_reg_size = gp_reg_size;
6615 current_frame_info.fp_reg_size = fp_reg_size;
6616 current_frame_info.gmask = gmask;
6617 current_frame_info.fmask = fmask;
6618 current_frame_info.reg_offset = reg_offset;
6619 current_frame_info.initialized = reload_completed;
6621 /* Ok, we're done. */
6625 /* Save/restore registers in GMASK and FMASK at register BASE_REG plus offset
6628 BASE_REG must be 8 byte aligned. This allows us to test OFFSET for
6629 appropriate alignment and use DOUBLEWORD_OP when we can. We assume
6630 [BASE_REG+OFFSET] will always be a valid address.
6632 WORD_OP is either "st" for save, "ld" for restore.
6633 DOUBLEWORD_OP is either "std" for save, "ldd" for restore. */
6636 sparc_flat_save_restore (file, base_reg, offset, gmask, fmask, word_op,
6637 doubleword_op, base_offset)
6639 const char *base_reg;
6640 unsigned int offset;
6641 unsigned long gmask;
6642 unsigned long fmask;
6643 const char *word_op;
6644 const char *doubleword_op;
6645 unsigned long base_offset;
6649 if (gmask == 0 && fmask == 0)
6652 /* Save registers starting from high to low. We've already saved the
6653 previous frame pointer and previous return address for the debugger's
6654 sake. The debugger allows us to not need a nop in the epilog if at least
6655 one register is reloaded in addition to return address. */
6659 for (regno = 1; regno <= 31; regno++)
6661 if ((gmask & (1L << regno)) != 0)
6663 if ((regno & 0x1) == 0 && ((gmask & (1L << (regno+1))) != 0))
6665 /* We can save two registers in a row. If we're not at a
6666 double word boundary, move to one.
6667 sparc_flat_compute_frame_size ensures there's room to do
6669 if (offset % 8 != 0)
6670 offset += UNITS_PER_WORD;
6672 if (word_op[0] == 's')
6674 fprintf (file, "\t%s\t%s, [%s+%d]\n",
6675 doubleword_op, reg_names[regno],
6677 if (dwarf2out_do_frame ())
6679 char *l = dwarf2out_cfi_label ();
6680 dwarf2out_reg_save (l, regno, offset + base_offset);
6682 (l, regno+1, offset+base_offset + UNITS_PER_WORD);
6686 fprintf (file, "\t%s\t[%s+%d], %s\n",
6687 doubleword_op, base_reg, offset,
6690 offset += 2 * UNITS_PER_WORD;
6695 if (word_op[0] == 's')
6697 fprintf (file, "\t%s\t%s, [%s+%d]\n",
6698 word_op, reg_names[regno],
6700 if (dwarf2out_do_frame ())
6701 dwarf2out_reg_save ("", regno, offset + base_offset);
6704 fprintf (file, "\t%s\t[%s+%d], %s\n",
6705 word_op, base_reg, offset, reg_names[regno]);
6707 offset += UNITS_PER_WORD;
6715 for (regno = 32; regno <= 63; regno++)
6717 if ((fmask & (1L << (regno - 32))) != 0)
6719 if (word_op[0] == 's')
6721 fprintf (file, "\t%s\t%s, [%s+%d]\n",
6722 word_op, reg_names[regno],
6724 if (dwarf2out_do_frame ())
6725 dwarf2out_reg_save ("", regno, offset + base_offset);
6728 fprintf (file, "\t%s\t[%s+%d], %s\n",
6729 word_op, base_reg, offset, reg_names[regno]);
6731 offset += UNITS_PER_WORD;
6737 /* Set up the stack and frame (if desired) for the function. */
6740 sparc_flat_function_prologue (file, size)
6744 const char *sp_str = reg_names[STACK_POINTER_REGNUM];
6745 unsigned long gmask = current_frame_info.gmask;
6747 sparc_output_scratch_registers (file);
6749 /* This is only for the human reader. */
6750 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
6751 fprintf (file, "\t%s# vars= %ld, regs= %d/%d, args= %d, extra= %ld\n",
6753 current_frame_info.var_size,
6754 current_frame_info.gp_reg_size / 4,
6755 current_frame_info.fp_reg_size / 4,
6756 current_function_outgoing_args_size,
6757 current_frame_info.extra_size);
6759 size = SPARC_STACK_ALIGN (size);
6760 size = (! current_frame_info.initialized
6761 ? sparc_flat_compute_frame_size (size)
6762 : current_frame_info.total_size);
6764 /* These cases shouldn't happen. Catch them now. */
6765 if (size == 0 && (gmask || current_frame_info.fmask))
6768 /* Allocate our stack frame by decrementing %sp.
6769 At present, the only algorithm gdb can use to determine if this is a
6770 flat frame is if we always set %i7 if we set %sp. This can be optimized
6771 in the future by putting in some sort of debugging information that says
6772 this is a `flat' function. However, there is still the case of debugging
6773 code without such debugging information (including cases where most fns
6774 have such info, but there is one that doesn't). So, always do this now
6775 so we don't get a lot of code out there that gdb can't handle.
6776 If the frame pointer isn't needn't then that's ok - gdb won't be able to
6777 distinguish us from a non-flat function but there won't (and shouldn't)
6778 be any differences anyway. The return pc is saved (if necessary) right
6779 after %i7 so gdb won't have to look too far to find it. */
6782 unsigned int reg_offset = current_frame_info.reg_offset;
6783 const char *const fp_str = reg_names[HARD_FRAME_POINTER_REGNUM];
6784 static const char *const t1_str = "%g1";
6786 /* Things get a little tricky if local variables take up more than ~4096
6787 bytes and outgoing arguments take up more than ~4096 bytes. When that
6788 happens, the register save area can't be accessed from either end of
6789 the frame. Handle this by decrementing %sp to the start of the gp
6790 register save area, save the regs, update %i7, and then set %sp to its
6791 final value. Given that we only have one scratch register to play
6792 with it is the cheapest solution, and it helps gdb out as it won't
6793 slow down recognition of flat functions.
6794 Don't change the order of insns emitted here without checking with
6795 the gdb folk first. */
6797 /* Is the entire register save area offsettable from %sp? */
6798 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
6802 fprintf (file, "\tadd\t%s, %d, %s\n",
6803 sp_str, (int) -size, sp_str);
6804 if (gmask & HARD_FRAME_POINTER_MASK)
6806 fprintf (file, "\tst\t%s, [%s+%d]\n",
6807 fp_str, sp_str, reg_offset);
6808 fprintf (file, "\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
6809 sp_str, (int) -size, fp_str, ASM_COMMENT_START);
6815 fprintf (file, "\tset\t");
6816 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
6817 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
6818 t1_str, sp_str, t1_str, sp_str);
6819 if (gmask & HARD_FRAME_POINTER_MASK)
6821 fprintf (file, "\tst\t%s, [%s+%d]\n",
6822 fp_str, sp_str, reg_offset);
6823 fprintf (file, "\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
6824 sp_str, t1_str, fp_str, ASM_COMMENT_START);
6828 if (dwarf2out_do_frame ())
6830 char *l = dwarf2out_cfi_label ();
6831 if (gmask & HARD_FRAME_POINTER_MASK)
6833 dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM,
6834 reg_offset - 4 - size);
6835 dwarf2out_def_cfa (l, HARD_FRAME_POINTER_REGNUM, 0);
6838 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size);
6840 if (gmask & RETURN_ADDR_MASK)
6842 fprintf (file, "\tst\t%s, [%s+%d]\n",
6843 reg_names[RETURN_ADDR_REGNUM], sp_str, reg_offset);
6844 if (dwarf2out_do_frame ())
6845 dwarf2out_return_save ("", reg_offset - size);
6848 sparc_flat_save_restore (file, sp_str, reg_offset,
6849 gmask & ~(HARD_FRAME_POINTER_MASK | RETURN_ADDR_MASK),
6850 current_frame_info.fmask,
6851 "st", "std", -size);
6855 /* Subtract %sp in two steps, but make sure there is always a
6856 64 byte register save area, and %sp is properly aligned. */
6857 /* Amount to decrement %sp by, the first time. */
6858 unsigned HOST_WIDE_INT size1 = ((size - reg_offset + 64) + 15) & -16;
6859 /* Offset to register save area from %sp. */
6860 unsigned HOST_WIDE_INT offset = size1 - (size - reg_offset);
6864 fprintf (file, "\tadd\t%s, %d, %s\n",
6865 sp_str, (int) -size1, sp_str);
6866 if (gmask & HARD_FRAME_POINTER_MASK)
6868 fprintf (file, "\tst\t%s, [%s+%d]\n\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
6869 fp_str, sp_str, (int) offset, sp_str, (int) -size1,
6870 fp_str, ASM_COMMENT_START);
6876 fprintf (file, "\tset\t");
6877 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size1);
6878 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
6879 t1_str, sp_str, t1_str, sp_str);
6880 if (gmask & HARD_FRAME_POINTER_MASK)
6882 fprintf (file, "\tst\t%s, [%s+%d]\n\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
6883 fp_str, sp_str, (int) offset, sp_str, t1_str,
6884 fp_str, ASM_COMMENT_START);
6888 if (dwarf2out_do_frame ())
6890 char *l = dwarf2out_cfi_label ();
6891 if (gmask & HARD_FRAME_POINTER_MASK)
6893 dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM,
6894 offset - 4 - size1);
6895 dwarf2out_def_cfa (l, HARD_FRAME_POINTER_REGNUM, 0);
6898 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size1);
6900 if (gmask & RETURN_ADDR_MASK)
6902 fprintf (file, "\tst\t%s, [%s+%d]\n",
6903 reg_names[RETURN_ADDR_REGNUM], sp_str, (int) offset);
6904 if (dwarf2out_do_frame ())
6905 /* offset - size1 == reg_offset - size
6906 if reg_offset were updated above like offset. */
6907 dwarf2out_return_save ("", offset - size1);
6910 sparc_flat_save_restore (file, sp_str, offset,
6911 gmask & ~(HARD_FRAME_POINTER_MASK | RETURN_ADDR_MASK),
6912 current_frame_info.fmask,
6913 "st", "std", -size1);
6914 fprintf (file, "\tset\t");
6915 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size - size1);
6916 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
6917 t1_str, sp_str, t1_str, sp_str);
6918 if (dwarf2out_do_frame ())
6919 if (! (gmask & HARD_FRAME_POINTER_MASK))
6920 dwarf2out_def_cfa ("", STACK_POINTER_REGNUM, size);
6924 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
6927 /* Do any necessary cleanup after a function to restore stack, frame,
6931 sparc_flat_function_epilogue (file, size)
6935 rtx epilogue_delay = current_function_epilogue_delay_list;
6936 int noepilogue = FALSE;
6938 /* This is only for the human reader. */
6939 fprintf (file, "\t%s#EPILOGUE#\n", ASM_COMMENT_START);
6941 /* The epilogue does not depend on any registers, but the stack
6942 registers, so we assume that if we have 1 pending nop, it can be
6943 ignored, and 2 it must be filled (2 nops occur for integer
6944 multiply and divide). */
6946 size = SPARC_STACK_ALIGN (size);
6947 size = (!current_frame_info.initialized
6948 ? sparc_flat_compute_frame_size (size)
6949 : current_frame_info.total_size);
6951 if (size == 0 && epilogue_delay == 0)
6953 rtx insn = get_last_insn ();
6955 /* If the last insn was a BARRIER, we don't have to write any code
6956 because a jump (aka return) was put there. */
6957 if (GET_CODE (insn) == NOTE)
6958 insn = prev_nonnote_insn (insn);
6959 if (insn && GET_CODE (insn) == BARRIER)
6965 unsigned HOST_WIDE_INT reg_offset = current_frame_info.reg_offset;
6966 unsigned HOST_WIDE_INT size1;
6967 const char *const sp_str = reg_names[STACK_POINTER_REGNUM];
6968 const char *const fp_str = reg_names[HARD_FRAME_POINTER_REGNUM];
6969 static const char *const t1_str = "%g1";
6971 /* In the reload sequence, we don't need to fill the load delay
6972 slots for most of the loads, also see if we can fill the final
6973 delay slot if not otherwise filled by the reload sequence. */
6977 fprintf (file, "\tset\t");
6978 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
6979 fprintf (file, ", %s\n", t1_str);
6982 if (frame_pointer_needed)
6985 fprintf (file,"\tsub\t%s, %s, %s\t\t%s# sp not trusted here\n",
6986 fp_str, t1_str, sp_str, ASM_COMMENT_START);
6988 fprintf (file,"\tsub\t%s, %d, %s\t\t%s# sp not trusted here\n",
6989 fp_str, (int) size, sp_str, ASM_COMMENT_START);
6992 /* Is the entire register save area offsettable from %sp? */
6993 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
6999 /* Restore %sp in two steps, but make sure there is always a
7000 64 byte register save area, and %sp is properly aligned. */
7001 /* Amount to increment %sp by, the first time. */
7002 size1 = ((reg_offset - 64 - 16) + 15) & -16;
7003 /* Offset to register save area from %sp. */
7004 reg_offset = size1 - reg_offset;
7006 fprintf (file, "\tset\t");
7007 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size1);
7008 fprintf (file, ", %s\n\tadd\t%s, %s, %s\n",
7009 t1_str, sp_str, t1_str, sp_str);
7012 /* We must restore the frame pointer and return address reg first
7013 because they are treated specially by the prologue output code. */
7014 if (current_frame_info.gmask & HARD_FRAME_POINTER_MASK)
7016 fprintf (file, "\tld\t[%s+%d], %s\n",
7017 sp_str, (int) reg_offset, fp_str);
7020 if (current_frame_info.gmask & RETURN_ADDR_MASK)
7022 fprintf (file, "\tld\t[%s+%d], %s\n",
7023 sp_str, (int) reg_offset, reg_names[RETURN_ADDR_REGNUM]);
7027 /* Restore any remaining saved registers. */
7028 sparc_flat_save_restore (file, sp_str, reg_offset,
7029 current_frame_info.gmask & ~(HARD_FRAME_POINTER_MASK | RETURN_ADDR_MASK),
7030 current_frame_info.fmask,
7033 /* If we had to increment %sp in two steps, record it so the second
7034 restoration in the epilogue finishes up. */
7040 fprintf (file, "\tset\t");
7041 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
7042 fprintf (file, ", %s\n", t1_str);
7046 if (current_function_returns_struct)
7047 fprintf (file, "\tjmp\t%%o7+12\n");
7049 fprintf (file, "\tretl\n");
7051 /* If the only register saved is the return address, we need a
7052 nop, unless we have an instruction to put into it. Otherwise
7053 we don't since reloading multiple registers doesn't reference
7054 the register being loaded. */
7060 final_scan_insn (XEXP (epilogue_delay, 0), file, 1, -2, 1);
7063 else if (size > 4095)
7064 fprintf (file, "\tadd\t%s, %s, %s\n", sp_str, t1_str, sp_str);
7067 fprintf (file, "\tadd\t%s, %d, %s\n", sp_str, (int) size, sp_str);
7070 fprintf (file, "\tnop\n");
7073 /* Reset state info for each function. */
7074 current_frame_info = zero_frame_info;
7076 sparc_output_deferred_case_vectors ();
7079 /* Define the number of delay slots needed for the function epilogue.
7081 On the sparc, we need a slot if either no stack has been allocated,
7082 or the only register saved is the return register. */
7085 sparc_flat_epilogue_delay_slots ()
7087 if (!current_frame_info.initialized)
7088 (void) sparc_flat_compute_frame_size (get_frame_size ());
7090 if (current_frame_info.total_size == 0)
7096 /* Return true if TRIAL is a valid insn for the epilogue delay slot.
7097 Any single length instruction which doesn't reference the stack or frame
7101 sparc_flat_eligible_for_epilogue_delay (trial, slot)
7103 int slot ATTRIBUTE_UNUSED;
7105 rtx pat = PATTERN (trial);
7107 if (get_attr_length (trial) != 1)
7110 if (! reg_mentioned_p (stack_pointer_rtx, pat)
7111 && ! reg_mentioned_p (frame_pointer_rtx, pat))
7117 /* Adjust the cost of a scheduling dependency. Return the new cost of
7118 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7121 supersparc_adjust_cost (insn, link, dep_insn, cost)
7127 enum attr_type insn_type;
7129 if (! recog_memoized (insn))
7132 insn_type = get_attr_type (insn);
7134 if (REG_NOTE_KIND (link) == 0)
7136 /* Data dependency; DEP_INSN writes a register that INSN reads some
7139 /* if a load, then the dependence must be on the memory address;
7140 add an extra "cycle". Note that the cost could be two cycles
7141 if the reg was written late in an instruction group; we ca not tell
7143 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
7146 /* Get the delay only if the address of the store is the dependence. */
7147 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
7149 rtx pat = PATTERN(insn);
7150 rtx dep_pat = PATTERN (dep_insn);
7152 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7153 return cost; /* This should not happen! */
7155 /* The dependency between the two instructions was on the data that
7156 is being stored. Assume that this implies that the address of the
7157 store is not dependent. */
7158 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7161 return cost + 3; /* An approximation. */
7164 /* A shift instruction cannot receive its data from an instruction
7165 in the same cycle; add a one cycle penalty. */
7166 if (insn_type == TYPE_SHIFT)
7167 return cost + 3; /* Split before cascade into shift. */
7171 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7172 INSN writes some cycles later. */
7174 /* These are only significant for the fpu unit; writing a fp reg before
7175 the fpu has finished with it stalls the processor. */
7177 /* Reusing an integer register causes no problems. */
7178 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7186 hypersparc_adjust_cost (insn, link, dep_insn, cost)
7192 enum attr_type insn_type, dep_type;
7193 rtx pat = PATTERN(insn);
7194 rtx dep_pat = PATTERN (dep_insn);
7196 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7199 insn_type = get_attr_type (insn);
7200 dep_type = get_attr_type (dep_insn);
7202 switch (REG_NOTE_KIND (link))
7205 /* Data dependency; DEP_INSN writes a register that INSN reads some
7212 /* Get the delay iff the address of the store is the dependence. */
7213 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7216 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7223 /* If a load, then the dependence must be on the memory address. If
7224 the addresses aren't equal, then it might be a false dependency */
7225 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7227 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7228 || GET_CODE (SET_DEST (dep_pat)) != MEM
7229 || GET_CODE (SET_SRC (pat)) != MEM
7230 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
7231 XEXP (SET_SRC (pat), 0)))
7239 /* Compare to branch latency is 0. There is no benefit from
7240 separating compare and branch. */
7241 if (dep_type == TYPE_COMPARE)
7243 /* Floating point compare to branch latency is less than
7244 compare to conditional move. */
7245 if (dep_type == TYPE_FPCMP)
7254 /* Anti-dependencies only penalize the fpu unit. */
7255 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7267 ultrasparc_adjust_cost (insn, link, dep_insn, cost)
7273 enum attr_type insn_type, dep_type;
7274 rtx pat = PATTERN(insn);
7275 rtx dep_pat = PATTERN (dep_insn);
7277 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7280 insn_type = get_attr_type (insn);
7281 dep_type = get_attr_type (dep_insn);
7283 /* Nothing issues in parallel with integer multiplies, so
7284 mark as zero cost since the scheduler can not do anything
7286 if (insn_type == TYPE_IMUL || insn_type == TYPE_IDIV)
7289 #define SLOW_FP(dep_type) \
7290 (dep_type == TYPE_FPSQRTS || dep_type == TYPE_FPSQRTD || \
7291 dep_type == TYPE_FPDIVS || dep_type == TYPE_FPDIVD)
7293 switch (REG_NOTE_KIND (link))
7296 /* Data dependency; DEP_INSN writes a register that INSN reads some
7299 if (dep_type == TYPE_CMOVE)
7301 /* Instructions that read the result of conditional moves cannot
7302 be in the same group or the following group. */
7308 /* UltraSPARC can dual issue a store and an instruction setting
7309 the value stored, except for divide and square root. */
7311 if (! SLOW_FP (dep_type))
7316 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7319 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7320 /* The dependency between the two instructions is on the data
7321 that is being stored. Assume that the address of the store
7322 is not also dependent. */
7329 /* A load does not return data until at least 11 cycles after
7330 a store to the same location. 3 cycles are accounted for
7331 in the load latency; add the other 8 here. */
7332 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7334 /* If the addresses are not equal this may be a false
7335 dependency because pointer aliasing could not be
7336 determined. Add only 2 cycles in that case. 2 is
7337 an arbitrary compromise between 8, which would cause
7338 the scheduler to generate worse code elsewhere to
7339 compensate for a dependency which might not really
7341 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7342 || GET_CODE (SET_SRC (pat)) != MEM
7343 || GET_CODE (SET_DEST (dep_pat)) != MEM
7344 || ! rtx_equal_p (XEXP (SET_SRC (pat), 0),
7345 XEXP (SET_DEST (dep_pat), 0)))
7353 /* Compare to branch latency is 0. There is no benefit from
7354 separating compare and branch. */
7355 if (dep_type == TYPE_COMPARE)
7357 /* Floating point compare to branch latency is less than
7358 compare to conditional move. */
7359 if (dep_type == TYPE_FPCMP)
7364 /* FMOVR class instructions can not issue in the same cycle
7365 or the cycle after an instruction which writes any
7366 integer register. Model this as cost 2 for dependent
7368 if (dep_type == TYPE_IALU
7371 /* Otherwise check as for integer conditional moves. */
7374 /* Conditional moves involving integer registers wait until
7375 3 cycles after loads return data. The interlock applies
7376 to all loads, not just dependent loads, but that is hard
7378 if (dep_type == TYPE_LOAD || dep_type == TYPE_SLOAD)
7388 /* Divide and square root lock destination registers for full latency. */
7389 if (! SLOW_FP (dep_type))
7393 case REG_DEP_OUTPUT:
7394 /* IEU and FPU instruction that have the same destination
7395 register cannot be grouped together. */
7402 /* Other costs not accounted for:
7403 - Single precision floating point loads lock the other half of
7404 the even/odd register pair.
7405 - Several hazards associated with ldd/std are ignored because these
7406 instructions are rarely generated for V9.
7407 - The floating point pipeline can not have both a single and double
7408 precision operation active at the same time. Format conversions
7409 and graphics instructions are given honorary double precision status.
7410 - call and jmpl are always the first instruction in a group. */
7418 sparc_adjust_cost(insn, link, dep, cost)
7426 case PROCESSOR_SUPERSPARC:
7427 cost = supersparc_adjust_cost (insn, link, dep, cost);
7429 case PROCESSOR_HYPERSPARC:
7430 case PROCESSOR_SPARCLITE86X:
7431 cost = hypersparc_adjust_cost (insn, link, dep, cost);
7433 case PROCESSOR_ULTRASPARC:
7434 cost = ultrasparc_adjust_cost (insn, link, dep, cost);
7442 /* This describes the state of the UltraSPARC pipeline during
7443 instruction scheduling. */
7445 #define TMASK(__x) ((unsigned)1 << ((int)(__x)))
7446 #define UMASK(__x) ((unsigned)1 << ((int)(__x)))
7448 enum ultra_code { NONE=0, /* no insn at all */
7449 IEU0, /* shifts and conditional moves */
7450 IEU1, /* condition code setting insns, calls+jumps */
7451 IEUN, /* all other single cycle ieu insns */
7452 LSU, /* loads and stores */
7454 FPM, /* FPU pipeline 1, multiplies and divides */
7455 FPA, /* FPU pipeline 2, all other operations */
7456 SINGLE, /* single issue instructions */
7459 static enum ultra_code ultra_code_from_mask PARAMS ((int));
7460 static void ultra_schedule_insn PARAMS ((rtx *, rtx *, int, enum ultra_code));
7462 static const char *const ultra_code_names[NUM_ULTRA_CODES] = {
7463 "NONE", "IEU0", "IEU1", "IEUN", "LSU", "CTI",
7464 "FPM", "FPA", "SINGLE" };
7466 struct ultrasparc_pipeline_state {
7467 /* The insns in this group. */
7470 /* The code for each insn. */
7471 enum ultra_code codes[4];
7473 /* Which insns in this group have been committed by the
7474 scheduler. This is how we determine how many more
7475 can issue this cycle. */
7478 /* How many insns in this group. */
7481 /* Mask of free slots still in this group. */
7482 char free_slot_mask;
7484 /* The slotter uses the following to determine what other
7485 insn types can still make their way into this group. */
7486 char contents [NUM_ULTRA_CODES];
7490 #define ULTRA_NUM_HIST 8
7491 static struct ultrasparc_pipeline_state ultra_pipe_hist[ULTRA_NUM_HIST];
7492 static int ultra_cur_hist;
7493 static int ultra_cycles_elapsed;
7495 #define ultra_pipe (ultra_pipe_hist[ultra_cur_hist])
7497 /* Given TYPE_MASK compute the ultra_code it has. */
7498 static enum ultra_code
7499 ultra_code_from_mask (type_mask)
7502 if (type_mask & (TMASK (TYPE_SHIFT) | TMASK (TYPE_CMOVE)))
7504 else if (type_mask & (TMASK (TYPE_COMPARE) |
7506 TMASK (TYPE_SIBCALL) |
7507 TMASK (TYPE_UNCOND_BRANCH)))
7509 else if (type_mask & TMASK (TYPE_IALU))
7511 else if (type_mask & (TMASK (TYPE_LOAD) | TMASK (TYPE_SLOAD) |
7512 TMASK (TYPE_STORE) | TMASK (TYPE_FPLOAD) |
7513 TMASK (TYPE_FPSTORE)))
7515 else if (type_mask & (TMASK (TYPE_FPMUL) | TMASK (TYPE_FPDIVS) |
7516 TMASK (TYPE_FPDIVD) | TMASK (TYPE_FPSQRTS) |
7517 TMASK (TYPE_FPSQRTD)))
7519 else if (type_mask & (TMASK (TYPE_FPMOVE) | TMASK (TYPE_FPCMOVE) |
7520 TMASK (TYPE_FP) | TMASK (TYPE_FPCMP)))
7522 else if (type_mask & TMASK (TYPE_BRANCH))
7528 /* Check INSN (a conditional move) and make sure that it's
7529 results are available at this cycle. Return 1 if the
7530 results are in fact ready. */
7532 ultra_cmove_results_ready_p (insn)
7535 struct ultrasparc_pipeline_state *up;
7538 /* If this got dispatched in the previous
7539 group, the results are not ready. */
7540 entry = (ultra_cur_hist - 1) & (ULTRA_NUM_HIST - 1);
7541 up = &ultra_pipe_hist[entry];
7544 if (up->group[slot] == insn)
7550 /* Walk backwards in pipeline history looking for FPU
7551 operations which use a mode different than FPMODE and
7552 will create a stall if an insn using FPMODE were to be
7553 dispatched this cycle. */
7555 ultra_fpmode_conflict_exists (fpmode)
7556 enum machine_mode fpmode;
7561 hist_ent = (ultra_cur_hist - 1) & (ULTRA_NUM_HIST - 1);
7562 if (ultra_cycles_elapsed < 4)
7563 hist_lim = ultra_cycles_elapsed;
7566 while (hist_lim > 0)
7568 struct ultrasparc_pipeline_state *up = &ultra_pipe_hist[hist_ent];
7573 rtx insn = up->group[slot];
7574 enum machine_mode this_mode;
7578 || GET_CODE (insn) != INSN
7579 || (pat = PATTERN (insn)) == 0
7580 || GET_CODE (pat) != SET)
7583 this_mode = GET_MODE (SET_DEST (pat));
7584 if ((this_mode != SFmode
7585 && this_mode != DFmode)
7586 || this_mode == fpmode)
7589 /* If it is not FMOV, FABS, FNEG, FDIV, or FSQRT then
7590 we will get a stall. Loads and stores are independent
7592 if (GET_CODE (SET_SRC (pat)) != ABS
7593 && GET_CODE (SET_SRC (pat)) != NEG
7594 && ((TMASK (get_attr_type (insn)) &
7595 (TMASK (TYPE_FPDIVS) | TMASK (TYPE_FPDIVD) |
7596 TMASK (TYPE_FPMOVE) | TMASK (TYPE_FPSQRTS) |
7597 TMASK (TYPE_FPSQRTD) |
7598 TMASK (TYPE_LOAD) | TMASK (TYPE_STORE))) == 0))
7602 hist_ent = (hist_ent - 1) & (ULTRA_NUM_HIST - 1);
7605 /* No conflicts, safe to dispatch. */
7609 /* Find an instruction in LIST which has one of the
7610 type attributes enumerated in TYPE_MASK. START
7611 says where to begin the search.
7613 NOTE: This scheme depends upon the fact that we
7614 have less than 32 distinct type attributes. */
7616 static int ultra_types_avail;
7619 ultra_find_type (type_mask, list, start)
7626 /* Short circuit if no such insn exists in the ready
7628 if ((type_mask & ultra_types_avail) == 0)
7631 for (i = start; i >= 0; i--)
7635 if (recog_memoized (insn) >= 0
7636 && (TMASK(get_attr_type (insn)) & type_mask))
7638 enum machine_mode fpmode = SFmode;
7641 int check_depend = 0;
7642 int check_fpmode_conflict = 0;
7644 if (GET_CODE (insn) == INSN
7645 && (pat = PATTERN(insn)) != 0
7646 && GET_CODE (pat) == SET
7647 && !(type_mask & (TMASK (TYPE_STORE) |
7648 TMASK (TYPE_FPSTORE))))
7651 if (GET_MODE (SET_DEST (pat)) == SFmode
7652 || GET_MODE (SET_DEST (pat)) == DFmode)
7654 fpmode = GET_MODE (SET_DEST (pat));
7655 check_fpmode_conflict = 1;
7662 rtx slot_insn = ultra_pipe.group[slot];
7665 /* Already issued, bad dependency, or FPU
7668 && (slot_pat = PATTERN (slot_insn)) != 0
7669 && ((insn == slot_insn)
7670 || (check_depend == 1
7671 && GET_CODE (slot_insn) == INSN
7672 && GET_CODE (slot_pat) == SET
7673 && ((GET_CODE (SET_DEST (slot_pat)) == REG
7674 && GET_CODE (SET_SRC (pat)) == REG
7675 && REGNO (SET_DEST (slot_pat)) ==
7676 REGNO (SET_SRC (pat)))
7677 || (GET_CODE (SET_DEST (slot_pat)) == SUBREG
7678 && GET_CODE (SET_SRC (pat)) == SUBREG
7679 && REGNO (SUBREG_REG (SET_DEST (slot_pat))) ==
7680 REGNO (SUBREG_REG (SET_SRC (pat)))
7681 && SUBREG_BYTE (SET_DEST (slot_pat)) ==
7682 SUBREG_BYTE (SET_SRC (pat)))))
7683 || (check_fpmode_conflict == 1
7684 && GET_CODE (slot_insn) == INSN
7685 && GET_CODE (slot_pat) == SET
7686 && (GET_MODE (SET_DEST (slot_pat)) == SFmode
7687 || GET_MODE (SET_DEST (slot_pat)) == DFmode)
7688 && GET_MODE (SET_DEST (slot_pat)) != fpmode)))
7692 /* Check for peculiar result availability and dispatch
7693 interference situations. */
7695 && ultra_cycles_elapsed > 0)
7699 for (link = LOG_LINKS (insn); link; link = XEXP (link, 1))
7701 rtx link_insn = XEXP (link, 0);
7702 if (GET_CODE (link_insn) == INSN
7703 && recog_memoized (link_insn) >= 0
7704 && (TMASK (get_attr_type (link_insn)) &
7705 (TMASK (TYPE_CMOVE) | TMASK (TYPE_FPCMOVE)))
7706 && ! ultra_cmove_results_ready_p (link_insn))
7710 if (check_fpmode_conflict
7711 && ultra_fpmode_conflict_exists (fpmode))
7724 ultra_build_types_avail (ready, n_ready)
7728 int i = n_ready - 1;
7730 ultra_types_avail = 0;
7733 rtx insn = ready[i];
7735 if (recog_memoized (insn) >= 0)
7736 ultra_types_avail |= TMASK (get_attr_type (insn));
7742 /* Place insn pointed to my IP into the pipeline.
7743 Make element THIS of READY be that insn if it
7744 is not already. TYPE indicates the pipeline class
7745 this insn falls into. */
7747 ultra_schedule_insn (ip, ready, this, type)
7751 enum ultra_code type;
7754 char mask = ultra_pipe.free_slot_mask;
7757 /* Obtain free slot. */
7758 for (pipe_slot = 0; pipe_slot < 4; pipe_slot++)
7759 if ((mask & (1 << pipe_slot)) != 0)
7764 /* In it goes, and it hasn't been committed yet. */
7765 ultra_pipe.group[pipe_slot] = *ip;
7766 ultra_pipe.codes[pipe_slot] = type;
7767 ultra_pipe.contents[type] = 1;
7769 (UMASK (IEUN) | UMASK (IEU0) | UMASK (IEU1)))
7770 ultra_pipe.num_ieu_insns += 1;
7772 ultra_pipe.free_slot_mask = (mask & ~(1 << pipe_slot));
7773 ultra_pipe.group_size += 1;
7774 ultra_pipe.commit[pipe_slot] = 0;
7776 /* Update ready list. */
7778 while (ip != &ready[this])
7786 /* Advance to the next pipeline group. */
7788 ultra_flush_pipeline ()
7790 ultra_cur_hist = (ultra_cur_hist + 1) & (ULTRA_NUM_HIST - 1);
7791 ultra_cycles_elapsed += 1;
7792 memset ((char *) &ultra_pipe, 0, sizeof ultra_pipe);
7793 ultra_pipe.free_slot_mask = 0xf;
7796 /* Init our data structures for this current block. */
7798 ultrasparc_sched_init ()
7800 memset ((char *) ultra_pipe_hist, 0, sizeof ultra_pipe_hist);
7802 ultra_cycles_elapsed = 0;
7803 ultra_pipe.free_slot_mask = 0xf;
7807 sparc_sched_init (dump, sched_verbose, max_ready)
7808 FILE *dump ATTRIBUTE_UNUSED;
7809 int sched_verbose ATTRIBUTE_UNUSED;
7810 int max_ready ATTRIBUTE_UNUSED;
7812 if (sparc_cpu == PROCESSOR_ULTRASPARC)
7813 ultrasparc_sched_init ();
7816 /* INSN has been scheduled, update pipeline commit state
7817 and return how many instructions are still to be
7818 scheduled in this group. */
7820 ultrasparc_variable_issue (insn)
7823 struct ultrasparc_pipeline_state *up = &ultra_pipe;
7824 int i, left_to_fire;
7827 for (i = 0; i < 4; i++)
7829 if (up->group[i] == 0)
7832 if (up->group[i] == insn)
7836 else if (! up->commit[i])
7840 return left_to_fire;
7844 sparc_variable_issue (dump, sched_verbose, insn, cim)
7845 FILE *dump ATTRIBUTE_UNUSED;
7846 int sched_verbose ATTRIBUTE_UNUSED;
7850 if (sparc_cpu == PROCESSOR_ULTRASPARC)
7851 return ultrasparc_variable_issue (insn);
7856 /* In actual_hazard_this_instance, we may have yanked some
7857 instructions from the ready list due to conflict cost
7858 adjustments. If so, and such an insn was in our pipeline
7859 group, remove it and update state. */
7861 ultra_rescan_pipeline_state (ready, n_ready)
7865 struct ultrasparc_pipeline_state *up = &ultra_pipe;
7868 for (i = 0; i < 4; i++)
7870 rtx insn = up->group[i];
7876 /* If it has been committed, then it was removed from
7877 the ready list because it was actually scheduled,
7878 and that is not the case we are searching for here. */
7879 if (up->commit[i] != 0)
7882 for (j = n_ready - 1; j >= 0; j--)
7883 if (ready[j] == insn)
7886 /* If we didn't find it, toss it. */
7889 enum ultra_code ucode = up->codes[i];
7892 up->codes[i] = NONE;
7893 up->contents[ucode] = 0;
7895 (UMASK (IEUN) | UMASK (IEU0) | UMASK (IEU1)))
7896 up->num_ieu_insns -= 1;
7898 up->free_slot_mask |= (1 << i);
7899 up->group_size -= 1;
7906 ultrasparc_sched_reorder (dump, sched_verbose, ready, n_ready)
7912 struct ultrasparc_pipeline_state *up = &ultra_pipe;
7919 fprintf (dump, "\n;;\tUltraSPARC Looking at [");
7920 for (n = n_ready - 1; n >= 0; n--)
7922 rtx insn = ready[n];
7923 enum ultra_code ucode;
7925 if (recog_memoized (insn) < 0)
7927 ucode = ultra_code_from_mask (TMASK (get_attr_type (insn)));
7929 fprintf (dump, "%s(%d) ",
7930 ultra_code_names[ucode],
7933 fprintf (dump, "%s(%d)",
7934 ultra_code_names[ucode],
7937 fprintf (dump, "]\n");
7940 this_insn = n_ready - 1;
7942 /* Skip over junk we don't understand. */
7943 while ((this_insn >= 0)
7944 && recog_memoized (ready[this_insn]) < 0)
7947 ultra_build_types_avail (ready, this_insn + 1);
7949 while (this_insn >= 0) {
7950 int old_group_size = up->group_size;
7952 if (up->group_size != 0)
7956 num_committed = (up->commit[0] + up->commit[1] +
7957 up->commit[2] + up->commit[3]);
7958 /* If nothing has been commited from our group, or all of
7959 them have. Clear out the (current cycle's) pipeline
7960 state and start afresh. */
7961 if (num_committed == 0
7962 || num_committed == up->group_size)
7964 ultra_flush_pipeline ();
7970 /* OK, some ready list insns got requeued and thus removed
7971 from the ready list. Account for this fact. */
7972 ultra_rescan_pipeline_state (ready, n_ready);
7974 /* Something "changed", make this look like a newly
7975 formed group so the code at the end of the loop
7976 knows that progress was in fact made. */
7977 if (up->group_size != old_group_size)
7982 if (up->group_size == 0)
7984 /* If the pipeline is (still) empty and we have any single
7985 group insns, get them out now as this is a good time. */
7986 rtx *ip = ultra_find_type ((TMASK (TYPE_RETURN) | TMASK (TYPE_IDIV) |
7987 TMASK (TYPE_IMUL) | TMASK (TYPE_CMOVE) |
7988 TMASK (TYPE_MULTI) | TMASK (TYPE_MISC)),
7992 ultra_schedule_insn (ip, ready, this_insn, SINGLE);
7996 /* If we are not in the process of emptying out the pipe, try to
7997 obtain an instruction which must be the first in it's group. */
7998 ip = ultra_find_type ((TMASK (TYPE_CALL) |
7999 TMASK (TYPE_SIBCALL) |
8000 TMASK (TYPE_CALL_NO_DELAY_SLOT) |
8001 TMASK (TYPE_UNCOND_BRANCH)),
8005 ultra_schedule_insn (ip, ready, this_insn, IEU1);
8008 else if ((ip = ultra_find_type ((TMASK (TYPE_FPDIVS) |
8009 TMASK (TYPE_FPDIVD) |
8010 TMASK (TYPE_FPSQRTS) |
8011 TMASK (TYPE_FPSQRTD)),
8012 ready, this_insn)) != 0)
8014 ultra_schedule_insn (ip, ready, this_insn, FPM);
8019 /* Try to fill the integer pipeline. First, look for an IEU0 specific
8020 operation. We can't do more IEU operations if the first 3 slots are
8021 all full or we have dispatched two IEU insns already. */
8022 if ((up->free_slot_mask & 0x7) != 0
8023 && up->num_ieu_insns < 2
8024 && up->contents[IEU0] == 0
8025 && up->contents[IEUN] == 0)
8027 rtx *ip = ultra_find_type (TMASK(TYPE_SHIFT), ready, this_insn);
8030 ultra_schedule_insn (ip, ready, this_insn, IEU0);
8035 /* If we can, try to find an IEU1 specific or an unnamed
8037 if ((up->free_slot_mask & 0x7) != 0
8038 && up->num_ieu_insns < 2)
8040 rtx *ip = ultra_find_type ((TMASK (TYPE_IALU) |
8041 (up->contents[IEU1] == 0 ? TMASK (TYPE_COMPARE) : 0)),
8047 ultra_schedule_insn (ip, ready, this_insn,
8048 (!up->contents[IEU1]
8049 && get_attr_type (insn) == TYPE_COMPARE)
8055 /* If only one IEU insn has been found, try to find another unnamed
8056 IEU operation or an IEU1 specific one. */
8057 if ((up->free_slot_mask & 0x7) != 0
8058 && up->num_ieu_insns < 2)
8061 int tmask = TMASK (TYPE_IALU);
8063 if (!up->contents[IEU1])
8064 tmask |= TMASK (TYPE_COMPARE);
8065 ip = ultra_find_type (tmask, ready, this_insn);
8070 ultra_schedule_insn (ip, ready, this_insn,
8071 (!up->contents[IEU1]
8072 && get_attr_type (insn) == TYPE_COMPARE)
8078 /* Try for a load or store, but such an insn can only be issued
8079 if it is within' one of the first 3 slots. */
8080 if ((up->free_slot_mask & 0x7) != 0
8081 && up->contents[LSU] == 0)
8083 rtx *ip = ultra_find_type ((TMASK (TYPE_LOAD) | TMASK (TYPE_SLOAD) |
8084 TMASK (TYPE_STORE) | TMASK (TYPE_FPLOAD) |
8085 TMASK (TYPE_FPSTORE)), ready, this_insn);
8088 ultra_schedule_insn (ip, ready, this_insn, LSU);
8093 /* Now find FPU operations, first FPM class. But not divisions or
8094 square-roots because those will break the group up. Unlike all
8095 the previous types, these can go in any slot. */
8096 if (up->free_slot_mask != 0
8097 && up->contents[FPM] == 0)
8099 rtx *ip = ultra_find_type (TMASK (TYPE_FPMUL), ready, this_insn);
8102 ultra_schedule_insn (ip, ready, this_insn, FPM);
8107 /* Continue on with FPA class if we have not filled the group already. */
8108 if (up->free_slot_mask != 0
8109 && up->contents[FPA] == 0)
8111 rtx *ip = ultra_find_type ((TMASK (TYPE_FPMOVE) | TMASK (TYPE_FPCMOVE) |
8112 TMASK (TYPE_FP) | TMASK (TYPE_FPCMP)),
8116 ultra_schedule_insn (ip, ready, this_insn, FPA);
8121 /* Finally, maybe stick a branch in here. */
8122 if (up->free_slot_mask != 0
8123 && up->contents[CTI] == 0)
8125 rtx *ip = ultra_find_type (TMASK (TYPE_BRANCH), ready, this_insn);
8127 /* Try to slip in a branch only if it is one of the
8128 next 2 in the ready list. */
8129 if (ip && ((&ready[this_insn] - ip) < 2))
8131 ultra_schedule_insn (ip, ready, this_insn, CTI);
8137 for (i = 0; i < 4; i++)
8138 if ((up->free_slot_mask & (1 << i)) == 0)
8141 /* See if we made any progress... */
8142 if (old_group_size != up->group_size)
8145 /* Clean out the (current cycle's) pipeline state
8146 and try once more. If we placed no instructions
8147 into the pipeline at all, it means a real hard
8148 conflict exists with some earlier issued instruction
8149 so we must advance to the next cycle to clear it up. */
8150 if (up->group_size == 0)
8152 ultra_flush_pipeline ();
8157 memset ((char *) &ultra_pipe, 0, sizeof ultra_pipe);
8158 ultra_pipe.free_slot_mask = 0xf;
8166 fprintf (dump, ";;\tUltraSPARC Launched [");
8167 gsize = up->group_size;
8168 for (n = 0; n < 4; n++)
8170 rtx insn = up->group[n];
8177 fprintf (dump, "%s(%d) ",
8178 ultra_code_names[up->codes[n]],
8181 fprintf (dump, "%s(%d)",
8182 ultra_code_names[up->codes[n]],
8185 fprintf (dump, "]\n");
8190 sparc_sched_reorder (dump, sched_verbose, ready, n_readyp, clock)
8195 int clock ATTRIBUTE_UNUSED;
8197 if (sparc_cpu == PROCESSOR_ULTRASPARC)
8198 ultrasparc_sched_reorder (dump, sched_verbose, ready, *n_readyp);
8199 return sparc_issue_rate ();
8210 /* Assume V9 processors are capable of at least dual-issue. */
8212 case PROCESSOR_SUPERSPARC:
8214 case PROCESSOR_HYPERSPARC:
8215 case PROCESSOR_SPARCLITE86X:
8217 case PROCESSOR_ULTRASPARC:
8226 register rtx pat = PATTERN (insn);
8228 switch (GET_CODE (SET_SRC (pat)))
8230 /* Load and some shift instructions zero extend. */
8233 /* sethi clears the high bits */
8235 /* LO_SUM is used with sethi. sethi cleared the high
8236 bits and the values used with lo_sum are positive */
8238 /* Store flag stores 0 or 1 */
8248 rtx op0 = XEXP (SET_SRC (pat), 0);
8249 rtx op1 = XEXP (SET_SRC (pat), 1);
8250 if (GET_CODE (op1) == CONST_INT)
8251 return INTVAL (op1) >= 0;
8252 if (GET_CODE (op0) != REG)
8254 if (sparc_check_64 (op0, insn) == 1)
8256 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
8261 rtx op0 = XEXP (SET_SRC (pat), 0);
8262 rtx op1 = XEXP (SET_SRC (pat), 1);
8263 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
8265 if (GET_CODE (op1) == CONST_INT)
8266 return INTVAL (op1) >= 0;
8267 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
8271 return GET_MODE (SET_SRC (pat)) == SImode;
8272 /* Positive integers leave the high bits zero. */
8274 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
8276 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
8279 return - (GET_MODE (SET_SRC (pat)) == SImode);
8281 return sparc_check_64 (SET_SRC (pat), insn);
8287 /* We _ought_ to have only one kind per function, but... */
8288 static rtx sparc_addr_diff_list;
8289 static rtx sparc_addr_list;
8292 sparc_defer_case_vector (lab, vec, diff)
8296 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
8298 sparc_addr_diff_list
8299 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
8301 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
8305 sparc_output_addr_vec (vec)
8308 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8309 int idx, vlen = XVECLEN (body, 0);
8311 #ifdef ASM_OUTPUT_ADDR_VEC_START
8312 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8315 #ifdef ASM_OUTPUT_CASE_LABEL
8316 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8319 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8322 for (idx = 0; idx < vlen; idx++)
8324 ASM_OUTPUT_ADDR_VEC_ELT
8325 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
8328 #ifdef ASM_OUTPUT_ADDR_VEC_END
8329 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8334 sparc_output_addr_diff_vec (vec)
8337 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8338 rtx base = XEXP (XEXP (body, 0), 0);
8339 int idx, vlen = XVECLEN (body, 1);
8341 #ifdef ASM_OUTPUT_ADDR_VEC_START
8342 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8345 #ifdef ASM_OUTPUT_CASE_LABEL
8346 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8349 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8352 for (idx = 0; idx < vlen; idx++)
8354 ASM_OUTPUT_ADDR_DIFF_ELT
8357 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
8358 CODE_LABEL_NUMBER (base));
8361 #ifdef ASM_OUTPUT_ADDR_VEC_END
8362 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8367 sparc_output_deferred_case_vectors ()
8372 if (sparc_addr_list == NULL_RTX
8373 && sparc_addr_diff_list == NULL_RTX)
8376 /* Align to cache line in the function's code section. */
8377 function_section (current_function_decl);
8379 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
8381 ASM_OUTPUT_ALIGN (asm_out_file, align);
8383 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
8384 sparc_output_addr_vec (XEXP (t, 0));
8385 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
8386 sparc_output_addr_diff_vec (XEXP (t, 0));
8388 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
8391 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
8392 unknown. Return 1 if the high bits are zero, -1 if the register is
8395 sparc_check_64 (x, insn)
8398 /* If a register is set only once it is safe to ignore insns this
8399 code does not know how to handle. The loop will either recognize
8400 the single set and return the correct value or fail to recognize
8405 if (GET_CODE (x) != REG)
8408 if (GET_MODE (x) == DImode)
8409 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
8411 if (flag_expensive_optimizations
8412 && REG_N_SETS (REGNO (y)) == 1)
8418 insn = get_last_insn_anywhere ();
8423 while ((insn = PREV_INSN (insn)))
8425 switch (GET_CODE (insn))
8438 rtx pat = PATTERN (insn);
8439 if (GET_CODE (pat) != SET)
8441 if (rtx_equal_p (x, SET_DEST (pat)))
8442 return set_extends (insn);
8443 if (y && rtx_equal_p (y, SET_DEST (pat)))
8444 return set_extends (insn);
8445 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
8454 sparc_v8plus_shift (operands, insn, opcode)
8459 static char asm_code[60];
8461 if (GET_CODE (operands[3]) == SCRATCH)
8462 operands[3] = operands[0];
8463 if (GET_CODE (operands[1]) == CONST_INT)
8465 output_asm_insn ("mov\t%1, %3", operands);
8469 output_asm_insn ("sllx\t%H1, 32, %3", operands);
8470 if (sparc_check_64 (operands[1], insn) <= 0)
8471 output_asm_insn ("srl\t%L1, 0, %L1", operands);
8472 output_asm_insn ("or\t%L1, %3, %3", operands);
8475 strcpy(asm_code, opcode);
8476 if (which_alternative != 2)
8477 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
8479 return strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
8482 /* Output rtl to increment the profiler label LABELNO
8483 for profiling a function entry. */
8486 sparc_profile_hook (labelno)
8492 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
8493 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
8494 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
8496 emit_library_call (fun, 0, VOIDmode, 1, lab, Pmode);
8499 /* Mark ARG, which is really a struct ultrasparc_pipline_state *, for
8503 mark_ultrasparc_pipeline_state (arg)
8506 struct ultrasparc_pipeline_state *ups;
8509 ups = (struct ultrasparc_pipeline_state *) arg;
8510 for (i = 0; i < ARRAY_SIZE (ups->group); ++i)
8511 ggc_mark_rtx (ups->group[i]);
8514 /* Called to register all of our global variables with the garbage
8518 sparc_add_gc_roots ()
8520 ggc_add_rtx_root (&sparc_compare_op0, 1);
8521 ggc_add_rtx_root (&sparc_compare_op1, 1);
8522 ggc_add_rtx_root (&global_offset_table, 1);
8523 ggc_add_rtx_root (&get_pc_symbol, 1);
8524 ggc_add_rtx_root (&sparc_addr_diff_list, 1);
8525 ggc_add_rtx_root (&sparc_addr_list, 1);
8526 ggc_add_root (ultra_pipe_hist, ARRAY_SIZE (ultra_pipe_hist),
8527 sizeof (ultra_pipe_hist[0]), &mark_ultrasparc_pipeline_state);
8530 #ifdef OBJECT_FORMAT_ELF
8532 sparc_elf_asm_named_section (name, flags)
8536 if (flags & SECTION_MERGE)
8538 /* entsize cannot be expressed in this section attributes
8540 default_elf_asm_named_section (name, flags);
8544 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
8546 if (!(flags & SECTION_DEBUG))
8547 fputs (",#alloc", asm_out_file);
8548 if (flags & SECTION_WRITE)
8549 fputs (",#write", asm_out_file);
8550 if (flags & SECTION_CODE)
8551 fputs (",#execinstr", asm_out_file);
8553 /* ??? Handle SECTION_BSS. */
8555 fputc ('\n', asm_out_file);
8557 #endif /* OBJECT_FORMAT_ELF */