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 saved
72 (as 4-byte quantities). This is only done if TARGET_EPILOGUE. */
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. */
78 rtx sparc_compare_op0, sparc_compare_op1;
80 /* We may need an epilogue if we spill too many registers.
81 If this is non-zero, then we branch here for the epilogue. */
82 static rtx leaf_label;
86 /* Vector to say how input registers are mapped to output
87 registers. FRAME_POINTER_REGNUM cannot be remapped by
88 this function to eliminate it. You must use -fomit-frame-pointer
90 const char leaf_reg_remap[] =
91 { 0, 1, 2, 3, 4, 5, 6, 7,
92 -1, -1, -1, -1, -1, -1, 14, -1,
93 -1, -1, -1, -1, -1, -1, -1, -1,
94 8, 9, 10, 11, 12, 13, -1, 15,
96 32, 33, 34, 35, 36, 37, 38, 39,
97 40, 41, 42, 43, 44, 45, 46, 47,
98 48, 49, 50, 51, 52, 53, 54, 55,
99 56, 57, 58, 59, 60, 61, 62, 63,
100 64, 65, 66, 67, 68, 69, 70, 71,
101 72, 73, 74, 75, 76, 77, 78, 79,
102 80, 81, 82, 83, 84, 85, 86, 87,
103 88, 89, 90, 91, 92, 93, 94, 95,
104 96, 97, 98, 99, 100};
106 /* Vector, indexed by hard register number, which contains 1
107 for a register that is allowable in a candidate for leaf
108 function treatment. */
109 char sparc_leaf_regs[] =
110 { 1, 1, 1, 1, 1, 1, 1, 1,
111 0, 0, 0, 0, 0, 0, 1, 0,
112 0, 0, 0, 0, 0, 0, 0, 0,
113 1, 1, 1, 1, 1, 1, 0, 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,
120 1, 1, 1, 1, 1, 1, 1, 1,
121 1, 1, 1, 1, 1, 1, 1, 1,
126 /* Name of where we pretend to think the frame pointer points.
127 Normally, this is "%fp", but if we are in a leaf procedure,
128 this is "%sp+something". We record "something" separately as it may be
129 too big for reg+constant addressing. */
131 static const char *frame_base_name;
132 static int frame_base_offset;
134 static void sparc_init_modes PARAMS ((void));
135 static int save_regs PARAMS ((FILE *, int, int, const char *,
137 static int restore_regs PARAMS ((FILE *, int, int, const char *, int, int));
138 static void build_big_number PARAMS ((FILE *, int, const char *));
139 static int function_arg_slotno PARAMS ((const CUMULATIVE_ARGS *,
140 enum machine_mode, tree, int, int,
143 static int supersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
144 static int hypersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
145 static int ultrasparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
147 static void sparc_output_addr_vec PARAMS ((rtx));
148 static void sparc_output_addr_diff_vec PARAMS ((rtx));
149 static void sparc_output_deferred_case_vectors PARAMS ((void));
150 static void sparc_add_gc_roots PARAMS ((void));
151 static void mark_ultrasparc_pipeline_state PARAMS ((void *));
152 static int check_return_regs PARAMS ((rtx));
153 static int epilogue_renumber PARAMS ((rtx *, int));
154 static int ultra_cmove_results_ready_p PARAMS ((rtx));
155 static int ultra_fpmode_conflict_exists PARAMS ((enum machine_mode));
156 static rtx *ultra_find_type PARAMS ((int, rtx *, int));
157 static void ultra_build_types_avail PARAMS ((rtx *, int));
158 static void ultra_flush_pipeline PARAMS ((void));
159 static void ultra_rescan_pipeline_state PARAMS ((rtx *, int));
160 static int set_extends PARAMS ((rtx));
161 static void output_restore_regs PARAMS ((FILE *, int));
162 static void sparc_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
163 static void sparc_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
164 static void sparc_flat_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
165 static void sparc_flat_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
166 static void sparc_nonflat_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT,
168 static void sparc_nonflat_function_prologue PARAMS ((FILE *, HOST_WIDE_INT,
170 #ifdef OBJECT_FORMAT_ELF
171 static void sparc_elf_asm_named_section PARAMS ((const char *, unsigned int));
173 static void ultrasparc_sched_reorder PARAMS ((FILE *, int, rtx *, int));
174 static int ultrasparc_variable_issue PARAMS ((rtx));
175 static void ultrasparc_sched_init PARAMS ((void));
177 static int sparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
178 static int sparc_issue_rate PARAMS ((void));
179 static int sparc_variable_issue PARAMS ((FILE *, int, rtx, int));
180 static void sparc_sched_init PARAMS ((FILE *, int, int));
181 static int sparc_sched_reorder PARAMS ((FILE *, int, rtx *, int *, int));
183 /* Option handling. */
185 /* Code model option as passed by user. */
186 const char *sparc_cmodel_string;
188 enum cmodel sparc_cmodel;
190 char sparc_hard_reg_printed[8];
192 struct sparc_cpu_select sparc_select[] =
194 /* switch name, tune arch */
195 { (char *)0, "default", 1, 1 },
196 { (char *)0, "-mcpu=", 1, 1 },
197 { (char *)0, "-mtune=", 1, 0 },
201 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
202 enum processor_type sparc_cpu;
204 /* Initialize the GCC target structure. */
205 #undef TARGET_ASM_FUNCTION_PROLOGUE
206 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_output_function_prologue
207 #undef TARGET_ASM_FUNCTION_EPILOGUE
208 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_output_function_epilogue
210 #undef TARGET_SCHED_ADJUST_COST
211 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
212 #undef TARGET_SCHED_ISSUE_RATE
213 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
214 #undef TARGET_SCHED_VARIABLE_ISSUE
215 #define TARGET_SCHED_VARIABLE_ISSUE sparc_variable_issue
216 #undef TARGET_SCHED_INIT
217 #define TARGET_SCHED_INIT sparc_sched_init
218 #undef TARGET_SCHED_REORDER
219 #define TARGET_SCHED_REORDER sparc_sched_reorder
221 struct gcc_target targetm = TARGET_INITIALIZER;
223 /* Validate and override various options, and do some machine dependent
227 sparc_override_options ()
229 static struct code_model {
230 const char *const name;
232 } const cmodels[] = {
234 { "medlow", CM_MEDLOW },
235 { "medmid", CM_MEDMID },
236 { "medany", CM_MEDANY },
237 { "embmedany", CM_EMBMEDANY },
240 const struct code_model *cmodel;
241 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
242 static struct cpu_default {
244 const char *const name;
245 } const cpu_default[] = {
246 /* There must be one entry here for each TARGET_CPU value. */
247 { TARGET_CPU_sparc, "cypress" },
248 { TARGET_CPU_sparclet, "tsc701" },
249 { TARGET_CPU_sparclite, "f930" },
250 { TARGET_CPU_v8, "v8" },
251 { TARGET_CPU_hypersparc, "hypersparc" },
252 { TARGET_CPU_sparclite86x, "sparclite86x" },
253 { TARGET_CPU_supersparc, "supersparc" },
254 { TARGET_CPU_v9, "v9" },
255 { TARGET_CPU_ultrasparc, "ultrasparc" },
258 const struct cpu_default *def;
259 /* Table of values for -m{cpu,tune}=. */
260 static struct cpu_table {
261 const char *const name;
262 const enum processor_type processor;
265 } const cpu_table[] = {
266 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
267 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
268 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
269 /* TI TMS390Z55 supersparc */
270 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
271 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
272 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
273 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
274 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
275 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
276 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
277 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
279 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
281 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
282 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
283 /* TI ultrasparc I, II, IIi */
284 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
285 /* Although insns using %y are deprecated, it is a clear win on current
287 |MASK_DEPRECATED_V8_INSNS},
290 const struct cpu_table *cpu;
291 const struct sparc_cpu_select *sel;
294 #ifndef SPARC_BI_ARCH
295 /* Check for unsupported architecture size. */
296 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
297 error ("%s is not supported by this configuration",
298 DEFAULT_ARCH32_P ? "-m64" : "-m32");
301 /* We force all 64bit archs to use 128 bit long double */
302 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
304 error ("-mlong-double-64 not allowed with -m64");
305 target_flags |= MASK_LONG_DOUBLE_128;
308 /* Code model selection. */
309 sparc_cmodel = SPARC_DEFAULT_CMODEL;
313 sparc_cmodel = CM_32;
316 if (sparc_cmodel_string != NULL)
320 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
321 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
323 if (cmodel->name == NULL)
324 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
326 sparc_cmodel = cmodel->value;
329 error ("-mcmodel= is not supported on 32 bit systems");
332 fpu = TARGET_FPU; /* save current -mfpu status */
334 /* Set the default CPU. */
335 for (def = &cpu_default[0]; def->name; ++def)
336 if (def->cpu == TARGET_CPU_DEFAULT)
340 sparc_select[0].string = def->name;
342 for (sel = &sparc_select[0]; sel->name; ++sel)
346 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
347 if (! strcmp (sel->string, cpu->name))
350 sparc_cpu = cpu->processor;
354 target_flags &= ~cpu->disable;
355 target_flags |= cpu->enable;
361 error ("bad value (%s) for %s switch", sel->string, sel->name);
365 /* If -mfpu or -mno-fpu was explicitly used, don't override with
366 the processor default. Clear MASK_FPU_SET to avoid confusing
367 the reverse mapping from switch values to names. */
370 target_flags = (target_flags & ~MASK_FPU) | fpu;
371 target_flags &= ~MASK_FPU_SET;
374 /* Don't allow -mvis if FPU is disabled. */
376 target_flags &= ~MASK_VIS;
378 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
380 -m64 also implies v9. */
381 if (TARGET_VIS || TARGET_ARCH64)
382 target_flags |= MASK_V9;
384 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
385 if (TARGET_V9 && TARGET_ARCH32)
386 target_flags |= MASK_DEPRECATED_V8_INSNS;
388 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
389 if (! TARGET_V9 || TARGET_ARCH64)
390 target_flags &= ~MASK_V8PLUS;
392 /* Don't use stack biasing in 32 bit mode. */
394 target_flags &= ~MASK_STACK_BIAS;
396 /* Supply a default value for align_functions. */
397 if (align_functions == 0 && sparc_cpu == PROCESSOR_ULTRASPARC)
398 align_functions = 32;
400 /* Validate PCC_STRUCT_RETURN. */
401 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
402 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
404 /* Do various machine dependent initializations. */
408 && sparc_cmodel != CM_32 && sparc_cmodel != CM_MEDLOW)
410 error ("profiling does not support code models other than medlow");
413 /* Register global variables with the garbage collector. */
414 sparc_add_gc_roots ();
417 /* Miscellaneous utilities. */
419 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
420 or branch on register contents instructions. */
426 return (code == EQ || code == NE || code == GE || code == LT
427 || code == LE || code == GT);
431 /* Operand constraints. */
433 /* Return non-zero only if OP is a register of mode MODE,
437 reg_or_0_operand (op, mode)
439 enum machine_mode mode;
441 if (register_operand (op, mode))
443 if (op == const0_rtx)
445 if (GET_MODE (op) == VOIDmode && GET_CODE (op) == CONST_DOUBLE
446 && CONST_DOUBLE_HIGH (op) == 0
447 && CONST_DOUBLE_LOW (op) == 0)
449 if (fp_zero_operand (op, mode))
454 /* Nonzero if OP is a floating point value with value 0.0. */
457 fp_zero_operand (op, mode)
459 enum machine_mode mode;
461 if (GET_MODE_CLASS (GET_MODE (op)) != MODE_FLOAT)
463 return op == CONST0_RTX (mode);
466 /* Nonzero if OP is a floating point constant which can
467 be loaded into an integer register using a single
468 sethi instruction. */
474 if (GET_CODE (op) == CONST_DOUBLE)
479 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
480 if (REAL_VALUES_EQUAL (r, dconst0) &&
481 ! REAL_VALUE_MINUS_ZERO (r))
483 REAL_VALUE_TO_TARGET_SINGLE (r, i);
484 if (SPARC_SETHI_P (i))
491 /* Nonzero if OP is a floating point constant which can
492 be loaded into an integer register using a single
499 if (GET_CODE (op) == CONST_DOUBLE)
504 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
505 if (REAL_VALUES_EQUAL (r, dconst0) &&
506 ! REAL_VALUE_MINUS_ZERO (r))
508 REAL_VALUE_TO_TARGET_SINGLE (r, i);
509 if (SPARC_SIMM13_P (i))
516 /* Nonzero if OP is a floating point constant which can
517 be loaded into an integer register using a high/losum
518 instruction sequence. */
524 /* The constraints calling this should only be in
525 SFmode move insns, so any constant which cannot
526 be moved using a single insn will do. */
527 if (GET_CODE (op) == CONST_DOUBLE)
532 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
533 if (REAL_VALUES_EQUAL (r, dconst0) &&
534 ! REAL_VALUE_MINUS_ZERO (r))
536 REAL_VALUE_TO_TARGET_SINGLE (r, i);
537 if (! SPARC_SETHI_P (i)
538 && ! SPARC_SIMM13_P (i))
545 /* Nonzero if OP is an integer register. */
548 intreg_operand (op, mode)
550 enum machine_mode mode ATTRIBUTE_UNUSED;
552 return (register_operand (op, SImode)
553 || (TARGET_ARCH64 && register_operand (op, DImode)));
556 /* Nonzero if OP is a floating point condition code register. */
559 fcc_reg_operand (op, mode)
561 enum machine_mode mode;
563 /* This can happen when recog is called from combine. Op may be a MEM.
564 Fail instead of calling abort in this case. */
565 if (GET_CODE (op) != REG)
568 if (mode != VOIDmode && mode != GET_MODE (op))
571 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
574 #if 0 /* ??? ==> 1 when %fcc0-3 are pseudos first. See gen_compare_reg(). */
575 if (reg_renumber == 0)
576 return REGNO (op) >= FIRST_PSEUDO_REGISTER;
577 return REGNO_OK_FOR_CCFP_P (REGNO (op));
579 return (unsigned) REGNO (op) - SPARC_FIRST_V9_FCC_REG < 4;
583 /* Nonzero if OP is an integer or floating point condition code register. */
586 icc_or_fcc_reg_operand (op, mode)
588 enum machine_mode mode;
590 if (GET_CODE (op) == REG && REGNO (op) == SPARC_ICC_REG)
592 if (mode != VOIDmode && mode != GET_MODE (op))
595 && GET_MODE (op) != CCmode && GET_MODE (op) != CCXmode)
600 return fcc_reg_operand (op, mode);
603 /* Nonzero if OP can appear as the dest of a RESTORE insn. */
605 restore_operand (op, mode)
607 enum machine_mode mode;
609 return (GET_CODE (op) == REG && GET_MODE (op) == mode
610 && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32)));
613 /* Call insn on SPARC can take a PC-relative constant address, or any regular
617 call_operand (op, mode)
619 enum machine_mode mode;
621 if (GET_CODE (op) != MEM)
624 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
628 call_operand_address (op, mode)
630 enum machine_mode mode;
632 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
635 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
636 reference and a constant. */
639 symbolic_operand (op, mode)
641 enum machine_mode mode;
643 enum machine_mode omode = GET_MODE (op);
645 if (omode != mode && omode != VOIDmode && mode != VOIDmode)
648 switch (GET_CODE (op))
656 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
657 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
658 && GET_CODE (XEXP (op, 1)) == CONST_INT);
665 /* Return truth value of statement that OP is a symbolic memory
666 operand of mode MODE. */
669 symbolic_memory_operand (op, mode)
671 enum machine_mode mode ATTRIBUTE_UNUSED;
673 if (GET_CODE (op) == SUBREG)
674 op = SUBREG_REG (op);
675 if (GET_CODE (op) != MEM)
678 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
679 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
682 /* Return truth value of statement that OP is a LABEL_REF of mode MODE. */
685 label_ref_operand (op, mode)
687 enum machine_mode mode;
689 if (GET_CODE (op) != LABEL_REF)
691 if (GET_MODE (op) != mode)
696 /* Return 1 if the operand is an argument used in generating pic references
697 in either the medium/low or medium/anywhere code models of sparc64. */
700 sp64_medium_pic_operand (op, mode)
702 enum machine_mode mode ATTRIBUTE_UNUSED;
704 /* Check for (const (minus (symbol_ref:GOT)
705 (const (minus (label) (pc))))). */
706 if (GET_CODE (op) != CONST)
709 if (GET_CODE (op) != MINUS)
711 if (GET_CODE (XEXP (op, 0)) != SYMBOL_REF)
713 /* ??? Ensure symbol is GOT. */
714 if (GET_CODE (XEXP (op, 1)) != CONST)
716 if (GET_CODE (XEXP (XEXP (op, 1), 0)) != MINUS)
721 /* Return 1 if the operand is a data segment reference. This includes
722 the readonly data segment, or in other words anything but the text segment.
723 This is needed in the medium/anywhere code model on v9. These values
724 are accessed with EMBMEDANY_BASE_REG. */
727 data_segment_operand (op, mode)
729 enum machine_mode mode ATTRIBUTE_UNUSED;
731 switch (GET_CODE (op))
734 return ! SYMBOL_REF_FLAG (op);
736 /* Assume canonical format of symbol + constant.
739 return data_segment_operand (XEXP (op, 0), VOIDmode);
745 /* Return 1 if the operand is a text segment reference.
746 This is needed in the medium/anywhere code model on v9. */
749 text_segment_operand (op, mode)
751 enum machine_mode mode ATTRIBUTE_UNUSED;
753 switch (GET_CODE (op))
758 return SYMBOL_REF_FLAG (op);
760 /* Assume canonical format of symbol + constant.
763 return text_segment_operand (XEXP (op, 0), VOIDmode);
769 /* Return 1 if the operand is either a register or a memory operand that is
773 reg_or_nonsymb_mem_operand (op, mode)
775 enum machine_mode mode;
777 if (register_operand (op, mode))
780 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
787 splittable_symbolic_memory_operand (op, mode)
789 enum machine_mode mode ATTRIBUTE_UNUSED;
791 if (GET_CODE (op) != MEM)
793 if (! symbolic_operand (XEXP (op, 0), Pmode))
799 splittable_immediate_memory_operand (op, mode)
801 enum machine_mode mode ATTRIBUTE_UNUSED;
803 if (GET_CODE (op) != MEM)
805 if (! immediate_operand (XEXP (op, 0), Pmode))
810 /* Return truth value of whether OP is EQ or NE. */
815 enum machine_mode mode ATTRIBUTE_UNUSED;
817 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
820 /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
821 or LTU for non-floating-point. We handle those specially. */
824 normal_comp_operator (op, mode)
826 enum machine_mode mode ATTRIBUTE_UNUSED;
828 enum rtx_code code = GET_CODE (op);
830 if (GET_RTX_CLASS (code) != '<')
833 if (GET_MODE (XEXP (op, 0)) == CCFPmode
834 || GET_MODE (XEXP (op, 0)) == CCFPEmode)
837 return (code != NE && code != EQ && code != GEU && code != LTU);
840 /* Return 1 if this is a comparison operator. This allows the use of
841 MATCH_OPERATOR to recognize all the branch insns. */
844 noov_compare_op (op, mode)
846 enum machine_mode mode ATTRIBUTE_UNUSED;
848 enum rtx_code code = GET_CODE (op);
850 if (GET_RTX_CLASS (code) != '<')
853 if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode)
854 /* These are the only branches which work with CC_NOOVmode. */
855 return (code == EQ || code == NE || code == GE || code == LT);
859 /* Nonzero if OP is a comparison operator suitable for use in v9
860 conditional move or branch on register contents instructions. */
863 v9_regcmp_op (op, mode)
865 enum machine_mode mode ATTRIBUTE_UNUSED;
867 enum rtx_code code = GET_CODE (op);
869 if (GET_RTX_CLASS (code) != '<')
872 return v9_regcmp_p (code);
875 /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */
880 enum machine_mode mode ATTRIBUTE_UNUSED;
882 return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
885 /* Return nonzero if OP is an operator of mode MODE which can set
886 the condition codes explicitly. We do not include PLUS and MINUS
887 because these require CC_NOOVmode, which we handle explicitly. */
890 cc_arithop (op, mode)
892 enum machine_mode mode ATTRIBUTE_UNUSED;
894 if (GET_CODE (op) == AND
895 || GET_CODE (op) == IOR
896 || GET_CODE (op) == XOR)
902 /* Return nonzero if OP is an operator of mode MODE which can bitwise
903 complement its second operand and set the condition codes explicitly. */
906 cc_arithopn (op, mode)
908 enum machine_mode mode ATTRIBUTE_UNUSED;
910 /* XOR is not here because combine canonicalizes (xor (not ...) ...)
911 and (xor ... (not ...)) to (not (xor ...)). */
912 return (GET_CODE (op) == AND
913 || GET_CODE (op) == IOR);
916 /* Return true if OP is a register, or is a CONST_INT that can fit in a
917 signed 13 bit immediate field. This is an acceptable SImode operand for
918 most 3 address instructions. */
921 arith_operand (op, mode)
923 enum machine_mode mode;
926 if (register_operand (op, mode))
928 if (GET_CODE (op) != CONST_INT)
930 val = INTVAL (op) & 0xffffffff;
931 return SPARC_SIMM13_P (val);
934 /* Return true if OP is a constant 4096 */
937 arith_4096_operand (op, mode)
939 enum machine_mode mode ATTRIBUTE_UNUSED;
942 if (GET_CODE (op) != CONST_INT)
944 val = INTVAL (op) & 0xffffffff;
948 /* Return true if OP is suitable as second operand for add/sub */
951 arith_add_operand (op, mode)
953 enum machine_mode mode;
955 return arith_operand (op, mode) || arith_4096_operand (op, mode);
958 /* Return true if OP is a CONST_INT or a CONST_DOUBLE which can fit in the
959 immediate field of OR and XOR instructions. Used for 64-bit
960 constant formation patterns. */
962 const64_operand (op, mode)
964 enum machine_mode mode ATTRIBUTE_UNUSED;
966 return ((GET_CODE (op) == CONST_INT
967 && SPARC_SIMM13_P (INTVAL (op)))
968 #if HOST_BITS_PER_WIDE_INT != 64
969 || (GET_CODE (op) == CONST_DOUBLE
970 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
971 && (CONST_DOUBLE_HIGH (op) ==
972 ((CONST_DOUBLE_LOW (op) & 0x80000000) != 0 ?
973 (HOST_WIDE_INT)0xffffffff : 0)))
978 /* The same, but only for sethi instructions. */
980 const64_high_operand (op, mode)
982 enum machine_mode mode ATTRIBUTE_UNUSED;
984 return ((GET_CODE (op) == CONST_INT
985 && (INTVAL (op) & 0xfffffc00) != 0
986 && SPARC_SETHI_P (INTVAL (op))
987 #if HOST_BITS_PER_WIDE_INT != 64
988 /* Must be positive on non-64bit host else the
989 optimizer is fooled into thinking that sethi
990 sign extends, even though it does not. */
994 || (GET_CODE (op) == CONST_DOUBLE
995 && CONST_DOUBLE_HIGH (op) == 0
996 && (CONST_DOUBLE_LOW (op) & 0xfffffc00) != 0
997 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op))));
1000 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1001 signed 11 bit immediate field. This is an acceptable SImode operand for
1002 the movcc instructions. */
1005 arith11_operand (op, mode)
1007 enum machine_mode mode;
1009 return (register_operand (op, mode)
1010 || (GET_CODE (op) == CONST_INT && SPARC_SIMM11_P (INTVAL (op))));
1013 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1014 signed 10 bit immediate field. This is an acceptable SImode operand for
1015 the movrcc instructions. */
1018 arith10_operand (op, mode)
1020 enum machine_mode mode;
1022 return (register_operand (op, mode)
1023 || (GET_CODE (op) == CONST_INT && SPARC_SIMM10_P (INTVAL (op))));
1026 /* Return true if OP is a register, is a CONST_INT that fits in a 13 bit
1027 immediate field, or is a CONST_DOUBLE whose both parts fit in a 13 bit
1029 v9: Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1030 can fit in a 13 bit immediate field. This is an acceptable DImode operand
1031 for most 3 address instructions. */
1034 arith_double_operand (op, mode)
1036 enum machine_mode mode;
1038 return (register_operand (op, mode)
1039 || (GET_CODE (op) == CONST_INT && SMALL_INT (op))
1041 && GET_CODE (op) == CONST_DOUBLE
1042 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1043 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_HIGH (op) + 0x1000) < 0x2000)
1045 && GET_CODE (op) == CONST_DOUBLE
1046 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1047 && ((CONST_DOUBLE_HIGH (op) == -1
1048 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
1049 || (CONST_DOUBLE_HIGH (op) == 0
1050 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
1053 /* Return true if OP is a constant 4096 for DImode on ARCH64 */
1056 arith_double_4096_operand (op, mode)
1058 enum machine_mode mode ATTRIBUTE_UNUSED;
1060 return (TARGET_ARCH64 &&
1061 ((GET_CODE (op) == CONST_INT && INTVAL (op) == 4096) ||
1062 (GET_CODE (op) == CONST_DOUBLE &&
1063 CONST_DOUBLE_LOW (op) == 4096 &&
1064 CONST_DOUBLE_HIGH (op) == 0)));
1067 /* Return true if OP is suitable as second operand for add/sub in DImode */
1070 arith_double_add_operand (op, mode)
1072 enum machine_mode mode;
1074 return arith_double_operand (op, mode) || arith_double_4096_operand (op, mode);
1077 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1078 can fit in an 11 bit immediate field. This is an acceptable DImode
1079 operand for the movcc instructions. */
1080 /* ??? Replace with arith11_operand? */
1083 arith11_double_operand (op, mode)
1085 enum machine_mode mode;
1087 return (register_operand (op, mode)
1088 || (GET_CODE (op) == CONST_DOUBLE
1089 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1090 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x400) < 0x800
1091 && ((CONST_DOUBLE_HIGH (op) == -1
1092 && (CONST_DOUBLE_LOW (op) & 0x400) == 0x400)
1093 || (CONST_DOUBLE_HIGH (op) == 0
1094 && (CONST_DOUBLE_LOW (op) & 0x400) == 0)))
1095 || (GET_CODE (op) == CONST_INT
1096 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1097 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x400) < 0x800));
1100 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1101 can fit in an 10 bit immediate field. This is an acceptable DImode
1102 operand for the movrcc instructions. */
1103 /* ??? Replace with arith10_operand? */
1106 arith10_double_operand (op, mode)
1108 enum machine_mode mode;
1110 return (register_operand (op, mode)
1111 || (GET_CODE (op) == CONST_DOUBLE
1112 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1113 && (unsigned) (CONST_DOUBLE_LOW (op) + 0x200) < 0x400
1114 && ((CONST_DOUBLE_HIGH (op) == -1
1115 && (CONST_DOUBLE_LOW (op) & 0x200) == 0x200)
1116 || (CONST_DOUBLE_HIGH (op) == 0
1117 && (CONST_DOUBLE_LOW (op) & 0x200) == 0)))
1118 || (GET_CODE (op) == CONST_INT
1119 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1120 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x200) < 0x400));
1123 /* Return truth value of whether OP is an integer which fits the
1124 range constraining immediate operands in most three-address insns,
1125 which have a 13 bit immediate field. */
1128 small_int (op, mode)
1130 enum machine_mode mode ATTRIBUTE_UNUSED;
1132 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
1136 small_int_or_double (op, mode)
1138 enum machine_mode mode ATTRIBUTE_UNUSED;
1140 return ((GET_CODE (op) == CONST_INT && SMALL_INT (op))
1141 || (GET_CODE (op) == CONST_DOUBLE
1142 && CONST_DOUBLE_HIGH (op) == 0
1143 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))));
1146 /* Recognize operand values for the umul instruction. That instruction sign
1147 extends immediate values just like all other sparc instructions, but
1148 interprets the extended result as an unsigned number. */
1151 uns_small_int (op, mode)
1153 enum machine_mode mode ATTRIBUTE_UNUSED;
1155 #if HOST_BITS_PER_WIDE_INT > 32
1156 /* All allowed constants will fit a CONST_INT. */
1157 return (GET_CODE (op) == CONST_INT
1158 && ((INTVAL (op) >= 0 && INTVAL (op) < 0x1000)
1159 || (INTVAL (op) >= 0xFFFFF000
1160 && INTVAL (op) <= 0xFFFFFFFF)));
1162 return ((GET_CODE (op) == CONST_INT && (unsigned) INTVAL (op) < 0x1000)
1163 || (GET_CODE (op) == CONST_DOUBLE
1164 && CONST_DOUBLE_HIGH (op) == 0
1165 && (unsigned) CONST_DOUBLE_LOW (op) - 0xFFFFF000 < 0x1000));
1170 uns_arith_operand (op, mode)
1172 enum machine_mode mode;
1174 return register_operand (op, mode) || uns_small_int (op, mode);
1177 /* Return truth value of statement that OP is a call-clobbered register. */
1179 clobbered_register (op, mode)
1181 enum machine_mode mode ATTRIBUTE_UNUSED;
1183 return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
1186 /* Return 1 if OP is a valid operand for the source of a move insn. */
1189 input_operand (op, mode)
1191 enum machine_mode mode;
1193 /* If both modes are non-void they must be the same. */
1194 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1197 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1198 if (GET_CODE (op) == CONST && GET_CODE (XEXP (op, 0)) == CONSTANT_P_RTX)
1201 /* Allow any one instruction integer constant, and all CONST_INT
1202 variants when we are working in DImode and !arch64. */
1203 if (GET_MODE_CLASS (mode) == MODE_INT
1204 && ((GET_CODE (op) == CONST_INT
1205 && ((SPARC_SETHI_P (INTVAL (op))
1207 || (INTVAL (op) >= 0)
1211 || SPARC_SIMM13_P (INTVAL (op))
1213 && ! TARGET_ARCH64)))
1215 && GET_CODE (op) == CONST_DOUBLE
1216 && ((CONST_DOUBLE_HIGH (op) == 0
1217 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op)))
1219 #if HOST_BITS_PER_WIDE_INT == 64
1220 (CONST_DOUBLE_HIGH (op) == 0
1221 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op)))
1223 (SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1224 && (((CONST_DOUBLE_LOW (op) & 0x80000000) == 0
1225 && CONST_DOUBLE_HIGH (op) == 0)
1226 || (CONST_DOUBLE_HIGH (op) == -1
1227 && CONST_DOUBLE_LOW (op) & 0x80000000) != 0))
1232 /* If !arch64 and this is a DImode const, allow it so that
1233 the splits can be generated. */
1236 && GET_CODE (op) == CONST_DOUBLE)
1239 if (register_operand (op, mode))
1242 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1243 && GET_CODE (op) == CONST_DOUBLE)
1246 /* If this is a SUBREG, look inside so that we handle
1247 paradoxical ones. */
1248 if (GET_CODE (op) == SUBREG)
1249 op = SUBREG_REG (op);
1251 /* Check for valid MEM forms. */
1252 if (GET_CODE (op) == MEM)
1254 rtx inside = XEXP (op, 0);
1256 if (GET_CODE (inside) == LO_SUM)
1258 /* We can't allow these because all of the splits
1259 (eventually as they trickle down into DFmode
1260 splits) require offsettable memory references. */
1262 && GET_MODE (op) == TFmode)
1265 return (register_operand (XEXP (inside, 0), Pmode)
1266 && CONSTANT_P (XEXP (inside, 1)));
1268 return memory_address_p (mode, inside);
1275 /* We know it can't be done in one insn when we get here,
1276 the movsi expander guarentees this. */
1278 sparc_emit_set_const32 (op0, op1)
1282 enum machine_mode mode = GET_MODE (op0);
1285 if (GET_CODE (op1) == CONST_INT)
1287 HOST_WIDE_INT value = INTVAL (op1);
1289 if (SPARC_SETHI_P (value)
1290 || SPARC_SIMM13_P (value))
1294 /* Full 2-insn decomposition is needed. */
1295 if (reload_in_progress || reload_completed)
1298 temp = gen_reg_rtx (mode);
1300 if (GET_CODE (op1) == CONST_INT)
1302 /* Emit them as real moves instead of a HIGH/LO_SUM,
1303 this way CSE can see everything and reuse intermediate
1304 values if it wants. */
1306 && HOST_BITS_PER_WIDE_INT != 64
1307 && (INTVAL (op1) & 0x80000000) != 0)
1308 emit_insn (gen_rtx_SET
1310 gen_rtx_CONST_DOUBLE (VOIDmode, INTVAL (op1) & 0xfffffc00,
1313 emit_insn (gen_rtx_SET (VOIDmode, temp,
1314 GEN_INT (INTVAL (op1) & 0xfffffc00)));
1316 emit_insn (gen_rtx_SET (VOIDmode,
1318 gen_rtx_IOR (mode, temp,
1319 GEN_INT (INTVAL (op1) & 0x3ff))));
1323 /* A symbol, emit in the traditional way. */
1324 emit_insn (gen_rtx_SET (VOIDmode, temp,
1325 gen_rtx_HIGH (mode, op1)));
1326 emit_insn (gen_rtx_SET (VOIDmode,
1327 op0, gen_rtx_LO_SUM (mode, temp, op1)));
1333 /* Sparc-v9 code-model support. */
1335 sparc_emit_set_symbolic_const64 (op0, op1, temp1)
1340 switch (sparc_cmodel)
1343 /* The range spanned by all instructions in the object is less
1344 than 2^31 bytes (2GB) and the distance from any instruction
1345 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1346 than 2^31 bytes (2GB).
1348 The executable must be in the low 4TB of the virtual address
1351 sethi %hi(symbol), %temp
1352 or %temp, %lo(symbol), %reg */
1353 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1354 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1358 /* The range spanned by all instructions in the object is less
1359 than 2^31 bytes (2GB) and the distance from any instruction
1360 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1361 than 2^31 bytes (2GB).
1363 The executable must be in the low 16TB of the virtual address
1366 sethi %h44(symbol), %temp1
1367 or %temp1, %m44(symbol), %temp2
1368 sllx %temp2, 12, %temp3
1369 or %temp3, %l44(symbol), %reg */
1370 emit_insn (gen_seth44 (op0, op1));
1371 emit_insn (gen_setm44 (op0, op0, op1));
1372 emit_insn (gen_rtx_SET (VOIDmode, temp1,
1373 gen_rtx_ASHIFT (DImode, op0, GEN_INT (12))));
1374 emit_insn (gen_setl44 (op0, temp1, op1));
1378 /* The range spanned by all instructions in the object is less
1379 than 2^31 bytes (2GB) and the distance from any instruction
1380 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1381 than 2^31 bytes (2GB).
1383 The executable can be placed anywhere in the virtual address
1386 sethi %hh(symbol), %temp1
1387 sethi %lm(symbol), %temp2
1388 or %temp1, %hm(symbol), %temp3
1389 or %temp2, %lo(symbol), %temp4
1390 sllx %temp3, 32, %temp5
1391 or %temp4, %temp5, %reg */
1393 /* Getting this right wrt. reloading is really tricky.
1394 We _MUST_ have a separate temporary at this point,
1395 if we don't barf immediately instead of generating
1400 emit_insn (gen_sethh (op0, op1));
1401 emit_insn (gen_setlm (temp1, op1));
1402 emit_insn (gen_sethm (op0, op0, op1));
1403 emit_insn (gen_rtx_SET (VOIDmode, op0,
1404 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1405 emit_insn (gen_rtx_SET (VOIDmode, op0,
1406 gen_rtx_PLUS (DImode, op0, temp1)));
1407 emit_insn (gen_setlo (op0, op0, op1));
1411 /* Old old old backwards compatibility kruft here.
1412 Essentially it is MEDLOW with a fixed 64-bit
1413 virtual base added to all data segment addresses.
1414 Text-segment stuff is computed like MEDANY, we can't
1415 reuse the code above because the relocation knobs
1418 Data segment: sethi %hi(symbol), %temp1
1419 or %temp1, %lo(symbol), %temp2
1420 add %temp2, EMBMEDANY_BASE_REG, %reg
1422 Text segment: sethi %uhi(symbol), %temp1
1423 sethi %hi(symbol), %temp2
1424 or %temp1, %ulo(symbol), %temp3
1425 or %temp2, %lo(symbol), %temp4
1426 sllx %temp3, 32, %temp5
1427 or %temp4, %temp5, %reg */
1428 if (data_segment_operand (op1, GET_MODE (op1)))
1430 emit_insn (gen_embmedany_sethi (temp1, op1));
1431 emit_insn (gen_embmedany_brsum (op0, temp1));
1432 emit_insn (gen_embmedany_losum (op0, op0, op1));
1436 /* Getting this right wrt. reloading is really tricky.
1437 We _MUST_ have a separate temporary at this point,
1438 so we barf immediately instead of generating
1443 emit_insn (gen_embmedany_textuhi (op0, op1));
1444 emit_insn (gen_embmedany_texthi (temp1, op1));
1445 emit_insn (gen_embmedany_textulo (op0, op0, op1));
1446 emit_insn (gen_rtx_SET (VOIDmode, op0,
1447 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1448 emit_insn (gen_rtx_SET (VOIDmode, op0,
1449 gen_rtx_PLUS (DImode, op0, temp1)));
1450 emit_insn (gen_embmedany_textlo (op0, op0, op1));
1459 /* These avoid problems when cross compiling. If we do not
1460 go through all this hair then the optimizer will see
1461 invalid REG_EQUAL notes or in some cases none at all. */
1462 static void sparc_emit_set_safe_HIGH64 PARAMS ((rtx, HOST_WIDE_INT));
1463 static rtx gen_safe_SET64 PARAMS ((rtx, HOST_WIDE_INT));
1464 static rtx gen_safe_OR64 PARAMS ((rtx, HOST_WIDE_INT));
1465 static rtx gen_safe_XOR64 PARAMS ((rtx, HOST_WIDE_INT));
1467 #if HOST_BITS_PER_WIDE_INT == 64
1468 #define GEN_HIGHINT64(__x) GEN_INT ((__x) & 0xfffffc00)
1469 #define GEN_INT64(__x) GEN_INT (__x)
1471 #define GEN_HIGHINT64(__x) \
1472 gen_rtx_CONST_DOUBLE (VOIDmode, (__x) & 0xfffffc00, 0)
1473 #define GEN_INT64(__x) \
1474 gen_rtx_CONST_DOUBLE (VOIDmode, (__x) & 0xffffffff, \
1475 ((__x) & 0x80000000 \
1479 /* The optimizer is not to assume anything about exactly
1480 which bits are set for a HIGH, they are unspecified.
1481 Unfortunately this leads to many missed optimizations
1482 during CSE. We mask out the non-HIGH bits, and matches
1483 a plain movdi, to alleviate this problem. */
1485 sparc_emit_set_safe_HIGH64 (dest, val)
1489 emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_HIGHINT64 (val)));
1493 gen_safe_SET64 (dest, val)
1497 return gen_rtx_SET (VOIDmode, dest, GEN_INT64 (val));
1501 gen_safe_OR64 (src, val)
1505 return gen_rtx_IOR (DImode, src, GEN_INT64 (val));
1509 gen_safe_XOR64 (src, val)
1513 return gen_rtx_XOR (DImode, src, GEN_INT64 (val));
1516 /* Worker routines for 64-bit constant formation on arch64.
1517 One of the key things to be doing in these emissions is
1518 to create as many temp REGs as possible. This makes it
1519 possible for half-built constants to be used later when
1520 such values are similar to something required later on.
1521 Without doing this, the optimizer cannot see such
1524 static void sparc_emit_set_const64_quick1
1525 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, int));
1528 sparc_emit_set_const64_quick1 (op0, temp, low_bits, is_neg)
1531 unsigned HOST_WIDE_INT low_bits;
1534 unsigned HOST_WIDE_INT high_bits;
1537 high_bits = (~low_bits) & 0xffffffff;
1539 high_bits = low_bits;
1541 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1544 emit_insn (gen_rtx_SET (VOIDmode, op0,
1545 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1549 /* If we are XOR'ing with -1, then we should emit a one's complement
1550 instead. This way the combiner will notice logical operations
1551 such as ANDN later on and substitute. */
1552 if ((low_bits & 0x3ff) == 0x3ff)
1554 emit_insn (gen_rtx_SET (VOIDmode, op0,
1555 gen_rtx_NOT (DImode, temp)));
1559 emit_insn (gen_rtx_SET (VOIDmode, op0,
1560 gen_safe_XOR64 (temp,
1561 (-0x400 | (low_bits & 0x3ff)))));
1566 static void sparc_emit_set_const64_quick2
1567 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT,
1568 unsigned HOST_WIDE_INT, int));
1571 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_immediate, shift_count)
1574 unsigned HOST_WIDE_INT high_bits;
1575 unsigned HOST_WIDE_INT low_immediate;
1580 if ((high_bits & 0xfffffc00) != 0)
1582 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1583 if ((high_bits & ~0xfffffc00) != 0)
1584 emit_insn (gen_rtx_SET (VOIDmode, op0,
1585 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1591 emit_insn (gen_safe_SET64 (temp, high_bits));
1595 /* Now shift it up into place. */
1596 emit_insn (gen_rtx_SET (VOIDmode, op0,
1597 gen_rtx_ASHIFT (DImode, temp2,
1598 GEN_INT (shift_count))));
1600 /* If there is a low immediate part piece, finish up by
1601 putting that in as well. */
1602 if (low_immediate != 0)
1603 emit_insn (gen_rtx_SET (VOIDmode, op0,
1604 gen_safe_OR64 (op0, low_immediate)));
1607 static void sparc_emit_set_const64_longway
1608 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1610 /* Full 64-bit constant decomposition. Even though this is the
1611 'worst' case, we still optimize a few things away. */
1613 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits)
1616 unsigned HOST_WIDE_INT high_bits;
1617 unsigned HOST_WIDE_INT low_bits;
1621 if (reload_in_progress || reload_completed)
1624 sub_temp = gen_reg_rtx (DImode);
1626 if ((high_bits & 0xfffffc00) != 0)
1628 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1629 if ((high_bits & ~0xfffffc00) != 0)
1630 emit_insn (gen_rtx_SET (VOIDmode,
1632 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1638 emit_insn (gen_safe_SET64 (temp, high_bits));
1642 if (!reload_in_progress && !reload_completed)
1644 rtx temp2 = gen_reg_rtx (DImode);
1645 rtx temp3 = gen_reg_rtx (DImode);
1646 rtx temp4 = gen_reg_rtx (DImode);
1648 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1649 gen_rtx_ASHIFT (DImode, sub_temp,
1652 sparc_emit_set_safe_HIGH64 (temp2, low_bits);
1653 if ((low_bits & ~0xfffffc00) != 0)
1655 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1656 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1657 emit_insn (gen_rtx_SET (VOIDmode, op0,
1658 gen_rtx_PLUS (DImode, temp4, temp3)));
1662 emit_insn (gen_rtx_SET (VOIDmode, op0,
1663 gen_rtx_PLUS (DImode, temp4, temp2)));
1668 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1669 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1670 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1673 /* We are in the middle of reload, so this is really
1674 painful. However we do still make an attempt to
1675 avoid emitting truly stupid code. */
1676 if (low1 != const0_rtx)
1678 emit_insn (gen_rtx_SET (VOIDmode, op0,
1679 gen_rtx_ASHIFT (DImode, sub_temp,
1680 GEN_INT (to_shift))));
1681 emit_insn (gen_rtx_SET (VOIDmode, op0,
1682 gen_rtx_IOR (DImode, op0, low1)));
1690 if (low2 != const0_rtx)
1692 emit_insn (gen_rtx_SET (VOIDmode, op0,
1693 gen_rtx_ASHIFT (DImode, sub_temp,
1694 GEN_INT (to_shift))));
1695 emit_insn (gen_rtx_SET (VOIDmode, op0,
1696 gen_rtx_IOR (DImode, op0, low2)));
1704 emit_insn (gen_rtx_SET (VOIDmode, op0,
1705 gen_rtx_ASHIFT (DImode, sub_temp,
1706 GEN_INT (to_shift))));
1707 if (low3 != const0_rtx)
1708 emit_insn (gen_rtx_SET (VOIDmode, op0,
1709 gen_rtx_IOR (DImode, op0, low3)));
1714 /* Analyze a 64-bit constant for certain properties. */
1715 static void analyze_64bit_constant
1716 PARAMS ((unsigned HOST_WIDE_INT,
1717 unsigned HOST_WIDE_INT,
1718 int *, int *, int *));
1721 analyze_64bit_constant (high_bits, low_bits, hbsp, lbsp, abbasp)
1722 unsigned HOST_WIDE_INT high_bits, low_bits;
1723 int *hbsp, *lbsp, *abbasp;
1725 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1728 lowest_bit_set = highest_bit_set = -1;
1732 if ((lowest_bit_set == -1)
1733 && ((low_bits >> i) & 1))
1735 if ((highest_bit_set == -1)
1736 && ((high_bits >> (32 - i - 1)) & 1))
1737 highest_bit_set = (64 - i - 1);
1740 && ((highest_bit_set == -1)
1741 || (lowest_bit_set == -1)));
1747 if ((lowest_bit_set == -1)
1748 && ((high_bits >> i) & 1))
1749 lowest_bit_set = i + 32;
1750 if ((highest_bit_set == -1)
1751 && ((low_bits >> (32 - i - 1)) & 1))
1752 highest_bit_set = 32 - i - 1;
1755 && ((highest_bit_set == -1)
1756 || (lowest_bit_set == -1)));
1758 /* If there are no bits set this should have gone out
1759 as one instruction! */
1760 if (lowest_bit_set == -1
1761 || highest_bit_set == -1)
1763 all_bits_between_are_set = 1;
1764 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1768 if ((low_bits & (1 << i)) != 0)
1773 if ((high_bits & (1 << (i - 32))) != 0)
1776 all_bits_between_are_set = 0;
1779 *hbsp = highest_bit_set;
1780 *lbsp = lowest_bit_set;
1781 *abbasp = all_bits_between_are_set;
1784 static int const64_is_2insns
1785 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1788 const64_is_2insns (high_bits, low_bits)
1789 unsigned HOST_WIDE_INT high_bits, low_bits;
1791 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1794 || high_bits == 0xffffffff)
1797 analyze_64bit_constant (high_bits, low_bits,
1798 &highest_bit_set, &lowest_bit_set,
1799 &all_bits_between_are_set);
1801 if ((highest_bit_set == 63
1802 || lowest_bit_set == 0)
1803 && all_bits_between_are_set != 0)
1806 if ((highest_bit_set - lowest_bit_set) < 21)
1812 static unsigned HOST_WIDE_INT create_simple_focus_bits
1813 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
1816 static unsigned HOST_WIDE_INT
1817 create_simple_focus_bits (high_bits, low_bits, lowest_bit_set, shift)
1818 unsigned HOST_WIDE_INT high_bits, low_bits;
1819 int lowest_bit_set, shift;
1821 HOST_WIDE_INT hi, lo;
1823 if (lowest_bit_set < 32)
1825 lo = (low_bits >> lowest_bit_set) << shift;
1826 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
1831 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
1838 /* Here we are sure to be arch64 and this is an integer constant
1839 being loaded into a register. Emit the most efficient
1840 insn sequence possible. Detection of all the 1-insn cases
1841 has been done already. */
1843 sparc_emit_set_const64 (op0, op1)
1847 unsigned HOST_WIDE_INT high_bits, low_bits;
1848 int lowest_bit_set, highest_bit_set;
1849 int all_bits_between_are_set;
1852 /* Sanity check that we know what we are working with. */
1853 if (! TARGET_ARCH64)
1856 if (GET_CODE (op0) != SUBREG)
1858 if (GET_CODE (op0) != REG
1859 || (REGNO (op0) >= SPARC_FIRST_FP_REG
1860 && REGNO (op0) <= SPARC_LAST_V9_FP_REG))
1864 if (reload_in_progress || reload_completed)
1867 temp = gen_reg_rtx (DImode);
1869 if (GET_CODE (op1) != CONST_DOUBLE
1870 && GET_CODE (op1) != CONST_INT)
1872 sparc_emit_set_symbolic_const64 (op0, op1, temp);
1876 if (GET_CODE (op1) == CONST_DOUBLE)
1878 #if HOST_BITS_PER_WIDE_INT == 64
1879 high_bits = (CONST_DOUBLE_LOW (op1) >> 32) & 0xffffffff;
1880 low_bits = CONST_DOUBLE_LOW (op1) & 0xffffffff;
1882 high_bits = CONST_DOUBLE_HIGH (op1);
1883 low_bits = CONST_DOUBLE_LOW (op1);
1888 #if HOST_BITS_PER_WIDE_INT == 64
1889 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
1890 low_bits = (INTVAL (op1) & 0xffffffff);
1892 high_bits = ((INTVAL (op1) < 0) ?
1895 low_bits = INTVAL (op1);
1899 /* low_bits bits 0 --> 31
1900 high_bits bits 32 --> 63 */
1902 analyze_64bit_constant (high_bits, low_bits,
1903 &highest_bit_set, &lowest_bit_set,
1904 &all_bits_between_are_set);
1906 /* First try for a 2-insn sequence. */
1908 /* These situations are preferred because the optimizer can
1909 * do more things with them:
1911 * sllx %reg, shift, %reg
1913 * srlx %reg, shift, %reg
1914 * 3) mov some_small_const, %reg
1915 * sllx %reg, shift, %reg
1917 if (((highest_bit_set == 63
1918 || lowest_bit_set == 0)
1919 && all_bits_between_are_set != 0)
1920 || ((highest_bit_set - lowest_bit_set) < 12))
1922 HOST_WIDE_INT the_const = -1;
1923 int shift = lowest_bit_set;
1925 if ((highest_bit_set != 63
1926 && lowest_bit_set != 0)
1927 || all_bits_between_are_set == 0)
1930 create_simple_focus_bits (high_bits, low_bits,
1933 else if (lowest_bit_set == 0)
1934 shift = -(63 - highest_bit_set);
1936 if (! SPARC_SIMM13_P (the_const))
1939 emit_insn (gen_safe_SET64 (temp, the_const));
1941 emit_insn (gen_rtx_SET (VOIDmode,
1943 gen_rtx_ASHIFT (DImode,
1947 emit_insn (gen_rtx_SET (VOIDmode,
1949 gen_rtx_LSHIFTRT (DImode,
1951 GEN_INT (-shift))));
1957 /* Now a range of 22 or less bits set somewhere.
1958 * 1) sethi %hi(focus_bits), %reg
1959 * sllx %reg, shift, %reg
1960 * 2) sethi %hi(focus_bits), %reg
1961 * srlx %reg, shift, %reg
1963 if ((highest_bit_set - lowest_bit_set) < 21)
1965 unsigned HOST_WIDE_INT focus_bits =
1966 create_simple_focus_bits (high_bits, low_bits,
1967 lowest_bit_set, 10);
1969 if (! SPARC_SETHI_P (focus_bits))
1972 sparc_emit_set_safe_HIGH64 (temp, focus_bits);
1974 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
1975 if (lowest_bit_set < 10)
1976 emit_insn (gen_rtx_SET (VOIDmode,
1978 gen_rtx_LSHIFTRT (DImode, temp,
1979 GEN_INT (10 - lowest_bit_set))));
1980 else if (lowest_bit_set > 10)
1981 emit_insn (gen_rtx_SET (VOIDmode,
1983 gen_rtx_ASHIFT (DImode, temp,
1984 GEN_INT (lowest_bit_set - 10))));
1990 /* 1) sethi %hi(low_bits), %reg
1991 * or %reg, %lo(low_bits), %reg
1992 * 2) sethi %hi(~low_bits), %reg
1993 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
1996 || high_bits == 0xffffffff)
1998 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
1999 (high_bits == 0xffffffff));
2003 /* Now, try 3-insn sequences. */
2005 /* 1) sethi %hi(high_bits), %reg
2006 * or %reg, %lo(high_bits), %reg
2007 * sllx %reg, 32, %reg
2011 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
2015 /* We may be able to do something quick
2016 when the constant is negated, so try that. */
2017 if (const64_is_2insns ((~high_bits) & 0xffffffff,
2018 (~low_bits) & 0xfffffc00))
2020 /* NOTE: The trailing bits get XOR'd so we need the
2021 non-negated bits, not the negated ones. */
2022 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
2024 if ((((~high_bits) & 0xffffffff) == 0
2025 && ((~low_bits) & 0x80000000) == 0)
2026 || (((~high_bits) & 0xffffffff) == 0xffffffff
2027 && ((~low_bits) & 0x80000000) != 0))
2029 int fast_int = (~low_bits & 0xffffffff);
2031 if ((SPARC_SETHI_P (fast_int)
2032 && (~high_bits & 0xffffffff) == 0)
2033 || SPARC_SIMM13_P (fast_int))
2034 emit_insn (gen_safe_SET64 (temp, fast_int));
2036 sparc_emit_set_const64 (temp, GEN_INT64 (fast_int));
2041 #if HOST_BITS_PER_WIDE_INT == 64
2042 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2043 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2045 negated_const = gen_rtx_CONST_DOUBLE (DImode,
2046 (~low_bits) & 0xfffffc00,
2047 (~high_bits) & 0xffffffff);
2049 sparc_emit_set_const64 (temp, negated_const);
2052 /* If we are XOR'ing with -1, then we should emit a one's complement
2053 instead. This way the combiner will notice logical operations
2054 such as ANDN later on and substitute. */
2055 if (trailing_bits == 0x3ff)
2057 emit_insn (gen_rtx_SET (VOIDmode, op0,
2058 gen_rtx_NOT (DImode, temp)));
2062 emit_insn (gen_rtx_SET (VOIDmode,
2064 gen_safe_XOR64 (temp,
2065 (-0x400 | trailing_bits))));
2070 /* 1) sethi %hi(xxx), %reg
2071 * or %reg, %lo(xxx), %reg
2072 * sllx %reg, yyy, %reg
2074 * ??? This is just a generalized version of the low_bits==0
2075 * thing above, FIXME...
2077 if ((highest_bit_set - lowest_bit_set) < 32)
2079 unsigned HOST_WIDE_INT focus_bits =
2080 create_simple_focus_bits (high_bits, low_bits,
2083 /* We can't get here in this state. */
2084 if (highest_bit_set < 32
2085 || lowest_bit_set >= 32)
2088 /* So what we know is that the set bits straddle the
2089 middle of the 64-bit word. */
2090 sparc_emit_set_const64_quick2 (op0, temp,
2096 /* 1) sethi %hi(high_bits), %reg
2097 * or %reg, %lo(high_bits), %reg
2098 * sllx %reg, 32, %reg
2099 * or %reg, low_bits, %reg
2101 if (SPARC_SIMM13_P(low_bits)
2102 && ((int)low_bits > 0))
2104 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2108 /* The easiest way when all else fails, is full decomposition. */
2110 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
2111 high_bits, low_bits, ~high_bits, ~low_bits);
2113 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2116 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2117 return the mode to be used for the comparison. For floating-point,
2118 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2119 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2120 processing is needed. */
2123 select_cc_mode (op, x, y)
2126 rtx y ATTRIBUTE_UNUSED;
2128 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2154 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2155 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2157 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2158 return CCX_NOOVmode;
2164 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2171 /* X and Y are two things to compare using CODE. Emit the compare insn and
2172 return the rtx for the cc reg in the proper mode. */
2175 gen_compare_reg (code, x, y)
2179 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
2182 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2183 fcc regs (cse can't tell they're really call clobbered regs and will
2184 remove a duplicate comparison even if there is an intervening function
2185 call - it will then try to reload the cc reg via an int reg which is why
2186 we need the movcc patterns). It is possible to provide the movcc
2187 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2188 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2189 to tell cse that CCFPE mode registers (even pseudos) are call
2192 /* ??? This is an experiment. Rather than making changes to cse which may
2193 or may not be easy/clean, we do our own cse. This is possible because
2194 we will generate hard registers. Cse knows they're call clobbered (it
2195 doesn't know the same thing about pseudos). If we guess wrong, no big
2196 deal, but if we win, great! */
2198 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2199 #if 1 /* experiment */
2202 /* We cycle through the registers to ensure they're all exercised. */
2203 static int next_fcc_reg = 0;
2204 /* Previous x,y for each fcc reg. */
2205 static rtx prev_args[4][2];
2207 /* Scan prev_args for x,y. */
2208 for (reg = 0; reg < 4; reg++)
2209 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2214 prev_args[reg][0] = x;
2215 prev_args[reg][1] = y;
2216 next_fcc_reg = (next_fcc_reg + 1) & 3;
2218 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2221 cc_reg = gen_reg_rtx (mode);
2222 #endif /* ! experiment */
2223 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2224 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2226 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2228 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2229 gen_rtx_COMPARE (mode, x, y)));
2234 /* This function is used for v9 only.
2235 CODE is the code for an Scc's comparison.
2236 OPERANDS[0] is the target of the Scc insn.
2237 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
2238 been generated yet).
2240 This function is needed to turn
2243 (gt (reg:CCX 100 %icc)
2247 (gt:DI (reg:CCX 100 %icc)
2250 IE: The instruction recognizer needs to see the mode of the comparison to
2251 find the right instruction. We could use "gt:DI" right in the
2252 define_expand, but leaving it out allows us to handle DI, SI, etc.
2254 We refer to the global sparc compare operands sparc_compare_op0 and
2255 sparc_compare_op1. */
2258 gen_v9_scc (compare_code, operands)
2259 enum rtx_code compare_code;
2260 register rtx *operands;
2265 && (GET_MODE (sparc_compare_op0) == DImode
2266 || GET_MODE (operands[0]) == DImode))
2269 /* Handle the case where operands[0] == sparc_compare_op0.
2270 We "early clobber" the result. */
2271 if (REGNO (operands[0]) == REGNO (sparc_compare_op0))
2273 op0 = gen_reg_rtx (GET_MODE (sparc_compare_op0));
2274 emit_move_insn (op0, sparc_compare_op0);
2277 op0 = sparc_compare_op0;
2278 /* For consistency in the following. */
2279 op1 = sparc_compare_op1;
2281 /* Try to use the movrCC insns. */
2283 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
2284 && op1 == const0_rtx
2285 && v9_regcmp_p (compare_code))
2287 /* Special case for op0 != 0. This can be done with one instruction if
2288 operands[0] == sparc_compare_op0. We don't assume they are equal
2291 if (compare_code == NE
2292 && GET_MODE (operands[0]) == DImode
2293 && GET_MODE (op0) == DImode)
2295 emit_insn (gen_rtx_SET (VOIDmode, operands[0], op0));
2296 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2297 gen_rtx_IF_THEN_ELSE (DImode,
2298 gen_rtx_fmt_ee (compare_code, DImode,
2305 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2306 if (GET_MODE (op0) != DImode)
2308 temp = gen_reg_rtx (DImode);
2309 convert_move (temp, op0, 0);
2313 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2314 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2315 gen_rtx_fmt_ee (compare_code, DImode,
2323 operands[1] = gen_compare_reg (compare_code, op0, op1);
2325 switch (GET_MODE (operands[1]))
2335 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2336 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2337 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2338 gen_rtx_fmt_ee (compare_code,
2339 GET_MODE (operands[1]),
2340 operands[1], const0_rtx),
2341 const1_rtx, operands[0])));
2346 /* Emit a conditional jump insn for the v9 architecture using comparison code
2347 CODE and jump target LABEL.
2348 This function exists to take advantage of the v9 brxx insns. */
2351 emit_v9_brxx_insn (code, op0, label)
2355 emit_jump_insn (gen_rtx_SET (VOIDmode,
2357 gen_rtx_IF_THEN_ELSE (VOIDmode,
2358 gen_rtx_fmt_ee (code, GET_MODE (op0),
2360 gen_rtx_LABEL_REF (VOIDmode, label),
2364 /* Generate a DFmode part of a hard TFmode register.
2365 REG is the TFmode hard register, LOW is 1 for the
2366 low 64bit of the register and 0 otherwise.
2369 gen_df_reg (reg, low)
2373 int regno = REGNO (reg);
2375 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2376 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
2377 return gen_rtx_REG (DFmode, regno);
2380 /* Return nonzero if a return peephole merging return with
2381 setting of output register is ok. */
2383 leaf_return_peephole_ok ()
2385 return (actual_fsize == 0);
2388 /* Return nonzero if TRIAL can go into the function epilogue's
2389 delay slot. SLOT is the slot we are trying to fill. */
2392 eligible_for_epilogue_delay (trial, slot)
2401 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2404 if (get_attr_length (trial) != 1)
2407 /* If there are any call-saved registers, we should scan TRIAL if it
2408 does not reference them. For now just make it easy. */
2412 /* If the function uses __builtin_eh_return, the eh_return machinery
2413 occupies the delay slot. */
2414 if (current_function_calls_eh_return)
2417 /* In the case of a true leaf function, anything can go into the delay slot.
2418 A delay slot only exists however if the frame size is zero, otherwise
2419 we will put an insn to adjust the stack after the return. */
2420 if (current_function_uses_only_leaf_regs)
2422 if (leaf_return_peephole_ok ())
2423 return ((get_attr_in_uncond_branch_delay (trial)
2424 == IN_BRANCH_DELAY_TRUE));
2428 pat = PATTERN (trial);
2430 /* Otherwise, only operations which can be done in tandem with
2431 a `restore' or `return' insn can go into the delay slot. */
2432 if (GET_CODE (SET_DEST (pat)) != REG
2433 || REGNO (SET_DEST (pat)) < 24)
2436 /* If this instruction sets up floating point register and we have a return
2437 instruction, it can probably go in. But restore will not work
2439 if (REGNO (SET_DEST (pat)) >= 32)
2441 if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2442 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2447 /* The set of insns matched here must agree precisely with the set of
2448 patterns paired with a RETURN in sparc.md. */
2450 src = SET_SRC (pat);
2452 /* This matches "*return_[qhs]i" or even "*return_di" on TARGET_ARCH64. */
2453 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2454 && arith_operand (src, GET_MODE (src)))
2457 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2459 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2462 /* This matches "*return_di". */
2463 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2464 && arith_double_operand (src, GET_MODE (src)))
2465 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2467 /* This matches "*return_sf_no_fpu". */
2468 else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode)
2469 && register_operand (src, SFmode))
2472 /* If we have return instruction, anything that does not use
2473 local or output registers and can go into a delay slot wins. */
2474 else if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2475 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2478 /* This matches "*return_addsi". */
2479 else if (GET_CODE (src) == PLUS
2480 && arith_operand (XEXP (src, 0), SImode)
2481 && arith_operand (XEXP (src, 1), SImode)
2482 && (register_operand (XEXP (src, 0), SImode)
2483 || register_operand (XEXP (src, 1), SImode)))
2486 /* This matches "*return_adddi". */
2487 else if (GET_CODE (src) == PLUS
2488 && arith_double_operand (XEXP (src, 0), DImode)
2489 && arith_double_operand (XEXP (src, 1), DImode)
2490 && (register_operand (XEXP (src, 0), DImode)
2491 || register_operand (XEXP (src, 1), DImode)))
2494 /* This can match "*return_losum_[sd]i".
2495 Catch only some cases, so that return_losum* don't have
2497 else if (GET_CODE (src) == LO_SUM
2498 && ! TARGET_CM_MEDMID
2499 && ((register_operand (XEXP (src, 0), SImode)
2500 && immediate_operand (XEXP (src, 1), SImode))
2502 && register_operand (XEXP (src, 0), DImode)
2503 && immediate_operand (XEXP (src, 1), DImode))))
2506 /* sll{,x} reg,1,reg2 is add reg,reg,reg2 as well. */
2507 else if (GET_CODE (src) == ASHIFT
2508 && (register_operand (XEXP (src, 0), SImode)
2509 || register_operand (XEXP (src, 0), DImode))
2510 && XEXP (src, 1) == const1_rtx)
2516 /* Return nonzero if TRIAL can go into the sibling call
2520 eligible_for_sibcall_delay (trial)
2525 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2528 if (get_attr_length (trial) != 1)
2531 pat = PATTERN (trial);
2533 if (current_function_uses_only_leaf_regs)
2535 /* If the tail call is done using the call instruction,
2536 we have to restore %o7 in the delay slot. */
2537 if ((TARGET_ARCH64 && ! TARGET_CM_MEDLOW) || flag_pic)
2540 /* %g1 is used to build the function address */
2541 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
2547 /* Otherwise, only operations which can be done in tandem with
2548 a `restore' insn can go into the delay slot. */
2549 if (GET_CODE (SET_DEST (pat)) != REG
2550 || REGNO (SET_DEST (pat)) < 24
2551 || REGNO (SET_DEST (pat)) >= 32)
2554 /* If it mentions %o7, it can't go in, because sibcall will clobber it
2556 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
2559 src = SET_SRC (pat);
2561 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2562 && arith_operand (src, GET_MODE (src)))
2565 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2567 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2570 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2571 && arith_double_operand (src, GET_MODE (src)))
2572 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2574 else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode)
2575 && register_operand (src, SFmode))
2578 else if (GET_CODE (src) == PLUS
2579 && arith_operand (XEXP (src, 0), SImode)
2580 && arith_operand (XEXP (src, 1), SImode)
2581 && (register_operand (XEXP (src, 0), SImode)
2582 || register_operand (XEXP (src, 1), SImode)))
2585 else if (GET_CODE (src) == PLUS
2586 && arith_double_operand (XEXP (src, 0), DImode)
2587 && arith_double_operand (XEXP (src, 1), DImode)
2588 && (register_operand (XEXP (src, 0), DImode)
2589 || register_operand (XEXP (src, 1), DImode)))
2592 else if (GET_CODE (src) == LO_SUM
2593 && ! TARGET_CM_MEDMID
2594 && ((register_operand (XEXP (src, 0), SImode)
2595 && immediate_operand (XEXP (src, 1), SImode))
2597 && register_operand (XEXP (src, 0), DImode)
2598 && immediate_operand (XEXP (src, 1), DImode))))
2601 else if (GET_CODE (src) == ASHIFT
2602 && (register_operand (XEXP (src, 0), SImode)
2603 || register_operand (XEXP (src, 0), DImode))
2604 && XEXP (src, 1) == const1_rtx)
2611 check_return_regs (x)
2614 switch (GET_CODE (x))
2617 return IN_OR_GLOBAL_P (x);
2632 if (check_return_regs (XEXP (x, 1)) == 0)
2637 return check_return_regs (XEXP (x, 0));
2645 /* Return 1 if TRIAL references only in and global registers. */
2647 eligible_for_return_delay (trial)
2650 if (GET_CODE (PATTERN (trial)) != SET)
2653 return check_return_regs (PATTERN (trial));
2657 short_branch (uid1, uid2)
2660 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
2662 /* Leave a few words of "slop". */
2663 if (delta >= -1023 && delta <= 1022)
2669 /* Return non-zero if REG is not used after INSN.
2670 We assume REG is a reload reg, and therefore does
2671 not live past labels or calls or jumps. */
2673 reg_unused_after (reg, insn)
2677 enum rtx_code code, prev_code = UNKNOWN;
2679 while ((insn = NEXT_INSN (insn)))
2681 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
2684 code = GET_CODE (insn);
2685 if (GET_CODE (insn) == CODE_LABEL)
2688 if (GET_RTX_CLASS (code) == 'i')
2690 rtx set = single_set (insn);
2691 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
2694 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
2696 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
2704 /* The table we use to reference PIC data. */
2705 static rtx global_offset_table;
2707 /* The function we use to get at it. */
2708 static rtx get_pc_symbol;
2709 static char get_pc_symbol_name[256];
2711 /* Ensure that we are not using patterns that are not OK with PIC. */
2720 if (GET_CODE (recog_data.operand[i]) == SYMBOL_REF
2721 || (GET_CODE (recog_data.operand[i]) == CONST
2722 && ! (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
2723 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
2724 == global_offset_table)
2725 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
2734 /* Return true if X is an address which needs a temporary register when
2735 reloaded while generating PIC code. */
2738 pic_address_needs_scratch (x)
2741 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
2742 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2743 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2744 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2745 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
2751 /* Legitimize PIC addresses. If the address is already position-independent,
2752 we return ORIG. Newly generated position-independent addresses go into a
2753 reg. This is REG if non zero, otherwise we allocate register(s) as
2757 legitimize_pic_address (orig, mode, reg)
2759 enum machine_mode mode ATTRIBUTE_UNUSED;
2762 if (GET_CODE (orig) == SYMBOL_REF)
2764 rtx pic_ref, address;
2769 if (reload_in_progress || reload_completed)
2772 reg = gen_reg_rtx (Pmode);
2777 /* If not during reload, allocate another temp reg here for loading
2778 in the address, so that these instructions can be optimized
2780 rtx temp_reg = ((reload_in_progress || reload_completed)
2781 ? reg : gen_reg_rtx (Pmode));
2783 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
2784 won't get confused into thinking that these two instructions
2785 are loading in the true address of the symbol. If in the
2786 future a PIC rtx exists, that should be used instead. */
2787 if (Pmode == SImode)
2789 emit_insn (gen_movsi_high_pic (temp_reg, orig));
2790 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
2794 emit_insn (gen_movdi_high_pic (temp_reg, orig));
2795 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
2802 pic_ref = gen_rtx_MEM (Pmode,
2803 gen_rtx_PLUS (Pmode,
2804 pic_offset_table_rtx, address));
2805 current_function_uses_pic_offset_table = 1;
2806 RTX_UNCHANGING_P (pic_ref) = 1;
2807 insn = emit_move_insn (reg, pic_ref);
2808 /* Put a REG_EQUAL note on this insn, so that it can be optimized
2810 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
2814 else if (GET_CODE (orig) == CONST)
2818 if (GET_CODE (XEXP (orig, 0)) == PLUS
2819 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
2824 if (reload_in_progress || reload_completed)
2827 reg = gen_reg_rtx (Pmode);
2830 if (GET_CODE (XEXP (orig, 0)) == PLUS)
2832 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
2833 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
2834 base == reg ? 0 : reg);
2839 if (GET_CODE (offset) == CONST_INT)
2841 if (SMALL_INT (offset))
2842 return plus_constant (base, INTVAL (offset));
2843 else if (! reload_in_progress && ! reload_completed)
2844 offset = force_reg (Pmode, offset);
2846 /* If we reach here, then something is seriously wrong. */
2849 return gen_rtx_PLUS (Pmode, base, offset);
2851 else if (GET_CODE (orig) == LABEL_REF)
2852 /* ??? Why do we do this? */
2853 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
2854 the register is live instead, in case it is eliminated. */
2855 current_function_uses_pic_offset_table = 1;
2860 /* Emit special PIC prologues. */
2863 load_pic_register ()
2865 /* Labels to get the PC in the prologue of this function. */
2866 int orig_flag_pic = flag_pic;
2871 /* If we haven't emitted the special get_pc helper function, do so now. */
2872 if (get_pc_symbol_name[0] == 0)
2876 ASM_GENERATE_INTERNAL_LABEL (get_pc_symbol_name, "LGETPC", 0);
2879 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
2881 ASM_OUTPUT_ALIGN (asm_out_file, align);
2882 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LGETPC", 0);
2883 fputs ("\tretl\n\tadd\t%o7, %l7, %l7\n", asm_out_file);
2886 /* Initialize every time through, since we can't easily
2887 know this to be permanent. */
2888 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2889 get_pc_symbol = gen_rtx_SYMBOL_REF (Pmode, get_pc_symbol_name);
2892 emit_insn (gen_get_pc (pic_offset_table_rtx, global_offset_table,
2895 flag_pic = orig_flag_pic;
2897 /* Need to emit this whether or not we obey regdecls,
2898 since setjmp/longjmp can cause life info to screw up.
2899 ??? In the case where we don't obey regdecls, this is not sufficient
2900 since we may not fall out the bottom. */
2901 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
2904 /* Return 1 if RTX is a MEM which is known to be aligned to at
2905 least an 8 byte boundary. */
2908 mem_min_alignment (mem, desired)
2912 rtx addr, base, offset;
2914 /* If it's not a MEM we can't accept it. */
2915 if (GET_CODE (mem) != MEM)
2918 addr = XEXP (mem, 0);
2919 base = offset = NULL_RTX;
2920 if (GET_CODE (addr) == PLUS)
2922 if (GET_CODE (XEXP (addr, 0)) == REG)
2924 base = XEXP (addr, 0);
2926 /* What we are saying here is that if the base
2927 REG is aligned properly, the compiler will make
2928 sure any REG based index upon it will be so
2930 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
2931 offset = XEXP (addr, 1);
2933 offset = const0_rtx;
2936 else if (GET_CODE (addr) == REG)
2939 offset = const0_rtx;
2942 if (base != NULL_RTX)
2944 int regno = REGNO (base);
2946 if (regno != FRAME_POINTER_REGNUM
2947 && regno != STACK_POINTER_REGNUM)
2949 /* Check if the compiler has recorded some information
2950 about the alignment of the base REG. If reload has
2951 completed, we already matched with proper alignments.
2952 If not running global_alloc, reload might give us
2953 unaligned pointer to local stack though. */
2955 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
2956 || (optimize && reload_completed))
2957 && (INTVAL (offset) & (desired - 1)) == 0)
2962 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
2966 else if (! TARGET_UNALIGNED_DOUBLES
2967 || CONSTANT_P (addr)
2968 || GET_CODE (addr) == LO_SUM)
2970 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
2971 is true, in which case we can only assume that an access is aligned if
2972 it is to a constant address, or the address involves a LO_SUM. */
2976 /* An obviously unaligned address. */
2981 /* Vectors to keep interesting information about registers where it can easily
2982 be got. We use to use the actual mode value as the bit number, but there
2983 are more than 32 modes now. Instead we use two tables: one indexed by
2984 hard register number, and one indexed by mode. */
2986 /* The purpose of sparc_mode_class is to shrink the range of modes so that
2987 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
2988 mapped into one sparc_mode_class mode. */
2990 enum sparc_mode_class {
2991 S_MODE, D_MODE, T_MODE, O_MODE,
2992 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
2996 /* Modes for single-word and smaller quantities. */
2997 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
2999 /* Modes for double-word and smaller quantities. */
3000 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
3002 /* Modes for quad-word and smaller quantities. */
3003 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
3005 /* Modes for 8-word and smaller quantities. */
3006 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
3008 /* Modes for single-float quantities. We must allow any single word or
3009 smaller quantity. This is because the fix/float conversion instructions
3010 take integer inputs/outputs from the float registers. */
3011 #define SF_MODES (S_MODES)
3013 /* Modes for double-float and smaller quantities. */
3014 #define DF_MODES (S_MODES | D_MODES)
3016 /* Modes for double-float only quantities. */
3017 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
3019 /* Modes for quad-float only quantities. */
3020 #define TF_ONLY_MODES (1 << (int) TF_MODE)
3022 /* Modes for quad-float and smaller quantities. */
3023 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
3025 /* Modes for quad-float and double-float quantities. */
3026 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
3028 /* Modes for quad-float pair only quantities. */
3029 #define OF_ONLY_MODES (1 << (int) OF_MODE)
3031 /* Modes for quad-float pairs and smaller quantities. */
3032 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
3034 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
3036 /* Modes for condition codes. */
3037 #define CC_MODES (1 << (int) CC_MODE)
3038 #define CCFP_MODES (1 << (int) CCFP_MODE)
3040 /* Value is 1 if register/mode pair is acceptable on sparc.
3041 The funny mixture of D and T modes is because integer operations
3042 do not specially operate on tetra quantities, so non-quad-aligned
3043 registers can hold quadword quantities (except %o4 and %i4 because
3044 they cross fixed registers). */
3046 /* This points to either the 32 bit or the 64 bit version. */
3047 int *hard_regno_mode_classes;
3049 static int hard_32bit_mode_classes[] = {
3050 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3051 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3052 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3053 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3055 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3056 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3057 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3058 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3060 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3061 and none can hold SFmode/SImode values. */
3062 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3063 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3064 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3065 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3068 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3074 static int hard_64bit_mode_classes[] = {
3075 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3076 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3077 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3078 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3080 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3081 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3082 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3083 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3085 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3086 and none can hold SFmode/SImode values. */
3087 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3088 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3089 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3090 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3093 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3099 int sparc_mode_class [NUM_MACHINE_MODES];
3101 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
3108 for (i = 0; i < NUM_MACHINE_MODES; i++)
3110 switch (GET_MODE_CLASS (i))
3113 case MODE_PARTIAL_INT:
3114 case MODE_COMPLEX_INT:
3115 if (GET_MODE_SIZE (i) <= 4)
3116 sparc_mode_class[i] = 1 << (int) S_MODE;
3117 else if (GET_MODE_SIZE (i) == 8)
3118 sparc_mode_class[i] = 1 << (int) D_MODE;
3119 else if (GET_MODE_SIZE (i) == 16)
3120 sparc_mode_class[i] = 1 << (int) T_MODE;
3121 else if (GET_MODE_SIZE (i) == 32)
3122 sparc_mode_class[i] = 1 << (int) O_MODE;
3124 sparc_mode_class[i] = 0;
3127 case MODE_COMPLEX_FLOAT:
3128 if (GET_MODE_SIZE (i) <= 4)
3129 sparc_mode_class[i] = 1 << (int) SF_MODE;
3130 else if (GET_MODE_SIZE (i) == 8)
3131 sparc_mode_class[i] = 1 << (int) DF_MODE;
3132 else if (GET_MODE_SIZE (i) == 16)
3133 sparc_mode_class[i] = 1 << (int) TF_MODE;
3134 else if (GET_MODE_SIZE (i) == 32)
3135 sparc_mode_class[i] = 1 << (int) OF_MODE;
3137 sparc_mode_class[i] = 0;
3141 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
3142 we must explicitly check for them here. */
3143 if (i == (int) CCFPmode || i == (int) CCFPEmode)
3144 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
3145 else if (i == (int) CCmode || i == (int) CC_NOOVmode
3146 || i == (int) CCXmode || i == (int) CCX_NOOVmode)
3147 sparc_mode_class[i] = 1 << (int) CC_MODE;
3149 sparc_mode_class[i] = 0;
3155 hard_regno_mode_classes = hard_64bit_mode_classes;
3157 hard_regno_mode_classes = hard_32bit_mode_classes;
3159 /* Initialize the array used by REGNO_REG_CLASS. */
3160 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3162 if (i < 16 && TARGET_V8PLUS)
3163 sparc_regno_reg_class[i] = I64_REGS;
3165 sparc_regno_reg_class[i] = GENERAL_REGS;
3167 sparc_regno_reg_class[i] = FP_REGS;
3169 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
3171 sparc_regno_reg_class[i] = FPCC_REGS;
3173 sparc_regno_reg_class[i] = NO_REGS;
3177 /* Save non call used registers from LOW to HIGH at BASE+OFFSET.
3178 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3179 v9 int regs as it simplifies the code. */
3182 save_regs (file, low, high, base, offset, n_regs, real_offset)
3192 if (TARGET_ARCH64 && high <= 32)
3194 for (i = low; i < high; i++)
3196 if (regs_ever_live[i] && ! call_used_regs[i])
3198 fprintf (file, "\tstx\t%s, [%s+%d]\n",
3199 reg_names[i], base, offset + 4 * n_regs);
3200 if (dwarf2out_do_frame ())
3201 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3208 for (i = low; i < high; i += 2)
3210 if (regs_ever_live[i] && ! call_used_regs[i])
3212 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3214 fprintf (file, "\tstd\t%s, [%s+%d]\n",
3215 reg_names[i], base, offset + 4 * n_regs);
3216 if (dwarf2out_do_frame ())
3218 char *l = dwarf2out_cfi_label ();
3219 dwarf2out_reg_save (l, i, real_offset + 4 * n_regs);
3220 dwarf2out_reg_save (l, i+1, real_offset + 4 * n_regs + 4);
3226 fprintf (file, "\tst\t%s, [%s+%d]\n",
3227 reg_names[i], base, offset + 4 * n_regs);
3228 if (dwarf2out_do_frame ())
3229 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3235 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3237 fprintf (file, "\tst\t%s, [%s+%d]\n",
3238 reg_names[i+1], base, offset + 4 * n_regs + 4);
3239 if (dwarf2out_do_frame ())
3240 dwarf2out_reg_save ("", i + 1, real_offset + 4 * n_regs + 4);
3249 /* Restore non call used registers from LOW to HIGH at BASE+OFFSET.
3251 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3252 v9 int regs as it simplifies the code. */
3255 restore_regs (file, low, high, base, offset, n_regs)
3264 if (TARGET_ARCH64 && high <= 32)
3266 for (i = low; i < high; i++)
3268 if (regs_ever_live[i] && ! call_used_regs[i])
3269 fprintf (file, "\tldx\t[%s+%d], %s\n",
3270 base, offset + 4 * n_regs, reg_names[i]),
3276 for (i = low; i < high; i += 2)
3278 if (regs_ever_live[i] && ! call_used_regs[i])
3279 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3280 fprintf (file, "\tldd\t[%s+%d], %s\n",
3281 base, offset + 4 * n_regs, reg_names[i]),
3284 fprintf (file, "\tld\t[%s+%d], %s\n",
3285 base, offset + 4 * n_regs, reg_names[i]),
3287 else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3288 fprintf (file, "\tld\t[%s+%d], %s\n",
3289 base, offset + 4 * n_regs + 4, reg_names[i+1]),
3296 /* Compute the frame size required by the function. This function is called
3297 during the reload pass and also by output_function_prologue(). */
3300 compute_frame_size (size, leaf_function)
3305 int outgoing_args_size = (current_function_outgoing_args_size
3306 + REG_PARM_STACK_SPACE (current_function_decl));
3308 if (TARGET_EPILOGUE)
3310 /* N_REGS is the number of 4-byte regs saved thus far. This applies
3311 even to v9 int regs to be consistent with save_regs/restore_regs. */
3315 for (i = 0; i < 8; i++)
3316 if (regs_ever_live[i] && ! call_used_regs[i])
3321 for (i = 0; i < 8; i += 2)
3322 if ((regs_ever_live[i] && ! call_used_regs[i])
3323 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3327 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
3328 if ((regs_ever_live[i] && ! call_used_regs[i])
3329 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3333 /* Set up values for use in `function_epilogue'. */
3334 num_gfregs = n_regs;
3336 if (leaf_function && n_regs == 0
3337 && size == 0 && current_function_outgoing_args_size == 0)
3339 actual_fsize = apparent_fsize = 0;
3343 /* We subtract STARTING_FRAME_OFFSET, remember it's negative.
3344 The stack bias (if any) is taken out to undo its effects. */
3345 apparent_fsize = (size - STARTING_FRAME_OFFSET + SPARC_STACK_BIAS + 7) & -8;
3346 apparent_fsize += n_regs * 4;
3347 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
3350 /* Make sure nothing can clobber our register windows.
3351 If a SAVE must be done, or there is a stack-local variable,
3352 the register window area must be allocated.
3353 ??? For v8 we apparently need an additional 8 bytes of reserved space. */
3354 if (leaf_function == 0 || size > 0)
3355 actual_fsize += (16 * UNITS_PER_WORD) + (TARGET_ARCH64 ? 0 : 8);
3357 return SPARC_STACK_ALIGN (actual_fsize);
3360 /* Build a (32 bit) big number in a register. */
3361 /* ??? We may be able to use the set macro here too. */
3364 build_big_number (file, num, reg)
3369 if (num >= 0 || ! TARGET_ARCH64)
3371 fprintf (file, "\tsethi\t%%hi(%d), %s\n", num, reg);
3372 if ((num & 0x3ff) != 0)
3373 fprintf (file, "\tor\t%s, %%lo(%d), %s\n", reg, num, reg);
3375 else /* num < 0 && TARGET_ARCH64 */
3377 /* Sethi does not sign extend, so we must use a little trickery
3378 to use it for negative numbers. Invert the constant before
3379 loading it in, then use xor immediate to invert the loaded bits
3380 (along with the upper 32 bits) to the desired constant. This
3381 works because the sethi and immediate fields overlap. */
3384 int low = -0x400 + (asize & 0x3FF);
3386 fprintf (file, "\tsethi\t%%hi(%d), %s\n\txor\t%s, %d, %s\n",
3387 inv, reg, reg, low, reg);
3391 /* Output any necessary .register pseudo-ops. */
3393 sparc_output_scratch_registers (file)
3394 FILE *file ATTRIBUTE_UNUSED;
3396 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
3402 /* Check if %g[2367] were used without
3403 .register being printed for them already. */
3404 for (i = 2; i < 8; i++)
3406 if (regs_ever_live [i]
3407 && ! sparc_hard_reg_printed [i])
3409 sparc_hard_reg_printed [i] = 1;
3410 fprintf (file, "\t.register\t%%g%d, #scratch\n", i);
3417 /* This function generates the assembly code for function entry.
3418 FILE is a stdio stream to output the code to.
3419 SIZE is an int: how many units of temporary storage to allocate.
3420 Refer to the array `regs_ever_live' to determine which registers
3421 to save; `regs_ever_live[I]' is nonzero if register number I
3422 is ever used in the function. This macro is responsible for
3423 knowing which registers should not be saved even if used. */
3425 /* On SPARC, move-double insns between fpu and cpu need an 8-byte block
3426 of memory. If any fpu reg is used in the function, we allocate
3427 such a block here, at the bottom of the frame, just in case it's needed.
3429 If this function is a leaf procedure, then we may choose not
3430 to do a "save" insn. The decision about whether or not
3431 to do this is made in regclass.c. */
3434 sparc_output_function_prologue (file, size)
3439 sparc_flat_function_prologue (file, size);
3441 sparc_nonflat_function_prologue (file, size,
3442 current_function_uses_only_leaf_regs);
3445 /* Output code for the function prologue. */
3448 sparc_nonflat_function_prologue (file, size, leaf_function)
3453 sparc_output_scratch_registers (file);
3455 /* Need to use actual_fsize, since we are also allocating
3456 space for our callee (and our own register save area). */
3457 actual_fsize = compute_frame_size (size, leaf_function);
3461 frame_base_name = "%sp";
3462 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
3466 frame_base_name = "%fp";
3467 frame_base_offset = SPARC_STACK_BIAS;
3470 /* This is only for the human reader. */
3471 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
3473 if (actual_fsize == 0)
3475 else if (! leaf_function)
3477 if (actual_fsize <= 4096)
3478 fprintf (file, "\tsave\t%%sp, -%d, %%sp\n", actual_fsize);
3479 else if (actual_fsize <= 8192)
3481 fprintf (file, "\tsave\t%%sp, -4096, %%sp\n");
3482 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3486 build_big_number (file, -actual_fsize, "%g1");
3487 fprintf (file, "\tsave\t%%sp, %%g1, %%sp\n");
3490 else /* leaf function */
3492 if (actual_fsize <= 4096)
3493 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize);
3494 else if (actual_fsize <= 8192)
3496 fprintf (file, "\tadd\t%%sp, -4096, %%sp\n");
3497 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3501 build_big_number (file, -actual_fsize, "%g1");
3502 fprintf (file, "\tadd\t%%sp, %%g1, %%sp\n");
3506 if (dwarf2out_do_frame () && actual_fsize)
3508 char *label = dwarf2out_cfi_label ();
3510 /* The canonical frame address refers to the top of the frame. */
3511 dwarf2out_def_cfa (label, (leaf_function ? STACK_POINTER_REGNUM
3512 : FRAME_POINTER_REGNUM),
3515 if (! leaf_function)
3517 /* Note the register window save. This tells the unwinder that
3518 it needs to restore the window registers from the previous
3519 frame's window save area at 0(cfa). */
3520 dwarf2out_window_save (label);
3522 /* The return address (-8) is now in %i7. */
3523 dwarf2out_return_reg (label, 31);
3527 /* If doing anything with PIC, do it now. */
3529 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
3531 /* Call saved registers are saved just above the outgoing argument area. */
3534 int offset, real_offset, n_regs;
3537 real_offset = -apparent_fsize;
3538 offset = -apparent_fsize + frame_base_offset;
3539 if (offset < -4096 || offset + num_gfregs * 4 > 4096)
3541 /* ??? This might be optimized a little as %g1 might already have a
3542 value close enough that a single add insn will do. */
3543 /* ??? Although, all of this is probably only a temporary fix
3544 because if %g1 can hold a function result, then
3545 output_function_epilogue will lose (the result will get
3547 build_big_number (file, offset, "%g1");
3548 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
3554 base = frame_base_name;
3558 if (TARGET_EPILOGUE && ! leaf_function)
3559 /* ??? Originally saved regs 0-15 here. */
3560 n_regs = save_regs (file, 0, 8, base, offset, 0, real_offset);
3561 else if (leaf_function)
3562 /* ??? Originally saved regs 0-31 here. */
3563 n_regs = save_regs (file, 0, 8, base, offset, 0, real_offset);
3564 if (TARGET_EPILOGUE)
3565 save_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs,
3570 if (leaf_function && actual_fsize != 0)
3572 /* warning ("leaf procedure with frame size %d", actual_fsize); */
3573 if (! TARGET_EPILOGUE)
3574 leaf_label = gen_label_rtx ();
3578 /* Output code to restore any call saved registers. */
3581 output_restore_regs (file, leaf_function)
3588 offset = -apparent_fsize + frame_base_offset;
3589 if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/)
3591 build_big_number (file, offset, "%g1");
3592 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
3598 base = frame_base_name;
3602 if (TARGET_EPILOGUE && ! leaf_function)
3603 /* ??? Originally saved regs 0-15 here. */
3604 n_regs = restore_regs (file, 0, 8, base, offset, 0);
3605 else if (leaf_function)
3606 /* ??? Originally saved regs 0-31 here. */
3607 n_regs = restore_regs (file, 0, 8, base, offset, 0);
3608 if (TARGET_EPILOGUE)
3609 restore_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs);
3612 /* This function generates the assembly code for function exit,
3613 on machines that need it.
3615 The function epilogue should not depend on the current stack pointer!
3616 It should use the frame pointer only. This is mandatory because
3617 of alloca; we also take advantage of it to omit stack adjustments
3618 before returning. */
3621 sparc_output_function_epilogue (file, size)
3626 sparc_flat_function_epilogue (file, size);
3628 sparc_nonflat_function_epilogue (file, size,
3629 current_function_uses_only_leaf_regs);
3632 /* Output code for the function epilogue. */
3635 sparc_nonflat_function_epilogue (file, size, leaf_function)
3637 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
3644 emit_label_after (leaf_label, get_last_insn ());
3645 final_scan_insn (get_last_insn (), file, 0, 0, 1);
3648 if (current_function_epilogue_delay_list == 0)
3650 /* If code does not drop into the epilogue, we need
3651 do nothing except output pending case vectors. */
3652 rtx insn = get_last_insn ();
3653 if (GET_CODE (insn) == NOTE)
3654 insn = prev_nonnote_insn (insn);
3655 if (insn && GET_CODE (insn) == BARRIER)
3656 goto output_vectors;
3660 output_restore_regs (file, leaf_function);
3662 /* Work out how to skip the caller's unimp instruction if required. */
3664 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%o7+12" : "retl");
3666 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%i7+12" : "ret");
3668 if (TARGET_EPILOGUE || leaf_label)
3670 int old_target_epilogue = TARGET_EPILOGUE;
3671 target_flags &= ~old_target_epilogue;
3673 if (! leaf_function)
3675 if (current_function_calls_eh_return)
3677 if (current_function_epilogue_delay_list)
3679 if (SKIP_CALLERS_UNIMP_P)
3682 fputs ("\trestore\n\tretl\n\tadd\t%sp, %g1, %sp\n", file);
3684 /* If we wound up with things in our delay slot, flush them here. */
3685 else if (current_function_epilogue_delay_list)
3687 rtx delay = PATTERN (XEXP (current_function_epilogue_delay_list, 0));
3689 if (TARGET_V9 && ! epilogue_renumber (&delay, 1))
3691 epilogue_renumber (&delay, 0);
3692 fputs (SKIP_CALLERS_UNIMP_P
3693 ? "\treturn\t%i7+12\n"
3694 : "\treturn\t%i7+8\n", file);
3695 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0), file, 1, 0, 0);
3699 rtx insn = emit_jump_insn_after (gen_rtx_RETURN (VOIDmode),
3703 if (GET_CODE (delay) != SET)
3706 src = SET_SRC (delay);
3707 if (GET_CODE (src) == ASHIFT)
3709 if (XEXP (src, 1) != const1_rtx)
3711 SET_SRC (delay) = gen_rtx_PLUS (GET_MODE (src), XEXP (src, 0),
3715 PATTERN (insn) = gen_rtx_PARALLEL (VOIDmode,
3716 gen_rtvec (2, delay, PATTERN (insn)));
3717 final_scan_insn (insn, file, 1, 0, 1);
3720 else if (TARGET_V9 && ! SKIP_CALLERS_UNIMP_P)
3721 fputs ("\treturn\t%i7+8\n\tnop\n", file);
3723 fprintf (file, "\t%s\n\trestore\n", ret);
3725 else if (current_function_calls_eh_return)
3727 /* All of the following cases are for leaf functions. */
3728 else if (current_function_epilogue_delay_list)
3730 /* eligible_for_epilogue_delay_slot ensures that if this is a
3731 leaf function, then we will only have insn in the delay slot
3732 if the frame size is zero, thus no adjust for the stack is
3734 if (actual_fsize != 0)
3736 fprintf (file, "\t%s\n", ret);
3737 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
3740 /* Output 'nop' instead of 'sub %sp,-0,%sp' when no frame, so as to
3741 avoid generating confusing assembly language output. */
3742 else if (actual_fsize == 0)
3743 fprintf (file, "\t%s\n\tnop\n", ret);
3744 else if (actual_fsize <= 4096)
3745 fprintf (file, "\t%s\n\tsub\t%%sp, -%d, %%sp\n", ret, actual_fsize);
3746 else if (actual_fsize <= 8192)
3747 fprintf (file, "\tsub\t%%sp, -4096, %%sp\n\t%s\n\tsub\t%%sp, -%d, %%sp\n",
3748 ret, actual_fsize - 4096);
3749 else if ((actual_fsize & 0x3ff) == 0)
3750 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
3753 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\tor\t%%g1, %%lo(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
3754 actual_fsize, actual_fsize, ret);
3755 target_flags |= old_target_epilogue;
3759 sparc_output_deferred_case_vectors ();
3762 /* Output a sibling call. */
3765 output_sibcall (insn, call_operand)
3766 rtx insn, call_operand;
3768 int leaf_regs = current_function_uses_only_leaf_regs;
3770 int delay_slot = dbr_sequence_length () > 0;
3774 /* Call to restore global regs might clobber
3775 the delay slot. Instead of checking for this
3776 output the delay slot now. */
3779 rtx delay = NEXT_INSN (insn);
3784 final_scan_insn (delay, asm_out_file, 1, 0, 1);
3785 PATTERN (delay) = gen_blockage ();
3786 INSN_CODE (delay) = -1;
3789 output_restore_regs (asm_out_file, leaf_regs);
3792 operands[0] = call_operand;
3796 #ifdef HAVE_AS_RELAX_OPTION
3797 /* If as and ld are relaxing tail call insns into branch always,
3798 use or %o7,%g0,X; call Y; or X,%g0,%o7 always, so that it can
3799 be optimized. With sethi/jmpl as nor ld has no easy way how to
3800 find out if somebody does not branch between the sethi and jmpl. */
3803 int spare_slot = ((TARGET_ARCH32 || TARGET_CM_MEDLOW) && ! flag_pic);
3807 if ((actual_fsize || ! spare_slot) && delay_slot)
3809 rtx delay = NEXT_INSN (insn);
3814 final_scan_insn (delay, asm_out_file, 1, 0, 1);
3815 PATTERN (delay) = gen_blockage ();
3816 INSN_CODE (delay) = -1;
3821 if (actual_fsize <= 4096)
3822 size = actual_fsize;
3823 else if (actual_fsize <= 8192)
3825 fputs ("\tsub\t%sp, -4096, %sp\n", asm_out_file);
3826 size = actual_fsize - 4096;
3828 else if ((actual_fsize & 0x3ff) == 0)
3829 fprintf (asm_out_file,
3830 "\tsethi\t%%hi(%d), %%g1\n\tadd\t%%sp, %%g1, %%sp\n",
3834 fprintf (asm_out_file,
3835 "\tsethi\t%%hi(%d), %%g1\n\tor\t%%g1, %%lo(%d), %%g1\n",
3836 actual_fsize, actual_fsize);
3837 fputs ("\tadd\t%%sp, %%g1, %%sp\n", asm_out_file);
3842 output_asm_insn ("sethi\t%%hi(%a0), %%g1", operands);
3843 output_asm_insn ("jmpl\t%%g1 + %%lo(%a0), %%g0", operands);
3845 fprintf (asm_out_file, "\t sub\t%%sp, -%d, %%sp\n", size);
3846 else if (! delay_slot)
3847 fputs ("\t nop\n", asm_out_file);
3852 fprintf (asm_out_file, "\tsub\t%%sp, -%d, %%sp\n", size);
3853 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
3854 it into branch if possible. */
3855 output_asm_insn ("or\t%%o7, %%g0, %%g1", operands);
3856 output_asm_insn ("call\t%a0, 0", operands);
3857 output_asm_insn (" or\t%%g1, %%g0, %%o7", operands);
3862 output_asm_insn ("call\t%a0, 0", operands);
3865 rtx delay = NEXT_INSN (insn), pat;
3870 pat = PATTERN (delay);
3871 if (GET_CODE (pat) != SET)
3874 operands[0] = SET_DEST (pat);
3875 pat = SET_SRC (pat);
3876 switch (GET_CODE (pat))
3879 operands[1] = XEXP (pat, 0);
3880 operands[2] = XEXP (pat, 1);
3881 output_asm_insn (" restore %r1, %2, %Y0", operands);
3884 operands[1] = XEXP (pat, 0);
3885 operands[2] = XEXP (pat, 1);
3886 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
3889 operands[1] = XEXP (pat, 0);
3890 output_asm_insn (" restore %r1, %r1, %Y0", operands);
3894 output_asm_insn (" restore %%g0, %1, %Y0", operands);
3897 PATTERN (delay) = gen_blockage ();
3898 INSN_CODE (delay) = -1;
3901 fputs ("\t restore\n", asm_out_file);
3905 /* Functions for handling argument passing.
3907 For v8 the first six args are normally in registers and the rest are
3908 pushed. Any arg that starts within the first 6 words is at least
3909 partially passed in a register unless its data type forbids.
3911 For v9, the argument registers are laid out as an array of 16 elements
3912 and arguments are added sequentially. The first 6 int args and up to the
3913 first 16 fp args (depending on size) are passed in regs.
3915 Slot Stack Integral Float Float in structure Double Long Double
3916 ---- ----- -------- ----- ------------------ ------ -----------
3917 15 [SP+248] %f31 %f30,%f31 %d30
3918 14 [SP+240] %f29 %f28,%f29 %d28 %q28
3919 13 [SP+232] %f27 %f26,%f27 %d26
3920 12 [SP+224] %f25 %f24,%f25 %d24 %q24
3921 11 [SP+216] %f23 %f22,%f23 %d22
3922 10 [SP+208] %f21 %f20,%f21 %d20 %q20
3923 9 [SP+200] %f19 %f18,%f19 %d18
3924 8 [SP+192] %f17 %f16,%f17 %d16 %q16
3925 7 [SP+184] %f15 %f14,%f15 %d14
3926 6 [SP+176] %f13 %f12,%f13 %d12 %q12
3927 5 [SP+168] %o5 %f11 %f10,%f11 %d10
3928 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
3929 3 [SP+152] %o3 %f7 %f6,%f7 %d6
3930 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
3931 1 [SP+136] %o1 %f3 %f2,%f3 %d2
3932 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
3934 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
3936 Integral arguments are always passed as 64 bit quantities appropriately
3939 Passing of floating point values is handled as follows.
3940 If a prototype is in scope:
3941 If the value is in a named argument (i.e. not a stdarg function or a
3942 value not part of the `...') then the value is passed in the appropriate
3944 If the value is part of the `...' and is passed in one of the first 6
3945 slots then the value is passed in the appropriate int reg.
3946 If the value is part of the `...' and is not passed in one of the first 6
3947 slots then the value is passed in memory.
3948 If a prototype is not in scope:
3949 If the value is one of the first 6 arguments the value is passed in the
3950 appropriate integer reg and the appropriate fp reg.
3951 If the value is not one of the first 6 arguments the value is passed in
3952 the appropriate fp reg and in memory.
3955 /* Maximum number of int regs for args. */
3956 #define SPARC_INT_ARG_MAX 6
3957 /* Maximum number of fp regs for args. */
3958 #define SPARC_FP_ARG_MAX 16
3960 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
3962 /* Handle the INIT_CUMULATIVE_ARGS macro.
3963 Initialize a variable CUM of type CUMULATIVE_ARGS
3964 for a call to a function whose data type is FNTYPE.
3965 For a library call, FNTYPE is 0. */
3968 init_cumulative_args (cum, fntype, libname, indirect)
3969 CUMULATIVE_ARGS *cum;
3971 rtx libname ATTRIBUTE_UNUSED;
3972 int indirect ATTRIBUTE_UNUSED;
3975 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
3976 cum->libcall_p = fntype == 0;
3979 /* Compute the slot number to pass an argument in.
3980 Returns the slot number or -1 if passing on the stack.
3982 CUM is a variable of type CUMULATIVE_ARGS which gives info about
3983 the preceding args and about the function being called.
3984 MODE is the argument's machine mode.
3985 TYPE is the data type of the argument (as a tree).
3986 This is null for libcalls where that information may
3988 NAMED is nonzero if this argument is a named parameter
3989 (otherwise it is an extra parameter matching an ellipsis).
3990 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
3991 *PREGNO records the register number to use if scalar type.
3992 *PPADDING records the amount of padding needed in words. */
3995 function_arg_slotno (cum, mode, type, named, incoming_p, pregno, ppadding)
3996 const CUMULATIVE_ARGS *cum;
3997 enum machine_mode mode;
4004 int regbase = (incoming_p
4005 ? SPARC_INCOMING_INT_ARG_FIRST
4006 : SPARC_OUTGOING_INT_ARG_FIRST);
4007 int slotno = cum->words;
4012 if (type != 0 && TREE_ADDRESSABLE (type))
4015 && type != 0 && mode == BLKmode
4016 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
4022 /* MODE is VOIDmode when generating the actual call.
4026 case QImode : case CQImode :
4027 case HImode : case CHImode :
4028 case SImode : case CSImode :
4029 case DImode : case CDImode :
4030 case TImode : case CTImode :
4031 if (slotno >= SPARC_INT_ARG_MAX)
4033 regno = regbase + slotno;
4036 case SFmode : case SCmode :
4037 case DFmode : case DCmode :
4038 case TFmode : case TCmode :
4041 if (slotno >= SPARC_INT_ARG_MAX)
4043 regno = regbase + slotno;
4047 if ((mode == TFmode || mode == TCmode)
4048 && (slotno & 1) != 0)
4049 slotno++, *ppadding = 1;
4050 if (TARGET_FPU && named)
4052 if (slotno >= SPARC_FP_ARG_MAX)
4054 regno = SPARC_FP_ARG_FIRST + slotno * 2;
4060 if (slotno >= SPARC_INT_ARG_MAX)
4062 regno = regbase + slotno;
4068 /* For sparc64, objects requiring 16 byte alignment get it. */
4071 if (type && TYPE_ALIGN (type) == 128 && (slotno & 1) != 0)
4072 slotno++, *ppadding = 1;
4076 || (type && TREE_CODE (type) == UNION_TYPE))
4078 if (slotno >= SPARC_INT_ARG_MAX)
4080 regno = regbase + slotno;
4085 int intregs_p = 0, fpregs_p = 0;
4086 /* The ABI obviously doesn't specify how packed
4087 structures are passed. These are defined to be passed
4088 in int regs if possible, otherwise memory. */
4091 /* First see what kinds of registers we need. */
4092 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4094 if (TREE_CODE (field) == FIELD_DECL)
4096 if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4101 if (DECL_PACKED (field))
4105 if (packed_p || !named)
4106 fpregs_p = 0, intregs_p = 1;
4108 /* If all arg slots are filled, then must pass on stack. */
4109 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
4111 /* If there are only int args and all int arg slots are filled,
4112 then must pass on stack. */
4113 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
4115 /* Note that even if all int arg slots are filled, fp members may
4116 still be passed in regs if such regs are available.
4117 *PREGNO isn't set because there may be more than one, it's up
4118 to the caller to compute them. */
4131 /* Handle recursive register counting for structure field layout. */
4133 struct function_arg_record_value_parms
4136 int slotno, named, regbase;
4141 static void function_arg_record_value_3
4142 PARAMS ((HOST_WIDE_INT, struct function_arg_record_value_parms *));
4143 static void function_arg_record_value_2
4144 PARAMS ((tree, HOST_WIDE_INT,
4145 struct function_arg_record_value_parms *));
4146 static void function_arg_record_value_1
4147 PARAMS ((tree, HOST_WIDE_INT,
4148 struct function_arg_record_value_parms *));
4149 static rtx function_arg_record_value
4150 PARAMS ((tree, enum machine_mode, int, int, int));
4152 /* A subroutine of function_arg_record_value. Traverse the structure
4153 recusively and determine how many registers will be required. */
4156 function_arg_record_value_1 (type, startbitpos, parms)
4158 HOST_WIDE_INT startbitpos;
4159 struct function_arg_record_value_parms *parms;
4163 /* The ABI obviously doesn't specify how packed structures are
4164 passed. These are defined to be passed in int regs if possible,
4165 otherwise memory. */
4168 /* We need to compute how many registers are needed so we can
4169 allocate the PARALLEL but before we can do that we need to know
4170 whether there are any packed fields. If there are, int regs are
4171 used regardless of whether there are fp values present. */
4172 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4174 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4181 /* Compute how many registers we need. */
4182 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4184 if (TREE_CODE (field) == FIELD_DECL)
4186 HOST_WIDE_INT bitpos = startbitpos;
4188 if (DECL_SIZE (field) != 0
4189 && host_integerp (bit_position (field), 1))
4190 bitpos += int_bit_position (field);
4192 /* ??? FIXME: else assume zero offset. */
4194 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4195 function_arg_record_value_1 (TREE_TYPE (field), bitpos, parms);
4196 else if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4201 if (parms->intoffset != -1)
4203 int intslots, this_slotno;
4205 intslots = (bitpos - parms->intoffset + BITS_PER_WORD - 1)
4207 this_slotno = parms->slotno + parms->intoffset
4210 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4211 intslots = MAX (intslots, 0);
4212 parms->nregs += intslots;
4213 parms->intoffset = -1;
4216 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
4217 If it wasn't true we wouldn't be here. */
4222 if (parms->intoffset == -1)
4223 parms->intoffset = bitpos;
4229 /* A subroutine of function_arg_record_value. Assign the bits of the
4230 structure between parms->intoffset and bitpos to integer registers. */
4233 function_arg_record_value_3 (bitpos, parms)
4234 HOST_WIDE_INT bitpos;
4235 struct function_arg_record_value_parms *parms;
4237 enum machine_mode mode;
4239 unsigned int startbit, endbit;
4240 int this_slotno, intslots, intoffset;
4243 if (parms->intoffset == -1)
4246 intoffset = parms->intoffset;
4247 parms->intoffset = -1;
4249 startbit = intoffset & -BITS_PER_WORD;
4250 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4251 intslots = (endbit - startbit) / BITS_PER_WORD;
4252 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
4254 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4258 /* If this is the trailing part of a word, only load that much into
4259 the register. Otherwise load the whole register. Note that in
4260 the latter case we may pick up unwanted bits. It's not a problem
4261 at the moment but may wish to revisit. */
4263 if (intoffset % BITS_PER_WORD != 0)
4264 mode = mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
4269 intoffset /= BITS_PER_UNIT;
4272 regno = parms->regbase + this_slotno;
4273 reg = gen_rtx_REG (mode, regno);
4274 XVECEXP (parms->ret, 0, parms->nregs)
4275 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
4278 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
4282 while (intslots > 0);
4285 /* A subroutine of function_arg_record_value. Traverse the structure
4286 recursively and assign bits to floating point registers. Track which
4287 bits in between need integer registers; invoke function_arg_record_value_3
4288 to make that happen. */
4291 function_arg_record_value_2 (type, startbitpos, parms)
4293 HOST_WIDE_INT startbitpos;
4294 struct function_arg_record_value_parms *parms;
4299 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4301 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4308 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4310 if (TREE_CODE (field) == FIELD_DECL)
4312 HOST_WIDE_INT bitpos = startbitpos;
4314 if (DECL_SIZE (field) != 0
4315 && host_integerp (bit_position (field), 1))
4316 bitpos += int_bit_position (field);
4318 /* ??? FIXME: else assume zero offset. */
4320 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4321 function_arg_record_value_2 (TREE_TYPE (field), bitpos, parms);
4322 else if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4327 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
4330 function_arg_record_value_3 (bitpos, parms);
4332 reg = gen_rtx_REG (DECL_MODE (field),
4333 (SPARC_FP_ARG_FIRST + this_slotno * 2
4334 + (DECL_MODE (field) == SFmode
4335 && (bitpos & 32) != 0)));
4336 XVECEXP (parms->ret, 0, parms->nregs)
4337 = gen_rtx_EXPR_LIST (VOIDmode, reg,
4338 GEN_INT (bitpos / BITS_PER_UNIT));
4343 if (parms->intoffset == -1)
4344 parms->intoffset = bitpos;
4350 /* Used by function_arg and function_value to implement the complex
4351 Sparc64 structure calling conventions. */
4354 function_arg_record_value (type, mode, slotno, named, regbase)
4356 enum machine_mode mode;
4357 int slotno, named, regbase;
4359 HOST_WIDE_INT typesize = int_size_in_bytes (type);
4360 struct function_arg_record_value_parms parms;
4363 parms.ret = NULL_RTX;
4364 parms.slotno = slotno;
4365 parms.named = named;
4366 parms.regbase = regbase;
4368 /* Compute how many registers we need. */
4370 parms.intoffset = 0;
4371 function_arg_record_value_1 (type, 0, &parms);
4373 if (parms.intoffset != -1)
4375 unsigned int startbit, endbit;
4376 int intslots, this_slotno;
4378 startbit = parms.intoffset & -BITS_PER_WORD;
4379 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4380 intslots = (endbit - startbit) / BITS_PER_WORD;
4381 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
4383 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4384 intslots = MAX (intslots, 0);
4386 parms.nregs += intslots;
4388 nregs = parms.nregs;
4390 /* Allocate the vector and handle some annoying special cases. */
4393 /* ??? Empty structure has no value? Duh? */
4396 /* Though there's nothing really to store, return a word register
4397 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
4398 leads to breakage due to the fact that there are zero bytes to
4400 return gen_rtx_REG (mode, regbase);
4404 /* ??? C++ has structures with no fields, and yet a size. Give up
4405 for now and pass everything back in integer registers. */
4406 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4408 if (nregs + slotno > SPARC_INT_ARG_MAX)
4409 nregs = SPARC_INT_ARG_MAX - slotno;
4414 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (nregs));
4416 /* Fill in the entries. */
4418 parms.intoffset = 0;
4419 function_arg_record_value_2 (type, 0, &parms);
4420 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
4422 if (parms.nregs != nregs)
4428 /* Handle the FUNCTION_ARG macro.
4429 Determine where to put an argument to a function.
4430 Value is zero to push the argument on the stack,
4431 or a hard register in which to store the argument.
4433 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4434 the preceding args and about the function being called.
4435 MODE is the argument's machine mode.
4436 TYPE is the data type of the argument (as a tree).
4437 This is null for libcalls where that information may
4439 NAMED is nonzero if this argument is a named parameter
4440 (otherwise it is an extra parameter matching an ellipsis).
4441 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
4444 function_arg (cum, mode, type, named, incoming_p)
4445 const CUMULATIVE_ARGS *cum;
4446 enum machine_mode mode;
4451 int regbase = (incoming_p
4452 ? SPARC_INCOMING_INT_ARG_FIRST
4453 : SPARC_OUTGOING_INT_ARG_FIRST);
4454 int slotno, regno, padding;
4457 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
4465 reg = gen_rtx_REG (mode, regno);
4469 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
4470 but also have the slot allocated for them.
4471 If no prototype is in scope fp values in register slots get passed
4472 in two places, either fp regs and int regs or fp regs and memory. */
4473 if ((GET_MODE_CLASS (mode) == MODE_FLOAT
4474 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4475 && SPARC_FP_REG_P (regno))
4477 reg = gen_rtx_REG (mode, regno);
4478 if (cum->prototype_p || cum->libcall_p)
4480 /* "* 2" because fp reg numbers are recorded in 4 byte
4483 /* ??? This will cause the value to be passed in the fp reg and
4484 in the stack. When a prototype exists we want to pass the
4485 value in the reg but reserve space on the stack. That's an
4486 optimization, and is deferred [for a bit]. */
4487 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
4488 return gen_rtx_PARALLEL (mode,
4490 gen_rtx_EXPR_LIST (VOIDmode,
4491 NULL_RTX, const0_rtx),
4492 gen_rtx_EXPR_LIST (VOIDmode,
4496 /* ??? It seems that passing back a register even when past
4497 the area declared by REG_PARM_STACK_SPACE will allocate
4498 space appropriately, and will not copy the data onto the
4499 stack, exactly as we desire.
4501 This is due to locate_and_pad_parm being called in
4502 expand_call whenever reg_parm_stack_space > 0, which
4503 while benefical to our example here, would seem to be
4504 in error from what had been intended. Ho hum... -- r~ */
4512 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
4516 /* On incoming, we don't need to know that the value
4517 is passed in %f0 and %i0, and it confuses other parts
4518 causing needless spillage even on the simplest cases. */
4522 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
4523 + (regno - SPARC_FP_ARG_FIRST) / 2);
4525 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4526 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
4528 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4532 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4533 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4534 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4538 else if (type && TREE_CODE (type) == RECORD_TYPE)
4540 /* Structures up to 16 bytes in size are passed in arg slots on the
4541 stack and are promoted to registers where possible. */
4543 if (int_size_in_bytes (type) > 16)
4544 abort (); /* shouldn't get here */
4546 return function_arg_record_value (type, mode, slotno, named, regbase);
4548 else if (type && TREE_CODE (type) == UNION_TYPE)
4550 enum machine_mode mode;
4551 int bytes = int_size_in_bytes (type);
4556 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
4557 reg = gen_rtx_REG (mode, regno);
4561 /* Scalar or complex int. */
4562 reg = gen_rtx_REG (mode, regno);
4568 /* Handle the FUNCTION_ARG_PARTIAL_NREGS macro.
4569 For an arg passed partly in registers and partly in memory,
4570 this is the number of registers used.
4571 For args passed entirely in registers or entirely in memory, zero.
4573 Any arg that starts in the first 6 regs but won't entirely fit in them
4574 needs partial registers on v8. On v9, structures with integer
4575 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
4576 values that begin in the last fp reg [where "last fp reg" varies with the
4577 mode] will be split between that reg and memory. */
4580 function_arg_partial_nregs (cum, mode, type, named)
4581 const CUMULATIVE_ARGS *cum;
4582 enum machine_mode mode;
4586 int slotno, regno, padding;
4588 /* We pass 0 for incoming_p here, it doesn't matter. */
4589 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
4596 if ((slotno + (mode == BLKmode
4597 ? ROUND_ADVANCE (int_size_in_bytes (type))
4598 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
4599 > NPARM_REGS (SImode))
4600 return NPARM_REGS (SImode) - slotno;
4605 if (type && AGGREGATE_TYPE_P (type))
4607 int size = int_size_in_bytes (type);
4608 int align = TYPE_ALIGN (type);
4611 slotno += slotno & 1;
4612 if (size > 8 && size <= 16
4613 && slotno == SPARC_INT_ARG_MAX - 1)
4616 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
4617 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
4620 if (GET_MODE_ALIGNMENT (mode) == 128)
4622 slotno += slotno & 1;
4623 if (slotno == SPARC_INT_ARG_MAX - 2)
4628 if (slotno == SPARC_INT_ARG_MAX - 1)
4632 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4634 if (GET_MODE_ALIGNMENT (mode) == 128)
4635 slotno += slotno & 1;
4636 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
4644 /* Handle the FUNCTION_ARG_PASS_BY_REFERENCE macro.
4645 !v9: The SPARC ABI stipulates passing struct arguments (of any size) and
4646 quad-precision floats by invisible reference.
4647 v9: Aggregates greater than 16 bytes are passed by reference.
4648 For Pascal, also pass arrays by reference. */
4651 function_arg_pass_by_reference (cum, mode, type, named)
4652 const CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
4653 enum machine_mode mode;
4655 int named ATTRIBUTE_UNUSED;
4659 return ((type && AGGREGATE_TYPE_P (type))
4660 || mode == TFmode || mode == TCmode);
4664 return ((type && TREE_CODE (type) == ARRAY_TYPE)
4665 /* Consider complex values as aggregates, so care for TCmode. */
4666 || GET_MODE_SIZE (mode) > 16
4667 || (type && AGGREGATE_TYPE_P (type)
4668 && int_size_in_bytes (type) > 16));
4672 /* Handle the FUNCTION_ARG_ADVANCE macro.
4673 Update the data in CUM to advance over an argument
4674 of mode MODE and data type TYPE.
4675 TYPE is null for libcalls where that information may not be available. */
4678 function_arg_advance (cum, mode, type, named)
4679 CUMULATIVE_ARGS *cum;
4680 enum machine_mode mode;
4684 int slotno, regno, padding;
4686 /* We pass 0 for incoming_p here, it doesn't matter. */
4687 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
4689 /* If register required leading padding, add it. */
4691 cum->words += padding;
4695 cum->words += (mode != BLKmode
4696 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
4697 : ROUND_ADVANCE (int_size_in_bytes (type)));
4701 if (type && AGGREGATE_TYPE_P (type))
4703 int size = int_size_in_bytes (type);
4707 else if (size <= 16)
4709 else /* passed by reference */
4712 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
4716 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4718 cum->words += GET_MODE_SIZE (mode) / UNITS_PER_WORD;
4722 cum->words += (mode != BLKmode
4723 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
4724 : ROUND_ADVANCE (int_size_in_bytes (type)));
4729 /* Handle the FUNCTION_ARG_PADDING macro.
4730 For the 64 bit ABI structs are always stored left shifted in their
4734 function_arg_padding (mode, type)
4735 enum machine_mode mode;
4738 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
4741 /* This is the default definition. */
4742 return (! BYTES_BIG_ENDIAN
4745 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
4746 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
4747 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
4748 ? downward : upward));
4751 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
4752 For v9, function return values are subject to the same rules as arguments,
4753 except that up to 32-bytes may be returned in registers. */
4756 function_value (type, mode, incoming_p)
4758 enum machine_mode mode;
4762 int regbase = (incoming_p
4763 ? SPARC_OUTGOING_INT_ARG_FIRST
4764 : SPARC_INCOMING_INT_ARG_FIRST);
4766 if (TARGET_ARCH64 && type)
4768 if (TREE_CODE (type) == RECORD_TYPE)
4770 /* Structures up to 32 bytes in size are passed in registers,
4771 promoted to fp registers where possible. */
4773 if (int_size_in_bytes (type) > 32)
4774 abort (); /* shouldn't get here */
4776 return function_arg_record_value (type, mode, 0, 1, regbase);
4778 else if (AGGREGATE_TYPE_P (type))
4780 /* All other aggregate types are passed in an integer register
4781 in a mode corresponding to the size of the type. */
4782 HOST_WIDE_INT bytes = int_size_in_bytes (type);
4787 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
4792 && GET_MODE_CLASS (mode) == MODE_INT
4793 && GET_MODE_SIZE (mode) < UNITS_PER_WORD
4794 && type && ! AGGREGATE_TYPE_P (type))
4798 regno = BASE_RETURN_VALUE_REG (mode);
4800 regno = BASE_OUTGOING_VALUE_REG (mode);
4802 return gen_rtx_REG (mode, regno);
4805 /* Do what is necessary for `va_start'. We look at the current function
4806 to determine if stdarg or varargs is used and return the address of
4807 the first unnamed parameter. */
4810 sparc_builtin_saveregs ()
4812 int first_reg = current_function_args_info.words;
4816 for (regno = first_reg; regno < NPARM_REGS (word_mode); regno++)
4817 emit_move_insn (gen_rtx_MEM (word_mode,
4818 gen_rtx_PLUS (Pmode,
4820 GEN_INT (STACK_POINTER_OFFSET
4823 gen_rtx_REG (word_mode,
4824 BASE_INCOMING_ARG_REG (word_mode) + regno));
4826 address = gen_rtx_PLUS (Pmode,
4828 GEN_INT (STACK_POINTER_OFFSET
4829 + UNITS_PER_WORD * first_reg));
4834 /* Implement `va_start' for varargs and stdarg. */
4837 sparc_va_start (stdarg_p, valist, nextarg)
4838 int stdarg_p ATTRIBUTE_UNUSED;
4842 nextarg = expand_builtin_saveregs ();
4843 std_expand_builtin_va_start (1, valist, nextarg);
4846 /* Implement `va_arg'. */
4849 sparc_va_arg (valist, type)
4852 HOST_WIDE_INT size, rsize, align;
4857 /* Round up sizeof(type) to a word. */
4858 size = int_size_in_bytes (type);
4859 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
4864 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
4865 align = 2 * UNITS_PER_WORD;
4867 if (AGGREGATE_TYPE_P (type))
4872 size = rsize = UNITS_PER_WORD;
4880 if (AGGREGATE_TYPE_P (type)
4881 || TYPE_MODE (type) == TFmode
4882 || TYPE_MODE (type) == TCmode)
4885 size = rsize = UNITS_PER_WORD;
4892 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
4893 build_int_2 (align - 1, 0)));
4894 incr = fold (build (BIT_AND_EXPR, ptr_type_node, incr,
4895 build_int_2 (-align, -1)));
4898 addr = incr = save_expr (incr);
4899 if (BYTES_BIG_ENDIAN && size < rsize)
4901 addr = fold (build (PLUS_EXPR, ptr_type_node, incr,
4902 build_int_2 (rsize - size, 0)));
4904 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
4905 build_int_2 (rsize, 0)));
4907 incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
4908 TREE_SIDE_EFFECTS (incr) = 1;
4909 expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
4911 addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
4913 /* If the address isn't aligned properly for the type,
4914 we may need to copy to a temporary.
4915 FIXME: This is inefficient. Usually we can do this
4918 && TYPE_ALIGN (type) > BITS_PER_WORD
4921 /* FIXME: We really need to specify that the temporary is live
4922 for the whole function because expand_builtin_va_arg wants
4923 the alias set to be get_varargs_alias_set (), but in this
4924 case the alias set is that for TYPE and if the memory gets
4925 reused it will be reused with alias set TYPE. */
4926 rtx tmp = assign_temp (type, 0, 1, 0);
4929 addr_rtx = force_reg (Pmode, addr_rtx);
4930 addr_rtx = gen_rtx_MEM (BLKmode, addr_rtx);
4931 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
4932 set_mem_align (addr_rtx, BITS_PER_WORD);
4933 tmp = shallow_copy_rtx (tmp);
4934 PUT_MODE (tmp, BLKmode);
4935 set_mem_alias_set (tmp, 0);
4937 dest_addr = emit_block_move (tmp, addr_rtx, GEN_INT (rsize));
4938 if (dest_addr != NULL_RTX)
4939 addr_rtx = dest_addr;
4941 addr_rtx = XCEXP (tmp, 0, MEM);
4946 addr_rtx = force_reg (Pmode, addr_rtx);
4947 addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
4948 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
4954 /* Return the string to output a conditional branch to LABEL, which is
4955 the operand number of the label. OP is the conditional expression.
4956 XEXP (OP, 0) is assumed to be a condition code register (integer or
4957 floating point) and its mode specifies what kind of comparison we made.
4959 REVERSED is non-zero if we should reverse the sense of the comparison.
4961 ANNUL is non-zero if we should generate an annulling branch.
4963 NOOP is non-zero if we have to follow this branch by a noop.
4965 INSN, if set, is the insn. */
4968 output_cbranch (op, label, reversed, annul, noop, insn)
4971 int reversed, annul, noop;
4974 static char string[32];
4975 enum rtx_code code = GET_CODE (op);
4976 rtx cc_reg = XEXP (op, 0);
4977 enum machine_mode mode = GET_MODE (cc_reg);
4978 static char v8_labelno[] = "%lX";
4979 static char v9_icc_labelno[] = "%%icc, %lX";
4980 static char v9_xcc_labelno[] = "%%xcc, %lX";
4981 static char v9_fcc_labelno[] = "%%fccX, %lY";
4984 int labeloff, spaces = 8;
4988 /* Reversal of FP compares takes care -- an ordered compare
4989 becomes an unordered compare and vice versa. */
4990 if (mode == CCFPmode || mode == CCFPEmode)
4991 code = reverse_condition_maybe_unordered (code);
4993 code = reverse_condition (code);
4996 /* Start by writing the branch condition. */
4997 if (mode == CCFPmode || mode == CCFPEmode)
5048 /* ??? !v9: FP branches cannot be preceded by another floating point
5049 insn. Because there is currently no concept of pre-delay slots,
5050 we can fix this only by always emitting a nop before a floating
5055 strcpy (string, "nop\n\t");
5056 strcat (string, branch);
5069 if (mode == CC_NOOVmode)
5081 if (mode == CC_NOOVmode)
5102 strcpy (string, branch);
5104 spaces -= strlen (branch);
5106 /* Now add the annulling, the label, and a possible noop. */
5109 strcat (string, ",a");
5116 labelno = v8_labelno;
5122 if (insn && (note = find_reg_note (insn, REG_BR_PRED, NULL_RTX)))
5125 INTVAL (XEXP (note, 0)) & ATTR_FLAG_likely ? ",pt" : ",pn");
5130 if (mode == CCFPmode || mode == CCFPEmode)
5133 labelno = v9_fcc_labelno;
5134 /* Set the char indicating the number of the fcc reg to use. */
5135 labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
5137 else if (mode == CCXmode || mode == CCX_NOOVmode)
5138 labelno = v9_xcc_labelno;
5140 labelno = v9_icc_labelno;
5142 /* Set the char indicating the number of the operand containing the
5144 labelno[labeloff] = label + '0';
5146 strcat (string, "\t");
5148 strcat (string, " ");
5149 strcat (string, labelno);
5152 strcat (string, "\n\tnop");
5157 /* Emit a library call comparison between floating point X and Y.
5158 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
5159 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
5160 values as arguments instead of the TFmode registers themselves,
5161 that's why we cannot call emit_float_lib_cmp. */
5163 sparc_emit_float_lib_cmp (x, y, comparison)
5165 enum rtx_code comparison;
5168 rtx slot0, slot1, result, tem, tem2;
5169 enum machine_mode mode;
5174 qpfunc = (TARGET_ARCH64) ? "_Qp_feq" : "_Q_feq";
5178 qpfunc = (TARGET_ARCH64) ? "_Qp_fne" : "_Q_fne";
5182 qpfunc = (TARGET_ARCH64) ? "_Qp_fgt" : "_Q_fgt";
5186 qpfunc = (TARGET_ARCH64) ? "_Qp_fge" : "_Q_fge";
5190 qpfunc = (TARGET_ARCH64) ? "_Qp_flt" : "_Q_flt";
5194 qpfunc = (TARGET_ARCH64) ? "_Qp_fle" : "_Q_fle";
5205 qpfunc = (TARGET_ARCH64) ? "_Qp_cmp" : "_Q_cmp";
5215 if (GET_CODE (x) != MEM)
5217 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5218 emit_insn (gen_rtx_SET (VOIDmode, slot0, x));
5223 if (GET_CODE (y) != MEM)
5225 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5226 emit_insn (gen_rtx_SET (VOIDmode, slot1, y));
5231 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), 1,
5233 XEXP (slot0, 0), Pmode,
5234 XEXP (slot1, 0), Pmode);
5240 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), 1,
5242 x, TFmode, y, TFmode);
5248 /* Immediately move the result of the libcall into a pseudo
5249 register so reload doesn't clobber the value if it needs
5250 the return register for a spill reg. */
5251 result = gen_reg_rtx (mode);
5252 emit_move_insn (result, hard_libcall_value (mode));
5257 emit_cmp_insn (result, const0_rtx, NE, NULL_RTX, mode, 0);
5261 emit_cmp_insn (result, GEN_INT(3), comparison == UNORDERED ? EQ : NE,
5266 emit_cmp_insn (result, const1_rtx,
5267 comparison == UNGT ? GT : NE, NULL_RTX, mode, 0);
5270 emit_cmp_insn (result, const2_rtx, NE, NULL_RTX, mode, 0);
5273 tem = gen_reg_rtx (mode);
5275 emit_insn (gen_andsi3 (tem, result, const1_rtx));
5277 emit_insn (gen_anddi3 (tem, result, const1_rtx));
5278 emit_cmp_insn (tem, const0_rtx, NE, NULL_RTX, mode, 0);
5282 tem = gen_reg_rtx (mode);
5284 emit_insn (gen_addsi3 (tem, result, const1_rtx));
5286 emit_insn (gen_adddi3 (tem, result, const1_rtx));
5287 tem2 = gen_reg_rtx (mode);
5289 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
5291 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
5292 emit_cmp_insn (tem2, const0_rtx, comparison == UNEQ ? EQ : NE,
5298 /* Return the string to output a conditional branch to LABEL, testing
5299 register REG. LABEL is the operand number of the label; REG is the
5300 operand number of the reg. OP is the conditional expression. The mode
5301 of REG says what kind of comparison we made.
5303 REVERSED is non-zero if we should reverse the sense of the comparison.
5305 ANNUL is non-zero if we should generate an annulling branch.
5307 NOOP is non-zero if we have to follow this branch by a noop. */
5310 output_v9branch (op, reg, label, reversed, annul, noop, insn)
5313 int reversed, annul, noop;
5316 static char string[20];
5317 enum rtx_code code = GET_CODE (op);
5318 enum machine_mode mode = GET_MODE (XEXP (op, 0));
5319 static char labelno[] = "%X, %lX";
5323 /* If not floating-point or if EQ or NE, we can just reverse the code. */
5325 code = reverse_condition (code), reversed = 0;
5327 /* Only 64 bit versions of these instructions exist. */
5331 /* Start by writing the branch condition. */
5336 strcpy (string, "brnz");
5341 strcpy (string, "brz");
5346 strcpy (string, "brgez");
5351 strcpy (string, "brlz");
5356 strcpy (string, "brlez");
5361 strcpy (string, "brgz");
5369 /* Now add the annulling, reg, label, and nop. */
5372 strcat (string, ",a");
5376 if (insn && (note = find_reg_note (insn, REG_BR_PRED, NULL_RTX)))
5379 INTVAL (XEXP (note, 0)) & ATTR_FLAG_likely ? ",pt" : ",pn");
5383 labelno[1] = reg + '0';
5384 labelno[6] = label + '0';
5386 strcat (string, "\t");
5388 strcat (string, " ");
5389 strcat (string, labelno);
5392 strcat (string, "\n\tnop");
5397 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
5398 Such instructions cannot be used in the delay slot of return insn on v9.
5399 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
5403 epilogue_renumber (where, test)
5404 register rtx *where;
5407 register const char *fmt;
5409 register enum rtx_code code;
5414 code = GET_CODE (*where);
5419 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
5421 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
5422 *where = gen_rtx (REG, GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
5430 /* Do not replace the frame pointer with the stack pointer because
5431 it can cause the delayed instruction to load below the stack.
5432 This occurs when instructions like:
5434 (set (reg/i:SI 24 %i0)
5435 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
5436 (const_int -20 [0xffffffec])) 0))
5438 are in the return delayed slot. */
5440 if (GET_CODE (XEXP (*where, 0)) == REG
5441 && REGNO (XEXP (*where, 0)) == FRAME_POINTER_REGNUM
5442 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
5443 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
5448 if (SPARC_STACK_BIAS
5449 && GET_CODE (XEXP (*where, 0)) == REG
5450 && REGNO (XEXP (*where, 0)) == FRAME_POINTER_REGNUM)
5458 fmt = GET_RTX_FORMAT (code);
5460 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5465 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
5466 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
5469 else if (fmt[i] == 'e'
5470 && epilogue_renumber (&(XEXP (*where, i)), test))
5476 /* Output assembler code to return from a function. */
5479 output_return (operands)
5482 rtx delay = final_sequence ? XVECEXP (final_sequence, 0, 1) : 0;
5486 operands[0] = leaf_label;
5489 else if (current_function_uses_only_leaf_regs)
5491 /* No delay slot in a leaf function. */
5495 /* If we didn't allocate a frame pointer for the current function,
5496 the stack pointer might have been adjusted. Output code to
5499 operands[0] = GEN_INT (actual_fsize);
5501 /* Use sub of negated value in first two cases instead of add to
5502 allow actual_fsize == 4096. */
5504 if (actual_fsize <= 4096)
5506 if (SKIP_CALLERS_UNIMP_P)
5507 return "jmp\t%%o7+12\n\tsub\t%%sp, -%0, %%sp";
5509 return "retl\n\tsub\t%%sp, -%0, %%sp";
5511 else if (actual_fsize <= 8192)
5513 operands[0] = GEN_INT (actual_fsize - 4096);
5514 if (SKIP_CALLERS_UNIMP_P)
5515 return "sub\t%%sp, -4096, %%sp\n\tjmp\t%%o7+12\n\tsub\t%%sp, -%0, %%sp";
5517 return "sub\t%%sp, -4096, %%sp\n\tretl\n\tsub\t%%sp, -%0, %%sp";
5519 else if (SKIP_CALLERS_UNIMP_P)
5521 if ((actual_fsize & 0x3ff) != 0)
5522 return "sethi\t%%hi(%a0), %%g1\n\tor\t%%g1, %%lo(%a0), %%g1\n\tjmp\t%%o7+12\n\tadd\t%%sp, %%g1, %%sp";
5524 return "sethi\t%%hi(%a0), %%g1\n\tjmp\t%%o7+12\n\tadd\t%%sp, %%g1, %%sp";
5528 if ((actual_fsize & 0x3ff) != 0)
5529 return "sethi\t%%hi(%a0), %%g1\n\tor\t%%g1, %%lo(%a0), %%g1\n\tretl\n\tadd\t%%sp, %%g1, %%sp";
5531 return "sethi\t%%hi(%a0), %%g1\n\tretl\n\tadd\t%%sp, %%g1, %%sp";
5538 epilogue_renumber (&SET_DEST (PATTERN (delay)), 0);
5539 epilogue_renumber (&SET_SRC (PATTERN (delay)), 0);
5541 if (SKIP_CALLERS_UNIMP_P)
5542 return "return\t%%i7+12%#";
5544 return "return\t%%i7+8%#";
5550 if (SKIP_CALLERS_UNIMP_P)
5551 return "jmp\t%%i7+12\n\trestore";
5553 return "ret\n\trestore";
5557 /* Leaf functions and non-leaf functions have different needs. */
5560 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
5563 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
5565 static const int *const reg_alloc_orders[] = {
5566 reg_leaf_alloc_order,
5567 reg_nonleaf_alloc_order};
5570 order_regs_for_local_alloc ()
5572 static int last_order_nonleaf = 1;
5574 if (regs_ever_live[15] != last_order_nonleaf)
5576 last_order_nonleaf = !last_order_nonleaf;
5577 memcpy ((char *) reg_alloc_order,
5578 (const char *) reg_alloc_orders[last_order_nonleaf],
5579 FIRST_PSEUDO_REGISTER * sizeof (int));
5583 /* Return 1 if REG and MEM are legitimate enough to allow the various
5584 mem<-->reg splits to be run. */
5587 sparc_splitdi_legitimate (reg, mem)
5591 /* Punt if we are here by mistake. */
5592 if (! reload_completed)
5595 /* We must have an offsettable memory reference. */
5596 if (! offsettable_memref_p (mem))
5599 /* If we have legitimate args for ldd/std, we do not want
5600 the split to happen. */
5601 if ((REGNO (reg) % 2) == 0
5602 && mem_min_alignment (mem, 8))
5609 /* Return 1 if x and y are some kind of REG and they refer to
5610 different hard registers. This test is guarenteed to be
5611 run after reload. */
5614 sparc_absnegfloat_split_legitimate (x, y)
5617 if (GET_CODE (x) != REG)
5619 if (GET_CODE (y) != REG)
5621 if (REGNO (x) == REGNO (y))
5626 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
5627 This makes them candidates for using ldd and std insns.
5629 Note reg1 and reg2 *must* be hard registers. */
5632 registers_ok_for_ldd_peep (reg1, reg2)
5635 /* We might have been passed a SUBREG. */
5636 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
5639 if (REGNO (reg1) % 2 != 0)
5642 /* Integer ldd is deprecated in SPARC V9 */
5643 if (TARGET_V9 && REGNO (reg1) < 32)
5646 return (REGNO (reg1) == REGNO (reg2) - 1);
5649 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
5652 This can only happen when addr1 and addr2, the addresses in mem1
5653 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
5654 addr1 must also be aligned on a 64-bit boundary. */
5657 mems_ok_for_ldd_peep (mem1, mem2)
5664 addr1 = XEXP (mem1, 0);
5665 addr2 = XEXP (mem2, 0);
5667 /* mem1 should be aligned on a 64-bit boundary */
5668 if (MEM_ALIGN (mem1) < 64)
5671 /* Extract a register number and offset (if used) from the first addr. */
5672 if (GET_CODE (addr1) == PLUS)
5674 /* If not a REG, return zero. */
5675 if (GET_CODE (XEXP (addr1, 0)) != REG)
5679 reg1 = REGNO (XEXP (addr1, 0));
5680 /* The offset must be constant! */
5681 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
5683 offset1 = INTVAL (XEXP (addr1, 1));
5686 else if (GET_CODE (addr1) != REG)
5690 reg1 = REGNO (addr1);
5691 /* This was a simple (mem (reg)) expression. Offset is 0. */
5695 /* Make sure the second address is a (mem (plus (reg) (const_int). */
5696 if (GET_CODE (addr2) != PLUS)
5699 if (GET_CODE (XEXP (addr2, 0)) != REG
5700 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
5703 if (reg1 != REGNO (XEXP (addr2, 0)))
5706 /* The first offset must be evenly divisible by 8 to ensure the
5707 address is 64 bit aligned. */
5708 if (offset1 % 8 != 0)
5711 /* The offset for the second addr must be 4 more than the first addr. */
5712 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
5715 /* All the tests passed. addr1 and addr2 are valid for ldd and std
5720 /* Return 1 if reg is a pseudo, or is the first register in
5721 a hard register pair. This makes it a candidate for use in
5722 ldd and std insns. */
5725 register_ok_for_ldd (reg)
5728 /* We might have been passed a SUBREG. */
5729 if (GET_CODE (reg) != REG)
5732 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
5733 return (REGNO (reg) % 2 == 0);
5738 /* Print operand X (an rtx) in assembler syntax to file FILE.
5739 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
5740 For `%' followed by punctuation, CODE is the punctuation and X is null. */
5743 print_operand (file, x, code)
5751 /* Output a 'nop' if there's nothing for the delay slot. */
5752 if (dbr_sequence_length () == 0)
5753 fputs ("\n\t nop", file);
5756 /* Output an annul flag if there's nothing for the delay slot and we
5757 are optimizing. This is always used with '(' below. */
5758 /* Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
5759 this is a dbx bug. So, we only do this when optimizing. */
5760 /* On UltraSPARC, a branch in a delay slot causes a pipeline flush.
5761 Always emit a nop in case the next instruction is a branch. */
5762 if (dbr_sequence_length () == 0
5763 && (optimize && (int)sparc_cpu < PROCESSOR_V9))
5767 /* Output a 'nop' if there's nothing for the delay slot and we are
5768 not optimizing. This is always used with '*' above. */
5769 if (dbr_sequence_length () == 0
5770 && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
5771 fputs ("\n\t nop", file);
5774 /* Output the Embedded Medium/Anywhere code model base register. */
5775 fputs (EMBMEDANY_BASE_REG, file);
5778 /* Print out what we are using as the frame pointer. This might
5779 be %fp, or might be %sp+offset. */
5780 /* ??? What if offset is too big? Perhaps the caller knows it isn't? */
5781 fprintf (file, "%s+%d", frame_base_name, frame_base_offset);
5784 /* Adjust the operand to take into account a RESTORE operation. */
5785 if (GET_CODE (x) == CONST_INT)
5787 else if (GET_CODE (x) != REG)
5788 output_operand_lossage ("invalid %%Y operand");
5789 else if (REGNO (x) < 8)
5790 fputs (reg_names[REGNO (x)], file);
5791 else if (REGNO (x) >= 24 && REGNO (x) < 32)
5792 fputs (reg_names[REGNO (x)-16], file);
5794 output_operand_lossage ("invalid %%Y operand");
5797 /* Print out the low order register name of a register pair. */
5798 if (WORDS_BIG_ENDIAN)
5799 fputs (reg_names[REGNO (x)+1], file);
5801 fputs (reg_names[REGNO (x)], file);
5804 /* Print out the high order register name of a register pair. */
5805 if (WORDS_BIG_ENDIAN)
5806 fputs (reg_names[REGNO (x)], file);
5808 fputs (reg_names[REGNO (x)+1], file);
5811 /* Print out the second register name of a register pair or quad.
5812 I.e., R (%o0) => %o1. */
5813 fputs (reg_names[REGNO (x)+1], file);
5816 /* Print out the third register name of a register quad.
5817 I.e., S (%o0) => %o2. */
5818 fputs (reg_names[REGNO (x)+2], file);
5821 /* Print out the fourth register name of a register quad.
5822 I.e., T (%o0) => %o3. */
5823 fputs (reg_names[REGNO (x)+3], file);
5826 /* Print a condition code register. */
5827 if (REGNO (x) == SPARC_ICC_REG)
5829 /* We don't handle CC[X]_NOOVmode because they're not supposed
5831 if (GET_MODE (x) == CCmode)
5832 fputs ("%icc", file);
5833 else if (GET_MODE (x) == CCXmode)
5834 fputs ("%xcc", file);
5839 /* %fccN register */
5840 fputs (reg_names[REGNO (x)], file);
5843 /* Print the operand's address only. */
5844 output_address (XEXP (x, 0));
5847 /* In this case we need a register. Use %g0 if the
5848 operand is const0_rtx. */
5850 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
5852 fputs ("%g0", file);
5859 switch (GET_CODE (x))
5861 case IOR: fputs ("or", file); break;
5862 case AND: fputs ("and", file); break;
5863 case XOR: fputs ("xor", file); break;
5864 default: output_operand_lossage ("invalid %%A operand");
5869 switch (GET_CODE (x))
5871 case IOR: fputs ("orn", file); break;
5872 case AND: fputs ("andn", file); break;
5873 case XOR: fputs ("xnor", file); break;
5874 default: output_operand_lossage ("invalid %%B operand");
5878 /* These are used by the conditional move instructions. */
5882 enum rtx_code rc = GET_CODE (x);
5886 enum machine_mode mode = GET_MODE (XEXP (x, 0));
5887 if (mode == CCFPmode || mode == CCFPEmode)
5888 rc = reverse_condition_maybe_unordered (GET_CODE (x));
5890 rc = reverse_condition (GET_CODE (x));
5894 case NE: fputs ("ne", file); break;
5895 case EQ: fputs ("e", file); break;
5896 case GE: fputs ("ge", file); break;
5897 case GT: fputs ("g", file); break;
5898 case LE: fputs ("le", file); break;
5899 case LT: fputs ("l", file); break;
5900 case GEU: fputs ("geu", file); break;
5901 case GTU: fputs ("gu", file); break;
5902 case LEU: fputs ("leu", file); break;
5903 case LTU: fputs ("lu", file); break;
5904 case LTGT: fputs ("lg", file); break;
5905 case UNORDERED: fputs ("u", file); break;
5906 case ORDERED: fputs ("o", file); break;
5907 case UNLT: fputs ("ul", file); break;
5908 case UNLE: fputs ("ule", file); break;
5909 case UNGT: fputs ("ug", file); break;
5910 case UNGE: fputs ("uge", file); break;
5911 case UNEQ: fputs ("ue", file); break;
5912 default: output_operand_lossage (code == 'c'
5913 ? "invalid %%c operand"
5914 : "invalid %%C operand");
5919 /* These are used by the movr instruction pattern. */
5923 enum rtx_code rc = (code == 'd'
5924 ? reverse_condition (GET_CODE (x))
5928 case NE: fputs ("ne", file); break;
5929 case EQ: fputs ("e", file); break;
5930 case GE: fputs ("gez", file); break;
5931 case LT: fputs ("lz", file); break;
5932 case LE: fputs ("lez", file); break;
5933 case GT: fputs ("gz", file); break;
5934 default: output_operand_lossage (code == 'd'
5935 ? "invalid %%d operand"
5936 : "invalid %%D operand");
5943 /* Print a sign-extended character. */
5944 int i = INTVAL (x) & 0xff;
5947 fprintf (file, "%d", i);
5952 /* Operand must be a MEM; write its address. */
5953 if (GET_CODE (x) != MEM)
5954 output_operand_lossage ("invalid %%f operand");
5955 output_address (XEXP (x, 0));
5959 /* Do nothing special. */
5963 /* Undocumented flag. */
5964 output_operand_lossage ("invalid operand output code");
5967 if (GET_CODE (x) == REG)
5968 fputs (reg_names[REGNO (x)], file);
5969 else if (GET_CODE (x) == MEM)
5972 /* Poor Sun assembler doesn't understand absolute addressing. */
5973 if (CONSTANT_P (XEXP (x, 0)))
5974 fputs ("%g0+", file);
5975 output_address (XEXP (x, 0));
5978 else if (GET_CODE (x) == HIGH)
5980 fputs ("%hi(", file);
5981 output_addr_const (file, XEXP (x, 0));
5984 else if (GET_CODE (x) == LO_SUM)
5986 print_operand (file, XEXP (x, 0), 0);
5987 if (TARGET_CM_MEDMID)
5988 fputs ("+%l44(", file);
5990 fputs ("+%lo(", file);
5991 output_addr_const (file, XEXP (x, 1));
5994 else if (GET_CODE (x) == CONST_DOUBLE
5995 && (GET_MODE (x) == VOIDmode
5996 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
5998 if (CONST_DOUBLE_HIGH (x) == 0)
5999 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
6000 else if (CONST_DOUBLE_HIGH (x) == -1
6001 && CONST_DOUBLE_LOW (x) < 0)
6002 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
6004 output_operand_lossage ("long long constant not a valid immediate operand");
6006 else if (GET_CODE (x) == CONST_DOUBLE)
6007 output_operand_lossage ("floating point constant not a valid immediate operand");
6008 else { output_addr_const (file, x); }
6011 /* This function outputs assembler code for VALUE to FILE, where VALUE is
6012 a 64 bit (DImode) value. */
6014 /* ??? If there is a 64 bit counterpart to .word that the assembler
6015 understands, then using that would simply this code greatly. */
6016 /* ??? We only output .xword's for symbols and only then in environments
6017 where the assembler can handle them. */
6020 output_double_int (file, value)
6024 if (GET_CODE (value) == CONST_INT)
6026 /* ??? This has endianness issues. */
6027 #if HOST_BITS_PER_WIDE_INT == 64
6028 HOST_WIDE_INT xword = INTVAL (value);
6029 HOST_WIDE_INT high, low;
6031 high = (xword >> 32) & 0xffffffff;
6032 low = xword & 0xffffffff;
6033 ASM_OUTPUT_INT (file, GEN_INT (high));
6034 ASM_OUTPUT_INT (file, GEN_INT (low));
6036 if (INTVAL (value) < 0)
6037 ASM_OUTPUT_INT (file, constm1_rtx);
6039 ASM_OUTPUT_INT (file, const0_rtx);
6040 ASM_OUTPUT_INT (file, value);
6043 else if (GET_CODE (value) == CONST_DOUBLE)
6045 ASM_OUTPUT_INT (file, GEN_INT (CONST_DOUBLE_HIGH (value)));
6046 ASM_OUTPUT_INT (file, GEN_INT (CONST_DOUBLE_LOW (value)));
6048 else if (GET_CODE (value) == SYMBOL_REF
6049 || GET_CODE (value) == CONST
6050 || GET_CODE (value) == PLUS
6051 || (TARGET_ARCH64 &&
6052 (GET_CODE (value) == LABEL_REF
6053 || GET_CODE (value) == CODE_LABEL
6054 || GET_CODE (value) == MINUS)))
6058 ASM_OUTPUT_INT (file, const0_rtx);
6059 ASM_OUTPUT_INT (file, value);
6063 fprintf (file, "\t%s\t", ASM_LONGLONG);
6064 output_addr_const (file, value);
6065 fprintf (file, "\n");
6072 /* Return the value of a code used in the .proc pseudo-op that says
6073 what kind of result this function returns. For non-C types, we pick
6074 the closest C type. */
6076 #ifndef CHAR_TYPE_SIZE
6077 #define CHAR_TYPE_SIZE BITS_PER_UNIT
6080 #ifndef SHORT_TYPE_SIZE
6081 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
6084 #ifndef INT_TYPE_SIZE
6085 #define INT_TYPE_SIZE BITS_PER_WORD
6088 #ifndef LONG_TYPE_SIZE
6089 #define LONG_TYPE_SIZE BITS_PER_WORD
6092 #ifndef LONG_LONG_TYPE_SIZE
6093 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
6096 #ifndef FLOAT_TYPE_SIZE
6097 #define FLOAT_TYPE_SIZE BITS_PER_WORD
6100 #ifndef DOUBLE_TYPE_SIZE
6101 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6104 #ifndef LONG_DOUBLE_TYPE_SIZE
6105 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6109 sparc_type_code (type)
6112 register unsigned long qualifiers = 0;
6113 register unsigned shift;
6115 /* Only the first 30 bits of the qualifier are valid. We must refrain from
6116 setting more, since some assemblers will give an error for this. Also,
6117 we must be careful to avoid shifts of 32 bits or more to avoid getting
6118 unpredictable results. */
6120 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
6122 switch (TREE_CODE (type))
6128 qualifiers |= (3 << shift);
6133 qualifiers |= (2 << shift);
6137 case REFERENCE_TYPE:
6139 qualifiers |= (1 << shift);
6143 return (qualifiers | 8);
6146 case QUAL_UNION_TYPE:
6147 return (qualifiers | 9);
6150 return (qualifiers | 10);
6153 return (qualifiers | 16);
6156 /* If this is a range type, consider it to be the underlying
6158 if (TREE_TYPE (type) != 0)
6161 /* Carefully distinguish all the standard types of C,
6162 without messing up if the language is not C. We do this by
6163 testing TYPE_PRECISION and TREE_UNSIGNED. The old code used to
6164 look at both the names and the above fields, but that's redundant.
6165 Any type whose size is between two C types will be considered
6166 to be the wider of the two types. Also, we do not have a
6167 special code to use for "long long", so anything wider than
6168 long is treated the same. Note that we can't distinguish
6169 between "int" and "long" in this code if they are the same
6170 size, but that's fine, since neither can the assembler. */
6172 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
6173 return (qualifiers | (TREE_UNSIGNED (type) ? 12 : 2));
6175 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
6176 return (qualifiers | (TREE_UNSIGNED (type) ? 13 : 3));
6178 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
6179 return (qualifiers | (TREE_UNSIGNED (type) ? 14 : 4));
6182 return (qualifiers | (TREE_UNSIGNED (type) ? 15 : 5));
6185 /* If this is a range type, consider it to be the underlying
6187 if (TREE_TYPE (type) != 0)
6190 /* Carefully distinguish all the standard types of C,
6191 without messing up if the language is not C. */
6193 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
6194 return (qualifiers | 6);
6197 return (qualifiers | 7);
6199 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
6200 /* ??? We need to distinguish between double and float complex types,
6201 but I don't know how yet because I can't reach this code from
6202 existing front-ends. */
6203 return (qualifiers | 7); /* Who knows? */
6205 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
6206 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
6207 case FILE_TYPE: /* GNU Pascal FILE type. */
6208 case SET_TYPE: /* GNU Pascal SET type. */
6209 case LANG_TYPE: /* ? */
6213 abort (); /* Not a type! */
6220 /* Nested function support. */
6222 /* Emit RTL insns to initialize the variable parts of a trampoline.
6223 FNADDR is an RTX for the address of the function's pure code.
6224 CXT is an RTX for the static chain value for the function.
6226 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
6227 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
6228 (to store insns). This is a bit excessive. Perhaps a different
6229 mechanism would be better here.
6231 Emit enough FLUSH insns to synchronize the data and instruction caches. */
6234 sparc_initialize_trampoline (tramp, fnaddr, cxt)
6235 rtx tramp, fnaddr, cxt;
6237 /* SPARC 32 bit trampoline:
6240 sethi %hi(static), %g2
6242 or %g2, %lo(static), %g2
6244 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
6245 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
6247 #ifdef TRANSFER_FROM_TRAMPOLINE
6248 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
6249 0, VOIDmode, 1, tramp, Pmode);
6252 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
6253 expand_binop (SImode, ior_optab,
6254 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
6255 size_int (10), 0, 1),
6256 GEN_INT (0x03000000),
6257 NULL_RTX, 1, OPTAB_DIRECT));
6259 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6260 expand_binop (SImode, ior_optab,
6261 expand_shift (RSHIFT_EXPR, SImode, cxt,
6262 size_int (10), 0, 1),
6263 GEN_INT (0x05000000),
6264 NULL_RTX, 1, OPTAB_DIRECT));
6266 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6267 expand_binop (SImode, ior_optab,
6268 expand_and (fnaddr, GEN_INT (0x3ff), NULL_RTX),
6269 GEN_INT (0x81c06000),
6270 NULL_RTX, 1, OPTAB_DIRECT));
6272 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6273 expand_binop (SImode, ior_optab,
6274 expand_and (cxt, GEN_INT (0x3ff), NULL_RTX),
6275 GEN_INT (0x8410a000),
6276 NULL_RTX, 1, OPTAB_DIRECT));
6278 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
6279 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
6280 aligned on a 16 byte boundary so one flush clears it all. */
6281 if (sparc_cpu != PROCESSOR_ULTRASPARC)
6282 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
6283 plus_constant (tramp, 8)))));
6286 /* The 64 bit version is simpler because it makes more sense to load the
6287 values as "immediate" data out of the trampoline. It's also easier since
6288 we can read the PC without clobbering a register. */
6291 sparc64_initialize_trampoline (tramp, fnaddr, cxt)
6292 rtx tramp, fnaddr, cxt;
6294 #ifdef TRANSFER_FROM_TRAMPOLINE
6295 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
6296 0, VOIDmode, 1, tramp, Pmode);
6307 emit_move_insn (gen_rtx_MEM (SImode, tramp),
6308 GEN_INT (0x83414000));
6309 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6310 GEN_INT (0xca586018));
6311 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6312 GEN_INT (0x81c14000));
6313 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6314 GEN_INT (0xca586010));
6315 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
6316 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
6317 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
6319 if (sparc_cpu != PROCESSOR_ULTRASPARC)
6320 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
6323 /* Subroutines to support a flat (single) register window calling
6326 /* Single-register window sparc stack frames look like:
6328 Before call After call
6329 +-----------------------+ +-----------------------+
6331 mem | caller's temps. | | caller's temps. |
6333 +-----------------------+ +-----------------------+
6335 | arguments on stack. | | arguments on stack. |
6337 +-----------------------+FP+92->+-----------------------+
6338 | 6 words to save | | 6 words to save |
6339 | arguments passed | | arguments passed |
6340 | in registers, even | | in registers, even |
6341 | if not passed. | | if not passed. |
6342 SP+68->+-----------------------+FP+68->+-----------------------+
6343 | 1 word struct addr | | 1 word struct addr |
6344 +-----------------------+FP+64->+-----------------------+
6346 | 16 word reg save area | | 16 word reg save area |
6348 SP->+-----------------------+ FP->+-----------------------+
6350 | fp/alu reg moves |
6351 FP-16->+-----------------------+
6355 +-----------------------+
6357 | fp register save |
6359 +-----------------------+
6361 | gp register save |
6363 +-----------------------+
6365 | alloca allocations |
6367 +-----------------------+
6369 | arguments on stack |
6371 SP+92->+-----------------------+
6373 | arguments passed |
6374 | in registers, even |
6375 low | if not passed. |
6376 memory SP+68->+-----------------------+
6377 | 1 word struct addr |
6378 SP+64->+-----------------------+
6380 I 16 word reg save area |
6382 SP->+-----------------------+ */
6384 /* Structure to be filled in by sparc_flat_compute_frame_size with register
6385 save masks, and offsets for the current function. */
6387 struct sparc_frame_info
6389 unsigned long total_size; /* # bytes that the entire frame takes up. */
6390 unsigned long var_size; /* # bytes that variables take up. */
6391 unsigned long args_size; /* # bytes that outgoing arguments take up. */
6392 unsigned long extra_size; /* # bytes of extra gunk. */
6393 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
6394 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
6395 unsigned long gmask; /* Mask of saved gp registers. */
6396 unsigned long fmask; /* Mask of saved fp registers. */
6397 unsigned long reg_offset; /* Offset from new sp to store regs. */
6398 int initialized; /* Nonzero if frame size already calculated. */
6401 /* Current frame information calculated by sparc_flat_compute_frame_size. */
6402 struct sparc_frame_info current_frame_info;
6404 /* Zero structure to initialize current_frame_info. */
6405 struct sparc_frame_info zero_frame_info;
6407 /* Tell prologue and epilogue if register REGNO should be saved / restored. */
6409 #define RETURN_ADDR_REGNUM 15
6410 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
6411 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
6413 #define MUST_SAVE_REGISTER(regno) \
6414 ((regs_ever_live[regno] && !call_used_regs[regno]) \
6415 || (regno == FRAME_POINTER_REGNUM && frame_pointer_needed) \
6416 || (regno == RETURN_ADDR_REGNUM && regs_ever_live[RETURN_ADDR_REGNUM]))
6418 /* Return the bytes needed to compute the frame pointer from the current
6422 sparc_flat_compute_frame_size (size)
6423 int size; /* # of var. bytes allocated. */
6426 unsigned long total_size; /* # bytes that the entire frame takes up. */
6427 unsigned long var_size; /* # bytes that variables take up. */
6428 unsigned long args_size; /* # bytes that outgoing arguments take up. */
6429 unsigned long extra_size; /* # extra bytes. */
6430 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
6431 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
6432 unsigned long gmask; /* Mask of saved gp registers. */
6433 unsigned long fmask; /* Mask of saved fp registers. */
6434 unsigned long reg_offset; /* Offset to register save area. */
6435 int need_aligned_p; /* 1 if need the save area 8 byte aligned. */
6437 /* This is the size of the 16 word reg save area, 1 word struct addr
6438 area, and 4 word fp/alu register copy area. */
6439 extra_size = -STARTING_FRAME_OFFSET + FIRST_PARM_OFFSET(0);
6449 if (!leaf_function_p ())
6451 /* Also include the size needed for the 6 parameter registers. */
6452 args_size = current_function_outgoing_args_size + 24;
6454 total_size = var_size + args_size;
6456 /* Calculate space needed for gp registers. */
6457 for (regno = 1; regno <= 31; regno++)
6459 if (MUST_SAVE_REGISTER (regno))
6461 /* If we need to save two regs in a row, ensure there's room to bump
6462 up the address to align it to a doubleword boundary. */
6463 if ((regno & 0x1) == 0 && MUST_SAVE_REGISTER (regno+1))
6465 if (gp_reg_size % 8 != 0)
6467 gp_reg_size += 2 * UNITS_PER_WORD;
6468 gmask |= 3 << regno;
6474 gp_reg_size += UNITS_PER_WORD;
6475 gmask |= 1 << regno;
6480 /* Calculate space needed for fp registers. */
6481 for (regno = 32; regno <= 63; regno++)
6483 if (regs_ever_live[regno] && !call_used_regs[regno])
6485 fp_reg_size += UNITS_PER_WORD;
6486 fmask |= 1 << (regno - 32);
6493 reg_offset = FIRST_PARM_OFFSET(0) + args_size;
6494 /* Ensure save area is 8 byte aligned if we need it. */
6496 if (need_aligned_p && n != 0)
6498 total_size += 8 - n;
6499 reg_offset += 8 - n;
6501 total_size += gp_reg_size + fp_reg_size;
6504 /* If we must allocate a stack frame at all, we must also allocate
6505 room for register window spillage, so as to be binary compatible
6506 with libraries and operating systems that do not use -mflat. */
6508 total_size += extra_size;
6512 total_size = SPARC_STACK_ALIGN (total_size);
6514 /* Save other computed information. */
6515 current_frame_info.total_size = total_size;
6516 current_frame_info.var_size = var_size;
6517 current_frame_info.args_size = args_size;
6518 current_frame_info.extra_size = extra_size;
6519 current_frame_info.gp_reg_size = gp_reg_size;
6520 current_frame_info.fp_reg_size = fp_reg_size;
6521 current_frame_info.gmask = gmask;
6522 current_frame_info.fmask = fmask;
6523 current_frame_info.reg_offset = reg_offset;
6524 current_frame_info.initialized = reload_completed;
6526 /* Ok, we're done. */
6530 /* Save/restore registers in GMASK and FMASK at register BASE_REG plus offset
6533 BASE_REG must be 8 byte aligned. This allows us to test OFFSET for
6534 appropriate alignment and use DOUBLEWORD_OP when we can. We assume
6535 [BASE_REG+OFFSET] will always be a valid address.
6537 WORD_OP is either "st" for save, "ld" for restore.
6538 DOUBLEWORD_OP is either "std" for save, "ldd" for restore. */
6541 sparc_flat_save_restore (file, base_reg, offset, gmask, fmask, word_op,
6542 doubleword_op, base_offset)
6544 const char *base_reg;
6545 unsigned int offset;
6546 unsigned long gmask;
6547 unsigned long fmask;
6548 const char *word_op;
6549 const char *doubleword_op;
6550 unsigned long base_offset;
6554 if (gmask == 0 && fmask == 0)
6557 /* Save registers starting from high to low. We've already saved the
6558 previous frame pointer and previous return address for the debugger's
6559 sake. The debugger allows us to not need a nop in the epilog if at least
6560 one register is reloaded in addition to return address. */
6564 for (regno = 1; regno <= 31; regno++)
6566 if ((gmask & (1L << regno)) != 0)
6568 if ((regno & 0x1) == 0 && ((gmask & (1L << (regno+1))) != 0))
6570 /* We can save two registers in a row. If we're not at a
6571 double word boundary, move to one.
6572 sparc_flat_compute_frame_size ensures there's room to do
6574 if (offset % 8 != 0)
6575 offset += UNITS_PER_WORD;
6577 if (word_op[0] == 's')
6579 fprintf (file, "\t%s\t%s, [%s+%d]\n",
6580 doubleword_op, reg_names[regno],
6582 if (dwarf2out_do_frame ())
6584 char *l = dwarf2out_cfi_label ();
6585 dwarf2out_reg_save (l, regno, offset + base_offset);
6587 (l, regno+1, offset+base_offset + UNITS_PER_WORD);
6591 fprintf (file, "\t%s\t[%s+%d], %s\n",
6592 doubleword_op, base_reg, offset,
6595 offset += 2 * UNITS_PER_WORD;
6600 if (word_op[0] == 's')
6602 fprintf (file, "\t%s\t%s, [%s+%d]\n",
6603 word_op, reg_names[regno],
6605 if (dwarf2out_do_frame ())
6606 dwarf2out_reg_save ("", regno, offset + base_offset);
6609 fprintf (file, "\t%s\t[%s+%d], %s\n",
6610 word_op, base_reg, offset, reg_names[regno]);
6612 offset += UNITS_PER_WORD;
6620 for (regno = 32; regno <= 63; regno++)
6622 if ((fmask & (1L << (regno - 32))) != 0)
6624 if (word_op[0] == 's')
6626 fprintf (file, "\t%s\t%s, [%s+%d]\n",
6627 word_op, reg_names[regno],
6629 if (dwarf2out_do_frame ())
6630 dwarf2out_reg_save ("", regno, offset + base_offset);
6633 fprintf (file, "\t%s\t[%s+%d], %s\n",
6634 word_op, base_reg, offset, reg_names[regno]);
6636 offset += UNITS_PER_WORD;
6642 /* Set up the stack and frame (if desired) for the function. */
6645 sparc_flat_function_prologue (file, size)
6649 const char *sp_str = reg_names[STACK_POINTER_REGNUM];
6650 unsigned long gmask = current_frame_info.gmask;
6652 sparc_output_scratch_registers (file);
6654 /* This is only for the human reader. */
6655 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
6656 fprintf (file, "\t%s# vars= %ld, regs= %d/%d, args= %d, extra= %ld\n",
6658 current_frame_info.var_size,
6659 current_frame_info.gp_reg_size / 4,
6660 current_frame_info.fp_reg_size / 4,
6661 current_function_outgoing_args_size,
6662 current_frame_info.extra_size);
6664 size = SPARC_STACK_ALIGN (size);
6665 size = (! current_frame_info.initialized
6666 ? sparc_flat_compute_frame_size (size)
6667 : current_frame_info.total_size);
6669 /* These cases shouldn't happen. Catch them now. */
6670 if (size == 0 && (gmask || current_frame_info.fmask))
6673 /* Allocate our stack frame by decrementing %sp.
6674 At present, the only algorithm gdb can use to determine if this is a
6675 flat frame is if we always set %i7 if we set %sp. This can be optimized
6676 in the future by putting in some sort of debugging information that says
6677 this is a `flat' function. However, there is still the case of debugging
6678 code without such debugging information (including cases where most fns
6679 have such info, but there is one that doesn't). So, always do this now
6680 so we don't get a lot of code out there that gdb can't handle.
6681 If the frame pointer isn't needn't then that's ok - gdb won't be able to
6682 distinguish us from a non-flat function but there won't (and shouldn't)
6683 be any differences anyway. The return pc is saved (if necessary) right
6684 after %i7 so gdb won't have to look too far to find it. */
6687 unsigned int reg_offset = current_frame_info.reg_offset;
6688 const char *const fp_str = reg_names[FRAME_POINTER_REGNUM];
6689 static const char *const t1_str = "%g1";
6691 /* Things get a little tricky if local variables take up more than ~4096
6692 bytes and outgoing arguments take up more than ~4096 bytes. When that
6693 happens, the register save area can't be accessed from either end of
6694 the frame. Handle this by decrementing %sp to the start of the gp
6695 register save area, save the regs, update %i7, and then set %sp to its
6696 final value. Given that we only have one scratch register to play
6697 with it is the cheapest solution, and it helps gdb out as it won't
6698 slow down recognition of flat functions.
6699 Don't change the order of insns emitted here without checking with
6700 the gdb folk first. */
6702 /* Is the entire register save area offsettable from %sp? */
6703 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
6707 fprintf (file, "\tadd\t%s, %d, %s\n",
6708 sp_str, (int) -size, sp_str);
6709 if (gmask & FRAME_POINTER_MASK)
6711 fprintf (file, "\tst\t%s, [%s+%d]\n",
6712 fp_str, sp_str, reg_offset);
6713 fprintf (file, "\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
6714 sp_str, (int) -size, fp_str, ASM_COMMENT_START);
6720 fprintf (file, "\tset\t");
6721 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
6722 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
6723 t1_str, sp_str, t1_str, sp_str);
6724 if (gmask & FRAME_POINTER_MASK)
6726 fprintf (file, "\tst\t%s, [%s+%d]\n",
6727 fp_str, sp_str, reg_offset);
6728 fprintf (file, "\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
6729 sp_str, t1_str, fp_str, ASM_COMMENT_START);
6733 if (dwarf2out_do_frame ())
6735 char *l = dwarf2out_cfi_label ();
6736 if (gmask & FRAME_POINTER_MASK)
6738 dwarf2out_reg_save (l, FRAME_POINTER_REGNUM,
6739 reg_offset - 4 - size);
6740 dwarf2out_def_cfa (l, FRAME_POINTER_REGNUM, 0);
6743 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size);
6745 if (gmask & RETURN_ADDR_MASK)
6747 fprintf (file, "\tst\t%s, [%s+%d]\n",
6748 reg_names[RETURN_ADDR_REGNUM], sp_str, reg_offset);
6749 if (dwarf2out_do_frame ())
6750 dwarf2out_return_save ("", reg_offset - size);
6753 sparc_flat_save_restore (file, sp_str, reg_offset,
6754 gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK),
6755 current_frame_info.fmask,
6756 "st", "std", -size);
6760 /* Subtract %sp in two steps, but make sure there is always a
6761 64 byte register save area, and %sp is properly aligned. */
6762 /* Amount to decrement %sp by, the first time. */
6763 unsigned HOST_WIDE_INT size1 = ((size - reg_offset + 64) + 15) & -16;
6764 /* Offset to register save area from %sp. */
6765 unsigned HOST_WIDE_INT offset = size1 - (size - reg_offset);
6769 fprintf (file, "\tadd\t%s, %d, %s\n",
6770 sp_str, (int) -size1, sp_str);
6771 if (gmask & FRAME_POINTER_MASK)
6773 fprintf (file, "\tst\t%s, [%s+%d]\n\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
6774 fp_str, sp_str, (int) offset, sp_str, (int) -size1,
6775 fp_str, ASM_COMMENT_START);
6781 fprintf (file, "\tset\t");
6782 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size1);
6783 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
6784 t1_str, sp_str, t1_str, sp_str);
6785 if (gmask & FRAME_POINTER_MASK)
6787 fprintf (file, "\tst\t%s, [%s+%d]\n\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
6788 fp_str, sp_str, (int) offset, sp_str, t1_str,
6789 fp_str, ASM_COMMENT_START);
6793 if (dwarf2out_do_frame ())
6795 char *l = dwarf2out_cfi_label ();
6796 if (gmask & FRAME_POINTER_MASK)
6798 dwarf2out_reg_save (l, FRAME_POINTER_REGNUM,
6799 offset - 4 - size1);
6800 dwarf2out_def_cfa (l, FRAME_POINTER_REGNUM, 0);
6803 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size1);
6805 if (gmask & RETURN_ADDR_MASK)
6807 fprintf (file, "\tst\t%s, [%s+%d]\n",
6808 reg_names[RETURN_ADDR_REGNUM], sp_str, (int) offset);
6809 if (dwarf2out_do_frame ())
6810 /* offset - size1 == reg_offset - size
6811 if reg_offset were updated above like offset. */
6812 dwarf2out_return_save ("", offset - size1);
6815 sparc_flat_save_restore (file, sp_str, offset,
6816 gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK),
6817 current_frame_info.fmask,
6818 "st", "std", -size1);
6819 fprintf (file, "\tset\t");
6820 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size - size1);
6821 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
6822 t1_str, sp_str, t1_str, sp_str);
6823 if (dwarf2out_do_frame ())
6824 if (! (gmask & FRAME_POINTER_MASK))
6825 dwarf2out_def_cfa ("", STACK_POINTER_REGNUM, size);
6829 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
6832 /* Do any necessary cleanup after a function to restore stack, frame,
6836 sparc_flat_function_epilogue (file, size)
6840 rtx epilogue_delay = current_function_epilogue_delay_list;
6841 int noepilogue = FALSE;
6843 /* This is only for the human reader. */
6844 fprintf (file, "\t%s#EPILOGUE#\n", ASM_COMMENT_START);
6846 /* The epilogue does not depend on any registers, but the stack
6847 registers, so we assume that if we have 1 pending nop, it can be
6848 ignored, and 2 it must be filled (2 nops occur for integer
6849 multiply and divide). */
6851 size = SPARC_STACK_ALIGN (size);
6852 size = (!current_frame_info.initialized
6853 ? sparc_flat_compute_frame_size (size)
6854 : current_frame_info.total_size);
6856 if (size == 0 && epilogue_delay == 0)
6858 rtx insn = get_last_insn ();
6860 /* If the last insn was a BARRIER, we don't have to write any code
6861 because a jump (aka return) was put there. */
6862 if (GET_CODE (insn) == NOTE)
6863 insn = prev_nonnote_insn (insn);
6864 if (insn && GET_CODE (insn) == BARRIER)
6870 unsigned HOST_WIDE_INT reg_offset = current_frame_info.reg_offset;
6871 unsigned HOST_WIDE_INT size1;
6872 const char *const sp_str = reg_names[STACK_POINTER_REGNUM];
6873 const char *const fp_str = reg_names[FRAME_POINTER_REGNUM];
6874 static const char *const t1_str = "%g1";
6876 /* In the reload sequence, we don't need to fill the load delay
6877 slots for most of the loads, also see if we can fill the final
6878 delay slot if not otherwise filled by the reload sequence. */
6882 fprintf (file, "\tset\t");
6883 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
6884 fprintf (file, ", %s\n", t1_str);
6887 if (frame_pointer_needed)
6890 fprintf (file,"\tsub\t%s, %s, %s\t\t%s# sp not trusted here\n",
6891 fp_str, t1_str, sp_str, ASM_COMMENT_START);
6893 fprintf (file,"\tsub\t%s, %d, %s\t\t%s# sp not trusted here\n",
6894 fp_str, (int) size, sp_str, ASM_COMMENT_START);
6897 /* Is the entire register save area offsettable from %sp? */
6898 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
6904 /* Restore %sp in two steps, but make sure there is always a
6905 64 byte register save area, and %sp is properly aligned. */
6906 /* Amount to increment %sp by, the first time. */
6907 size1 = ((reg_offset - 64 - 16) + 15) & -16;
6908 /* Offset to register save area from %sp. */
6909 reg_offset = size1 - reg_offset;
6911 fprintf (file, "\tset\t");
6912 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size1);
6913 fprintf (file, ", %s\n\tadd\t%s, %s, %s\n",
6914 t1_str, sp_str, t1_str, sp_str);
6917 /* We must restore the frame pointer and return address reg first
6918 because they are treated specially by the prologue output code. */
6919 if (current_frame_info.gmask & FRAME_POINTER_MASK)
6921 fprintf (file, "\tld\t[%s+%d], %s\n",
6922 sp_str, (int) reg_offset, fp_str);
6925 if (current_frame_info.gmask & RETURN_ADDR_MASK)
6927 fprintf (file, "\tld\t[%s+%d], %s\n",
6928 sp_str, (int) reg_offset, reg_names[RETURN_ADDR_REGNUM]);
6932 /* Restore any remaining saved registers. */
6933 sparc_flat_save_restore (file, sp_str, reg_offset,
6934 current_frame_info.gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK),
6935 current_frame_info.fmask,
6938 /* If we had to increment %sp in two steps, record it so the second
6939 restoration in the epilogue finishes up. */
6945 fprintf (file, "\tset\t");
6946 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
6947 fprintf (file, ", %s\n", t1_str);
6951 if (current_function_returns_struct)
6952 fprintf (file, "\tjmp\t%%o7+12\n");
6954 fprintf (file, "\tretl\n");
6956 /* If the only register saved is the return address, we need a
6957 nop, unless we have an instruction to put into it. Otherwise
6958 we don't since reloading multiple registers doesn't reference
6959 the register being loaded. */
6965 final_scan_insn (XEXP (epilogue_delay, 0), file, 1, -2, 1);
6968 else if (size > 4095)
6969 fprintf (file, "\tadd\t%s, %s, %s\n", sp_str, t1_str, sp_str);
6972 fprintf (file, "\tadd\t%s, %d, %s\n", sp_str, (int) size, sp_str);
6975 fprintf (file, "\tnop\n");
6978 /* Reset state info for each function. */
6979 current_frame_info = zero_frame_info;
6981 sparc_output_deferred_case_vectors ();
6984 /* Define the number of delay slots needed for the function epilogue.
6986 On the sparc, we need a slot if either no stack has been allocated,
6987 or the only register saved is the return register. */
6990 sparc_flat_epilogue_delay_slots ()
6992 if (!current_frame_info.initialized)
6993 (void) sparc_flat_compute_frame_size (get_frame_size ());
6995 if (current_frame_info.total_size == 0)
7001 /* Return true if TRIAL is a valid insn for the epilogue delay slot.
7002 Any single length instruction which doesn't reference the stack or frame
7006 sparc_flat_eligible_for_epilogue_delay (trial, slot)
7008 int slot ATTRIBUTE_UNUSED;
7010 rtx pat = PATTERN (trial);
7012 if (get_attr_length (trial) != 1)
7015 if (! reg_mentioned_p (stack_pointer_rtx, pat)
7016 && ! reg_mentioned_p (frame_pointer_rtx, pat))
7022 /* Adjust the cost of a scheduling dependency. Return the new cost of
7023 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7026 supersparc_adjust_cost (insn, link, dep_insn, cost)
7032 enum attr_type insn_type;
7034 if (! recog_memoized (insn))
7037 insn_type = get_attr_type (insn);
7039 if (REG_NOTE_KIND (link) == 0)
7041 /* Data dependency; DEP_INSN writes a register that INSN reads some
7044 /* if a load, then the dependence must be on the memory address;
7045 add an extra "cycle". Note that the cost could be two cycles
7046 if the reg was written late in an instruction group; we ca not tell
7048 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
7051 /* Get the delay only if the address of the store is the dependence. */
7052 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
7054 rtx pat = PATTERN(insn);
7055 rtx dep_pat = PATTERN (dep_insn);
7057 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7058 return cost; /* This should not happen! */
7060 /* The dependency between the two instructions was on the data that
7061 is being stored. Assume that this implies that the address of the
7062 store is not dependent. */
7063 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7066 return cost + 3; /* An approximation. */
7069 /* A shift instruction cannot receive its data from an instruction
7070 in the same cycle; add a one cycle penalty. */
7071 if (insn_type == TYPE_SHIFT)
7072 return cost + 3; /* Split before cascade into shift. */
7076 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7077 INSN writes some cycles later. */
7079 /* These are only significant for the fpu unit; writing a fp reg before
7080 the fpu has finished with it stalls the processor. */
7082 /* Reusing an integer register causes no problems. */
7083 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7091 hypersparc_adjust_cost (insn, link, dep_insn, cost)
7097 enum attr_type insn_type, dep_type;
7098 rtx pat = PATTERN(insn);
7099 rtx dep_pat = PATTERN (dep_insn);
7101 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7104 insn_type = get_attr_type (insn);
7105 dep_type = get_attr_type (dep_insn);
7107 switch (REG_NOTE_KIND (link))
7110 /* Data dependency; DEP_INSN writes a register that INSN reads some
7117 /* Get the delay iff the address of the store is the dependence. */
7118 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7121 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7128 /* If a load, then the dependence must be on the memory address. If
7129 the addresses aren't equal, then it might be a false dependency */
7130 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7132 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7133 || GET_CODE (SET_DEST (dep_pat)) != MEM
7134 || GET_CODE (SET_SRC (pat)) != MEM
7135 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
7136 XEXP (SET_SRC (pat), 0)))
7144 /* Compare to branch latency is 0. There is no benefit from
7145 separating compare and branch. */
7146 if (dep_type == TYPE_COMPARE)
7148 /* Floating point compare to branch latency is less than
7149 compare to conditional move. */
7150 if (dep_type == TYPE_FPCMP)
7159 /* Anti-dependencies only penalize the fpu unit. */
7160 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7172 ultrasparc_adjust_cost (insn, link, dep_insn, cost)
7178 enum attr_type insn_type, dep_type;
7179 rtx pat = PATTERN(insn);
7180 rtx dep_pat = PATTERN (dep_insn);
7182 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7185 insn_type = get_attr_type (insn);
7186 dep_type = get_attr_type (dep_insn);
7188 /* Nothing issues in parallel with integer multiplies, so
7189 mark as zero cost since the scheduler can not do anything
7191 if (insn_type == TYPE_IMUL)
7194 #define SLOW_FP(dep_type) \
7195 (dep_type == TYPE_FPSQRTS || dep_type == TYPE_FPSQRTD || \
7196 dep_type == TYPE_FPDIVS || dep_type == TYPE_FPDIVD)
7198 switch (REG_NOTE_KIND (link))
7201 /* Data dependency; DEP_INSN writes a register that INSN reads some
7204 if (dep_type == TYPE_CMOVE)
7206 /* Instructions that read the result of conditional moves cannot
7207 be in the same group or the following group. */
7213 /* UltraSPARC can dual issue a store and an instruction setting
7214 the value stored, except for divide and square root. */
7216 if (! SLOW_FP (dep_type))
7221 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7224 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7225 /* The dependency between the two instructions is on the data
7226 that is being stored. Assume that the address of the store
7227 is not also dependent. */
7234 /* A load does not return data until at least 11 cycles after
7235 a store to the same location. 3 cycles are accounted for
7236 in the load latency; add the other 8 here. */
7237 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7239 /* If the addresses are not equal this may be a false
7240 dependency because pointer aliasing could not be
7241 determined. Add only 2 cycles in that case. 2 is
7242 an arbitrary compromise between 8, which would cause
7243 the scheduler to generate worse code elsewhere to
7244 compensate for a dependency which might not really
7246 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7247 || GET_CODE (SET_SRC (pat)) != MEM
7248 || GET_CODE (SET_DEST (dep_pat)) != MEM
7249 || ! rtx_equal_p (XEXP (SET_SRC (pat), 0),
7250 XEXP (SET_DEST (dep_pat), 0)))
7258 /* Compare to branch latency is 0. There is no benefit from
7259 separating compare and branch. */
7260 if (dep_type == TYPE_COMPARE)
7262 /* Floating point compare to branch latency is less than
7263 compare to conditional move. */
7264 if (dep_type == TYPE_FPCMP)
7269 /* FMOVR class instructions can not issue in the same cycle
7270 or the cycle after an instruction which writes any
7271 integer register. Model this as cost 2 for dependent
7273 if (dep_type == TYPE_IALU
7276 /* Otherwise check as for integer conditional moves. */
7279 /* Conditional moves involving integer registers wait until
7280 3 cycles after loads return data. The interlock applies
7281 to all loads, not just dependent loads, but that is hard
7283 if (dep_type == TYPE_LOAD || dep_type == TYPE_SLOAD)
7293 /* Divide and square root lock destination registers for full latency. */
7294 if (! SLOW_FP (dep_type))
7298 case REG_DEP_OUTPUT:
7299 /* IEU and FPU instruction that have the same destination
7300 register cannot be grouped together. */
7307 /* Other costs not accounted for:
7308 - Single precision floating point loads lock the other half of
7309 the even/odd register pair.
7310 - Several hazards associated with ldd/std are ignored because these
7311 instructions are rarely generated for V9.
7312 - The floating point pipeline can not have both a single and double
7313 precision operation active at the same time. Format conversions
7314 and graphics instructions are given honorary double precision status.
7315 - call and jmpl are always the first instruction in a group. */
7323 sparc_adjust_cost(insn, link, dep, cost)
7331 case PROCESSOR_SUPERSPARC:
7332 cost = supersparc_adjust_cost (insn, link, dep, cost);
7334 case PROCESSOR_HYPERSPARC:
7335 case PROCESSOR_SPARCLITE86X:
7336 cost = hypersparc_adjust_cost (insn, link, dep, cost);
7338 case PROCESSOR_ULTRASPARC:
7339 cost = ultrasparc_adjust_cost (insn, link, dep, cost);
7347 /* This describes the state of the UltraSPARC pipeline during
7348 instruction scheduling. */
7350 #define TMASK(__x) ((unsigned)1 << ((int)(__x)))
7351 #define UMASK(__x) ((unsigned)1 << ((int)(__x)))
7353 enum ultra_code { NONE=0, /* no insn at all */
7354 IEU0, /* shifts and conditional moves */
7355 IEU1, /* condition code setting insns, calls+jumps */
7356 IEUN, /* all other single cycle ieu insns */
7357 LSU, /* loads and stores */
7359 FPM, /* FPU pipeline 1, multiplies and divides */
7360 FPA, /* FPU pipeline 2, all other operations */
7361 SINGLE, /* single issue instructions */
7364 static enum ultra_code ultra_code_from_mask PARAMS ((int));
7365 static void ultra_schedule_insn PARAMS ((rtx *, rtx *, int, enum ultra_code));
7367 static const char *const ultra_code_names[NUM_ULTRA_CODES] = {
7368 "NONE", "IEU0", "IEU1", "IEUN", "LSU", "CTI",
7369 "FPM", "FPA", "SINGLE" };
7371 struct ultrasparc_pipeline_state {
7372 /* The insns in this group. */
7375 /* The code for each insn. */
7376 enum ultra_code codes[4];
7378 /* Which insns in this group have been committed by the
7379 scheduler. This is how we determine how many more
7380 can issue this cycle. */
7383 /* How many insns in this group. */
7386 /* Mask of free slots still in this group. */
7387 char free_slot_mask;
7389 /* The slotter uses the following to determine what other
7390 insn types can still make their way into this group. */
7391 char contents [NUM_ULTRA_CODES];
7395 #define ULTRA_NUM_HIST 8
7396 static struct ultrasparc_pipeline_state ultra_pipe_hist[ULTRA_NUM_HIST];
7397 static int ultra_cur_hist;
7398 static int ultra_cycles_elapsed;
7400 #define ultra_pipe (ultra_pipe_hist[ultra_cur_hist])
7402 /* Given TYPE_MASK compute the ultra_code it has. */
7403 static enum ultra_code
7404 ultra_code_from_mask (type_mask)
7407 if (type_mask & (TMASK (TYPE_SHIFT) | TMASK (TYPE_CMOVE)))
7409 else if (type_mask & (TMASK (TYPE_COMPARE) |
7411 TMASK (TYPE_SIBCALL) |
7412 TMASK (TYPE_UNCOND_BRANCH)))
7414 else if (type_mask & TMASK (TYPE_IALU))
7416 else if (type_mask & (TMASK (TYPE_LOAD) | TMASK (TYPE_SLOAD) |
7417 TMASK (TYPE_STORE) | TMASK (TYPE_FPLOAD) |
7418 TMASK (TYPE_FPSTORE)))
7420 else if (type_mask & (TMASK (TYPE_FPMUL) | TMASK (TYPE_FPDIVS) |
7421 TMASK (TYPE_FPDIVD) | TMASK (TYPE_FPSQRTS) |
7422 TMASK (TYPE_FPSQRTD)))
7424 else if (type_mask & (TMASK (TYPE_FPMOVE) | TMASK (TYPE_FPCMOVE) |
7425 TMASK (TYPE_FP) | TMASK (TYPE_FPCMP)))
7427 else if (type_mask & TMASK (TYPE_BRANCH))
7433 /* Check INSN (a conditional move) and make sure that it's
7434 results are available at this cycle. Return 1 if the
7435 results are in fact ready. */
7437 ultra_cmove_results_ready_p (insn)
7440 struct ultrasparc_pipeline_state *up;
7443 /* If this got dispatched in the previous
7444 group, the results are not ready. */
7445 entry = (ultra_cur_hist - 1) & (ULTRA_NUM_HIST - 1);
7446 up = &ultra_pipe_hist[entry];
7449 if (up->group[slot] == insn)
7455 /* Walk backwards in pipeline history looking for FPU
7456 operations which use a mode different than FPMODE and
7457 will create a stall if an insn using FPMODE were to be
7458 dispatched this cycle. */
7460 ultra_fpmode_conflict_exists (fpmode)
7461 enum machine_mode fpmode;
7466 hist_ent = (ultra_cur_hist - 1) & (ULTRA_NUM_HIST - 1);
7467 if (ultra_cycles_elapsed < 4)
7468 hist_lim = ultra_cycles_elapsed;
7471 while (hist_lim > 0)
7473 struct ultrasparc_pipeline_state *up = &ultra_pipe_hist[hist_ent];
7478 rtx insn = up->group[slot];
7479 enum machine_mode this_mode;
7483 || GET_CODE (insn) != INSN
7484 || (pat = PATTERN (insn)) == 0
7485 || GET_CODE (pat) != SET)
7488 this_mode = GET_MODE (SET_DEST (pat));
7489 if ((this_mode != SFmode
7490 && this_mode != DFmode)
7491 || this_mode == fpmode)
7494 /* If it is not FMOV, FABS, FNEG, FDIV, or FSQRT then
7495 we will get a stall. Loads and stores are independent
7497 if (GET_CODE (SET_SRC (pat)) != ABS
7498 && GET_CODE (SET_SRC (pat)) != NEG
7499 && ((TMASK (get_attr_type (insn)) &
7500 (TMASK (TYPE_FPDIVS) | TMASK (TYPE_FPDIVD) |
7501 TMASK (TYPE_FPMOVE) | TMASK (TYPE_FPSQRTS) |
7502 TMASK (TYPE_FPSQRTD) |
7503 TMASK (TYPE_LOAD) | TMASK (TYPE_STORE))) == 0))
7507 hist_ent = (hist_ent - 1) & (ULTRA_NUM_HIST - 1);
7510 /* No conflicts, safe to dispatch. */
7514 /* Find an instruction in LIST which has one of the
7515 type attributes enumerated in TYPE_MASK. START
7516 says where to begin the search.
7518 NOTE: This scheme depends upon the fact that we
7519 have less than 32 distinct type attributes. */
7521 static int ultra_types_avail;
7524 ultra_find_type (type_mask, list, start)
7531 /* Short circuit if no such insn exists in the ready
7533 if ((type_mask & ultra_types_avail) == 0)
7536 for (i = start; i >= 0; i--)
7540 if (recog_memoized (insn) >= 0
7541 && (TMASK(get_attr_type (insn)) & type_mask))
7543 enum machine_mode fpmode = SFmode;
7546 int check_depend = 0;
7547 int check_fpmode_conflict = 0;
7549 if (GET_CODE (insn) == INSN
7550 && (pat = PATTERN(insn)) != 0
7551 && GET_CODE (pat) == SET
7552 && !(type_mask & (TMASK (TYPE_STORE) |
7553 TMASK (TYPE_FPSTORE))))
7556 if (GET_MODE (SET_DEST (pat)) == SFmode
7557 || GET_MODE (SET_DEST (pat)) == DFmode)
7559 fpmode = GET_MODE (SET_DEST (pat));
7560 check_fpmode_conflict = 1;
7567 rtx slot_insn = ultra_pipe.group[slot];
7570 /* Already issued, bad dependency, or FPU
7573 && (slot_pat = PATTERN (slot_insn)) != 0
7574 && ((insn == slot_insn)
7575 || (check_depend == 1
7576 && GET_CODE (slot_insn) == INSN
7577 && GET_CODE (slot_pat) == SET
7578 && ((GET_CODE (SET_DEST (slot_pat)) == REG
7579 && GET_CODE (SET_SRC (pat)) == REG
7580 && REGNO (SET_DEST (slot_pat)) ==
7581 REGNO (SET_SRC (pat)))
7582 || (GET_CODE (SET_DEST (slot_pat)) == SUBREG
7583 && GET_CODE (SET_SRC (pat)) == SUBREG
7584 && REGNO (SUBREG_REG (SET_DEST (slot_pat))) ==
7585 REGNO (SUBREG_REG (SET_SRC (pat)))
7586 && SUBREG_BYTE (SET_DEST (slot_pat)) ==
7587 SUBREG_BYTE (SET_SRC (pat)))))
7588 || (check_fpmode_conflict == 1
7589 && GET_CODE (slot_insn) == INSN
7590 && GET_CODE (slot_pat) == SET
7591 && (GET_MODE (SET_DEST (slot_pat)) == SFmode
7592 || GET_MODE (SET_DEST (slot_pat)) == DFmode)
7593 && GET_MODE (SET_DEST (slot_pat)) != fpmode)))
7597 /* Check for peculiar result availability and dispatch
7598 interference situations. */
7600 && ultra_cycles_elapsed > 0)
7604 for (link = LOG_LINKS (insn); link; link = XEXP (link, 1))
7606 rtx link_insn = XEXP (link, 0);
7607 if (GET_CODE (link_insn) == INSN
7608 && recog_memoized (link_insn) >= 0
7609 && (TMASK (get_attr_type (link_insn)) &
7610 (TMASK (TYPE_CMOVE) | TMASK (TYPE_FPCMOVE)))
7611 && ! ultra_cmove_results_ready_p (link_insn))
7615 if (check_fpmode_conflict
7616 && ultra_fpmode_conflict_exists (fpmode))
7629 ultra_build_types_avail (ready, n_ready)
7633 int i = n_ready - 1;
7635 ultra_types_avail = 0;
7638 rtx insn = ready[i];
7640 if (recog_memoized (insn) >= 0)
7641 ultra_types_avail |= TMASK (get_attr_type (insn));
7647 /* Place insn pointed to my IP into the pipeline.
7648 Make element THIS of READY be that insn if it
7649 is not already. TYPE indicates the pipeline class
7650 this insn falls into. */
7652 ultra_schedule_insn (ip, ready, this, type)
7656 enum ultra_code type;
7659 char mask = ultra_pipe.free_slot_mask;
7662 /* Obtain free slot. */
7663 for (pipe_slot = 0; pipe_slot < 4; pipe_slot++)
7664 if ((mask & (1 << pipe_slot)) != 0)
7669 /* In it goes, and it hasn't been committed yet. */
7670 ultra_pipe.group[pipe_slot] = *ip;
7671 ultra_pipe.codes[pipe_slot] = type;
7672 ultra_pipe.contents[type] = 1;
7674 (UMASK (IEUN) | UMASK (IEU0) | UMASK (IEU1)))
7675 ultra_pipe.num_ieu_insns += 1;
7677 ultra_pipe.free_slot_mask = (mask & ~(1 << pipe_slot));
7678 ultra_pipe.group_size += 1;
7679 ultra_pipe.commit[pipe_slot] = 0;
7681 /* Update ready list. */
7683 while (ip != &ready[this])
7691 /* Advance to the next pipeline group. */
7693 ultra_flush_pipeline ()
7695 ultra_cur_hist = (ultra_cur_hist + 1) & (ULTRA_NUM_HIST - 1);
7696 ultra_cycles_elapsed += 1;
7697 memset ((char *) &ultra_pipe, 0, sizeof ultra_pipe);
7698 ultra_pipe.free_slot_mask = 0xf;
7701 /* Init our data structures for this current block. */
7703 ultrasparc_sched_init ()
7705 memset ((char *) ultra_pipe_hist, 0, sizeof ultra_pipe_hist);
7707 ultra_cycles_elapsed = 0;
7708 ultra_pipe.free_slot_mask = 0xf;
7712 sparc_sched_init (dump, sched_verbose, max_ready)
7713 FILE *dump ATTRIBUTE_UNUSED;
7714 int sched_verbose ATTRIBUTE_UNUSED;
7715 int max_ready ATTRIBUTE_UNUSED;
7717 if (sparc_cpu == PROCESSOR_ULTRASPARC)
7718 ultrasparc_sched_init ();
7721 /* INSN has been scheduled, update pipeline commit state
7722 and return how many instructions are still to be
7723 scheduled in this group. */
7725 ultrasparc_variable_issue (insn)
7728 struct ultrasparc_pipeline_state *up = &ultra_pipe;
7729 int i, left_to_fire;
7732 for (i = 0; i < 4; i++)
7734 if (up->group[i] == 0)
7737 if (up->group[i] == insn)
7741 else if (! up->commit[i])
7745 return left_to_fire;
7749 sparc_variable_issue (dump, sched_verbose, insn, cim)
7750 FILE *dump ATTRIBUTE_UNUSED;
7751 int sched_verbose ATTRIBUTE_UNUSED;
7755 if (sparc_cpu == PROCESSOR_ULTRASPARC)
7756 return ultrasparc_variable_issue (insn);
7761 /* In actual_hazard_this_instance, we may have yanked some
7762 instructions from the ready list due to conflict cost
7763 adjustments. If so, and such an insn was in our pipeline
7764 group, remove it and update state. */
7766 ultra_rescan_pipeline_state (ready, n_ready)
7770 struct ultrasparc_pipeline_state *up = &ultra_pipe;
7773 for (i = 0; i < 4; i++)
7775 rtx insn = up->group[i];
7781 /* If it has been committed, then it was removed from
7782 the ready list because it was actually scheduled,
7783 and that is not the case we are searching for here. */
7784 if (up->commit[i] != 0)
7787 for (j = n_ready - 1; j >= 0; j--)
7788 if (ready[j] == insn)
7791 /* If we didn't find it, toss it. */
7794 enum ultra_code ucode = up->codes[i];
7797 up->codes[i] = NONE;
7798 up->contents[ucode] = 0;
7800 (UMASK (IEUN) | UMASK (IEU0) | UMASK (IEU1)))
7801 up->num_ieu_insns -= 1;
7803 up->free_slot_mask |= (1 << i);
7804 up->group_size -= 1;
7811 ultrasparc_sched_reorder (dump, sched_verbose, ready, n_ready)
7817 struct ultrasparc_pipeline_state *up = &ultra_pipe;
7824 fprintf (dump, "\n;;\tUltraSPARC Looking at [");
7825 for (n = n_ready - 1; n >= 0; n--)
7827 rtx insn = ready[n];
7828 enum ultra_code ucode;
7830 if (recog_memoized (insn) < 0)
7832 ucode = ultra_code_from_mask (TMASK (get_attr_type (insn)));
7834 fprintf (dump, "%s(%d) ",
7835 ultra_code_names[ucode],
7838 fprintf (dump, "%s(%d)",
7839 ultra_code_names[ucode],
7842 fprintf (dump, "]\n");
7845 this_insn = n_ready - 1;
7847 /* Skip over junk we don't understand. */
7848 while ((this_insn >= 0)
7849 && recog_memoized (ready[this_insn]) < 0)
7852 ultra_build_types_avail (ready, this_insn + 1);
7854 while (this_insn >= 0) {
7855 int old_group_size = up->group_size;
7857 if (up->group_size != 0)
7861 num_committed = (up->commit[0] + up->commit[1] +
7862 up->commit[2] + up->commit[3]);
7863 /* If nothing has been commited from our group, or all of
7864 them have. Clear out the (current cycle's) pipeline
7865 state and start afresh. */
7866 if (num_committed == 0
7867 || num_committed == up->group_size)
7869 ultra_flush_pipeline ();
7875 /* OK, some ready list insns got requeued and thus removed
7876 from the ready list. Account for this fact. */
7877 ultra_rescan_pipeline_state (ready, n_ready);
7879 /* Something "changed", make this look like a newly
7880 formed group so the code at the end of the loop
7881 knows that progress was in fact made. */
7882 if (up->group_size != old_group_size)
7887 if (up->group_size == 0)
7889 /* If the pipeline is (still) empty and we have any single
7890 group insns, get them out now as this is a good time. */
7891 rtx *ip = ultra_find_type ((TMASK (TYPE_RETURN) |
7892 TMASK (TYPE_IMUL) | TMASK (TYPE_CMOVE) |
7893 TMASK (TYPE_MULTI) | TMASK (TYPE_MISC)),
7897 ultra_schedule_insn (ip, ready, this_insn, SINGLE);
7901 /* If we are not in the process of emptying out the pipe, try to
7902 obtain an instruction which must be the first in it's group. */
7903 ip = ultra_find_type ((TMASK (TYPE_CALL) |
7904 TMASK (TYPE_SIBCALL) |
7905 TMASK (TYPE_CALL_NO_DELAY_SLOT) |
7906 TMASK (TYPE_UNCOND_BRANCH)),
7910 ultra_schedule_insn (ip, ready, this_insn, IEU1);
7913 else if ((ip = ultra_find_type ((TMASK (TYPE_FPDIVS) |
7914 TMASK (TYPE_FPDIVD) |
7915 TMASK (TYPE_FPSQRTS) |
7916 TMASK (TYPE_FPSQRTD)),
7917 ready, this_insn)) != 0)
7919 ultra_schedule_insn (ip, ready, this_insn, FPM);
7924 /* Try to fill the integer pipeline. First, look for an IEU0 specific
7925 operation. We can't do more IEU operations if the first 3 slots are
7926 all full or we have dispatched two IEU insns already. */
7927 if ((up->free_slot_mask & 0x7) != 0
7928 && up->num_ieu_insns < 2
7929 && up->contents[IEU0] == 0
7930 && up->contents[IEUN] == 0)
7932 rtx *ip = ultra_find_type (TMASK(TYPE_SHIFT), ready, this_insn);
7935 ultra_schedule_insn (ip, ready, this_insn, IEU0);
7940 /* If we can, try to find an IEU1 specific or an unnamed
7942 if ((up->free_slot_mask & 0x7) != 0
7943 && up->num_ieu_insns < 2)
7945 rtx *ip = ultra_find_type ((TMASK (TYPE_IALU) |
7946 (up->contents[IEU1] == 0 ? TMASK (TYPE_COMPARE) : 0)),
7952 ultra_schedule_insn (ip, ready, this_insn,
7953 (!up->contents[IEU1]
7954 && get_attr_type (insn) == TYPE_COMPARE)
7960 /* If only one IEU insn has been found, try to find another unnamed
7961 IEU operation or an IEU1 specific one. */
7962 if ((up->free_slot_mask & 0x7) != 0
7963 && up->num_ieu_insns < 2)
7966 int tmask = TMASK (TYPE_IALU);
7968 if (!up->contents[IEU1])
7969 tmask |= TMASK (TYPE_COMPARE);
7970 ip = ultra_find_type (tmask, ready, this_insn);
7975 ultra_schedule_insn (ip, ready, this_insn,
7976 (!up->contents[IEU1]
7977 && get_attr_type (insn) == TYPE_COMPARE)
7983 /* Try for a load or store, but such an insn can only be issued
7984 if it is within' one of the first 3 slots. */
7985 if ((up->free_slot_mask & 0x7) != 0
7986 && up->contents[LSU] == 0)
7988 rtx *ip = ultra_find_type ((TMASK (TYPE_LOAD) | TMASK (TYPE_SLOAD) |
7989 TMASK (TYPE_STORE) | TMASK (TYPE_FPLOAD) |
7990 TMASK (TYPE_FPSTORE)), ready, this_insn);
7993 ultra_schedule_insn (ip, ready, this_insn, LSU);
7998 /* Now find FPU operations, first FPM class. But not divisions or
7999 square-roots because those will break the group up. Unlike all
8000 the previous types, these can go in any slot. */
8001 if (up->free_slot_mask != 0
8002 && up->contents[FPM] == 0)
8004 rtx *ip = ultra_find_type (TMASK (TYPE_FPMUL), ready, this_insn);
8007 ultra_schedule_insn (ip, ready, this_insn, FPM);
8012 /* Continue on with FPA class if we have not filled the group already. */
8013 if (up->free_slot_mask != 0
8014 && up->contents[FPA] == 0)
8016 rtx *ip = ultra_find_type ((TMASK (TYPE_FPMOVE) | TMASK (TYPE_FPCMOVE) |
8017 TMASK (TYPE_FP) | TMASK (TYPE_FPCMP)),
8021 ultra_schedule_insn (ip, ready, this_insn, FPA);
8026 /* Finally, maybe stick a branch in here. */
8027 if (up->free_slot_mask != 0
8028 && up->contents[CTI] == 0)
8030 rtx *ip = ultra_find_type (TMASK (TYPE_BRANCH), ready, this_insn);
8032 /* Try to slip in a branch only if it is one of the
8033 next 2 in the ready list. */
8034 if (ip && ((&ready[this_insn] - ip) < 2))
8036 ultra_schedule_insn (ip, ready, this_insn, CTI);
8042 for (i = 0; i < 4; i++)
8043 if ((up->free_slot_mask & (1 << i)) == 0)
8046 /* See if we made any progress... */
8047 if (old_group_size != up->group_size)
8050 /* Clean out the (current cycle's) pipeline state
8051 and try once more. If we placed no instructions
8052 into the pipeline at all, it means a real hard
8053 conflict exists with some earlier issued instruction
8054 so we must advance to the next cycle to clear it up. */
8055 if (up->group_size == 0)
8057 ultra_flush_pipeline ();
8062 memset ((char *) &ultra_pipe, 0, sizeof ultra_pipe);
8063 ultra_pipe.free_slot_mask = 0xf;
8071 fprintf (dump, ";;\tUltraSPARC Launched [");
8072 gsize = up->group_size;
8073 for (n = 0; n < 4; n++)
8075 rtx insn = up->group[n];
8082 fprintf (dump, "%s(%d) ",
8083 ultra_code_names[up->codes[n]],
8086 fprintf (dump, "%s(%d)",
8087 ultra_code_names[up->codes[n]],
8090 fprintf (dump, "]\n");
8095 sparc_sched_reorder (dump, sched_verbose, ready, n_readyp, clock)
8100 int clock ATTRIBUTE_UNUSED;
8102 if (sparc_cpu == PROCESSOR_ULTRASPARC)
8103 ultrasparc_sched_reorder (dump, sched_verbose, ready, *n_readyp);
8104 return sparc_issue_rate ();
8115 /* Assume V9 processors are capable of at least dual-issue. */
8117 case PROCESSOR_SUPERSPARC:
8119 case PROCESSOR_HYPERSPARC:
8120 case PROCESSOR_SPARCLITE86X:
8122 case PROCESSOR_ULTRASPARC:
8131 register rtx pat = PATTERN (insn);
8133 switch (GET_CODE (SET_SRC (pat)))
8135 /* Load and some shift instructions zero extend. */
8138 /* sethi clears the high bits */
8140 /* LO_SUM is used with sethi. sethi cleared the high
8141 bits and the values used with lo_sum are positive */
8143 /* Store flag stores 0 or 1 */
8153 rtx op0 = XEXP (SET_SRC (pat), 0);
8154 rtx op1 = XEXP (SET_SRC (pat), 1);
8155 if (GET_CODE (op1) == CONST_INT)
8156 return INTVAL (op1) >= 0;
8157 if (GET_CODE (op0) != REG)
8159 if (sparc_check_64 (op0, insn) == 1)
8161 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
8166 rtx op0 = XEXP (SET_SRC (pat), 0);
8167 rtx op1 = XEXP (SET_SRC (pat), 1);
8168 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
8170 if (GET_CODE (op1) == CONST_INT)
8171 return INTVAL (op1) >= 0;
8172 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
8176 return GET_MODE (SET_SRC (pat)) == SImode;
8177 /* Positive integers leave the high bits zero. */
8179 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
8181 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
8184 return - (GET_MODE (SET_SRC (pat)) == SImode);
8186 return sparc_check_64 (SET_SRC (pat), insn);
8192 /* We _ought_ to have only one kind per function, but... */
8193 static rtx sparc_addr_diff_list;
8194 static rtx sparc_addr_list;
8197 sparc_defer_case_vector (lab, vec, diff)
8201 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
8203 sparc_addr_diff_list
8204 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
8206 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
8210 sparc_output_addr_vec (vec)
8213 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8214 int idx, vlen = XVECLEN (body, 0);
8216 #ifdef ASM_OUTPUT_ADDR_VEC_START
8217 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8220 #ifdef ASM_OUTPUT_CASE_LABEL
8221 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8224 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8227 for (idx = 0; idx < vlen; idx++)
8229 ASM_OUTPUT_ADDR_VEC_ELT
8230 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
8233 #ifdef ASM_OUTPUT_ADDR_VEC_END
8234 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8239 sparc_output_addr_diff_vec (vec)
8242 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8243 rtx base = XEXP (XEXP (body, 0), 0);
8244 int idx, vlen = XVECLEN (body, 1);
8246 #ifdef ASM_OUTPUT_ADDR_VEC_START
8247 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8250 #ifdef ASM_OUTPUT_CASE_LABEL
8251 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8254 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8257 for (idx = 0; idx < vlen; idx++)
8259 ASM_OUTPUT_ADDR_DIFF_ELT
8262 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
8263 CODE_LABEL_NUMBER (base));
8266 #ifdef ASM_OUTPUT_ADDR_VEC_END
8267 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8272 sparc_output_deferred_case_vectors ()
8277 if (sparc_addr_list == NULL_RTX
8278 && sparc_addr_diff_list == NULL_RTX)
8281 /* Align to cache line in the function's code section. */
8282 function_section (current_function_decl);
8284 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
8286 ASM_OUTPUT_ALIGN (asm_out_file, align);
8288 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
8289 sparc_output_addr_vec (XEXP (t, 0));
8290 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
8291 sparc_output_addr_diff_vec (XEXP (t, 0));
8293 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
8296 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
8297 unknown. Return 1 if the high bits are zero, -1 if the register is
8300 sparc_check_64 (x, insn)
8303 /* If a register is set only once it is safe to ignore insns this
8304 code does not know how to handle. The loop will either recognize
8305 the single set and return the correct value or fail to recognize
8310 if (GET_CODE (x) != REG)
8313 if (GET_MODE (x) == DImode)
8314 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
8316 if (flag_expensive_optimizations
8317 && REG_N_SETS (REGNO (y)) == 1)
8323 insn = get_last_insn_anywhere ();
8328 while ((insn = PREV_INSN (insn)))
8330 switch (GET_CODE (insn))
8343 rtx pat = PATTERN (insn);
8344 if (GET_CODE (pat) != SET)
8346 if (rtx_equal_p (x, SET_DEST (pat)))
8347 return set_extends (insn);
8348 if (y && rtx_equal_p (y, SET_DEST (pat)))
8349 return set_extends (insn);
8350 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
8359 sparc_v8plus_shift (operands, insn, opcode)
8364 static char asm_code[60];
8366 if (GET_CODE (operands[3]) == SCRATCH)
8367 operands[3] = operands[0];
8368 if (GET_CODE (operands[1]) == CONST_INT)
8370 output_asm_insn ("mov\t%1, %3", operands);
8374 output_asm_insn ("sllx\t%H1, 32, %3", operands);
8375 if (sparc_check_64 (operands[1], insn) <= 0)
8376 output_asm_insn ("srl\t%L1, 0, %L1", operands);
8377 output_asm_insn ("or\t%L1, %3, %3", operands);
8380 strcpy(asm_code, opcode);
8381 if (which_alternative != 2)
8382 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
8384 return strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
8388 /* Return 1 if DEST and SRC reference only global and in registers. */
8391 sparc_return_peephole_ok (dest, src)
8396 if (current_function_uses_only_leaf_regs)
8398 if (GET_CODE (src) != CONST_INT
8399 && (GET_CODE (src) != REG || ! IN_OR_GLOBAL_P (src)))
8401 return IN_OR_GLOBAL_P (dest);
8404 /* Output assembler code to FILE to increment profiler label # LABELNO
8405 for profiling a function entry.
8407 32 bit sparc uses %g2 as the STATIC_CHAIN_REGNUM which gets clobbered
8408 during profiling so we need to save/restore it around the call to mcount.
8409 We're guaranteed that a save has just been done, and we use the space
8410 allocated for intreg/fpreg value passing. */
8413 sparc_function_profiler (file, labelno)
8418 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
8420 if (! TARGET_ARCH64)
8421 fputs ("\tst\t%g2, [%fp-4]\n", file);
8423 fputs ("\tsethi\t%hi(", file);
8424 assemble_name (file, buf);
8425 fputs ("), %o0\n", file);
8427 fputs ("\tcall\t", file);
8428 assemble_name (file, MCOUNT_FUNCTION);
8431 fputs ("\t or\t%o0, %lo(", file);
8432 assemble_name (file, buf);
8433 fputs ("), %o0\n", file);
8435 if (! TARGET_ARCH64)
8436 fputs ("\tld\t[%fp-4], %g2\n", file);
8440 /* Mark ARG, which is really a struct ultrasparc_pipline_state *, for
8444 mark_ultrasparc_pipeline_state (arg)
8447 struct ultrasparc_pipeline_state *ups;
8450 ups = (struct ultrasparc_pipeline_state *) arg;
8451 for (i = 0; i < sizeof (ups->group) / sizeof (rtx); ++i)
8452 ggc_mark_rtx (ups->group[i]);
8455 /* Called to register all of our global variables with the garbage
8459 sparc_add_gc_roots ()
8461 ggc_add_rtx_root (&sparc_compare_op0, 1);
8462 ggc_add_rtx_root (&sparc_compare_op1, 1);
8463 ggc_add_rtx_root (&leaf_label, 1);
8464 ggc_add_rtx_root (&global_offset_table, 1);
8465 ggc_add_rtx_root (&get_pc_symbol, 1);
8466 ggc_add_rtx_root (&sparc_addr_diff_list, 1);
8467 ggc_add_rtx_root (&sparc_addr_list, 1);
8468 ggc_add_root (ultra_pipe_hist, ARRAY_SIZE (ultra_pipe_hist),
8469 sizeof (ultra_pipe_hist[0]), &mark_ultrasparc_pipeline_state);
8472 #ifdef OBJECT_FORMAT_ELF
8474 sparc_elf_asm_named_section (name, flags)
8478 if (flags & SECTION_MERGE)
8480 /* entsize cannot be expressed in this section attributes
8482 default_elf_asm_named_section (name, flags);
8486 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
8488 if (!(flags & SECTION_DEBUG))
8489 fputs (",#alloc", asm_out_file);
8490 if (flags & SECTION_WRITE)
8491 fputs (",#write", asm_out_file);
8492 if (flags & SECTION_CODE)
8493 fputs (",#execinstr", asm_out_file);
8495 /* ??? Handle SECTION_BSS. */
8497 fputc ('\n', asm_out_file);
8499 #endif /* OBJECT_FORMAT_ELF */