return cur;
}
-/* Return true if VAR is a PARM_DECL or a RESULT_DECL of type BLKmode.
+/* Return true if VAR is a PARM_DECL or a RESULT_DECL that ought to be
+ assigned to a stack slot. We can't have expand_one_ssa_partition
+ choose their address: the pseudo holding the address would be set
+ up too late for assign_params to copy the parameter if needed.
+
Such parameters are likely passed as a pointer to the value, rather
than as a value, and so we must not coalesce them, nor allocate
stack space for them before determining the calling conventions for
- them. For their SSA_NAMEs, expand_one_ssa_partition emits RTL as
- MEMs with pc_rtx as the address, and then it replaces the pc_rtx
- with NULL so as to make sure the MEM is not used before it is
- adjusted in assign_parm_setup_reg. */
+ them.
+
+ For their SSA_NAMEs, expand_one_ssa_partition emits RTL as MEMs
+ with pc_rtx as the address, and then it replaces the pc_rtx with
+ NULL so as to make sure the MEM is not used before it is adjusted
+ in assign_parm_setup_reg. */
bool
-parm_maybe_byref_p (tree var)
+parm_in_stack_slot_p (tree var)
{
if (!var || VAR_P (var))
return false;
gcc_assert (TREE_CODE (var) == PARM_DECL
|| TREE_CODE (var) == RESULT_DECL);
- return TYPE_MODE (TREE_TYPE (var)) == BLKmode;
+ return !use_register_for_decl (var);
}
/* Return the partition of the default SSA_DEF for decl VAR. */
if (!use_register_for_decl (var))
{
- if (parm_maybe_byref_p (SSA_NAME_VAR (var))
- && ssa_default_def_partition (SSA_NAME_VAR (var)) == part)
+ /* We can't risk having the parm assigned to a MEM location
+ whose address references a pseudo, for the pseudo will only
+ be set up after arguments are copied to the stack slot.
+
+ If the parm doesn't have a default def (e.g., because its
+ incoming value is unused), then we want to let assign_params
+ do the allocation, too. In this case we want to make sure
+ SSA_NAMEs associated with the parm don't get assigned to more
+ than one partition, lest we'd create two unassigned stac
+ slots for the same parm, thus the assert at the end of the
+ block. */
+ if (parm_in_stack_slot_p (SSA_NAME_VAR (var))
+ && (ssa_default_def_partition (SSA_NAME_VAR (var)) == part
+ || !ssa_default_def (cfun, SSA_NAME_VAR (var))))
{
expand_one_stack_var_at (var, pc_rtx, 0, 0);
rtx x = SA.partition_to_pseudo[part];
gcc_assert (GET_CODE (x) == MEM);
- gcc_assert (GET_MODE (x) == BLKmode);
gcc_assert (XEXP (x, 0) == pc_rtx);
/* Reset the address, so that any attempt to use it will
ICE. It will be adjusted in assign_parm_setup_reg. */
XEXP (x, 0) = NULL_RTX;
+ /* If the RTL associated with the parm is not what we have
+ just created, the parm has been split over multiple
+ partitions. In order for this to work, we must have a
+ default def for the parm, otherwise assign_params won't
+ know what to do. */
+ gcc_assert (DECL_RTL_IF_SET (SSA_NAME_VAR (var)) == x
+ || ssa_default_def (cfun, SSA_NAME_VAR (var)));
}
else if (defer_stack_allocation (var, true))
add_stack_var (var);
static void do_use_return_reg (rtx, void *);
static rtx rtl_for_parm (struct assign_parm_data_all *, tree);
static void maybe_reset_rtl_for_parm (tree);
+static bool parm_in_unassigned_mem_p (tree, rtx);
\f
/* Stack of nested functions. */
rtx rtl = rtl_for_parm (all, cparm);
if (rtl)
{
+ /* If this is parm is unassigned, assign it now: the
+ newly-created decls wouldn't expect the need for
+ assignment, and if they were assigned
+ independently, they might not end up in adjacent
+ slots, so unsplit wouldn't be able to fill in the
+ unassigned address of the complex MEM. */
+ if (parm_in_unassigned_mem_p (cparm, rtl))
+ {
+ int align = STACK_SLOT_ALIGNMENT
+ (TREE_TYPE (cparm), GET_MODE (rtl), MEM_ALIGN (rtl));
+ rtx loc = assign_stack_local
+ (GET_MODE (rtl), GET_MODE_SIZE (GET_MODE (rtl)),
+ align);
+ XEXP (rtl, 0) = XEXP (loc, 0);
+ }
+
SET_DECL_RTL (p, read_complex_part (rtl, false));
SET_DECL_RTL (decl, read_complex_part (rtl, true));
return false;
}
+/* Return true if FROM_EXPAND is a MEM with an address to be filled in
+ by assign_params. This should be the case if, and only if,
+ parm_in_stack_slot_p holds for the parm DECL that expanded to
+ FROM_EXPAND, so we check that, too. */
+
+static bool
+parm_in_unassigned_mem_p (tree decl, rtx from_expand)
+{
+ bool result = MEM_P (from_expand) && !XEXP (from_expand, 0);
+
+ gcc_assert (result == parm_in_stack_slot_p (decl)
+ /* Maybe it was already assigned. That's ok, especially
+ for split complex args. */
+ || (!result && MEM_P (from_expand)
+ && (XEXP (from_expand, 0) == virtual_stack_vars_rtx
+ || (GET_CODE (XEXP (from_expand, 0)) == PLUS
+ && XEXP (XEXP (from_expand, 0), 0) == virtual_stack_vars_rtx))));
+
+ return result;
+}
+
/* A subroutine of assign_parms. Arrange for the parameter to be
present and valid in DATA->STACK_RTL. */
{
DECL_ALIGN (parm) = MAX (DECL_ALIGN (parm), BITS_PER_WORD);
rtx from_expand = rtl_for_parm (all, parm);
- if (from_expand && (!parm_maybe_byref_p (parm)
- || XEXP (from_expand, 0) != NULL_RTX))
+ if (from_expand && !parm_in_unassigned_mem_p (parm, from_expand))
stack_parm = copy_rtx (from_expand);
else
{
if (from_expand)
{
gcc_assert (GET_CODE (stack_parm) == MEM);
- gcc_assert (GET_CODE (from_expand) == MEM);
- gcc_assert (XEXP (from_expand, 0) == NULL_RTX);
+ gcc_assert (parm_in_unassigned_mem_p (parm, from_expand));
XEXP (from_expand, 0) = XEXP (stack_parm, 0);
PUT_MODE (from_expand, GET_MODE (stack_parm));
stack_parm = copy_rtx (from_expand);
else if (size == 0)
;
+ /* MEM may be a REG if coalescing assigns the param's partition
+ to a pseudo. */
+ else if (REG_P (mem))
+ emit_move_insn (mem, entry_parm);
+
/* If SIZE is that of a mode no bigger than a word, just use
that mode's store operation. */
else if (size <= UNITS_PER_WORD)
if (GET_MODE (parmreg) != promoted_nominal_mode)
parmreg = gen_lowpart (promoted_nominal_mode, parmreg);
}
- else if (!from_expand || parm_maybe_byref_p (parm))
+ else if (!from_expand || parm_in_unassigned_mem_p (parm, from_expand))
{
parmreg = gen_reg_rtx (promoted_nominal_mode);
if (!DECL_ARTIFICIAL (parm))
{
gcc_assert (data->passed_pointer);
gcc_assert (GET_CODE (from_expand) == MEM
- && GET_MODE (from_expand) == BLKmode
&& XEXP (from_expand, 0) == NULL_RTX);
XEXP (from_expand, 0) = parmreg;
}
did_conversion = true;
}
else if (GET_MODE (parmreg) == BLKmode)
- gcc_assert (parm_maybe_byref_p (parm));
+ gcc_assert (parm_in_stack_slot_p (parm));
else
emit_move_insn (parmreg, src);
if (data->entry_parm != data->stack_parm)
{
rtx src, dest;
+ rtx from_expand = NULL_RTX;
if (data->stack_parm == 0)
{
- rtx x = data->stack_parm = rtl_for_parm (all, parm);
- if (x)
- gcc_assert (GET_MODE (x) == GET_MODE (data->entry_parm));
+ from_expand = rtl_for_parm (all, parm);
+ if (from_expand)
+ gcc_assert (GET_MODE (from_expand) == GET_MODE (data->entry_parm));
+ if (from_expand && !parm_in_unassigned_mem_p (parm, from_expand))
+ data->stack_parm = from_expand;
}
if (data->stack_parm == 0)
= assign_stack_local (GET_MODE (data->entry_parm),
GET_MODE_SIZE (GET_MODE (data->entry_parm)),
align);
- set_mem_attributes (data->stack_parm, parm, 1);
+ if (!from_expand)
+ set_mem_attributes (data->stack_parm, parm, 1);
+ else
+ {
+ gcc_assert (GET_CODE (data->stack_parm) == MEM);
+ gcc_assert (parm_in_unassigned_mem_p (parm, from_expand));
+ XEXP (from_expand, 0) = XEXP (data->stack_parm, 0);
+ PUT_MODE (from_expand, GET_MODE (data->stack_parm));
+ data->stack_parm = copy_rtx (from_expand);
+ }
}
dest = validize_mem (copy_rtx (data->stack_parm));