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 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"
34 #include "insn-flags.h"
36 #include "insn-attr.h"
45 /* 1 if the caller has placed an "unimp" insn immediately after the call.
46 This is used in v8 code when calling a function that returns a structure.
47 v9 doesn't have this. Be careful to have this test be the same as that
50 #define SKIP_CALLERS_UNIMP_P \
51 (!TARGET_ARCH64 && current_function_returns_struct \
52 && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))) \
53 && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl))) \
56 /* Global variables for machine-dependent things. */
58 /* Size of frame. Need to know this to emit return insns from leaf procedures.
59 ACTUAL_FSIZE is set by compute_frame_size() which is called during the
60 reload pass. This is important as the value is later used in insn
61 scheduling (to see what can go in a delay slot).
62 APPARENT_FSIZE is the size of the stack less the register save area and less
63 the outgoing argument area. It is used when saving call preserved regs. */
64 static int apparent_fsize;
65 static int actual_fsize;
67 /* Number of live general or floating point registers needed to be saved
68 (as 4-byte quantities). This is only done if TARGET_EPILOGUE. */
69 static int num_gfregs;
71 /* Save the operands last given to a compare for use when we
72 generate a scc or bcc insn. */
74 rtx sparc_compare_op0, sparc_compare_op1;
76 /* We may need an epilogue if we spill too many registers.
77 If this is non-zero, then we branch here for the epilogue. */
78 static rtx leaf_label;
82 /* Vector to say how input registers are mapped to output
83 registers. FRAME_POINTER_REGNUM cannot be remapped by
84 this function to eliminate it. You must use -fomit-frame-pointer
86 char leaf_reg_remap[] =
87 { 0, 1, 2, 3, 4, 5, 6, 7,
88 -1, -1, -1, -1, -1, -1, 14, -1,
89 -1, -1, -1, -1, -1, -1, -1, -1,
90 8, 9, 10, 11, 12, 13, -1, 15,
92 32, 33, 34, 35, 36, 37, 38, 39,
93 40, 41, 42, 43, 44, 45, 46, 47,
94 48, 49, 50, 51, 52, 53, 54, 55,
95 56, 57, 58, 59, 60, 61, 62, 63,
96 64, 65, 66, 67, 68, 69, 70, 71,
97 72, 73, 74, 75, 76, 77, 78, 79,
98 80, 81, 82, 83, 84, 85, 86, 87,
99 88, 89, 90, 91, 92, 93, 94, 95,
100 96, 97, 98, 99, 100};
104 /* Name of where we pretend to think the frame pointer points.
105 Normally, this is "%fp", but if we are in a leaf procedure,
106 this is "%sp+something". We record "something" separately as it may be
107 too big for reg+constant addressing. */
109 static const char *frame_base_name;
110 static int frame_base_offset;
112 static rtx pic_setup_code PARAMS ((void));
113 static void sparc_init_modes PARAMS ((void));
114 static int save_regs PARAMS ((FILE *, int, int, const char *,
116 static int restore_regs PARAMS ((FILE *, int, int, const char *, int, int));
117 static void build_big_number PARAMS ((FILE *, int, const char *));
118 static int function_arg_slotno PARAMS ((const CUMULATIVE_ARGS *,
119 enum machine_mode, tree, int, int,
122 static int supersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
123 static int hypersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
124 static int ultrasparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
126 static void sparc_output_addr_vec PARAMS ((rtx));
127 static void sparc_output_addr_diff_vec PARAMS ((rtx));
128 static void sparc_output_deferred_case_vectors PARAMS ((void));
129 static void sparc_add_gc_roots PARAMS ((void));
130 static void mark_ultrasparc_pipeline_state PARAMS ((void *));
131 static int check_return_regs PARAMS ((rtx));
132 static int epilogue_renumber PARAMS ((rtx *, int));
133 static int ultra_cmove_results_ready_p PARAMS ((rtx));
134 static int ultra_fpmode_conflict_exists PARAMS ((enum machine_mode));
135 static rtx *ultra_find_type PARAMS ((int, rtx *, int));
136 static void ultra_build_types_avail PARAMS ((rtx *, int));
137 static void ultra_flush_pipeline PARAMS ((void));
138 static void ultra_rescan_pipeline_state PARAMS ((rtx *, int));
139 static int set_extends PARAMS ((rtx, rtx));
141 /* Option handling. */
143 /* Code model option as passed by user. */
144 const char *sparc_cmodel_string;
146 enum cmodel sparc_cmodel;
148 char sparc_hard_reg_printed[8];
150 struct sparc_cpu_select sparc_select[] =
152 /* switch name, tune arch */
153 { (char *)0, "default", 1, 1 },
154 { (char *)0, "-mcpu=", 1, 1 },
155 { (char *)0, "-mtune=", 1, 0 },
159 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
160 enum processor_type sparc_cpu;
162 /* Validate and override various options, and do some machine dependent
166 sparc_override_options ()
168 static struct code_model {
173 { "medlow", CM_MEDLOW },
174 { "medmid", CM_MEDMID },
175 { "medany", CM_MEDANY },
176 { "embmedany", CM_EMBMEDANY },
179 struct code_model *cmodel;
180 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
181 static struct cpu_default {
185 /* There must be one entry here for each TARGET_CPU value. */
186 { TARGET_CPU_sparc, "cypress" },
187 { TARGET_CPU_sparclet, "tsc701" },
188 { TARGET_CPU_sparclite, "f930" },
189 { TARGET_CPU_v8, "v8" },
190 { TARGET_CPU_hypersparc, "hypersparc" },
191 { TARGET_CPU_sparclite86x, "sparclite86x" },
192 { TARGET_CPU_supersparc, "supersparc" },
193 { TARGET_CPU_v9, "v9" },
194 { TARGET_CPU_ultrasparc, "ultrasparc" },
197 struct cpu_default *def;
198 /* Table of values for -m{cpu,tune}=. */
199 static struct cpu_table {
201 enum processor_type processor;
205 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
206 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
207 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
208 /* TI TMS390Z55 supersparc */
209 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
210 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
211 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
212 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
213 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
214 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
215 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
216 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
218 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
220 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
221 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
222 /* TI ultrasparc I, II, IIi */
223 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
224 /* Although insns using %y are deprecated, it is a clear win on current
226 |MASK_DEPRECATED_V8_INSNS },
229 struct cpu_table *cpu;
230 struct sparc_cpu_select *sel;
233 #ifndef SPARC_BI_ARCH
234 /* Check for unsupported architecture size. */
235 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
237 error ("%s is not supported by this configuration",
238 DEFAULT_ARCH32_P ? "-m64" : "-m32");
242 /* At the moment we don't allow different pointer size and architecture */
243 if (! TARGET_64BIT != ! TARGET_PTR64)
245 error ("-mptr%d not allowed on -m%d",
246 TARGET_PTR64 ? 64 : 32, TARGET_64BIT ? 64 : 32);
248 target_flags |= MASK_PTR64;
250 target_flags &= ~MASK_PTR64;
253 /* Code model selection. */
254 sparc_cmodel = SPARC_DEFAULT_CMODEL;
258 sparc_cmodel = CM_32;
261 if (sparc_cmodel_string != NULL)
265 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
266 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
268 if (cmodel->name == NULL)
269 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
271 sparc_cmodel = cmodel->value;
274 error ("-mcmodel= is not supported on 32 bit systems");
277 fpu = TARGET_FPU; /* save current -mfpu status */
279 /* Set the default CPU. */
280 for (def = &cpu_default[0]; def->name; ++def)
281 if (def->cpu == TARGET_CPU_DEFAULT)
285 sparc_select[0].string = def->name;
287 for (sel = &sparc_select[0]; sel->name; ++sel)
291 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
292 if (! strcmp (sel->string, cpu->name))
295 sparc_cpu = cpu->processor;
299 target_flags &= ~cpu->disable;
300 target_flags |= cpu->enable;
306 error ("bad value (%s) for %s switch", sel->string, sel->name);
310 /* If -mfpu or -mno-fpu was explicitly used, don't override with
311 the processor default. Clear MASK_FPU_SET to avoid confusing
312 the reverse mapping from switch values to names. */
315 target_flags = (target_flags & ~MASK_FPU) | fpu;
316 target_flags &= ~MASK_FPU_SET;
319 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
320 if (TARGET_V9 && TARGET_ARCH32)
321 target_flags |= MASK_DEPRECATED_V8_INSNS;
323 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
324 if (! TARGET_V9 || TARGET_ARCH64)
325 target_flags &= ~MASK_V8PLUS;
327 /* Don't use stack biasing in 32 bit mode. */
329 target_flags &= ~MASK_STACK_BIAS;
331 /* Don't allow -mvis if FPU is disabled. */
333 target_flags &= ~MASK_VIS;
335 /* Supply a default value for align_functions. */
336 if (align_functions == 0 && sparc_cpu == PROCESSOR_ULTRASPARC)
337 align_functions = 32;
339 /* Validate PCC_STRUCT_RETURN. */
340 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
341 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
343 /* Do various machine dependent initializations. */
346 if ((profile_flag || profile_block_flag)
347 && sparc_cmodel != CM_32 && sparc_cmodel != CM_MEDLOW)
349 error ("profiling does not support code models other than medlow");
352 /* Register global variables with the garbage collector. */
353 sparc_add_gc_roots ();
356 /* Miscellaneous utilities. */
358 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
359 or branch on register contents instructions. */
365 return (code == EQ || code == NE || code == GE || code == LT
366 || code == LE || code == GT);
370 /* Operand constraints. */
372 /* Return non-zero only if OP is a register of mode MODE,
373 or const0_rtx. Don't allow const0_rtx if TARGET_LIVE_G0 because
374 %g0 may contain anything. */
377 reg_or_0_operand (op, mode)
379 enum machine_mode mode;
381 if (register_operand (op, mode))
385 if (op == const0_rtx)
387 if (GET_MODE (op) == VOIDmode && GET_CODE (op) == CONST_DOUBLE
388 && CONST_DOUBLE_HIGH (op) == 0
389 && CONST_DOUBLE_LOW (op) == 0)
391 if (fp_zero_operand (op, mode))
396 /* Nonzero if OP is a floating point value with value 0.0. */
399 fp_zero_operand (op, mode)
401 enum machine_mode mode;
403 if (GET_MODE_CLASS (GET_MODE (op)) != MODE_FLOAT)
405 return op == CONST0_RTX (mode);
408 /* Nonzero if OP is a floating point constant which can
409 be loaded into an integer register using a single
410 sethi instruction. */
416 if (GET_CODE (op) == CONST_DOUBLE)
421 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
422 if (REAL_VALUES_EQUAL (r, dconst0) &&
423 ! REAL_VALUE_MINUS_ZERO (r))
425 REAL_VALUE_TO_TARGET_SINGLE (r, i);
426 if (SPARC_SETHI_P (i))
433 /* Nonzero if OP is a floating point constant which can
434 be loaded into an integer register using a single
441 if (GET_CODE (op) == CONST_DOUBLE)
446 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
447 if (REAL_VALUES_EQUAL (r, dconst0) &&
448 ! REAL_VALUE_MINUS_ZERO (r))
450 REAL_VALUE_TO_TARGET_SINGLE (r, i);
451 if (SPARC_SIMM13_P (i))
458 /* Nonzero if OP is a floating point constant which can
459 be loaded into an integer register using a high/losum
460 instruction sequence. */
466 /* The constraints calling this should only be in
467 SFmode move insns, so any constant which cannot
468 be moved using a single insn will do. */
469 if (GET_CODE (op) == CONST_DOUBLE)
474 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
475 if (REAL_VALUES_EQUAL (r, dconst0) &&
476 ! REAL_VALUE_MINUS_ZERO (r))
478 REAL_VALUE_TO_TARGET_SINGLE (r, i);
479 if (! SPARC_SETHI_P (i)
480 && ! SPARC_SIMM13_P (i))
487 /* Nonzero if OP is an integer register. */
490 intreg_operand (op, mode)
492 enum machine_mode mode ATTRIBUTE_UNUSED;
494 return (register_operand (op, SImode)
495 || (TARGET_ARCH64 && register_operand (op, DImode)));
498 /* Nonzero if OP is a floating point condition code register. */
501 fcc_reg_operand (op, mode)
503 enum machine_mode mode;
505 /* This can happen when recog is called from combine. Op may be a MEM.
506 Fail instead of calling abort in this case. */
507 if (GET_CODE (op) != REG)
510 if (mode != VOIDmode && mode != GET_MODE (op))
513 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
516 #if 0 /* ??? ==> 1 when %fcc0-3 are pseudos first. See gen_compare_reg(). */
517 if (reg_renumber == 0)
518 return REGNO (op) >= FIRST_PSEUDO_REGISTER;
519 return REGNO_OK_FOR_CCFP_P (REGNO (op));
521 return (unsigned) REGNO (op) - SPARC_FIRST_V9_FCC_REG < 4;
525 /* Nonzero if OP is an integer or floating point condition code register. */
528 icc_or_fcc_reg_operand (op, mode)
530 enum machine_mode mode;
532 if (GET_CODE (op) == REG && REGNO (op) == SPARC_ICC_REG)
534 if (mode != VOIDmode && mode != GET_MODE (op))
537 && GET_MODE (op) != CCmode && GET_MODE (op) != CCXmode)
542 return fcc_reg_operand (op, mode);
545 /* Nonzero if OP can appear as the dest of a RESTORE insn. */
547 restore_operand (op, mode)
549 enum machine_mode mode;
551 return (GET_CODE (op) == REG && GET_MODE (op) == mode
552 && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32)));
555 /* Call insn on SPARC can take a PC-relative constant address, or any regular
559 call_operand (op, mode)
561 enum machine_mode mode;
563 if (GET_CODE (op) != MEM)
566 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
570 call_operand_address (op, mode)
572 enum machine_mode mode;
574 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
577 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
578 reference and a constant. */
581 symbolic_operand (op, mode)
583 enum machine_mode mode;
585 enum machine_mode omode = GET_MODE (op);
587 if (omode != mode && omode != VOIDmode && mode != VOIDmode)
590 switch (GET_CODE (op))
598 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
599 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
600 && GET_CODE (XEXP (op, 1)) == CONST_INT);
607 /* Return truth value of statement that OP is a symbolic memory
608 operand of mode MODE. */
611 symbolic_memory_operand (op, mode)
613 enum machine_mode mode ATTRIBUTE_UNUSED;
615 if (GET_CODE (op) == SUBREG)
616 op = SUBREG_REG (op);
617 if (GET_CODE (op) != MEM)
620 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
621 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
624 /* Return truth value of statement that OP is a LABEL_REF of mode MODE. */
627 label_ref_operand (op, mode)
629 enum machine_mode mode;
631 if (GET_CODE (op) != LABEL_REF)
633 if (GET_MODE (op) != mode)
638 /* Return 1 if the operand is an argument used in generating pic references
639 in either the medium/low or medium/anywhere code models of sparc64. */
642 sp64_medium_pic_operand (op, mode)
644 enum machine_mode mode ATTRIBUTE_UNUSED;
646 /* Check for (const (minus (symbol_ref:GOT)
647 (const (minus (label) (pc))))). */
648 if (GET_CODE (op) != CONST)
651 if (GET_CODE (op) != MINUS)
653 if (GET_CODE (XEXP (op, 0)) != SYMBOL_REF)
655 /* ??? Ensure symbol is GOT. */
656 if (GET_CODE (XEXP (op, 1)) != CONST)
658 if (GET_CODE (XEXP (XEXP (op, 1), 0)) != MINUS)
663 /* Return 1 if the operand is a data segment reference. This includes
664 the readonly data segment, or in other words anything but the text segment.
665 This is needed in the medium/anywhere code model on v9. These values
666 are accessed with EMBMEDANY_BASE_REG. */
669 data_segment_operand (op, mode)
671 enum machine_mode mode ATTRIBUTE_UNUSED;
673 switch (GET_CODE (op))
676 return ! SYMBOL_REF_FLAG (op);
678 /* Assume canonical format of symbol + constant.
681 return data_segment_operand (XEXP (op, 0), VOIDmode);
687 /* Return 1 if the operand is a text segment reference.
688 This is needed in the medium/anywhere code model on v9. */
691 text_segment_operand (op, mode)
693 enum machine_mode mode ATTRIBUTE_UNUSED;
695 switch (GET_CODE (op))
700 return SYMBOL_REF_FLAG (op);
702 /* Assume canonical format of symbol + constant.
705 return text_segment_operand (XEXP (op, 0), VOIDmode);
711 /* Return 1 if the operand is either a register or a memory operand that is
715 reg_or_nonsymb_mem_operand (op, mode)
717 enum machine_mode mode;
719 if (register_operand (op, mode))
722 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
729 splittable_symbolic_memory_operand (op, mode)
731 enum machine_mode mode ATTRIBUTE_UNUSED;
733 if (GET_CODE (op) != MEM)
735 if (! symbolic_operand (XEXP (op, 0), Pmode))
741 splittable_immediate_memory_operand (op, mode)
743 enum machine_mode mode ATTRIBUTE_UNUSED;
745 if (GET_CODE (op) != MEM)
747 if (! immediate_operand (XEXP (op, 0), Pmode))
752 /* Return truth value of whether OP is EQ or NE. */
757 enum machine_mode mode ATTRIBUTE_UNUSED;
759 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
762 /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
763 or LTU for non-floating-point. We handle those specially. */
766 normal_comp_operator (op, mode)
768 enum machine_mode mode ATTRIBUTE_UNUSED;
770 enum rtx_code code = GET_CODE (op);
772 if (GET_RTX_CLASS (code) != '<')
775 if (GET_MODE (XEXP (op, 0)) == CCFPmode
776 || GET_MODE (XEXP (op, 0)) == CCFPEmode)
779 return (code != NE && code != EQ && code != GEU && code != LTU);
782 /* Return 1 if this is a comparison operator. This allows the use of
783 MATCH_OPERATOR to recognize all the branch insns. */
786 noov_compare_op (op, mode)
788 enum machine_mode mode ATTRIBUTE_UNUSED;
790 enum rtx_code code = GET_CODE (op);
792 if (GET_RTX_CLASS (code) != '<')
795 if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode)
796 /* These are the only branches which work with CC_NOOVmode. */
797 return (code == EQ || code == NE || code == GE || code == LT);
801 /* Nonzero if OP is a comparison operator suitable for use in v9
802 conditional move or branch on register contents instructions. */
805 v9_regcmp_op (op, mode)
807 enum machine_mode mode ATTRIBUTE_UNUSED;
809 enum rtx_code code = GET_CODE (op);
811 if (GET_RTX_CLASS (code) != '<')
814 return v9_regcmp_p (code);
817 /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */
822 enum machine_mode mode ATTRIBUTE_UNUSED;
824 return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
827 /* Return nonzero if OP is an operator of mode MODE which can set
828 the condition codes explicitly. We do not include PLUS and MINUS
829 because these require CC_NOOVmode, which we handle explicitly. */
832 cc_arithop (op, mode)
834 enum machine_mode mode ATTRIBUTE_UNUSED;
836 if (GET_CODE (op) == AND
837 || GET_CODE (op) == IOR
838 || GET_CODE (op) == XOR)
844 /* Return nonzero if OP is an operator of mode MODE which can bitwise
845 complement its second operand and set the condition codes explicitly. */
848 cc_arithopn (op, mode)
850 enum machine_mode mode ATTRIBUTE_UNUSED;
852 /* XOR is not here because combine canonicalizes (xor (not ...) ...)
853 and (xor ... (not ...)) to (not (xor ...)). */
854 return (GET_CODE (op) == AND
855 || GET_CODE (op) == IOR);
858 /* Return true if OP is a register, or is a CONST_INT that can fit in a
859 signed 13 bit immediate field. This is an acceptable SImode operand for
860 most 3 address instructions. */
863 arith_operand (op, mode)
865 enum machine_mode mode;
868 if (register_operand (op, mode))
870 if (GET_CODE (op) != CONST_INT)
872 val = INTVAL (op) & 0xffffffff;
873 return SPARC_SIMM13_P (val);
876 /* Return true if OP is a constant 4096 */
879 arith_4096_operand (op, mode)
881 enum machine_mode mode ATTRIBUTE_UNUSED;
884 if (GET_CODE (op) != CONST_INT)
886 val = INTVAL (op) & 0xffffffff;
890 /* Return true if OP is suitable as second operand for add/sub */
893 arith_add_operand (op, mode)
895 enum machine_mode mode;
897 return arith_operand (op, mode) || arith_4096_operand (op, mode);
900 /* Return true if OP is a CONST_INT or a CONST_DOUBLE which can fit in the
901 immediate field of OR and XOR instructions. Used for 64-bit
902 constant formation patterns. */
904 const64_operand (op, mode)
906 enum machine_mode mode ATTRIBUTE_UNUSED;
908 return ((GET_CODE (op) == CONST_INT
909 && SPARC_SIMM13_P (INTVAL (op)))
910 #if HOST_BITS_PER_WIDE_INT != 64
911 || (GET_CODE (op) == CONST_DOUBLE
912 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
913 && (CONST_DOUBLE_HIGH (op) ==
914 ((CONST_DOUBLE_LOW (op) & 0x80000000) != 0 ?
915 (HOST_WIDE_INT)0xffffffff : 0)))
920 /* The same, but only for sethi instructions. */
922 const64_high_operand (op, mode)
924 enum machine_mode mode ATTRIBUTE_UNUSED;
926 return ((GET_CODE (op) == CONST_INT
927 && (INTVAL (op) & 0xfffffc00) != 0
928 && SPARC_SETHI_P (INTVAL (op))
929 #if HOST_BITS_PER_WIDE_INT != 64
930 /* Must be positive on non-64bit host else the
931 optimizer is fooled into thinking that sethi
932 sign extends, even though it does not. */
936 || (GET_CODE (op) == CONST_DOUBLE
937 && CONST_DOUBLE_HIGH (op) == 0
938 && (CONST_DOUBLE_LOW (op) & 0xfffffc00) != 0
939 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op))));
942 /* Return true if OP is a register, or is a CONST_INT that can fit in a
943 signed 11 bit immediate field. This is an acceptable SImode operand for
944 the movcc instructions. */
947 arith11_operand (op, mode)
949 enum machine_mode mode;
951 return (register_operand (op, mode)
952 || (GET_CODE (op) == CONST_INT && SPARC_SIMM11_P (INTVAL (op))));
955 /* Return true if OP is a register, or is a CONST_INT that can fit in a
956 signed 10 bit immediate field. This is an acceptable SImode operand for
957 the movrcc instructions. */
960 arith10_operand (op, mode)
962 enum machine_mode mode;
964 return (register_operand (op, mode)
965 || (GET_CODE (op) == CONST_INT && SPARC_SIMM10_P (INTVAL (op))));
968 /* Return true if OP is a register, is a CONST_INT that fits in a 13 bit
969 immediate field, or is a CONST_DOUBLE whose both parts fit in a 13 bit
971 v9: Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
972 can fit in a 13 bit immediate field. This is an acceptable DImode operand
973 for most 3 address instructions. */
976 arith_double_operand (op, mode)
978 enum machine_mode mode;
980 return (register_operand (op, mode)
981 || (GET_CODE (op) == CONST_INT && SMALL_INT (op))
983 && GET_CODE (op) == CONST_DOUBLE
984 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
985 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_HIGH (op) + 0x1000) < 0x2000)
987 && GET_CODE (op) == CONST_DOUBLE
988 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
989 && ((CONST_DOUBLE_HIGH (op) == -1
990 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
991 || (CONST_DOUBLE_HIGH (op) == 0
992 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
995 /* Return true if OP is a constant 4096 for DImode on ARCH64 */
998 arith_double_4096_operand (op, mode)
1000 enum machine_mode mode ATTRIBUTE_UNUSED;
1002 return (TARGET_ARCH64 &&
1003 ((GET_CODE (op) == CONST_INT && INTVAL (op) == 4096) ||
1004 (GET_CODE (op) == CONST_DOUBLE &&
1005 CONST_DOUBLE_LOW (op) == 4096 &&
1006 CONST_DOUBLE_HIGH (op) == 0)));
1009 /* Return true if OP is suitable as second operand for add/sub in DImode */
1012 arith_double_add_operand (op, mode)
1014 enum machine_mode mode;
1016 return arith_double_operand (op, mode) || arith_double_4096_operand (op, mode);
1019 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1020 can fit in an 11 bit immediate field. This is an acceptable DImode
1021 operand for the movcc instructions. */
1022 /* ??? Replace with arith11_operand? */
1025 arith11_double_operand (op, mode)
1027 enum machine_mode mode;
1029 return (register_operand (op, mode)
1030 || (GET_CODE (op) == CONST_DOUBLE
1031 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1032 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x400) < 0x800
1033 && ((CONST_DOUBLE_HIGH (op) == -1
1034 && (CONST_DOUBLE_LOW (op) & 0x400) == 0x400)
1035 || (CONST_DOUBLE_HIGH (op) == 0
1036 && (CONST_DOUBLE_LOW (op) & 0x400) == 0)))
1037 || (GET_CODE (op) == CONST_INT
1038 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1039 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x400) < 0x800));
1042 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1043 can fit in an 10 bit immediate field. This is an acceptable DImode
1044 operand for the movrcc instructions. */
1045 /* ??? Replace with arith10_operand? */
1048 arith10_double_operand (op, mode)
1050 enum machine_mode mode;
1052 return (register_operand (op, mode)
1053 || (GET_CODE (op) == CONST_DOUBLE
1054 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1055 && (unsigned) (CONST_DOUBLE_LOW (op) + 0x200) < 0x400
1056 && ((CONST_DOUBLE_HIGH (op) == -1
1057 && (CONST_DOUBLE_LOW (op) & 0x200) == 0x200)
1058 || (CONST_DOUBLE_HIGH (op) == 0
1059 && (CONST_DOUBLE_LOW (op) & 0x200) == 0)))
1060 || (GET_CODE (op) == CONST_INT
1061 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1062 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x200) < 0x400));
1065 /* Return truth value of whether OP is a integer which fits the
1066 range constraining immediate operands in most three-address insns,
1067 which have a 13 bit immediate field. */
1070 small_int (op, mode)
1072 enum machine_mode mode ATTRIBUTE_UNUSED;
1074 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
1078 small_int_or_double (op, mode)
1080 enum machine_mode mode ATTRIBUTE_UNUSED;
1082 return ((GET_CODE (op) == CONST_INT && SMALL_INT (op))
1083 || (GET_CODE (op) == CONST_DOUBLE
1084 && CONST_DOUBLE_HIGH (op) == 0
1085 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))));
1088 /* Recognize operand values for the umul instruction. That instruction sign
1089 extends immediate values just like all other sparc instructions, but
1090 interprets the extended result as an unsigned number. */
1093 uns_small_int (op, mode)
1095 enum machine_mode mode ATTRIBUTE_UNUSED;
1097 #if HOST_BITS_PER_WIDE_INT > 32
1098 /* All allowed constants will fit a CONST_INT. */
1099 return (GET_CODE (op) == CONST_INT
1100 && ((INTVAL (op) >= 0 && INTVAL (op) < 0x1000)
1101 || (INTVAL (op) >= 0xFFFFF000
1102 && INTVAL (op) < 0x100000000)));
1104 return ((GET_CODE (op) == CONST_INT && (unsigned) INTVAL (op) < 0x1000)
1105 || (GET_CODE (op) == CONST_DOUBLE
1106 && CONST_DOUBLE_HIGH (op) == 0
1107 && (unsigned) CONST_DOUBLE_LOW (op) - 0xFFFFF000 < 0x1000));
1112 uns_arith_operand (op, mode)
1114 enum machine_mode mode;
1116 return register_operand (op, mode) || uns_small_int (op, mode);
1119 /* Return truth value of statement that OP is a call-clobbered register. */
1121 clobbered_register (op, mode)
1123 enum machine_mode mode ATTRIBUTE_UNUSED;
1125 return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
1128 /* Return 1 if OP is const0_rtx, used for TARGET_LIVE_G0 insns. */
1131 zero_operand (op, mode)
1133 enum machine_mode mode ATTRIBUTE_UNUSED;
1135 return op == const0_rtx;
1138 /* Return 1 if OP is a valid operand for the source of a move insn. */
1141 input_operand (op, mode)
1143 enum machine_mode mode;
1145 /* If both modes are non-void they must be the same. */
1146 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1149 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1150 if (GET_CODE (op) == CONST && GET_CODE (XEXP (op, 0)) == CONSTANT_P_RTX)
1153 /* Allow any one instruction integer constant, and all CONST_INT
1154 variants when we are working in DImode and !arch64. */
1155 if (GET_MODE_CLASS (mode) == MODE_INT
1156 && ((GET_CODE (op) == CONST_INT
1157 && ((SPARC_SETHI_P (INTVAL (op))
1159 || (INTVAL (op) >= 0)
1163 || SPARC_SIMM13_P (INTVAL (op))
1165 && ! TARGET_ARCH64)))
1167 && GET_CODE (op) == CONST_DOUBLE
1168 && ((CONST_DOUBLE_HIGH (op) == 0
1169 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op)))
1171 #if HOST_BITS_PER_WIDE_INT == 64
1172 (CONST_DOUBLE_HIGH (op) == 0
1173 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op)))
1175 (SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1176 && (((CONST_DOUBLE_LOW (op) & 0x80000000) == 0
1177 && CONST_DOUBLE_HIGH (op) == 0)
1178 || (CONST_DOUBLE_HIGH (op) == -1)))
1183 /* If !arch64 and this is a DImode const, allow it so that
1184 the splits can be generated. */
1187 && GET_CODE (op) == CONST_DOUBLE)
1190 if (register_operand (op, mode))
1193 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1194 && GET_CODE (op) == CONST_DOUBLE)
1197 /* If this is a SUBREG, look inside so that we handle
1198 paradoxical ones. */
1199 if (GET_CODE (op) == SUBREG)
1200 op = SUBREG_REG (op);
1202 /* Check for valid MEM forms. */
1203 if (GET_CODE (op) == MEM)
1205 rtx inside = XEXP (op, 0);
1207 if (GET_CODE (inside) == LO_SUM)
1209 /* We can't allow these because all of the splits
1210 (eventually as they trickle down into DFmode
1211 splits) require offsettable memory references. */
1213 && GET_MODE (op) == TFmode)
1216 return (register_operand (XEXP (inside, 0), Pmode)
1217 && CONSTANT_P (XEXP (inside, 1)));
1219 return memory_address_p (mode, inside);
1226 /* We know it can't be done in one insn when we get here,
1227 the movsi expander guarentees this. */
1229 sparc_emit_set_const32 (op0, op1)
1233 enum machine_mode mode = GET_MODE (op0);
1236 if (GET_CODE (op1) == CONST_INT)
1238 HOST_WIDE_INT value = INTVAL (op1);
1240 if (SPARC_SETHI_P (value)
1241 || SPARC_SIMM13_P (value))
1245 /* Full 2-insn decomposition is needed. */
1246 if (reload_in_progress || reload_completed)
1249 temp = gen_reg_rtx (mode);
1251 if (GET_CODE (op1) == CONST_INT)
1253 /* Emit them as real moves instead of a HIGH/LO_SUM,
1254 this way CSE can see everything and reuse intermediate
1255 values if it wants. */
1257 && HOST_BITS_PER_WIDE_INT != 64
1258 && (INTVAL (op1) & 0x80000000) != 0)
1260 emit_insn (gen_rtx_SET (VOIDmode,
1262 gen_rtx_CONST_DOUBLE (VOIDmode, const0_rtx,
1263 INTVAL (op1) & 0xfffffc00, 0)));
1267 emit_insn (gen_rtx_SET (VOIDmode,
1269 GEN_INT (INTVAL (op1) & 0xfffffc00)));
1271 emit_insn (gen_rtx_SET (VOIDmode,
1275 GEN_INT (INTVAL (op1) & 0x3ff))));
1279 /* A symbol, emit in the traditional way. */
1280 emit_insn (gen_rtx_SET (VOIDmode,
1284 emit_insn (gen_rtx_SET (VOIDmode,
1286 gen_rtx_LO_SUM (mode,
1294 /* Sparc-v9 code-model support. */
1296 sparc_emit_set_symbolic_const64 (op0, op1, temp1)
1301 switch (sparc_cmodel)
1304 /* The range spanned by all instructions in the object is less
1305 than 2^31 bytes (2GB) and the distance from any instruction
1306 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1307 than 2^31 bytes (2GB).
1309 The executable must be in the low 4TB of the virtual address
1312 sethi %hi(symbol), %temp
1313 or %temp, %lo(symbol), %reg */
1314 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1315 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1319 /* The range spanned by all instructions in the object is less
1320 than 2^31 bytes (2GB) and the distance from any instruction
1321 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1322 than 2^31 bytes (2GB).
1324 The executable must be in the low 16TB of the virtual address
1327 sethi %h44(symbol), %temp1
1328 or %temp1, %m44(symbol), %temp2
1329 sllx %temp2, 12, %temp3
1330 or %temp3, %l44(symbol), %reg */
1331 emit_insn (gen_seth44 (op0, op1));
1332 emit_insn (gen_setm44 (op0, op0, op1));
1333 emit_insn (gen_rtx_SET (VOIDmode, temp1,
1334 gen_rtx_ASHIFT (DImode, op0, GEN_INT (12))));
1335 emit_insn (gen_setl44 (op0, temp1, op1));
1339 /* The range spanned by all instructions in the object is less
1340 than 2^31 bytes (2GB) and the distance from any instruction
1341 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1342 than 2^31 bytes (2GB).
1344 The executable can be placed anywhere in the virtual address
1347 sethi %hh(symbol), %temp1
1348 sethi %lm(symbol), %temp2
1349 or %temp1, %hm(symbol), %temp3
1350 or %temp2, %lo(symbol), %temp4
1351 sllx %temp3, 32, %temp5
1352 or %temp4, %temp5, %reg */
1354 /* Getting this right wrt. reloading is really tricky.
1355 We _MUST_ have a separate temporary at this point,
1356 if we don't barf immediately instead of generating
1361 emit_insn (gen_sethh (op0, op1));
1362 emit_insn (gen_setlm (temp1, op1));
1363 emit_insn (gen_sethm (op0, op0, op1));
1364 emit_insn (gen_rtx_SET (VOIDmode, op0,
1365 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1366 emit_insn (gen_rtx_SET (VOIDmode, op0,
1367 gen_rtx_PLUS (DImode, op0, temp1)));
1368 emit_insn (gen_setlo (op0, op0, op1));
1372 /* Old old old backwards compatibility kruft here.
1373 Essentially it is MEDLOW with a fixed 64-bit
1374 virtual base added to all data segment addresses.
1375 Text-segment stuff is computed like MEDANY, we can't
1376 reuse the code above because the relocation knobs
1379 Data segment: sethi %hi(symbol), %temp1
1380 or %temp1, %lo(symbol), %temp2
1381 add %temp2, EMBMEDANY_BASE_REG, %reg
1383 Text segment: sethi %uhi(symbol), %temp1
1384 sethi %hi(symbol), %temp2
1385 or %temp1, %ulo(symbol), %temp3
1386 or %temp2, %lo(symbol), %temp4
1387 sllx %temp3, 32, %temp5
1388 or %temp4, %temp5, %reg */
1389 if (data_segment_operand (op1, GET_MODE (op1)))
1391 emit_insn (gen_embmedany_sethi (temp1, op1));
1392 emit_insn (gen_embmedany_brsum (op0, temp1));
1393 emit_insn (gen_embmedany_losum (op0, op0, op1));
1397 /* Getting this right wrt. reloading is really tricky.
1398 We _MUST_ have a separate temporary at this point,
1399 so we barf immediately instead of generating
1404 emit_insn (gen_embmedany_textuhi (op0, op1));
1405 emit_insn (gen_embmedany_texthi (temp1, op1));
1406 emit_insn (gen_embmedany_textulo (op0, op0, op1));
1407 emit_insn (gen_rtx_SET (VOIDmode, op0,
1408 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1409 emit_insn (gen_rtx_SET (VOIDmode, op0,
1410 gen_rtx_PLUS (DImode, op0, temp1)));
1411 emit_insn (gen_embmedany_textlo (op0, op0, op1));
1420 /* These avoid problems when cross compiling. If we do not
1421 go through all this hair then the optimizer will see
1422 invalid REG_EQUAL notes or in some cases none at all. */
1423 static void sparc_emit_set_safe_HIGH64 PARAMS ((rtx, HOST_WIDE_INT));
1424 static rtx gen_safe_SET64 PARAMS ((rtx, HOST_WIDE_INT));
1425 static rtx gen_safe_OR64 PARAMS ((rtx, HOST_WIDE_INT));
1426 static rtx gen_safe_XOR64 PARAMS ((rtx, HOST_WIDE_INT));
1428 #if HOST_BITS_PER_WIDE_INT == 64
1429 #define GEN_HIGHINT64(__x) GEN_INT ((__x) & 0xfffffc00)
1430 #define GEN_INT64(__x) GEN_INT (__x)
1432 #define GEN_HIGHINT64(__x) \
1433 gen_rtx_CONST_DOUBLE (VOIDmode, const0_rtx, \
1434 (__x) & 0xfffffc00, 0)
1435 #define GEN_INT64(__x) \
1436 gen_rtx_CONST_DOUBLE (VOIDmode, const0_rtx, \
1437 (__x) & 0xffffffff, \
1438 ((__x) & 0x80000000 \
1442 /* The optimizer is not to assume anything about exactly
1443 which bits are set for a HIGH, they are unspecified.
1444 Unfortunately this leads to many missed optimizations
1445 during CSE. We mask out the non-HIGH bits, and matches
1446 a plain movdi, to alleviate this problem. */
1448 sparc_emit_set_safe_HIGH64 (dest, val)
1452 emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_HIGHINT64 (val)));
1456 gen_safe_SET64 (dest, val)
1460 return gen_rtx_SET (VOIDmode, dest, GEN_INT64 (val));
1464 gen_safe_OR64 (src, val)
1468 return gen_rtx_IOR (DImode, src, GEN_INT64 (val));
1472 gen_safe_XOR64 (src, val)
1476 return gen_rtx_XOR (DImode, src, GEN_INT64 (val));
1479 /* Worker routines for 64-bit constant formation on arch64.
1480 One of the key things to be doing in these emissions is
1481 to create as many temp REGs as possible. This makes it
1482 possible for half-built constants to be used later when
1483 such values are similar to something required later on.
1484 Without doing this, the optimizer cannot see such
1487 static void sparc_emit_set_const64_quick1
1488 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, int));
1491 sparc_emit_set_const64_quick1 (op0, temp, low_bits, is_neg)
1494 unsigned HOST_WIDE_INT low_bits;
1497 unsigned HOST_WIDE_INT high_bits;
1500 high_bits = (~low_bits) & 0xffffffff;
1502 high_bits = low_bits;
1504 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1507 emit_insn (gen_rtx_SET (VOIDmode, op0,
1508 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1512 /* If we are XOR'ing with -1, then we should emit a one's complement
1513 instead. This way the combiner will notice logical operations
1514 such as ANDN later on and substitute. */
1515 if ((low_bits & 0x3ff) == 0x3ff)
1517 emit_insn (gen_rtx_SET (VOIDmode, op0,
1518 gen_rtx_NOT (DImode, temp)));
1522 emit_insn (gen_rtx_SET (VOIDmode, op0,
1523 gen_safe_XOR64 (temp,
1524 (-0x400 | (low_bits & 0x3ff)))));
1529 static void sparc_emit_set_const64_quick2
1530 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT,
1531 unsigned HOST_WIDE_INT, int));
1534 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_immediate, shift_count)
1537 unsigned HOST_WIDE_INT high_bits;
1538 unsigned HOST_WIDE_INT low_immediate;
1543 if ((high_bits & 0xfffffc00) != 0)
1545 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1546 if ((high_bits & ~0xfffffc00) != 0)
1547 emit_insn (gen_rtx_SET (VOIDmode, op0,
1548 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1554 emit_insn (gen_safe_SET64 (temp, high_bits));
1558 /* Now shift it up into place. */
1559 emit_insn (gen_rtx_SET (VOIDmode, op0,
1560 gen_rtx_ASHIFT (DImode, temp2,
1561 GEN_INT (shift_count))));
1563 /* If there is a low immediate part piece, finish up by
1564 putting that in as well. */
1565 if (low_immediate != 0)
1566 emit_insn (gen_rtx_SET (VOIDmode, op0,
1567 gen_safe_OR64 (op0, low_immediate)));
1570 static void sparc_emit_set_const64_longway
1571 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1573 /* Full 64-bit constant decomposition. Even though this is the
1574 'worst' case, we still optimize a few things away. */
1576 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits)
1579 unsigned HOST_WIDE_INT high_bits;
1580 unsigned HOST_WIDE_INT low_bits;
1584 if (reload_in_progress || reload_completed)
1587 sub_temp = gen_reg_rtx (DImode);
1589 if ((high_bits & 0xfffffc00) != 0)
1591 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1592 if ((high_bits & ~0xfffffc00) != 0)
1593 emit_insn (gen_rtx_SET (VOIDmode,
1595 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1601 emit_insn (gen_safe_SET64 (temp, high_bits));
1605 if (!reload_in_progress && !reload_completed)
1607 rtx temp2 = gen_reg_rtx (DImode);
1608 rtx temp3 = gen_reg_rtx (DImode);
1609 rtx temp4 = gen_reg_rtx (DImode);
1611 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1612 gen_rtx_ASHIFT (DImode, sub_temp,
1615 sparc_emit_set_safe_HIGH64 (temp2, low_bits);
1616 if ((low_bits & ~0xfffffc00) != 0)
1618 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1619 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1620 emit_insn (gen_rtx_SET (VOIDmode, op0,
1621 gen_rtx_PLUS (DImode, temp4, temp3)));
1625 emit_insn (gen_rtx_SET (VOIDmode, op0,
1626 gen_rtx_PLUS (DImode, temp4, temp2)));
1631 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1632 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1633 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1636 /* We are in the middle of reload, so this is really
1637 painful. However we do still make an attempt to
1638 avoid emitting truly stupid code. */
1639 if (low1 != const0_rtx)
1641 emit_insn (gen_rtx_SET (VOIDmode, op0,
1642 gen_rtx_ASHIFT (DImode, sub_temp,
1643 GEN_INT (to_shift))));
1644 emit_insn (gen_rtx_SET (VOIDmode, op0,
1645 gen_rtx_IOR (DImode, op0, low1)));
1653 if (low2 != const0_rtx)
1655 emit_insn (gen_rtx_SET (VOIDmode, op0,
1656 gen_rtx_ASHIFT (DImode, sub_temp,
1657 GEN_INT (to_shift))));
1658 emit_insn (gen_rtx_SET (VOIDmode, op0,
1659 gen_rtx_IOR (DImode, op0, low2)));
1667 emit_insn (gen_rtx_SET (VOIDmode, op0,
1668 gen_rtx_ASHIFT (DImode, sub_temp,
1669 GEN_INT (to_shift))));
1670 if (low3 != const0_rtx)
1671 emit_insn (gen_rtx_SET (VOIDmode, op0,
1672 gen_rtx_IOR (DImode, op0, low3)));
1677 /* Analyze a 64-bit constant for certain properties. */
1678 static void analyze_64bit_constant
1679 PARAMS ((unsigned HOST_WIDE_INT,
1680 unsigned HOST_WIDE_INT,
1681 int *, int *, int *));
1684 analyze_64bit_constant (high_bits, low_bits, hbsp, lbsp, abbasp)
1685 unsigned HOST_WIDE_INT high_bits, low_bits;
1686 int *hbsp, *lbsp, *abbasp;
1688 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1691 lowest_bit_set = highest_bit_set = -1;
1695 if ((lowest_bit_set == -1)
1696 && ((low_bits >> i) & 1))
1698 if ((highest_bit_set == -1)
1699 && ((high_bits >> (32 - i - 1)) & 1))
1700 highest_bit_set = (64 - i - 1);
1703 && ((highest_bit_set == -1)
1704 || (lowest_bit_set == -1)));
1710 if ((lowest_bit_set == -1)
1711 && ((high_bits >> i) & 1))
1712 lowest_bit_set = i + 32;
1713 if ((highest_bit_set == -1)
1714 && ((low_bits >> (32 - i - 1)) & 1))
1715 highest_bit_set = 32 - i - 1;
1718 && ((highest_bit_set == -1)
1719 || (lowest_bit_set == -1)));
1721 /* If there are no bits set this should have gone out
1722 as one instruction! */
1723 if (lowest_bit_set == -1
1724 || highest_bit_set == -1)
1726 all_bits_between_are_set = 1;
1727 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1731 if ((low_bits & (1 << i)) != 0)
1736 if ((high_bits & (1 << (i - 32))) != 0)
1739 all_bits_between_are_set = 0;
1742 *hbsp = highest_bit_set;
1743 *lbsp = lowest_bit_set;
1744 *abbasp = all_bits_between_are_set;
1747 static int const64_is_2insns
1748 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1751 const64_is_2insns (high_bits, low_bits)
1752 unsigned HOST_WIDE_INT high_bits, low_bits;
1754 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1757 || high_bits == 0xffffffff)
1760 analyze_64bit_constant (high_bits, low_bits,
1761 &highest_bit_set, &lowest_bit_set,
1762 &all_bits_between_are_set);
1764 if ((highest_bit_set == 63
1765 || lowest_bit_set == 0)
1766 && all_bits_between_are_set != 0)
1769 if ((highest_bit_set - lowest_bit_set) < 21)
1775 static unsigned HOST_WIDE_INT create_simple_focus_bits
1776 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
1779 static unsigned HOST_WIDE_INT
1780 create_simple_focus_bits (high_bits, low_bits, lowest_bit_set, shift)
1781 unsigned HOST_WIDE_INT high_bits, low_bits;
1782 int lowest_bit_set, shift;
1784 HOST_WIDE_INT hi, lo;
1786 if (lowest_bit_set < 32)
1788 lo = (low_bits >> lowest_bit_set) << shift;
1789 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
1794 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
1801 /* Here we are sure to be arch64 and this is an integer constant
1802 being loaded into a register. Emit the most efficient
1803 insn sequence possible. Detection of all the 1-insn cases
1804 has been done already. */
1806 sparc_emit_set_const64 (op0, op1)
1810 unsigned HOST_WIDE_INT high_bits, low_bits;
1811 int lowest_bit_set, highest_bit_set;
1812 int all_bits_between_are_set;
1815 /* Sanity check that we know what we are working with. */
1817 || GET_CODE (op0) != REG
1818 || (REGNO (op0) >= SPARC_FIRST_FP_REG
1819 && REGNO (op0) <= SPARC_LAST_V9_FP_REG))
1822 if (reload_in_progress || reload_completed)
1825 temp = gen_reg_rtx (DImode);
1827 if (GET_CODE (op1) != CONST_DOUBLE
1828 && GET_CODE (op1) != CONST_INT)
1830 sparc_emit_set_symbolic_const64 (op0, op1, temp);
1834 if (GET_CODE (op1) == CONST_DOUBLE)
1836 #if HOST_BITS_PER_WIDE_INT == 64
1837 high_bits = (CONST_DOUBLE_LOW (op1) >> 32) & 0xffffffff;
1838 low_bits = CONST_DOUBLE_LOW (op1) & 0xffffffff;
1840 high_bits = CONST_DOUBLE_HIGH (op1);
1841 low_bits = CONST_DOUBLE_LOW (op1);
1846 #if HOST_BITS_PER_WIDE_INT == 64
1847 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
1848 low_bits = (INTVAL (op1) & 0xffffffff);
1850 high_bits = ((INTVAL (op1) < 0) ?
1853 low_bits = INTVAL (op1);
1857 /* low_bits bits 0 --> 31
1858 high_bits bits 32 --> 63 */
1860 analyze_64bit_constant (high_bits, low_bits,
1861 &highest_bit_set, &lowest_bit_set,
1862 &all_bits_between_are_set);
1864 /* First try for a 2-insn sequence. */
1866 /* These situations are preferred because the optimizer can
1867 * do more things with them:
1869 * sllx %reg, shift, %reg
1871 * srlx %reg, shift, %reg
1872 * 3) mov some_small_const, %reg
1873 * sllx %reg, shift, %reg
1875 if (((highest_bit_set == 63
1876 || lowest_bit_set == 0)
1877 && all_bits_between_are_set != 0)
1878 || ((highest_bit_set - lowest_bit_set) < 12))
1880 HOST_WIDE_INT the_const = -1;
1881 int shift = lowest_bit_set;
1883 if ((highest_bit_set != 63
1884 && lowest_bit_set != 0)
1885 || all_bits_between_are_set == 0)
1888 create_simple_focus_bits (high_bits, low_bits,
1891 else if (lowest_bit_set == 0)
1892 shift = -(63 - highest_bit_set);
1894 if (! SPARC_SIMM13_P (the_const))
1897 emit_insn (gen_safe_SET64 (temp, the_const));
1899 emit_insn (gen_rtx_SET (VOIDmode,
1901 gen_rtx_ASHIFT (DImode,
1905 emit_insn (gen_rtx_SET (VOIDmode,
1907 gen_rtx_LSHIFTRT (DImode,
1909 GEN_INT (-shift))));
1915 /* Now a range of 22 or less bits set somewhere.
1916 * 1) sethi %hi(focus_bits), %reg
1917 * sllx %reg, shift, %reg
1918 * 2) sethi %hi(focus_bits), %reg
1919 * srlx %reg, shift, %reg
1921 if ((highest_bit_set - lowest_bit_set) < 21)
1923 unsigned HOST_WIDE_INT focus_bits =
1924 create_simple_focus_bits (high_bits, low_bits,
1925 lowest_bit_set, 10);
1927 if (! SPARC_SETHI_P (focus_bits))
1930 sparc_emit_set_safe_HIGH64 (temp, focus_bits);
1932 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
1933 if (lowest_bit_set < 10)
1934 emit_insn (gen_rtx_SET (VOIDmode,
1936 gen_rtx_LSHIFTRT (DImode, temp,
1937 GEN_INT (10 - lowest_bit_set))));
1938 else if (lowest_bit_set > 10)
1939 emit_insn (gen_rtx_SET (VOIDmode,
1941 gen_rtx_ASHIFT (DImode, temp,
1942 GEN_INT (lowest_bit_set - 10))));
1948 /* 1) sethi %hi(low_bits), %reg
1949 * or %reg, %lo(low_bits), %reg
1950 * 2) sethi %hi(~low_bits), %reg
1951 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
1954 || high_bits == 0xffffffff)
1956 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
1957 (high_bits == 0xffffffff));
1961 /* Now, try 3-insn sequences. */
1963 /* 1) sethi %hi(high_bits), %reg
1964 * or %reg, %lo(high_bits), %reg
1965 * sllx %reg, 32, %reg
1969 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
1973 /* We may be able to do something quick
1974 when the constant is negated, so try that. */
1975 if (const64_is_2insns ((~high_bits) & 0xffffffff,
1976 (~low_bits) & 0xfffffc00))
1978 /* NOTE: The trailing bits get XOR'd so we need the
1979 non-negated bits, not the negated ones. */
1980 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
1982 if ((((~high_bits) & 0xffffffff) == 0
1983 && ((~low_bits) & 0x80000000) == 0)
1984 || (((~high_bits) & 0xffffffff) == 0xffffffff
1985 && ((~low_bits) & 0x80000000) != 0))
1987 int fast_int = (~low_bits & 0xffffffff);
1989 if ((SPARC_SETHI_P (fast_int)
1990 && (~high_bits & 0xffffffff) == 0)
1991 || SPARC_SIMM13_P (fast_int))
1992 emit_insn (gen_safe_SET64 (temp, fast_int));
1994 sparc_emit_set_const64 (temp, GEN_INT64 (fast_int));
1999 #if HOST_BITS_PER_WIDE_INT == 64
2000 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2001 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2003 negated_const = gen_rtx_CONST_DOUBLE (DImode, const0_rtx,
2004 (~low_bits) & 0xfffffc00,
2005 (~high_bits) & 0xffffffff);
2007 sparc_emit_set_const64 (temp, negated_const);
2010 /* If we are XOR'ing with -1, then we should emit a one's complement
2011 instead. This way the combiner will notice logical operations
2012 such as ANDN later on and substitute. */
2013 if (trailing_bits == 0x3ff)
2015 emit_insn (gen_rtx_SET (VOIDmode, op0,
2016 gen_rtx_NOT (DImode, temp)));
2020 emit_insn (gen_rtx_SET (VOIDmode,
2022 gen_safe_XOR64 (temp,
2023 (-0x400 | trailing_bits))));
2028 /* 1) sethi %hi(xxx), %reg
2029 * or %reg, %lo(xxx), %reg
2030 * sllx %reg, yyy, %reg
2032 * ??? This is just a generalized version of the low_bits==0
2033 * thing above, FIXME...
2035 if ((highest_bit_set - lowest_bit_set) < 32)
2037 unsigned HOST_WIDE_INT focus_bits =
2038 create_simple_focus_bits (high_bits, low_bits,
2041 /* We can't get here in this state. */
2042 if (highest_bit_set < 32
2043 || lowest_bit_set >= 32)
2046 /* So what we know is that the set bits straddle the
2047 middle of the 64-bit word. */
2048 sparc_emit_set_const64_quick2 (op0, temp,
2054 /* 1) sethi %hi(high_bits), %reg
2055 * or %reg, %lo(high_bits), %reg
2056 * sllx %reg, 32, %reg
2057 * or %reg, low_bits, %reg
2059 if (SPARC_SIMM13_P(low_bits)
2060 && ((int)low_bits > 0))
2062 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2066 /* The easiest way when all else fails, is full decomposition. */
2068 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
2069 high_bits, low_bits, ~high_bits, ~low_bits);
2071 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2074 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2075 return the mode to be used for the comparison. For floating-point,
2076 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2077 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2078 processing is needed. */
2081 select_cc_mode (op, x, y)
2084 rtx y ATTRIBUTE_UNUSED;
2086 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2112 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2113 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2115 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2116 return CCX_NOOVmode;
2122 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2129 /* X and Y are two things to compare using CODE. Emit the compare insn and
2130 return the rtx for the cc reg in the proper mode. */
2133 gen_compare_reg (code, x, y)
2137 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
2140 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2141 fcc regs (cse can't tell they're really call clobbered regs and will
2142 remove a duplicate comparison even if there is an intervening function
2143 call - it will then try to reload the cc reg via an int reg which is why
2144 we need the movcc patterns). It is possible to provide the movcc
2145 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2146 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2147 to tell cse that CCFPE mode registers (even pseudos) are call
2150 /* ??? This is an experiment. Rather than making changes to cse which may
2151 or may not be easy/clean, we do our own cse. This is possible because
2152 we will generate hard registers. Cse knows they're call clobbered (it
2153 doesn't know the same thing about pseudos). If we guess wrong, no big
2154 deal, but if we win, great! */
2156 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2157 #if 1 /* experiment */
2160 /* We cycle through the registers to ensure they're all exercised. */
2161 static int next_fcc_reg = 0;
2162 /* Previous x,y for each fcc reg. */
2163 static rtx prev_args[4][2];
2165 /* Scan prev_args for x,y. */
2166 for (reg = 0; reg < 4; reg++)
2167 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2172 prev_args[reg][0] = x;
2173 prev_args[reg][1] = y;
2174 next_fcc_reg = (next_fcc_reg + 1) & 3;
2176 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2179 cc_reg = gen_reg_rtx (mode);
2180 #endif /* ! experiment */
2181 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2182 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2184 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2186 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2187 gen_rtx_COMPARE (mode, x, y)));
2192 /* This function is used for v9 only.
2193 CODE is the code for an Scc's comparison.
2194 OPERANDS[0] is the target of the Scc insn.
2195 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
2196 been generated yet).
2198 This function is needed to turn
2201 (gt (reg:CCX 100 %icc)
2205 (gt:DI (reg:CCX 100 %icc)
2208 IE: The instruction recognizer needs to see the mode of the comparison to
2209 find the right instruction. We could use "gt:DI" right in the
2210 define_expand, but leaving it out allows us to handle DI, SI, etc.
2212 We refer to the global sparc compare operands sparc_compare_op0 and
2213 sparc_compare_op1. */
2216 gen_v9_scc (compare_code, operands)
2217 enum rtx_code compare_code;
2218 register rtx *operands;
2223 && (GET_MODE (sparc_compare_op0) == DImode
2224 || GET_MODE (operands[0]) == DImode))
2227 /* Handle the case where operands[0] == sparc_compare_op0.
2228 We "early clobber" the result. */
2229 if (REGNO (operands[0]) == REGNO (sparc_compare_op0))
2231 op0 = gen_reg_rtx (GET_MODE (sparc_compare_op0));
2232 emit_move_insn (op0, sparc_compare_op0);
2235 op0 = sparc_compare_op0;
2236 /* For consistency in the following. */
2237 op1 = sparc_compare_op1;
2239 /* Try to use the movrCC insns. */
2241 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
2242 && op1 == const0_rtx
2243 && v9_regcmp_p (compare_code))
2245 /* Special case for op0 != 0. This can be done with one instruction if
2246 operands[0] == sparc_compare_op0. We don't assume they are equal
2249 if (compare_code == NE
2250 && GET_MODE (operands[0]) == DImode
2251 && GET_MODE (op0) == DImode)
2253 emit_insn (gen_rtx_SET (VOIDmode, operands[0], op0));
2254 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2255 gen_rtx_IF_THEN_ELSE (DImode,
2256 gen_rtx_fmt_ee (compare_code, DImode,
2263 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2264 if (GET_MODE (op0) != DImode)
2266 temp = gen_reg_rtx (DImode);
2267 convert_move (temp, op0, 0);
2271 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2272 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2273 gen_rtx_fmt_ee (compare_code, DImode,
2281 operands[1] = gen_compare_reg (compare_code, op0, op1);
2283 switch (GET_MODE (operands[1]))
2293 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2294 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2295 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2296 gen_rtx_fmt_ee (compare_code,
2297 GET_MODE (operands[1]),
2298 operands[1], const0_rtx),
2299 const1_rtx, operands[0])));
2304 /* Emit a conditional jump insn for the v9 architecture using comparison code
2305 CODE and jump target LABEL.
2306 This function exists to take advantage of the v9 brxx insns. */
2309 emit_v9_brxx_insn (code, op0, label)
2313 emit_jump_insn (gen_rtx_SET (VOIDmode,
2315 gen_rtx_IF_THEN_ELSE (VOIDmode,
2316 gen_rtx_fmt_ee (code, GET_MODE (op0),
2318 gen_rtx_LABEL_REF (VOIDmode, label),
2322 /* Generate a DFmode part of a hard TFmode register.
2323 REG is the TFmode hard register, LOW is 1 for the
2324 low 64bit of the register and 0 otherwise.
2327 gen_df_reg (reg, low)
2331 int regno = REGNO (reg);
2333 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2334 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
2335 return gen_rtx_REG (DFmode, regno);
2338 /* Return nonzero if a return peephole merging return with
2339 setting of output register is ok. */
2341 leaf_return_peephole_ok ()
2343 return (actual_fsize == 0);
2346 /* Return nonzero if TRIAL can go into the function epilogue's
2347 delay slot. SLOT is the slot we are trying to fill. */
2350 eligible_for_epilogue_delay (trial, slot)
2359 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2362 if (get_attr_length (trial) != 1)
2365 /* If %g0 is live, there are lots of things we can't handle.
2366 Rather than trying to find them all now, let's punt and only
2367 optimize things as necessary. */
2371 /* If there are any call-saved registers, we should scan TRIAL if it
2372 does not reference them. For now just make it easy. */
2376 /* In the case of a true leaf function, anything can go into the delay slot.
2377 A delay slot only exists however if the frame size is zero, otherwise
2378 we will put an insn to adjust the stack after the return. */
2379 if (current_function_uses_only_leaf_regs)
2381 if (leaf_return_peephole_ok ())
2382 return ((get_attr_in_uncond_branch_delay (trial)
2383 == IN_BRANCH_DELAY_TRUE));
2387 /* If only trivial `restore' insns work, nothing can go in the
2389 else if (TARGET_BROKEN_SAVERESTORE)
2392 pat = PATTERN (trial);
2394 /* Otherwise, only operations which can be done in tandem with
2395 a `restore' or `return' insn can go into the delay slot. */
2396 if (GET_CODE (SET_DEST (pat)) != REG
2397 || REGNO (SET_DEST (pat)) < 24)
2400 /* If this instruction sets up floating point register and we have a return
2401 instruction, it can probably go in. But restore will not work
2403 if (REGNO (SET_DEST (pat)) >= 32)
2405 if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2406 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2411 /* The set of insns matched here must agree precisely with the set of
2412 patterns paired with a RETURN in sparc.md. */
2414 src = SET_SRC (pat);
2416 /* This matches "*return_[qhs]i" or even "*return_di" on TARGET_ARCH64. */
2417 if (arith_operand (src, GET_MODE (src)))
2420 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2422 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2425 /* This matches "*return_di". */
2426 else if (arith_double_operand (src, GET_MODE (src)))
2427 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2429 /* This matches "*return_sf_no_fpu". */
2430 else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode)
2431 && register_operand (src, SFmode))
2434 /* If we have return instruction, anything that does not use
2435 local or output registers and can go into a delay slot wins. */
2436 else if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2437 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2440 /* This matches "*return_addsi". */
2441 else if (GET_CODE (src) == PLUS
2442 && arith_operand (XEXP (src, 0), SImode)
2443 && arith_operand (XEXP (src, 1), SImode)
2444 && (register_operand (XEXP (src, 0), SImode)
2445 || register_operand (XEXP (src, 1), SImode)))
2448 /* This matches "*return_adddi". */
2449 else if (GET_CODE (src) == PLUS
2450 && arith_double_operand (XEXP (src, 0), DImode)
2451 && arith_double_operand (XEXP (src, 1), DImode)
2452 && (register_operand (XEXP (src, 0), DImode)
2453 || register_operand (XEXP (src, 1), DImode)))
2456 /* This can match "*return_losum_[sd]i".
2457 Catch only some cases, so that return_losum* don't have
2459 else if (GET_CODE (src) == LO_SUM
2460 && ! TARGET_CM_MEDMID
2461 && ((register_operand (XEXP (src, 0), SImode)
2462 && immediate_operand (XEXP (src, 1), SImode))
2464 && register_operand (XEXP (src, 0), DImode)
2465 && immediate_operand (XEXP (src, 1), DImode))))
2468 /* sll{,x} reg,1,reg2 is add reg,reg,reg2 as well. */
2469 else if (GET_CODE (src) == ASHIFT
2470 && (register_operand (XEXP (src, 0), SImode)
2471 || register_operand (XEXP (src, 0), DImode))
2472 && XEXP (src, 1) == const1_rtx)
2479 check_return_regs (x)
2482 switch (GET_CODE (x))
2485 return IN_OR_GLOBAL_P (x);
2500 if (check_return_regs (XEXP (x, 1)) == 0)
2505 return check_return_regs (XEXP (x, 0));
2513 /* Return 1 if TRIAL references only in and global registers. */
2515 eligible_for_return_delay (trial)
2518 if (GET_CODE (PATTERN (trial)) != SET)
2521 return check_return_regs (PATTERN (trial));
2525 short_branch (uid1, uid2)
2528 unsigned int delta = insn_addresses[uid1] - insn_addresses[uid2];
2529 if (delta + 1024 < 2048)
2531 /* warning ("long branch, distance %d", delta); */
2535 /* Return non-zero if REG is not used after INSN.
2536 We assume REG is a reload reg, and therefore does
2537 not live past labels or calls or jumps. */
2539 reg_unused_after (reg, insn)
2543 enum rtx_code code, prev_code = UNKNOWN;
2545 while ((insn = NEXT_INSN (insn)))
2547 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
2550 code = GET_CODE (insn);
2551 if (GET_CODE (insn) == CODE_LABEL)
2554 if (GET_RTX_CLASS (code) == 'i')
2556 rtx set = single_set (insn);
2557 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
2560 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
2562 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
2570 /* The table we use to reference PIC data. */
2571 static rtx global_offset_table;
2573 /* The function we use to get at it. */
2574 static rtx get_pc_symbol;
2575 static char get_pc_symbol_name[256];
2577 /* Ensure that we are not using patterns that are not OK with PIC. */
2586 if (GET_CODE (recog_data.operand[i]) == SYMBOL_REF
2587 || (GET_CODE (recog_data.operand[i]) == CONST
2588 && ! (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
2589 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
2590 == global_offset_table)
2591 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
2600 /* Return true if X is an address which needs a temporary register when
2601 reloaded while generating PIC code. */
2604 pic_address_needs_scratch (x)
2607 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
2608 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2609 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2610 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2611 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
2617 /* Legitimize PIC addresses. If the address is already position-independent,
2618 we return ORIG. Newly generated position-independent addresses go into a
2619 reg. This is REG if non zero, otherwise we allocate register(s) as
2623 legitimize_pic_address (orig, mode, reg)
2625 enum machine_mode mode ATTRIBUTE_UNUSED;
2628 if (GET_CODE (orig) == SYMBOL_REF)
2630 rtx pic_ref, address;
2635 if (reload_in_progress || reload_completed)
2638 reg = gen_reg_rtx (Pmode);
2643 /* If not during reload, allocate another temp reg here for loading
2644 in the address, so that these instructions can be optimized
2646 rtx temp_reg = ((reload_in_progress || reload_completed)
2647 ? reg : gen_reg_rtx (Pmode));
2649 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
2650 won't get confused into thinking that these two instructions
2651 are loading in the true address of the symbol. If in the
2652 future a PIC rtx exists, that should be used instead. */
2653 if (Pmode == SImode)
2655 emit_insn (gen_movsi_high_pic (temp_reg, orig));
2656 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
2660 emit_insn (gen_movdi_high_pic (temp_reg, orig));
2661 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
2668 pic_ref = gen_rtx_MEM (Pmode,
2669 gen_rtx_PLUS (Pmode,
2670 pic_offset_table_rtx, address));
2671 current_function_uses_pic_offset_table = 1;
2672 RTX_UNCHANGING_P (pic_ref) = 1;
2673 insn = emit_move_insn (reg, pic_ref);
2674 /* Put a REG_EQUAL note on this insn, so that it can be optimized
2676 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
2680 else if (GET_CODE (orig) == CONST)
2684 if (GET_CODE (XEXP (orig, 0)) == PLUS
2685 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
2690 if (reload_in_progress || reload_completed)
2693 reg = gen_reg_rtx (Pmode);
2696 if (GET_CODE (XEXP (orig, 0)) == PLUS)
2698 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
2699 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
2700 base == reg ? 0 : reg);
2705 if (GET_CODE (offset) == CONST_INT)
2707 if (SMALL_INT (offset))
2708 return plus_constant_for_output (base, INTVAL (offset));
2709 else if (! reload_in_progress && ! reload_completed)
2710 offset = force_reg (Pmode, offset);
2712 /* If we reach here, then something is seriously wrong. */
2715 return gen_rtx_PLUS (Pmode, base, offset);
2717 else if (GET_CODE (orig) == LABEL_REF)
2718 /* ??? Why do we do this? */
2719 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
2720 the register is live instead, in case it is eliminated. */
2721 current_function_uses_pic_offset_table = 1;
2726 /* Return the RTX for insns to set the PIC register. */
2734 emit_insn (gen_get_pc (pic_offset_table_rtx, global_offset_table,
2736 seq = gen_sequence ();
2742 /* Emit special PIC prologues and epilogues. */
2747 /* Labels to get the PC in the prologue of this function. */
2748 int orig_flag_pic = flag_pic;
2751 if (current_function_uses_pic_offset_table == 0)
2757 /* If we havn't emitted the special get_pc helper function, do so now. */
2758 if (get_pc_symbol_name[0] == 0)
2762 ASM_GENERATE_INTERNAL_LABEL (get_pc_symbol_name, "LGETPC", 0);
2765 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
2767 ASM_OUTPUT_ALIGN (asm_out_file, align);
2768 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LGETPC", 0);
2769 fputs ("\tretl\n\tadd %o7,%l7,%l7\n", asm_out_file);
2772 /* Initialize every time through, since we can't easily
2773 know this to be permanent. */
2774 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2775 get_pc_symbol = gen_rtx_SYMBOL_REF (Pmode, get_pc_symbol_name);
2778 emit_insn_after (pic_setup_code (), get_insns ());
2780 /* Insert the code in each nonlocal goto receiver.
2781 If you make changes here or to the nonlocal_goto_receiver
2782 pattern, make sure the unspec_volatile numbers still
2784 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2785 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
2786 && XINT (PATTERN (insn), 1) == 5)
2787 emit_insn_after (pic_setup_code (), insn);
2789 flag_pic = orig_flag_pic;
2791 /* Need to emit this whether or not we obey regdecls,
2792 since setjmp/longjmp can cause life info to screw up.
2793 ??? In the case where we don't obey regdecls, this is not sufficient
2794 since we may not fall out the bottom. */
2795 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
2798 /* Return 1 if RTX is a MEM which is known to be aligned to at
2799 least an 8 byte boundary. */
2802 mem_min_alignment (mem, desired)
2806 rtx addr, base, offset;
2808 /* If it's not a MEM we can't accept it. */
2809 if (GET_CODE (mem) != MEM)
2812 addr = XEXP (mem, 0);
2813 base = offset = NULL_RTX;
2814 if (GET_CODE (addr) == PLUS)
2816 if (GET_CODE (XEXP (addr, 0)) == REG)
2818 base = XEXP (addr, 0);
2820 /* What we are saying here is that if the base
2821 REG is aligned properly, the compiler will make
2822 sure any REG based index upon it will be so
2824 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
2825 offset = XEXP (addr, 1);
2827 offset = const0_rtx;
2830 else if (GET_CODE (addr) == REG)
2833 offset = const0_rtx;
2836 if (base != NULL_RTX)
2838 int regno = REGNO (base);
2840 if (regno != FRAME_POINTER_REGNUM
2841 && regno != STACK_POINTER_REGNUM)
2843 /* Check if the compiler has recorded some information
2844 about the alignment of the base REG. If reload has
2845 completed, we already matched with proper alignments. */
2846 if (((cfun != 0 && REGNO_POINTER_ALIGN (regno) >= desired)
2847 || reload_completed)
2848 && ((INTVAL (offset) & (desired - 1)) == 0))
2853 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
2857 else if (! TARGET_UNALIGNED_DOUBLES
2858 || CONSTANT_P (addr)
2859 || GET_CODE (addr) == LO_SUM)
2861 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
2862 is true, in which case we can only assume that an access is aligned if
2863 it is to a constant address, or the address involves a LO_SUM. */
2867 /* An obviously unaligned address. */
2872 /* Vectors to keep interesting information about registers where it can easily
2873 be got. We use to use the actual mode value as the bit number, but there
2874 are more than 32 modes now. Instead we use two tables: one indexed by
2875 hard register number, and one indexed by mode. */
2877 /* The purpose of sparc_mode_class is to shrink the range of modes so that
2878 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
2879 mapped into one sparc_mode_class mode. */
2881 enum sparc_mode_class {
2882 S_MODE, D_MODE, T_MODE, O_MODE,
2883 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
2887 /* Modes for single-word and smaller quantities. */
2888 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
2890 /* Modes for double-word and smaller quantities. */
2891 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
2893 /* Modes for quad-word and smaller quantities. */
2894 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
2896 /* Modes for 8-word and smaller quantities. */
2897 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
2899 /* Modes for single-float quantities. We must allow any single word or
2900 smaller quantity. This is because the fix/float conversion instructions
2901 take integer inputs/outputs from the float registers. */
2902 #define SF_MODES (S_MODES)
2904 /* Modes for double-float and smaller quantities. */
2905 #define DF_MODES (S_MODES | D_MODES)
2907 /* Modes for double-float only quantities. */
2908 #define DF_MODES_NO_S (D_MODES)
2910 /* Modes for quad-float only quantities. */
2911 #define TF_ONLY_MODES (1 << (int) TF_MODE)
2913 /* Modes for quad-float and smaller quantities. */
2914 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
2916 /* Modes for quad-float and double-float quantities. */
2917 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
2919 /* Modes for quad-float pair only quantities. */
2920 #define OF_ONLY_MODES (1 << (int) OF_MODE)
2922 /* Modes for quad-float pairs and smaller quantities. */
2923 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
2925 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
2927 /* Modes for condition codes. */
2928 #define CC_MODES (1 << (int) CC_MODE)
2929 #define CCFP_MODES (1 << (int) CCFP_MODE)
2931 /* Value is 1 if register/mode pair is acceptable on sparc.
2932 The funny mixture of D and T modes is because integer operations
2933 do not specially operate on tetra quantities, so non-quad-aligned
2934 registers can hold quadword quantities (except %o4 and %i4 because
2935 they cross fixed registers). */
2937 /* This points to either the 32 bit or the 64 bit version. */
2938 int *hard_regno_mode_classes;
2940 static int hard_32bit_mode_classes[] = {
2941 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
2942 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
2943 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
2944 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
2946 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
2947 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
2948 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
2949 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
2951 /* FP regs f32 to f63. Only the even numbered registers actually exist,
2952 and none can hold SFmode/SImode values. */
2953 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
2954 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
2955 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
2956 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
2959 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
2965 static int hard_64bit_mode_classes[] = {
2966 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
2967 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
2968 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
2969 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
2971 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
2972 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
2973 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
2974 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
2976 /* FP regs f32 to f63. Only the even numbered registers actually exist,
2977 and none can hold SFmode/SImode values. */
2978 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
2979 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
2980 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
2981 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
2984 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
2990 int sparc_mode_class [NUM_MACHINE_MODES];
2992 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
2999 for (i = 0; i < NUM_MACHINE_MODES; i++)
3001 switch (GET_MODE_CLASS (i))
3004 case MODE_PARTIAL_INT:
3005 case MODE_COMPLEX_INT:
3006 if (GET_MODE_SIZE (i) <= 4)
3007 sparc_mode_class[i] = 1 << (int) S_MODE;
3008 else if (GET_MODE_SIZE (i) == 8)
3009 sparc_mode_class[i] = 1 << (int) D_MODE;
3010 else if (GET_MODE_SIZE (i) == 16)
3011 sparc_mode_class[i] = 1 << (int) T_MODE;
3012 else if (GET_MODE_SIZE (i) == 32)
3013 sparc_mode_class[i] = 1 << (int) O_MODE;
3015 sparc_mode_class[i] = 0;
3018 case MODE_COMPLEX_FLOAT:
3019 if (GET_MODE_SIZE (i) <= 4)
3020 sparc_mode_class[i] = 1 << (int) SF_MODE;
3021 else if (GET_MODE_SIZE (i) == 8)
3022 sparc_mode_class[i] = 1 << (int) DF_MODE;
3023 else if (GET_MODE_SIZE (i) == 16)
3024 sparc_mode_class[i] = 1 << (int) TF_MODE;
3025 else if (GET_MODE_SIZE (i) == 32)
3026 sparc_mode_class[i] = 1 << (int) OF_MODE;
3028 sparc_mode_class[i] = 0;
3032 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
3033 we must explicitly check for them here. */
3034 if (i == (int) CCFPmode || i == (int) CCFPEmode)
3035 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
3036 else if (i == (int) CCmode || i == (int) CC_NOOVmode
3037 || i == (int) CCXmode || i == (int) CCX_NOOVmode)
3038 sparc_mode_class[i] = 1 << (int) CC_MODE;
3040 sparc_mode_class[i] = 0;
3046 hard_regno_mode_classes = hard_64bit_mode_classes;
3048 hard_regno_mode_classes = hard_32bit_mode_classes;
3050 /* Initialize the array used by REGNO_REG_CLASS. */
3051 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3053 if (i < 16 && TARGET_V8PLUS)
3054 sparc_regno_reg_class[i] = I64_REGS;
3056 sparc_regno_reg_class[i] = GENERAL_REGS;
3058 sparc_regno_reg_class[i] = FP_REGS;
3060 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
3062 sparc_regno_reg_class[i] = FPCC_REGS;
3064 sparc_regno_reg_class[i] = NO_REGS;
3068 /* Save non call used registers from LOW to HIGH at BASE+OFFSET.
3069 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3070 v9 int regs as it simplifies the code. */
3073 save_regs (file, low, high, base, offset, n_regs, real_offset)
3083 if (TARGET_ARCH64 && high <= 32)
3085 for (i = low; i < high; i++)
3087 if (regs_ever_live[i] && ! call_used_regs[i])
3089 fprintf (file, "\tstx\t%s, [%s+%d]\n",
3090 reg_names[i], base, offset + 4 * n_regs);
3091 if (dwarf2out_do_frame ())
3092 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3099 for (i = low; i < high; i += 2)
3101 if (regs_ever_live[i] && ! call_used_regs[i])
3103 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3105 fprintf (file, "\tstd\t%s, [%s+%d]\n",
3106 reg_names[i], base, offset + 4 * n_regs);
3107 if (dwarf2out_do_frame ())
3109 char *l = dwarf2out_cfi_label ();
3110 dwarf2out_reg_save (l, i, real_offset + 4 * n_regs);
3111 dwarf2out_reg_save (l, i+1, real_offset + 4 * n_regs + 4);
3117 fprintf (file, "\tst\t%s, [%s+%d]\n",
3118 reg_names[i], base, offset + 4 * n_regs);
3119 if (dwarf2out_do_frame ())
3120 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3126 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3128 fprintf (file, "\tst\t%s, [%s+%d]\n",
3129 reg_names[i+1], base, offset + 4 * n_regs + 4);
3130 if (dwarf2out_do_frame ())
3131 dwarf2out_reg_save ("", i + 1, real_offset + 4 * n_regs + 4);
3140 /* Restore non call used registers from LOW to HIGH at BASE+OFFSET.
3142 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3143 v9 int regs as it simplifies the code. */
3146 restore_regs (file, low, high, base, offset, n_regs)
3155 if (TARGET_ARCH64 && high <= 32)
3157 for (i = low; i < high; i++)
3159 if (regs_ever_live[i] && ! call_used_regs[i])
3160 fprintf (file, "\tldx\t[%s+%d], %s\n",
3161 base, offset + 4 * n_regs, reg_names[i]),
3167 for (i = low; i < high; i += 2)
3169 if (regs_ever_live[i] && ! call_used_regs[i])
3170 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3171 fprintf (file, "\tldd\t[%s+%d], %s\n",
3172 base, offset + 4 * n_regs, reg_names[i]),
3175 fprintf (file, "\tld\t[%s+%d],%s\n",
3176 base, offset + 4 * n_regs, reg_names[i]),
3178 else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3179 fprintf (file, "\tld\t[%s+%d],%s\n",
3180 base, offset + 4 * n_regs + 4, reg_names[i+1]),
3187 /* Compute the frame size required by the function. This function is called
3188 during the reload pass and also by output_function_prologue(). */
3191 compute_frame_size (size, leaf_function)
3196 int outgoing_args_size = (current_function_outgoing_args_size
3197 + REG_PARM_STACK_SPACE (current_function_decl));
3199 if (TARGET_EPILOGUE)
3201 /* N_REGS is the number of 4-byte regs saved thus far. This applies
3202 even to v9 int regs to be consistent with save_regs/restore_regs. */
3206 for (i = 0; i < 8; i++)
3207 if (regs_ever_live[i] && ! call_used_regs[i])
3212 for (i = 0; i < 8; i += 2)
3213 if ((regs_ever_live[i] && ! call_used_regs[i])
3214 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3218 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
3219 if ((regs_ever_live[i] && ! call_used_regs[i])
3220 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3224 /* Set up values for use in `function_epilogue'. */
3225 num_gfregs = n_regs;
3227 if (leaf_function && n_regs == 0
3228 && size == 0 && current_function_outgoing_args_size == 0)
3230 actual_fsize = apparent_fsize = 0;
3234 /* We subtract STARTING_FRAME_OFFSET, remember it's negative.
3235 The stack bias (if any) is taken out to undo its effects. */
3236 apparent_fsize = (size - STARTING_FRAME_OFFSET + SPARC_STACK_BIAS + 7) & -8;
3237 apparent_fsize += n_regs * 4;
3238 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
3241 /* Make sure nothing can clobber our register windows.
3242 If a SAVE must be done, or there is a stack-local variable,
3243 the register window area must be allocated.
3244 ??? For v8 we apparently need an additional 8 bytes of reserved space. */
3245 if (leaf_function == 0 || size > 0)
3246 actual_fsize += (16 * UNITS_PER_WORD) + (TARGET_ARCH64 ? 0 : 8);
3248 return SPARC_STACK_ALIGN (actual_fsize);
3251 /* Build a (32 bit) big number in a register. */
3252 /* ??? We may be able to use the set macro here too. */
3255 build_big_number (file, num, reg)
3260 if (num >= 0 || ! TARGET_ARCH64)
3262 fprintf (file, "\tsethi\t%%hi(%d), %s\n", num, reg);
3263 if ((num & 0x3ff) != 0)
3264 fprintf (file, "\tor\t%s, %%lo(%d), %s\n", reg, num, reg);
3266 else /* num < 0 && TARGET_ARCH64 */
3268 /* Sethi does not sign extend, so we must use a little trickery
3269 to use it for negative numbers. Invert the constant before
3270 loading it in, then use xor immediate to invert the loaded bits
3271 (along with the upper 32 bits) to the desired constant. This
3272 works because the sethi and immediate fields overlap. */
3275 int low = -0x400 + (asize & 0x3FF);
3277 fprintf (file, "\tsethi\t%%hi(%d), %s\n\txor\t%s, %d, %s\n",
3278 inv, reg, reg, low, reg);
3282 /* Output any necessary .register pseudo-ops. */
3284 sparc_output_scratch_registers (file)
3285 FILE *file ATTRIBUTE_UNUSED;
3287 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
3293 /* Check if %g[2367] were used without
3294 .register being printed for them already. */
3295 for (i = 2; i < 8; i++)
3297 if (regs_ever_live [i]
3298 && ! sparc_hard_reg_printed [i])
3300 sparc_hard_reg_printed [i] = 1;
3301 fprintf (file, "\t.register\t%%g%d, #scratch\n", i);
3308 /* Output code for the function prologue. */
3311 output_function_prologue (file, size, leaf_function)
3316 sparc_output_scratch_registers (file);
3318 /* Need to use actual_fsize, since we are also allocating
3319 space for our callee (and our own register save area). */
3320 actual_fsize = compute_frame_size (size, leaf_function);
3324 frame_base_name = "%sp";
3325 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
3329 frame_base_name = "%fp";
3330 frame_base_offset = SPARC_STACK_BIAS;
3333 /* This is only for the human reader. */
3334 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
3336 if (actual_fsize == 0)
3338 else if (! leaf_function && ! TARGET_BROKEN_SAVERESTORE)
3340 if (actual_fsize <= 4096)
3341 fprintf (file, "\tsave\t%%sp, -%d, %%sp\n", actual_fsize);
3342 else if (actual_fsize <= 8192)
3344 fprintf (file, "\tsave\t%%sp, -4096, %%sp\n");
3345 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3349 build_big_number (file, -actual_fsize, "%g1");
3350 fprintf (file, "\tsave\t%%sp, %%g1, %%sp\n");
3353 else if (! leaf_function && TARGET_BROKEN_SAVERESTORE)
3355 /* We assume the environment will properly handle or otherwise avoid
3356 trouble associated with an interrupt occurring after the `save' or
3357 trap occurring during it. */
3358 fprintf (file, "\tsave\n");
3360 if (actual_fsize <= 4096)
3361 fprintf (file, "\tadd\t%%fp, -%d, %%sp\n", actual_fsize);
3362 else if (actual_fsize <= 8192)
3364 fprintf (file, "\tadd\t%%fp, -4096, %%sp\n");
3365 fprintf (file, "\tadd\t%%fp, -%d, %%sp\n", actual_fsize - 4096);
3369 build_big_number (file, -actual_fsize, "%g1");
3370 fprintf (file, "\tadd\t%%fp, %%g1, %%sp\n");
3373 else /* leaf function */
3375 if (actual_fsize <= 4096)
3376 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize);
3377 else if (actual_fsize <= 8192)
3379 fprintf (file, "\tadd\t%%sp, -4096, %%sp\n");
3380 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3384 build_big_number (file, -actual_fsize, "%g1");
3385 fprintf (file, "\tadd\t%%sp, %%g1, %%sp\n");
3389 if (dwarf2out_do_frame () && actual_fsize)
3391 char *label = dwarf2out_cfi_label ();
3393 /* The canonical frame address refers to the top of the frame. */
3394 dwarf2out_def_cfa (label, (leaf_function ? STACK_POINTER_REGNUM
3395 : FRAME_POINTER_REGNUM),
3398 if (! leaf_function)
3400 /* Note the register window save. This tells the unwinder that
3401 it needs to restore the window registers from the previous
3402 frame's window save area at 0(cfa). */
3403 dwarf2out_window_save (label);
3405 /* The return address (-8) is now in %i7. */
3406 dwarf2out_return_reg (label, 31);
3410 /* If doing anything with PIC, do it now. */
3412 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
3414 /* Call saved registers are saved just above the outgoing argument area. */
3417 int offset, real_offset, n_regs;
3420 real_offset = -apparent_fsize;
3421 offset = -apparent_fsize + frame_base_offset;
3422 if (offset < -4096 || offset + num_gfregs * 4 > 4096)
3424 /* ??? This might be optimized a little as %g1 might already have a
3425 value close enough that a single add insn will do. */
3426 /* ??? Although, all of this is probably only a temporary fix
3427 because if %g1 can hold a function result, then
3428 output_function_epilogue will lose (the result will get
3430 build_big_number (file, offset, "%g1");
3431 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
3437 base = frame_base_name;
3441 if (TARGET_EPILOGUE && ! leaf_function)
3442 /* ??? Originally saved regs 0-15 here. */
3443 n_regs = save_regs (file, 0, 8, base, offset, 0, real_offset);
3444 else if (leaf_function)
3445 /* ??? Originally saved regs 0-31 here. */
3446 n_regs = save_regs (file, 0, 8, base, offset, 0, real_offset);
3447 if (TARGET_EPILOGUE)
3448 save_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs,
3453 if (leaf_function && actual_fsize != 0)
3455 /* warning ("leaf procedure with frame size %d", actual_fsize); */
3456 if (! TARGET_EPILOGUE)
3457 leaf_label = gen_label_rtx ();
3461 /* Output code for the function epilogue. */
3464 output_function_epilogue (file, size, leaf_function)
3466 int size ATTRIBUTE_UNUSED;
3473 emit_label_after (leaf_label, get_last_insn ());
3474 final_scan_insn (get_last_insn (), file, 0, 0, 1);
3477 #ifdef FUNCTION_BLOCK_PROFILER_EXIT
3478 else if (profile_block_flag == 2)
3480 FUNCTION_BLOCK_PROFILER_EXIT(file);
3484 else if (current_function_epilogue_delay_list == 0)
3486 /* If code does not drop into the epilogue, we need
3487 do nothing except output pending case vectors. */
3488 rtx insn = get_last_insn ();
3489 if (GET_CODE (insn) == NOTE)
3490 insn = prev_nonnote_insn (insn);
3491 if (insn && GET_CODE (insn) == BARRIER)
3492 goto output_vectors;
3495 /* Restore any call saved registers. */
3501 offset = -apparent_fsize + frame_base_offset;
3502 if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/)
3504 build_big_number (file, offset, "%g1");
3505 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
3511 base = frame_base_name;
3515 if (TARGET_EPILOGUE && ! leaf_function)
3516 /* ??? Originally saved regs 0-15 here. */
3517 n_regs = restore_regs (file, 0, 8, base, offset, 0);
3518 else if (leaf_function)
3519 /* ??? Originally saved regs 0-31 here. */
3520 n_regs = restore_regs (file, 0, 8, base, offset, 0);
3521 if (TARGET_EPILOGUE)
3522 restore_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs);
3525 /* Work out how to skip the caller's unimp instruction if required. */
3527 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%o7+12" : "retl");
3529 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%i7+12" : "ret");
3531 if (TARGET_EPILOGUE || leaf_label)
3533 int old_target_epilogue = TARGET_EPILOGUE;
3534 target_flags &= ~old_target_epilogue;
3536 if (! leaf_function)
3538 /* If we wound up with things in our delay slot, flush them here. */
3539 if (current_function_epilogue_delay_list)
3541 rtx delay = PATTERN (XEXP (current_function_epilogue_delay_list, 0));
3543 if (TARGET_V9 && ! epilogue_renumber (&delay, 1))
3545 epilogue_renumber (&delay, 0);
3546 fputs (SKIP_CALLERS_UNIMP_P
3547 ? "\treturn\t%i7+12\n"
3548 : "\treturn\t%i7+8\n", file);
3549 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0), file, 1, 0, 0);
3553 rtx insn = emit_jump_insn_after (gen_rtx_RETURN (VOIDmode),
3557 if (GET_CODE (delay) != SET)
3560 src = SET_SRC (delay);
3561 if (GET_CODE (src) == ASHIFT)
3563 if (XEXP (src, 1) != const1_rtx)
3565 SET_SRC (delay) = gen_rtx_PLUS (GET_MODE (src), XEXP (src, 0),
3569 PATTERN (insn) = gen_rtx_PARALLEL (VOIDmode,
3570 gen_rtvec (2, delay, PATTERN (insn)));
3571 final_scan_insn (insn, file, 1, 0, 1);
3574 else if (TARGET_V9 && ! SKIP_CALLERS_UNIMP_P)
3575 fputs ("\treturn\t%i7+8\n\tnop\n", file);
3577 fprintf (file, "\t%s\n\trestore\n", ret);
3579 /* All of the following cases are for leaf functions. */
3580 else if (current_function_epilogue_delay_list)
3582 /* eligible_for_epilogue_delay_slot ensures that if this is a
3583 leaf function, then we will only have insn in the delay slot
3584 if the frame size is zero, thus no adjust for the stack is
3586 if (actual_fsize != 0)
3588 fprintf (file, "\t%s\n", ret);
3589 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
3592 /* Output 'nop' instead of 'sub %sp,-0,%sp' when no frame, so as to
3593 avoid generating confusing assembly language output. */
3594 else if (actual_fsize == 0)
3595 fprintf (file, "\t%s\n\tnop\n", ret);
3596 else if (actual_fsize <= 4096)
3597 fprintf (file, "\t%s\n\tsub\t%%sp, -%d, %%sp\n", ret, actual_fsize);
3598 else if (actual_fsize <= 8192)
3599 fprintf (file, "\tsub\t%%sp, -4096, %%sp\n\t%s\n\tsub\t%%sp, -%d, %%sp\n",
3600 ret, actual_fsize - 4096);
3601 else if ((actual_fsize & 0x3ff) == 0)
3602 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
3605 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\tor\t%%g1, %%lo(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
3606 actual_fsize, actual_fsize, ret);
3607 target_flags |= old_target_epilogue;
3611 sparc_output_deferred_case_vectors ();
3614 /* Functions for handling argument passing.
3616 For v8 the first six args are normally in registers and the rest are
3617 pushed. Any arg that starts within the first 6 words is at least
3618 partially passed in a register unless its data type forbids.
3620 For v9, the argument registers are laid out as an array of 16 elements
3621 and arguments are added sequentially. The first 6 int args and up to the
3622 first 16 fp args (depending on size) are passed in regs.
3624 Slot Stack Integral Float Float in structure Double Long Double
3625 ---- ----- -------- ----- ------------------ ------ -----------
3626 15 [SP+248] %f31 %f30,%f31 %d30
3627 14 [SP+240] %f29 %f28,%f29 %d28 %q28
3628 13 [SP+232] %f27 %f26,%f27 %d26
3629 12 [SP+224] %f25 %f24,%f25 %d24 %q24
3630 11 [SP+216] %f23 %f22,%f23 %d22
3631 10 [SP+208] %f21 %f20,%f21 %d20 %q20
3632 9 [SP+200] %f19 %f18,%f19 %d18
3633 8 [SP+192] %f17 %f16,%f17 %d16 %q16
3634 7 [SP+184] %f15 %f14,%f15 %d14
3635 6 [SP+176] %f13 %f12,%f13 %d12 %q12
3636 5 [SP+168] %o5 %f11 %f10,%f11 %d10
3637 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
3638 3 [SP+152] %o3 %f7 %f6,%f7 %d6
3639 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
3640 1 [SP+136] %o1 %f3 %f2,%f3 %d2
3641 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
3643 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
3645 Integral arguments are always passed as 64 bit quantities appropriately
3648 Passing of floating point values is handled as follows.
3649 If a prototype is in scope:
3650 If the value is in a named argument (i.e. not a stdarg function or a
3651 value not part of the `...') then the value is passed in the appropriate
3653 If the value is part of the `...' and is passed in one of the first 6
3654 slots then the value is passed in the appropriate int reg.
3655 If the value is part of the `...' and is not passed in one of the first 6
3656 slots then the value is passed in memory.
3657 If a prototype is not in scope:
3658 If the value is one of the first 6 arguments the value is passed in the
3659 appropriate integer reg and the appropriate fp reg.
3660 If the value is not one of the first 6 arguments the value is passed in
3661 the appropriate fp reg and in memory.
3664 /* Maximum number of int regs for args. */
3665 #define SPARC_INT_ARG_MAX 6
3666 /* Maximum number of fp regs for args. */
3667 #define SPARC_FP_ARG_MAX 16
3669 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
3671 /* Handle the INIT_CUMULATIVE_ARGS macro.
3672 Initialize a variable CUM of type CUMULATIVE_ARGS
3673 for a call to a function whose data type is FNTYPE.
3674 For a library call, FNTYPE is 0. */
3677 init_cumulative_args (cum, fntype, libname, indirect)
3678 CUMULATIVE_ARGS *cum;
3680 rtx libname ATTRIBUTE_UNUSED;
3681 int indirect ATTRIBUTE_UNUSED;
3684 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
3685 cum->libcall_p = fntype == 0;
3688 /* Compute the slot number to pass an argument in.
3689 Returns the slot number or -1 if passing on the stack.
3691 CUM is a variable of type CUMULATIVE_ARGS which gives info about
3692 the preceding args and about the function being called.
3693 MODE is the argument's machine mode.
3694 TYPE is the data type of the argument (as a tree).
3695 This is null for libcalls where that information may
3697 NAMED is nonzero if this argument is a named parameter
3698 (otherwise it is an extra parameter matching an ellipsis).
3699 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
3700 *PREGNO records the register number to use if scalar type.
3701 *PPADDING records the amount of padding needed in words. */
3704 function_arg_slotno (cum, mode, type, named, incoming_p, pregno, ppadding)
3705 const CUMULATIVE_ARGS *cum;
3706 enum machine_mode mode;
3713 int regbase = (incoming_p
3714 ? SPARC_INCOMING_INT_ARG_FIRST
3715 : SPARC_OUTGOING_INT_ARG_FIRST);
3716 int slotno = cum->words;
3721 if (type != 0 && TREE_ADDRESSABLE (type))
3724 && type != 0 && mode == BLKmode
3725 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
3731 /* MODE is VOIDmode when generating the actual call.
3735 case QImode : case CQImode :
3736 case HImode : case CHImode :
3737 case SImode : case CSImode :
3738 case DImode : case CDImode :
3739 if (slotno >= SPARC_INT_ARG_MAX)
3741 regno = regbase + slotno;
3744 case SFmode : case SCmode :
3745 case DFmode : case DCmode :
3746 case TFmode : case TCmode :
3749 if (slotno >= SPARC_INT_ARG_MAX)
3751 regno = regbase + slotno;
3755 if ((mode == TFmode || mode == TCmode)
3756 && (slotno & 1) != 0)
3757 slotno++, *ppadding = 1;
3758 if (TARGET_FPU && named)
3760 if (slotno >= SPARC_FP_ARG_MAX)
3762 regno = SPARC_FP_ARG_FIRST + slotno * 2;
3768 if (slotno >= SPARC_INT_ARG_MAX)
3770 regno = regbase + slotno;
3776 /* For sparc64, objects requiring 16 byte alignment get it. */
3779 if (type && TYPE_ALIGN (type) == 128 && (slotno & 1) != 0)
3780 slotno++, *ppadding = 1;
3784 || (type && TREE_CODE (type) == UNION_TYPE))
3786 if (slotno >= SPARC_INT_ARG_MAX)
3788 regno = regbase + slotno;
3793 int intregs_p = 0, fpregs_p = 0;
3794 /* The ABI obviously doesn't specify how packed
3795 structures are passed. These are defined to be passed
3796 in int regs if possible, otherwise memory. */
3799 /* First see what kinds of registers we need. */
3800 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3802 if (TREE_CODE (field) == FIELD_DECL)
3804 if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
3809 if (DECL_PACKED (field))
3813 if (packed_p || !named)
3814 fpregs_p = 0, intregs_p = 1;
3816 /* If all arg slots are filled, then must pass on stack. */
3817 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
3819 /* If there are only int args and all int arg slots are filled,
3820 then must pass on stack. */
3821 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
3823 /* Note that even if all int arg slots are filled, fp members may
3824 still be passed in regs if such regs are available.
3825 *PREGNO isn't set because there may be more than one, it's up
3826 to the caller to compute them. */
3839 /* Handle recursive register counting for structure field layout. */
3841 struct function_arg_record_value_parms
3844 int slotno, named, regbase;
3845 int nregs, intoffset;
3848 static void function_arg_record_value_3
3849 PARAMS ((int, struct function_arg_record_value_parms *));
3850 static void function_arg_record_value_2
3851 PARAMS ((tree, int, struct function_arg_record_value_parms *));
3852 static void function_arg_record_value_1
3853 PARAMS ((tree, int, struct function_arg_record_value_parms *));
3854 static rtx function_arg_record_value
3855 PARAMS ((tree, enum machine_mode, int, int, int));
3858 function_arg_record_value_1 (type, startbitpos, parms)
3861 struct function_arg_record_value_parms *parms;
3865 /* The ABI obviously doesn't specify how packed structures are
3866 passed. These are defined to be passed in int regs if possible,
3867 otherwise memory. */
3870 /* We need to compute how many registers are needed so we can
3871 allocate the PARALLEL but before we can do that we need to know
3872 whether there are any packed fields. If there are, int regs are
3873 used regardless of whether there are fp values present. */
3874 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3876 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
3883 /* Compute how many registers we need. */
3884 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3886 if (TREE_CODE (field) == FIELD_DECL)
3888 int bitpos = startbitpos;
3889 if (DECL_FIELD_BITPOS (field))
3890 bitpos += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3891 /* ??? FIXME: else assume zero offset. */
3893 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
3895 function_arg_record_value_1 (TREE_TYPE (field), bitpos, parms);
3897 else if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
3902 if (parms->intoffset != -1)
3904 int intslots, this_slotno;
3906 intslots = (bitpos - parms->intoffset + BITS_PER_WORD - 1)
3908 this_slotno = parms->slotno + parms->intoffset
3911 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
3912 intslots = MAX (intslots, 0);
3913 parms->nregs += intslots;
3914 parms->intoffset = -1;
3917 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
3918 If it wasn't true we wouldn't be here. */
3923 if (parms->intoffset == -1)
3924 parms->intoffset = bitpos;
3930 /* Handle recursive structure field register assignment. */
3933 function_arg_record_value_3 (bitpos, parms)
3935 struct function_arg_record_value_parms *parms;
3937 enum machine_mode mode;
3938 int regno, this_slotno, intslots, intoffset;
3941 if (parms->intoffset == -1)
3943 intoffset = parms->intoffset;
3944 parms->intoffset = -1;
3946 intslots = (bitpos - intoffset + BITS_PER_WORD - 1) / BITS_PER_WORD;
3947 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
3949 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
3953 /* If this is the trailing part of a word, only load that much into
3954 the register. Otherwise load the whole register. Note that in
3955 the latter case we may pick up unwanted bits. It's not a problem
3956 at the moment but may wish to revisit. */
3958 if (intoffset % BITS_PER_WORD != 0)
3960 mode = mode_for_size (BITS_PER_WORD - intoffset%BITS_PER_WORD,
3966 intoffset /= BITS_PER_UNIT;
3969 regno = parms->regbase + this_slotno;
3970 reg = gen_rtx_REG (mode, regno);
3971 XVECEXP (parms->ret, 0, parms->nregs)
3972 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
3975 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
3979 while (intslots > 0);
3983 function_arg_record_value_2 (type, startbitpos, parms)
3986 struct function_arg_record_value_parms *parms;
3991 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3993 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4000 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4002 if (TREE_CODE (field) == FIELD_DECL)
4004 int bitpos = startbitpos;
4005 if (DECL_FIELD_BITPOS (field))
4006 bitpos += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4007 /* ??? FIXME: else assume zero offset. */
4009 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4011 function_arg_record_value_2 (TREE_TYPE (field), bitpos, parms);
4013 else if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4018 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
4021 function_arg_record_value_3 (bitpos, parms);
4023 reg = gen_rtx_REG (DECL_MODE (field),
4024 (SPARC_FP_ARG_FIRST + this_slotno * 2
4025 + (DECL_MODE (field) == SFmode
4026 && (bitpos & 32) != 0)));
4027 XVECEXP (parms->ret, 0, parms->nregs)
4028 = gen_rtx_EXPR_LIST (VOIDmode, reg,
4029 GEN_INT (bitpos / BITS_PER_UNIT));
4034 if (parms->intoffset == -1)
4035 parms->intoffset = bitpos;
4042 function_arg_record_value (type, mode, slotno, named, regbase)
4044 enum machine_mode mode;
4045 int slotno, named, regbase;
4047 HOST_WIDE_INT typesize = int_size_in_bytes (type);
4048 struct function_arg_record_value_parms parms;
4051 parms.ret = NULL_RTX;
4052 parms.slotno = slotno;
4053 parms.named = named;
4054 parms.regbase = regbase;
4056 /* Compute how many registers we need. */
4058 parms.intoffset = 0;
4059 function_arg_record_value_1 (type, 0, &parms);
4061 if (parms.intoffset != -1)
4063 int intslots, this_slotno;
4065 intslots = (typesize*BITS_PER_UNIT - parms.intoffset + BITS_PER_WORD - 1)
4067 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
4069 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4070 intslots = MAX (intslots, 0);
4072 parms.nregs += intslots;
4074 nregs = parms.nregs;
4076 /* Allocate the vector and handle some annoying special cases. */
4079 /* ??? Empty structure has no value? Duh? */
4082 /* Though there's nothing really to store, return a word register
4083 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
4084 leads to breakage due to the fact that there are zero bytes to
4086 return gen_rtx_REG (mode, regbase);
4090 /* ??? C++ has structures with no fields, and yet a size. Give up
4091 for now and pass everything back in integer registers. */
4092 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4094 if (nregs + slotno > SPARC_INT_ARG_MAX)
4095 nregs = SPARC_INT_ARG_MAX - slotno;
4100 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (nregs));
4102 /* Fill in the entries. */
4104 parms.intoffset = 0;
4105 function_arg_record_value_2 (type, 0, &parms);
4106 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
4108 if (parms.nregs != nregs)
4114 /* Handle the FUNCTION_ARG macro.
4115 Determine where to put an argument to a function.
4116 Value is zero to push the argument on the stack,
4117 or a hard register in which to store the argument.
4119 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4120 the preceding args and about the function being called.
4121 MODE is the argument's machine mode.
4122 TYPE is the data type of the argument (as a tree).
4123 This is null for libcalls where that information may
4125 NAMED is nonzero if this argument is a named parameter
4126 (otherwise it is an extra parameter matching an ellipsis).
4127 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
4130 function_arg (cum, mode, type, named, incoming_p)
4131 const CUMULATIVE_ARGS *cum;
4132 enum machine_mode mode;
4137 int regbase = (incoming_p
4138 ? SPARC_INCOMING_INT_ARG_FIRST
4139 : SPARC_OUTGOING_INT_ARG_FIRST);
4140 int slotno, regno, padding;
4143 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
4151 reg = gen_rtx_REG (mode, regno);
4155 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
4156 but also have the slot allocated for them.
4157 If no prototype is in scope fp values in register slots get passed
4158 in two places, either fp regs and int regs or fp regs and memory. */
4159 if ((GET_MODE_CLASS (mode) == MODE_FLOAT
4160 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4161 && SPARC_FP_REG_P (regno))
4163 reg = gen_rtx_REG (mode, regno);
4164 if (cum->prototype_p || cum->libcall_p)
4166 /* "* 2" because fp reg numbers are recorded in 4 byte
4169 /* ??? This will cause the value to be passed in the fp reg and
4170 in the stack. When a prototype exists we want to pass the
4171 value in the reg but reserve space on the stack. That's an
4172 optimization, and is deferred [for a bit]. */
4173 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
4174 return gen_rtx_PARALLEL (mode,
4176 gen_rtx_EXPR_LIST (VOIDmode,
4177 NULL_RTX, const0_rtx),
4178 gen_rtx_EXPR_LIST (VOIDmode,
4182 /* ??? It seems that passing back a register even when past
4183 the area declared by REG_PARM_STACK_SPACE will allocate
4184 space appropriately, and will not copy the data onto the
4185 stack, exactly as we desire.
4187 This is due to locate_and_pad_parm being called in
4188 expand_call whenever reg_parm_stack_space > 0, which
4189 while benefical to our example here, would seem to be
4190 in error from what had been intended. Ho hum... -- r~ */
4198 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
4202 /* On incoming, we don't need to know that the value
4203 is passed in %f0 and %i0, and it confuses other parts
4204 causing needless spillage even on the simplest cases. */
4208 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
4209 + (regno - SPARC_FP_ARG_FIRST) / 2);
4211 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4212 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
4214 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4218 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4219 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4220 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4224 else if (type && TREE_CODE (type) == RECORD_TYPE)
4226 /* Structures up to 16 bytes in size are passed in arg slots on the
4227 stack and are promoted to registers where possible. */
4229 if (int_size_in_bytes (type) > 16)
4230 abort (); /* shouldn't get here */
4232 return function_arg_record_value (type, mode, slotno, named, regbase);
4234 else if (type && TREE_CODE (type) == UNION_TYPE)
4236 enum machine_mode mode;
4237 int bytes = int_size_in_bytes (type);
4242 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
4243 reg = gen_rtx_REG (mode, regno);
4247 /* Scalar or complex int. */
4248 reg = gen_rtx_REG (mode, regno);
4254 /* Handle the FUNCTION_ARG_PARTIAL_NREGS macro.
4255 For an arg passed partly in registers and partly in memory,
4256 this is the number of registers used.
4257 For args passed entirely in registers or entirely in memory, zero.
4259 Any arg that starts in the first 6 regs but won't entirely fit in them
4260 needs partial registers on v8. On v9, structures with integer
4261 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
4262 values that begin in the last fp reg [where "last fp reg" varies with the
4263 mode] will be split between that reg and memory. */
4266 function_arg_partial_nregs (cum, mode, type, named)
4267 const CUMULATIVE_ARGS *cum;
4268 enum machine_mode mode;
4272 int slotno, regno, padding;
4274 /* We pass 0 for incoming_p here, it doesn't matter. */
4275 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
4282 if ((slotno + (mode == BLKmode
4283 ? ROUND_ADVANCE (int_size_in_bytes (type))
4284 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
4285 > NPARM_REGS (SImode))
4286 return NPARM_REGS (SImode) - slotno;
4291 if (type && AGGREGATE_TYPE_P (type))
4293 int size = int_size_in_bytes (type);
4294 int align = TYPE_ALIGN (type);
4297 slotno += slotno & 1;
4298 if (size > 8 && size <= 16
4299 && slotno == SPARC_INT_ARG_MAX - 1)
4302 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
4303 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
4306 if (GET_MODE_ALIGNMENT (mode) == 128)
4308 slotno += slotno & 1;
4309 if (slotno == SPARC_INT_ARG_MAX - 2)
4314 if (slotno == SPARC_INT_ARG_MAX - 1)
4318 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4320 if (GET_MODE_ALIGNMENT (mode) == 128)
4321 slotno += slotno & 1;
4322 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
4330 /* Handle the FUNCTION_ARG_PASS_BY_REFERENCE macro.
4331 !v9: The SPARC ABI stipulates passing struct arguments (of any size) and
4332 quad-precision floats by invisible reference.
4333 v9: Aggregates greater than 16 bytes are passed by reference.
4334 For Pascal, also pass arrays by reference. */
4337 function_arg_pass_by_reference (cum, mode, type, named)
4338 const CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
4339 enum machine_mode mode;
4341 int named ATTRIBUTE_UNUSED;
4345 return ((type && AGGREGATE_TYPE_P (type))
4346 || mode == TFmode || mode == TCmode);
4350 return ((type && TREE_CODE (type) == ARRAY_TYPE)
4351 /* Consider complex values as aggregates, so care for TCmode. */
4352 || GET_MODE_SIZE (mode) > 16
4353 || (type && AGGREGATE_TYPE_P (type)
4354 && int_size_in_bytes (type) > 16));
4358 /* Handle the FUNCTION_ARG_ADVANCE macro.
4359 Update the data in CUM to advance over an argument
4360 of mode MODE and data type TYPE.
4361 TYPE is null for libcalls where that information may not be available. */
4364 function_arg_advance (cum, mode, type, named)
4365 CUMULATIVE_ARGS *cum;
4366 enum machine_mode mode;
4370 int slotno, regno, padding;
4372 /* We pass 0 for incoming_p here, it doesn't matter. */
4373 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
4375 /* If register required leading padding, add it. */
4377 cum->words += padding;
4381 cum->words += (mode != BLKmode
4382 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
4383 : ROUND_ADVANCE (int_size_in_bytes (type)));
4387 if (type && AGGREGATE_TYPE_P (type))
4389 int size = int_size_in_bytes (type);
4393 else if (size <= 16)
4395 else /* passed by reference */
4398 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
4402 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4404 cum->words += GET_MODE_SIZE (mode) / UNITS_PER_WORD;
4408 cum->words += (mode != BLKmode
4409 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
4410 : ROUND_ADVANCE (int_size_in_bytes (type)));
4415 /* Handle the FUNCTION_ARG_PADDING macro.
4416 For the 64 bit ABI structs are always stored left shifted in their
4420 function_arg_padding (mode, type)
4421 enum machine_mode mode;
4424 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
4427 /* This is the default definition. */
4428 return (! BYTES_BIG_ENDIAN
4431 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
4432 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
4433 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
4434 ? downward : upward));
4437 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
4438 For v9, function return values are subject to the same rules as arguments,
4439 except that up to 32-bytes may be returned in registers. */
4442 function_value (type, mode, incoming_p)
4444 enum machine_mode mode;
4448 int regbase = (incoming_p
4449 ? SPARC_OUTGOING_INT_ARG_FIRST
4450 : SPARC_INCOMING_INT_ARG_FIRST);
4452 if (TARGET_ARCH64 && type)
4454 if (TREE_CODE (type) == RECORD_TYPE)
4456 /* Structures up to 32 bytes in size are passed in registers,
4457 promoted to fp registers where possible. */
4459 if (int_size_in_bytes (type) > 32)
4460 abort (); /* shouldn't get here */
4462 return function_arg_record_value (type, mode, 0, 1, regbase);
4464 else if (TREE_CODE (type) == UNION_TYPE)
4466 int bytes = int_size_in_bytes (type);
4471 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
4476 && GET_MODE_CLASS (mode) == MODE_INT
4477 && GET_MODE_SIZE (mode) < UNITS_PER_WORD
4478 && type && TREE_CODE (type) != UNION_TYPE)
4482 regno = BASE_RETURN_VALUE_REG (mode);
4484 regno = BASE_OUTGOING_VALUE_REG (mode);
4486 return gen_rtx_REG (mode, regno);
4489 /* Do what is necessary for `va_start'. We look at the current function
4490 to determine if stdarg or varargs is used and return the address of
4491 the first unnamed parameter. */
4494 sparc_builtin_saveregs ()
4496 int first_reg = current_function_args_info.words;
4500 for (regno = first_reg; regno < NPARM_REGS (word_mode); regno++)
4501 emit_move_insn (gen_rtx_MEM (word_mode,
4502 gen_rtx_PLUS (Pmode,
4504 GEN_INT (STACK_POINTER_OFFSET
4505 + UNITS_PER_WORD * regno))),
4506 gen_rtx_REG (word_mode,
4507 BASE_INCOMING_ARG_REG (word_mode) + regno));
4509 address = gen_rtx_PLUS (Pmode,
4511 GEN_INT (STACK_POINTER_OFFSET
4512 + UNITS_PER_WORD * first_reg));
4514 if (current_function_check_memory_usage
4515 && first_reg < NPARM_REGS (word_mode))
4516 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4518 GEN_INT (UNITS_PER_WORD
4519 * (NPARM_REGS (word_mode) - first_reg)),
4520 TYPE_MODE (sizetype), GEN_INT (MEMORY_USE_RW),
4521 TYPE_MODE (integer_type_node));
4526 /* Implement `va_start' for varargs and stdarg. */
4529 sparc_va_start (stdarg_p, valist, nextarg)
4530 int stdarg_p ATTRIBUTE_UNUSED;
4534 nextarg = expand_builtin_saveregs ();
4535 std_expand_builtin_va_start (1, valist, nextarg);
4538 /* Implement `va_arg'. */
4541 sparc_va_arg (valist, type)
4544 HOST_WIDE_INT size, rsize, align;
4549 /* Round up sizeof(type) to a word. */
4550 size = int_size_in_bytes (type);
4551 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
4556 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
4557 align = 2 * UNITS_PER_WORD;
4559 if (AGGREGATE_TYPE_P (type))
4564 size = rsize = UNITS_PER_WORD;
4572 if (AGGREGATE_TYPE_P (type)
4573 || TYPE_MODE (type) == TFmode
4574 || TYPE_MODE (type) == TCmode)
4577 size = rsize = UNITS_PER_WORD;
4581 /* ??? The old va-sparc.h implementation, for 8 byte objects
4582 copied stuff to a temporary -- I don't see that that
4583 provides any more alignment than the stack slot did. */
4590 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
4591 build_int_2 (align - 1, 0)));
4592 incr = fold (build (BIT_AND_EXPR, ptr_type_node, incr,
4593 build_int_2 (-align, -1)));
4596 addr = incr = save_expr (incr);
4597 if (BYTES_BIG_ENDIAN && size < rsize)
4599 addr = fold (build (PLUS_EXPR, ptr_type_node, incr,
4600 build_int_2 (rsize - size, 0)));
4602 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
4603 build_int_2 (rsize, 0)));
4605 incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
4606 TREE_SIDE_EFFECTS (incr) = 1;
4607 expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
4609 addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
4613 addr_rtx = force_reg (Pmode, addr_rtx);
4614 addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
4615 MEM_ALIAS_SET (addr_rtx) = get_varargs_alias_set ();
4621 /* Return the string to output a conditional branch to LABEL, which is
4622 the operand number of the label. OP is the conditional expression.
4623 XEXP (OP, 0) is assumed to be a condition code register (integer or
4624 floating point) and its mode specifies what kind of comparison we made.
4626 REVERSED is non-zero if we should reverse the sense of the comparison.
4628 ANNUL is non-zero if we should generate an annulling branch.
4630 NOOP is non-zero if we have to follow this branch by a noop.
4632 INSN, if set, is the insn. */
4635 output_cbranch (op, label, reversed, annul, noop, insn)
4638 int reversed, annul, noop;
4641 static char string[32];
4642 enum rtx_code code = GET_CODE (op);
4643 rtx cc_reg = XEXP (op, 0);
4644 enum machine_mode mode = GET_MODE (cc_reg);
4645 static char v8_labelno[] = "%lX";
4646 static char v9_icc_labelno[] = "%%icc, %lX";
4647 static char v9_xcc_labelno[] = "%%xcc, %lX";
4648 static char v9_fcc_labelno[] = "%%fccX, %lY";
4651 int labeloff, spaces = 8;
4655 /* Reversal of FP compares takes care -- an ordered compare
4656 becomes an unordered compare and vice versa. */
4657 if (mode == CCFPmode || mode == CCFPEmode)
4658 code = reverse_condition_maybe_unordered (code);
4660 code = reverse_condition (code);
4663 /* Start by writing the branch condition. */
4664 if (mode == CCFPmode || mode == CCFPEmode)
4715 /* ??? !v9: FP branches cannot be preceded by another floating point
4716 insn. Because there is currently no concept of pre-delay slots,
4717 we can fix this only by always emitting a nop before a floating
4722 strcpy (string, "nop\n\t");
4723 strcat (string, branch);
4736 if (mode == CC_NOOVmode)
4748 if (mode == CC_NOOVmode)
4769 strcpy (string, branch);
4771 spaces -= strlen (branch);
4773 /* Now add the annulling, the label, and a possible noop. */
4776 strcat (string, ",a");
4783 labelno = v8_labelno;
4789 if (insn && (note = find_reg_note (insn, REG_BR_PRED, NULL_RTX)))
4792 INTVAL (XEXP (note, 0)) & ATTR_FLAG_likely ? ",pt" : ",pn");
4797 if (mode == CCFPmode || mode == CCFPEmode)
4800 labelno = v9_fcc_labelno;
4801 /* Set the char indicating the number of the fcc reg to use. */
4802 labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
4804 else if (mode == CCXmode || mode == CCX_NOOVmode)
4805 labelno = v9_xcc_labelno;
4807 labelno = v9_icc_labelno;
4809 /* Set the char indicating the number of the operand containing the
4811 labelno[labeloff] = label + '0';
4813 strcat (string, "\t");
4815 strcat (string, " ");
4816 strcat (string, labelno);
4819 strcat (string, "\n\tnop");
4824 /* Emit a library call comparison between floating point X and Y.
4825 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
4826 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
4827 values as arguments instead of the TFmode registers themselves,
4828 that's why we cannot call emit_float_lib_cmp. */
4830 sparc_emit_float_lib_cmp (x, y, comparison)
4832 enum rtx_code comparison;
4835 rtx slot0, slot1, result, tem, tem2;
4836 enum machine_mode mode;
4841 qpfunc = (TARGET_ARCH64) ? "_Qp_feq" : "_Q_feq";
4845 qpfunc = (TARGET_ARCH64) ? "_Qp_fne" : "_Q_fne";
4849 qpfunc = (TARGET_ARCH64) ? "_Qp_fgt" : "_Q_fgt";
4853 qpfunc = (TARGET_ARCH64) ? "_Qp_fge" : "_Q_fge";
4857 qpfunc = (TARGET_ARCH64) ? "_Qp_flt" : "_Q_flt";
4861 qpfunc = (TARGET_ARCH64) ? "_Qp_fle" : "_Q_fle";
4872 qpfunc = (TARGET_ARCH64) ? "_Qp_cmp" : "_Q_cmp";
4882 if (GET_CODE (x) != MEM)
4884 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
4885 emit_insn (gen_rtx_SET (VOIDmode, slot0, x));
4890 if (GET_CODE (y) != MEM)
4892 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
4893 emit_insn (gen_rtx_SET (VOIDmode, slot1, y));
4898 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), 1,
4900 XEXP (slot0, 0), Pmode,
4901 XEXP (slot1, 0), Pmode);
4907 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), 1,
4909 x, TFmode, y, TFmode);
4915 /* Immediately move the result of the libcall into a pseudo
4916 register so reload doesn't clobber the value if it needs
4917 the return register for a spill reg. */
4918 result = gen_reg_rtx (mode);
4919 emit_move_insn (result, hard_libcall_value (mode));
4924 emit_cmp_insn (result, const0_rtx, NE,
4925 NULL_RTX, mode, 0, 0);
4929 emit_cmp_insn (result, GEN_INT(3),
4930 (comparison == UNORDERED) ? EQ : NE,
4931 NULL_RTX, mode, 0, 0);
4935 emit_cmp_insn (result, const1_rtx,
4936 (comparison == UNGT) ? GT : NE,
4937 NULL_RTX, mode, 0, 0);
4940 emit_cmp_insn (result, const2_rtx, NE,
4941 NULL_RTX, mode, 0, 0);
4944 tem = gen_reg_rtx (mode);
4946 emit_insn (gen_andsi3 (tem, result, const1_rtx));
4948 emit_insn (gen_anddi3 (tem, result, const1_rtx));
4949 emit_cmp_insn (tem, const0_rtx, NE,
4950 NULL_RTX, mode, 0, 0);
4954 tem = gen_reg_rtx (mode);
4956 emit_insn (gen_addsi3 (tem, result, const1_rtx));
4958 emit_insn (gen_adddi3 (tem, result, const1_rtx));
4959 tem2 = gen_reg_rtx (mode);
4961 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
4963 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
4964 emit_cmp_insn (tem2, const0_rtx,
4965 (comparison == UNEQ) ? EQ : NE,
4966 NULL_RTX, mode, 0, 0);
4971 /* Return the string to output a conditional branch to LABEL, testing
4972 register REG. LABEL is the operand number of the label; REG is the
4973 operand number of the reg. OP is the conditional expression. The mode
4974 of REG says what kind of comparison we made.
4976 REVERSED is non-zero if we should reverse the sense of the comparison.
4978 ANNUL is non-zero if we should generate an annulling branch.
4980 NOOP is non-zero if we have to follow this branch by a noop. */
4983 output_v9branch (op, reg, label, reversed, annul, noop, insn)
4986 int reversed, annul, noop;
4989 static char string[20];
4990 enum rtx_code code = GET_CODE (op);
4991 enum machine_mode mode = GET_MODE (XEXP (op, 0));
4992 static char labelno[] = "%X, %lX";
4996 /* If not floating-point or if EQ or NE, we can just reverse the code. */
4998 code = reverse_condition (code), reversed = 0;
5000 /* Only 64 bit versions of these instructions exist. */
5004 /* Start by writing the branch condition. */
5009 strcpy (string, "brnz");
5014 strcpy (string, "brz");
5019 strcpy (string, "brgez");
5024 strcpy (string, "brlz");
5029 strcpy (string, "brlez");
5034 strcpy (string, "brgz");
5042 /* Now add the annulling, reg, label, and nop. */
5045 strcat (string, ",a");
5049 if (insn && (note = find_reg_note (insn, REG_BR_PRED, NULL_RTX)))
5052 INTVAL (XEXP (note, 0)) & ATTR_FLAG_likely ? ",pt" : ",pn");
5056 labelno[1] = reg + '0';
5057 labelno[6] = label + '0';
5059 strcat (string, "\t");
5061 strcat (string, " ");
5062 strcat (string, labelno);
5065 strcat (string, "\n\tnop");
5070 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
5071 Such instructions cannot be used in the delay slot of return insn on v9.
5072 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
5076 epilogue_renumber (where, test)
5077 register rtx *where;
5080 register const char *fmt;
5082 register enum rtx_code code;
5087 code = GET_CODE (*where);
5092 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
5094 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
5095 *where = gen_rtx (REG, GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
5107 fmt = GET_RTX_FORMAT (code);
5109 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5114 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
5115 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
5118 else if (fmt[i] == 'e'
5119 && epilogue_renumber (&(XEXP (*where, i)), test))
5125 /* Output assembler code to return from a function. */
5128 output_return (operands)
5131 rtx delay = final_sequence ? XVECEXP (final_sequence, 0, 1) : 0;
5135 operands[0] = leaf_label;
5138 else if (current_function_uses_only_leaf_regs)
5140 /* No delay slot in a leaf function. */
5144 /* If we didn't allocate a frame pointer for the current function,
5145 the stack pointer might have been adjusted. Output code to
5148 operands[0] = GEN_INT (actual_fsize);
5150 /* Use sub of negated value in first two cases instead of add to
5151 allow actual_fsize == 4096. */
5153 if (actual_fsize <= 4096)
5155 if (SKIP_CALLERS_UNIMP_P)
5156 return "jmp\t%%o7+12\n\tsub\t%%sp, -%0, %%sp";
5158 return "retl\n\tsub\t%%sp, -%0, %%sp";
5160 else if (actual_fsize <= 8192)
5162 operands[0] = GEN_INT (actual_fsize - 4096);
5163 if (SKIP_CALLERS_UNIMP_P)
5164 return "sub\t%%sp, -4096, %%sp\n\tjmp\t%%o7+12\n\tsub\t%%sp, -%0, %%sp";
5166 return "sub\t%%sp, -4096, %%sp\n\tretl\n\tsub\t%%sp, -%0, %%sp";
5168 else if (SKIP_CALLERS_UNIMP_P)
5170 if ((actual_fsize & 0x3ff) != 0)
5171 return "sethi\t%%hi(%a0), %%g1\n\tor\t%%g1, %%lo(%a0), %%g1\n\tjmp\t%%o7+12\n\tadd\t%%sp, %%g1, %%sp";
5173 return "sethi\t%%hi(%a0), %%g1\n\tjmp\t%%o7+12\n\tadd\t%%sp, %%g1, %%sp";
5177 if ((actual_fsize & 0x3ff) != 0)
5178 return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp";
5180 return "sethi %%hi(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp";
5187 epilogue_renumber (&SET_DEST (PATTERN (delay)), 0);
5188 epilogue_renumber (&SET_SRC (PATTERN (delay)), 0);
5190 if (SKIP_CALLERS_UNIMP_P)
5191 return "return\t%%i7+12%#";
5193 return "return\t%%i7+8%#";
5199 if (SKIP_CALLERS_UNIMP_P)
5200 return "jmp\t%%i7+12\n\trestore";
5202 return "ret\n\trestore";
5206 /* Leaf functions and non-leaf functions have different needs. */
5209 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
5212 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
5214 static int *reg_alloc_orders[] = {
5215 reg_leaf_alloc_order,
5216 reg_nonleaf_alloc_order};
5219 order_regs_for_local_alloc ()
5221 static int last_order_nonleaf = 1;
5223 if (regs_ever_live[15] != last_order_nonleaf)
5225 last_order_nonleaf = !last_order_nonleaf;
5226 bcopy ((char *) reg_alloc_orders[last_order_nonleaf],
5227 (char *) reg_alloc_order, FIRST_PSEUDO_REGISTER * sizeof (int));
5231 /* Return 1 if REG and MEM are legitimate enough to allow the various
5232 mem<-->reg splits to be run. */
5235 sparc_splitdi_legitimate (reg, mem)
5239 /* Punt if we are here by mistake. */
5240 if (! reload_completed)
5243 /* We must have an offsettable memory reference. */
5244 if (! offsettable_memref_p (mem))
5247 /* If we have legitimate args for ldd/std, we do not want
5248 the split to happen. */
5249 if ((REGNO (reg) % 2) == 0
5250 && mem_min_alignment (mem, 8))
5257 /* Return 1 if x and y are some kind of REG and they refer to
5258 different hard registers. This test is guarenteed to be
5259 run after reload. */
5262 sparc_absnegfloat_split_legitimate (x, y)
5265 if (GET_CODE (x) == SUBREG)
5266 x = alter_subreg (x);
5267 if (GET_CODE (x) != REG)
5269 if (GET_CODE (y) == SUBREG)
5270 y = alter_subreg (y);
5271 if (GET_CODE (y) != REG)
5273 if (REGNO (x) == REGNO (y))
5278 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
5279 This makes them candidates for using ldd and std insns.
5281 Note reg1 and reg2 *must* be hard registers. */
5284 registers_ok_for_ldd_peep (reg1, reg2)
5287 /* We might have been passed a SUBREG. */
5288 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
5291 if (REGNO (reg1) % 2 != 0)
5294 /* Integer ldd is deprecated in SPARC V9 */
5295 if (TARGET_V9 && REGNO (reg1) < 32)
5298 return (REGNO (reg1) == REGNO (reg2) - 1);
5301 /* Return 1 if addr1 and addr2 are suitable for use in an ldd or
5304 This can only happen when addr1 and addr2 are consecutive memory
5305 locations (addr1 + 4 == addr2). addr1 must also be aligned on a
5306 64 bit boundary (addr1 % 8 == 0).
5308 We know %sp and %fp are kept aligned on a 64 bit boundary. Other
5309 registers are assumed to *never* be properly aligned and are
5312 Knowing %sp and %fp are kept aligned on a 64 bit boundary, we
5313 need only check that the offset for addr1 % 8 == 0. */
5316 addrs_ok_for_ldd_peep (addr1, addr2)
5321 /* Extract a register number and offset (if used) from the first addr. */
5322 if (GET_CODE (addr1) == PLUS)
5324 /* If not a REG, return zero. */
5325 if (GET_CODE (XEXP (addr1, 0)) != REG)
5329 reg1 = REGNO (XEXP (addr1, 0));
5330 /* The offset must be constant! */
5331 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
5333 offset1 = INTVAL (XEXP (addr1, 1));
5336 else if (GET_CODE (addr1) != REG)
5340 reg1 = REGNO (addr1);
5341 /* This was a simple (mem (reg)) expression. Offset is 0. */
5345 /* Make sure the second address is a (mem (plus (reg) (const_int). */
5346 if (GET_CODE (addr2) != PLUS)
5349 if (GET_CODE (XEXP (addr2, 0)) != REG
5350 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
5353 /* Only %fp and %sp are allowed. Additionally both addresses must
5354 use the same register. */
5355 if (reg1 != FRAME_POINTER_REGNUM && reg1 != STACK_POINTER_REGNUM)
5358 if (reg1 != REGNO (XEXP (addr2, 0)))
5361 /* The first offset must be evenly divisible by 8 to ensure the
5362 address is 64 bit aligned. */
5363 if (offset1 % 8 != 0)
5366 /* The offset for the second addr must be 4 more than the first addr. */
5367 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
5370 /* All the tests passed. addr1 and addr2 are valid for ldd and std
5375 /* Return 1 if reg is a pseudo, or is the first register in
5376 a hard register pair. This makes it a candidate for use in
5377 ldd and std insns. */
5380 register_ok_for_ldd (reg)
5383 /* We might have been passed a SUBREG. */
5384 if (GET_CODE (reg) != REG)
5387 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
5388 return (REGNO (reg) % 2 == 0);
5393 /* Print operand X (an rtx) in assembler syntax to file FILE.
5394 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
5395 For `%' followed by punctuation, CODE is the punctuation and X is null. */
5398 print_operand (file, x, code)
5406 /* Output a 'nop' if there's nothing for the delay slot. */
5407 if (dbr_sequence_length () == 0)
5408 fputs ("\n\t nop", file);
5411 /* Output an annul flag if there's nothing for the delay slot and we
5412 are optimizing. This is always used with '(' below. */
5413 /* Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
5414 this is a dbx bug. So, we only do this when optimizing. */
5415 /* On UltraSPARC, a branch in a delay slot causes a pipeline flush.
5416 Always emit a nop in case the next instruction is a branch. */
5417 if (dbr_sequence_length () == 0
5418 && (optimize && (int)sparc_cpu < PROCESSOR_V9))
5422 /* Output a 'nop' if there's nothing for the delay slot and we are
5423 not optimizing. This is always used with '*' above. */
5424 if (dbr_sequence_length () == 0
5425 && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
5426 fputs ("\n\t nop", file);
5429 /* Output the Embedded Medium/Anywhere code model base register. */
5430 fputs (EMBMEDANY_BASE_REG, file);
5433 /* Print out what we are using as the frame pointer. This might
5434 be %fp, or might be %sp+offset. */
5435 /* ??? What if offset is too big? Perhaps the caller knows it isn't? */
5436 fprintf (file, "%s+%d", frame_base_name, frame_base_offset);
5439 /* Adjust the operand to take into account a RESTORE operation. */
5440 if (GET_CODE (x) == CONST_INT)
5442 else if (GET_CODE (x) != REG)
5443 output_operand_lossage ("Invalid %%Y operand");
5444 else if (REGNO (x) < 8)
5445 fputs (reg_names[REGNO (x)], file);
5446 else if (REGNO (x) >= 24 && REGNO (x) < 32)
5447 fputs (reg_names[REGNO (x)-16], file);
5449 output_operand_lossage ("Invalid %%Y operand");
5452 /* Print out the low order register name of a register pair. */
5453 if (WORDS_BIG_ENDIAN)
5454 fputs (reg_names[REGNO (x)+1], file);
5456 fputs (reg_names[REGNO (x)], file);
5459 /* Print out the high order register name of a register pair. */
5460 if (WORDS_BIG_ENDIAN)
5461 fputs (reg_names[REGNO (x)], file);
5463 fputs (reg_names[REGNO (x)+1], file);
5466 /* Print out the second register name of a register pair or quad.
5467 I.e., R (%o0) => %o1. */
5468 fputs (reg_names[REGNO (x)+1], file);
5471 /* Print out the third register name of a register quad.
5472 I.e., S (%o0) => %o2. */
5473 fputs (reg_names[REGNO (x)+2], file);
5476 /* Print out the fourth register name of a register quad.
5477 I.e., T (%o0) => %o3. */
5478 fputs (reg_names[REGNO (x)+3], file);
5481 /* Print a condition code register. */
5482 if (REGNO (x) == SPARC_ICC_REG)
5484 /* We don't handle CC[X]_NOOVmode because they're not supposed
5486 if (GET_MODE (x) == CCmode)
5487 fputs ("%icc", file);
5488 else if (GET_MODE (x) == CCXmode)
5489 fputs ("%xcc", file);
5494 /* %fccN register */
5495 fputs (reg_names[REGNO (x)], file);
5498 /* Print the operand's address only. */
5499 output_address (XEXP (x, 0));
5502 /* In this case we need a register. Use %g0 if the
5503 operand is const0_rtx. */
5505 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
5507 fputs ("%g0", file);
5514 switch (GET_CODE (x))
5516 case IOR: fputs ("or", file); break;
5517 case AND: fputs ("and", file); break;
5518 case XOR: fputs ("xor", file); break;
5519 default: output_operand_lossage ("Invalid %%A operand");
5524 switch (GET_CODE (x))
5526 case IOR: fputs ("orn", file); break;
5527 case AND: fputs ("andn", file); break;
5528 case XOR: fputs ("xnor", file); break;
5529 default: output_operand_lossage ("Invalid %%B operand");
5533 /* These are used by the conditional move instructions. */
5537 enum rtx_code rc = GET_CODE (x);
5541 enum machine_mode mode = GET_MODE (XEXP (x, 0));
5542 if (mode == CCFPmode || mode == CCFPEmode)
5543 rc = reverse_condition_maybe_unordered (GET_CODE (x));
5545 rc = reverse_condition (GET_CODE (x));
5549 case NE: fputs ("ne", file); break;
5550 case EQ: fputs ("e", file); break;
5551 case GE: fputs ("ge", file); break;
5552 case GT: fputs ("g", file); break;
5553 case LE: fputs ("le", file); break;
5554 case LT: fputs ("l", file); break;
5555 case GEU: fputs ("geu", file); break;
5556 case GTU: fputs ("gu", file); break;
5557 case LEU: fputs ("leu", file); break;
5558 case LTU: fputs ("lu", file); break;
5559 case LTGT: fputs ("lg", file); break;
5560 case UNORDERED: fputs ("u", file); break;
5561 case ORDERED: fputs ("o", file); break;
5562 case UNLT: fputs ("ul", file); break;
5563 case UNLE: fputs ("ule", file); break;
5564 case UNGT: fputs ("ug", file); break;
5565 case UNGE: fputs ("uge", file); break;
5566 case UNEQ: fputs ("ue", file); break;
5567 default: output_operand_lossage (code == 'c'
5568 ? "Invalid %%c operand"
5569 : "Invalid %%C operand");
5574 /* These are used by the movr instruction pattern. */
5578 enum rtx_code rc = (code == 'd'
5579 ? reverse_condition (GET_CODE (x))
5583 case NE: fputs ("ne", file); break;
5584 case EQ: fputs ("e", file); break;
5585 case GE: fputs ("gez", file); break;
5586 case LT: fputs ("lz", file); break;
5587 case LE: fputs ("lez", file); break;
5588 case GT: fputs ("gz", file); break;
5589 default: output_operand_lossage (code == 'd'
5590 ? "Invalid %%d operand"
5591 : "Invalid %%D operand");
5598 /* Print a sign-extended character. */
5599 int i = INTVAL (x) & 0xff;
5602 fprintf (file, "%d", i);
5607 /* Operand must be a MEM; write its address. */
5608 if (GET_CODE (x) != MEM)
5609 output_operand_lossage ("Invalid %%f operand");
5610 output_address (XEXP (x, 0));
5614 /* Do nothing special. */
5618 /* Undocumented flag. */
5619 output_operand_lossage ("invalid operand output code");
5622 if (GET_CODE (x) == REG)
5623 fputs (reg_names[REGNO (x)], file);
5624 else if (GET_CODE (x) == MEM)
5627 /* Poor Sun assembler doesn't understand absolute addressing. */
5628 if (CONSTANT_P (XEXP (x, 0))
5629 && ! TARGET_LIVE_G0)
5630 fputs ("%g0+", file);
5631 output_address (XEXP (x, 0));
5634 else if (GET_CODE (x) == HIGH)
5636 fputs ("%hi(", file);
5637 output_addr_const (file, XEXP (x, 0));
5640 else if (GET_CODE (x) == LO_SUM)
5642 print_operand (file, XEXP (x, 0), 0);
5643 if (TARGET_CM_MEDMID)
5644 fputs ("+%l44(", file);
5646 fputs ("+%lo(", file);
5647 output_addr_const (file, XEXP (x, 1));
5650 else if (GET_CODE (x) == CONST_DOUBLE
5651 && (GET_MODE (x) == VOIDmode
5652 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
5654 if (CONST_DOUBLE_HIGH (x) == 0)
5655 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
5656 else if (CONST_DOUBLE_HIGH (x) == -1
5657 && CONST_DOUBLE_LOW (x) < 0)
5658 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
5660 output_operand_lossage ("long long constant not a valid immediate operand");
5662 else if (GET_CODE (x) == CONST_DOUBLE)
5663 output_operand_lossage ("floating point constant not a valid immediate operand");
5664 else { output_addr_const (file, x); }
5667 /* This function outputs assembler code for VALUE to FILE, where VALUE is
5668 a 64 bit (DImode) value. */
5670 /* ??? If there is a 64 bit counterpart to .word that the assembler
5671 understands, then using that would simply this code greatly. */
5672 /* ??? We only output .xword's for symbols and only then in environments
5673 where the assembler can handle them. */
5676 output_double_int (file, value)
5680 if (GET_CODE (value) == CONST_INT)
5682 /* ??? This has endianness issues. */
5683 #if HOST_BITS_PER_WIDE_INT == 64
5684 HOST_WIDE_INT xword = INTVAL (value);
5685 HOST_WIDE_INT high, low;
5687 high = (xword >> 32) & 0xffffffff;
5688 low = xword & 0xffffffff;
5689 ASM_OUTPUT_INT (file, GEN_INT (high));
5690 ASM_OUTPUT_INT (file, GEN_INT (low));
5692 if (INTVAL (value) < 0)
5693 ASM_OUTPUT_INT (file, constm1_rtx);
5695 ASM_OUTPUT_INT (file, const0_rtx);
5696 ASM_OUTPUT_INT (file, value);
5699 else if (GET_CODE (value) == CONST_DOUBLE)
5701 ASM_OUTPUT_INT (file, GEN_INT (CONST_DOUBLE_HIGH (value)));
5702 ASM_OUTPUT_INT (file, GEN_INT (CONST_DOUBLE_LOW (value)));
5704 else if (GET_CODE (value) == SYMBOL_REF
5705 || GET_CODE (value) == CONST
5706 || GET_CODE (value) == PLUS
5707 || (TARGET_ARCH64 &&
5708 (GET_CODE (value) == LABEL_REF
5709 || GET_CODE (value) == CODE_LABEL
5710 || GET_CODE (value) == MINUS)))
5714 ASM_OUTPUT_INT (file, const0_rtx);
5715 ASM_OUTPUT_INT (file, value);
5719 fprintf (file, "\t%s\t", ASM_LONGLONG);
5720 output_addr_const (file, value);
5721 fprintf (file, "\n");
5728 /* Return the value of a code used in the .proc pseudo-op that says
5729 what kind of result this function returns. For non-C types, we pick
5730 the closest C type. */
5732 #ifndef CHAR_TYPE_SIZE
5733 #define CHAR_TYPE_SIZE BITS_PER_UNIT
5736 #ifndef SHORT_TYPE_SIZE
5737 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
5740 #ifndef INT_TYPE_SIZE
5741 #define INT_TYPE_SIZE BITS_PER_WORD
5744 #ifndef LONG_TYPE_SIZE
5745 #define LONG_TYPE_SIZE BITS_PER_WORD
5748 #ifndef LONG_LONG_TYPE_SIZE
5749 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
5752 #ifndef FLOAT_TYPE_SIZE
5753 #define FLOAT_TYPE_SIZE BITS_PER_WORD
5756 #ifndef DOUBLE_TYPE_SIZE
5757 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
5760 #ifndef LONG_DOUBLE_TYPE_SIZE
5761 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
5765 sparc_type_code (type)
5768 register unsigned long qualifiers = 0;
5769 register unsigned shift;
5771 /* Only the first 30 bits of the qualifier are valid. We must refrain from
5772 setting more, since some assemblers will give an error for this. Also,
5773 we must be careful to avoid shifts of 32 bits or more to avoid getting
5774 unpredictable results. */
5776 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
5778 switch (TREE_CODE (type))
5784 qualifiers |= (3 << shift);
5789 qualifiers |= (2 << shift);
5793 case REFERENCE_TYPE:
5795 qualifiers |= (1 << shift);
5799 return (qualifiers | 8);
5802 case QUAL_UNION_TYPE:
5803 return (qualifiers | 9);
5806 return (qualifiers | 10);
5809 return (qualifiers | 16);
5812 /* If this is a range type, consider it to be the underlying
5814 if (TREE_TYPE (type) != 0)
5817 /* Carefully distinguish all the standard types of C,
5818 without messing up if the language is not C. We do this by
5819 testing TYPE_PRECISION and TREE_UNSIGNED. The old code used to
5820 look at both the names and the above fields, but that's redundant.
5821 Any type whose size is between two C types will be considered
5822 to be the wider of the two types. Also, we do not have a
5823 special code to use for "long long", so anything wider than
5824 long is treated the same. Note that we can't distinguish
5825 between "int" and "long" in this code if they are the same
5826 size, but that's fine, since neither can the assembler. */
5828 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
5829 return (qualifiers | (TREE_UNSIGNED (type) ? 12 : 2));
5831 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
5832 return (qualifiers | (TREE_UNSIGNED (type) ? 13 : 3));
5834 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
5835 return (qualifiers | (TREE_UNSIGNED (type) ? 14 : 4));
5838 return (qualifiers | (TREE_UNSIGNED (type) ? 15 : 5));
5841 /* If this is a range type, consider it to be the underlying
5843 if (TREE_TYPE (type) != 0)
5846 /* Carefully distinguish all the standard types of C,
5847 without messing up if the language is not C. */
5849 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
5850 return (qualifiers | 6);
5853 return (qualifiers | 7);
5855 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
5856 /* ??? We need to distinguish between double and float complex types,
5857 but I don't know how yet because I can't reach this code from
5858 existing front-ends. */
5859 return (qualifiers | 7); /* Who knows? */
5861 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
5862 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
5863 case FILE_TYPE: /* GNU Pascal FILE type. */
5864 case SET_TYPE: /* GNU Pascal SET type. */
5865 case LANG_TYPE: /* ? */
5869 abort (); /* Not a type! */
5876 /* Nested function support. */
5878 /* Emit RTL insns to initialize the variable parts of a trampoline.
5879 FNADDR is an RTX for the address of the function's pure code.
5880 CXT is an RTX for the static chain value for the function.
5882 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
5883 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
5884 (to store insns). This is a bit excessive. Perhaps a different
5885 mechanism would be better here.
5887 Emit enough FLUSH insns to synchronize the data and instruction caches. */
5890 sparc_initialize_trampoline (tramp, fnaddr, cxt)
5891 rtx tramp, fnaddr, cxt;
5893 /* SPARC 32 bit trampoline:
5896 sethi %hi(static), %g2
5898 or %g2, %lo(static), %g2
5900 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
5901 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
5903 #ifdef TRANSFER_FROM_TRAMPOLINE
5904 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
5905 0, VOIDmode, 1, tramp, Pmode);
5908 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
5909 expand_binop (SImode, ior_optab,
5910 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
5911 size_int (10), 0, 1),
5912 GEN_INT (0x03000000),
5913 NULL_RTX, 1, OPTAB_DIRECT));
5915 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
5916 expand_binop (SImode, ior_optab,
5917 expand_shift (RSHIFT_EXPR, SImode, cxt,
5918 size_int (10), 0, 1),
5919 GEN_INT (0x05000000),
5920 NULL_RTX, 1, OPTAB_DIRECT));
5922 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
5923 expand_binop (SImode, ior_optab,
5924 expand_and (fnaddr, GEN_INT (0x3ff), NULL_RTX),
5925 GEN_INT (0x81c06000),
5926 NULL_RTX, 1, OPTAB_DIRECT));
5928 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
5929 expand_binop (SImode, ior_optab,
5930 expand_and (cxt, GEN_INT (0x3ff), NULL_RTX),
5931 GEN_INT (0x8410a000),
5932 NULL_RTX, 1, OPTAB_DIRECT));
5934 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
5935 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
5936 aligned on a 16 byte boundary so one flush clears it all. */
5937 if (sparc_cpu != PROCESSOR_ULTRASPARC)
5938 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
5939 plus_constant (tramp, 8)))));
5942 /* The 64 bit version is simpler because it makes more sense to load the
5943 values as "immediate" data out of the trampoline. It's also easier since
5944 we can read the PC without clobbering a register. */
5947 sparc64_initialize_trampoline (tramp, fnaddr, cxt)
5948 rtx tramp, fnaddr, cxt;
5950 #ifdef TRANSFER_FROM_TRAMPOLINE
5951 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
5952 0, VOIDmode, 1, tramp, Pmode);
5963 emit_move_insn (gen_rtx_MEM (SImode, tramp),
5964 GEN_INT (0x83414000));
5965 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
5966 GEN_INT (0xca586018));
5967 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
5968 GEN_INT (0x81c14000));
5969 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
5970 GEN_INT (0xca586010));
5971 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
5972 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
5973 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
5975 if (sparc_cpu != PROCESSOR_ULTRASPARC)
5976 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
5979 /* Subroutines to support a flat (single) register window calling
5982 /* Single-register window sparc stack frames look like:
5984 Before call After call
5985 +-----------------------+ +-----------------------+
5987 mem | caller's temps. | | caller's temps. |
5989 +-----------------------+ +-----------------------+
5991 | arguments on stack. | | arguments on stack. |
5993 +-----------------------+FP+92->+-----------------------+
5994 | 6 words to save | | 6 words to save |
5995 | arguments passed | | arguments passed |
5996 | in registers, even | | in registers, even |
5997 | if not passed. | | if not passed. |
5998 SP+68->+-----------------------+FP+68->+-----------------------+
5999 | 1 word struct addr | | 1 word struct addr |
6000 +-----------------------+FP+64->+-----------------------+
6002 | 16 word reg save area | | 16 word reg save area |
6004 SP->+-----------------------+ FP->+-----------------------+
6006 | fp/alu reg moves |
6007 FP-16->+-----------------------+
6011 +-----------------------+
6013 | fp register save |
6015 +-----------------------+
6017 | gp register save |
6019 +-----------------------+
6021 | alloca allocations |
6023 +-----------------------+
6025 | arguments on stack |
6027 SP+92->+-----------------------+
6029 | arguments passed |
6030 | in registers, even |
6031 low | if not passed. |
6032 memory SP+68->+-----------------------+
6033 | 1 word struct addr |
6034 SP+64->+-----------------------+
6036 I 16 word reg save area |
6038 SP->+-----------------------+ */
6040 /* Structure to be filled in by sparc_flat_compute_frame_size with register
6041 save masks, and offsets for the current function. */
6043 struct sparc_frame_info
6045 unsigned long total_size; /* # bytes that the entire frame takes up. */
6046 unsigned long var_size; /* # bytes that variables take up. */
6047 unsigned long args_size; /* # bytes that outgoing arguments take up. */
6048 unsigned long extra_size; /* # bytes of extra gunk. */
6049 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
6050 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
6051 unsigned long gmask; /* Mask of saved gp registers. */
6052 unsigned long fmask; /* Mask of saved fp registers. */
6053 unsigned long reg_offset; /* Offset from new sp to store regs. */
6054 int initialized; /* Nonzero if frame size already calculated. */
6057 /* Current frame information calculated by sparc_flat_compute_frame_size. */
6058 struct sparc_frame_info current_frame_info;
6060 /* Zero structure to initialize current_frame_info. */
6061 struct sparc_frame_info zero_frame_info;
6063 /* Tell prologue and epilogue if register REGNO should be saved / restored. */
6065 #define RETURN_ADDR_REGNUM 15
6066 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
6067 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
6069 #define MUST_SAVE_REGISTER(regno) \
6070 ((regs_ever_live[regno] && !call_used_regs[regno]) \
6071 || (regno == FRAME_POINTER_REGNUM && frame_pointer_needed) \
6072 || (regno == RETURN_ADDR_REGNUM && regs_ever_live[RETURN_ADDR_REGNUM]))
6074 /* Return the bytes needed to compute the frame pointer from the current
6078 sparc_flat_compute_frame_size (size)
6079 int size; /* # of var. bytes allocated. */
6082 unsigned long total_size; /* # bytes that the entire frame takes up. */
6083 unsigned long var_size; /* # bytes that variables take up. */
6084 unsigned long args_size; /* # bytes that outgoing arguments take up. */
6085 unsigned long extra_size; /* # extra bytes. */
6086 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
6087 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
6088 unsigned long gmask; /* Mask of saved gp registers. */
6089 unsigned long fmask; /* Mask of saved fp registers. */
6090 unsigned long reg_offset; /* Offset to register save area. */
6091 int need_aligned_p; /* 1 if need the save area 8 byte aligned. */
6093 /* This is the size of the 16 word reg save area, 1 word struct addr
6094 area, and 4 word fp/alu register copy area. */
6095 extra_size = -STARTING_FRAME_OFFSET + FIRST_PARM_OFFSET(0);
6105 if (!leaf_function_p ())
6107 /* Also include the size needed for the 6 parameter registers. */
6108 args_size = current_function_outgoing_args_size + 24;
6110 total_size = var_size + args_size;
6112 /* Calculate space needed for gp registers. */
6113 for (regno = 1; regno <= 31; regno++)
6115 if (MUST_SAVE_REGISTER (regno))
6117 /* If we need to save two regs in a row, ensure there's room to bump
6118 up the address to align it to a doubleword boundary. */
6119 if ((regno & 0x1) == 0 && MUST_SAVE_REGISTER (regno+1))
6121 if (gp_reg_size % 8 != 0)
6123 gp_reg_size += 2 * UNITS_PER_WORD;
6124 gmask |= 3 << regno;
6130 gp_reg_size += UNITS_PER_WORD;
6131 gmask |= 1 << regno;
6136 /* Calculate space needed for fp registers. */
6137 for (regno = 32; regno <= 63; regno++)
6139 if (regs_ever_live[regno] && !call_used_regs[regno])
6141 fp_reg_size += UNITS_PER_WORD;
6142 fmask |= 1 << (regno - 32);
6149 reg_offset = FIRST_PARM_OFFSET(0) + args_size;
6150 /* Ensure save area is 8 byte aligned if we need it. */
6152 if (need_aligned_p && n != 0)
6154 total_size += 8 - n;
6155 reg_offset += 8 - n;
6157 total_size += gp_reg_size + fp_reg_size;
6160 /* If we must allocate a stack frame at all, we must also allocate
6161 room for register window spillage, so as to be binary compatible
6162 with libraries and operating systems that do not use -mflat. */
6164 total_size += extra_size;
6168 total_size = SPARC_STACK_ALIGN (total_size);
6170 /* Save other computed information. */
6171 current_frame_info.total_size = total_size;
6172 current_frame_info.var_size = var_size;
6173 current_frame_info.args_size = args_size;
6174 current_frame_info.extra_size = extra_size;
6175 current_frame_info.gp_reg_size = gp_reg_size;
6176 current_frame_info.fp_reg_size = fp_reg_size;
6177 current_frame_info.gmask = gmask;
6178 current_frame_info.fmask = fmask;
6179 current_frame_info.reg_offset = reg_offset;
6180 current_frame_info.initialized = reload_completed;
6182 /* Ok, we're done. */
6186 /* Save/restore registers in GMASK and FMASK at register BASE_REG plus offset
6189 BASE_REG must be 8 byte aligned. This allows us to test OFFSET for
6190 appropriate alignment and use DOUBLEWORD_OP when we can. We assume
6191 [BASE_REG+OFFSET] will always be a valid address.
6193 WORD_OP is either "st" for save, "ld" for restore.
6194 DOUBLEWORD_OP is either "std" for save, "ldd" for restore. */
6197 sparc_flat_save_restore (file, base_reg, offset, gmask, fmask, word_op,
6198 doubleword_op, base_offset)
6200 const char *base_reg;
6201 unsigned int offset;
6202 unsigned long gmask;
6203 unsigned long fmask;
6204 const char *word_op;
6205 const char *doubleword_op;
6206 unsigned long base_offset;
6210 if (gmask == 0 && fmask == 0)
6213 /* Save registers starting from high to low. We've already saved the
6214 previous frame pointer and previous return address for the debugger's
6215 sake. The debugger allows us to not need a nop in the epilog if at least
6216 one register is reloaded in addition to return address. */
6220 for (regno = 1; regno <= 31; regno++)
6222 if ((gmask & (1L << regno)) != 0)
6224 if ((regno & 0x1) == 0 && ((gmask & (1L << (regno+1))) != 0))
6226 /* We can save two registers in a row. If we're not at a
6227 double word boundary, move to one.
6228 sparc_flat_compute_frame_size ensures there's room to do
6230 if (offset % 8 != 0)
6231 offset += UNITS_PER_WORD;
6233 if (word_op[0] == 's')
6235 fprintf (file, "\t%s\t%s, [%s+%d]\n",
6236 doubleword_op, reg_names[regno],
6238 if (dwarf2out_do_frame ())
6240 char *l = dwarf2out_cfi_label ();
6241 dwarf2out_reg_save (l, regno, offset + base_offset);
6243 (l, regno+1, offset+base_offset + UNITS_PER_WORD);
6247 fprintf (file, "\t%s\t[%s+%d], %s\n",
6248 doubleword_op, base_reg, offset,
6251 offset += 2 * UNITS_PER_WORD;
6256 if (word_op[0] == 's')
6258 fprintf (file, "\t%s\t%s, [%s+%d]\n",
6259 word_op, reg_names[regno],
6261 if (dwarf2out_do_frame ())
6262 dwarf2out_reg_save ("", regno, offset + base_offset);
6265 fprintf (file, "\t%s\t[%s+%d], %s\n",
6266 word_op, base_reg, offset, reg_names[regno]);
6268 offset += UNITS_PER_WORD;
6276 for (regno = 32; regno <= 63; regno++)
6278 if ((fmask & (1L << (regno - 32))) != 0)
6280 if (word_op[0] == 's')
6282 fprintf (file, "\t%s\t%s, [%s+%d]\n",
6283 word_op, reg_names[regno],
6285 if (dwarf2out_do_frame ())
6286 dwarf2out_reg_save ("", regno, offset + base_offset);
6289 fprintf (file, "\t%s\t[%s+%d], %s\n",
6290 word_op, base_reg, offset, reg_names[regno]);
6292 offset += UNITS_PER_WORD;
6298 /* Set up the stack and frame (if desired) for the function. */
6301 sparc_flat_output_function_prologue (file, size)
6305 const char *sp_str = reg_names[STACK_POINTER_REGNUM];
6306 unsigned long gmask = current_frame_info.gmask;
6308 sparc_output_scratch_registers (file);
6310 /* This is only for the human reader. */
6311 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
6312 fprintf (file, "\t%s# vars= %ld, regs= %d/%d, args= %d, extra= %ld\n",
6314 current_frame_info.var_size,
6315 current_frame_info.gp_reg_size / 4,
6316 current_frame_info.fp_reg_size / 4,
6317 current_function_outgoing_args_size,
6318 current_frame_info.extra_size);
6320 size = SPARC_STACK_ALIGN (size);
6321 size = (! current_frame_info.initialized
6322 ? sparc_flat_compute_frame_size (size)
6323 : current_frame_info.total_size);
6325 /* These cases shouldn't happen. Catch them now. */
6326 if (size == 0 && (gmask || current_frame_info.fmask))
6329 /* Allocate our stack frame by decrementing %sp.
6330 At present, the only algorithm gdb can use to determine if this is a
6331 flat frame is if we always set %i7 if we set %sp. This can be optimized
6332 in the future by putting in some sort of debugging information that says
6333 this is a `flat' function. However, there is still the case of debugging
6334 code without such debugging information (including cases where most fns
6335 have such info, but there is one that doesn't). So, always do this now
6336 so we don't get a lot of code out there that gdb can't handle.
6337 If the frame pointer isn't needn't then that's ok - gdb won't be able to
6338 distinguish us from a non-flat function but there won't (and shouldn't)
6339 be any differences anyway. The return pc is saved (if necessary) right
6340 after %i7 so gdb won't have to look too far to find it. */
6343 unsigned int reg_offset = current_frame_info.reg_offset;
6344 const char *fp_str = reg_names[FRAME_POINTER_REGNUM];
6345 const char *t1_str = "%g1";
6347 /* Things get a little tricky if local variables take up more than ~4096
6348 bytes and outgoing arguments take up more than ~4096 bytes. When that
6349 happens, the register save area can't be accessed from either end of
6350 the frame. Handle this by decrementing %sp to the start of the gp
6351 register save area, save the regs, update %i7, and then set %sp to its
6352 final value. Given that we only have one scratch register to play
6353 with it is the cheapest solution, and it helps gdb out as it won't
6354 slow down recognition of flat functions.
6355 Don't change the order of insns emitted here without checking with
6356 the gdb folk first. */
6358 /* Is the entire register save area offsettable from %sp? */
6359 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
6363 fprintf (file, "\tadd\t%s, %d, %s\n",
6364 sp_str, -size, sp_str);
6365 if (gmask & FRAME_POINTER_MASK)
6367 fprintf (file, "\tst\t%s, [%s+%d]\n",
6368 fp_str, sp_str, reg_offset);
6369 fprintf (file, "\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
6370 sp_str, -size, fp_str, ASM_COMMENT_START);
6376 fprintf (file, "\tset\t%d, %s\n\tsub\t%s, %s, %s\n",
6377 size, t1_str, sp_str, t1_str, sp_str);
6378 if (gmask & FRAME_POINTER_MASK)
6380 fprintf (file, "\tst\t%s, [%s+%d]\n",
6381 fp_str, sp_str, reg_offset);
6382 fprintf (file, "\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
6383 sp_str, t1_str, fp_str, ASM_COMMENT_START);
6387 if (dwarf2out_do_frame ())
6389 char *l = dwarf2out_cfi_label ();
6390 if (gmask & FRAME_POINTER_MASK)
6392 dwarf2out_reg_save (l, FRAME_POINTER_REGNUM,
6393 reg_offset - 4 - size);
6394 dwarf2out_def_cfa (l, FRAME_POINTER_REGNUM, 0);
6397 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size);
6399 if (gmask & RETURN_ADDR_MASK)
6401 fprintf (file, "\tst\t%s, [%s+%d]\n",
6402 reg_names[RETURN_ADDR_REGNUM], sp_str, reg_offset);
6403 if (dwarf2out_do_frame ())
6404 dwarf2out_return_save ("", reg_offset - size);
6407 sparc_flat_save_restore (file, sp_str, reg_offset,
6408 gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK),
6409 current_frame_info.fmask,
6410 "st", "std", -size);
6414 /* Subtract %sp in two steps, but make sure there is always a
6415 64 byte register save area, and %sp is properly aligned. */
6416 /* Amount to decrement %sp by, the first time. */
6417 unsigned int size1 = ((size - reg_offset + 64) + 15) & -16;
6418 /* Offset to register save area from %sp. */
6419 unsigned int offset = size1 - (size - reg_offset);
6423 fprintf (file, "\tadd\t%s, %d, %s\n",
6424 sp_str, -size1, sp_str);
6425 if (gmask & FRAME_POINTER_MASK)
6427 fprintf (file, "\tst\t%s, [%s+%d]\n\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
6428 fp_str, sp_str, offset, sp_str, -size1, fp_str,
6435 fprintf (file, "\tset\t%d, %s\n\tsub\t%s, %s, %s\n",
6436 size1, t1_str, sp_str, t1_str, sp_str);
6437 if (gmask & FRAME_POINTER_MASK)
6439 fprintf (file, "\tst\t%s, [%s+%d]\n\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
6440 fp_str, sp_str, offset, sp_str, t1_str, fp_str,
6445 if (dwarf2out_do_frame ())
6447 char *l = dwarf2out_cfi_label ();
6448 if (gmask & FRAME_POINTER_MASK)
6450 dwarf2out_reg_save (l, FRAME_POINTER_REGNUM,
6451 offset - 4 - size1);
6452 dwarf2out_def_cfa (l, FRAME_POINTER_REGNUM, 0);
6455 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size1);
6457 if (gmask & RETURN_ADDR_MASK)
6459 fprintf (file, "\tst\t%s, [%s+%d]\n",
6460 reg_names[RETURN_ADDR_REGNUM], sp_str, offset);
6461 if (dwarf2out_do_frame ())
6462 /* offset - size1 == reg_offset - size
6463 if reg_offset were updated above like offset. */
6464 dwarf2out_return_save ("", offset - size1);
6467 sparc_flat_save_restore (file, sp_str, offset,
6468 gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK),
6469 current_frame_info.fmask,
6470 "st", "std", -size1);
6471 fprintf (file, "\tset\t%d, %s\n\tsub\t%s, %s, %s\n",
6472 size - size1, t1_str, sp_str, t1_str, sp_str);
6473 if (dwarf2out_do_frame ())
6474 if (! (gmask & FRAME_POINTER_MASK))
6475 dwarf2out_def_cfa ("", STACK_POINTER_REGNUM, size);
6479 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
6482 /* Do any necessary cleanup after a function to restore stack, frame,
6486 sparc_flat_output_function_epilogue (file, size)
6490 rtx epilogue_delay = current_function_epilogue_delay_list;
6491 int noepilogue = FALSE;
6493 /* This is only for the human reader. */
6494 fprintf (file, "\t%s#EPILOGUE#\n", ASM_COMMENT_START);
6496 /* The epilogue does not depend on any registers, but the stack
6497 registers, so we assume that if we have 1 pending nop, it can be
6498 ignored, and 2 it must be filled (2 nops occur for integer
6499 multiply and divide). */
6501 size = SPARC_STACK_ALIGN (size);
6502 size = (!current_frame_info.initialized
6503 ? sparc_flat_compute_frame_size (size)
6504 : current_frame_info.total_size);
6506 if (size == 0 && epilogue_delay == 0)
6508 rtx insn = get_last_insn ();
6510 /* If the last insn was a BARRIER, we don't have to write any code
6511 because a jump (aka return) was put there. */
6512 if (GET_CODE (insn) == NOTE)
6513 insn = prev_nonnote_insn (insn);
6514 if (insn && GET_CODE (insn) == BARRIER)
6520 unsigned int reg_offset = current_frame_info.reg_offset;
6522 const char *sp_str = reg_names[STACK_POINTER_REGNUM];
6523 const char *fp_str = reg_names[FRAME_POINTER_REGNUM];
6524 const char *t1_str = "%g1";
6526 /* In the reload sequence, we don't need to fill the load delay
6527 slots for most of the loads, also see if we can fill the final
6528 delay slot if not otherwise filled by the reload sequence. */
6531 fprintf (file, "\tset\t%d, %s\n", size, t1_str);
6533 if (frame_pointer_needed)
6536 fprintf (file,"\tsub\t%s, %s, %s\t\t%s# sp not trusted here\n",
6537 fp_str, t1_str, sp_str, ASM_COMMENT_START);
6539 fprintf (file,"\tsub\t%s, %d, %s\t\t%s# sp not trusted here\n",
6540 fp_str, size, sp_str, ASM_COMMENT_START);
6543 /* Is the entire register save area offsettable from %sp? */
6544 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
6550 /* Restore %sp in two steps, but make sure there is always a
6551 64 byte register save area, and %sp is properly aligned. */
6552 /* Amount to increment %sp by, the first time. */
6553 size1 = ((reg_offset - 64 - 16) + 15) & -16;
6554 /* Offset to register save area from %sp. */
6555 reg_offset = size1 - reg_offset;
6557 fprintf (file, "\tset\t%d, %s\n\tadd\t%s, %s, %s\n",
6558 size1, t1_str, sp_str, t1_str, sp_str);
6561 /* We must restore the frame pointer and return address reg first
6562 because they are treated specially by the prologue output code. */
6563 if (current_frame_info.gmask & FRAME_POINTER_MASK)
6565 fprintf (file, "\tld\t[%s+%d], %s\n",
6566 sp_str, reg_offset, fp_str);
6569 if (current_frame_info.gmask & RETURN_ADDR_MASK)
6571 fprintf (file, "\tld\t[%s+%d], %s\n",
6572 sp_str, reg_offset, reg_names[RETURN_ADDR_REGNUM]);
6576 /* Restore any remaining saved registers. */
6577 sparc_flat_save_restore (file, sp_str, reg_offset,
6578 current_frame_info.gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK),
6579 current_frame_info.fmask,
6582 /* If we had to increment %sp in two steps, record it so the second
6583 restoration in the epilogue finishes up. */
6588 fprintf (file, "\tset\t%d, %s\n",
6592 if (current_function_returns_struct)
6593 fprintf (file, "\tjmp\t%%o7+12\n");
6595 fprintf (file, "\tretl\n");
6597 /* If the only register saved is the return address, we need a
6598 nop, unless we have an instruction to put into it. Otherwise
6599 we don't since reloading multiple registers doesn't reference
6600 the register being loaded. */
6606 final_scan_insn (XEXP (epilogue_delay, 0), file, 1, -2, 1);
6609 else if (size > 4095)
6610 fprintf (file, "\tadd\t%s, %s, %s\n", sp_str, t1_str, sp_str);
6613 fprintf (file, "\tadd\t%s, %d, %s\n", sp_str, size, sp_str);
6616 fprintf (file, "\tnop\n");
6619 /* Reset state info for each function. */
6620 current_frame_info = zero_frame_info;
6622 sparc_output_deferred_case_vectors ();
6625 /* Define the number of delay slots needed for the function epilogue.
6627 On the sparc, we need a slot if either no stack has been allocated,
6628 or the only register saved is the return register. */
6631 sparc_flat_epilogue_delay_slots ()
6633 if (!current_frame_info.initialized)
6634 (void) sparc_flat_compute_frame_size (get_frame_size ());
6636 if (current_frame_info.total_size == 0)
6642 /* Return true is TRIAL is a valid insn for the epilogue delay slot.
6643 Any single length instruction which doesn't reference the stack or frame
6647 sparc_flat_eligible_for_epilogue_delay (trial, slot)
6649 int slot ATTRIBUTE_UNUSED;
6651 rtx pat = PATTERN (trial);
6653 if (get_attr_length (trial) != 1)
6656 /* If %g0 is live, there are lots of things we can't handle.
6657 Rather than trying to find them all now, let's punt and only
6658 optimize things as necessary. */
6662 if (! reg_mentioned_p (stack_pointer_rtx, pat)
6663 && ! reg_mentioned_p (frame_pointer_rtx, pat))
6669 /* Adjust the cost of a scheduling dependency. Return the new cost of
6670 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
6673 supersparc_adjust_cost (insn, link, dep_insn, cost)
6679 enum attr_type insn_type;
6681 if (! recog_memoized (insn))
6684 insn_type = get_attr_type (insn);
6686 if (REG_NOTE_KIND (link) == 0)
6688 /* Data dependency; DEP_INSN writes a register that INSN reads some
6691 /* if a load, then the dependence must be on the memory address;
6692 add an extra "cycle". Note that the cost could be two cycles
6693 if the reg was written late in an instruction group; we ca not tell
6695 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
6698 /* Get the delay only if the address of the store is the dependence. */
6699 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
6701 rtx pat = PATTERN(insn);
6702 rtx dep_pat = PATTERN (dep_insn);
6704 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
6705 return cost; /* This should not happen! */
6707 /* The dependency between the two instructions was on the data that
6708 is being stored. Assume that this implies that the address of the
6709 store is not dependent. */
6710 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
6713 return cost + 3; /* An approximation. */
6716 /* A shift instruction cannot receive its data from an instruction
6717 in the same cycle; add a one cycle penalty. */
6718 if (insn_type == TYPE_SHIFT)
6719 return cost + 3; /* Split before cascade into shift. */
6723 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
6724 INSN writes some cycles later. */
6726 /* These are only significant for the fpu unit; writing a fp reg before
6727 the fpu has finished with it stalls the processor. */
6729 /* Reusing an integer register causes no problems. */
6730 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
6738 hypersparc_adjust_cost (insn, link, dep_insn, cost)
6744 enum attr_type insn_type, dep_type;
6745 rtx pat = PATTERN(insn);
6746 rtx dep_pat = PATTERN (dep_insn);
6748 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
6751 insn_type = get_attr_type (insn);
6752 dep_type = get_attr_type (dep_insn);
6754 switch (REG_NOTE_KIND (link))
6757 /* Data dependency; DEP_INSN writes a register that INSN reads some
6764 /* Get the delay iff the address of the store is the dependence. */
6765 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
6768 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
6775 /* If a load, then the dependence must be on the memory address. If
6776 the addresses aren't equal, then it might be a false dependency */
6777 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
6779 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
6780 || GET_CODE (SET_DEST (dep_pat)) != MEM
6781 || GET_CODE (SET_SRC (pat)) != MEM
6782 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
6783 XEXP (SET_SRC (pat), 0)))
6791 /* Compare to branch latency is 0. There is no benefit from
6792 separating compare and branch. */
6793 if (dep_type == TYPE_COMPARE)
6795 /* Floating point compare to branch latency is less than
6796 compare to conditional move. */
6797 if (dep_type == TYPE_FPCMP)
6806 /* Anti-dependencies only penalize the fpu unit. */
6807 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
6819 ultrasparc_adjust_cost (insn, link, dep_insn, cost)
6825 enum attr_type insn_type, dep_type;
6826 rtx pat = PATTERN(insn);
6827 rtx dep_pat = PATTERN (dep_insn);
6829 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
6832 insn_type = get_attr_type (insn);
6833 dep_type = get_attr_type (dep_insn);
6835 /* Nothing issues in parallel with integer multiplies, so
6836 mark as zero cost since the scheduler can not do anything
6838 if (insn_type == TYPE_IMUL)
6841 #define SLOW_FP(dep_type) \
6842 (dep_type == TYPE_FPSQRTS || dep_type == TYPE_FPSQRTD || \
6843 dep_type == TYPE_FPDIVS || dep_type == TYPE_FPDIVD)
6845 switch (REG_NOTE_KIND (link))
6848 /* Data dependency; DEP_INSN writes a register that INSN reads some
6851 if (dep_type == TYPE_CMOVE)
6853 /* Instructions that read the result of conditional moves cannot
6854 be in the same group or the following group. */
6860 /* UltraSPARC can dual issue a store and an instruction setting
6861 the value stored, except for divide and square root. */
6863 if (! SLOW_FP (dep_type))
6868 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
6871 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
6872 /* The dependency between the two instructions is on the data
6873 that is being stored. Assume that the address of the store
6874 is not also dependent. */
6881 /* A load does not return data until at least 11 cycles after
6882 a store to the same location. 3 cycles are accounted for
6883 in the load latency; add the other 8 here. */
6884 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
6886 /* If the addresses are not equal this may be a false
6887 dependency because pointer aliasing could not be
6888 determined. Add only 2 cycles in that case. 2 is
6889 an arbitrary compromise between 8, which would cause
6890 the scheduler to generate worse code elsewhere to
6891 compensate for a dependency which might not really
6893 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
6894 || GET_CODE (SET_SRC (pat)) != MEM
6895 || GET_CODE (SET_DEST (dep_pat)) != MEM
6896 || ! rtx_equal_p (XEXP (SET_SRC (pat), 0),
6897 XEXP (SET_DEST (dep_pat), 0)))
6905 /* Compare to branch latency is 0. There is no benefit from
6906 separating compare and branch. */
6907 if (dep_type == TYPE_COMPARE)
6909 /* Floating point compare to branch latency is less than
6910 compare to conditional move. */
6911 if (dep_type == TYPE_FPCMP)
6916 /* FMOVR class instructions can not issue in the same cycle
6917 or the cycle after an instruction which writes any
6918 integer register. Model this as cost 2 for dependent
6920 if ((dep_type == TYPE_IALU || dep_type == TYPE_UNARY
6921 || dep_type == TYPE_BINARY)
6924 /* Otherwise check as for integer conditional moves. */
6927 /* Conditional moves involving integer registers wait until
6928 3 cycles after loads return data. The interlock applies
6929 to all loads, not just dependent loads, but that is hard
6931 if (dep_type == TYPE_LOAD || dep_type == TYPE_SLOAD)
6941 /* Divide and square root lock destination registers for full latency. */
6942 if (! SLOW_FP (dep_type))
6946 case REG_DEP_OUTPUT:
6947 /* IEU and FPU instruction that have the same destination
6948 register cannot be grouped together. */
6955 /* Other costs not accounted for:
6956 - Single precision floating point loads lock the other half of
6957 the even/odd register pair.
6958 - Several hazards associated with ldd/std are ignored because these
6959 instructions are rarely generated for V9.
6960 - The floating point pipeline can not have both a single and double
6961 precision operation active at the same time. Format conversions
6962 and graphics instructions are given honorary double precision status.
6963 - call and jmpl are always the first instruction in a group. */
6971 sparc_adjust_cost(insn, link, dep, cost)
6979 case PROCESSOR_SUPERSPARC:
6980 cost = supersparc_adjust_cost (insn, link, dep, cost);
6982 case PROCESSOR_HYPERSPARC:
6983 case PROCESSOR_SPARCLITE86X:
6984 cost = hypersparc_adjust_cost (insn, link, dep, cost);
6986 case PROCESSOR_ULTRASPARC:
6987 cost = ultrasparc_adjust_cost (insn, link, dep, cost);
6995 /* This describes the state of the UltraSPARC pipeline during
6996 instruction scheduling. */
6998 #define TMASK(__x) ((unsigned)1 << ((int)(__x)))
6999 #define UMASK(__x) ((unsigned)1 << ((int)(__x)))
7001 enum ultra_code { NONE=0, /* no insn at all */
7002 IEU0, /* shifts and conditional moves */
7003 IEU1, /* condition code setting insns, calls+jumps */
7004 IEUN, /* all other single cycle ieu insns */
7005 LSU, /* loads and stores */
7007 FPM, /* FPU pipeline 1, multiplies and divides */
7008 FPA, /* FPU pipeline 2, all other operations */
7009 SINGLE, /* single issue instructions */
7012 static enum ultra_code ultra_code_from_mask PARAMS ((int));
7013 static void ultra_schedule_insn PARAMS ((rtx *, rtx *, int, enum ultra_code));
7015 static const char *ultra_code_names[NUM_ULTRA_CODES] = {
7016 "NONE", "IEU0", "IEU1", "IEUN", "LSU", "CTI",
7017 "FPM", "FPA", "SINGLE" };
7019 struct ultrasparc_pipeline_state {
7020 /* The insns in this group. */
7023 /* The code for each insn. */
7024 enum ultra_code codes[4];
7026 /* Which insns in this group have been committed by the
7027 scheduler. This is how we determine how many more
7028 can issue this cycle. */
7031 /* How many insns in this group. */
7034 /* Mask of free slots still in this group. */
7035 char free_slot_mask;
7037 /* The slotter uses the following to determine what other
7038 insn types can still make their way into this group. */
7039 char contents [NUM_ULTRA_CODES];
7043 #define ULTRA_NUM_HIST 8
7044 static struct ultrasparc_pipeline_state ultra_pipe_hist[ULTRA_NUM_HIST];
7045 static int ultra_cur_hist;
7046 static int ultra_cycles_elapsed;
7048 #define ultra_pipe (ultra_pipe_hist[ultra_cur_hist])
7050 /* Given TYPE_MASK compute the ultra_code it has. */
7051 static enum ultra_code
7052 ultra_code_from_mask (type_mask)
7055 if (type_mask & (TMASK (TYPE_SHIFT) | TMASK (TYPE_CMOVE)))
7057 else if (type_mask & (TMASK (TYPE_COMPARE) |
7059 TMASK (TYPE_UNCOND_BRANCH)))
7061 else if (type_mask & (TMASK (TYPE_IALU) | TMASK (TYPE_BINARY) |
7062 TMASK (TYPE_MOVE) | TMASK (TYPE_UNARY)))
7064 else if (type_mask & (TMASK (TYPE_LOAD) | TMASK (TYPE_SLOAD) |
7065 TMASK (TYPE_STORE) | TMASK (TYPE_FPLOAD) |
7066 TMASK (TYPE_FPSTORE)))
7068 else if (type_mask & (TMASK (TYPE_FPMUL) | TMASK (TYPE_FPDIVS) |
7069 TMASK (TYPE_FPDIVD) | TMASK (TYPE_FPSQRTS) |
7070 TMASK (TYPE_FPSQRTD)))
7072 else if (type_mask & (TMASK (TYPE_FPMOVE) | TMASK (TYPE_FPCMOVE) |
7073 TMASK (TYPE_FP) | TMASK (TYPE_FPCMP)))
7075 else if (type_mask & TMASK (TYPE_BRANCH))
7081 /* Check INSN (a conditional move) and make sure that it's
7082 results are available at this cycle. Return 1 if the
7083 results are in fact ready. */
7085 ultra_cmove_results_ready_p (insn)
7088 struct ultrasparc_pipeline_state *up;
7091 /* If this got dispatched in the previous
7092 group, the results are not ready. */
7093 entry = (ultra_cur_hist - 1) & (ULTRA_NUM_HIST - 1);
7094 up = &ultra_pipe_hist[entry];
7097 if (up->group[slot] == insn)
7103 /* Walk backwards in pipeline history looking for FPU
7104 operations which use a mode different than FPMODE and
7105 will create a stall if an insn using FPMODE were to be
7106 dispatched this cycle. */
7108 ultra_fpmode_conflict_exists (fpmode)
7109 enum machine_mode fpmode;
7114 hist_ent = (ultra_cur_hist - 1) & (ULTRA_NUM_HIST - 1);
7115 if (ultra_cycles_elapsed < 4)
7116 hist_lim = ultra_cycles_elapsed;
7119 while (hist_lim > 0)
7121 struct ultrasparc_pipeline_state *up = &ultra_pipe_hist[hist_ent];
7126 rtx insn = up->group[slot];
7127 enum machine_mode this_mode;
7131 || GET_CODE (insn) != INSN
7132 || (pat = PATTERN (insn)) == 0
7133 || GET_CODE (pat) != SET)
7136 this_mode = GET_MODE (SET_DEST (pat));
7137 if ((this_mode != SFmode
7138 && this_mode != DFmode)
7139 || this_mode == fpmode)
7142 /* If it is not FMOV, FABS, FNEG, FDIV, or FSQRT then
7143 we will get a stall. Loads and stores are independant
7145 if (GET_CODE (SET_SRC (pat)) != ABS
7146 && GET_CODE (SET_SRC (pat)) != NEG
7147 && ((TMASK (get_attr_type (insn)) &
7148 (TMASK (TYPE_FPDIVS) | TMASK (TYPE_FPDIVD) |
7149 TMASK (TYPE_FPMOVE) | TMASK (TYPE_FPSQRTS) |
7150 TMASK (TYPE_FPSQRTD) |
7151 TMASK (TYPE_LOAD) | TMASK (TYPE_STORE))) == 0))
7155 hist_ent = (hist_ent - 1) & (ULTRA_NUM_HIST - 1);
7158 /* No conflicts, safe to dispatch. */
7162 /* Find an instruction in LIST which has one of the
7163 type attributes enumerated in TYPE_MASK. START
7164 says where to begin the search.
7166 NOTE: This scheme depends upon the fact that we
7167 have less than 32 distinct type attributes. */
7169 static int ultra_types_avail;
7172 ultra_find_type (type_mask, list, start)
7179 /* Short circuit if no such insn exists in the ready
7181 if ((type_mask & ultra_types_avail) == 0)
7184 for (i = start; i >= 0; i--)
7188 if (recog_memoized (insn) >= 0
7189 && (TMASK(get_attr_type (insn)) & type_mask))
7191 enum machine_mode fpmode = SFmode;
7194 int check_depend = 0;
7195 int check_fpmode_conflict = 0;
7197 if (GET_CODE (insn) == INSN
7198 && (pat = PATTERN(insn)) != 0
7199 && GET_CODE (pat) == SET
7200 && !(type_mask & (TMASK (TYPE_STORE) |
7201 TMASK (TYPE_FPSTORE))))
7204 if (GET_MODE (SET_DEST (pat)) == SFmode
7205 || GET_MODE (SET_DEST (pat)) == DFmode)
7207 fpmode = GET_MODE (SET_DEST (pat));
7208 check_fpmode_conflict = 1;
7215 rtx slot_insn = ultra_pipe.group[slot];
7218 /* Already issued, bad dependency, or FPU
7221 && (slot_pat = PATTERN (slot_insn)) != 0
7222 && ((insn == slot_insn)
7223 || (check_depend == 1
7224 && GET_CODE (slot_insn) == INSN
7225 && GET_CODE (slot_pat) == SET
7226 && ((GET_CODE (SET_DEST (slot_pat)) == REG
7227 && GET_CODE (SET_SRC (pat)) == REG
7228 && REGNO (SET_DEST (slot_pat)) ==
7229 REGNO (SET_SRC (pat)))
7230 || (GET_CODE (SET_DEST (slot_pat)) == SUBREG
7231 && GET_CODE (SET_SRC (pat)) == SUBREG
7232 && REGNO (SUBREG_REG (SET_DEST (slot_pat))) ==
7233 REGNO (SUBREG_REG (SET_SRC (pat)))
7234 && SUBREG_WORD (SET_DEST (slot_pat)) ==
7235 SUBREG_WORD (SET_SRC (pat)))))
7236 || (check_fpmode_conflict == 1
7237 && GET_CODE (slot_insn) == INSN
7238 && GET_CODE (slot_pat) == SET
7239 && (GET_MODE (SET_DEST (slot_pat)) == SFmode
7240 || GET_MODE (SET_DEST (slot_pat)) == DFmode)
7241 && GET_MODE (SET_DEST (slot_pat)) != fpmode)))
7245 /* Check for peculiar result availability and dispatch
7246 interference situations. */
7248 && ultra_cycles_elapsed > 0)
7252 for (link = LOG_LINKS (insn); link; link = XEXP (link, 1))
7254 rtx link_insn = XEXP (link, 0);
7255 if (GET_CODE (link_insn) == INSN
7256 && recog_memoized (link_insn) >= 0
7257 && (TMASK (get_attr_type (link_insn)) &
7258 (TMASK (TYPE_CMOVE) | TMASK (TYPE_FPCMOVE)))
7259 && ! ultra_cmove_results_ready_p (link_insn))
7263 if (check_fpmode_conflict
7264 && ultra_fpmode_conflict_exists (fpmode))
7277 ultra_build_types_avail (ready, n_ready)
7281 int i = n_ready - 1;
7283 ultra_types_avail = 0;
7286 rtx insn = ready[i];
7288 if (recog_memoized (insn) >= 0)
7289 ultra_types_avail |= TMASK (get_attr_type (insn));
7295 /* Place insn pointed to my IP into the pipeline.
7296 Make element THIS of READY be that insn if it
7297 is not already. TYPE indicates the pipeline class
7298 this insn falls into. */
7300 ultra_schedule_insn (ip, ready, this, type)
7304 enum ultra_code type;
7307 char mask = ultra_pipe.free_slot_mask;
7310 /* Obtain free slot. */
7311 for (pipe_slot = 0; pipe_slot < 4; pipe_slot++)
7312 if ((mask & (1 << pipe_slot)) != 0)
7317 /* In it goes, and it hasn't been committed yet. */
7318 ultra_pipe.group[pipe_slot] = *ip;
7319 ultra_pipe.codes[pipe_slot] = type;
7320 ultra_pipe.contents[type] = 1;
7322 (UMASK (IEUN) | UMASK (IEU0) | UMASK (IEU1)))
7323 ultra_pipe.num_ieu_insns += 1;
7325 ultra_pipe.free_slot_mask = (mask & ~(1 << pipe_slot));
7326 ultra_pipe.group_size += 1;
7327 ultra_pipe.commit[pipe_slot] = 0;
7329 /* Update ready list. */
7331 while (ip != &ready[this])
7339 /* Advance to the next pipeline group. */
7341 ultra_flush_pipeline ()
7343 ultra_cur_hist = (ultra_cur_hist + 1) & (ULTRA_NUM_HIST - 1);
7344 ultra_cycles_elapsed += 1;
7345 bzero ((char *) &ultra_pipe, sizeof ultra_pipe);
7346 ultra_pipe.free_slot_mask = 0xf;
7349 /* Init our data structures for this current block. */
7351 ultrasparc_sched_init (dump, sched_verbose)
7352 FILE *dump ATTRIBUTE_UNUSED;
7353 int sched_verbose ATTRIBUTE_UNUSED;
7355 bzero ((char *) ultra_pipe_hist, sizeof ultra_pipe_hist);
7357 ultra_cycles_elapsed = 0;
7358 ultra_pipe.free_slot_mask = 0xf;
7361 /* INSN has been scheduled, update pipeline commit state
7362 and return how many instructions are still to be
7363 scheduled in this group. */
7365 ultrasparc_variable_issue (insn)
7368 struct ultrasparc_pipeline_state *up = &ultra_pipe;
7369 int i, left_to_fire;
7372 for (i = 0; i < 4; i++)
7374 if (up->group[i] == 0)
7377 if (up->group[i] == insn)
7381 else if (! up->commit[i])
7385 return left_to_fire;
7388 /* In actual_hazard_this_instance, we may have yanked some
7389 instructions from the ready list due to conflict cost
7390 adjustments. If so, and such an insn was in our pipeline
7391 group, remove it and update state. */
7393 ultra_rescan_pipeline_state (ready, n_ready)
7397 struct ultrasparc_pipeline_state *up = &ultra_pipe;
7400 for (i = 0; i < 4; i++)
7402 rtx insn = up->group[i];
7408 /* If it has been committed, then it was removed from
7409 the ready list because it was actually scheduled,
7410 and that is not the case we are searching for here. */
7411 if (up->commit[i] != 0)
7414 for (j = n_ready - 1; j >= 0; j--)
7415 if (ready[j] == insn)
7418 /* If we didn't find it, toss it. */
7421 enum ultra_code ucode = up->codes[i];
7424 up->codes[i] = NONE;
7425 up->contents[ucode] = 0;
7427 (UMASK (IEUN) | UMASK (IEU0) | UMASK (IEU1)))
7428 up->num_ieu_insns -= 1;
7430 up->free_slot_mask |= (1 << i);
7431 up->group_size -= 1;
7438 ultrasparc_sched_reorder (dump, sched_verbose, ready, n_ready)
7444 struct ultrasparc_pipeline_state *up = &ultra_pipe;
7451 fprintf (dump, "\n;;\tUltraSPARC Looking at [");
7452 for (n = n_ready - 1; n >= 0; n--)
7454 rtx insn = ready[n];
7455 enum ultra_code ucode;
7457 if (recog_memoized (insn) < 0)
7459 ucode = ultra_code_from_mask (TMASK (get_attr_type (insn)));
7461 fprintf (dump, "%s(%d) ",
7462 ultra_code_names[ucode],
7465 fprintf (dump, "%s(%d)",
7466 ultra_code_names[ucode],
7469 fprintf (dump, "]\n");
7472 this_insn = n_ready - 1;
7474 /* Skip over junk we don't understand. */
7475 while ((this_insn >= 0)
7476 && recog_memoized (ready[this_insn]) < 0)
7479 ultra_build_types_avail (ready, this_insn + 1);
7481 while (this_insn >= 0) {
7482 int old_group_size = up->group_size;
7484 if (up->group_size != 0)
7488 num_committed = (up->commit[0] + up->commit[1] +
7489 up->commit[2] + up->commit[3]);
7490 /* If nothing has been commited from our group, or all of
7491 them have. Clear out the (current cycle's) pipeline
7492 state and start afresh. */
7493 if (num_committed == 0
7494 || num_committed == up->group_size)
7496 ultra_flush_pipeline ();
7502 /* OK, some ready list insns got requeued and thus removed
7503 from the ready list. Account for this fact. */
7504 ultra_rescan_pipeline_state (ready, n_ready);
7506 /* Something "changed", make this look like a newly
7507 formed group so the code at the end of the loop
7508 knows that progress was in fact made. */
7509 if (up->group_size != old_group_size)
7514 if (up->group_size == 0)
7516 /* If the pipeline is (still) empty and we have any single
7517 group insns, get them out now as this is a good time. */
7518 rtx *ip = ultra_find_type ((TMASK (TYPE_RETURN) | TMASK (TYPE_ADDRESS) |
7519 TMASK (TYPE_IMUL) | TMASK (TYPE_CMOVE) |
7520 TMASK (TYPE_MULTI) | TMASK (TYPE_MISC)),
7524 ultra_schedule_insn (ip, ready, this_insn, SINGLE);
7528 /* If we are not in the process of emptying out the pipe, try to
7529 obtain an instruction which must be the first in it's group. */
7530 ip = ultra_find_type ((TMASK (TYPE_CALL) |
7531 TMASK (TYPE_CALL_NO_DELAY_SLOT) |
7532 TMASK (TYPE_UNCOND_BRANCH)),
7536 ultra_schedule_insn (ip, ready, this_insn, IEU1);
7539 else if ((ip = ultra_find_type ((TMASK (TYPE_FPDIVS) |
7540 TMASK (TYPE_FPDIVD) |
7541 TMASK (TYPE_FPSQRTS) |
7542 TMASK (TYPE_FPSQRTD)),
7543 ready, this_insn)) != 0)
7545 ultra_schedule_insn (ip, ready, this_insn, FPM);
7550 /* Try to fill the integer pipeline. First, look for an IEU0 specific
7551 operation. We can't do more IEU operations if the first 3 slots are
7552 all full or we have dispatched two IEU insns already. */
7553 if ((up->free_slot_mask & 0x7) != 0
7554 && up->num_ieu_insns < 2
7555 && up->contents[IEU0] == 0
7556 && up->contents[IEUN] == 0)
7558 rtx *ip = ultra_find_type (TMASK(TYPE_SHIFT), ready, this_insn);
7561 ultra_schedule_insn (ip, ready, this_insn, IEU0);
7566 /* If we can, try to find an IEU1 specific or an unnamed
7568 if ((up->free_slot_mask & 0x7) != 0
7569 && up->num_ieu_insns < 2)
7571 rtx *ip = ultra_find_type ((TMASK (TYPE_IALU) | TMASK (TYPE_BINARY) |
7572 TMASK (TYPE_MOVE) | TMASK (TYPE_UNARY) |
7573 (up->contents[IEU1] == 0 ? TMASK (TYPE_COMPARE) : 0)),
7579 ultra_schedule_insn (ip, ready, this_insn,
7580 (!up->contents[IEU1]
7581 && get_attr_type (insn) == TYPE_COMPARE)
7587 /* If only one IEU insn has been found, try to find another unnamed
7588 IEU operation or an IEU1 specific one. */
7589 if ((up->free_slot_mask & 0x7) != 0
7590 && up->num_ieu_insns < 2)
7593 int tmask = (TMASK (TYPE_IALU) | TMASK (TYPE_BINARY) |
7594 TMASK (TYPE_MOVE) | TMASK (TYPE_UNARY));
7596 if (!up->contents[IEU1])
7597 tmask |= TMASK (TYPE_COMPARE);
7598 ip = ultra_find_type (tmask, ready, this_insn);
7603 ultra_schedule_insn (ip, ready, this_insn,
7604 (!up->contents[IEU1]
7605 && get_attr_type (insn) == TYPE_COMPARE)
7611 /* Try for a load or store, but such an insn can only be issued
7612 if it is within' one of the first 3 slots. */
7613 if ((up->free_slot_mask & 0x7) != 0
7614 && up->contents[LSU] == 0)
7616 rtx *ip = ultra_find_type ((TMASK (TYPE_LOAD) | TMASK (TYPE_SLOAD) |
7617 TMASK (TYPE_STORE) | TMASK (TYPE_FPLOAD) |
7618 TMASK (TYPE_FPSTORE)), ready, this_insn);
7621 ultra_schedule_insn (ip, ready, this_insn, LSU);
7626 /* Now find FPU operations, first FPM class. But not divisions or
7627 square-roots because those will break the group up. Unlike all
7628 the previous types, these can go in any slot. */
7629 if (up->free_slot_mask != 0
7630 && up->contents[FPM] == 0)
7632 rtx *ip = ultra_find_type (TMASK (TYPE_FPMUL), ready, this_insn);
7635 ultra_schedule_insn (ip, ready, this_insn, FPM);
7640 /* Continue on with FPA class if we have not filled the group already. */
7641 if (up->free_slot_mask != 0
7642 && up->contents[FPA] == 0)
7644 rtx *ip = ultra_find_type ((TMASK (TYPE_FPMOVE) | TMASK (TYPE_FPCMOVE) |
7645 TMASK (TYPE_FP) | TMASK (TYPE_FPCMP)),
7649 ultra_schedule_insn (ip, ready, this_insn, FPA);
7654 /* Finally, maybe stick a branch in here. */
7655 if (up->free_slot_mask != 0
7656 && up->contents[CTI] == 0)
7658 rtx *ip = ultra_find_type (TMASK (TYPE_BRANCH), ready, this_insn);
7660 /* Try to slip in a branch only if it is one of the
7661 next 2 in the ready list. */
7662 if (ip && ((&ready[this_insn] - ip) < 2))
7664 ultra_schedule_insn (ip, ready, this_insn, CTI);
7670 for (i = 0; i < 4; i++)
7671 if ((up->free_slot_mask & (1 << i)) == 0)
7674 /* See if we made any progress... */
7675 if (old_group_size != up->group_size)
7678 /* Clean out the (current cycle's) pipeline state
7679 and try once more. If we placed no instructions
7680 into the pipeline at all, it means a real hard
7681 conflict exists with some earlier issued instruction
7682 so we must advance to the next cycle to clear it up. */
7683 if (up->group_size == 0)
7685 ultra_flush_pipeline ();
7690 bzero ((char *) &ultra_pipe, sizeof ultra_pipe);
7691 ultra_pipe.free_slot_mask = 0xf;
7699 fprintf (dump, ";;\tUltraSPARC Launched [");
7700 gsize = up->group_size;
7701 for (n = 0; n < 4; n++)
7703 rtx insn = up->group[n];
7710 fprintf (dump, "%s(%d) ",
7711 ultra_code_names[up->codes[n]],
7714 fprintf (dump, "%s(%d)",
7715 ultra_code_names[up->codes[n]],
7718 fprintf (dump, "]\n");
7730 /* Assume V9 processors are capable of at least dual-issue. */
7732 case PROCESSOR_SUPERSPARC:
7734 case PROCESSOR_HYPERSPARC:
7735 case PROCESSOR_SPARCLITE86X:
7737 case PROCESSOR_ULTRASPARC:
7743 set_extends(x, insn)
7746 register rtx pat = PATTERN (insn);
7748 switch (GET_CODE (SET_SRC (pat)))
7750 /* Load and some shift instructions zero extend. */
7753 /* sethi clears the high bits */
7755 /* LO_SUM is used with sethi. sethi cleared the high
7756 bits and the values used with lo_sum are positive */
7758 /* Store flag stores 0 or 1 */
7768 rtx op1 = XEXP (SET_SRC (pat), 1);
7769 if (GET_CODE (op1) == CONST_INT)
7770 return INTVAL (op1) >= 0;
7771 if (GET_CODE (XEXP (SET_SRC (pat), 0)) == REG
7772 && sparc_check_64 (XEXP (SET_SRC (pat), 0), insn) == 1)
7774 if (GET_CODE (op1) == REG
7775 && sparc_check_64 ((op1), insn) == 1)
7780 return GET_MODE (SET_SRC (pat)) == SImode;
7781 /* Positive integers leave the high bits zero. */
7783 return ! (CONST_DOUBLE_LOW (x) & 0x80000000);
7785 return ! (INTVAL (x) & 0x80000000);
7788 return - (GET_MODE (SET_SRC (pat)) == SImode);
7794 /* We _ought_ to have only one kind per function, but... */
7795 static rtx sparc_addr_diff_list;
7796 static rtx sparc_addr_list;
7799 sparc_defer_case_vector (lab, vec, diff)
7803 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
7805 sparc_addr_diff_list
7806 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
7808 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
7812 sparc_output_addr_vec (vec)
7815 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7816 int idx, vlen = XVECLEN (body, 0);
7818 #ifdef ASM_OUTPUT_ADDR_VEC_START
7819 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7822 #ifdef ASM_OUTPUT_CASE_LABEL
7823 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7826 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7829 for (idx = 0; idx < vlen; idx++)
7831 ASM_OUTPUT_ADDR_VEC_ELT
7832 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
7835 #ifdef ASM_OUTPUT_ADDR_VEC_END
7836 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7841 sparc_output_addr_diff_vec (vec)
7844 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7845 rtx base = XEXP (XEXP (body, 0), 0);
7846 int idx, vlen = XVECLEN (body, 1);
7848 #ifdef ASM_OUTPUT_ADDR_VEC_START
7849 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7852 #ifdef ASM_OUTPUT_CASE_LABEL
7853 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7856 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7859 for (idx = 0; idx < vlen; idx++)
7861 ASM_OUTPUT_ADDR_DIFF_ELT
7864 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
7865 CODE_LABEL_NUMBER (base));
7868 #ifdef ASM_OUTPUT_ADDR_VEC_END
7869 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7874 sparc_output_deferred_case_vectors ()
7879 if (sparc_addr_list == NULL_RTX
7880 && sparc_addr_diff_list == NULL_RTX)
7883 /* Align to cache line in the function's code section. */
7884 function_section (current_function_decl);
7886 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
7888 ASM_OUTPUT_ALIGN (asm_out_file, align);
7890 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
7891 sparc_output_addr_vec (XEXP (t, 0));
7892 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
7893 sparc_output_addr_diff_vec (XEXP (t, 0));
7895 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
7898 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
7899 unknown. Return 1 if the high bits are zero, -1 if the register is
7902 sparc_check_64 (x, insn)
7905 /* If a register is set only once it is safe to ignore insns this
7906 code does not know how to handle. The loop will either recognize
7907 the single set and return the correct value or fail to recognize
7911 if (GET_CODE (x) == REG
7912 && flag_expensive_optimizations
7913 && REG_N_SETS (REGNO (x)) == 1)
7919 insn = get_last_insn_anywhere ();
7924 while ((insn = PREV_INSN (insn)))
7926 switch (GET_CODE (insn))
7939 rtx pat = PATTERN (insn);
7940 if (GET_CODE (pat) != SET)
7942 if (rtx_equal_p (x, SET_DEST (pat)))
7943 return set_extends (x, insn);
7944 if (reg_overlap_mentioned_p (SET_DEST (pat), x))
7953 sparc_v8plus_shift (operands, insn, opcode)
7958 static char asm_code[60];
7960 if (GET_CODE (operands[3]) == SCRATCH)
7961 operands[3] = operands[0];
7962 if (GET_CODE (operands[1]) == CONST_INT)
7964 output_asm_insn ("mov %1,%3", operands);
7968 output_asm_insn ("sllx %H1,32,%3", operands);
7969 if (sparc_check_64 (operands[1], insn) <= 0)
7970 output_asm_insn ("srl %L1,0,%L1", operands);
7971 output_asm_insn ("or %L1,%3,%3", operands);
7974 strcpy(asm_code, opcode);
7975 if (which_alternative != 2)
7976 return strcat (asm_code, " %0,%2,%L0\n\tsrlx %L0,32,%H0");
7978 return strcat (asm_code, " %3,%2,%3\n\tsrlx %3,32,%H0\n\tmov %3,%L0");
7982 /* Return 1 if DEST and SRC reference only global and in registers. */
7985 sparc_return_peephole_ok (dest, src)
7990 if (current_function_uses_only_leaf_regs)
7992 if (GET_CODE (src) != CONST_INT
7993 && (GET_CODE (src) != REG || ! IN_OR_GLOBAL_P (src)))
7995 return IN_OR_GLOBAL_P (dest);
7998 /* Output assembler code to FILE to increment profiler label # LABELNO
7999 for profiling a function entry.
8001 32 bit sparc uses %g2 as the STATIC_CHAIN_REGNUM which gets clobbered
8002 during profiling so we need to save/restore it around the call to mcount.
8003 We're guaranteed that a save has just been done, and we use the space
8004 allocated for intreg/fpreg value passing. */
8007 sparc_function_profiler (file, labelno)
8012 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
8014 if (! TARGET_ARCH64)
8015 fputs ("\tst\t%g2,[%fp-4]\n", file);
8017 fputs ("\tsethi\t%hi(", file);
8018 assemble_name (file, buf);
8019 fputs ("),%o0\n", file);
8021 fputs ("\tcall\t", file);
8022 assemble_name (file, MCOUNT_FUNCTION);
8025 fputs ("\t or\t%o0,%lo(", file);
8026 assemble_name (file, buf);
8027 fputs ("),%o0\n", file);
8029 if (! TARGET_ARCH64)
8030 fputs ("\tld\t[%fp-4],%g2\n", file);
8034 /* The following macro shall output assembler code to FILE
8035 to initialize basic-block profiling.
8037 If profile_block_flag == 2
8039 Output code to call the subroutine `__bb_init_trace_func'
8040 and pass two parameters to it. The first parameter is
8041 the address of a block allocated in the object module.
8042 The second parameter is the number of the first basic block
8045 The name of the block is a local symbol made with this statement:
8047 ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 0);
8049 Of course, since you are writing the definition of
8050 `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you
8051 can take a short cut in the definition of this macro and use the
8052 name that you know will result.
8054 The number of the first basic block of the function is
8055 passed to the macro in BLOCK_OR_LABEL.
8057 If described in a virtual assembler language the code to be
8061 parameter2 <- BLOCK_OR_LABEL
8062 call __bb_init_trace_func
8064 else if profile_block_flag != 0
8066 Output code to call the subroutine `__bb_init_func'
8067 and pass one single parameter to it, which is the same
8068 as the first parameter to `__bb_init_trace_func'.
8070 The first word of this parameter is a flag which will be nonzero if
8071 the object module has already been initialized. So test this word
8072 first, and do not call `__bb_init_func' if the flag is nonzero.
8073 Note: When profile_block_flag == 2 the test need not be done
8074 but `__bb_init_trace_func' *must* be called.
8076 BLOCK_OR_LABEL may be used to generate a label number as a
8077 branch destination in case `__bb_init_func' will not be called.
8079 If described in a virtual assembler language the code to be
8091 sparc_function_block_profiler(file, block_or_label)
8096 ASM_GENERATE_INTERNAL_LABEL (LPBX, "LPBX", 0);
8098 if (profile_block_flag == 2)
8100 fputs ("\tsethi\t%hi(", file);
8101 assemble_name (file, LPBX);
8102 fputs ("),%o0\n", file);
8104 fprintf (file, "\tsethi\t%%hi(%d),%%o1\n", block_or_label);
8106 fputs ("\tor\t%o0,%lo(", file);
8107 assemble_name (file, LPBX);
8108 fputs ("),%o0\n", file);
8110 fprintf (file, "\tcall\t%s__bb_init_trace_func\n", user_label_prefix);
8112 fprintf (file, "\t or\t%%o1,%%lo(%d),%%o1\n", block_or_label);
8114 else if (profile_block_flag != 0)
8117 ASM_GENERATE_INTERNAL_LABEL (LPBY, "LPBY", block_or_label);
8119 fputs ("\tsethi\t%hi(", file);
8120 assemble_name (file, LPBX);
8121 fputs ("),%o0\n", file);
8123 fputs ("\tld\t[%lo(", file);
8124 assemble_name (file, LPBX);
8125 fputs (")+%o0],%o1\n", file);
8127 fputs ("\ttst\t%o1\n", file);
8131 fputs ("\tbne,pn\t%icc,", file);
8132 assemble_name (file, LPBY);
8137 fputs ("\tbne\t", file);
8138 assemble_name (file, LPBY);
8142 fputs ("\t or\t%o0,%lo(", file);
8143 assemble_name (file, LPBX);
8144 fputs ("),%o0\n", file);
8146 fprintf (file, "\tcall\t%s__bb_init_func\n\t nop\n", user_label_prefix);
8148 ASM_OUTPUT_INTERNAL_LABEL (file, "LPBY", block_or_label);
8152 /* The following macro shall output assembler code to FILE
8153 to increment a counter associated with basic block number BLOCKNO.
8155 If profile_block_flag == 2
8157 Output code to initialize the global structure `__bb' and
8158 call the function `__bb_trace_func' which will increment the
8161 `__bb' consists of two words. In the first word the number
8162 of the basic block has to be stored. In the second word
8163 the address of a block allocated in the object module
8166 The basic block number is given by BLOCKNO.
8168 The address of the block is given by the label created with
8170 ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 0);
8172 by FUNCTION_BLOCK_PROFILER.
8174 Of course, since you are writing the definition of
8175 `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you
8176 can take a short cut in the definition of this macro and use the
8177 name that you know will result.
8179 If described in a virtual assembler language the code to be
8182 move BLOCKNO -> (__bb)
8183 move LPBX0 -> (__bb+4)
8184 call __bb_trace_func
8186 Note that function `__bb_trace_func' must not change the
8187 machine state, especially the flag register. To grant
8188 this, you must output code to save and restore registers
8189 either in this macro or in the macros MACHINE_STATE_SAVE
8190 and MACHINE_STATE_RESTORE. The last two macros will be
8191 used in the function `__bb_trace_func', so you must make
8192 sure that the function prologue does not change any
8193 register prior to saving it with MACHINE_STATE_SAVE.
8195 else if profile_block_flag != 0
8197 Output code to increment the counter directly.
8198 Basic blocks are numbered separately from zero within each
8199 compiled object module. The count associated with block number
8200 BLOCKNO is at index BLOCKNO in an array of words; the name of
8201 this array is a local symbol made with this statement:
8203 ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 2);
8205 Of course, since you are writing the definition of
8206 `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you
8207 can take a short cut in the definition of this macro and use the
8208 name that you know will result.
8210 If described in a virtual assembler language, the code to be
8213 inc (LPBX2+4*BLOCKNO)
8218 sparc_block_profiler(file, blockno)
8223 int bbreg = TARGET_ARCH64 ? 4 : 2;
8225 if (profile_block_flag == 2)
8227 ASM_GENERATE_INTERNAL_LABEL (LPBX, "LPBX", 0);
8229 fprintf (file, "\tsethi\t%%hi(%s__bb),%%g1\n", user_label_prefix);
8230 fprintf (file, "\tsethi\t%%hi(%d),%%g%d\n", blockno, bbreg);
8231 fprintf (file, "\tor\t%%g1,%%lo(%s__bb),%%g1\n", user_label_prefix);
8232 fprintf (file, "\tor\t%%g%d,%%lo(%d),%%g%d\n", bbreg, blockno, bbreg);
8234 fprintf (file, "\tst\t%%g%d,[%%g1]\n", bbreg);
8236 fputs ("\tsethi\t%hi(", file);
8237 assemble_name (file, LPBX);
8238 fprintf (file, "),%%g%d\n", bbreg);
8240 fputs ("\tor\t%o2,%lo(", file);
8241 assemble_name (file, LPBX);
8242 fprintf (file, "),%%g%d\n", bbreg);
8244 fprintf (file, "\tst\t%%g%d,[%%g1+4]\n", bbreg);
8245 fprintf (file, "\tmov\t%%o7,%%g%d\n", bbreg);
8247 fprintf (file, "\tcall\t%s__bb_trace_func\n\t nop\n", user_label_prefix);
8249 fprintf (file, "\tmov\t%%g%d,%%o7\n", bbreg);
8251 else if (profile_block_flag != 0)
8253 ASM_GENERATE_INTERNAL_LABEL (LPBX, "LPBX", 2);
8255 fputs ("\tsethi\t%hi(", file);
8256 assemble_name (file, LPBX);
8257 fprintf (file, "+%d),%%g1\n", blockno*4);
8259 fputs ("\tld\t[%g1+%lo(", file);
8260 assemble_name (file, LPBX);
8261 if (TARGET_ARCH64 && USE_AS_OFFSETABLE_LO10)
8262 fprintf (file, ")+%d],%%g%d\n", blockno*4, bbreg);
8264 fprintf (file, "+%d)],%%g%d\n", blockno*4, bbreg);
8266 fprintf (file, "\tadd\t%%g%d,1,%%g%d\n", bbreg, bbreg);
8268 fprintf (file, "\tst\t%%g%d,[%%g1+%%lo(", bbreg);
8269 assemble_name (file, LPBX);
8270 if (TARGET_ARCH64 && USE_AS_OFFSETABLE_LO10)
8271 fprintf (file, ")+%d]\n", blockno*4);
8273 fprintf (file, "+%d)]\n", blockno*4);
8277 /* The following macro shall output assembler code to FILE
8278 to indicate a return from function during basic-block profiling.
8280 If profile_block_flag == 2:
8282 Output assembler code to call function `__bb_trace_ret'.
8284 Note that function `__bb_trace_ret' must not change the
8285 machine state, especially the flag register. To grant
8286 this, you must output code to save and restore registers
8287 either in this macro or in the macros MACHINE_STATE_SAVE_RET
8288 and MACHINE_STATE_RESTORE_RET. The last two macros will be
8289 used in the function `__bb_trace_ret', so you must make
8290 sure that the function prologue does not change any
8291 register prior to saving it with MACHINE_STATE_SAVE_RET.
8293 else if profile_block_flag != 0:
8295 The macro will not be used, so it need not distinguish
8300 sparc_function_block_profiler_exit(file)
8303 if (profile_block_flag == 2)
8304 fprintf (file, "\tcall\t%s__bb_trace_ret\n\t nop\n", user_label_prefix);
8309 /* Mark ARG, which is really a struct ultrasparc_pipline_state *, for
8313 mark_ultrasparc_pipeline_state (arg)
8316 struct ultrasparc_pipeline_state *ups;
8319 ups = (struct ultrasparc_pipeline_state *) arg;
8320 for (i = 0; i < sizeof (ups->group) / sizeof (rtx); ++i)
8321 ggc_mark_rtx (ups->group[i]);
8324 /* Called to register all of our global variables with the garbage
8328 sparc_add_gc_roots ()
8330 ggc_add_rtx_root (&sparc_compare_op0, 1);
8331 ggc_add_rtx_root (&sparc_compare_op1, 1);
8332 ggc_add_rtx_root (&leaf_label, 1);
8333 ggc_add_rtx_root (&global_offset_table, 1);
8334 ggc_add_rtx_root (&get_pc_symbol, 1);
8335 ggc_add_rtx_root (&sparc_addr_diff_list, 1);
8336 ggc_add_rtx_root (&sparc_addr_list, 1);
8337 ggc_add_root (ultra_pipe_hist,
8338 sizeof (ultra_pipe_hist) / sizeof (ultra_pipe_hist[0]),
8339 sizeof (ultra_pipe_hist[0]),
8340 &mark_ultrasparc_pipeline_state);