OSDN Git Service

Fix mips64vr4100-elf build failure.
[pf3gnuchains/gcc-fork.git] / gcc / calls.c
index 6c52191..8133cc0 100644 (file)
@@ -19,18 +19,20 @@ the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
 #include "config.h"
-#include <stdio.h>
-#include "rtl.h"
-#include "tree.h"
-#include "flags.h"
-#include "expr.h"
-#include "regs.h"
 #ifdef __STDC__
 #include <stdarg.h>
 #else
 #include <varargs.h>
 #endif
+#include "system.h"
+#include "rtl.h"
+#include "tree.h"
+#include "flags.h"
+#include "expr.h"
+#include "regs.h"
 #include "insn-flags.h"
+#include "toplev.h"
+#include "output.h"
 
 /* Decide whether a function's arguments should be processed
    from first to last or from last to first.
@@ -125,7 +127,8 @@ int stack_arg_under_construction;
 
 static int calls_function      PROTO((tree, int));
 static int calls_function_1    PROTO((tree, int));
-static void emit_call_1                PROTO((rtx, tree, tree, int, int, rtx, rtx,
+static void emit_call_1                PROTO((rtx, tree, tree, HOST_WIDE_INT,
+                                      HOST_WIDE_INT, rtx, rtx,
                                       int, rtx, int));
 static void store_one_arg      PROTO ((struct arg_data *, rtx, int, int,
                                        tree, int));
@@ -347,8 +350,8 @@ emit_call_1 (funexp, fndecl, funtype, stack_size, struct_value_size,
      rtx funexp;
      tree fndecl;
      tree funtype;
-     int stack_size;
-     int struct_value_size;
+     HOST_WIDE_INT stack_size;
+     HOST_WIDE_INT struct_value_size;
      rtx next_arg_reg;
      rtx valreg;
      int old_inhibit_defer_pop;
@@ -358,7 +361,9 @@ emit_call_1 (funexp, fndecl, funtype, stack_size, struct_value_size,
   rtx stack_size_rtx = GEN_INT (stack_size);
   rtx struct_value_size_rtx = GEN_INT (struct_value_size);
   rtx call_insn;
+#ifndef ACCUMULATE_OUTGOING_ARGS
   int already_popped = 0;
+#endif
 
   /* Ensure address is valid.  SYMBOL_REF is already valid, so no need,
      and we don't want to load it into a register as an optimization,
@@ -507,7 +512,7 @@ expand_call (exp, target, ignore)
   /* Size of aggregate value wanted, or zero if none wanted
      or if we are using the non-reentrant PCC calling convention
      or expecting the value in registers.  */
-  int struct_value_size = 0;
+  HOST_WIDE_INT struct_value_size = 0;
   /* Nonzero if called function returns an aggregate in memory PCC style,
      by returning the address of where to find it.  */
   int pcc_struct_value = 0;
@@ -541,15 +546,11 @@ expand_call (exp, target, ignore)
      So the entire argument block must then be preallocated (i.e., we
      ignore PUSH_ROUNDING in that case).  */
 
-#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
-  int must_preallocate = 1;
-#else
 #ifdef PUSH_ROUNDING
   int must_preallocate = 0;
 #else
   int must_preallocate = 1;
 #endif
-#endif
 
   /* Size of the stack reserved for parameter registers.  */
   int reg_parm_stack_space = 0;
@@ -660,6 +661,11 @@ expand_call (exp, target, ignore)
 #endif
 #endif
 
+#if defined(PUSH_ROUNDING) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
+  if (reg_parm_stack_space > 0)
+    must_preallocate = 1;
+#endif
+
   /* Warn if this value is an aggregate type,
      regardless of which calling convention we are using for it.  */
   if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
@@ -710,8 +716,7 @@ expand_call (exp, target, ignore)
            DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
            mark_addressable (d);
            structure_value_addr = XEXP (DECL_RTL (d), 0);
-           MEM_IN_STRUCT_P (structure_value_addr)
-             = AGGREGATE_TYPE_P (TREE_TYPE (exp));
+           TREE_USED (d) = 1;
            target = 0;
          }
       }
