1 /* Subroutines used for code generation on the DEC Alpha.
2 Copyright (C) 1992, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 #include "hard-reg-set.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "insn-flags.h"
33 #include "insn-attr.h"
41 /* Specify which cpu to schedule for. */
42 enum processor_type alpha_cpu;
44 /* Specify how accurate floating-point traps need to be. */
46 enum alpha_trap_precision alpha_tp;
48 /* Specify the floating-point rounding mode. */
50 enum alpha_fp_rounding_mode alpha_fprm;
52 /* Specify which things cause traps. */
54 enum alpha_fp_trap_mode alpha_fptm;
56 /* Strings decoded into the above options. */
57 char *alpha_cpu_string; /* -mcpu=ev[4|5] */
58 char *alpha_tp_string; /* -mtrap-precision=[p|s|i] */
59 char *alpha_fprm_string; /* -mfp-rounding-mode=[n|m|c|d] */
60 char *alpha_fptm_string; /* -mfp-trap-mode=[n|u|su|sui] */
62 /* Save information from a "cmpxx" operation until the branch or scc is
65 rtx alpha_compare_op0, alpha_compare_op1;
66 int alpha_compare_fp_p;
68 /* Save the name of the current function as used by the assembler. This
69 is used by the epilogue. */
71 char *alpha_function_name;
73 /* Non-zero if inside of a function, because the Alpha asm can't
74 handle .files inside of functions. */
76 static int inside_function = FALSE;
78 /* Non-zero if an instruction that may cause a trap is pending. */
80 static int trap_pending = 0;
82 /* Nonzero if the current function needs gp. */
84 int alpha_function_needs_gp;
86 extern char *version_string;
87 extern int rtx_equal_function_value_matters;
89 /* Declarations of static functions. */
90 static void alpha_set_memflags_1 PROTO((rtx, int, int, int));
91 static rtx alpha_emit_set_const_1 PROTO((rtx, enum machine_mode,
93 static void add_long_const PROTO((FILE *, HOST_WIDE_INT, int, int, int));
95 /* Compute the size of the save area in the stack. */
96 static void alpha_sa_mask PROTO((unsigned long *imaskP,
97 unsigned long *fmaskP));
98 /* Strip type information. */
99 #define CURRENT_FUNCTION_ARGS_INFO \
100 (TARGET_OPEN_VMS ? current_function_args_info & 0xff \
101 : current_function_args_info)
103 /* Parse target option strings. */
108 alpha_cpu = PROCESSOR_EV4;
110 if (alpha_cpu_string)
112 if (! strcmp (alpha_cpu_string, "ev4")
113 || ! strcmp (alpha_cpu_string, "21064"))
114 alpha_cpu = PROCESSOR_EV4;
115 else if (! strcmp (alpha_cpu_string, "ev5")
116 || ! strcmp (alpha_cpu_string, "21164"))
117 alpha_cpu = PROCESSOR_EV5;
119 error ("bad value `%s' for -mcpu switch", alpha_cpu_string);
122 alpha_tp = ALPHA_TP_PROG;
123 alpha_fprm = ALPHA_FPRM_NORM;
124 alpha_fptm = ALPHA_FPTM_N;
128 alpha_tp = ALPHA_TP_INSN;
129 alpha_fptm = ALPHA_FPTM_SU;
132 if (TARGET_IEEE_WITH_INEXACT)
134 alpha_tp = ALPHA_TP_INSN;
135 alpha_fptm = ALPHA_FPTM_SUI;
140 if (! strcmp (alpha_tp_string, "p"))
141 alpha_tp = ALPHA_TP_PROG;
142 else if (! strcmp (alpha_tp_string, "f"))
143 alpha_tp = ALPHA_TP_FUNC;
144 else if (! strcmp (alpha_tp_string, "i"))
145 alpha_tp = ALPHA_TP_INSN;
147 error ("bad value `%s' for -mtrap-precision switch", alpha_tp_string);
150 if (alpha_fprm_string)
152 if (! strcmp (alpha_fprm_string, "n"))
153 alpha_fprm = ALPHA_FPRM_NORM;
154 else if (! strcmp (alpha_fprm_string, "m"))
155 alpha_fprm = ALPHA_FPRM_MINF;
156 else if (! strcmp (alpha_fprm_string, "c"))
157 alpha_fprm = ALPHA_FPRM_CHOP;
158 else if (! strcmp (alpha_fprm_string,"d"))
159 alpha_fprm = ALPHA_FPRM_DYN;
161 error ("bad value `%s' for -mfp-rounding-mode switch",
165 if (alpha_fptm_string)
167 if (strcmp (alpha_fptm_string, "n") == 0)
168 alpha_fptm = ALPHA_FPTM_N;
169 else if (strcmp (alpha_fptm_string, "u") == 0)
170 alpha_fptm = ALPHA_FPTM_U;
171 else if (strcmp (alpha_fptm_string, "su") == 0)
172 alpha_fptm = ALPHA_FPTM_SU;
173 else if (strcmp (alpha_fptm_string, "sui") == 0)
174 alpha_fptm = ALPHA_FPTM_SUI;
176 error ("bad value `%s' for -mfp-trap-mode switch", alpha_fptm_string);
179 /* Do some sanity checks on the above option. */
181 if ((alpha_fptm == ALPHA_FPTM_SU || alpha_fptm == ALPHA_FPTM_SUI)
182 && alpha_tp != ALPHA_TP_INSN)
184 warning ("fp software completion requires -mtrap-precision=i");
185 alpha_tp = ALPHA_TP_INSN;
188 if (TARGET_FLOAT_VAX)
190 if (alpha_fprm == ALPHA_FPRM_MINF || alpha_fprm == ALPHA_FPRM_DYN)
192 warning ("rounding mode not supported for VAX floats");
193 alpha_fprm = ALPHA_FPRM_NORM;
195 if (alpha_fptm == ALPHA_FPTM_SUI)
197 warning ("trap mode not supported for VAX floats");
198 alpha_fptm = ALPHA_FPTM_SU;
203 /* Returns 1 if VALUE is a mask that contains full bytes of zero or ones. */
211 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
213 if ((value & 0xff) != 0 && (value & 0xff) != 0xff)
219 /* Returns 1 if OP is either the constant zero or a register. If a
220 register, it must be in the proper mode unless MODE is VOIDmode. */
223 reg_or_0_operand (op, mode)
225 enum machine_mode mode;
227 return op == const0_rtx || register_operand (op, mode);
230 /* Return 1 if OP is a constant in the range of 0-63 (for a shift) or
234 reg_or_6bit_operand (op, mode)
236 enum machine_mode mode;
238 return ((GET_CODE (op) == CONST_INT
239 && (unsigned HOST_WIDE_INT) INTVAL (op) < 64)
240 || register_operand (op, mode));
244 /* Return 1 if OP is an 8-bit constant or any register. */
247 reg_or_8bit_operand (op, mode)
249 enum machine_mode mode;
251 return ((GET_CODE (op) == CONST_INT
252 && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100)
253 || register_operand (op, mode));
256 /* Return 1 if OP is an 8-bit constant. */
259 cint8_operand (op, mode)
261 enum machine_mode mode;
263 return (GET_CODE (op) == CONST_INT
264 && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100);
267 /* Return 1 if the operand is a valid second operand to an add insn. */
270 add_operand (op, mode)
272 enum machine_mode mode;
274 if (GET_CODE (op) == CONST_INT)
275 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')
276 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')
277 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O'));
279 return register_operand (op, mode);
282 /* Return 1 if the operand is a valid second operand to a sign-extending
286 sext_add_operand (op, mode)
288 enum machine_mode mode;
290 if (GET_CODE (op) == CONST_INT)
291 return ((unsigned HOST_WIDE_INT) INTVAL (op) < 255
292 || (unsigned HOST_WIDE_INT) (- INTVAL (op)) < 255);
294 return register_operand (op, mode);
297 /* Return 1 if OP is the constant 4 or 8. */
300 const48_operand (op, mode)
302 enum machine_mode mode;
304 return (GET_CODE (op) == CONST_INT
305 && (INTVAL (op) == 4 || INTVAL (op) == 8));
308 /* Return 1 if OP is a valid first operand to an AND insn. */
311 and_operand (op, mode)
313 enum machine_mode mode;
315 if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
316 return (zap_mask (CONST_DOUBLE_LOW (op))
317 && zap_mask (CONST_DOUBLE_HIGH (op)));
319 if (GET_CODE (op) == CONST_INT)
320 return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
321 || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100
322 || zap_mask (INTVAL (op)));
324 return register_operand (op, mode);
327 /* Return 1 if OP is a valid first operand to an IOR or XOR insn. */
330 or_operand (op, mode)
332 enum machine_mode mode;
334 if (GET_CODE (op) == CONST_INT)
335 return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
336 || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100);
338 return register_operand (op, mode);
341 /* Return 1 if OP is a constant that is the width, in bits, of an integral
342 mode smaller than DImode. */
345 mode_width_operand (op, mode)
347 enum machine_mode mode;
349 return (GET_CODE (op) == CONST_INT
350 && (INTVAL (op) == 8 || INTVAL (op) == 16 || INTVAL (op) == 32));
353 /* Return 1 if OP is a constant that is the width of an integral machine mode
354 smaller than an integer. */
357 mode_mask_operand (op, mode)
359 enum machine_mode mode;
361 #if HOST_BITS_PER_WIDE_INT == 32
362 if (GET_CODE (op) == CONST_DOUBLE)
363 return CONST_DOUBLE_HIGH (op) == 0 && CONST_DOUBLE_LOW (op) == -1;
366 return (GET_CODE (op) == CONST_INT
367 && (INTVAL (op) == 0xff
368 || INTVAL (op) == 0xffff
369 #if HOST_BITS_PER_WIDE_INT == 64
370 || INTVAL (op) == 0xffffffff
375 /* Return 1 if OP is a multiple of 8 less than 64. */
378 mul8_operand (op, mode)
380 enum machine_mode mode;
382 return (GET_CODE (op) == CONST_INT
383 && (unsigned HOST_WIDE_INT) INTVAL (op) < 64
384 && (INTVAL (op) & 7) == 0);
387 /* Return 1 if OP is the constant zero in floating-point. */
390 fp0_operand (op, mode)
392 enum machine_mode mode;
394 return (GET_MODE (op) == mode
395 && GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode));
398 /* Return 1 if OP is the floating-point constant zero or a register. */
401 reg_or_fp0_operand (op, mode)
403 enum machine_mode mode;
405 return fp0_operand (op, mode) || register_operand (op, mode);
408 /* Return 1 if OP is a register or a constant integer. */
412 reg_or_cint_operand (op, mode)
414 enum machine_mode mode;
416 return GET_CODE (op) == CONST_INT || register_operand (op, mode);
419 /* Return 1 if OP is something that can be reloaded into a register;
420 if it is a MEM, it need not be valid. */
423 some_operand (op, mode)
425 enum machine_mode mode;
427 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
430 switch (GET_CODE (op))
432 case REG: case MEM: case CONST_DOUBLE:
433 case CONST_INT: case LABEL_REF: case SYMBOL_REF: case CONST:
437 return some_operand (SUBREG_REG (op), VOIDmode);
443 /* Return 1 if OP is a valid operand for the source of a move insn. */
446 input_operand (op, mode)
448 enum machine_mode mode;
450 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
453 if (GET_MODE_CLASS (mode) == MODE_FLOAT && GET_MODE (op) != mode)
456 switch (GET_CODE (op))
461 /* This handles both the Windows/NT and OSF cases. */
462 return mode == ptr_mode || mode == DImode;
468 if (register_operand (op, mode))
470 /* ... fall through ... */
472 return (TARGET_BYTE_OPS || (mode != HImode && mode != QImode)
473 && general_operand (op, mode));
476 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
479 return mode == QImode || mode == HImode || add_operand (op, mode);
485 /* Return 1 if OP is a SYMBOL_REF for a function known to be in this
489 current_file_function_operand (op, mode)
491 enum machine_mode mode;
493 return (GET_CODE (op) == SYMBOL_REF
494 && ! profile_flag && ! profile_block_flag
495 && (SYMBOL_REF_FLAG (op)
496 || op == XEXP (DECL_RTL (current_function_decl), 0)));
499 /* Return 1 if OP is a valid operand for the MEM of a CALL insn. */
502 call_operand (op, mode)
504 enum machine_mode mode;
509 return (GET_CODE (op) == SYMBOL_REF
510 || (GET_CODE (op) == REG && (TARGET_OPEN_VMS || REGNO (op) == 27)));
513 /* Return 1 if OP is a valid Alpha comparison operator. Here we know which
514 comparisons are valid in which insn. */
517 alpha_comparison_operator (op, mode)
519 enum machine_mode mode;
521 enum rtx_code code = GET_CODE (op);
523 if (mode != GET_MODE (op) || GET_RTX_CLASS (code) != '<')
526 return (code == EQ || code == LE || code == LT
527 || (mode == DImode && (code == LEU || code == LTU)));
530 /* Return 1 if OP is a valid Alpha swapped comparison operator. */
533 alpha_swapped_comparison_operator (op, mode)
535 enum machine_mode mode;
537 enum rtx_code code = GET_CODE (op);
539 if (mode != GET_MODE (op) || GET_RTX_CLASS (code) != '<')
542 code = swap_condition (code);
543 return (code == EQ || code == LE || code == LT
544 || (mode == DImode && (code == LEU || code == LTU)));
547 /* Return 1 if OP is a signed comparison operation. */
550 signed_comparison_operator (op, mode)
552 enum machine_mode mode;
554 switch (GET_CODE (op))
556 case EQ: case NE: case LE: case LT: case GE: case GT:
563 /* Return 1 if this is a divide or modulus operator. */
566 divmod_operator (op, mode)
568 enum machine_mode mode;
570 switch (GET_CODE (op))
572 case DIV: case MOD: case UDIV: case UMOD:
579 /* Return 1 if this memory address is a known aligned register plus
580 a constant. It must be a valid address. This means that we can do
581 this as an aligned reference plus some offset.
583 Take into account what reload will do.
585 We could say that out-of-range stack slots are alignable, but that would
586 complicate get_aligned_mem and it isn't worth the trouble since few
587 functions have large stack space. */
590 aligned_memory_operand (op, mode)
592 enum machine_mode mode;
594 if (GET_CODE (op) == SUBREG)
596 if (GET_MODE (op) != mode)
598 op = SUBREG_REG (op);
599 mode = GET_MODE (op);
602 if (reload_in_progress && GET_CODE (op) == REG
603 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
604 op = reg_equiv_mem[REGNO (op)];
606 if (GET_CODE (op) != MEM || GET_MODE (op) != mode
607 || ! memory_address_p (mode, XEXP (op, 0)))
612 if (GET_CODE (op) == PLUS)
615 return (GET_CODE (op) == REG
616 && REGNO_POINTER_ALIGN (REGNO (op)) >= 4);
619 /* Similar, but return 1 if OP is a MEM which is not alignable. */
622 unaligned_memory_operand (op, mode)
624 enum machine_mode mode;
626 if (GET_CODE (op) == SUBREG)
628 if (GET_MODE (op) != mode)
630 op = SUBREG_REG (op);
631 mode = GET_MODE (op);
634 if (reload_in_progress && GET_CODE (op) == REG
635 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
636 op = reg_equiv_mem[REGNO (op)];
638 if (GET_CODE (op) != MEM || GET_MODE (op) != mode)
643 if (! memory_address_p (mode, op))
646 if (GET_CODE (op) == PLUS)
649 return (GET_CODE (op) != REG
650 || REGNO_POINTER_ALIGN (REGNO (op)) < 4);
653 /* Return 1 if OP is either a register or an unaligned memory location. */
656 reg_or_unaligned_mem_operand (op, mode)
658 enum machine_mode mode;
660 return register_operand (op, mode) || unaligned_memory_operand (op, mode);
663 /* Return 1 if OP is any memory location. During reload a pseudo matches. */
666 any_memory_operand (op, mode)
668 enum machine_mode mode;
670 return (GET_CODE (op) == MEM
671 || (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG)
672 || (reload_in_progress && GET_CODE (op) == REG
673 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
674 || (reload_in_progress && GET_CODE (op) == SUBREG
675 && GET_CODE (SUBREG_REG (op)) == REG
676 && REGNO (SUBREG_REG (op)) >= FIRST_PSEUDO_REGISTER));
679 /* REF is an alignable memory location. Place an aligned SImode
680 reference into *PALIGNED_MEM and the number of bits to shift into
684 get_aligned_mem (ref, paligned_mem, pbitnum)
686 rtx *paligned_mem, *pbitnum;
689 HOST_WIDE_INT offset = 0;
691 if (GET_CODE (ref) == SUBREG)
693 offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
694 if (BYTES_BIG_ENDIAN)
695 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
696 - MIN (UNITS_PER_WORD,
697 GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
698 ref = SUBREG_REG (ref);
701 if (GET_CODE (ref) == REG)
702 ref = reg_equiv_mem[REGNO (ref)];
704 if (reload_in_progress)
705 base = find_replacement (&XEXP (ref, 0));
707 base = XEXP (ref, 0);
709 if (GET_CODE (base) == PLUS)
710 offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
712 *paligned_mem = gen_rtx (MEM, SImode,
713 plus_constant (base, offset & ~3));
714 MEM_IN_STRUCT_P (*paligned_mem) = MEM_IN_STRUCT_P (ref);
715 MEM_VOLATILE_P (*paligned_mem) = MEM_VOLATILE_P (ref);
716 RTX_UNCHANGING_P (*paligned_mem) = RTX_UNCHANGING_P (ref);
718 *pbitnum = GEN_INT ((offset & 3) * 8);
721 /* Similar, but just get the address. Handle the two reload cases.
722 Add EXTRA_OFFSET to the address we return. */
725 get_unaligned_address (ref, extra_offset)
730 HOST_WIDE_INT offset = 0;
732 if (GET_CODE (ref) == SUBREG)
734 offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
735 if (BYTES_BIG_ENDIAN)
736 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
737 - MIN (UNITS_PER_WORD,
738 GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
739 ref = SUBREG_REG (ref);
742 if (GET_CODE (ref) == REG)
743 ref = reg_equiv_mem[REGNO (ref)];
745 if (reload_in_progress)
746 base = find_replacement (&XEXP (ref, 0));
748 base = XEXP (ref, 0);
750 if (GET_CODE (base) == PLUS)
751 offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
753 return plus_constant (base, offset + extra_offset);
756 /* Subfunction of the following function. Update the flags of any MEM
757 found in part of X. */
760 alpha_set_memflags_1 (x, in_struct_p, volatile_p, unchanging_p)
762 int in_struct_p, volatile_p, unchanging_p;
766 switch (GET_CODE (x))
770 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
771 alpha_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p,
776 alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p,
781 alpha_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p,
783 alpha_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p,
788 MEM_IN_STRUCT_P (x) = in_struct_p;
789 MEM_VOLATILE_P (x) = volatile_p;
790 RTX_UNCHANGING_P (x) = unchanging_p;
795 /* Given INSN, which is either an INSN or a SEQUENCE generated to
796 perform a memory operation, look for any MEMs in either a SET_DEST or
797 a SET_SRC and copy the in-struct, unchanging, and volatile flags from
798 REF into each of the MEMs found. If REF is not a MEM, don't do
802 alpha_set_memflags (insn, ref)
806 /* Note that it is always safe to get these flags, though they won't
807 be what we think if REF is not a MEM. */
808 int in_struct_p = MEM_IN_STRUCT_P (ref);
809 int volatile_p = MEM_VOLATILE_P (ref);
810 int unchanging_p = RTX_UNCHANGING_P (ref);
812 if (GET_CODE (ref) != MEM
813 || (! in_struct_p && ! volatile_p && ! unchanging_p))
816 alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p);
819 /* Try to output insns to set TARGET equal to the constant C if it can be
820 done in less than N insns. Do all computations in MODE. Returns the place
821 where the output has been placed if it can be done and the insns have been
822 emitted. If it would take more than N insns, zero is returned and no
823 insns and emitted. */
826 alpha_emit_set_const (target, mode, c, n)
828 enum machine_mode mode;
835 /* Try 1 insn, then 2, then up to N. */
836 for (i = 1; i <= n; i++)
837 if ((pat = alpha_emit_set_const_1 (target, mode, c, i)) != 0)
843 /* Internal routine for the above to check for N or below insns. */
846 alpha_emit_set_const_1 (target, mode, c, n)
848 enum machine_mode mode;
852 HOST_WIDE_INT new = c;
854 /* Use a pseudo if highly optimizing and still generating RTL. */
856 = (flag_expensive_optimizations && rtx_equal_function_value_matters
860 #if HOST_BITS_PER_WIDE_INT == 64
861 /* We are only called for SImode and DImode. If this is SImode, ensure that
862 we are sign extended to a full word. This does not make any sense when
863 cross-compiling on a narrow machine. */
866 c = (c & 0xffffffff) - 2 * (c & 0x80000000);
869 /* If this is a sign-extended 32-bit constant, we can do this in at most
870 three insns, so do it if we have enough insns left. We always have
871 a sign-extended 32-bit constant when compiling on a narrow machine.
872 Note that we cannot handle the constant 0x80000000. */
874 if ((HOST_BITS_PER_WIDE_INT != 64
875 || c >> 31 == -1 || c >> 31 == 0)
878 HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
879 HOST_WIDE_INT tmp1 = c - low;
881 = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
882 HOST_WIDE_INT extra = 0;
884 /* If HIGH will be interpreted as negative but the constant is
885 positive, we must adjust it to do two ldha insns. */
887 if ((high & 0x8000) != 0 && c >= 0)
891 high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
894 if (c == low || (low == 0 && extra == 0))
895 return copy_to_suggested_reg (GEN_INT (c), target, mode);
896 else if (n >= 2 + (extra != 0))
898 temp = copy_to_suggested_reg (GEN_INT (low), subtarget, mode);
901 temp = expand_binop (mode, add_optab, temp, GEN_INT (extra << 16),
902 subtarget, 0, OPTAB_WIDEN);
904 return expand_binop (mode, add_optab, temp, GEN_INT (high << 16),
905 target, 0, OPTAB_WIDEN);
909 /* If we couldn't do it that way, try some other methods. But if we have
910 no instructions left, don't bother. Likewise, if this is SImode and
911 we can't make pseudos, we can't do anything since the expand_binop
912 and expand_unop calls will widen and try to make pseudos. */
915 || (mode == SImode && ! rtx_equal_function_value_matters))
918 #if HOST_BITS_PER_WIDE_INT == 64
919 /* First, see if can load a value into the target that is the same as the
920 constant except that all bytes that are 0 are changed to be 0xff. If we
921 can, then we can do a ZAPNOT to obtain the desired constant. */
923 for (i = 0; i < 64; i += 8)
924 if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0)
925 new |= (HOST_WIDE_INT) 0xff << i;
927 /* We are only called for SImode and DImode. If this is SImode, ensure that
928 we are sign extended to a full word. */
931 new = (new & 0xffffffff) - 2 * (new & 0x80000000);
934 && (temp = alpha_emit_set_const (subtarget, mode, new, n - 1)) != 0)
935 return expand_binop (mode, and_optab, temp, GEN_INT (c | ~ new),
936 target, 0, OPTAB_WIDEN);
939 /* Next, see if we can load a related constant and then shift and possibly
940 negate it to get the constant we want. Try this once each increasing
943 for (i = 1; i < n; i++)
945 /* First try complementing. */
946 if ((temp = alpha_emit_set_const (subtarget, mode, ~ c, i)) != 0)
947 return expand_unop (mode, one_cmpl_optab, temp, target, 0);
949 /* Next try to form a constant and do a left shift. We can do this
950 if some low-order bits are zero; the exact_log2 call below tells
951 us that information. The bits we are shifting out could be any
952 value, but here we'll just try the 0- and sign-extended forms of
953 the constant. To try to increase the chance of having the same
954 constant in more than one insn, start at the highest number of
955 bits to shift, but try all possibilities in case a ZAPNOT will
958 if ((bits = exact_log2 (c & - c)) > 0)
959 for (; bits > 0; bits--)
960 if ((temp = (alpha_emit_set_const
962 (unsigned HOST_WIDE_INT) c >> bits, i))) != 0
963 || ((temp = (alpha_emit_set_const
965 ((unsigned HOST_WIDE_INT) c) >> bits, i)))
967 return expand_binop (mode, ashl_optab, temp, GEN_INT (bits),
968 target, 0, OPTAB_WIDEN);
970 /* Now try high-order zero bits. Here we try the shifted-in bits as
971 all zero and all ones. Be careful to avoid shifting outside the
972 mode and to avoid shifting outside the host wide int size. */
974 if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
975 - floor_log2 (c) - 1)) > 0)
976 for (; bits > 0; bits--)
977 if ((temp = alpha_emit_set_const (subtarget, mode,
979 || ((temp = (alpha_emit_set_const
981 ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
984 return expand_binop (mode, lshr_optab, temp, GEN_INT (bits),
985 target, 1, OPTAB_WIDEN);
987 /* Now try high-order 1 bits. We get that with a sign-extension.
988 But one bit isn't enough here. Be careful to avoid shifting outside
989 the mode and to avoid shifting outside the host wide int size. */
991 if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
992 - floor_log2 (~ c) - 2)) > 0)
993 for (; bits > 0; bits--)
994 if ((temp = alpha_emit_set_const (subtarget, mode,
996 || ((temp = (alpha_emit_set_const
998 ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
1001 return expand_binop (mode, ashr_optab, temp, GEN_INT (bits),
1002 target, 0, OPTAB_WIDEN);
1008 #if HOST_BITS_PER_WIDE_INT == 64
1009 /* Having failed to find a 3 insn sequence in alpha_emit_set_const,
1010 fall back to a straight forward decomposition. We do this to avoid
1011 exponential run times encountered when looking for longer sequences
1012 with alpha_emit_set_const. */
1015 alpha_emit_set_long_const (target, c)
1019 /* Use a pseudo if highly optimizing and still generating RTL. */
1021 = (flag_expensive_optimizations && rtx_equal_function_value_matters
1023 HOST_WIDE_INT d1, d2, d3, d4;
1026 /* Decompose the entire word */
1027 d1 = ((c & 0xffff) ^ 0x8000) - 0x8000;
1029 d2 = ((c & 0xffffffff) ^ 0x80000000) - 0x80000000;
1031 d3 = ((c & 0xffff) ^ 0x8000) - 0x8000;
1033 d4 = ((c & 0xffffffff) ^ 0x80000000) - 0x80000000;
1038 /* Construct the high word */
1040 r1 = copy_to_suggested_reg (GEN_INT (d4), subtarget, DImode);
1042 r1 = copy_to_suggested_reg (GEN_INT (d3), subtarget, DImode);
1044 r1 = expand_binop (DImode, add_optab, GEN_INT (d3), GEN_INT (d4),
1045 subtarget, 0, OPTAB_WIDEN);
1047 /* Shift it into place */
1048 r2 = expand_binop (DImode, ashl_optab, r1, GEN_INT (32),
1049 subtarget, 0, OPTAB_WIDEN);
1051 if (subtarget == 0 && d1 == d3 && d2 == d4)
1052 r1 = expand_binop (DImode, add_optab, r1, r2, subtarget, 0, OPTAB_WIDEN);
1057 /* Add in the low word */
1059 r1 = expand_binop (DImode, add_optab, r1, GEN_INT (d2),
1060 subtarget, 0, OPTAB_WIDEN);
1062 r1 = expand_binop (DImode, add_optab, r1, GEN_INT (d1),
1063 subtarget, 0, OPTAB_WIDEN);
1067 r1 = copy_to_suggested_reg(r1, target, DImode);
1071 #endif /* HOST_BITS_PER_WIDE_INT == 64 */
1073 /* Rewrite a comparison against zero CMP of the form
1074 (CODE (cc0) (const_int 0)) so it can be written validly in
1075 a conditional move (if_then_else CMP ...).
1076 If both of the operands that set cc0 are non-zero we must emit
1077 an insn to perform the compare (it can't be done within
1078 the conditional move). */
1080 alpha_emit_conditional_move (cmp, mode)
1082 enum machine_mode mode;
1084 enum rtx_code code = GET_CODE (cmp);
1085 enum rtx_code cmov_code = NE;
1086 rtx op0 = alpha_compare_op0;
1087 rtx op1 = alpha_compare_op1;
1088 enum machine_mode cmp_mode
1089 = (GET_MODE (op0) == VOIDmode ? DImode : GET_MODE (op0));
1090 enum machine_mode cmp_op_mode = alpha_compare_fp_p ? DFmode : DImode;
1093 if (alpha_compare_fp_p != FLOAT_MODE_P (mode))
1096 /* We may be able to use a conditional move directly.
1097 This avoids emitting spurious compares. */
1098 if (signed_comparison_operator (cmp, cmp_op_mode)
1099 && (op0 == CONST0_RTX (cmp_mode) || op1 == CONST0_RTX (cmp_mode)))
1100 return gen_rtx (code, VOIDmode, op0, op1);
1102 /* We can't put the comparison insides a conditional move;
1103 emit a compare instruction and put that inside the
1104 conditional move. Make sure we emit only comparisons we have;
1105 swap or reverse as necessary. */
1109 case EQ: case LE: case LT: case LEU: case LTU:
1110 /* We have these compares: */
1114 /* This must be reversed. */
1115 code = reverse_condition (code);
1119 case GE: case GT: case GEU: case GTU:
1120 /* These must be swapped. Make sure the new first operand is in
1122 code = swap_condition (code);
1123 tem = op0, op0 = op1, op1 = tem;
1124 op0 = force_reg (cmp_mode, op0);
1131 tem = gen_reg_rtx (cmp_op_mode);
1132 emit_move_insn (tem, gen_rtx (code, cmp_op_mode, op0, op1));
1133 return gen_rtx (cmov_code, VOIDmode, tem, CONST0_RTX (cmp_op_mode));
1136 /* Adjust the cost of a scheduling dependency. Return the new cost of
1137 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
1140 alpha_adjust_cost (insn, link, dep_insn, cost)
1148 /* If the dependence is an anti-dependence, there is no cost. For an
1149 output dependence, there is sometimes a cost, but it doesn't seem
1150 worth handling those few cases. */
1152 if (REG_NOTE_KIND (link) != 0)
1155 /* EV5 costs are as given in alpha.md; exceptions are given here. */
1156 if (alpha_cpu == PROCESSOR_EV5)
1158 /* And the lord DEC sayeth: "A special bypass provides an effective
1159 latency of 0 cycles for an ICMP or ILOG insn producing the test
1160 operand of an IBR or CMOV insn." */
1161 if (recog_memoized (dep_insn) >= 0
1162 && (get_attr_type (dep_insn) == TYPE_ICMP
1163 || get_attr_type (dep_insn) == TYPE_ILOG)
1164 && recog_memoized (insn) >= 0
1165 && (get_attr_type (insn) == TYPE_IBR
1166 || (get_attr_type (insn) == TYPE_CMOV
1167 && !((set = single_set (dep_insn)) != 0
1168 && GET_CODE (PATTERN (insn)) == SET
1169 && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE
1170 && (rtx_equal_p (SET_DEST (set),
1171 XEXP (SET_SRC (PATTERN (insn)), 1))
1172 || rtx_equal_p (SET_DEST (set),
1173 XEXP (SET_SRC (PATTERN (insn)), 2)))))))
1178 /* If INSN is a store insn and DEP_INSN is setting the data being stored,
1179 we can sometimes lower the cost. */
1181 if (recog_memoized (insn) >= 0 && get_attr_type (insn) == TYPE_ST
1182 && (set = single_set (dep_insn)) != 0
1183 && GET_CODE (PATTERN (insn)) == SET
1184 && rtx_equal_p (SET_DEST (set), SET_SRC (PATTERN (insn))))
1185 switch (get_attr_type (dep_insn))
1188 /* No savings here. */
1193 /* In these cases, we save one cycle. */
1197 /* In all other cases, we save two cycles. */
1198 return MAX (0, cost - 4);
1201 /* Another case that needs adjustment is an arithmetic or logical
1202 operation. It's cost is usually one cycle, but we default it to
1203 two in the MD file. The only case that it is actually two is
1204 for the address in loads and stores. */
1206 if (recog_memoized (dep_insn) >= 0
1207 && (get_attr_type (dep_insn) == TYPE_IADD
1208 || get_attr_type (dep_insn) == TYPE_ILOG))
1209 switch (get_attr_type (insn))
1219 /* The final case is when a compare feeds into an integer branch. The cost
1220 is only one cycle in that case. */
1222 if (recog_memoized (dep_insn) >= 0
1223 && get_attr_type (dep_insn) == TYPE_ICMP
1224 && recog_memoized (insn) >= 0
1225 && get_attr_type (insn) == TYPE_IBR)
1228 /* Otherwise, return the default cost. */
1233 /* Print an operand. Recognize special options, documented below. */
1236 print_operand (file, x, code)
1246 /* Generates fp-rounding mode suffix: nothing for normal, 'c' for
1247 chopped, 'm' for minus-infinity, and 'd' for dynamic rounding
1248 mode. alpha_fprm controls which suffix is generated. */
1251 case ALPHA_FPRM_NORM:
1253 case ALPHA_FPRM_MINF:
1256 case ALPHA_FPRM_CHOP:
1259 case ALPHA_FPRM_DYN:
1266 /* Generates trap-mode suffix for instructions that accept the su
1267 suffix only (cmpt et al). */
1268 if (alpha_tp == ALPHA_TP_INSN)
1273 /* Generates trap-mode suffix for instructions that accept the u, su,
1274 and sui suffix. This is the bulk of the IEEE floating point
1275 instructions (addt et al). */
1286 case ALPHA_FPTM_SUI:
1287 fputs ("sui", file);
1293 /* Generates trap-mode suffix for instructions that accept the sui
1294 suffix (cvtqt and cvtqs). */
1297 case ALPHA_FPTM_N: case ALPHA_FPTM_U:
1298 case ALPHA_FPTM_SU: /* cvtqt/cvtqs can't cause underflow */
1300 case ALPHA_FPTM_SUI:
1301 fputs ("sui", file);
1307 /* Generates single precision instruction suffix. */
1308 fprintf (file, "%c", (TARGET_FLOAT_VAX?'f':'s'));
1312 /* Generates double precision instruction suffix. */
1313 fprintf (file, "%c", (TARGET_FLOAT_VAX?'g':'t'));
1317 /* If this operand is the constant zero, write it as "$31". */
1318 if (GET_CODE (x) == REG)
1319 fprintf (file, "%s", reg_names[REGNO (x)]);
1320 else if (x == CONST0_RTX (GET_MODE (x)))
1321 fprintf (file, "$31");
1323 output_operand_lossage ("invalid %%r value");
1328 /* Similar, but for floating-point. */
1329 if (GET_CODE (x) == REG)
1330 fprintf (file, "%s", reg_names[REGNO (x)]);
1331 else if (x == CONST0_RTX (GET_MODE (x)))
1332 fprintf (file, "$f31");
1334 output_operand_lossage ("invalid %%R value");
1339 /* Write the 1's complement of a constant. */
1340 if (GET_CODE (x) != CONST_INT)
1341 output_operand_lossage ("invalid %%N value");
1343 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x));
1347 /* Write 1 << C, for a constant C. */
1348 if (GET_CODE (x) != CONST_INT)
1349 output_operand_lossage ("invalid %%P value");
1351 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) 1 << INTVAL (x));
1355 /* Write the high-order 16 bits of a constant, sign-extended. */
1356 if (GET_CODE (x) != CONST_INT)
1357 output_operand_lossage ("invalid %%h value");
1359 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) >> 16);
1363 /* Write the low-order 16 bits of a constant, sign-extended. */
1364 if (GET_CODE (x) != CONST_INT)
1365 output_operand_lossage ("invalid %%L value");
1367 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
1368 (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000));
1372 /* Write mask for ZAP insn. */
1373 if (GET_CODE (x) == CONST_DOUBLE)
1375 HOST_WIDE_INT mask = 0;
1376 HOST_WIDE_INT value;
1378 value = CONST_DOUBLE_LOW (x);
1379 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
1384 value = CONST_DOUBLE_HIGH (x);
1385 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
1388 mask |= (1 << (i + sizeof (int)));
1390 fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask & 0xff);
1393 else if (GET_CODE (x) == CONST_INT)
1395 HOST_WIDE_INT mask = 0, value = INTVAL (x);
1397 for (i = 0; i < 8; i++, value >>= 8)
1401 fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask);
1404 output_operand_lossage ("invalid %%m value");
1408 /* 'b', 'w', or 'l' as the value of the constant. */
1409 if (GET_CODE (x) != CONST_INT
1410 || (INTVAL (x) != 8 && INTVAL (x) != 16 && INTVAL (x) != 32))
1411 output_operand_lossage ("invalid %%M value");
1413 fprintf (file, "%s",
1414 INTVAL (x) == 8 ? "b" : INTVAL (x) == 16 ? "w" : "l");
1418 /* Similar, except do it from the mask. */
1419 if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xff)
1420 fprintf (file, "b");
1421 else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffff)
1422 fprintf (file, "w");
1423 #if HOST_BITS_PER_WIDE_INT == 32
1424 else if (GET_CODE (x) == CONST_DOUBLE
1425 && CONST_DOUBLE_HIGH (x) == 0
1426 && CONST_DOUBLE_LOW (x) == -1)
1427 fprintf (file, "l");
1429 else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffffffff)
1430 fprintf (file, "l");
1433 output_operand_lossage ("invalid %%U value");
1437 /* Write the constant value divided by 8. */
1438 if (GET_CODE (x) != CONST_INT
1439 && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
1440 && (INTVAL (x) & 7) != 8)
1441 output_operand_lossage ("invalid %%s value");
1443 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) / 8);
1447 /* Same, except compute (64 - c) / 8 */
1449 if (GET_CODE (x) != CONST_INT
1450 && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
1451 && (INTVAL (x) & 7) != 8)
1452 output_operand_lossage ("invalid %%s value");
1454 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (64 - INTVAL (x)) / 8);
1457 case 'C': case 'D': case 'c': case 'd':
1458 /* Write out comparison name. */
1460 enum rtx_code c = GET_CODE (x);
1462 if (GET_RTX_CLASS (c) != '<')
1463 output_operand_lossage ("invalid %%C value");
1466 c = reverse_condition (c);
1467 else if (code == 'c')
1468 c = swap_condition (c);
1469 else if (code == 'd')
1470 c = swap_condition (reverse_condition (c));
1473 fprintf (file, "ule");
1475 fprintf (file, "ult");
1477 fprintf (file, "%s", GET_RTX_NAME (c));
1482 /* Write the divide or modulus operator. */
1483 switch (GET_CODE (x))
1486 fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q");
1489 fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q");
1492 fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q");
1495 fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q");
1498 output_operand_lossage ("invalid %%E value");
1504 /* Write "_u" for unaligned access. */
1505 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
1506 fprintf (file, "_u");
1510 if (GET_CODE (x) == REG)
1511 fprintf (file, "%s", reg_names[REGNO (x)]);
1512 else if (GET_CODE (x) == MEM)
1513 output_address (XEXP (x, 0));
1515 output_addr_const (file, x);
1519 output_operand_lossage ("invalid %%xn code");
1523 /* Do what is necessary for `va_start'. The argument is ignored;
1524 We look at the current function to determine if stdarg or varargs
1525 is used and fill in an initial va_list. A pointer to this constructor
1529 alpha_builtin_saveregs (arglist)
1532 rtx block, addr, argsize;
1533 tree fntype = TREE_TYPE (current_function_decl);
1534 int stdarg = (TYPE_ARG_TYPES (fntype) != 0
1535 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
1536 != void_type_node));
1538 /* Compute the current position into the args, taking into account
1539 both registers and memory. Both of these are already included in
1540 current_function_args_info. */
1542 argsize = GEN_INT (CURRENT_FUNCTION_ARGS_INFO * UNITS_PER_WORD);
1544 /* For Unix, SETUP_INCOMING_VARARGS moves the starting address base up by 48,
1545 storing fp arg registers in the first 48 bytes, and the integer arg
1546 registers in the next 48 bytes. This is only done, however, if any
1547 integer registers need to be stored.
1549 If no integer registers need be stored, then we must subtract 48 in
1550 order to account for the integer arg registers which are counted in
1551 argsize above, but which are not actually stored on the stack. */
1553 if (TARGET_OPEN_VMS)
1554 addr = plus_constant (virtual_incoming_args_rtx,
1555 CURRENT_FUNCTION_ARGS_INFO <= 5 + stdarg
1556 ? UNITS_PER_WORD : - 6 * UNITS_PER_WORD);
1558 addr = (CURRENT_FUNCTION_ARGS_INFO <= 5 + stdarg
1559 ? plus_constant (virtual_incoming_args_rtx,
1561 : plus_constant (virtual_incoming_args_rtx,
1562 - (6 * UNITS_PER_WORD)));
1564 /* For VMS, we include the argsize, while on Unix, it's handled as
1565 a separate field. */
1566 if (TARGET_OPEN_VMS)
1567 addr = plus_constant (addr, INTVAL (argsize));
1569 addr = force_operand (addr, NULL_RTX);
1571 #ifdef POINTERS_EXTEND_UNSIGNED
1572 addr = convert_memory_address (ptr_mode, addr);
1575 if (TARGET_OPEN_VMS)
1579 /* Allocate the va_list constructor */
1580 block = assign_stack_local (BLKmode, 2 * UNITS_PER_WORD, BITS_PER_WORD);
1581 RTX_UNCHANGING_P (block) = 1;
1582 RTX_UNCHANGING_P (XEXP (block, 0)) = 1;
1584 /* Store the address of the first integer register in the __base
1587 emit_move_insn (change_address (block, ptr_mode, XEXP (block, 0)), addr);
1589 /* Store the argsize as the __va_offset member. */
1591 (change_address (block, TYPE_MODE (integer_type_node),
1592 plus_constant (XEXP (block, 0),
1593 POINTER_SIZE/BITS_PER_UNIT)),
1596 /* Return the address of the va_list constructor, but don't put it in a
1597 register. Doing so would fail when not optimizing and produce worse
1598 code when optimizing. */
1599 return XEXP (block, 0);
1603 /* This page contains routines that are used to determine what the function
1604 prologue and epilogue code will do and write them out. */
1606 /* Compute the size of the save area in the stack. */
1613 /* These variables are used for communication between the following functions.
1614 They indicate various things about the current function being compiled
1615 that are used to tell what kind of prologue, epilogue and procedure
1616 descriptior to generate. */
1618 /* Nonzero if we need a stack procedure. */
1619 static int is_stack_procedure;
1621 /* Register number (either FP or SP) that is used to unwind the frame. */
1622 static int unwind_regno;
1624 /* Register number used to save FP. We need not have one for RA since
1625 we don't modify it for register procedures. This is only defined
1626 for register frame procedures. */
1627 static int save_fp_regno;
1629 /* Register number used to reference objects off our PV. */
1630 static int base_regno;
1632 /* Compute register masks for saved registers. */
1635 alpha_sa_mask (imaskP, fmaskP)
1636 unsigned long *imaskP;
1637 unsigned long *fmaskP;
1639 unsigned long imask = 0;
1640 unsigned long fmask = 0;
1643 if (is_stack_procedure)
1644 imask |= (1L << HARD_FRAME_POINTER_REGNUM);
1646 /* One for every register we have to save. */
1648 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1649 if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i])
1654 fmask |= (1L << (i - 32));
1667 HOST_WIDE_INT stack_needed;
1670 /* One for every register we have to save. */
1672 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1673 if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i])
1676 /* Start by assuming we can use a register procedure if we don't make any
1677 calls (REG_RA not used) or need to save any registers and a stack
1678 procedure if we do. */
1679 is_stack_procedure = regs_ever_live[REG_RA] || sa_size != 0;
1681 /* Decide whether to refer to objects off our PV via FP or PV.
1682 If we need need FP for something else or if we receive a nonlocal
1683 goto (which expects PV to contain the value), we must use PV.
1684 Otherwise, start by assuming we can use FP. */
1685 base_regno = (frame_pointer_needed || current_function_has_nonlocal_label
1686 || is_stack_procedure
1687 || current_function_outgoing_args_size
1688 ? REG_PV : HARD_FRAME_POINTER_REGNUM);
1690 /* If we want to copy PV into FP, we need to find some register in which to
1695 if (base_regno == HARD_FRAME_POINTER_REGNUM)
1696 for (i = 0; i < 32; i++)
1697 if (! fixed_regs[i] && call_used_regs[i] && ! regs_ever_live[i])
1700 if (save_fp_regno == -1)
1701 base_regno = REG_PV, is_stack_procedure = 1;
1703 /* Stack unwinding should be done via FP unless we use it for PV. */
1705 = base_regno == REG_PV ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM;
1707 /* If this is a stack procedure, allow space for saving FP and RA. */
1708 if (is_stack_procedure)
1715 alpha_pv_save_size ()
1718 return is_stack_procedure ? 8 : 0;
1725 return unwind_regno == HARD_FRAME_POINTER_REGNUM;
1728 #else /* ! OPEN_VMS */
1736 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1737 if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i])
1740 /* If some registers were saved but not reg 26, reg 26 must also
1741 be saved, so leave space for it. */
1742 if (size != 0 && ! regs_ever_live[26])
1745 /* Our size must be even (multiple of 16 bytes). */
1752 #endif /* ! OPEN_VMS */
1754 /* Return 1 if this function can directly return via $26. */
1759 return (! TARGET_OPEN_VMS && reload_completed && alpha_sa_size () == 0
1760 && get_frame_size () == 0
1761 && current_function_outgoing_args_size == 0
1762 && current_function_pretend_args_size == 0);
1765 /* Write a version stamp. Don't write anything if we are running as a
1766 cross-compiler. Otherwise, use the versions in /usr/include/stamp.h. */
1768 #if !defined(CROSS_COMPILE) && !defined(_WIN32) && !defined(__linux__) && !defined(VMS)
1773 alpha_write_verstamp (file)
1777 fprintf (file, "\t.verstamp %d %d\n", MS_STAMP, LS_STAMP);
1781 /* Write code to add constant C to register number IN_REG (possibly 31)
1782 and put the result into OUT_REG. Use TEMP_REG as a scratch register;
1783 usually this will be OUT_REG, but should not be if OUT_REG is
1784 STACK_POINTER_REGNUM, since it must be updated in a single instruction.
1785 Write the code to FILE. */
1788 add_long_const (file, c, in_reg, out_reg, temp_reg)
1791 int in_reg, out_reg, temp_reg;
1793 HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
1794 HOST_WIDE_INT tmp1 = c - low;
1795 HOST_WIDE_INT high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
1796 HOST_WIDE_INT extra = 0;
1798 /* We don't have code to write out constants larger than 32 bits. */
1799 #if HOST_BITS_PER_LONG_INT == 64
1800 if ((unsigned HOST_WIDE_INT) c >> 32 != 0)
1804 /* If HIGH will be interpreted as negative, we must adjust it to do two
1805 ldha insns. Note that we will never be building a negative constant
1812 high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
1817 int result_reg = (extra == 0 && high == 0) ? out_reg : temp_reg;
1819 if (low >= 0 && low < 255)
1820 fprintf (file, "\taddq $%d,%d,$%d\n", in_reg, low, result_reg);
1822 fprintf (file, "\tlda $%d,%d($%d)\n", result_reg, low, in_reg);
1824 in_reg = result_reg;
1829 int result_reg = (high == 0) ? out_reg : temp_reg;
1831 fprintf (file, "\tldah $%d,%d($%d)\n", result_reg, extra, in_reg);
1832 in_reg = result_reg;
1836 fprintf (file, "\tldah $%d,%d($%d)\n", out_reg, high, in_reg);
1839 /* Write function prologue. */
1844 Quick and dirty vmskrunch routine to ensure symbols are within the
1845 64 bytes limit imposed by VMS.
1847 This is written specifically for GNAT, and may not work for C++.
1849 This routine duplicates every symbol passed to it whether it is too
1850 long or not, which is a waste of space, fix later.
1858 int max = 60; /* Allow for the ..xx extension */
1864 len = tlen = strlen (name);
1865 foo = xstrdup (name);
1867 /* Don't muck with the ..xx extenstion */
1868 if ((foo [tlen-4] == '.') && (foo [tlen-3] == '.'))
1882 int i, j, slen, nlen, xlen, chopchar;
1886 /* Change all _ and . characters to spaces, if thats enough then quit.
1887 For example: "foobar__foo__bar" becomes "foobar foo bar" */
1889 for (i = 0; bar = index (foo, '_'); i++)
1893 for (i = 0; bar = index (foo, '.'); i++)
1897 for (i = 0; bar = index (foo, '$'); i++)
1901 /* Iteratively make blank the rightmost non-blank character on the
1902 longest leftmost substring delmited by blanks, until it's short
1903 enough. For example: "foobar foo bar" becomes, successively:
1922 /* Find first non-blank */
1924 for (i = j; foo[i]==' ' && foo[i]; i++)
1927 /* Find the first blank */
1930 for (i = j + 1; foo[i] != ' ' && foo[i]; i++)
1933 /* If this substring is the longest so far, remember the
1934 position of the character to chop off. */
1945 /* Try to avoid chopping uppercase suffix letters */
1946 if (isupper (foo [chopchar]))
1949 isupper (foo[i]) && foo[i] != ' ' && i >= 0;
1952 if (islower (foo[i]))
1955 foo [chopchar] = ' ';
1959 /* Put the ..xx extension back */
1966 /* Collapse all the blanks */
1968 for (i = 0; foo[i]; i++)
1976 /* Put back the ..xx extension */
1987 /* On vms we have two kinds of functions:
1989 - stack frame (PROC_STACK)
1990 these are 'normal' functions with local vars and which are
1991 calling other functions
1992 - register frame (PROC_REGISTER)
1993 keeps all data in registers, needs no stack
1995 We must pass this to the assembler so it can generate the
1996 proper pdsc (procedure descriptor)
1997 This is done with the '.pdesc' command.
1999 size is the stack size needed for local variables. */
2002 output_prolog (file, size)
2006 unsigned long imask = 0;
2007 unsigned long fmask = 0;
2008 /* Stack space needed for pushing registers clobbered by us. */
2009 HOST_WIDE_INT sa_size;
2010 /* Complete stack size needed. */
2011 HOST_WIDE_INT frame_size;
2012 /* Offset from base reg to register save area. */
2014 /* Offset during register save. */
2016 /* Label for the procedure entry. */
2017 char entry_label[70];
2020 sa_size = alpha_sa_size ();
2022 = ALPHA_ROUND (sa_size
2023 + (is_stack_procedure ? 8 : 0)
2024 + size + current_function_pretend_args_size);
2026 /* Issue function start and label. */
2027 fprintf (file, "\t.ent ");
2028 assemble_name (file, alpha_function_name);
2029 fprintf (file, "\n");
2030 sprintf (entry_label, "%.64s..en", alpha_function_name);
2031 ASM_OUTPUT_LABEL (file, entry_label);
2032 inside_function = TRUE;
2034 fprintf (file, "\t.base $%d\n", base_regno);
2036 /* Calculate register masks for clobbered registers. */
2038 if (is_stack_procedure)
2039 alpha_sa_mask (&imask, &fmask);
2041 /* Adjust the stack by the frame size. If the frame size is > 4096
2042 bytes, we need to be sure we probe somewhere in the first and last
2043 4096 bytes (we can probably get away without the latter test) and
2044 every 8192 bytes in between. If the frame size is > 32768, we
2045 do this in a loop. Otherwise, we generate the explicit probe
2048 Note that we are only allowed to adjust sp once in the prologue. */
2050 if (frame_size < 32768)
2052 if (frame_size > 4096)
2056 fprintf (file, "\tstq $31,-%d($30)\n", probed);
2058 while (probed + 8192 < frame_size)
2059 fprintf (file, "\tstq $31,-%d($30)\n", probed += 8192);
2061 /* We only have to do this probe if we aren't saving registers. */
2062 if (sa_size == 0 && probed + 4096 < frame_size)
2063 fprintf (file, "\tstq $31,-%d($30)\n", frame_size);
2066 if (frame_size != 0)
2067 fprintf (file, "\tlda $30,-%d($30)\n", frame_size);
2071 /* Here we generate code to set R4 to SP + 4096 and set R23 to the
2072 number of 8192 byte blocks to probe. We then probe each block
2073 in the loop and then set SP to the proper location. If the
2074 amount remaining is > 4096, we have to do one more probe if we
2075 are not saving any registers. */
2077 HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
2078 HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
2080 add_long_const (file, blocks, 31, 23, 23);
2082 fprintf (file, "\tlda $22,4096($30)\n");
2084 assemble_name (file, alpha_function_name);
2085 fprintf (file, "..sc:\n");
2087 fprintf (file, "\tstq $31,-8192($22)\n");
2088 fprintf (file, "\tsubq $23,1,$23\n");
2089 fprintf (file, "\tlda $22,-8192($22)\n");
2091 fprintf (file, "\tbne $23,");
2092 assemble_name (file, alpha_function_name);
2093 fprintf (file, "..sc\n");
2095 if (leftover > 4096 && sa_size == 0)
2096 fprintf (file, "\tstq $31,-%d($22)\n", leftover);
2098 fprintf (file, "\tlda $30,-%d($22)\n", leftover);
2101 if (is_stack_procedure)
2103 int reg_offset = rsa_offset;
2105 /* Store R26 (RA) first. */
2106 fprintf (file, "\tstq $26,%d($30)\n", reg_offset);
2109 /* Store integer regs. according to mask. */
2110 for (i = 0; i < 32; i++)
2111 if (imask & (1L<<i))
2113 fprintf (file, "\tstq $%d,%d($30)\n", i, reg_offset);
2117 /* Print the register mask and do floating-point saves. */
2120 fprintf (file, "\t.mask 0x%x,0\n", imask);
2122 for (i = 0; i < 32; i++)
2124 if (fmask & (1L << i))
2126 fprintf (file, "\tstt $f%d,%d($30)\n", i, reg_offset);
2131 /* Print the floating-point mask, if we've saved any fp register. */
2133 fprintf (file, "\t.fmask 0x%x,0\n", fmask);
2135 fprintf (file, "\tstq $27,0($30)\n");
2139 fprintf (file, "\t.fp_save $%d\n", save_fp_regno);
2140 fprintf (file, "\tbis $%d,$%d,$%d\n", HARD_FRAME_POINTER_REGNUM,
2141 HARD_FRAME_POINTER_REGNUM, save_fp_regno);
2144 if (base_regno != REG_PV)
2145 fprintf (file, "\tbis $%d,$%d,$%d\n", REG_PV, REG_PV, base_regno);
2147 if (unwind_regno == HARD_FRAME_POINTER_REGNUM)
2148 fprintf (file, "\tbis $%d,$%d,$%d\n", STACK_POINTER_REGNUM,
2149 STACK_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM);
2151 /* Describe our frame. */
2152 fprintf (file, "\t.frame $%d,%d,$26,%d\n",
2153 unwind_regno, frame_size, rsa_offset);
2155 /* If we have to allocate space for outgoing args, do it now. */
2156 if (current_function_outgoing_args_size != 0)
2157 fprintf (file, "\tlda $%d,%d($%d)\n", STACK_POINTER_REGNUM,
2158 - ALPHA_ROUND (current_function_outgoing_args_size),
2159 HARD_FRAME_POINTER_REGNUM);
2161 fprintf (file, "\t.prologue\n");
2164 fprintf (file, "\t.align 3\n");
2165 ASM_OUTPUT_LABEL (file, alpha_function_name);
2166 fprintf (file, "\t.pdesc ");
2167 assemble_name (file, alpha_function_name);
2168 fprintf (file, "..en,%s\n", is_stack_procedure ? "stack" : "reg");
2169 alpha_need_linkage (alpha_function_name, 1);
2175 /* Write function epilogue. */
2178 output_epilog (file, size)
2182 unsigned long imask = 0;
2183 unsigned long fmask = 0;
2184 /* Stack space needed for pushing registers clobbered by us. */
2185 HOST_WIDE_INT sa_size = alpha_sa_size ();
2186 /* Complete stack size needed. */
2187 HOST_WIDE_INT frame_size
2188 = ALPHA_ROUND (sa_size
2189 + (is_stack_procedure ? 8 : 0)
2190 + size + current_function_pretend_args_size);
2192 rtx insn = get_last_insn ();
2194 /* If the last insn was a BARRIER, we don't have to write anything except
2195 the .end pseudo-op. */
2197 if (GET_CODE (insn) == NOTE)
2198 insn = prev_nonnote_insn (insn);
2200 if (insn == 0 || GET_CODE (insn) != BARRIER)
2202 /* Restore clobbered registers, load FP last. */
2204 if (is_stack_procedure)
2210 if (unwind_regno == HARD_FRAME_POINTER_REGNUM)
2211 fprintf (file, "\tbis $%d,$%d,$%d\n", HARD_FRAME_POINTER_REGNUM,
2212 HARD_FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM);
2214 alpha_sa_mask (&imask, &fmask);
2216 /* Start reloading registers after RA. */
2217 reg_offset = rsa_offset + 8;
2219 for (i = 0; i < 32; i++)
2220 if (imask & (1L<<i))
2222 if (i == HARD_FRAME_POINTER_REGNUM)
2223 fp_offset = reg_offset;
2225 fprintf (file, "\tldq $%d,%d($30)\n",
2230 for (i = 0; i < 32; i++)
2231 if (fmask & (1L << i))
2233 fprintf (file, "\tldt $f%d,%d($30)\n", i, reg_offset);
2237 /* Restore R26 (RA). */
2238 fprintf (file, "\tldq $26,%d($30)\n", rsa_offset);
2240 /* Restore R29 (FP). */
2241 fprintf (file, "\tldq $29,%d($30)\n", fp_offset);
2244 fprintf (file, "\tbis $%d,$%d,$%d\n", save_fp_regno, save_fp_regno,
2245 HARD_FRAME_POINTER_REGNUM);
2247 if (frame_size != 0)
2249 if (frame_size < 32768)
2250 fprintf (file, "\tlda $30,%d($30)\n", frame_size);
2253 long high = frame_size >> 16;
2254 long low = frame_size & 0xffff;
2258 low = -32768 + (low & 0x7fff);
2260 fprintf (file, "\tldah $2,%ld($31)\n", high);
2261 fprintf (file, "\tlda $2,%ld($2)\n", low);
2262 fprintf (file, "\taddq $30,$2,$30\n");
2266 /* Finally return to the caller. */
2267 fprintf (file, "\tret $31,($26),1\n");
2270 /* End the function. */
2271 fprintf (file, "\t.end ");
2272 assemble_name (file, alpha_function_name);
2273 fprintf (file, "\n");
2274 inside_function = FALSE;
2276 /* Show that we know this function if it is called again. */
2277 SYMBOL_REF_FLAG (XEXP (DECL_RTL (current_function_decl), 0)) = 1;
2280 #else /* !OPEN_VMS */
2283 output_prolog (file, size)
2287 HOST_WIDE_INT out_args_size
2288 = ALPHA_ROUND (current_function_outgoing_args_size);
2289 HOST_WIDE_INT sa_size = alpha_sa_size ();
2290 HOST_WIDE_INT frame_size
2291 = (out_args_size + sa_size
2292 + ALPHA_ROUND (size + current_function_pretend_args_size));
2293 HOST_WIDE_INT reg_offset = out_args_size;
2294 HOST_WIDE_INT start_reg_offset = reg_offset;
2295 HOST_WIDE_INT actual_start_reg_offset = start_reg_offset;
2296 int int_reg_save_area_size = 0;
2298 unsigned reg_mask = 0;
2301 /* Ecoff can handle multiple .file directives, so put out file and lineno.
2302 We have to do that before the .ent directive as we cannot switch
2303 files within procedures with native ecoff because line numbers are
2304 linked to procedure descriptors.
2305 Outputting the lineno helps debugging of one line functions as they
2306 would otherwise get no line number at all. Please note that we would
2307 like to put out last_linenum from final.c, but it is not accessible. */
2309 if (write_symbols == SDB_DEBUG)
2311 ASM_OUTPUT_SOURCE_FILENAME (file,
2312 DECL_SOURCE_FILE (current_function_decl));
2313 if (debug_info_level != DINFO_LEVEL_TERSE)
2314 ASM_OUTPUT_SOURCE_LINE (file,
2315 DECL_SOURCE_LINE (current_function_decl));
2318 /* The assembly language programmer's guide states that the second argument
2319 to the .ent directive, the lex_level, is ignored by the assembler,
2320 so we might as well omit it. */
2322 if (!flag_inhibit_size_directive)
2324 fprintf (file, "\t.ent ");
2325 assemble_name (file, alpha_function_name);
2326 fprintf (file, "\n");
2328 ASM_OUTPUT_LABEL (file, alpha_function_name);
2329 inside_function = TRUE;
2331 if (TARGET_IEEE_CONFORMANT && !flag_inhibit_size_directive)
2332 /* Set flags in procedure descriptor to request IEEE-conformant
2333 math-library routines. The value we set it to is PDSC_EXC_IEEE
2334 (/usr/include/pdsc.h). */
2335 fprintf (file, "\t.eflag 48\n");
2337 /* Set up offsets to alpha virtual arg/local debugging pointer. */
2339 alpha_auto_offset = -frame_size + current_function_pretend_args_size;
2340 alpha_arg_offset = -frame_size + 48;
2342 /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first.
2343 Even if we are a static function, we still need to do this in case
2344 our address is taken and passed to something like qsort.
2346 We never need a GP for Windows/NT. */
2348 alpha_function_needs_gp = 0;
2350 #ifdef TARGET_PROFILING_NEEDS_GP
2352 alpha_function_needs_gp = 1;
2355 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2356 if ((GET_CODE (insn) == CALL_INSN)
2357 || (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2358 && GET_CODE (PATTERN (insn)) != USE
2359 && GET_CODE (PATTERN (insn)) != CLOBBER
2360 && (get_attr_type (insn) == TYPE_LDSYM
2361 || get_attr_type (insn) == TYPE_ISUBR)))
2363 alpha_function_needs_gp = 1;
2367 if (TARGET_WINDOWS_NT == 0)
2369 if (alpha_function_needs_gp)
2370 fprintf (file, "\tldgp $29,0($27)\n");
2372 /* Put a label after the GP load so we can enter the function at it. */
2373 assemble_name (file, alpha_function_name);
2374 fprintf (file, "..ng:\n");
2377 /* Adjust the stack by the frame size. If the frame size is > 4096
2378 bytes, we need to be sure we probe somewhere in the first and last
2379 4096 bytes (we can probably get away without the latter test) and
2380 every 8192 bytes in between. If the frame size is > 32768, we
2381 do this in a loop. Otherwise, we generate the explicit probe
2384 Note that we are only allowed to adjust sp once in the prologue. */
2386 if (frame_size < 32768)
2388 if (frame_size > 4096)
2392 fprintf (file, "\tstq $31,-%d($30)\n", probed);
2394 while (probed + 8192 < frame_size)
2395 fprintf (file, "\tstq $31,-%d($30)\n", probed += 8192);
2397 /* We only have to do this probe if we aren't saving registers. */
2398 if (sa_size == 0 && probed + 4096 < frame_size)
2399 fprintf (file, "\tstq $31,-%d($30)\n", frame_size);
2402 if (frame_size != 0)
2403 fprintf (file, "\tlda $30,-%d($30)\n", frame_size);
2407 /* Here we generate code to set R4 to SP + 4096 and set R5 to the
2408 number of 8192 byte blocks to probe. We then probe each block
2409 in the loop and then set SP to the proper location. If the
2410 amount remaining is > 4096, we have to do one more probe if we
2411 are not saving any registers. */
2413 HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
2414 HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
2416 add_long_const (file, blocks, 31, 5, 5);
2418 fprintf (file, "\tlda $4,4096($30)\n");
2420 assemble_name (file, alpha_function_name);
2421 fprintf (file, "..sc:\n");
2423 fprintf (file, "\tstq $31,-8192($4)\n");
2424 fprintf (file, "\tsubq $5,1,$5\n");
2425 fprintf (file, "\tlda $4,-8192($4)\n");
2427 fprintf (file, "\tbne $5,");
2428 assemble_name (file, alpha_function_name);
2429 fprintf (file, "..sc\n");
2431 if (leftover > 4096 && sa_size == 0)
2432 fprintf (file, "\tstq $31,-%d($4)\n", leftover);
2434 fprintf (file, "\tlda $30,-%d($4)\n", leftover);
2437 /* Describe our frame. */
2438 if (!flag_inhibit_size_directive)
2440 fprintf (file, "\t.frame $%d,%d,$26,%d\n",
2441 (frame_pointer_needed
2442 ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM),
2443 frame_size, current_function_pretend_args_size);
2446 /* Save register 26 if any other register needs to be saved. */
2449 reg_mask |= 1 << 26;
2450 fprintf (file, "\tstq $26,%d($30)\n", reg_offset);
2452 int_reg_save_area_size += 8;
2455 /* Now save any other used integer registers required to be saved. */
2456 for (i = 0; i < 32; i++)
2457 if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i] && i != 26)
2460 fprintf (file, "\tstq $%d,%d($30)\n", i, reg_offset);
2462 int_reg_save_area_size += 8;
2465 /* Print the register mask and do floating-point saves. */
2466 if (reg_mask && !flag_inhibit_size_directive)
2467 fprintf (file, "\t.mask 0x%x,%d\n", reg_mask,
2468 actual_start_reg_offset - frame_size);
2470 start_reg_offset = reg_offset;
2473 for (i = 0; i < 32; i++)
2474 if (! fixed_regs[i + 32] && ! call_used_regs[i + 32]
2475 && regs_ever_live[i + 32])
2478 fprintf (file, "\tstt $f%d,%d($30)\n", i, reg_offset);
2482 /* Print the floating-point mask, if we've saved any fp register. */
2483 if (reg_mask && !flag_inhibit_size_directive)
2484 fprintf (file, "\t.fmask 0x%x,%d\n", reg_mask,
2485 actual_start_reg_offset - frame_size + int_reg_save_area_size);
2487 /* If we need a frame pointer, set it from the stack pointer. Note that
2488 this must always be the last instruction in the prologue. */
2489 if (frame_pointer_needed)
2490 fprintf (file, "\tbis $30,$30,$15\n");
2492 /* End the prologue and say if we used gp. */
2493 if (!flag_inhibit_size_directive)
2494 fprintf (file, "\t.prologue %d\n", alpha_function_needs_gp);
2497 /* Write function epilogue. */
2500 output_epilog (file, size)
2504 rtx insn = get_last_insn ();
2505 HOST_WIDE_INT out_args_size
2506 = ALPHA_ROUND (current_function_outgoing_args_size);
2507 HOST_WIDE_INT sa_size = alpha_sa_size ();
2508 HOST_WIDE_INT frame_size
2509 = (out_args_size + sa_size
2510 + ALPHA_ROUND (size + current_function_pretend_args_size));
2511 HOST_WIDE_INT reg_offset = out_args_size;
2512 HOST_WIDE_INT frame_size_from_reg_save = frame_size - reg_offset;
2514 = frame_pointer_needed && regs_ever_live[HARD_FRAME_POINTER_REGNUM];
2517 /* If the last insn was a BARRIER, we don't have to write anything except
2518 the .end pseudo-op. */
2519 if (GET_CODE (insn) == NOTE)
2520 insn = prev_nonnote_insn (insn);
2521 if (insn == 0 || GET_CODE (insn) != BARRIER)
2525 final_prescan_insn (NULL_RTX, NULL_PTR, 0);
2527 /* If we have a frame pointer, restore SP from it. */
2528 if (frame_pointer_needed)
2529 fprintf (file, "\tbis $15,$15,$30\n");
2531 /* Restore all the registers, starting with the return address
2535 fprintf (file, "\tldq $26,%d($30)\n", reg_offset);
2539 /* Now restore any other used integer registers that that we saved,
2540 except for FP if it is being used as FP, since it must be
2543 for (i = 0; i < 32; i++)
2544 if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i]
2547 if (i == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
2548 fp_offset = reg_offset;
2550 fprintf (file, "\tldq $%d,%d($30)\n", i, reg_offset);
2554 for (i = 0; i < 32; i++)
2555 if (! fixed_regs[i + 32] && ! call_used_regs[i + 32]
2556 && regs_ever_live[i + 32])
2558 fprintf (file, "\tldt $f%d,%d($30)\n", i, reg_offset);
2562 /* If the stack size is large and we have a frame pointer, compute the
2563 size of the stack into a register because the old FP restore, stack
2564 pointer adjust, and return are required to be consecutive
2566 if (frame_size > 32767 && restore_fp)
2567 add_long_const (file, frame_size, 31, 1, 1);
2569 /* If we needed a frame pointer and we have to restore it, do it
2570 now. This must be done in one instruction immediately
2571 before the SP update. */
2572 if (restore_fp && fp_offset)
2573 fprintf (file, "\tldq $15,%d($30)\n", fp_offset);
2575 /* Now update the stack pointer, if needed. Only one instruction must
2576 modify the stack pointer. It must be the last instruction in the
2577 sequence and must be an ADDQ or LDA instruction. If the frame
2578 pointer was loaded above, we may only put one instruction here. */
2580 if (frame_size > 32768 && restore_fp)
2581 fprintf (file, "\taddq $1,$30,$30\n");
2583 add_long_const (file, frame_size, 30, 30, 1);
2585 /* Finally return to the caller. */
2586 fprintf (file, "\tret $31,($26),1\n");
2589 /* End the function. */
2590 if (!flag_inhibit_size_directive)
2592 fprintf (file, "\t.end ");
2593 assemble_name (file, alpha_function_name);
2594 fprintf (file, "\n");
2596 inside_function = FALSE;
2598 /* Show that we know this function if it is called again. */
2599 SYMBOL_REF_FLAG (XEXP (DECL_RTL (current_function_decl), 0)) = 1;
2601 #endif /* !OPEN_VMS */
2603 /* Debugging support. */
2607 /* Count the number of sdb related labels are generated (to find block
2608 start and end boundaries). */
2610 int sdb_label_count = 0;
2612 /* Next label # for each statement. */
2614 static int sym_lineno = 0;
2616 /* Count the number of .file directives, so that .loc is up to date. */
2618 static int num_source_filenames = 0;
2620 /* Name of the file containing the current function. */
2622 static char *current_function_file = "";
2624 /* Offsets to alpha virtual arg/local debugging pointers. */
2626 long alpha_arg_offset;
2627 long alpha_auto_offset;
2629 /* Emit a new filename to a stream. */
2632 alpha_output_filename (stream, name)
2636 static int first_time = TRUE;
2637 char ltext_label_name[100];
2642 ++num_source_filenames;
2643 current_function_file = name;
2644 fprintf (stream, "\t.file\t%d ", num_source_filenames);
2645 output_quoted_string (stream, name);
2646 fprintf (stream, "\n");
2647 if (!TARGET_GAS && write_symbols == DBX_DEBUG)
2648 fprintf (stream, "\t#@stabs\n");
2651 else if (write_symbols == DBX_DEBUG)
2653 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
2654 fprintf (stream, "%s ", ASM_STABS_OP);
2655 output_quoted_string (stream, name);
2656 fprintf (stream, ",%d,0,0,%s\n", N_SOL, <ext_label_name[1]);
2659 else if (name != current_function_file
2660 && strcmp (name, current_function_file) != 0)
2662 if (inside_function && ! TARGET_GAS)
2663 fprintf (stream, "\t#.file\t%d ", num_source_filenames);
2666 ++num_source_filenames;
2667 current_function_file = name;
2668 fprintf (stream, "\t.file\t%d ", num_source_filenames);
2671 output_quoted_string (stream, name);
2672 fprintf (stream, "\n");
2676 /* Emit a linenumber to a stream. */
2679 alpha_output_lineno (stream, line)
2683 if (write_symbols == DBX_DEBUG)
2685 /* mips-tfile doesn't understand .stabd directives. */
2687 fprintf (stream, "$LM%d:\n\t%s %d,0,%d,$LM%d\n",
2688 sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno);
2691 fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line);
2694 /* Structure to show the current status of registers and memory. */
2696 struct shadow_summary
2699 unsigned long i : 32; /* Mask of int regs */
2700 unsigned long fp : 32; /* Mask of fp regs */
2701 unsigned long mem : 1; /* mem == imem | fpmem */
2705 /* Summary the effects of expression X on the machine. Update SUM, a pointer
2706 to the summary structure. SET is nonzero if the insn is setting the
2707 object, otherwise zero. */
2710 summarize_insn (x, sum, set)
2712 struct shadow_summary *sum;
2721 switch (GET_CODE (x))
2723 /* ??? Note that this case would be incorrect if the Alpha had a
2724 ZERO_EXTRACT in SET_DEST. */
2726 summarize_insn (SET_SRC (x), sum, 0);
2727 summarize_insn (SET_DEST (x), sum, 1);
2731 summarize_insn (XEXP (x, 0), sum, 1);
2735 summarize_insn (XEXP (x, 0), sum, 0);
2739 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
2740 summarize_insn (XVECEXP (x, 0, i), sum, 0);
2745 int regno = REGNO (x);
2746 unsigned long mask = 1UL << (regno % 32);
2748 if (regno == 31 || regno == 63)
2754 sum->defd.i |= mask;
2756 sum->defd.fp |= mask;
2761 sum->used.i |= mask;
2763 sum->used.fp |= mask;
2774 /* Find the regs used in memory address computation: */
2775 summarize_insn (XEXP (x, 0), sum, 0);
2779 summarize_insn (SUBREG_REG (x), sum, 0);
2782 case CONST_INT: case CONST_DOUBLE:
2783 case SYMBOL_REF: case LABEL_REF: case CONST:
2786 /* Handle common unary and binary ops for efficiency. */
2787 case COMPARE: case PLUS: case MINUS: case MULT: case DIV:
2788 case MOD: case UDIV: case UMOD: case AND: case IOR:
2789 case XOR: case ASHIFT: case ROTATE: case ASHIFTRT: case LSHIFTRT:
2790 case ROTATERT: case SMIN: case SMAX: case UMIN: case UMAX:
2791 case NE: case EQ: case GE: case GT: case LE:
2792 case LT: case GEU: case GTU: case LEU: case LTU:
2793 summarize_insn (XEXP (x, 0), sum, 0);
2794 summarize_insn (XEXP (x, 1), sum, 0);
2797 case NEG: case NOT: case SIGN_EXTEND: case ZERO_EXTEND:
2798 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: case FLOAT:
2799 case FIX: case UNSIGNED_FLOAT: case UNSIGNED_FIX: case ABS:
2800 case SQRT: case FFS:
2801 summarize_insn (XEXP (x, 0), sum, 0);
2805 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
2806 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2807 switch (format_ptr[i])
2810 summarize_insn (XEXP (x, i), sum, 0);
2814 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2815 summarize_insn (XVECEXP (x, i, j), sum, 0);
2824 /* This function is executed just prior to the output of assembler code for
2825 INSN to modify the extracted operands so they will be output differently.
2827 OPVEC is the vector containing the operands extracted from INSN, and
2828 NOPERANDS is the number of elements of the vector which contain meaningful
2829 data for this insn. The contents of this vector are what will be used to
2830 convert the insn template into assembler code, so you can change the
2831 assembler output by changing the contents of the vector.
2833 We use this function to ensure a sufficient number of `trapb' instructions
2834 are in the code when the user requests code with a trap precision of
2835 functions or instructions.
2837 In naive mode, when the user requests a trap-precision of "instruction", a
2838 trapb is needed after every instruction that may generate a trap (and after
2839 jsr/bsr instructions, because called functions may import a trap from the
2840 caller). This ensures that the code is resumption safe but it is also slow.
2842 When optimizations are turned on, we delay issuing a trapb as long as
2843 possible. In this context, a trap shadow is the sequence of instructions
2844 that starts with a (potentially) trap generating instruction and extends to
2845 the next trapb or call_pal instruction (but GCC never generates call_pal by
2846 itself). We can delay (and therefore sometimes omit) a trapb subject to the
2847 following conditions:
2849 (a) On entry to the trap shadow, if any Alpha register or memory location
2850 contains a value that is used as an operand value by some instruction in
2851 the trap shadow (live on entry), then no instruction in the trap shadow
2852 may modify the register or memory location.
2854 (b) Within the trap shadow, the computation of the base register for a
2855 memory load or store instruction may not involve using the result
2856 of an instruction that might generate an UNPREDICTABLE result.
2858 (c) Within the trap shadow, no register may be used more than once as a
2859 destination register. (This is to make life easier for the trap-handler.)
2861 (d) The trap shadow may not include any branch instructions.
2866 final_prescan_insn (insn, opvec, noperands)
2871 static struct shadow_summary shadow = {0, 0, 0, 0, 0};
2873 #define CLOSE_SHADOW \
2876 fputs ("\ttrapb\n", asm_out_file); \
2878 bzero ((char *) &shadow, sizeof shadow); \
2882 if (alpha_tp == ALPHA_TP_PROG)
2889 /* Generate one trapb before epilogue (indicated by INSN==0) */
2895 if (optimize && insn != 0)
2897 struct shadow_summary sum = {0, 0, 0};
2899 switch (GET_CODE(insn))
2902 summarize_insn (PATTERN (insn), &sum, 0);
2904 if ((sum.defd.i & shadow.defd.i)
2905 || (sum.defd.fp & shadow.defd.fp))
2907 /* (c) would be violated */
2912 /* Combine shadow with summary of current insn: */
2913 shadow.used.i |= sum.used.i;
2914 shadow.used.fp |= sum.used.fp;
2915 shadow.used.mem |= sum.used.mem;
2916 shadow.defd.i |= sum.defd.i;
2917 shadow.defd.fp |= sum.defd.fp;
2918 shadow.defd.mem |= sum.defd.mem;
2920 if ((sum.defd.i & shadow.used.i)
2921 || (sum.defd.fp & shadow.used.fp)
2922 || (sum.defd.mem & shadow.used.mem))
2924 /* (a) would be violated (also takes care of (b)). */
2925 if (get_attr_trap (insn) == TRAP_YES
2926 && ((sum.defd.i & sum.used.i)
2927 || (sum.defd.fp & sum.used.fp)))
2950 if (insn != 0 && get_attr_trap (insn) == TRAP_YES)
2952 if (optimize && !trap_pending && GET_CODE (insn) == INSN)
2953 summarize_insn (PATTERN (insn), &shadow, 0);
2958 /* Check a floating-point value for validity for a particular machine mode. */
2960 static char *float_strings[] =
2962 "1.70141173319264430e+38", /* 2^127 (2^24 - 1) / 2^24 */
2963 "-1.70141173319264430e+38",
2964 "2.93873587705571877e-39", /* 2^-128 */
2965 "-2.93873587705571877e-39"
2968 static REAL_VALUE_TYPE float_values[4];
2969 static int inited_float_values = 0;
2972 check_float_value (mode, d, overflow)
2973 enum machine_mode mode;
2978 if (TARGET_IEEE || TARGET_IEEE_CONFORMANT || TARGET_IEEE_WITH_INEXACT)
2981 if (TARGET_FLOAT_VAX)
2984 if (inited_float_values == 0)
2987 for (i = 0; i < 4; i++)
2988 float_values[i] = REAL_VALUE_ATOF (float_strings[i], DFmode);
2990 inited_float_values = 1;
2997 bcopy ((char *) d, (char *) &r, sizeof (REAL_VALUE_TYPE));
2998 if (REAL_VALUES_LESS (float_values[0], r))
3000 bcopy ((char *) &float_values[0], (char *) d,
3001 sizeof (REAL_VALUE_TYPE));
3004 else if (REAL_VALUES_LESS (r, float_values[1]))
3006 bcopy ((char *) &float_values[1], (char *) d,
3007 sizeof (REAL_VALUE_TYPE));
3010 else if (REAL_VALUES_LESS (dconst0, r)
3011 && REAL_VALUES_LESS (r, float_values[2]))
3013 bcopy ((char *) &dconst0, (char *) d, sizeof (REAL_VALUE_TYPE));
3016 else if (REAL_VALUES_LESS (r, dconst0)
3017 && REAL_VALUES_LESS (float_values[3], r))
3019 bcopy ((char *) &dconst0, (char *) d, sizeof (REAL_VALUE_TYPE));
3030 function_arg (cum, mode, type, named)
3031 CUMULATIVE_ARGS *cum;
3032 enum machine_mode mode;
3038 if (mode == VOIDmode) /* final call, return argument information */
3040 return GEN_INT (*cum);
3048 *cum |= (((TARGET_FLOAT_VAX)?1:4) << ((arg * 3)+8)); /* 4 = AI$K_AR_FS, IEEE single */
3051 *cum |= (((TARGET_FLOAT_VAX)?3:5) << ((arg * 3)+8)); /* 5 = AI$K_AR_FT, IEEE double */
3054 *cum |= (7 << ((arg * 3)+8)); /* 5 = AI$K_AR_FT, IEEE double */
3060 return (arg < 6 && ! MUST_PASS_IN_STACK (mode, type)
3061 ? gen_rtx(REG, mode,
3062 (*cum & 0xff) + 16 + ((TARGET_FPREGS
3063 && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3064 || GET_MODE_CLASS (mode) == MODE_FLOAT))
3069 /* Structure to collect function names for final output
3072 enum links_kind {KIND_UNUSED, KIND_LOCAL, KIND_EXTERN};
3075 struct alpha_links {
3076 struct alpha_links *next;
3078 enum links_kind kind;
3081 static struct alpha_links *alpha_links_base = 0;
3083 /* Make (or fake) .linkage entry for function call.
3085 IS_LOCAL is 0 if name is used in call, 1 if name is used in definition. */
3088 alpha_need_linkage (name, is_local)
3093 struct alpha_links *lptr, *nptr;
3098 /* Is this name already defined ? */
3100 for (lptr = alpha_links_base; lptr; lptr = lptr->next)
3101 if (strcmp (lptr->name, name) == 0)
3105 /* Defined here but external assumed. */
3106 if (lptr->kind == KIND_EXTERN)
3107 lptr->kind = KIND_LOCAL;
3111 /* Used here but unused assumed. */
3112 if (lptr->kind == KIND_UNUSED)
3113 lptr->kind = KIND_LOCAL;
3118 nptr = (struct alpha_links *) xmalloc (sizeof (struct alpha_links));
3119 nptr->next = alpha_links_base;
3120 nptr->name = xstrdup (name);
3122 /* Assume external if no definition. */
3123 nptr->kind = (is_local ? KIND_UNUSED : KIND_EXTERN);
3125 /* Ensure we have an IDENTIFIER so assemble_name can mark is used. */
3126 get_identifier (name);
3128 alpha_links_base = nptr;
3135 alpha_write_linkage (stream)
3138 struct alpha_links *lptr, *nptr;
3140 readonly_section ();
3142 fprintf (stream, "\t.align 3\n");
3144 for (lptr = alpha_links_base; lptr; lptr = nptr)
3148 if (lptr->kind == KIND_UNUSED
3149 || ! TREE_SYMBOL_REFERENCED (get_identifier (lptr->name)))
3152 fprintf (stream, "%s..lk:\n", lptr->name);
3153 if (lptr->kind == KIND_LOCAL)
3155 /* Local and used, build linkage pair. */
3156 fprintf (stream, "\t.quad %s..en\n", lptr->name);
3157 fprintf (stream, "\t.quad %s\n", lptr->name);
3160 /* External and used, request linkage pair. */
3161 fprintf (stream, "\t.linkage %s\n", lptr->name);
3168 alpha_need_linkage (name, is_local)
3174 #endif /* OPEN_VMS */