OSDN Git Service

* alpha.c (alpha_write_verstamp): Only emit MS_STAMP and LS_STAMP,
[pf3gnuchains/gcc-fork.git] / gcc / config / alpha / alpha.c
index ca027ec..b5a42b7 100644 (file)
@@ -1,6 +1,6 @@
 /* Subroutines used for code generation on the DEC Alpha.
-   Copyright (C) 1992 Free Software Foundation, Inc.
-   Contributed by Richard Kenner (kenner@nyu.edu)
+   Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+   Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
 
 This file is part of GNU CC.
 
@@ -16,7 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
 #include <stdio.h>
@@ -48,9 +49,21 @@ int alpha_compare_fp_p;
 
 char *alpha_function_name;
 
+/* Non-zero if inside of a function, because the Alpha asm can't
+   handle .files inside of functions.  */
+
+static int inside_function = FALSE;
+
 /* Nonzero if the current function needs gp.  */
 
 int alpha_function_needs_gp;
+
+extern char *version_string;
+extern int rtx_equal_function_value_matters;
+
+/* Declarations of static functions.  */
+static void alpha_set_memflags_1  PROTO((rtx, int, int, int));
+static void add_long_const     PROTO((FILE *, HOST_WIDE_INT, int, int, int));
 \f
 /* Returns 1 if VALUE is a mask that contains full bytes of zero or ones.  */
 
@@ -79,6 +92,20 @@ reg_or_0_operand (op, mode)
   return op == const0_rtx || register_operand (op, mode);
 }
 
+/* Return 1 if OP is a constant in the range of 0-63 (for a shift) or
+   any register.  */
+
+int
+reg_or_6bit_operand (op, mode)
+     register rtx op;
+     enum machine_mode mode;
+{
+  return ((GET_CODE (op) == CONST_INT
+          && (unsigned HOST_WIDE_INT) INTVAL (op) < 64)
+         || register_operand (op, mode));
+}
+
+
 /* Return 1 if OP is an 8-bit constant or any register.  */
 
 int
@@ -91,6 +118,17 @@ reg_or_8bit_operand (op, mode)
          || register_operand (op, mode));
 }
 
+/* Return 1 if OP is an 8-bit constant.  */
+
+int
+cint8_operand (op, mode)
+     register rtx op;
+     enum machine_mode mode;
+{
+  return (GET_CODE (op) == CONST_INT
+         && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100);
+}
+
 /* Return 1 if the operand is a valid second operand to an add insn.  */
 
 int
@@ -99,10 +137,9 @@ add_operand (op, mode)
      enum machine_mode mode;
 {
   if (GET_CODE (op) == CONST_INT)
-    return ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) < 0x10000
-           || ((INTVAL (op) & 0xffff) == 0
-               && (INTVAL (op) >> 31 == -1
-                   || INTVAL (op) >> 31 == 0)));
+    return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')
+           || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')
+           || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O'));
 
   return register_operand (op, mode);
 }
@@ -152,6 +189,20 @@ and_operand (op, mode)
   return register_operand (op, mode);
 }
 
+/* Return 1 if OP is a valid first operand to an IOR or XOR insn.  */
+
+int
+or_operand (op, mode)
+     register rtx op;
+     enum machine_mode mode;
+{
+  if (GET_CODE (op) == CONST_INT)
+    return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
+           || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100);
+
+  return register_operand (op, mode);
+}
+
 /* Return 1 if OP is a constant that is the width, in bits, of an integral
    mode smaller than DImode.  */
 
@@ -177,13 +228,13 @@ mode_mask_operand (op, mode)
     return CONST_DOUBLE_HIGH (op) == 0 && CONST_DOUBLE_LOW (op) == -1;
 #endif
 
-  if (GET_CODE (op) == CONST_INT)
-    return (INTVAL (op) == 0xff
-           || INTVAL (op) == 0xffff
+  return (GET_CODE (op) == CONST_INT
+         && (INTVAL (op) == 0xff
+             || INTVAL (op) == 0xffff
 #if HOST_BITS_PER_WIDE_INT == 64
-           || INTVAL (op) == 0xffffffff
+             || INTVAL (op) == 0xffffffff
 #endif
-           );
+             ));
 }
 
 /* Return 1 if OP is a multiple of 8 less than 64.  */
@@ -230,6 +281,30 @@ reg_or_cint_operand (op, mode)
      return GET_CODE (op) == CONST_INT || register_operand (op, mode);
 }
 
+/* Return 1 if OP is something that can be reloaded into a register;
+   if it is a MEM, it need not be valid.  */
+
+int
+some_operand (op, mode)
+     register rtx op;
+     enum machine_mode mode;
+{
+  if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
+    return 0;
+
+  switch (GET_CODE (op))
+    {
+    case REG:  case MEM:  case CONST_DOUBLE:
+    case CONST_INT:  case LABEL_REF:  case SYMBOL_REF:  case CONST:
+      return 1;
+
+    case SUBREG:
+      return some_operand (SUBREG_REG (op), VOIDmode);
+    }
+
+  return 0;
+}
+
 /* Return 1 if OP is a valid operand for the source of a move insn.  */
 
 int
@@ -248,7 +323,8 @@ input_operand (op, mode)
     case LABEL_REF:
     case SYMBOL_REF:
     case CONST:
-      return mode == DImode;
+        /* This handles both the Windows/NT and OSF cases.  */
+      return mode == ptr_mode || mode == DImode;
 
     case REG:
       return 1;
@@ -270,15 +346,31 @@ input_operand (op, mode)
   return 0;
 }
 
-/* Return 1 if OP is a SYMBOL_REF for the current function.  */
+/* Return 1 if OP is a SYMBOL_REF for a function known to be in this
+   file.  */
 
 int
-current_function_operand (op, mode)
+current_file_function_operand (op, mode)
      rtx op;
      enum machine_mode mode;
 {
   return (GET_CODE (op) == SYMBOL_REF
-         && ! strcmp (XSTR (op, 0), current_function_name));
+         && ! profile_flag && ! profile_block_flag
+         && (SYMBOL_REF_FLAG (op)
+             || op == XEXP (DECL_RTL (current_function_decl), 0)));
+}
+
+/* Return 1 if OP is a valid operand for the MEM of a CALL insn.  */
+
+int
+call_operand (op, mode)
+     rtx op;
+     enum machine_mode mode;
+{
+  if (mode != Pmode)
+    return 0;
+
+  return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
 }
 
 /* Return 1 if OP is a valid Alpha comparison operator.  Here we know which
@@ -367,9 +459,7 @@ aligned_memory_operand (op, mode)
     op = XEXP (op, 0);
 
   return (GET_CODE (op) == REG
-         && (REGNO (op) == STACK_POINTER_REGNUM || op == frame_pointer_rtx
-             || (REGNO (op) >= FIRST_VIRTUAL_REGISTER
-                 && REGNO (op) <= LAST_VIRTUAL_REGISTER)));
+         && REGNO_POINTER_ALIGN (REGNO (op)) >= 4);
 }
 
 /* Similar, but return 1 if OP is a MEM which is not alignable.  */
