OSDN Git Service

* gcj.texi (Input and output files): Mention non-class entries.
[pf3gnuchains/gcc-fork.git] / gcc / calls.c
index ffedaca..1c51e1a 100644 (file)
@@ -21,6 +21,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "rtl.h"
 #include "tree.h"
 #include "flags.h"
@@ -36,10 +38,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "langhooks.h"
 #include "target.h"
 
-#if !defined FUNCTION_OK_FOR_SIBCALL
-#define FUNCTION_OK_FOR_SIBCALL(DECL) 1
-#endif
-
 /* Decide whether a function's arguments should be processed
    from first to last or from last to first.
 
@@ -48,9 +46,11 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #ifdef PUSH_ROUNDING
 
+#ifndef PUSH_ARGS_REVERSED
 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
 #define PUSH_ARGS_REVERSED  PUSH_ARGS
 #endif
+#endif
 
 #endif
 
@@ -152,35 +152,6 @@ int stack_arg_under_construction;
 static int calls_function      PARAMS ((tree, int));
 static int calls_function_1    PARAMS ((tree, int));
 
-/* Nonzero if this is a call to a `const' function.  */
-#define ECF_CONST              1
-/* Nonzero if this is a call to a `volatile' function.  */
-#define ECF_NORETURN           2
-/* Nonzero if this is a call to malloc or a related function.  */
-#define ECF_MALLOC             4
-/* Nonzero if it is plausible that this is a call to alloca.  */
-#define ECF_MAY_BE_ALLOCA      8
-/* Nonzero if this is a call to a function that won't throw an exception.  */
-#define ECF_NOTHROW            16
-/* Nonzero if this is a call to setjmp or a related function.  */
-#define ECF_RETURNS_TWICE      32
-/* Nonzero if this is a call to `longjmp'.  */
-#define ECF_LONGJMP            64
-/* Nonzero if this is a syscall that makes a new process in the image of
-   the current one.  */
-#define ECF_FORK_OR_EXEC       128
-#define ECF_SIBCALL            256
-/* Nonzero if this is a call to "pure" function (like const function,
-   but may read memory.  */
-#define ECF_PURE               512
-/* Nonzero if this is a call to a function that returns with the stack
-   pointer depressed.  */
-#define ECF_SP_DEPRESSED       1024
-/* Nonzero if this call is known to always return.  */
-#define ECF_ALWAYS_RETURN      2048
-/* Create libcall block around the call.  */
-#define ECF_LIBCALL_BLOCK      4096
-
 static void emit_call_1                PARAMS ((rtx, tree, tree, HOST_WIDE_INT,
                                         HOST_WIDE_INT, HOST_WIDE_INT, rtx,
                                         rtx, int, rtx, int,
@@ -211,20 +182,22 @@ static void compute_argument_addresses            PARAMS ((struct arg_data *,
                                                         rtx, int));
 static rtx rtx_for_function_call               PARAMS ((tree, tree));
 static void load_register_parameters           PARAMS ((struct arg_data *,
-                                                        int, rtx *, int));
+                                                        int, rtx *, int,
+                                                        int, int *));
 static rtx emit_library_call_value_1           PARAMS ((int, rtx, rtx,
                                                         enum libcall_type,
                                                         enum machine_mode,
                                                         int, va_list));
 static int special_function_p                  PARAMS ((tree, int));
-static int flags_from_decl_or_type             PARAMS ((tree));
 static rtx try_to_integrate                    PARAMS ((tree, tree, rtx,
                                                         int, tree, rtx));
 static int check_sibcall_argument_overlap_1    PARAMS ((rtx));
-static int check_sibcall_argument_overlap      PARAMS ((rtx, struct arg_data *));
+static int check_sibcall_argument_overlap      PARAMS ((rtx, struct arg_data *,
+                                                        int));
 
 static int combine_pending_stack_adjustment_and_call
                                                 PARAMS ((int, struct args_size *, int));
+static tree fix_unsafe_tree            PARAMS ((tree));
 
 #ifdef REG_PARM_STACK_SPACE
 static rtx save_fixed_argument_area    PARAMS ((int, rtx, int *, int *));
@@ -799,9 +772,24 @@ setjmp_call_p (fndecl)
   return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
 }
 
