public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] morello: Finish outgoing side of new varargs PCS
@ 2021-12-10 16:49 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2021-12-10 16:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6c55a2178fd1e6979f8bf1803acc6632181f7828

commit 6c55a2178fd1e6979f8bf1803acc6632181f7828
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Fri Oct 29 17:55:23 2021 +0100

    morello: Finish outgoing side of new varargs PCS
    
    This ties together the implementation of the new Morello varargs PCS.
    The previous patch in the series set up the stack layout for the
    outgoing anonymous argument as required by the PCS (i.e. setting up the
    Anonymous Argument Memory Area). This patch adjusts call expansion to
    set up a pointer to the AAMA in c9.
    
    We achieve this by introducing a new target hook
    (targetm.calls.handle_outgoing_varargs). We adjust the mid-end to call
    this hook in expand_call for variadic functions and pass a pointer to
    the stack slot inhabited by the first anonymous argument (the last one
    to be pushed).
    
    The aarch64 backend then implements the new hook and moves the pointer
    to the AAMA into c9. It also adds a use of c9 to the call_insn's list of
    used regs to prevent the move being optimized away.
    
    gcc/ChangeLog:
    
            * calls.c (type_arg_types_variadic_p): New. Use it ...
            (expand_call): ... here. Call new target hook if callee is
            variadic, pass pointer to first anonymous argument.
            * config/aarch64/aarch64.c (aarch64_handle_outgoing_varargs):
            New.
            (TARGET_HANDLE_OUTGOING_VARARGS): New.
            * doc/tm.texi: Regenerate
            * doc/tm.texi.in (TARGET_HANDLE_OUTGOING_VARARGS): New.
            * target.def (handle_outgoing_varargs): New hook.
            * targhooks.c (default_handle_outgoing_varargs): New.
            * targhooks.h (default_handle_outgoing_varargs): New.

Diff:
---
 gcc/calls.c                  | 23 +++++++++++++++++++++++
 gcc/config/aarch64/aarch64.c | 17 +++++++++++++++++
 gcc/doc/tm.texi              |  5 +++++
 gcc/doc/tm.texi.in           |  2 ++
 gcc/target.def               |  7 +++++++
 gcc/targhooks.c              |  5 +++++
 gcc/targhooks.h              |  1 +
 7 files changed, 60 insertions(+)

diff --git a/gcc/calls.c b/gcc/calls.c
index 8d002bc415a..36c52447f77 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -3518,6 +3518,19 @@ update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate)
     crtl->preferred_stack_boundary = locate->boundary;
 }
 