@@ -403,9 +493,17 @@ unaligned_memory_operand (op, mode)
     op = XEXP (op, 0);
 
   return (GET_CODE (op) != REG
-         || (REGNO (op) != STACK_POINTER_REGNUM && op != frame_pointer_rtx
-             && (REGNO (op) < FIRST_VIRTUAL_REGISTER
-                 || REGNO (op) > LAST_VIRTUAL_REGISTER)));
+         || REGNO_POINTER_ALIGN (REGNO (op)) < 4);
+}
+
+/* Return 1 if OP is either a register or an unaligned memory location.  */
+
+int
+reg_or_unaligned_mem_operand (op, mode)
+     rtx op;
+     enum machine_mode mode;
+{
+  return register_operand (op, mode) || unaligned_memory_operand (op, mode);
 }
 
 /* Return 1 if OP is any memory location.  During reload a pseudo matches.  */
@@ -466,11 +564,13 @@ get_aligned_mem (ref, paligned_mem, pbitnum)
   *pbitnum = GEN_INT ((offset & 3) * 8);
 }
 
-/* Similar, but just get the address.  Handle the two reload cases.  */
+/* Similar, but just get the address.  Handle the two reload cases.  
+   Add EXTRA_OFFSET to the address we return.  */
 
 rtx
-get_unaligned_address (ref)
+get_unaligned_address (ref, extra_offset)
      rtx ref;
+     int extra_offset;
 {
   rtx base;
   HOST_WIDE_INT offset = 0;
@@ -496,7 +596,7 @@ get_unaligned_address (ref)
   if (GET_CODE (base) == PLUS)
     offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
 
-  return plus_constant (base, offset);
+  return plus_constant (base, offset + extra_offset);
 }
 \f
 /* Subfunction of the following function.  Update the flags of any MEM
@@ -563,43 +663,54 @@ alpha_set_memflags (insn, ref)
 }
 \f
 /* Try to output insns to set TARGET equal to the constant C if it can be
-   done in less than N insns.  Returns 1 if it can be done and the
-   insns have been emitted.  If it would take more than N insns, zero is
-   returned and no insns and emitted.  */
+   done in less than N insns.  Do all computations in MODE.  Returns the place
+   where the output has been placed if it can be done and the insns have been
+   emitted.  If it would take more than N insns, zero is returned and no
+   insns and emitted.  */
 
-int
-alpha_emit_set_const (target, c, n)
+rtx
+alpha_emit_set_const (target, mode, c, n)
      rtx target;
+     enum machine_mode mode;
      HOST_WIDE_INT c;
      int n;
 {
   HOST_WIDE_INT new = c;
   int i, bits;
+  /* Use a pseudo if highly optimizing and still generating RTL.  */
+  rtx subtarget
+    = (flag_expensive_optimizations && rtx_equal_function_value_matters
+       ? 0 : target);
+  rtx temp;
 
 #if HOST_BITS_PER_WIDE_INT == 64
   /* We are only called for SImode and DImode.  If this is SImode, ensure that
      we are sign extended to a full word.  This does not make any sense when
      cross-compiling on a narrow machine.  */
 
-  if (GET_MODE (target) == SImode)
+  if (mode == SImode)
     c = (c & 0xffffffff) - 2 * (c & 0x80000000);
 #endif
 
   /* If this is a sign-extended 32-bit constant, we can do this in at most
      three insns, so do it if we have enough insns left.  We always have
-     a sign-extended 32-bit constant when compiling on a narrow machine.  */
+     a sign-extended 32-bit constant when compiling on a narrow machine. 
+     Note that we cannot handle the constant 0x80000000.  */
 
-  if (HOST_BITS_PER_WIDE_INT != 64
-      || c >> 31 == -1 || c >> 31 == 0)
+  if ((HOST_BITS_PER_WIDE_INT != 64
+       || c >> 31 == -1 || c >> 31 == 0)
+      && c != 0x80000000U)
     {
       HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
       HOST_WIDE_INT tmp1 = c - low;
       HOST_WIDE_INT high
        = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
-      HOST_WIDE_INT tmp2 = c - (high << 16) - low;
       HOST_WIDE_INT extra = 0;
 
-      if (tmp2)
+      /* If HIGH will be interpreted as negative but the constant is
+        positive, we must adjust it to do two ldha insns.  */
+
+      if ((high & 0x8000) != 0 && c >= 0)
        {
          extra = 0x4000;
          tmp1 -= 0x40000000;
@@ -607,30 +718,35 @@ alpha_emit_set_const (target, c, n)
        }
 
       if (c == low || (low == 0 && extra == 0))
+       return copy_to_suggested_reg (GEN_INT (c), target, mode);
+      else if (n >= 2 + (extra != 0)
+              /* We can't do this when SImode if HIGH required adjustment.
+                 This is because the code relies on an implicit overflow
+                 which is invisible to the RTL.  We can thus get incorrect
+                 code if the two ldah instructions are combined.  */
+              && ! (mode == SImode && extra != 0))
        {
-         emit_move_insn (target, GEN_INT (c));
-         return 1;
-       }
-      else if (n >= 2 + (extra != 0))
-       {
-         emit_move_insn (target, GEN_INT (low));
+         temp = copy_to_suggested_reg (GEN_INT (low), subtarget, mode);
+
          if (extra != 0)
-           emit_insn (gen_add2_insn (target, GEN_INT (extra << 16)));
+           temp = expand_binop (mode, add_optab, temp, GEN_INT (extra << 16),
+                                subtarget, 0, OPTAB_WIDEN);
 
-         emit_insn (gen_add2_insn (target, GEN_INT (high << 16)));
-         return 1;
+         return expand_binop (mode, add_optab, temp, GEN_INT (high << 16),
+                              target, 0, OPTAB_WIDEN);
        }
     }
 
-  /* If we couldn't do it that way, try some other methods (that depend on
-     being able to compute in the target's word size).  But if we have no
-     instructions left, don't bother.  Also, don't even try if this is 
-     SImode (in which case we should have already done something, but
-     do a sanity check here).  */
+  /* If we couldn't do it that way, try some other methods.  But if we have
+     no instructions left, don't bother.  Likewise, if this is SImode and
+     we can't make pseudos, we can't do anything since the expand_binop
+     and expand_unop calls will widen and try to make pseudos.  */
 
-  if (n == 1 || HOST_BITS_PER_WIDE_INT < 64 || GET_MODE (target) != DImode)
+  if (n == 1
+      || (mode == SImode && ! rtx_equal_function_value_matters))
     return 0;
 
+#if HOST_BITS_PER_WIDE_INT == 64
   /* First, see if can load a value into the target that is the same as the
      constant except that all bytes that are 0 are changed to be 0xff.  If we
      can, then we can do a ZAPNOT to obtain the desired constant.  */
@@ -639,26 +755,29 @@ alpha_emit_set_const (target, c, n)
     if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0)
       new |= (HOST_WIDE_INT) 0xff << i;
 
