public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernd Schmidt <bernds@codesourcery.com>
To: Jeff Law <law@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: The nvptx port [7/11+] Inform the port about call arguments
Date: Tue, 28 Oct 2014 14:57:00 -0000	[thread overview]
Message-ID: <544FACE7.8030102@codesourcery.com> (raw)
In-Reply-To: <5447F392.6050909@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]

On 10/22/2014 08:12 PM, Jeff Law wrote:
> Yea, let's keep your approach.  Just wanted to explore a bit since the
> PA seems to have a variety of similar characteristics.

Here's an updated version of the patch. I experimented a little with ptx 
calling conventions and ran into an arg that had to be moved with 
memcpy, which exposed an ordering problem - all call_args were added to 
the memcpy call. So the invocation of the hook had to be moved downwards 
a bit, and the calculation of the return value needs to happen after it 
(since nvptx_function_value needs to know whether we are actually trying 
to construct a call at the moment).

Bootstrapped and tested on x86_64-linux, ok?


Bernd


[-- Attachment #2: 007-callargs.diff --]
[-- Type: text/x-patch, Size: 9038 bytes --]

	gcc/
	* target.def (call_args, end_call_args): New hooks.
	* hooks.c (hook_void_rtx_tree): New empty function.
	* hooks.h (hook_void_rtx_tree): Declare.
	* doc/tm.texi.in (TARGET_CALL_ARGS, TARGET_END_CALL_ARGS): Add.
	* doc/tm.texi: Regenerate.
	* calls.c (expand_call): Slightly rearrange the code.  Use the two new
	hooks.
	(expand_library_call_value_1): Use the two new hooks.

------------------------------------------------------------------------
Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi.orig
+++ gcc/doc/tm.texi
@@ -4960,6 +4960,29 @@ except the last are treated as named.
 You need not define this hook if it always returns @code{false}.
 @end deftypefn
 
+@deftypefn {Target Hook} void TARGET_CALL_ARGS (rtx, @var{tree})
+While generating RTL for a function call, this target hook is invoked once
+for each argument passed to the function, either a register returned by
+@code{TARGET_FUNCTION_ARG} or a memory location.  It is called just
+before the point where argument registers are stored.  The type of the
+function to be called is also passed as the second argument; it is
+@code{NULL_TREE} for libcalls.  The @code{TARGET_END_CALL_ARGS} hook is
+invoked just after the code to copy the return reg has been emitted.
+This functionality can be used to perform special setup of call argument
+registers if a target needs it.
+For functions without arguments, the hook is called once with @code{pc_rtx}
+passed instead of an argument register.
+Most ports do not need to implement anything for this hook.
+@end deftypefn
+
+@deftypefn {Target Hook} void TARGET_END_CALL_ARGS (void)
+This target hook is invoked while generating RTL for a function call,
+just after the point where the return reg is copied into a pseudo.  It
+signals that all the call argument and return registers for the just
+emitted call are now no longer in use.
+Most ports do not need to implement anything for this hook.
+@end deftypefn
+
 @deftypefn {Target Hook} bool TARGET_PRETEND_OUTGOING_VARARGS_NAMED (cumulative_args_t @var{ca})
 If you need to conditionally change ABIs so that one works with
 @code{TARGET_SETUP_INCOMING_VARARGS}, but the other works like neither
Index: gcc/doc/tm.texi.in
===================================================================
--- gcc/doc/tm.texi.in.orig
+++ gcc/doc/tm.texi.in
@@ -3856,6 +3856,10 @@ These machine description macros help im
 
 @hook TARGET_STRICT_ARGUMENT_NAMING
 
+@hook TARGET_CALL_ARGS
+
+@hook TARGET_END_CALL_ARGS
+
 @hook TARGET_PRETEND_OUTGOING_VARARGS_NAMED
 
 @node Trampolines
Index: gcc/hooks.c
===================================================================
--- gcc/hooks.c.orig
+++ gcc/hooks.c
@@ -245,6 +245,11 @@ hook_void_tree (tree a ATTRIBUTE_UNUSED)
 }
 
 void
+hook_void_rtx_tree (rtx, tree)
+{
+}
+
+void
 hook_void_constcharptr (const char *a ATTRIBUTE_UNUSED)
 {
 }
