/* Convert function calls to rtl insns, for GNU C compiler.
- Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998
- 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+ 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GCC.
#include "tree.h"
#include "flags.h"
#include "expr.h"
+#include "optabs.h"
#include "libfuncs.h"
#include "function.h"
#include "regs.h"
#include "cgraph.h"
#include "except.h"
-#ifndef STACK_POINTER_OFFSET
-#define STACK_POINTER_OFFSET 0
-#endif
-
/* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
#define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
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,
static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
int);
static tree fix_unsafe_tree (tree);
+static bool shift_returned_value (tree, rtx *);
#ifdef REG_PARM_STACK_SPACE
static rtx save_fixed_argument_area (int, rtx, int *, int *);
break;
}
- /* Only expressions, references, and blocks can contain calls. */
- if (! IS_EXPR_CODE_CLASS (class) && class != 'r' && class != 'b')
+ /* Only expressions and blocks can contain calls. */
+ if (! IS_EXPR_CODE_CLASS (class) && class != 'b')
return 0;
for (i = 0; i < length; i++)
/* Get possible static chain value for nested function in C. */
static_chain_value = lookup_static_chain (fndecl);
- /* Make a valid memory address and copy constants thru pseudo-regs,
+ /* Make a valid memory address and copy constants through pseudo-regs,
but not for a constant address if -fno-function-cse. */
if (GET_CODE (funexp) != SYMBOL_REF)
/* If we are using registers for parameters, force the
if (rounded_stack_size != 0)
{
- if (ecf_flags & ECF_SP_DEPRESSED)
+ if (ecf_flags & (ECF_SP_DEPRESSED | ECF_NORETURN | ECF_LONGJMP))
/* Just pretend we did the pop. */
stack_pointer_delta -= rounded_stack_size;
else if (flag_defer_pop && inhibit_defer_pop == 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. */
- && DECL_CONTEXT (fndecl) == NULL_TREE && TREE_PUBLIC (fndecl))
+ think they are.
+ FIXME: this should be handled with attributes, not with this
+ hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
+ because you can declare fork() inside a function if you
+ wish. */
+ && (DECL_CONTEXT (fndecl) == NULL_TREE
+ || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL)
+ && TREE_PUBLIC (fndecl))
{
const char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
const char *tname = name;
if (TREE_NOTHROW (exp))
flags |= ECF_NOTHROW;
- }
- if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
- flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
+ if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
+ flags |= ECF_LIBCALL_BLOCK | ECF_CONST;
+ }
+ else if (TYPE_P (exp) && TYPE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
+ flags |= ECF_CONST;
if (TREE_THIS_VOLATILE (exp))
flags |= ECF_NORETURN;
return flags;
}
+/* Detect flags from a CALL_EXPR. */
+
+int
+call_expr_flags (tree t)
+{
+ int flags;
+ tree decl = get_callee_fndecl (t);
+
+ if (decl)
+ flags = flags_from_decl_or_type (decl);
+ else
+ {
+ t = TREE_TYPE (TREE_OPERAND (t, 0));
+ if (t && TREE_CODE (t) == POINTER_TYPE)
+ flags = flags_from_decl_or_type (TREE_TYPE (t));
+ else
+ flags = 0;
+ }
+
+ return flags;
+}
+
/* Precompute all register parameters as described by ARGS, storing values
into fields within the ARGS array.
< (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
{
int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
- int big_endian_correction = 0;
+ int nregs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
+ int endian_correction = 0;
- args[i].n_aligned_regs
- = args[i].partial ? args[i].partial
- : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
+ args[i].n_aligned_regs = args[i].partial ? args[i].partial : nregs;
+ args[i].aligned_regs = xmalloc (sizeof (rtx) * args[i].n_aligned_regs);
- args[i].aligned_regs = (rtx *) xmalloc (sizeof (rtx)
- * args[i].n_aligned_regs);
-
- /* Structures smaller than a word are aligned to the least
- significant byte (to the right). On a BYTES_BIG_ENDIAN machine,
+ /* Structures smaller than a word are normally aligned to the
+ least significant byte. On a BYTES_BIG_ENDIAN machine,
this means we must skip the empty high order bytes when
calculating the bit offset. */
- if (BYTES_BIG_ENDIAN
- && bytes < UNITS_PER_WORD)
- big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
+ if (bytes < UNITS_PER_WORD
+#ifdef BLOCK_REG_PADDING
+ && (BLOCK_REG_PADDING (args[i].mode,
+ TREE_TYPE (args[i].tree_value), 1)
+ == downward)
+#else
+ && BYTES_BIG_ENDIAN
+#endif
+ )
+ endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT;
for (j = 0; j < args[i].n_aligned_regs; j++)
{
int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
args[i].aligned_regs[j] = reg;
+ word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
+ word_mode, word_mode, BITS_PER_WORD);
/* There is no need to restrict this code to loading items
in TYPE_ALIGN sized hunks. The bitfield instructions can
emit_move_insn (reg, const0_rtx);
bytes -= bitsize / BITS_PER_UNIT;
- store_bit_field (reg, bitsize, big_endian_correction, word_mode,
- extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
- word_mode, word_mode,
- BITS_PER_WORD),
- BITS_PER_WORD);
+ store_bit_field (reg, bitsize, endian_correction, word_mode,
+ word, BITS_PER_WORD);
}
}
}
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,
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;
{
/* 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)
}
mode = TYPE_MODE (type);
- unsignedp = TREE_UNSIGNED (type);
+ unsignedp = TYPE_UNSIGNED (type);
-#ifdef PROMOTE_FUNCTION_ARGS
- mode = promote_mode (type, mode, &unsignedp, 1);
-#endif
+ if (targetm.calls.promote_function_args (fndecl ? TREE_TYPE (fndecl) : 0))
+ mode = promote_mode (type, mode, &unsignedp, 1);
args[i].unsignedp = unsignedp;
args[i].mode = mode;
#endif
args[i].pass_on_stack ? 0 : args[i].partial,
fndecl, args_size, &args[i].locate);
+#ifdef BLOCK_REG_PADDING
+ else
+ /* The argument is passed entirely in registers. See at which
+ end it should be padded. */
+ args[i].locate.where_pad =
+ BLOCK_REG_PADDING (mode, type,
+ int_size_in_bytes (type) <= UNITS_PER_WORD);
+#endif
/* Update ARGS_SIZE, the total stack space for args so far. */
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
{
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)
{
int i, j;
-#ifdef LOAD_ARGS_REVERSED
- for (i = num_actuals - 1; i >= 0; i--)
-#else
for (i = 0; i < num_actuals; i++)
-#endif
{
rtx reg = ((flags & ECF_SIBCALL)
? args[i].tail_call_reg : args[i].reg);
- int partial = args[i].partial;
- int nregs;
-
if (reg)
{
+ int partial = args[i].partial;
+ int nregs;
+ int size = 0;
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
argument is a zero size structure with no fields. */
- nregs = (partial ? partial
- : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
- ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
- + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
- : -1));
+ nregs = -1;
+ if (partial)
+ nregs = partial;
+ else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode)
+ {
+ size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
+ nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
+ }
+ else
+ size = GET_MODE_SIZE (args[i].mode);
/* Handle calls that pass values in multiple non-contiguous
locations. The Irix 6 ABI has examples of this. */
if (GET_CODE (reg) == PARALLEL)
- emit_group_load (reg, args[i].value,
- int_size_in_bytes (TREE_TYPE (args[i].tree_value)));
+ {
+ tree type = TREE_TYPE (args[i].tree_value);
+ emit_group_load (reg, args[i].value, type,
+ int_size_in_bytes (type));
+ }
/* If simple case, just do move. If normal partial, store_one_arg
has already loaded the register for us. In all other cases,
load the register(s) from memory. */
else if (nregs == -1)
- emit_move_insn (reg, args[i].value);
+ {
+ emit_move_insn (reg, args[i].value);
+#ifdef BLOCK_REG_PADDING
+ /* Handle case where we have a value that needs shifting
+ up to the msb. eg. a QImode value and we're padding
+ upward on a BYTES_BIG_ENDIAN machine. */
+ if (size < UNITS_PER_WORD
+ && (args[i].locate.where_pad
+ == (BYTES_BIG_ENDIAN ? upward : downward)))
+ {
+ rtx x;
+ int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
+
+ /* Assigning REG here rather than a temp makes CALL_FUSAGE
+ report the whole reg as used. Strictly speaking, the
+ call only uses SIZE bytes at the msb end, but it doesn't
+ seem worth generating rtl to say that. */
+ reg = gen_rtx_REG (word_mode, REGNO (reg));
+ x = expand_binop (word_mode, ashl_optab, reg,
+ GEN_INT (shift), reg, 1, OPTAB_WIDEN);
+ if (x != reg)
+ emit_move_insn (reg, x);
+ }
+#endif
+ }
/* If we have pre-computed the values to put in the registers in
the case of non-aligned structures, copy them in now. */
args[i].aligned_regs[j]);
else if (partial == 0 || args[i].pass_on_stack)
- move_block_to_reg (REGNO (reg),
- validize_mem (args[i].value), nregs,
- args[i].mode);
+ {
+ rtx mem = validize_mem (args[i].value);
+
+ /* Handle a BLKmode that needs shifting. */
+ if (nregs == 1 && size < UNITS_PER_WORD
+#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));
+ rtx x = gen_reg_rtx (word_mode);
+ int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
+ optab dir = BYTES_BIG_ENDIAN ? lshr_optab : ashl_optab;
+
+ emit_move_insn (x, tem);
+ x = expand_binop (word_mode, dir, x, GEN_INT (shift),
+ ri, 1, OPTAB_WIDEN);
+ if (x != ri)
+ emit_move_insn (ri, x);
+ }
+ else
+ move_block_to_reg (REGNO (reg), mem, 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
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 ();
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;
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);
if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
&& optimize > 0 && !TREE_ADDRESSABLE (fndecl))
{
- warning_with_decl (fndecl, "inlining failed in call to `%s'");
+ 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;
}
return t;
}
+
+/* If function value *VALUE was returned at the most significant end of a
+ register, shift it towards the least significant end and convert it to
+ TYPE's mode. Return true and update *VALUE if some action was needed.
+
+ TYPE is the type of the function's return value, which is known not
+ to have mode BLKmode. */
+
+static bool
+shift_returned_value (tree type, rtx *value)
+{
+ if (targetm.calls.return_in_msb (type))
+ {
+ HOST_WIDE_INT shift;
+
+ shift = (GET_MODE_BITSIZE (GET_MODE (*value))
+ - BITS_PER_UNIT * int_size_in_bytes (type));
+ if (shift > 0)
+ {
+ *value = expand_binop (GET_MODE (*value), lshr_optab, *value,
+ GEN_INT (shift), 0, 1, OPTAB_WIDEN);
+ *value = convert_to_mode (TYPE_MODE (type), *value, 0);
+ return true;
+ }
+ }
+ return false;
+}
+
/* 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.
/* 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;
/* 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;
+ rtx struct_value = 0;
/* Number of actual parameters in this call, including struct value addr. */
int num_actuals;
#endif
int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
+ rtx temp_target = 0;
char *initial_stack_usage_map = stack_usage_map;
int old_stack_allocated;
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))
{
if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
&& optimize > 0)
{
- warning_with_decl (fndecl, "can't inline call to `%s'");
+ 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
+ && lookup_attribute ("warn_unused_result",
+ TYPE_ATTRIBUTES (TREE_TYPE (fndecl))))
+ warning ("ignoring return value of `%D', "
+ "declared with attribute warn_unused_result", fndecl);
+
flags |= flags_from_decl_or_type (fndecl);
}
/* If we don't have specific function to call, see if we have a
attributes set in the type. */
else
- flags |= flags_from_decl_or_type (TREE_TYPE (TREE_TYPE (p)));
+ {
+ fntype = TREE_TYPE (TREE_TYPE (p));
+ if (ignore
+ && 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 (fntype);
+ }
+
+ 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. */
}
#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)
/* Set up a place to return a structure. */
/* Cater to broken compilers. */
- if (aggregate_value_p (exp))
+ if (aggregate_value_p (exp, fndecl))
{
/* This call returns a big structure. */
flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
/* 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;
}
}
/* 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);
/* If struct_value_rtx is 0, it means pass the address
as if it were an extra parameter. */
- if (structure_value_addr && struct_value_rtx == 0)
+ if (structure_value_addr && struct_value == 0)
{
/* If structure_value_addr is a REG other than
virtual_outgoing_args_rtx, we can use always use it. If it
|| (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
/* 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 nonzero.
+ We do include the last named arg if
+ targetm.calls.strict_argument_naming() returns nonzero.
(If no anonymous args follow, the result of list_length is actually
one too large. This is harmless.)
- If PRETEND_OUTGOING_VARARGS_NAMED is set 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
+ If targetm.calls.pretend_outgoing_varargs_named() returns
+ nonzero, and targetm.calls.strict_argument_naming() returns 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 function declaration.
- If PRETEND_OUTGOING_VARARGS_NAMED is not set, we do not have any
- reliable way to pass unnamed args in registers, so we must force
- them into memory. */
+ If targetm.calls.pretend_outgoing_varargs_named() returns zero,
+ we do not have any reliable way to pass unnamed args in
+ registers, so we must force them into memory. */
- if ((STRICT_ARGUMENT_NAMING
- || ! PRETEND_OUTGOING_VARARGS_NAMED)
+ if ((targetm.calls.strict_argument_naming (&args_so_far)
+ || ! targetm.calls.pretend_outgoing_varargs_named (&args_so_far))
&& type_arg_types != 0)
n_named_args
= (list_length (type_arg_types)
/* Don't include the last named arg. */
- - (STRICT_ARGUMENT_NAMING ? 0 : 1)
+ - (targetm.calls.strict_argument_naming (&args_so_far) ? 0 : 1)
/* Count the struct value address, if it is passed as a parm. */
+ structure_value_addr_parm);
else
/* 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
+ 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);
+ 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 = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
- memset ((char *) args, 0, num_actuals * sizeof (struct arg_data));
+ args = alloca (num_actuals * sizeof (struct arg_data));
+ memset (args, 0, num_actuals * sizeof (struct arg_data));
/* Build up entries in the ARGS array, compute the size of the
arguments into ARGS_SIZE, etc. */
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)
{
finished with regular parsing. Which means that some of the
machinery we use to generate tail-calls is no longer in place.
This is most often true of sjlj-exceptions, which we couldn't
- tail-call to anyway. */
+ tail-call to anyway.
+ If current_nesting_level () == 0, we're being called after
+ the function body has been expanded. This can happen when
+ setting up trampolines in expand_function_end. */
if (currently_expanding_call++ != 0
|| !flag_optimize_sibling_calls
|| !rtx_equal_function_value_matters
- || any_pending_cleanups (1)
+ || current_nesting_level () == 0
+ || any_pending_cleanups ()
|| args_size.var)
try_tail_call = try_tail_recursion = 0;
|| 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))
!= 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)
addr = fix_unsafe_tree (addr);
/* Expanding one of those dangerous arguments could have added
cleanups, but otherwise give it a whirl. */
- if (any_pending_cleanups (1))
+ if (any_pending_cleanups ())
try_tail_call = try_tail_recursion = 0;
}
expand_start_target_temps ();
if (optimize_tail_recursion (actparms, get_last_insn ()))
{
- if (any_pending_cleanups (1))
+ if (any_pending_cleanups ())
try_tail_call = try_tail_recursion = 0;
else
tail_recursion_insns = get_insns ();
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);
highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
needed);
#endif
- stack_usage_map
- = (char *) alloca (highest_outgoing_arg_in_use);
+ stack_usage_map = alloca (highest_outgoing_arg_in_use);
if (initial_highest_arg_in_use)
memcpy (stack_usage_map, initial_stack_usage_map,
= stack_arg_under_construction;
stack_arg_under_construction = 0;
/* Make a new map for the new argument list. */
- stack_usage_map = (char *)
- alloca (highest_outgoing_arg_in_use);
+ stack_usage_map = alloca (highest_outgoing_arg_in_use);
memset (stack_usage_map, 0, highest_outgoing_arg_in_use);
highest_outgoing_arg_in_use = 0;
}
&& check_sibcall_argument_overlap (before_arg,
&args[i], 1)))
sibcall_failure = 1;
+
+ if (flags & ECF_CONST
+ && args[i].stack
+ && args[i].value == args[i].stack)
+ call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
+ gen_rtx_USE (VOIDmode,
+ args[i].value),
+ call_fusage);
}
/* If we have a parm that is passed in registers but not in memory
structure value. */
if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
{
-#ifdef POINTERS_EXTEND_UNSIGNED
- if (GET_MODE (structure_value_addr) != Pmode)
- structure_value_addr = convert_memory_address
- (Pmode, structure_value_addr);
-#endif
- emit_move_insn (struct_value_rtx,
+ structure_value_addr
+ = convert_memory_address (Pmode, structure_value_addr);
+ emit_move_insn (struct_value,
force_reg (Pmode,
force_operand (structure_value_addr,
NULL_RTX)));
- if (GET_CODE (struct_value_rtx) == REG)
- use_reg (&call_fusage, struct_value_rtx);
+ if (GET_CODE (struct_value) == REG)
+ use_reg (&call_fusage, struct_value);
}
funexp = prepare_call_address (funexp, fndecl, &call_fusage,
if (pass && (flags & ECF_LIBCALL_BLOCK))
{
rtx insns;
+ rtx insn;
+ bool failed = valreg == 0 || GET_CODE (valreg) == PARALLEL;
+
+ insns = get_insns ();
- if (valreg == 0 || GET_CODE (valreg) == PARALLEL)
+ /* Expansion of block moves possibly introduced a loop that may
+ not appear inside libcall block. */
+ for (insn = insns; insn; insn = NEXT_INSN (insn))
+ if (GET_CODE (insn) == JUMP_INSN)
+ failed = true;
+
+ if (failed)
{
- insns = get_insns ();
end_sequence ();
emit_insn (insns);
}
mark_reg_pointer (temp,
TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp))));
- /* Construct an "equal form" for the value which mentions all the
- arguments in order as well as the function name. */
- for (i = 0; i < num_actuals; i++)
- note = gen_rtx_EXPR_LIST (VOIDmode,
- args[i].initial_value, note);
- note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
-
- insns = get_insns ();
end_sequence ();
-
- if (flags & ECF_PURE)
- note = gen_rtx_EXPR_LIST (VOIDmode,
+ if (flag_unsafe_math_optimizations
+ && fndecl
+ && DECL_BUILT_IN (fndecl)
+ && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SQRT
+ || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SQRTF
+ || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SQRTL))
+ note = gen_rtx_fmt_e (SQRT,
+ GET_MODE (temp),
+ args[0].initial_value);
+ else
+ {
+ /* Construct an "equal form" for the value which
+ mentions all the arguments in order as well as
+ the function name. */
+ for (i = 0; i < num_actuals; i++)
+ note = gen_rtx_EXPR_LIST (VOIDmode,
+ args[i].initial_value, note);
+ note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
+
+ if (flags & ECF_PURE)
+ note = gen_rtx_EXPR_LIST (VOIDmode,
gen_rtx_USE (VOIDmode,
gen_rtx_MEM (BLKmode,
gen_rtx_SCRATCH (VOIDmode))),
note);
-
+ }
emit_libcall_block (insns, temp, valreg, note);
valreg = temp;
}
emit_barrier_after (last);
+
+ /* Stack adjustments after a noreturn call are dead code.
+ However when NO_DEFER_POP is in effect, we must preserve
+ stack_pointer_delta. */
+ if (inhibit_defer_pop == 0)
+ {
+ stack_pointer_delta = old_stack_allocated;
+ pending_stack_adjust = 0;
+ }
}
if (flags & ECF_LONGJMP)
/* If there are cleanups to be called, don't use a hard reg as target.
We need to double check this and see if it matters anymore. */
- if (any_pending_cleanups (1))
+ if (any_pending_cleanups ())
{
if (target && REG_P (target)
&& REGNO (target) < FIRST_PSEUDO_REGISTER)
The Irix 6 ABI has examples of this. */
else if (GET_CODE (valreg) == PARALLEL)
{
- if (target == 0)
+ /* Second condition is added because "target" is freed at the
+ the end of "pass0" for -O2 when call is made to
+ expand_end_target_temps (). Its "in_use" flag has been set
+ to false, so allocate a new temp. */
+ if (target == 0 || (pass == 1 && target == temp_target))
{
/* This will only be assigned once, so it can be readonly. */
tree nt = build_qualified_type (TREE_TYPE (exp),
| TYPE_QUAL_CONST));
target = assign_temp (nt, 0, 1, 1);
+ temp_target = target;
preserve_temp_slots (target);
}
if (! rtx_equal_p (target, valreg))
- emit_group_store (target, valreg,
+ emit_group_store (target, valreg, TREE_TYPE (exp),
int_size_in_bytes (TREE_TYPE (exp)));
/* We can not support sibling calls for this case. */
sibcall_failure = 1;
}
else
- target = copy_to_reg (valreg);
+ {
+ if (shift_returned_value (TREE_TYPE (exp), &valreg))
+ sibcall_failure = 1;
+
+ target = copy_to_reg (valreg);
+ }
-#ifdef PROMOTE_FUNCTION_RETURN
+ if (targetm.calls.promote_function_return(funtype))
+ {
/* If we promoted this return value, make the proper SUBREG. TARGET
might be const0_rtx here, so be careful. */
if (GET_CODE (target) == REG
&& 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. */
SUBREG_PROMOTED_VAR_P (target) = 1;
SUBREG_PROMOTED_UNSIGNED_SET (target, unsignedp);
}
-#endif
+ }
/* If size of args is variable or this was a constructor call for a stack
argument, restore saved stack-pointer value. */
normal_call_insns = insns;
/* Verify that we've deallocated all the stack we used. */
- if (old_stack_allocated !=
- stack_pointer_delta - pending_stack_adjust)
+ if (! (flags & (ECF_NORETURN | ECF_LONGJMP))
+ && old_stack_allocated != stack_pointer_delta
+ - pending_stack_adjust)
abort ();
}
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 ();
}
{
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))
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;
{
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;
int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
char *initial_stack_usage_map = stack_usage_map;
+ 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;
decide where in memory it should come back. */
if (outmode != VOIDmode)
{
- tfom = (*lang_hooks.types.type_for_mode) (outmode, 0);
- if (aggregate_value_p (tfom))
+ tfom = lang_hooks.types.type_for_mode (outmode, 0);
+ if (aggregate_value_p (tfom, 0))
{
#ifdef PCC_STATIC_STRUCT_RETURN
rtx pointer_reg
of the full argument passing conventions to limit complexity here since
library functions shouldn't have many args. */
- argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
- memset ((char *) argvec, 0, (nargs + 1) * sizeof (struct arg));
+ argvec = alloca ((nargs + 1) * sizeof (struct arg));
+ memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
#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;
/* If there's a structure value address to be passed,
either pass it in the special place, or pass it as an extra argument. */
- if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
+ if (mem_value && struct_value == 0 && ! pcc_struct_value)
{
rtx addr = XEXP (mem_value, 0);
nargs++;
|| (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
abort ();
- /* On some machines, there's no way to pass a float to a library fcn.
- Pass it as a double instead. */
-#ifdef LIBGCC_NEEDS_DOUBLE
- if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
- val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
-#endif
-
/* There's no need to call protect_from_queue, because
either emit_move_insn or emit_push_insn will do that. */
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,
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);
highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
needed);
#endif
- stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
+ stack_usage_map = alloca (highest_outgoing_arg_in_use);
if (initial_highest_arg_in_use)
memcpy (stack_usage_map, initial_stack_usage_map,
argvec[argnum].locate.offset.constant);
rtx stack_area
= gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
- argvec[argnum].save_area = gen_reg_rtx (save_mode);
- emit_move_insn (argvec[argnum].save_area, stack_area);
+ if (save_mode == BLKmode)
+ {
+ argvec[argnum].save_area
+ = assign_stack_temp (BLKmode,
+ argvec[argnum].locate.size.constant,
+ 0);
+
+ emit_block_move (validize_mem (argvec[argnum].save_area),
+ stack_area,
+ GEN_INT (argvec[argnum].locate.size.constant),
+ BLOCK_OP_CALL_PARM);
+ }
+ else
+ {
+ argvec[argnum].save_area = gen_reg_rtx (save_mode);
+
+ emit_move_insn (argvec[argnum].save_area, stack_area);
+ }
}
}
/* Handle calls that pass values in multiple non-contiguous
locations. The PA64 has examples of this for library calls. */
if (reg != 0 && GET_CODE (reg) == PARALLEL)
- emit_group_load (reg, val, GET_MODE_SIZE (GET_MODE (val)));
+ emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (GET_MODE (val)));
else if (reg != 0 && partial == 0)
emit_move_insn (reg, val);
}
/* Pass the function the address in which to return a structure value. */
- if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
+ if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
{
- emit_move_insn (struct_value_rtx,
+ emit_move_insn (struct_value,
force_reg (Pmode,
force_operand (XEXP (mem_value, 0),
NULL_RTX)));
- if (GET_CODE (struct_value_rtx) == REG)
- use_reg (&call_fusage, struct_value_rtx);
+ if (GET_CODE (struct_value) == REG)
+ use_reg (&call_fusage, struct_value);
}
/* Don't allow popping to be deferred, since then
if (GET_CODE (valreg) == PARALLEL)
{
temp = gen_reg_rtx (outmode);
- emit_group_store (temp, valreg, outmode);
+ emit_group_store (temp, valreg, NULL_TREE,
+ GET_MODE_SIZE (outmode));
valreg = temp;
}
{
if (value == 0)
value = gen_reg_rtx (outmode);
- emit_group_store (value, valreg, outmode);
+ emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
}
else if (value != 0)
emit_move_insn (value, valreg);
rtx stack_area = gen_rtx_MEM (save_mode,
memory_address (save_mode, adr));
- emit_move_insn (stack_area, argvec[count].save_area);
+ if (save_mode == BLKmode)
+ emit_block_move (stack_area,
+ validize_mem (argvec[count].save_area),
+ GEN_INT (argvec[count].locate.size.constant),
+ BLOCK_OP_CALL_PARM);
+ else
+ emit_move_insn (stack_area, argvec[count].save_area);
}
highest_outgoing_arg_in_use = initial_highest_arg_in_use;
{
/* PUSH_ROUNDING has no effect on us, because
emit_push_insn for BLKmode is careful to avoid it. */
- excess = (arg->locate.size.constant
- - int_size_in_bytes (TREE_TYPE (pval))
- + partial * UNITS_PER_WORD);
+ if (reg && GET_CODE (reg) == PARALLEL)
+ {
+ /* Use the size of the elt to compute excess. */
+ rtx elt = XEXP (XVECEXP (reg, 0, 0), 0);
+ excess = (arg->locate.size.constant
+ - int_size_in_bytes (TREE_TYPE (pval))
+ + partial * GET_MODE_SIZE (GET_MODE (elt)));
+ }
+ else
+ excess = (arg->locate.size.constant
+ - int_size_in_bytes (TREE_TYPE (pval))
+ + partial * UNITS_PER_WORD);
size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
NULL_RTX, TYPE_MODE (sizetype), 0);
}
if (XEXP (x, 0) != current_function_internal_arg_pointer)
i = INTVAL (XEXP (XEXP (x, 0), 1));
- /* expand_call should ensure this */
+ /* expand_call should ensure this. */
if (arg->locate.offset.var || GET_CODE (size_rtx) != CONST_INT)
abort ();