-  if (alpha_emit_set_const (target, new, n - 1))
-    {
-      emit_insn (gen_anddi3 (target, target, GEN_INT (c | ~ new)));
-      return 1;
-    }
+  /* We are only called for SImode and DImode.  If this is SImode, ensure that
+     we are sign extended to a full word.  */
+
+  if (mode == SImode)
+    new = (new & 0xffffffff) - 2 * (new & 0x80000000);
+
+  if (new != c
+      && (temp = alpha_emit_set_const (subtarget, mode, new, n - 1)) != 0)
+    return expand_binop (mode, and_optab, temp, GEN_INT (c | ~ new),
+                        target, 0, OPTAB_WIDEN);
+#endif
 
-  /* Find, see if we can load a related constant and then shift and possibly
+  /* Next, see if we can load a related constant and then shift and possibly
      negate it to get the constant we want.  Try this once each increasing
      numbers of insns.  */
 
   for (i = 1; i < n; i++)
     {
       /* First try complementing.  */
-      if (alpha_emit_set_const (target, ~ c, i))
-       {
-         emit_insn (gen_one_cmpldi2 (target, target));
-         return 1;
-       }
+      if ((temp = alpha_emit_set_const (subtarget, mode, ~ c, i)) != 0)
+       return expand_unop (mode, one_cmpl_optab, temp, target, 0);
 
-      /* First try to form a constant and do a left shift.  We can do this
+      /* Next try to form a constant and do a left shift.  We can do this
         if some low-order bits are zero; the exact_log2 call below tells
         us that information.  The bits we are shifting out could be any
         value, but here we'll just try the 0- and sign-extended forms of
@@ -669,44 +788,49 @@ alpha_emit_set_const (target, c, n)
 
       if ((bits = exact_log2 (c & - c)) > 0)
        for (; bits > 0; bits--)
-         if (alpha_emit_set_const (target, c >> bits, i)
-             || alpha_emit_set_const (target,
-                                      ((unsigned HOST_WIDE_INT) c) >> bits,
-                                      i))
-           {
-             emit_insn (gen_ashldi3 (target, target, GEN_INT (bits)));
-             return 1;
-           }
+         if ((temp = (alpha_emit_set_const
+                      (subtarget, mode,
+                       (unsigned HOST_WIDE_INT) c >> bits, i))) != 0
+             || ((temp = (alpha_emit_set_const
+                         (subtarget, mode,
+                          ((unsigned HOST_WIDE_INT) c) >> bits, i)))
+                 != 0))
+           return expand_binop (mode, ashl_optab, temp, GEN_INT (bits),
+                                target, 0, OPTAB_WIDEN);
 
       /* Now try high-order zero bits.  Here we try the shifted-in bits as
-        all zero and all ones.  */
+        all zero and all ones.  Be careful to avoid shifting outside the
+        mode and to avoid shifting outside the host wide int size.  */
 
-      if ((bits = HOST_BITS_PER_WIDE_INT - floor_log2 (c) - 1) > 0)
+      if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
+                  - floor_log2 (c) - 1)) > 0)
        for (; bits > 0; bits--)
-         if (alpha_emit_set_const (target, c << bits, i)
-             || alpha_emit_set_const (target,
-                                      ((c << bits)
-                                       | (((HOST_WIDE_INT) 1 << bits) - 1)),
-                                      i))
-           {
-             emit_insn (gen_lshrdi3 (target, target, GEN_INT (bits)));
-             return 1;
-           }
+         if ((temp = alpha_emit_set_const (subtarget, mode,
+                                           c << bits, i)) != 0
+             || ((temp = (alpha_emit_set_const
+                          (subtarget, mode,
+                           ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
+                           i)))
+                 != 0))
+           return expand_binop (mode, lshr_optab, temp, GEN_INT (bits),
+                                target, 1, OPTAB_WIDEN);
 
       /* Now try high-order 1 bits.  We get that with a sign-extension.
-        But one bit isn't enough here.  */
+        But one bit isn't enough here.  Be careful to avoid shifting outside
+        the mode and to avoid shifting outside the host wide int size. */
       
-      if ((bits = HOST_BITS_PER_WIDE_INT - floor_log2 (~ c) - 2) > 0)
+      if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
+                  - floor_log2 (~ c) - 2)) > 0)
        for (; bits > 0; bits--)
-         if (alpha_emit_set_const (target, c << bits, i)
-             || alpha_emit_set_const (target,
-                                      ((c << bits)
-                                       | (((HOST_WIDE_INT) 1 << bits) - 1)),
-                                      i))
-           {
-             emit_insn (gen_ashrdi3 (target, target, GEN_INT (bits)));
-             return 1;
-           }
+         if ((temp = alpha_emit_set_const (subtarget, mode,
+                                           c << bits, i)) != 0
+             || ((temp = (alpha_emit_set_const
+                          (subtarget, mode,
+                           ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
+                           i)))
+                 != 0))
+           return expand_binop (mode, ashr_optab, temp, GEN_INT (bits),
+                                target, 0, OPTAB_WIDEN);
     }
 
   return 0;
@@ -959,6 +1083,23 @@ print_operand (file, x, code)
       fprintf (file, "%s", GET_RTX_NAME (reverse_condition (GET_CODE (x))));
       break;
 
+    case 'c':
+      /* Similar to `c', but swap.  We can't get unsigned here either.  */
+      if (GET_RTX_CLASS (GET_CODE (x)) != '<')
+       output_operand_lossage ("invalid %%D value");
+
+      fprintf (file, "%s", GET_RTX_NAME (swap_condition (GET_CODE (x))));
+      break;
+
+    case 'd':
+      /* Similar, but reverse and swap.  We can't get unsigned here either.  */
+      if (GET_RTX_CLASS (GET_CODE (x)) != '<')
+       output_operand_lossage ("invalid %%D value");
+
+      fprintf (file, "%s",
+              GET_RTX_NAME (swap_condition (reverse_condition ((GET_CODE (x))))));
+      break;
+
     case 'E':
       /* Write the divide or modulus operator.  */
       switch (GET_CODE (x))