@@ -769,18 +774,18 @@ expand_call (exp, target, ignore)
                     outgoing argument list in addition to the requested
                     space, but there is no way to ask for stack space such
                     that an argument list of a certain length can be
-                    safely constructed.  */
+                    safely constructed. 
 
-                 int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl));
-#ifdef REG_PARM_STACK_SPACE
-                 /* Add the stack space reserved for register arguments
-                    in the inline function.  What is really needed is the
+                    Add the stack space reserved for register arguments, if
+                    any, in the inline function.  What is really needed is the
                     largest value of reg_parm_stack_space in the inline
                     function, but that is not available.  Using the current
                     value of reg_parm_stack_space is wrong, but gives
                     correct results on all supported machines.  */
-                 adjust += reg_parm_stack_space;
-#endif
+
+                 int adjust = (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl))
+                               + reg_parm_stack_space);
+
                  start_sequence ();
                  emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
                  allocate_dynamic_stack_space (GEN_INT (adjust),
@@ -851,7 +856,7 @@ expand_call (exp, target, ignore)
   is_longjmp = 0;
   is_malloc = 0;
 
-  if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15
+  if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
       /* Exclude functions not at the file scope, or not `extern',
         since they are not the magic functions we would otherwise
         think they are.  */
@@ -898,8 +903,12 @@ expand_call (exp, target, ignore)
       else if (! strcmp (tname, "malloc")
               || ! strcmp (tname, "calloc")
               || ! strcmp (tname, "realloc")
-              || ! strcmp (tname, "__builtin_new")
-              || ! strcmp (tname, "__builtin_vec_new"))
+              /* Note use of NAME rather than TNAME here.  These functions
+                 are only reserved when preceded with __.  */
+              || ! strcmp (name, "__vn")       /* mangled __builtin_vec_new */
+              || ! strcmp (name, "__nw")       /* mangled __builtin_new */
+              || ! strcmp (name, "__builtin_new")
+              || ! strcmp (name, "__builtin_vec_new"))
        is_malloc = 1;
     }
 
@@ -963,11 +972,11 @@ expand_call (exp, target, ignore)
 
   /* Compute number of named args.
      Normally, don't include the last named arg if anonymous args follow.
-     We do include the last named arg if STRICT_ARGUMENT_NAMING is defined.
+     We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
      (If no anonymous args follow, the result of list_length is actually
      one too large.  This is harmless.)
 
-     If SETUP_INCOMING_VARARGS is defined and STRICT_ARGUMENT_NAMING is not,
+     If SETUP_INCOMING_VARARGS is defined and STRICT_ARGUMENT_NAMING is zero,
      this machine will be able to place unnamed args that were passed in
      registers into the stack.  So treat all args as named.  This allows the
      insns emitting for a specific argument list to be independent of the
@@ -976,18 +985,20 @@ expand_call (exp, target, ignore)
      If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
      way to pass unnamed args in registers, so we must force them into
      memory.  */
-#if !defined(SETUP_INCOMING_VARARGS) || defined(STRICT_ARGUMENT_NAMING)
-  if (TYPE_ARG_TYPES (funtype) != 0)
+
+  if ((STRICT_ARGUMENT_NAMING
+#ifndef SETUP_INCOMING_VARARGS
+       || 1
+#endif
+       )
+      && TYPE_ARG_TYPES (funtype) != 0)
     n_named_args
       = (list_length (TYPE_ARG_TYPES (funtype))
-#ifndef STRICT_ARGUMENT_NAMING
         /* Don't include the last named arg.  */
-        - 1
-#endif
+        - (STRICT_ARGUMENT_NAMING ? 0 : 1)
         /* Count the struct value address, if it is passed as a parm.  */
         + structure_value_addr_parm);
   else
-#endif
     /* If we know nothing, treat all args as named.  */
     n_named_args = num_actuals;
 
