OSDN Git Service

* doc/install.texi (Specific, mips-sgi-irix5): Reflect working
[pf3gnuchains/gcc-fork.git] / gcc / calls.c
index b4d66f9..44d6360 100644 (file)
@@ -133,7 +133,8 @@ static int compute_argument_block_size (int, struct args_size *, int);
 static void initialize_argument_information (int, struct arg_data *,
                                             struct args_size *, int, tree,
                                             tree, CUMULATIVE_ARGS *, int,
-                                            rtx *, int *, int *, int *);
+                                            rtx *, int *, int *, int *,
+                                            bool);
 static void compute_argument_addresses (struct arg_data *, rtx, int);
 static rtx rtx_for_function_call (tree, tree);
 static void load_register_parameters (struct arg_data *, int, rtx *, int,
@@ -725,10 +726,9 @@ flags_from_decl_or_type (tree exp)
        flags |= ECF_NOTHROW;
 
       if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
-       flags |= ECF_LIBCALL_BLOCK;
+       flags |= ECF_LIBCALL_BLOCK | ECF_CONST;
     }
-
-  if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
+  else if (TYPE_P (exp) && TYPE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
     flags |= ECF_CONST;
 
   if (TREE_THIS_VOLATILE (exp))
@@ -1023,7 +1023,10 @@ store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
    and may be modified by this routine.
 
    OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
-   flags which may may be modified by this routine.  */
+   flags which may may be modified by this routine. 
+
+   CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
+   the thunked-to function.  */
 
 static void
 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
@@ -1034,7 +1037,8 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
                                 CUMULATIVE_ARGS *args_so_far,
                                 int reg_parm_stack_space,
                                 rtx *old_stack_level, int *old_pending_adj,
-                                int *must_preallocate, int *ecf_flags)
+                                int *must_preallocate, int *ecf_flags,
+                                bool call_from_thunk_p)
 {
   /* 1 if scanning parms front to back, -1 if scanning back to front.  */
   int inc;
@@ -1107,7 +1111,7 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
        {
          /* If we're compiling a thunk, pass through invisible
              references instead of making a copy.  */
-         if (current_function_is_thunk
+         if (call_from_thunk_p
 #ifdef FUNCTION_ARG_CALLEE_COPIES
              || (FUNCTION_ARG_CALLEE_COPIES (*args_so_far, TYPE_MODE (type),
                                             type, argpos < n_named_args)
@@ -1190,7 +1194,7 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
        }
 
       mode = TYPE_MODE (type);
-      unsignedp = TREE_UNSIGNED (type);
+      unsignedp = TYPE_UNSIGNED (type);
 
       if (targetm.calls.promote_function_args (fndecl ? TREE_TYPE (fndecl) : 0))
        mode = promote_mode (type, mode, &unsignedp, 1);
@@ -1344,11 +1348,6 @@ compute_argument_block_size (int 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
@@ -1371,20 +1370,16 @@ precompute_arguments (int flags, int num_actuals, struct arg_data *args)
 {
   int i;
 
-  /* If this function call is cse'able, precompute all the parameters.
-     Note that if the parameter is constructed into a temporary, this will
-     cause an additional copy because the parameter will be constructed
-     into a temporary location and then copied into the outgoing arguments.
-     If a parameter contains a call to alloca and this function uses the
-     stack, precompute the parameter.  */
-
-  /* If we preallocated the stack space, and some arguments must be passed
-     on the stack, then we must precompute any parameter which contains a
-     function call which will store arguments on the stack.
-     Otherwise, evaluating the parameter may clobber previous parameters
-     which have already been stored into the stack.  (we have code to avoid
-     such case by saving the outgoing stack arguments, but it results in
-     worse code)  */
+  /* If this is a libcall, then precompute all arguments so that we do not
+     get extraneous instructions emitted as part of the libcall sequence.
+
+     If this target defines ACCUMULATE_OUTGOING_ARGS to true, then we must
+     precompute all arguments that contain function calls.  Otherwise,
+     computing arguments for a subcall may clobber arguments for this call.
+
+     If this target defines ACCUMULATE_OUTGOING_ARGS to false, then we only
+     need to precompute arguments that change the stack pointer, such as calls
+     to alloca, and calls that do not pop all of their arguments.  */
 
   for (i = 0; i < num_actuals; i++)
     if ((flags & ECF_LIBCALL_BLOCK)
@@ -1679,10 +1674,14 @@ load_register_parameters (struct arg_data *args, int num_actuals,
            {
              rtx mem = validize_mem (args[i].value);
 
-#ifdef BLOCK_REG_PADDING
              /* Handle a BLKmode that needs shifting.  */
              if (nregs == 1 && size < UNITS_PER_WORD
-                 && args[i].locate.where_pad == downward)
+#ifdef BLOCK_REG_PADDING
+                 && args[i].locate.where_pad == downward
+#else
+                 && BYTES_BIG_ENDIAN
+#endif
+                )
                {
                  rtx tem = operand_subword_force (mem, 0, args[i].mode);
                  rtx ri = gen_rtx_REG (word_mode, REGNO (reg));
@@ -1697,7 +1696,6 @@ load_register_parameters (struct arg_data *args, int num_actuals,
                    emit_move_insn (ri, x);
                }
              else
-#endif
                move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
            }
 
@@ -1734,12 +1732,8 @@ try_to_integrate (tree fndecl, tree actparms, rtx target, int ignore,
   int reg_parm_stack_space = 0;
 
 #ifdef REG_PARM_STACK_SPACE
-#ifdef MAYBE_REG_PARM_STACK_SPACE
-  reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
-#else
   reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
 #endif
-#endif
 
   before_call = get_last_insn ();
 
@@ -1773,11 +1767,11 @@ try_to_integrate (tree fndecl, tree actparms, rtx target, int ignore,
              rtx insn = NULL_RTX, seq;
 
              /* Look for a call in the inline function code.
-                If DECL_SAVED_INSNS (fndecl)->outgoing_args_size is
+                If DECL_STRUCT_FUNCTION (fndecl)->outgoing_args_size is
                 nonzero then there is a call and it is not necessary
                 to scan the insns.  */
 
-             if (DECL_SAVED_INSNS (fndecl)->outgoing_args_size == 0)
+             if (DECL_STRUCT_FUNCTION (fndecl)->outgoing_args_size == 0)
                for (insn = first_insn; insn; insn = NEXT_INSN (insn))
                  if (GET_CODE (insn) == CALL_INSN)
                    break;
@@ -1801,8 +1795,9 @@ try_to_integrate (tree fndecl, tree actparms, rtx target, int ignore,
                     value of reg_parm_stack_space is wrong, but gives
                     correct results on all supported machines.  */
 
-                 int adjust = (DECL_SAVED_INSNS (fndecl)->outgoing_args_size
-                               + reg_parm_stack_space);
+                 int adjust =
+                       (DECL_STRUCT_FUNCTION (fndecl)->outgoing_args_size
+                        + reg_parm_stack_space);
 
                  start_sequence ();
                  emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
@@ -1833,7 +1828,7 @@ try_to_integrate (tree fndecl, tree actparms, rtx target, int ignore,
       warning ("%Jinlining failed in call to '%F'", fndecl, fndecl);
       warning ("called from here");
     }
-  (*lang_hooks.mark_addressable) (fndecl);
+  lang_hooks.mark_addressable (fndecl);
   return (rtx) (size_t) - 1;
 }
 
@@ -2075,6 +2070,8 @@ expand_call (tree exp, rtx target, int ignore)
   /* Declaration of the function being called,
      or 0 if the function is computed (not known by name).  */
   tree fndecl = 0;
+  /* The type of the function being called.  */
+  tree fntype;
   rtx insn;
   int try_tail_call = 1;
   int try_tail_recursion = 1;
@@ -2183,11 +2180,12 @@ expand_call (tree exp, rtx target, int ignore)
   fndecl = get_callee_fndecl (exp);
   if (fndecl)
     {
+      fntype = TREE_TYPE (fndecl);
       if (!flag_no_inline
          && fndecl != current_function_decl
          && DECL_INLINE (fndecl)
-         && DECL_SAVED_INSNS (fndecl)
-         && DECL_SAVED_INSNS (fndecl)->inlinable)
+         && DECL_STRUCT_FUNCTION (fndecl)
+         && DECL_STRUCT_FUNCTION (fndecl)->inlinable)
        is_integrable = 1;
       else if (! TREE_ADDRESSABLE (fndecl))
        {
@@ -2202,7 +2200,7 @@ expand_call (tree exp, rtx target, int ignore)
              warning ("%Jcan't inline call to '%F'", fndecl, fndecl);
              warning ("called from here");
            }
-         (*lang_hooks.mark_addressable) (fndecl);
+         lang_hooks.mark_addressable (fndecl);
        }
 
       if (ignore
@@ -2218,15 +2216,15 @@ expand_call (tree exp, rtx target, int ignore)
      attributes set in the type.  */
   else
     {
+      fntype = TREE_TYPE (TREE_TYPE (p));
       if (ignore
-         && lookup_attribute ("warn_unused_result",
-                              TYPE_ATTRIBUTES (TREE_TYPE (TREE_TYPE (p)))))
+         && lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (fntype)))
        warning ("ignoring return value of function "
                 "declared with attribute warn_unused_result");
-      flags |= flags_from_decl_or_type (TREE_TYPE (TREE_TYPE (p)));
+      flags |= flags_from_decl_or_type (fntype);
     }
 
-  struct_value = targetm.calls.struct_value_rtx (fndecl ? TREE_TYPE (fndecl) : 0, 0);
+  struct_value = targetm.calls.struct_value_rtx (fntype, 0);
 
   /* Warn if this value is an aggregate type,
      regardless of which calling convention we are using for it.  */
@@ -2260,12 +2258,8 @@ expand_call (tree exp, rtx target, int ignore)
     }
 
 #ifdef REG_PARM_STACK_SPACE
-#ifdef MAYBE_REG_PARM_STACK_SPACE
-  reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
-#else
   reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
 #endif
-#endif
 
 #ifndef OUTGOING_REG_PARM_STACK_SPACE
   if (reg_parm_stack_space > 0 && PUSH_ARGS)
@@ -2289,7 +2283,7 @@ expand_call (tree exp, rtx target, int ignore)
            /* In case this is a static function, note that it has been
               used.  */
            if (! TREE_ADDRESSABLE (fndecl))
-             (*lang_hooks.mark_addressable) (fndecl);
+             lang_hooks.mark_addressable (fndecl);
            is_integrable = 0;
          }
       }
@@ -2352,7 +2346,7 @@ expand_call (tree exp, rtx target, int ignore)
 
   /* Munge the tree to split complex arguments into their imaginary
      and real parts.  */
-  if (SPLIT_COMPLEX_ARGS)
+  if (targetm.calls.split_complex_arg)
     {
       type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
       actparms = split_complex_values (actparms);
@@ -2380,7 +2374,8 @@ expand_call (tree exp, rtx target, int ignore)
                  || (ACCUMULATE_OUTGOING_ARGS
                      && stack_arg_under_construction
                      && structure_value_addr == virtual_outgoing_args_rtx)
-                 ? copy_addr_to_reg (structure_value_addr)
+                 ? copy_addr_to_reg (convert_memory_address 
+                                     (Pmode, structure_value_addr))
                  : structure_value_addr);
 
       actparms
@@ -2395,14 +2390,6 @@ expand_call (tree exp, rtx target, int ignore)
   for (p = actparms, num_actuals = 0; p; p = TREE_CHAIN (p))
     num_actuals++;
 
-  /* Start updating where the next arg would go.
-
-     On some machines (such as the PA) indirect calls have a different
-     calling convention than normal calls.  The last argument in
-     INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
-     or not.  */
-  INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, fndecl);
-
   /* 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
@@ -2434,6 +2421,14 @@ expand_call (tree exp, rtx target, int ignore)
     /* If we know nothing, treat all args as named.  */
     n_named_args = num_actuals;
 
+  /* Start updating where the next arg would go.
+
+     On some machines (such as the PA) indirect calls have a different
+     calling convention than normal calls.  The fourth argument in
+     INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
+     or not.  */
+  INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, fndecl, n_named_args);
+
   /* Make a vector to hold all the information about each arg.  */
   args = alloca (num_actuals * sizeof (struct arg_data));
   memset (args, 0, num_actuals * sizeof (struct arg_data));
@@ -2444,7 +2439,8 @@ expand_call (tree exp, rtx target, int ignore)
                                   n_named_args, actparms, fndecl,
                                   &args_so_far, reg_parm_stack_space,
                                   &old_stack_level, &old_pending_adj,
-                                  &must_preallocate, &flags);
+                                  &must_preallocate, &flags,
+                                  CALL_FROM_THUNK_P (exp));
 
   if (args_size.var)
     {
@@ -2517,7 +2513,7 @@ expand_call (tree exp, rtx target, int ignore)
       || structure_value_addr != NULL_RTX
       /* Check whether the target is able to optimize the call
         into a sibcall.  */
-      || !(*targetm.function_ok_for_sibcall) (fndecl, exp)
+      || !targetm.function_ok_for_sibcall (fndecl, exp)
       /* Functions that do not return exactly once may not be sibcall
          optimized.  */
       || (flags & (ECF_RETURNS_TWICE | ECF_LONGJMP | ECF_NORETURN))
@@ -2535,7 +2531,7 @@ expand_call (tree exp, rtx target, int ignore)
          != RETURN_POPS_ARGS (current_function_decl,
                               TREE_TYPE (current_function_decl),
                               current_function_args_size))
-      || !(*lang_hooks.decls.ok_for_sibcall) (fndecl))
+      || !lang_hooks.decls.ok_for_sibcall (fndecl))
     try_tail_call = 0;
 
   if (try_tail_call || try_tail_recursion)