@@ -981,17 +1122,6 @@ print_operand (file, x, code)
        }
       break;
 
-    case 'F':
-      /* Write the symbol; if the current function uses GP, write a
-        modified version.  */
-      if (GET_CODE (x) != SYMBOL_REF)
-       output_operand_lossage ("invalid %%F value");
-
-      output_addr_const (file, x);
-      if (alpha_function_needs_gp)
-       fprintf (file, "..ng");
-      break;
-
     case 'A':
       /* Write "_u" for unaligned access.  */
       if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
@@ -1026,94 +1156,50 @@ alpha_builtin_saveregs (arglist)
   int stdarg = (TYPE_ARG_TYPES (fntype) != 0
                && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
                    != void_type_node));
-  int nregs = current_function_args_info;
 
-  /* If we have a variable-sized argument already, we will have used all
-     the registers, so set up to indicate that.  */
+  /* Compute the current position into the args, taking into account
+     both registers and memory.  Both of these are already included in
+     current_function_args_info.  */
 
-  if (GET_CODE (current_function_arg_offset_rtx) != CONST_INT)
-    {
-      argsize = plus_constant (current_function_arg_offset_rtx,
-                              (6 * UNITS_PER_WORD + UNITS_PER_WORD - 1));
-      argsize = expand_shift (RSHIFT_EXPR, Pmode, argsize,
-                             build_int_2 (3, 0), argsize, 0);
-    }
-  else
-    {
-      /* Compute the number of args in memory and number of arguments already
-        processed.  Then adjust the number of registers if this is stdarg.  */
-      int memargs = ((INTVAL (current_function_arg_offset_rtx)
-                     + UNITS_PER_WORD - 1)
-                    / UNITS_PER_WORD);
+  argsize = GEN_INT (current_function_args_info * UNITS_PER_WORD);
 
-      argsize = GEN_INT (MIN (nregs, 6) + memargs);
+  /* SETUP_INCOMING_VARARGS moves the starting address base up by 48,
+     storing fp arg registers in the first 48 bytes, and the integer arg
+     registers in the next 48 bytes.  This is only done, however, if any
+     integer registers need to be stored.
 
-      if (nregs <= 6)
-       nregs -= stdarg;
-    }
+     If no integer registers need be stored, then we must subtract 48 in
+     order to account for the integer arg registers which are counted in
+     argsize above, but which are not actually stored on the stack.  */
+
+  addr = (current_function_args_info <= 5 + stdarg
+         ? plus_constant (virtual_incoming_args_rtx, 6 * UNITS_PER_WORD)
+         : plus_constant (virtual_incoming_args_rtx, - (6 * UNITS_PER_WORD)));
+
+  addr = force_operand (addr, NULL_RTX);
 
   /* Allocate the va_list constructor */
-  block = assign_stack_local (BLKmode, 4 * UNITS_PER_WORD, BITS_PER_WORD);
+  block = assign_stack_local (BLKmode, 2 * UNITS_PER_WORD, BITS_PER_WORD);
   RTX_UNCHANGING_P (block) = 1;
   RTX_UNCHANGING_P (XEXP (block, 0)) = 1;
 
-  /* Store the argsize as the __va_arg member.  */
-  emit_move_insn (change_address (block, DImode, XEXP (block, 0)),
-                 argsize);
+  /* Store the address of the first integer register in the __base member.  */
 
-  /* Store the arg pointer in the __va_stack member.  */
-  emit_move_insn (change_address (block, Pmode,
-                                 plus_constant (XEXP (block, 0),
-                                                UNITS_PER_WORD)),
-                 virtual_incoming_args_rtx);
+#ifdef POINTERS_EXTEND_UNSIGNED
+  addr = convert_memory_address (ptr_mode, addr);
+#endif
 
-  /* Allocate the integer register space, and store it as the
-     __va_ireg member.  */
-  addr = assign_stack_local (BLKmode, 6 * UNITS_PER_WORD, -1);
-  MEM_IN_STRUCT_P (addr) = 1;
-  RTX_UNCHANGING_P (addr) = 1;
-  RTX_UNCHANGING_P (XEXP (addr, 0)) = 1;
+  emit_move_insn (change_address (block, ptr_mode, XEXP (block, 0)), addr);
 
-  emit_move_insn (change_address (block, Pmode,
+  /* Store the argsize as the __va_offset member.  */
+  emit_move_insn (change_address (block, TYPE_MODE (integer_type_node),
                                  plus_constant (XEXP (block, 0),
-                                                2 * UNITS_PER_WORD)),
-                 copy_to_reg (XEXP (addr, 0)));
-
-  /* Now store the incoming integer registers.  */
-  if (nregs < 6)
-      move_block_from_reg
-       (16 + nregs,
-        change_address (addr, Pmode,
-                        plus_constant (XEXP (addr, 0),
-                                       nregs * UNITS_PER_WORD)),
-        6 - nregs);
-
-  /* Allocate the FP register space, and store it as the
-     __va_freg member.  */
-  addr = assign_stack_local (BLKmode, 6 * UNITS_PER_WORD, -1);
-  MEM_IN_STRUCT_P (addr) = 1;
-  RTX_UNCHANGING_P (addr) = 1;
-  RTX_UNCHANGING_P (XEXP (addr, 0)) = 1;
-
-  emit_move_insn (change_address (block, Pmode,
-                                 plus_constant (XEXP (block, 0),
-                                                3 * UNITS_PER_WORD)),
-                 copy_to_reg (XEXP (addr, 0)));
-
-  /* Now store the incoming floating-point registers.   If we are not
-     to use the floating-point registers, store the integer registers
-     in those locations too.  */
-  if (nregs < 6)
-      move_block_from_reg
-       (16 + 32 * (TARGET_FPREGS != 0) + nregs,
-        change_address (addr, Pmode,
-                        plus_constant (XEXP (addr, 0),
-                                       nregs * UNITS_PER_WORD)),
-        6 - nregs);
+                                                POINTER_SIZE/BITS_PER_UNIT)),
+                 argsize);
 
   /* Return the address of the va_list constructor, but don't put it in a
-     register.  This fails when not optimizing and produces worse code when
-     optimizing.  */
+     register.  Doing so would fail when not optimizing and produce worse
+     code when optimizing.  */
   return XEXP (block, 0);
 }
 \f
@@ -1132,87 +1218,101 @@ alpha_sa_size ()
     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i])
       size++;
 