+/* Check if a function is variadic given the TYPE_ARG_TYPES from the
+   FUNCTION_TYPE.  */
+
+static bool
+type_arg_types_variadic_p (tree t)
+{
+  for (; t; t = TREE_CHAIN (t))
+    if (t == void_list_node)
+      return false;
+
+  return true;
+}
+
 /* Generate all the code for a CALL_EXPR exp
    and return an rtx for its value.
    Store the value in TARGET (specified as an rtx) if convenient.
@@ -4378,6 +4391,8 @@ expand_call (tree exp, rtx target, int ignore)
 					      &low_to_save, &high_to_save);
 #endif
 
+      rtx outgoing_varargs = CONST0_RTX (Pmode);
+
       /* Now store (and compute if necessary) all non-register parms.
 	 These come before register parms, since they can require block-moves,
 	 which could clobber the registers used for register parms.
@@ -4413,8 +4428,16 @@ expand_call (tree exp, rtx target, int ignore)
 	      = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
 				   gen_rtx_USE (VOIDmode, args[i].stack),
 				   call_fusage);
+
+	  if (num_actuals - i == n_named_args + 1 && args[i].stack_slot)
+	    outgoing_varargs = XEXP (args[i].stack_slot, 0);
 	}
 
+      if (type_arg_types && type_arg_types_variadic_p (type_arg_types))
+	targetm.calls.handle_outgoing_varargs (outgoing_varargs,
+					       num_actuals - n_named_args,
+					       &call_fusage);
+
       /* If we have a parm that is passed in registers but not in memory
 	 and whose alignment does not permit a direct copy into registers,
 	 make a group of pseudos that correspond to each register that we
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 39b8d738c0b..273b6de882f 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -17649,6 +17649,20 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v,
        + vr_saved * UNITS_PER_VREG);
 }
 
+static void
+aarch64_handle_outgoing_varargs (rtx aama_addr,
+				 int n_anon_args ATTRIBUTE_UNUSED,
+				 rtx *fusage)
+{
+  if (!TARGET_CAPABILITY_PURE)
+    return;
+
+  /* Morello TODO: emit scbnds with size of (n_anon_args * 16).  */
+  rtx c9 = gen_rtx_REG (CADImode, R9_REGNUM);
+  emit_move_insn (c9, aama_addr);
+  use_reg (fusage, c9);
+}
+
 static void
 aarch64_conditional_register_usage (void)
 {
@@ -24945,6 +24959,9 @@ aarch64_libgcc_floating_mode_supported_p
 #undef TARGET_SETUP_INCOMING_VARARGS
 #define TARGET_SETUP_INCOMING_VARARGS aarch64_setup_incoming_varargs
 
+#undef TARGET_HANDLE_OUTGOING_VARARGS
+#define TARGET_HANDLE_OUTGOING_VARARGS aarch64_handle_outgoing_varargs
+
 #undef TARGET_STRUCT_VALUE_RTX
 #define TARGET_STRUCT_VALUE_RTX   aarch64_struct_value_rtx
 
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index ec91a9dac66..0ce67733b49 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -5311,6 +5311,11 @@ end of the source file.  The hook @code{TARGET_SETUP_INCOMING_VARARGS} should
 not generate any instructions in this case.
 @end deftypefn
 
+@deftypefn {Target Hook} void TARGET_HANDLE_OUTGOING_VARARGS (rtx @var{varargs_addr}, int @var{n_anon_args}, rtx *@var{fusage})
+For anonymous arguments stored on the stack, a hook to allow the target to
+ perform some codegen with a pointer to the outgoing anonymous argument area.
+@end deftypefn
+
 @deftypefn {Target Hook} bool TARGET_STRICT_ARGUMENT_NAMING (cumulative_args_t @var{ca})
 Define this hook to return @code{true} if the location where a function
 argument is passed depends on whether or not it is a named argument.
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index a7c5769a1a0..98fde7445c6 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -3799,6 +3799,8 @@ These machine description macros help implement varargs:
 
 @hook TARGET_SETUP_INCOMING_VARARGS
 
+@hook TARGET_HANDLE_OUTGOING_VARARGS
+
 @hook TARGET_STRICT_ARGUMENT_NAMING
 
 @hook TARGET_CALL_ARGS
diff --git a/gcc/target.def b/gcc/target.def
index 67bab12f9b2..14eea320995 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -4705,6 +4705,13 @@ not generate any instructions in this case.",
 	int *pretend_args_size, int second_time),
  default_setup_incoming_varargs)
 
+DEFHOOK
+(handle_outgoing_varargs,
+ "For anonymous arguments stored on the stack, a hook to allow the target to\n\
+ perform some codegen with a pointer to the outgoing anonymous argument area.",
+ void, (rtx varargs_addr, int n_anon_args, rtx *fusage),
+ default_handle_outgoing_varargs)
+
 DEFHOOK
 (load_bounds_for_arg,
  "This hook is used by expand pass to emit insn to load bounds of\n\
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 60059a5bc93..19146dfc6db 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -198,6 +198,11 @@ default_setup_incoming_varargs (cumulative_args_t,
 {
 }
 
+void
+default_handle_outgoing_varargs (rtx, int, rtx *)
+{
+}
+
 /* The default implementation of TARGET_BUILTIN_SETJMP_FRAME_VALUE.  */
 
 rtx
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 85a92f18547..43ce9026981 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -43,6 +43,7 @@ extern rtx default_expand_builtin_saveregs (void);
 extern void default_setup_incoming_varargs (cumulative_args_t,
 					    const function_arg_info &,
 					    int *, int);
+extern void default_handle_outgoing_varargs (rtx, int, rtx *);
 extern rtx default_builtin_setjmp_frame_value (void);
 extern bool default_pretend_outgoing_varargs_named (cumulative_args_t);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-10 16:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-10 16:49 [gcc(refs/vendors/ARM/heads/morello)] morello: Finish outgoing side of new varargs PCS Matthew Malcomson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).