+/* Return true when exp contains alloca call.  */
+bool
+alloca_call_p (exp)
+     tree exp;
+{
+  if (TREE_CODE (exp) == CALL_EXPR
+      && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
+      && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
+         == FUNCTION_DECL)
+      && (special_function_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
+                             0) & ECF_MAY_BE_ALLOCA))
+    return true;
+  return false;
+}
+
 /* Detect flags (function attributes) from the function decl or type node.  */
 
-static int
+int
 flags_from_decl_or_type (exp)
      tree exp;
 {
@@ -876,6 +864,12 @@ precompute_register_parameters (num_actuals, args, reg_parm_seen)
            emit_queue ();
          }
 
+       /* If the value is a non-legitimate constant, force it into a
+          pseudo now.  TLS symbols sometimes need a call to resolve.  */
+       if (CONSTANT_P (args[i].value)
+           && !LEGITIMATE_CONSTANT_P (args[i].value))
+         args[i].value = force_reg (args[i].mode, args[i].value);
+
        /* If we are to promote the function arg to a wider mode,
           do it now.  */
 
@@ -1048,7 +1042,6 @@ store_unaligned_arguments_into_pseudos (args, num_actuals)
           this means we must skip the empty high order bytes when
           calculating the bit offset.  */
        if (BYTES_BIG_ENDIAN
-           && !FUNCTION_ARG_REG_LITTLE_ENDIAN
            && bytes < UNITS_PER_WORD)
          big_endian_correction = (BITS_PER_WORD  - (bytes * BITS_PER_UNIT));
 
@@ -1695,10 +1688,8 @@ rtx_for_function_call (fndecl, exp)
   else
     /* Generate an rtx (probably a pseudo-register) for the address.  */
     {
-      rtx funaddr;
       push_temp_slots ();
-      funaddr = funexp
-       = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
+      funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
       pop_temp_slots ();       /* FUNEXP can't be BLKmode.  */
       emit_queue ();
     }
@@ -1710,14 +1701,20 @@ rtx_for_function_call (fndecl, exp)
    expressions were already evaluated.
 
    Mark all register-parms as living through the call, putting these USE
-   insns in the CALL_INSN_FUNCTION_USAGE field.  */
+   insns in the CALL_INSN_FUNCTION_USAGE field.  
+   When IS_SIBCALL, perform the check_sibcall_overlap_argument_overlap
+   checking, setting *SIBCALL_FAILURE if appropriate.  */
 
 static void
-load_register_parameters (args, num_actuals, call_fusage, flags)
+load_register_parameters (args, num_actuals, call_fusage, flags, 
+                           is_sibcall, sibcall_failure)
      struct arg_data *args;
      int num_actuals;
      rtx *call_fusage;
      int flags;
+     int is_sibcall;
+     int *sibcall_failure;
 {
   int i, j;
 
@@ -1734,6 +1731,7 @@ load_register_parameters (args, num_actuals, call_fusage, flags)
 
       if (reg)
        {
+         rtx before_arg = get_last_insn ();
          /* Set to non-negative if must move a word at a time, even if just
             one word (e.g, partial == 1 && mode == DFmode).  Set to -1 if
             we just use a normal move insn.  This value can be zero if the
@@ -1771,6 +1769,13 @@ load_register_parameters (args, num_actuals, call_fusage, flags)
                               validize_mem (args[i].value), nregs,
                               args[i].mode);
 
+         /* When a parameter is a block, and perhaps in other cases, it is
+            possible that it did a load from an argument slot that was
+            already clobbered.  */
+         if (is_sibcall
+             && check_sibcall_argument_overlap (before_arg, &args[i], 0))
+           *sibcall_failure = 1;
+
          /* Handle calls that pass values in multiple non-contiguous
             locations.  The Irix 6 ABI has examples of this.  */
          if (GET_CODE (reg) == PARALLEL)
@@ -2027,14 +2032,16 @@ check_sibcall_argument_overlap_1 (x)
 
 /* Scan sequence after INSN if it does not dereference any argument slots
    we already clobbered by tail call arguments (as noted in stored_args_map
-   bitmap).  Add stack slots for ARG to stored_args_map bitmap afterwards.
-   Return nonzero if sequence after INSN dereferences such argument slots,
-   zero otherwise.  */
+   bitmap).  If MARK_STORED_ARGS_MAP, add stack slots for ARG to
+   stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
+   should be 0).  Return nonzero if sequence after INSN dereferences such argument
+   slots, zero otherwise.  */
 
 static int