+  /* If some registers were saved but not reg 26, reg 26 must also
+     be saved, so leave space for it.  */
+  if (size != 0 && ! regs_ever_live[26])
+    size++;
+
+  /* Our size must be even (multiple of 16 bytes).  */
+  if (size & 1)
+    size ++;
+
   return size * 8;
 }
 
-/* Return non-zero if this function needs gp.  It does if it has
-   an LDSYM insn.  */
+/* Return 1 if this function can directly return via $26.  */
 
 int
-alpha_need_gp ()
+direct_return ()
 {
-  rtx insn;
-
-  for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-    if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
-       && GET_CODE (PATTERN (insn)) != USE
-       && GET_CODE (PATTERN (insn)) != CLOBBER
-       && get_attr_type (insn) == TYPE_LDSYM)
-      return 1;
-
-  return 0;
+  return (reload_completed && alpha_sa_size () == 0
+         && get_frame_size () == 0
+         && current_function_outgoing_args_size == 0
+         && current_function_pretend_args_size == 0);
 }
 
-/* Return 1 if GP is dead at after INSN.  */
+/* Write a version stamp.  Don't write anything if we are running as a
+   cross-compiler.  Otherwise, use the versions in /usr/include/stamp.h.  */
 
-int
-alpha_gp_dead_after (insn)
-     rtx insn;
-{
-  int jump_count = 0;
-  int found = 0;
-  rtx p;
+#if !defined(CROSS_COMPILE) && !defined(_WIN32)
+#include <stamp.h>
+#endif
 
-  /* If we aren't optimizing, don't do this optimization.  More importantly,
-     JUMP_LABEL isn't properly set when not optimizing.  */
+void
+alpha_write_verstamp (file)
+     FILE *file;
+{
+#ifdef MS_STAMP
+  fprintf (file, "\t.verstamp %d %d\n", MS_STAMP, LS_STAMP);
+#endif
+}
+\f
+/* Write code to add constant C to register number IN_REG (possibly 31)
+   and put the result into OUT_REG.  Use TEMP_REG as a scratch register;
+   usually this will be OUT_REG, but should not be if OUT_REG is 
+   STACK_POINTER_REGNUM, since it must be updated in a single instruction.
+   Write the code to FILE.  */
 
-  if (optimize == 0)
-    return 0;
+static void
+add_long_const (file, c, in_reg, out_reg, temp_reg)
+     FILE *file;
+     HOST_WIDE_INT c;
+     int in_reg, out_reg, temp_reg;
+{
+  HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
+  HOST_WIDE_INT tmp1 = c - low;
+  HOST_WIDE_INT high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
+  HOST_WIDE_INT extra = 0;
 
-  /* If we are followed by a BARRIER, we don't return.  */
-  if (NEXT_INSN (insn) && GET_CODE (NEXT_INSN (insn)) == BARRIER)
-    return 1;
+  /* We don't have code to write out constants larger than 32 bits.  */
+#if HOST_BITS_PER_LONG_INT == 64
+  if ((unsigned HOST_WIDE_INT) c >> 32 != 0)
+    abort ();
+#endif
 
-  /* Otherwise search for a use of GP before a return.  */
+  /* If HIGH will be interpreted as negative, we must adjust it to do two
+     ldha insns.  Note that we will never be building a negative constant
+     here.  */
 
-  for (p = next_active_insn (insn); p; p = next_active_insn (p))
+  if (high & 0x8000)
     {
-      if (get_attr_type (p) == TYPE_LDSYM
-         || get_attr_type (p) == TYPE_JSR)
-       {
-         found = 1;
-         break;
-       }
+      extra = 0x4000;
+      tmp1 -= 0x40000000;
+      high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
+    }
 
-      if (GET_CODE (p) == JUMP_INSN)
-       {
-         if (GET_CODE (PATTERN (p)) == RETURN)
-           break;
+  if (low != 0)
+    {
+      int result_reg = (extra == 0 && high == 0) ? out_reg : temp_reg;
 
-         if (! simplejump_p (p) || jump_count++ > 10)
-           {
-             found = 1;
-             break;
-           }
+      if (low >= 0 && low < 255)
+       fprintf (file, "\taddq $%d,%d,$%d\n", in_reg, low, result_reg);
+      else
+       fprintf (file, "\tlda $%d,%d($%d)\n", result_reg, low, in_reg);
 
-         p = JUMP_LABEL (p);
-       }
+      in_reg = result_reg;
     }
 
-  /* Restore any operands destroyed by the attribute calls above.  */
-  insn_extract (insn);
-
-  return ! found;
-}
+  if (extra)
+    {
+      int result_reg = (high == 0) ? out_reg : temp_reg;
 
-/* Return 1 if this function can directly return via $26.  */
+      fprintf (file, "\tldah $%d,%d($%d)\n", result_reg, extra, in_reg);
+      in_reg = result_reg;
+    }
 
-int
-direct_return ()
-{
-  return (reload_completed && alpha_sa_size () == 0
-         && get_frame_size () == 0
-         && current_function_pretend_args_size == 0);
+  if (high)
+    fprintf (file, "\tldah $%d,%d($%d)\n", out_reg, high, in_reg);
 }
 
 /* Write function prologue.  */
@@ -1222,110 +1322,170 @@ output_prolog (file, size)
      FILE *file;
      int size;
 {
-  HOST_WIDE_INT frame_size = ((size + current_function_outgoing_args_size
-                              + current_function_pretend_args_size
-                              + alpha_sa_size () + 15) & ~15);
-  int reg_offset = current_function_outgoing_args_size;
-  int start_reg_offset = reg_offset;
+  HOST_WIDE_INT out_args_size
+    = ALPHA_ROUND (current_function_outgoing_args_size);
+  HOST_WIDE_INT sa_size = alpha_sa_size ();
+  HOST_WIDE_INT frame_size
+    = (out_args_size + sa_size
+       + ALPHA_ROUND (size + current_function_pretend_args_size));
+  HOST_WIDE_INT reg_offset = out_args_size;
+  HOST_WIDE_INT start_reg_offset = reg_offset;
+  HOST_WIDE_INT actual_start_reg_offset = start_reg_offset;
+  int int_reg_save_area_size = 0;
+  rtx insn;
   unsigned reg_mask = 0;
   int i;
 
-  /* If we need a GP, load it first.  */
-  alpha_function_needs_gp = alpha_need_gp ();
+  /* Ecoff can handle multiple .file directives, so put out file and lineno.
+     We have to do that before the .ent directive as we cannot switch
+     files within procedures with native ecoff because line numbers are
+     linked to procedure descriptors.
+     Outputting the lineno helps debugging of one line functions as they
+     would otherwise get no line number at all. Please note that we would
+     like to put out last_linenum from final.c, but it is not accessible.  */
 
-  if (alpha_function_needs_gp)
+  if (write_symbols == SDB_DEBUG)
     {
-      rtx insn;
+      ASM_OUTPUT_SOURCE_FILENAME (file,
+                                 DECL_SOURCE_FILE (current_function_decl));
+      if (debug_info_level != DINFO_LEVEL_TERSE)
+        ASM_OUTPUT_SOURCE_LINE (file,
+                               DECL_SOURCE_LINE (current_function_decl));
+    }
 
-      fprintf (file, "\tldgp $29,0($27)\n");
+  /* The assembly language programmer's guide states that the second argument
+     to the .ent directive, the lex_level, is ignored by the assembler,
+     so we might as well omit it.  */
+     
+  fprintf (file, "\t.ent ");
+  assemble_name (file, alpha_function_name);
+  fprintf (file, "\n");
+  ASM_OUTPUT_LABEL (file, alpha_function_name);
+  inside_function = TRUE;
 
-      /* If we have a recursive call, put a special label here.  */
-      for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-       if (GET_CODE (insn) == CALL_INSN
-           && get_attr_type (insn) != TYPE_JSR)
-         {
-           fprintf (file, "%s..ng:\n", current_function_name);
-           break;
-         }
-    }
+  /* Set up offsets to alpha virtual arg/local debugging pointer.  */
+
+  alpha_auto_offset = -frame_size + current_function_pretend_args_size;
+  alpha_arg_offset = -frame_size + 48;
+
+  /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first. 
+     Even if we are a static function, we still need to do this in case
+     our address is taken and passed to something like qsort.
 
-  /* Adjust the stack by the frame size.  If the frame size is > 32768
-     bytes, we have to load it into a register first and then subtract
-     from sp.  Note that we are only allowed to adjust sp once in the
-     prologue.  */
+     We never need a GP for Windows/NT.  */
+
+  alpha_function_needs_gp = 0;
+  for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
+    if ((GET_CODE (insn) == CALL_INSN)
+       || (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
+           && GET_CODE (PATTERN (insn)) != USE
+           && GET_CODE (PATTERN (insn)) != CLOBBER
+           && (get_attr_type (insn) == TYPE_LDSYM
+               || get_attr_type (insn) == TYPE_ISUBR)))
+      {
+       alpha_function_needs_gp = 1;
+       break;
+      }
 
-  if (frame_size > 32768)
+  if (WINDOWS_NT == 0)
     {
-      HOST_WIDE_INT low = (frame_size & 0xffff) - 2 * (frame_size & 0x8000);
-      HOST_WIDE_INT tmp1 = frame_size - low;
-      HOST_WIDE_INT high
-       = ((tmp1 >> 16) & 0xfff) - 2 * ((tmp1 >> 16) & 0x8000);
-      HOST_WIDE_INT tmp2 = frame_size - (high << 16) - low;
-      HOST_WIDE_INT extra = 0;
-      int in_reg = 31;
+      if (alpha_function_needs_gp)
+       fprintf (file, "\tldgp $29,0($27)\n");
 
-      /* We haven't written code to handle frames > 4GB.  */
-#if HOST_BITS_PER_LONG_INT == 64
-      if ((unsigned HOST_WIDE_INT) frame_size >> 32 != 0)
-       abort ();
-#endif
+      /* Put a label after the GP load so we can enter the function at it.  */
+      assemble_name (file, alpha_function_name);
+      fprintf (file, "..ng:\n");
+    }
 
-      if (tmp2)
-       {
-         extra = 0x4000;
-         tmp1 -= 0x40000000;
-         high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
-       }
+  /* Adjust the stack by the frame size.  If the frame size is > 4096
+     bytes, we need to be sure we probe somewhere in the first and last
+     4096 bytes (we can probably get away without the latter test) and
+     every 8192 bytes in between.  If the frame size is > 32768, we
+     do this in a loop.  Otherwise, we generate the explicit probe
+     instructions. 
 
-      if (low != 0)
-       {
-         fprintf (file, "\tlda $28,%d($%d)\n", low, in_reg);
-         in_reg = 28;
-       }
+     Note that we are only allowed to adjust sp once in the prologue.  */
 
-      if (extra)
+  if (frame_size < 32768)
+    {
+      if (frame_size > 4096)
        {
-         fprintf (file, "\tldah $28,%d($%d)\n", extra, in_reg);
-         in_reg = 28;
-       }
+         int probed = 4096;
 
-      fprintf (file, "\tldah $28,%d($%d)\n", high, in_reg);
+         fprintf (file, "\tstq $31,-%d($30)\n", probed);
 
-      fprintf (file, "\tsubq $30,$28,$30\n");
-    }
-  else if (frame_size)
-    fprintf (file, "\tlda $30,-%d($30)\n", frame_size);
+         while (probed + 8192 < frame_size)
+           fprintf (file, "\tstq $31,-%d($30)\n", probed += 8192);
 
-  /* Write out the .frame line.  If we need a frame pointer, we use
-     an offset of zero.  */
+         /* We only have to do this probe if we aren't saving registers.  */
+         if (sa_size == 0 && probed + 4096 < frame_size)
+           fprintf (file, "\tstq $31,-%d($30)\n", frame_size);
+       }
 