Index: gcc/hooks.h
===================================================================
--- gcc/hooks.h.orig
+++ gcc/hooks.h
@@ -71,6 +71,7 @@ extern void hook_void_constcharptr (cons
 extern void hook_void_rtx_insn_int (rtx_insn *, int);
 extern void hook_void_FILEptr_constcharptr (FILE *, const char *);
 extern bool hook_bool_FILEptr_rtx_false (FILE *, rtx);
+extern void hook_void_rtx_tree (rtx, tree);
 extern void hook_void_tree (tree);
 extern void hook_void_tree_treeptr (tree, tree *);
 extern void hook_void_int_int (int, int);
Index: gcc/target.def
===================================================================
--- gcc/target.def.orig
+++ gcc/target.def
@@ -3816,6 +3816,33 @@ not generate any instructions in this ca
  default_setup_incoming_varargs)
 
 DEFHOOK
+(call_args,
+ "While generating RTL for a function call, this target hook is invoked once\n\
+for each argument passed to the function, either a register returned by\n\
+@code{TARGET_FUNCTION_ARG} or a memory location.  It is called just\n\
+before the point where argument registers are stored.  The type of the\n\
+function to be called is also passed as the second argument; it is\n\
+@code{NULL_TREE} for libcalls.  The @code{TARGET_END_CALL_ARGS} hook is\n\
+invoked just after the code to copy the return reg has been emitted.\n\
+This functionality can be used to perform special setup of call argument\n\
+registers if a target needs it.\n\
+For functions without arguments, the hook is called once with @code{pc_rtx}\n\
+passed instead of an argument register.\n\
+Most ports do not need to implement anything for this hook.",
+ void, (rtx, tree),
+ hook_void_rtx_tree)
+
+DEFHOOK
+(end_call_args,
+ "This target hook is invoked while generating RTL for a function call,\n\
+just after the point where the return reg is copied into a pseudo.  It\n\
+signals that all the call argument and return registers for the just\n\
+emitted call are now no longer in use.\n\
+Most ports do not need to implement anything for this hook.",
+ void, (void),
+ hook_void_void)
+
+DEFHOOK
 (strict_argument_naming,
  "Define this hook to return @code{true} if the location where a function\n\
 argument is passed depends on whether or not it is a named argument.\n\
Index: gcc/calls.c
===================================================================
--- gcc/calls.c.orig
+++ gcc/calls.c
@@ -2978,32 +2978,6 @@ expand_call (tree exp, rtx target, int i
 
       funexp = rtx_for_function_call (fndecl, addr);
 
-      /* Figure out the register where the value, if any, will come back.  */
-      valreg = 0;
-      if (TYPE_MODE (rettype) != VOIDmode
-	  && ! structure_value_addr)
-	{
-	  if (pcc_struct_value)
-	    valreg = hard_function_value (build_pointer_type (rettype),
-					  fndecl, NULL, (pass == 0));
-	  else
-	    valreg = hard_function_value (rettype, fndecl, fntype,
-					  (pass == 0));
-
-	  /* If VALREG is a PARALLEL whose first member has a zero
-	     offset, use that.  This is for targets such as m68k that
-	     return the same value in multiple places.  */
-	  if (GET_CODE (valreg) == PARALLEL)
-	    {
-	      rtx elem = XVECEXP (valreg, 0, 0);
-	      rtx where = XEXP (elem, 0);
-	      rtx offset = XEXP (elem, 1);
-	      if (offset == const0_rtx
-		  && GET_MODE (where) == GET_MODE (valreg))
-		valreg = where;
-	    }
-	}
-
       /* Precompute all register parameters.  It isn't safe to compute anything
 	 once we have started filling any specific hard regs.  */
       precompute_register_parameters (num_actuals, args, &reg_parm_seen);
@@ -3082,6 +3056,42 @@ expand_call (tree exp, rtx target, int i
 		sibcall_failure = 1;
 	    }
 
+      bool any_regs = false;
+      for (i = 0; i < num_actuals; i++)
+	if (args[i].reg != NULL_RTX)
+	  {
+	    any_regs = true;
+	    targetm.calls.call_args (args[i].reg, funtype);
+	  }
+      if (!any_regs)
+	targetm.calls.call_args (pc_rtx, funtype);
+
+      /* Figure out the register where the value, if any, will come back.  */
+      valreg = 0;
+      if (TYPE_MODE (rettype) != VOIDmode
+	  && ! structure_value_addr)
+	{
+	  if (pcc_struct_value)
+	    valreg = hard_function_value (build_pointer_type (rettype),
+					  fndecl, NULL, (pass == 0));
+	  else
+	    valreg = hard_function_value (rettype, fndecl, fntype,
+					  (pass == 0));
+
+	  /* If VALREG is a PARALLEL whose first member has a zero
+	     offset, use that.  This is for targets such as m68k that
+	     return the same value in multiple places.  */
+	  if (GET_CODE (valreg) == PARALLEL)
+	    {
+	      rtx elem = XVECEXP (valreg, 0, 0);
+	      rtx where = XEXP (elem, 0);
+	      rtx offset = XEXP (elem, 1);
+	      if (offset == const0_rtx
+		  && GET_MODE (where) == GET_MODE (valreg))
+		valreg = where;
+	    }
+	}
+
       /* If register arguments require space on the stack and stack space
 	 was not preallocated, allocate stack space here for arguments
 	 passed in registers.  */
@@ -3430,6 +3440,8 @@ expand_call (tree exp, rtx target, int i
       for (i = 0; i < num_actuals; ++i)
 	free (args[i].aligned_regs);
 
+      targetm.calls.end_call_args ();
+
       insns = get_insns ();
       end_sequence ();
 
@@ -3956,6 +3968,18 @@ emit_library_call_value_1 (int retval, r
     }
 #endif
 
+  /* When expanding a normal call, args are stored in push order,
+     which is the reverse of what we have here.  */
+  bool any_regs = false;
+  for (int i = nargs; i-- > 0; )
+    if (argvec[i].reg != NULL_RTX)
+      {
+	targetm.calls.call_args (argvec[i].reg, NULL_TREE);
+	any_regs = true;
+      }
+  if (!any_regs)
+    targetm.calls.call_args (pc_rtx, NULL_TREE);
+
   /* Push the args that need to be pushed.  */
 
   /* ARGNUM indexes the ARGVEC array in the order in which the arguments
@@ -4196,6 +4220,8 @@ emit_library_call_value_1 (int retval, r
       valreg = gen_rtx_REG (TYPE_MODE (tfom), REGNO (valreg));
     }
 
+  targetm.calls.end_call_args ();
+
   /* For calls to `setjmp', etc., inform function.c:setjmp_warnings
      that it should complain if nonvolatile values are live.  For
      functions that cannot return, inform flow that control does not

  reply	other threads:[~2014-10-28 14:52 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-20 14:19 The nvptx port [0/11+] Bernd Schmidt
2014-10-20 14:21 ` The nvptx port [1/11+] indirect jumps Bernd Schmidt
2014-10-21 18:29   ` Jeff Law
2014-10-21 21:03     ` Bernd Schmidt
2014-10-21 21:30       ` Jakub Jelinek
2014-10-21 21:37         ` Bernd Schmidt
2014-10-22  8:21           ` Richard Biener
2014-10-22  8:34             ` Jakub Jelinek
2014-10-22  8:37             ` Thomas Schwinge
2014-10-22 10:03               ` Richard Biener
2014-10-22 10:32                 ` Jakub Jelinek
2014-11-04 15:35   ` Bernd Schmidt
2014-11-04 15:43     ` Richard Henderson
2014-10-20 14:22 ` The nvptx port [2/11+] No register allocation Bernd Schmidt
2014-10-20 14:24 ` Bernd Schmidt
2014-10-21 18:36   ` Jeff Law
2014-10-20 14:24 ` The nvptx port [3/11+] Struct returns Bernd Schmidt
2014-10-21 18:41   ` Jeff Law
2014-10-20 14:27 ` The nvptx port [5/11+] Variable declarations Bernd Schmidt
2014-10-21 18:44   ` Jeff Law
2014-10-20 14:27 ` The nvptx port [4/11+] Post-RA pipeline Bernd Schmidt
2014-10-21 18:42   ` Jeff Law
2024-06-28 15:07   ` Document 'pass_postreload' vs. 'pass_late_compilation' (was: The nvptx port [4/11+] Post-RA pipeline) Thomas Schwinge
2014-10-20 14:31 ` The nvptx port [6/11+] Pseudo call args Bernd Schmidt
2014-10-21 18:56   ` Jeff Law
2014-10-20 14:32 ` The nvptx port [8/11+] Write undefined decls Bernd Schmidt
2014-10-21 22:07   ` Jeff Law
2014-10-21 22:30     ` Bernd Schmidt
2014-10-22 18:23       ` Jeff Law
2014-11-05 12:05         ` Bernd Schmidt
2014-11-05 20:05           ` Jeff Law
2014-10-20 14:32 ` The nvptx port [7/11+] Inform the port about call arguments Bernd Schmidt
2014-10-21 21:25   ` Jeff Law
2014-10-21 21:33     ` Bernd Schmidt
2014-10-21 21:55       ` Jeff Law
2014-10-21 22:16         ` Bernd Schmidt
2014-10-22 18:23           ` Jeff Law
2014-10-28 14:57             ` Bernd Schmidt [this message]
2014-10-29 23:42               ` Jeff Law
2014-10-20 14:35 ` The nvptx port [9/11+] Epilogues Bernd Schmidt
2014-10-21 22:08   ` Jeff Law
2014-10-20 14:50 ` The nvptx port [10/11+] Target files Bernd Schmidt
2014-10-22 18:12   ` Jeff Law
2014-10-28 15:10     ` Bernd Schmidt
2014-10-29 23:51       ` Jeff Law
2014-10-30  2:53         ` Bernd Schmidt
2014-10-30  3:09           ` Jeff Law
2014-11-10 16:33         ` Bernd Schmidt
2014-11-10 20:06           ` Jakub Jelinek
2014-11-10 20:37             ` H.J. Lu
2014-11-10 20:40             ` H.J. Lu
2014-11-10 20:42               ` Mike Stump
2014-12-12 20:18           ` Thomas Schwinge
2014-12-23 18:51           ` nvptx-tools and nvptx-newlib (was: The nvptx port [10/11+] Target files) Thomas Schwinge
2015-02-02 15:33             ` Thomas Schwinge
2015-02-04  9:43               ` Jakub Jelinek
2015-02-18  8:50                 ` Thomas Schwinge
2015-02-18  9:03                   ` Jakub Jelinek
2015-07-08 15:03                   ` [nvptx offloading] Only 64-bit configurations are currently supported (was: nvptx-tools and nvptx-newlib) Thomas Schwinge
2015-07-14 20:10                     ` [nvptx offloading] Only 64-bit configurations are currently supported Thomas Schwinge
2015-07-14 20:25                       ` Richard Biener
2021-01-14 18:18                     ` [nvptx libgomp plugin] Build only in supported configurations (was: [nvptx offloading] Only 64-bit configurations are currently supported) Thomas Schwinge
2021-03-04  8:52                       ` [committed] libgomp: Use sizeof(void*) based checks instead of looking through $CC $CFLAGS for -m32/-mx32 Jakub Jelinek
2021-03-22 11:24                         ` Thomas Schwinge
2014-11-04 16:48       ` The nvptx port [10/11+] Target files Richard Henderson
2014-11-04 16:55         ` Bernd Schmidt
2014-11-05 13:07           ` Bernd Schmidt
2014-10-20 14:58 ` The nvptx port [11/11] More tools Bernd Schmidt
2014-10-21  0:16   ` Joseph S. Myers
2014-10-22 20:40   ` Jeff Law
2014-10-22 21:16     ` Bernd Schmidt
2014-10-24 19:52       ` Jeff Law
2014-10-31 21:04   ` Jeff Law
     [not found]     ` <54542050.6010908@codesourcery.com>
2014-11-03 21:49       ` Jeff Law
2014-10-21  8:23 ` The nvptx port [0/11+] Richard Biener
2014-10-21 10:57   ` Bernd Schmidt
2014-10-21 11:27     ` Richard Biener
2014-10-21  9:17 ` Jakub Jelinek
2014-10-21 11:19   ` Bernd Schmidt
2014-11-12 12:36 ` Richard Biener
2014-11-12 21:39   ` Jeff Law
2015-02-18  7:48 ` nvptx-none: Define empty GOMP_SELF_SPECS (was: The nvptx port [0/11+]) Thomas Schwinge
2015-02-18  8:01 ` The nvptx port [0/11+] Thomas Schwinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=544FACE7.8030102@codesourcery.com \
    --to=bernds@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).