-check_sibcall_argument_overlap (insn, arg)
+check_sibcall_argument_overlap (insn, arg, mark_stored_args_map)
      rtx insn;
      struct arg_data *arg;
+     int mark_stored_args_map;
 {
   int low, high;
 
@@ -2048,17 +2055,49 @@ check_sibcall_argument_overlap (insn, arg)
        && check_sibcall_argument_overlap_1 (PATTERN (insn)))
       break;
 
+  if (mark_stored_args_map)
+    {
 #ifdef ARGS_GROW_DOWNWARD
-  low = -arg->slot_offset.constant - arg->size.constant;
+      low = -arg->slot_offset.constant - arg->size.constant;
 #else
-  low = arg->slot_offset.constant;
+      low = arg->slot_offset.constant;
 #endif
 
-  for (high = low + arg->size.constant; low < high; low++)
-    SET_BIT (stored_args_map, low);
+      for (high = low + arg->size.constant; low < high; low++)
+       SET_BIT (stored_args_map, low);
+    }
   return insn != NULL_RTX;
 }
 
+static tree
+fix_unsafe_tree (t)
+     tree t;
+{
+  switch (unsafe_for_reeval (t))
+    {
+    case 0: /* Safe.  */
+      break;
+
+    case 1: /* Mildly unsafe.  */
+      t = unsave_expr (t);
+      break;
+
+    case 2: /* Wildly unsafe.  */
+      {
+       tree var = build_decl (VAR_DECL, NULL_TREE,
+                              TREE_TYPE (t));
+       SET_DECL_RTL (var,
+                     expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL));
+       t = var;
+      }
+      break;
+
+    default:
+      abort ();
+    }
+  return t;
+}
+
 /* Generate all the code for a function call
    and return an rtx for its value.
    Store the value in TARGET (specified as an rtx) if convenient.
@@ -2259,7 +2298,17 @@ expand_call (exp, target, ignore)
       {
        struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
 
-       if (target && GET_CODE (target) == MEM)
+       if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (exp))
+         {
+           /* The structure value address arg is already in actparms.
+              Pull it out.  It might be nice to just leave it there, but
+              we need to set structure_value_addr.  */
+           tree return_arg = TREE_VALUE (actparms);
+           actparms = TREE_CHAIN (actparms);
+           structure_value_addr = expand_expr (return_arg, NULL_RTX,
+                                               VOIDmode, EXPAND_NORMAL);
+         }
+       else if (target && GET_CODE (target) == MEM)
          structure_value_addr = XEXP (target, 0);
        else
          {
@@ -2445,17 +2494,13 @@ expand_call (exp, target, ignore)
         It does not seem worth the effort since few optimizable
         sibling calls will return a structure.  */
       || structure_value_addr != NULL_RTX
-      /* If the register holding the address is a callee saved
-        register, then we lose.  We have no way to prevent that,
-        so we only allow calls to named functions.  */
-      /* ??? This could be done by having the insn constraints
-        use a register class that is all call-clobbered.  Any
-        reload insns generated to fix things up would appear
-        before the sibcall_epilogue.  */
-      || fndecl == NULL_TREE
-      || (flags & (ECF_RETURNS_TWICE | ECF_LONGJMP))
-      || TREE_THIS_VOLATILE (fndecl)
-      || !FUNCTION_OK_FOR_SIBCALL (fndecl)
+      /* Check whether the target is able to optimize the call
+        into a sibcall.  */
+      || !(*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))
+      || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
       /* If this function requires more stack slots than the current
         function, we cannot change it into a sibling call.  */
       || args_size.constant > current_function_args_size