-  if (frame_pointer_needed)
-    fprintf (file, "\t.frame $15,0,$26\n");
+      if (frame_size != 0)
+       fprintf (file, "\tlda $30,-%d($30)\n", frame_size);
+    }
   else
-    fprintf (file, "\t.frame $30,%d,$26\n", frame_size);
+    {
+      /* Here we generate code to set R4 to SP + 4096 and set R5 to the
+        number of 8192 byte blocks to probe.  We then probe each block
+        in the loop and then set SP to the proper location.  If the
+        amount remaining is > 4096, we have to do one more probe if we
+        are not saving any registers.  */
+
+      HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
+      HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
+
+      add_long_const (file, blocks, 31, 5, 5);
+
+      fprintf (file, "\tlda $4,4096($30)\n");
 
+      assemble_name (file, alpha_function_name);
+      fprintf (file, "..sc:\n");
+
+      fprintf (file, "\tstq $31,-8192($4)\n");
+      fprintf (file, "\tsubq $5,1,$5\n");
+      fprintf (file, "\tlda $4,-8192($4)\n");
+
+      fprintf (file, "\tbne $5,");
+      assemble_name (file, alpha_function_name);
+      fprintf (file, "..sc\n");
+
+      if (leftover > 4096 && sa_size == 0)
+       fprintf (file, "\tstq $31,-%d($4)\n", leftover);
+
+      fprintf (file, "\tlda $30,-%d($4)\n", leftover);
+    }
+
+  /* Describe our frame.  */
+  fprintf (file, "\t.frame $%d,%d,$26,%d\n", 
+          (frame_pointer_needed
+           ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM),
+          frame_size, current_function_pretend_args_size);
     