@@ -2722,10 +2718,6 @@ expand_call (tree exp, rtx target, int ignore)
       if (pass && (flags & ECF_LIBCALL_BLOCK))
        NO_DEFER_POP;
 
-#ifdef FINAL_REG_PARM_STACK_SPACE
-      reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
-                                                        args_size.var);
-#endif
       /* Precompute any arguments as needed.  */
       if (pass)
        precompute_arguments (flags, num_actuals, args);
@@ -3353,7 +3345,7 @@ expand_call (tree exp, rtx target, int ignore)
          && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
        {
          tree type = TREE_TYPE (exp);
-         int unsignedp = TREE_UNSIGNED (type);
+         int unsignedp = TYPE_UNSIGNED (type);
          int offset = 0;
 
          /* If we don't promote as expected, something is wrong.  */
@@ -3549,7 +3541,7 @@ expand_call (tree exp, rtx target, int ignore)
   if (flags & ECF_SP_DEPRESSED)
     {
       clear_pending_stack_adjust ();
-      emit_insn (gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx));
+      emit_insn (gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx));
       emit_move_insn (virtual_stack_dynamic_rtx, stack_pointer_rtx);
       save_stack_pointer ();
     }
@@ -3564,6 +3556,17 @@ split_complex_values (tree values)
 {
   tree p;
 
+  /* Before allocating memory, check for the common case of no complex.  */
+  for (p = values; p; p = TREE_CHAIN (p))
+    {
+      tree type = TREE_TYPE (TREE_VALUE (p));
+      if (type && TREE_CODE (type) == COMPLEX_TYPE
+         && targetm.calls.split_complex_arg (type))
+        goto found;
+    }
+  return values;
+
+ found:
   values = copy_list (values);
 
   for (p = values; p; p = TREE_CHAIN (p))
@@ -3575,7 +3578,8 @@ split_complex_values (tree values)
       if (!complex_type)
        continue;
 
-      if (TREE_CODE (complex_type) == COMPLEX_TYPE)
+      if (TREE_CODE (complex_type) == COMPLEX_TYPE
+         && targetm.calls.split_complex_arg (complex_type))
        {
          tree subtype;
          tree real, imag, next;
@@ -3606,13 +3610,25 @@ split_complex_types (tree types)
 {
   tree p;
 
+  /* Before allocating memory, check for the common case of no complex.  */
+  for (p = types; p; p = TREE_CHAIN (p))
+    {
+      tree type = TREE_VALUE (p);
+      if (TREE_CODE (type) == COMPLEX_TYPE
+         && targetm.calls.split_complex_arg (type))
+        goto found;
+    }
+  return types;
+
+ found:
   types = copy_list (types);
 
   for (p = types; p; p = TREE_CHAIN (p))
     {
       tree complex_type = TREE_VALUE (p);
 
-      if (TREE_CODE (complex_type) == COMPLEX_TYPE)
+      if (TREE_CODE (complex_type) == COMPLEX_TYPE
+         && targetm.calls.split_complex_arg (complex_type))
        {
          tree next, imag;
 
@@ -3688,12 +3704,8 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
   rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
 
 #ifdef REG_PARM_STACK_SPACE
-#ifdef MAYBE_REG_PARM_STACK_SPACE
-  reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
-#else
   reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
 #endif
-#endif
 
   /* By default, library functions can not throw.  */
   flags = ECF_NOTHROW;
@@ -3738,7 +3750,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
      decide where in memory it should come back.  */
   if (outmode != VOIDmode)
     {
-      tfom = (*lang_hooks.types.type_for_mode) (outmode, 0);
+      tfom = lang_hooks.types.type_for_mode (outmode, 0);
       if (aggregate_value_p (tfom, 0))
        {
 #ifdef PCC_STATIC_STRUCT_RETURN
@@ -3777,7 +3789,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
   INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far, outmode, fun);
 #else
-  INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
+  INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0, nargs);
 #endif
 
   args_size.constant = 0;
@@ -3883,13 +3895,13 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
            slot = val;
          else if (must_copy)
            {
-             slot = assign_temp ((*lang_hooks.types.type_for_mode) (mode, 0),
+             slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0),
                                  0, 1, 1);
              emit_move_insn (slot, val);
            }
          else
            {
-             tree type = (*lang_hooks.types.type_for_mode) (mode, 0);
+             tree type = lang_hooks.types.type_for_mode (mode, 0);
 
              slot
                = gen_rtx_MEM (mode,
@@ -3944,10 +3956,6 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
       FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
     }
 
-#ifdef FINAL_REG_PARM_STACK_SPACE
-  reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
-                                                    args_size.var);
-#endif
   /* If this machine requires an external definition for library
      functions, write one out.  */
   assemble_external_libcall (fun);