Re: Turn FUNCTION_ARG_OFFSET into a hook

2017-09-14 Thread Jeff Law
On 09/13/2017 01:22 PM, Richard Sandiford wrote:
> Nice and easy, one definition and one use :-)
> 
> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.
> Also tested by comparing the testsuite assembly output on at least one
> target per CPU directory.  OK to install?
> 
> Richard
> 
> 
> 2017-09-13  Richard Sandiford  
>   Alan Hayward  
>   David Sherwood  
> 
> gcc/
>   * target.def (function_arg_offset): New hook.
>   * targhooks.h (default_function_arg_offset): Declare.
>   * targhooks.c (default_function_arg_offset): New function.
>   * function.c (locate_and_pad_parm): Use
>   targetm.calls.function_arg_offset instead of FUNCTION_ARG_OFFSET.
>   * doc/tm.texi.in (FUNCTION_ARG_OFFSET): Replace with...
>   (TARGET_FUNCTION_ARG_OFFSET): ...this.
>   * doc/tm.texi: Regenerate.
>   * config/spu/spu.h (FUNCTION_ARG_OFFSET): Delete.
>   * config/spu/spu.c (spu_function_arg_offset): New function.
>   (TARGET_FUNCTION_ARG_OFFSET): Redefine.
>   * system.h (FUNCTION_ARG_OFFSET): Poison.
OK.
jeff


Turn FUNCTION_ARG_OFFSET into a hook

2017-09-13 Thread Richard Sandiford
Nice and easy, one definition and one use :-)

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.
Also tested by comparing the testsuite assembly output on at least one
target per CPU directory.  OK to install?

Richard


2017-09-13  Richard Sandiford  
Alan Hayward  
David Sherwood  

gcc/
* target.def (function_arg_offset): New hook.
* targhooks.h (default_function_arg_offset): Declare.
* targhooks.c (default_function_arg_offset): New function.
* function.c (locate_and_pad_parm): Use
targetm.calls.function_arg_offset instead of FUNCTION_ARG_OFFSET.
* doc/tm.texi.in (FUNCTION_ARG_OFFSET): Replace with...
(TARGET_FUNCTION_ARG_OFFSET): ...this.
* doc/tm.texi: Regenerate.
* config/spu/spu.h (FUNCTION_ARG_OFFSET): Delete.
* config/spu/spu.c (spu_function_arg_offset): New function.
(TARGET_FUNCTION_ARG_OFFSET): Redefine.
* system.h (FUNCTION_ARG_OFFSET): Poison.

Index: gcc/target.def
===
--- gcc/target.def  2017-09-13 20:12:24.499190740 +0100
+++ gcc/target.def  2017-09-13 20:14:46.245761652 +0100
@@ -4573,6 +4573,16 @@ used for arguments without any special h
  default_function_arg_advance)
 
 DEFHOOK
+(function_arg_offset,
+ "This hook returns the number of bytes to add to the offset of an\n\
+argument of type @var{type} and mode @var{mode} when passed in memory.\n\
+This is needed for the SPU, which passes @code{char} and @code{short}\n\
+arguments in the preferred slot that is in the middle of the quad word\n\
+instead of starting at the top.  The default implementation returns 0.",
+ HOST_WIDE_INT, (machine_mode mode, const_tree type),
+ default_function_arg_offset)
+
+DEFHOOK
 (function_arg_padding,
  "This hook determines whether, and in which direction, to pad out\n\
 an argument of mode @var{mode} and type @var{type}.  It returns\n\
Index: gcc/targhooks.h
===
--- gcc/targhooks.h 2017-09-13 18:03:51.114330107 +0100
+++ gcc/targhooks.h 2017-09-13 20:14:46.245761652 +0100
@@ -132,6 +132,7 @@ extern bool hook_bool_CUMULATIVE_ARGS_tr
   (const_tree, const_tree, const_tree);
 extern void default_function_arg_advance
   (cumulative_args_t, machine_mode, const_tree, bool);
+extern HOST_WIDE_INT default_function_arg_offset (machine_mode, const_tree);
 extern pad_direction default_function_arg_padding (machine_mode, const_tree);
 extern rtx default_function_arg
   (cumulative_args_t, machine_mode, const_tree, bool);
Index: gcc/targhooks.c
===
--- gcc/targhooks.c 2017-09-13 18:03:51.114330107 +0100
+++ gcc/targhooks.c 2017-09-13 20:14:46.245761652 +0100
@@ -734,6 +734,14 @@ default_function_arg_advance (cumulative
   gcc_unreachable ();
 }
 
+/* Default implementation of TARGET_FUNCTION_ARG_OFFSET.  */
+
+HOST_WIDE_INT
+default_function_arg_offset (machine_mode, const_tree)
+{
+  return 0;
+}
+
 /* Default implementation of TARGET_FUNCTION_ARG_PADDING: usually pad
upward, but pad short args downward on big-endian machines.  */
 
Index: gcc/function.c
===
--- gcc/function.c  2017-09-13 20:12:24.498282217 +0100
+++ gcc/function.c  2017-09-13 20:14:46.244854334 +0100
@@ -4249,9 +4249,8 @@ locate_and_pad_parm (machine_mode passed
   locate->size.constant -= part_size_in_regs;
 }
 
-#ifdef FUNCTION_ARG_OFFSET
-  locate->offset.constant += FUNCTION_ARG_OFFSET (passed_mode, type);
-#endif
+  locate->offset.constant
++= targetm.calls.function_arg_offset (passed_mode, type);
 }
 
 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
Index: gcc/doc/tm.texi.in
===
--- gcc/doc/tm.texi.in  2017-09-13 20:12:24.496465170 +0100
+++ gcc/doc/tm.texi.in  2017-09-13 20:14:46.243947015 +0100
@@ -3281,13 +3281,7 @@ argument @var{libname} exists for symmet
 
 @hook TARGET_FUNCTION_ARG_ADVANCE
 
-@defmac FUNCTION_ARG_OFFSET (@var{mode}, @var{type})
-If defined, a C expression that is the number of bytes to add to the
-offset of the argument passed in memory.  This is needed for the SPU,
-which passes @code{char} and @code{short} arguments in the preferred
-slot that is in the middle of the quad word instead of starting at the
-top.
-@end defmac
+@hook TARGET_FUNCTION_ARG_OFFSET
 
 @hook TARGET_FUNCTION_ARG_PADDING
 
Index: gcc/doc/tm.texi
===
--- gcc/doc/tm.texi 2017-09-13 20:12:24.496465170 +0100
+++ gcc/doc/tm.texi 2017-09-13 20:14:46.243947015 +0100
@@ -4079,13 +4079,13 @@ on the stack.  The compiler knows how to
 used for arguments without any special help.
 @end