-  /* Save register 26 if it is used.  */
-  if (regs_ever_live[26])
+  /* Save register 26 if any other register needs to be saved.  */
+  if (sa_size != 0)
     {
       reg_mask |= 1 << 26;
       fprintf (file, "\tstq $26,%d($30)\n", reg_offset);
       reg_offset += 8;
+      int_reg_save_area_size += 8;
     }
 
-  /* Now save any other used register that are required to be saved.  */
+  /* Now save any other used integer registers required to be saved.  */
   for (i = 0; i < 32; i++)
     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i] && i != 26)
       {
        reg_mask |= 1 << i;
        fprintf (file, "\tstq $%d,%d($30)\n", i, reg_offset);
        reg_offset += 8;
+       int_reg_save_area_size += 8;
       }
 
   /* Print the register mask and do floating-point saves.  */
   if (reg_mask)
     fprintf (file, "\t.mask 0x%x,%d\n", reg_mask,
-            start_reg_offset - frame_size);
+            actual_start_reg_offset - frame_size);
 
   start_reg_offset = reg_offset;
   reg_mask = 0;
@@ -1341,23 +1501,16 @@ output_prolog (file, size)
 
   /* Print the floating-point mask, if we've saved any fp register.  */
   if (reg_mask)
-    fprintf (file, "\t.fmask 0x%x,%d\n", reg_mask, start_reg_offset);
-
-  /* If we need a frame pointer, set it to the value of incoming stack
-     which we compute by adding back the frame size pointer.  Because we
-     can subtract one more than we can add, we have to special-case
-     frame sizes of 32K.  Note that there is no restriction that the frame
-     pointer be updated in one instruction.  */
+    fprintf (file, "\t.fmask 0x%x,%d\n", reg_mask,
+            actual_start_reg_offset - frame_size + int_reg_save_area_size);
 
+  /* If we need a frame pointer, set it from the stack pointer.  Note that
+     this must always be the last instruction in the prologue.  */
   if (frame_pointer_needed)
-    {
-      if (frame_size == 32768)
-       fprintf (file, "\tlda $15,16384($30)\n\tlda $15,16384($15)\n");
-      else if (frame_size > 32768)
-       fprintf (file, "\taddq $30,$28,$15\n");
-      else
-       fprintf (file, "\tlda $15,%d($30)\n", frame_size);
-    }
+    fprintf (file, "\tbis $30,$30,$15\n");
+
+  /* End the prologue and say if we used gp.  */
+  fprintf (file, "\t.prologue %d\n", alpha_function_needs_gp);
 }
 
 /* Write function epilogue.  */
@@ -1368,11 +1521,16 @@ output_epilog (file, size)
      int size;
 {
   rtx insn = get_last_insn ();
-  HOST_WIDE_INT frame_size = ((size + current_function_outgoing_args_size
-                              + current_function_pretend_args_size
-                              + alpha_sa_size () + 15) & ~15);
-  int reg_offset = current_function_outgoing_args_size;
-  int reg_offset_from = STACK_POINTER_REGNUM;
+  HOST_WIDE_INT out_args_size
+    = ALPHA_ROUND (current_function_outgoing_args_size);
+  HOST_WIDE_INT sa_size = alpha_sa_size ();
+  HOST_WIDE_INT frame_size
+    = (out_args_size + sa_size
+       + ALPHA_ROUND (size + current_function_pretend_args_size));
+  HOST_WIDE_INT reg_offset = out_args_size;
+  HOST_WIDE_INT frame_size_from_reg_save = frame_size - reg_offset;
+  int restore_fp
+    = frame_pointer_needed && regs_ever_live[HARD_FRAME_POINTER_REGNUM];
   int i;
 
   /* If the last insn was a BARRIER, we don't have to write anything except
@@ -1381,72 +1539,32 @@ output_epilog (file, size)
     insn = prev_nonnote_insn (insn);
   if (insn == 0 || GET_CODE (insn) != BARRIER)
     {
-      /* If we have a frame pointer, we restore the registers from an
-        offset from it, assuming that we can reach the offset.  If not,
-        we have to compute the address using a scratch register.  This is
-        messy, but should not be common.  We have to copy the frame
-        pointer elsewhere here since we will be restoring it before we can
-        use it to restore the stack pointer.  We use $25.  */
+      int fp_offset = 0;
 
+      /* If we have a frame pointer, restore SP from it.  */
       if (frame_pointer_needed)
-       {
-         fprintf (file, "\tbis $15,$15,$25\n");
-
-         if (frame_size < 32768)
-           reg_offset -= frame_size, reg_offset_from = 25;
-         else
-           {
-             HOST_WIDE_INT low
-               = (frame_size & 0xffff) - 2 * (frame_size & 0x8000);
-             HOST_WIDE_INT tmp1 = frame_size - low;
-             HOST_WIDE_INT high
-               = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
-             HOST_WIDE_INT tmp2 = frame_size - (high << 16) - low;
-             int extra = 0;
-             int in_reg = 31;
-
-             if (tmp2)
-               {
-                 extra = 0x4000;
-                 tmp1 -= 0x40000000;   
-                 high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
-               }
-
-             if (low != 0)
-               {
-                 fprintf (file, "\tlda $28,%d($%d)\n", low, in_reg);
-                 in_reg = 28;
-               }
-
-             if (extra)
-               {
-                 fprintf (file, "\tldah $28,%d($%d)\n", extra, in_reg);
-                 in_reg = 28;
-               }
-
-             fprintf (file, "\tldah $28,%d($%d)\n", high, in_reg);
-
-             fprintf (file, "\tsubq $25,$28,$28\n");
-
-             reg_offset_from = 28;
-           }
-       }
+       fprintf (file, "\tbis $15,$15,$30\n");
 
       /* Restore all the registers, starting with the return address
         register.  */
-      if (regs_ever_live[26])
+      if (sa_size != 0)
        {
-         fprintf (file, "\tldq $26,%d($%d)\n", reg_offset, reg_offset_from);
+         fprintf (file, "\tldq $26,%d($30)\n", reg_offset);
          reg_offset += 8;
        }
 
-      /* Now restore any other used register that that we saved.  */
+      /* Now restore any other used integer registers that that we saved,
+        except for FP if it is being used as FP, since it must be
+        restored last.  */
+
       for (i = 0; i < 32; i++)
        if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i]
            && i != 26)
          {
-           fprintf (file, "\tldq $%d,%d($%d)\n",
-                    i, reg_offset, reg_offset_from);
+           if (i == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
+             fp_offset = reg_offset;
+           else
+             fprintf (file, "\tldq $%d,%d($30)\n", i, reg_offset);
            reg_offset += 8;
          }
 
@@ -1454,63 +1572,134 @@ output_epilog (file, size)
        if (! fixed_regs[i + 32] && ! call_used_regs[i + 32]
            && regs_ever_live[i + 32])
          {
-           fprintf (file, "\tldt $f%d,%d($%d)\n",
-                    i, reg_offset, reg_offset_from);
+           fprintf (file, "\tldt $f%d,%d($30)\n", i, reg_offset);
            reg_offset += 8;
          }
 
-      /* Restore the stack.  If we have a frame pointer, use it.  Otherwise,
-        add the size back into the stack, handling the large frame size.  */
+      /* If the stack size is large and we have a frame pointer, compute the
+        size of the stack into a register because the old FP restore, stack
+        pointer adjust, and return are required to be consecutive
+        instructions.   */
+      if (frame_size > 32767 && restore_fp)
+       add_long_const (file, frame_size, 31, 1, 1);
+
+      /* If we needed a frame pointer and we have to restore it, do it
+        now.  This must be done in one instruction immediately
+        before the SP update.  */
+      if (restore_fp && fp_offset)
+       fprintf (file, "\tldq $15,%d($30)\n", fp_offset);
+
+      /* Now update the stack pointer, if needed.  Only one instruction must
+        modify the stack pointer.  It must be the last instruction in the
+        sequence and must be an ADDQ or LDA instruction.  If the frame
+        pointer was loaded above, we may only put one instruction here.  */
+
+      if (frame_size > 32768 && restore_fp)
+       fprintf  (file, "\taddq $1,$30,$30\n");
+      else
+       add_long_const (file, frame_size, 30, 30, 1);
 
-      if (frame_pointer_needed)
-       fprintf (file, "\tbis $25,$25,$30\n");
-      else if (frame_size > 32767)
-       {
-         HOST_WIDE_INT low
-           = (frame_size & 0xffff) - 2 * (frame_size & 0x8000);
-         HOST_WIDE_INT tmp1 = frame_size - low;
-         HOST_WIDE_INT high
-           = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
-         HOST_WIDE_INT tmp2 = frame_size - (high << 16) - low;
-         HOST_WIDE_INT extra = 0;
-         int in_reg = 31;
-
-         /* We haven't written code to handle frames > 4GB.  */
-#if HOST_BITS_PER_LONG_INT == 64
-         if ((unsigned HOST_WIDE_INT) frame_size >> 32 != 0)
-           abort ();
-#endif
+      /* Finally return to the caller.  */
+      fprintf (file, "\tret $31,($26),1\n");
+    }
 
-         if (tmp2)
-           {
-             extra = 0x4000;
-             tmp1 -= 0x40000000;
-             high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
-           }
+  /* End the function.  */
+  fprintf (file, "\t.end ");
+  assemble_name (file, alpha_function_name);
+  fprintf (file, "\n");
+  inside_function = FALSE;
 
-         if (low != 0)
-           {
-             fprintf (file, "\tlda $28,%d($%d)\n", low, in_reg);
-             in_reg = 28;
-           }
+  /* Show that we know this function if it is called again.  */
+  SYMBOL_REF_FLAG (XEXP (DECL_RTL (current_function_decl), 0)) = 1;
+}
+\f
+/* Debugging support.  */
 