@@ -2501,35 +2546,16 @@ expand_call (exp, target, ignore)
 
       for (; i != end; i += inc)
        {
-         switch (unsafe_for_reeval (args[i].tree_value))
-           {
-           case 0: /* Safe.  */
-             break;
-
-           case 1: /* Mildly unsafe.  */
-             args[i].tree_value = unsave_expr (args[i].tree_value);
-             break;
-
-           case 2: /* Wildly unsafe.  */
-             {
-               tree var = build_decl (VAR_DECL, NULL_TREE,
-                                      TREE_TYPE (args[i].tree_value));
-               SET_DECL_RTL (var,
-                             expand_expr (args[i].tree_value, NULL_RTX,
-                                          VOIDmode, EXPAND_NORMAL));
-               args[i].tree_value = var;
-             }
-             break;
-
-           default:
-             abort ();
-           }
+          args[i].tree_value = fix_unsafe_tree (args[i].tree_value);
          /* We need to build actparms for optimize_tail_recursion.  We can
             safely trash away TREE_PURPOSE, since it is unused by this
             function.  */
          if (try_tail_recursion)
            actparms = tree_cons (NULL_TREE, args[i].tree_value, actparms);
        }
+      /* Do the same for the function address if it is an expression. */
+      if (!fndecl)
+        TREE_OPERAND (exp, 0) = fix_unsafe_tree (TREE_OPERAND (exp, 0));
       /* Expanding one of those dangerous arguments could have added
         cleanups, but otherwise give it a whirl.  */
       if (any_pending_cleanups (1))
@@ -2587,7 +2613,7 @@ expand_call (exp, target, ignore)
         is subject to race conditions, just as with multithreaded
         programs.  */
 
-      emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__bb_fork_func"),
+      emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__gcov_flush"),
                         LCT_ALWAYS_RETURN,
                         VOIDmode, 0);
     }
@@ -2965,7 +2991,7 @@ expand_call (exp, target, ignore)
                               reg_parm_stack_space)
                || (pass == 0
                    && check_sibcall_argument_overlap (before_arg,
-                                                      &args[i])))
+                                                      &args[i], 1)))
              sibcall_failure = 1;
          }
 
@@ -2989,7 +3015,7 @@ expand_call (exp, target, ignore)
                                 reg_parm_stack_space)
                  || (pass == 0
                      && check_sibcall_argument_overlap (before_arg,
-                                                        &args[i])))
+                                                        &args[i], 1)))
                sibcall_failure = 1;
            }
 
@@ -3024,7 +3050,8 @@ expand_call (exp, target, ignore)
       funexp = prepare_call_address (funexp, fndecl, &call_fusage,
                                     reg_parm_seen, pass == 0);
 
-      load_register_parameters (args, num_actuals, &call_fusage, flags);
+      load_register_parameters (args, num_actuals, &call_fusage, flags,
+                               pass == 0, &sibcall_failure);
 
       /* Perform postincrements before actually calling the function.  */
       emit_queue ();
@@ -4537,7 +4564,7 @@ store_one_arg (arg, argblock, flags, variable_size, reg_parm_stack_space)
            parm_align = BITS_PER_UNIT;
          else if (excess)
            {
-             int excess_align = (excess & -excess) * BITS_PER_UNIT;
+             unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT;
              parm_align = MIN (parm_align, excess_align);
            }
        }
@@ -4640,3 +4667,48 @@ store_one_arg (arg, argblock, flags, variable_size, reg_parm_stack_space)
 
   return sibcall_failure;
 }
+
+
+/* Nonzero if we do not know how to pass TYPE solely in registers.
+   We cannot do so in the following cases:
+
+   - if the type has variable size
+   - if the type is marked as addressable (it is required to be constructed
+     into the stack)
+   - if the padding and mode of the type is such that a copy into a register
+     would put it into the wrong part of the register.
+
+   Which padding can't be supported depends on the byte endianness.
+
+   A value in a register is implicitly padded at the most significant end.
+   On a big-endian machine, that is the lower end in memory.
+   So a value padded in memory at the upper end can't go in a register.
+   For a little-endian machine, the reverse is true.  */
+
+bool
+default_must_pass_in_stack (mode, type)
+     enum machine_mode mode;
+     tree type;
+{
+  if (!type)
+    return true;
+
+  /* If the type has variable size...  */
+  if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
+    return true;
+
+  /* If the type is marked as addressable (it is required
+     to be constructed into the stack)...  */
+  if (TREE_ADDRESSABLE (type))
+    return true;
+
+  /* If the padding and mode of the type is such that a copy into
+     a register would put it into the wrong part of the register.  */
+  if (mode == BLKmode
+      && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT)
+      && (FUNCTION_ARG_PADDING (mode, type)
+         == (BYTES_BIG_ENDIAN ? upward : downward)))
+    return true;
+
+  return false;
+}