@@ -1162,9 +1173,7 @@ expand_call (exp, target, ignore)
 
       /* Compute the stack-size of this argument.  */
       if (args[i].reg == 0 || args[i].partial != 0
-#ifdef REG_PARM_STACK_SPACE
          || reg_parm_stack_space > 0
-#endif
          || args[i].pass_on_stack)
        locate_and_pad_parm (mode, type,
 #ifdef STACK_PARMS_IN_REG_PARM_AREA
@@ -1179,14 +1188,12 @@ expand_call (exp, target, ignore)
       args[i].slot_offset = args_size;
 #endif
 
-#ifndef REG_PARM_STACK_SPACE
       /* If a part of the arg was put into registers,
         don't include that part in the amount pushed.  */
-      if (! args[i].pass_on_stack)
+      if (reg_parm_stack_space == 0 && ! args[i].pass_on_stack)
        args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
                                  / (PARM_BOUNDARY / BITS_PER_UNIT)
                                  * (PARM_BOUNDARY / BITS_PER_UNIT));
-#endif
       
       /* Update ARGS_SIZE, the total stack space for args so far.  */
 
@@ -1243,12 +1250,11 @@ expand_call (exp, target, ignore)
        args_size.var = round_up (args_size.var, STACK_BYTES);
 #endif
 
-#ifdef REG_PARM_STACK_SPACE
       if (reg_parm_stack_space > 0)
        {
          args_size.var
            = size_binop (MAX_EXPR, args_size.var,
-                         size_int (REG_PARM_STACK_SPACE (fndecl)));
+                         size_int (reg_parm_stack_space));
 
 #ifndef OUTGOING_REG_PARM_STACK_SPACE
          /* The area corresponding to register parameters is not to count in
@@ -1258,7 +1264,6 @@ expand_call (exp, target, ignore)
                          size_int (reg_parm_stack_space));
 #endif
        }
-#endif
     }
   else
     {
@@ -1267,17 +1272,17 @@ expand_call (exp, target, ignore)
                             / STACK_BYTES) * STACK_BYTES);
 #endif
 
-#ifdef REG_PARM_STACK_SPACE
       args_size.constant = MAX (args_size.constant,
                                reg_parm_stack_space);
+
 #ifdef MAYBE_REG_PARM_STACK_SPACE
       if (reg_parm_stack_space == 0)
        args_size.constant = 0;
 #endif
+
 #ifndef OUTGOING_REG_PARM_STACK_SPACE
       args_size.constant -= reg_parm_stack_space;
 #endif
-#endif
     }
 
   /* See if we have or want to preallocate stack space.
@@ -1442,7 +1447,7 @@ expand_call (exp, target, ignore)
             Another approach might be to try to reorder the argument
             evaluations to avoid this conflicting stack usage.  */
 
-#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
+#ifndef OUTGOING_REG_PARM_STACK_SPACE
          /* Since we will be writing into the entire argument area, the
             map must be allocated for its entire size, not just the part that
             is the responsibility of the caller.  */
@@ -1514,7 +1519,7 @@ expand_call (exp, target, ignore)
      to initialize an argument.  */
   if (stack_arg_under_construction)
     {
-#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
+#ifndef OUTGOING_REG_PARM_STACK_SPACE
       rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
 #else
       rtx push_size = GEN_INT (args_size.constant);
@@ -1693,6 +1698,7 @@ expand_call (exp, target, ignore)
       }
 
 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
+
   /* The argument list is the property of the called routine and it
      may clobber it.  If the fixed area has been used for previous
      parameters, we must save and restore it.
@@ -2110,7 +2116,6 @@ expand_call (exp, target, ignore)
         Deal with them explicitly by copying from the return registers
         into the target MEM locations.  */
       int bytes = int_size_in_bytes (TREE_TYPE (exp));
-      int i;
       rtx src, dst;
       int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (exp)), BITS_PER_WORD);
       int bitpos, xbitpos, big_endian_correction = 0;
@@ -2321,6 +2326,7 @@ emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
   struct arg *argvec;
   int old_inhibit_defer_pop = inhibit_defer_pop;
   rtx call_fusage = 0;
+  int reg_parm_stack_space = 0;
 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
   /* Define the boundary of the register parm stack space that needs to be
      save, if any.  */