-         if (extra)
-           {
-             fprintf (file, "\tldah $28,%d($%d)\n", extra, in_reg);
-             in_reg = 28;
-           }
+#include "gstab.h"
 
-         fprintf (file, "\tldah $28,%d($%d)\n", high, in_reg);
+/* Count the number of sdb related labels are generated (to find block
+   start and end boundaries).  */
 
-         fprintf (file, "\taddq $30,$28,$30\n");
+int sdb_label_count = 0;
+
+/* Next label # for each statement.  */
+
+static int sym_lineno = 0;
+
+/* Count the number of .file directives, so that .loc is up to date.  */
+
+static int num_source_filenames = 0;
+
+/* Name of the file containing the current function.  */
+
+static char *current_function_file = "";
+
+/* Offsets to alpha virtual arg/local debugging pointers.  */
+
+long alpha_arg_offset;
+long alpha_auto_offset;
+\f
+/* Emit a new filename to a stream.  */
+
+void
+alpha_output_filename (stream, name)
+     FILE *stream;
+     char *name;
+{
+  static int first_time = TRUE;
+  char ltext_label_name[100];
+
+  if (first_time)
+    {
+      first_time = FALSE;
+      ++num_source_filenames;
+      current_function_file = name;
+      fprintf (stream, "\t.file\t%d ", num_source_filenames);
+      output_quoted_string (stream, name);
+      fprintf (stream, "\n");
+      if (!TARGET_GAS && write_symbols == DBX_DEBUG)
+       fprintf (stream, "\t#@stabs\n");
+    }
+
+  else if (!TARGET_GAS && write_symbols == DBX_DEBUG)
+    {
+      ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
+      fprintf (stream, "%s ", ASM_STABS_OP);
+      output_quoted_string (stream, name);
+      fprintf (stream, ",%d,0,0,%s\n", N_SOL, &ltext_label_name[1]);
+    }
+
+  else if (name != current_function_file
+      && strcmp (name, current_function_file) != 0)
+    {
+      if (inside_function && ! TARGET_GAS)
+       fprintf (stream, "\t#.file\t%d ", num_source_filenames);
+      else
+       {
+         ++num_source_filenames;
+         current_function_file = name;
+         fprintf (stream, "\t.file\t%d ", num_source_filenames);
        }
-      else if (frame_size)
-       fprintf (file, "\tlda $30,%d($30)\n", frame_size);
 
-      /* Now return to the caller.  */
-      fprintf (file, "\tret $31,($26),1\n");
+      output_quoted_string (stream, name);
+      fprintf (stream, "\n");
     }
+}
+\f
+/* Emit a linenumber to a stream.  */
 
-  /* End the function.  */
-  fprintf (file, "\t.end %s\n", alpha_function_name);
+void
+alpha_output_lineno (stream, line)
+     FILE *stream;
+     int line;
+{
+  if (! TARGET_GAS && write_symbols == DBX_DEBUG)
+    {
+      /* mips-tfile doesn't understand .stabd directives.  */
+      ++sym_lineno;
+      fprintf (stream, "$LM%d:\n\t%s %d,0,%d,$LM%d\n",
+              sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno);
+    }
+  else
+    fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line);
 }