Re: [10/13] Add a apply_pass_by_reference_rules helper

2019-08-19 Thread Jeff Law
On 8/19/19 9:21 AM, Richard Sandiford wrote:
> This patch adds a helper routine that applies pass-by-reference
> semantics to an existing function_arg_info.
> 
> The c6x part means that c6x_function_arg and c6x_function_arg_advance
> see the same "named" value as pass_by_reference did, rather than
> pass_by_reference seeing "true" and the others seeing "false".
> This doesn't matter because the c6x port doesn't care about namedness.
> 
> The rs6000.c patch removes an assignment to "type", but the only
> later code to use it was the patched promote_mode line.
> 
> (The reason for patching these places despite the above is that
> often target code gets used as a basis for new targets or changes
> to existing ones.)
> 
> 
> 2019-08-19  Richard Sandiford  
> 
> gcc/
>   * calls.h (apply_pass_by_reference_rules): Declare.
>   * calls.c (apply_pass_by_reference_rules): New function.
>   * config/c6x/c6x.c (c6x_call_saved_register_used): Use it.
>   * config/rs6000/rs6000-call.c (rs6000_parm_needs_stack): Likewise.
>   * config/s390/s390.c (s390_call_saved_register_used): Likewise.
>   * function.c (assign_parm_find_data_types): Likewise.
>   * var-tracking.c (prepare_call_arguments): Likewise.
> 
OK
jeff


[10/13] Add a apply_pass_by_reference_rules helper

2019-08-19 Thread Richard Sandiford
This patch adds a helper routine that applies pass-by-reference
semantics to an existing function_arg_info.

The c6x part means that c6x_function_arg and c6x_function_arg_advance
see the same "named" value as pass_by_reference did, rather than
pass_by_reference seeing "true" and the others seeing "false".
This doesn't matter because the c6x port doesn't care about namedness.

The rs6000.c patch removes an assignment to "type", but the only
later code to use it was the patched promote_mode line.

(The reason for patching these places despite the above is that
often target code gets used as a basis for new targets or changes
to existing ones.)


2019-08-19  Richard Sandiford  

gcc/
* calls.h (apply_pass_by_reference_rules): Declare.
* calls.c (apply_pass_by_reference_rules): New function.
* config/c6x/c6x.c (c6x_call_saved_register_used): Use it.
* config/rs6000/rs6000-call.c (rs6000_parm_needs_stack): Likewise.
* config/s390/s390.c (s390_call_saved_register_used): Likewise.
* function.c (assign_parm_find_data_types): Likewise.
* var-tracking.c (prepare_call_arguments): Likewise.

Index: gcc/calls.h
===
--- gcc/calls.h 2019-08-19 15:59:04.261818304 +0100
+++ gcc/calls.h 2019-08-19 15:59:09.801778220 +0100
@@ -118,6 +118,8 @@ extern void fixup_tail_calls (void);
 
 extern bool pass_by_reference (CUMULATIVE_ARGS *, function_arg_info);
 extern bool pass_va_arg_by_reference (tree);
+extern bool apply_pass_by_reference_rules (CUMULATIVE_ARGS *,
+  function_arg_info &);
 extern bool reference_callee_copied (CUMULATIVE_ARGS *,
 const function_arg_info &);
 extern void maybe_warn_alloc_args_overflow (tree, tree, tree[2], int[2]);
Index: gcc/calls.c
===
--- gcc/calls.c 2019-08-19 15:59:04.261818304 +0100
+++ gcc/calls.c 2019-08-19 15:59:09.801778220 +0100
@@ -935,6 +935,22 @@ pass_va_arg_by_reference (tree type)
   return pass_by_reference (NULL, function_arg_info (type, /*named=*/false));
 }
 
+/* Decide whether ARG, which occurs in the state described by CA,
+   should be passed by reference.  Return true if so and update
+   ARG accordingly.  */
+
+bool
+apply_pass_by_reference_rules (CUMULATIVE_ARGS *ca, function_arg_info )
+{
+  if (pass_by_reference (ca, arg))
+{
+  arg.type = build_pointer_type (arg.type);
+  arg.mode = TYPE_MODE (arg.type);
+  return true;
+}
+  return false;
+}
+
 /* Return true if ARG, which is passed by reference, should be callee
copied instead of caller copied.  */
 
Index: gcc/config/c6x/c6x.c
===
--- gcc/config/c6x/c6x.c2019-08-19 15:58:58.001863604 +0100
+++ gcc/config/c6x/c6x.c2019-08-19 15:59:09.805778189 +0100
@@ -1088,8 +1088,6 @@ c6x_call_saved_register_used (tree call_
   cumulative_args_t cum;
   HARD_REG_SET call_saved_regset;
   tree parameter;
-  machine_mode mode;
-  tree type;
   rtx parm_rtx;
   int i;
 
@@ -1107,19 +1105,9 @@ c6x_call_saved_register_used (tree call_
   if (TREE_CODE (parameter) == ERROR_MARK)
return true;
 
-  type = TREE_TYPE (parameter);
-  gcc_assert (type);
+  function_arg_info arg (TREE_TYPE (parameter), /*named=*/true);
+  apply_pass_by_reference_rules (_v, arg);
 
-  mode = TYPE_MODE (type);
-  gcc_assert (mode);
-
-  if (pass_by_reference (_v, function_arg_info (type, /*named=*/true)))
-   {
- mode = Pmode;
- type = build_pointer_type (type);
-   }
-
-   function_arg_info arg (type, mode, /*named=*/false);
parm_rtx = c6x_function_arg (cum, arg);
 
c6x_function_arg_advance (cum, arg);
Index: gcc/config/rs6000/rs6000-call.c
===
--- gcc/config/rs6000/rs6000-call.c 2019-08-19 15:59:04.285818131 +0100
+++ gcc/config/rs6000/rs6000-call.c 2019-08-19 15:59:09.805778189 +0100
@@ -2170,7 +2170,6 @@ rs6000_pass_by_reference (cumulative_arg
 static bool
 rs6000_parm_needs_stack (cumulative_args_t args_so_far, tree type)
 {
-  machine_mode mode;
   int unsignedp;
   rtx entry_parm;
 
@@ -2193,16 +2192,14 @@ rs6000_parm_needs_stack (cumulative_args
 type = TREE_TYPE (first_field (type));
 
   /* See if this arg was passed by invisible reference.  */
-  if (pass_by_reference (get_cumulative_args (args_so_far),
-function_arg_info (type, /*named=*/true)))
-type = build_pointer_type (type);
+  function_arg_info arg (type, /*named=*/true);
+  apply_pass_by_reference_rules (get_cumulative_args (args_so_far), arg);
 
   /* Find mode as it is passed by the ABI.  */
   unsignedp = TYPE_UNSIGNED (type);
-  mode = promote_mode (type, TYPE_MODE (type), );
+  arg.mode = promote_mode (arg.type, arg.mode, );
 
   /* If we must pass