@@ -2336,7 +2342,6 @@ emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
 
 #ifdef REG_PARM_STACK_SPACE
   /* Size of the stack reserved for parameter registers.  */
-  int reg_parm_stack_space = 0;
 #ifdef MAYBE_REG_PARM_STACK_SPACE
   reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
 #else
@@ -2432,16 +2437,11 @@ emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
       if (argvec[count].size.var)
        abort ();
 
-#ifndef REG_PARM_STACK_SPACE
-      if (argvec[count].partial)
+      if (reg_parm_stack_space == 0 && argvec[count].partial)
        argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
-#endif
 
       if (argvec[count].reg == 0 || argvec[count].partial != 0
-#ifdef REG_PARM_STACK_SPACE
-         || 1
-#endif
-         )
+         || reg_parm_stack_space > 0)
        args_size.constant += argvec[count].size.constant;
 
       FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
@@ -2463,13 +2463,12 @@ emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
                         / STACK_BYTES) * STACK_BYTES);
 #endif
 
-#ifdef REG_PARM_STACK_SPACE
   args_size.constant = MAX (args_size.constant,
                            reg_parm_stack_space);
+
 #ifndef OUTGOING_REG_PARM_STACK_SPACE
   args_size.constant -= reg_parm_stack_space;
 #endif
-#endif
 
   if (args_size.constant > current_function_outgoing_args_size)
     current_function_outgoing_args_size = args_size.constant;
@@ -2488,7 +2487,8 @@ emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
      evaluations to avoid this conflicting stack usage.  */
 
   needed = args_size.constant;
-#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
+
+#ifndef OUTGOING_REG_PARM_STACK_SPACE
   /* Since we will be writing into the entire argument area, the
      map must be allocated for its entire size, not just the part that
      is the responsibility of the caller.  */
@@ -2637,17 +2637,14 @@ emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
 
          for (i = lower_bound; i < upper_bound; i++)
            if (stack_usage_map[i]
-#ifdef REG_PARM_STACK_SPACE
                /* Don't store things in the fixed argument area at this point;
                   it has already been saved.  */
-               && i > reg_parm_stack_space
-#endif
-               )
+               && i > reg_parm_stack_space)
              break;
 
          if (i != upper_bound)
            {
-             /* We need to make a save area.  See what mode we can make it.  */
+             /* We need to make a save area.  See what mode we can make it. */
              enum machine_mode save_mode
                = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
                                 MODE_INT, 1);
@@ -2660,7 +2657,8 @@ emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
            }
 #endif
          emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
-                         argblock, GEN_INT (argvec[argnum].offset.constant));
+                         argblock, GEN_INT (argvec[argnum].offset.constant),
+                         reg_parm_stack_space);
 
 #ifdef ACCUMULATE_OUTGOING_ARGS
          /* Now mark the segment we just used.  */
@@ -2696,7 +2694,6 @@ emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
      are to be pushed.  */
   for (count = 0; count < nargs; count++, argnum += inc)
     {
-      register enum machine_mode mode = argvec[argnum].mode;
       register rtx val = argvec[argnum].value;
       rtx reg = argvec[argnum].reg;
       int partial = argvec[argnum].partial;
@@ -2825,6 +2822,7 @@ emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
   int pcc_struct_value = 0;
   int struct_value_size = 0;
   int is_const;
+  int reg_parm_stack_space = 0;
 #ifdef ACCUMULATE_OUTGOING_ARGS
   int needed;
 #endif
@@ -2838,7 +2836,6 @@ emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
 
 #ifdef ACCUMULATE_OUTGOING_ARGS
   /* Size of the stack reserved for parameter registers.  */
-  int reg_parm_stack_space = 0;
   int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
   char *initial_stack_usage_map = stack_usage_map;
 #endif
@@ -2938,10 +2935,7 @@ emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
 
 
       if (argvec[count].reg == 0 || argvec[count].partial != 0
-#ifdef REG_PARM_STACK_SPACE
-         || 1
-#endif
-         )
+         || reg_parm_stack_space > 0)
        args_size.constant += argvec[count].size.constant;
 
       FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
@@ -3008,16 +3002,11 @@ emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
       if (argvec[count].size.var)
        abort ();
 
-#ifndef REG_PARM_STACK_SPACE
-      if (argvec[count].partial)
+      if (reg_parm_stack_space == 0 && argvec[count].partial)
        argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
-#endif
 
       if (argvec[count].reg == 0 || argvec[count].partial != 0
-#ifdef REG_PARM_STACK_SPACE
-         || 1
-#endif
-         )
+         || reg_parm_stack_space > 0)
        args_size.constant += argvec[count].size.constant;
 
       FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
@@ -3038,13 +3027,12 @@ emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
                         / STACK_BYTES) * STACK_BYTES);
 #endif
 
-#ifdef REG_PARM_STACK_SPACE
   args_size.constant = MAX (args_size.constant,
                            reg_parm_stack_space);
+
 #ifndef OUTGOING_REG_PARM_STACK_SPACE
   args_size.constant -= reg_parm_stack_space;
 #endif
-#endif
 
   if (args_size.constant > current_function_outgoing_args_size)
     current_function_outgoing_args_size = args_size.constant;
@@ -3063,7 +3051,8 @@ emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
      evaluations to avoid this conflicting stack usage.  */
 
   needed = args_size.constant;
-#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
+
+#ifndef OUTGOING_REG_PARM_STACK_SPACE
   /* Since we will be writing into the entire argument area, the
      map must be allocated for its entire size, not just the part that
      is the responsibility of the caller.  */
@@ -3212,17 +3201,14 @@ emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
 
          for (i = lower_bound; i < upper_bound; i++)
            if (stack_usage_map[i]
-#ifdef REG_PARM_STACK_SPACE
                /* Don't store things in the fixed argument area at this point;
                   it has already been saved.  */
-               && i > reg_parm_stack_space
-#endif
-               )
+               && i > reg_parm_stack_space)
              break;
 
          if (i != upper_bound)
            {
-             /* We need to make a save area.  See what mode we can make it.  */
+             /* We need to make a save area.  See what mode we can make it. */
              enum machine_mode save_mode
                = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
                                 MODE_INT, 1);
@@ -3236,7 +3222,8 @@ emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
            }
 #endif
          emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
-                         argblock, GEN_INT (argvec[argnum].offset.constant));
+                         argblock, GEN_INT (argvec[argnum].offset.constant),
+                         reg_parm_stack_space);
 
 #ifdef ACCUMULATE_OUTGOING_ARGS
          /* Now mark the segment we just used.  */
@@ -3272,7 +3259,6 @@ emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
      are to be pushed.  */
   for (count = 0; count < nargs; count++, argnum += inc)
     {
-      register enum machine_mode mode = argvec[argnum].mode;
       register rtx val = argvec[argnum].value;
       rtx reg = argvec[argnum].reg;
       int partial = argvec[argnum].partial;
@@ -3492,12 +3478,9 @@ store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
 
       for (i = lower_bound; i < upper_bound; i++)
        if (stack_usage_map[i]
-#ifdef REG_PARM_STACK_SPACE
            /* Don't store things in the fixed argument area at this point;
               it has already been saved.  */
-           && i > reg_parm_stack_space
-#endif
-           )
+           && i > reg_parm_stack_space)
          break;
 
       if (i != upper_bound)
@@ -3643,9 +3626,9 @@ store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
 
       /* This isn't already where we want it on the stack, so put it there.
         This can either be done with push or copy insns.  */
-      emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
-                     0, partial, reg, used - size,
-                     argblock, ARGS_SIZE_RTX (arg->offset));
+      emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 0,
+                     partial, reg, used - size, argblock,
+                     ARGS_SIZE_RTX (arg->offset), reg_parm_stack_space);
     }
   else
     {
@@ -3677,7 +3660,8 @@ store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
 
       emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
                      TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
-                     reg, excess, argblock, ARGS_SIZE_RTX (arg->offset));
+                     reg, excess, argblock, ARGS_SIZE_RTX (arg->offset),
+                     reg_parm_stack_space);
     }