public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@arm.com>
To: gcc-patches@gcc.gnu.org
Subject: [12/13] Make calls.c use function_arg_info internally
Date: Mon, 19 Aug 2019 15:52:00 -0000	[thread overview]
Message-ID: <mptef1hb2mw.fsf@arm.com> (raw)
In-Reply-To: <mpt1rxhdwbz.fsf@arm.com> (Richard Sandiford's message of "Mon,	19 Aug 2019 16:11:12 +0100")

This patch makes the two main calls.c argument-processing
routines track the state of the argument in a function_arg_info
instead of using separate mode variables.


2019-08-19  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* calls.c (emit_library_call_value_1): Merge arg and orig_arg
	into a single function_arg_info, updating its fields when we
	apply pass-by-reference and promotion semantics.  Use the
	function_arg_info to track the mode rather than keeping it in
	a separate local variable.
	(initialize_argument_information): Likewise.  Base the final
	arg_to_skip on this new function_arg_info rather than creating
	a new one from scratch.

Index: gcc/calls.c
===================================================================
--- gcc/calls.c	2019-08-19 15:59:09.801778220 +0100
+++ gcc/calls.c	2019-08-19 15:59:18.145717843 +0100
@@ -1982,7 +1982,6 @@ initialize_argument_information (int num
     {
       tree type = TREE_TYPE (args[i].tree_value);
       int unsignedp;
-      machine_mode mode;
 
       /* Replace erroneous argument with constant zero.  */
       if (type == error_mark_node || !COMPLETE_TYPE_P (type))
@@ -2010,13 +2009,13 @@ initialize_argument_information (int num
 	 with those made by function.c.  */
 
       /* See if this argument should be passed by invisible reference.  */
-      function_arg_info orig_arg (type, argpos < n_named_args);
-      if (pass_by_reference (args_so_far_pnt, orig_arg))
+      function_arg_info arg (type, argpos < n_named_args);
+      if (pass_by_reference (args_so_far_pnt, arg))
 	{
 	  bool callee_copies;
 	  tree base = NULL_TREE;
 
-	  callee_copies = reference_callee_copied (args_so_far_pnt, orig_arg);
+	  callee_copies = reference_callee_copied (args_so_far_pnt, arg);
 
 	  /* If we're compiling a thunk, pass through invisible references
 	     instead of making a copy.  */
@@ -2129,15 +2128,16 @@ initialize_argument_information (int num
 	}
 
       unsignedp = TYPE_UNSIGNED (type);
-      mode = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
-				    fndecl ? TREE_TYPE (fndecl) : fntype, 0);
+      arg.type = type;
+      arg.mode
+	= promote_function_mode (type, TYPE_MODE (type), &unsignedp,
+				 fndecl ? TREE_TYPE (fndecl) : fntype, 0);
 
       args[i].unsignedp = unsignedp;
-      args[i].mode = mode;
+      args[i].mode = arg.mode;
 
       targetm.calls.warn_parameter_passing_abi (args_so_far, type);
 
-      function_arg_info arg (type, mode, argpos < n_named_args);
       args[i].reg = targetm.calls.function_arg (args_so_far, arg);
 
       if (args[i].reg && CONST_INT_P (args[i].reg))
@@ -2177,7 +2177,7 @@ initialize_argument_information (int num
       if (args[i].reg == 0 || args[i].partial != 0
 	       || reg_parm_stack_space > 0
 	       || args[i].pass_on_stack)
-	locate_and_pad_parm (mode, type,
+	locate_and_pad_parm (arg.mode, type,
 #ifdef STACK_PARMS_IN_REG_PARM_AREA
 			     1,
 #else
@@ -2191,7 +2191,7 @@ initialize_argument_information (int num
 	/* The argument is passed entirely in registers.  See at which
 	   end it should be padded.  */
 	args[i].locate.where_pad =
-	  BLOCK_REG_PADDING (mode, type,
+	  BLOCK_REG_PADDING (arg.mode, type,
 			     int_size_in_bytes (type) <= UNITS_PER_WORD);
 #endif
 
@@ -2208,9 +2208,8 @@ initialize_argument_information (int num
 	 promoted_mode used for function_arg above.  However, the
 	 corresponding handling of incoming arguments in function.c
 	 does pass the promoted mode.  */
-      function_arg_info arg_to_skip (type, TYPE_MODE (type),
-				     argpos < n_named_args);
-      targetm.calls.function_arg_advance (args_so_far, arg_to_skip);
+      arg.mode = TYPE_MODE (type);
+      targetm.calls.function_arg_advance (args_so_far, arg);
 
       /* Store argument values for functions decorated with attribute
 	 alloc_size.  */
@@ -4906,24 +4905,25 @@ emit_library_call_value_1 (int retval, r
   for (unsigned int i = 0; count < nargs; i++, count++)
     {
       rtx val = args[i].first;
-      machine_mode mode = args[i].second;
+      function_arg_info arg (args[i].second, /*named=*/true);
       int unsigned_p = 0;
 
       /* We cannot convert the arg value to the mode the library wants here;
 	 must do it earlier where we know the signedness of the arg.  */
-      gcc_assert (mode != BLKmode
-		  && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode));
+      gcc_assert (arg.mode != BLKmode
+		  && (GET_MODE (val) == arg.mode
+		      || GET_MODE (val) == VOIDmode));
 
       /* Make sure it is a reasonable operand for a move or push insn.  */
       if (!REG_P (val) && !MEM_P (val)
-	  && !(CONSTANT_P (val) && targetm.legitimate_constant_p (mode, val)))
+	  && !(CONSTANT_P (val)
+	       && targetm.legitimate_constant_p (arg.mode, val)))
 	val = force_operand (val, NULL_RTX);
 
-      function_arg_info orig_arg (mode, /*named=*/true);
-      if (pass_by_reference (&args_so_far_v, orig_arg))
+      if (pass_by_reference (&args_so_far_v, arg))
 	{
 	  rtx slot;
-	  int must_copy = !reference_callee_copied (&args_so_far_v, orig_arg);
+	  int must_copy = !reference_callee_copied (&args_so_far_v, arg);
 
 	  /* If this was a CONST function, it is now PURE since it now
 	     reads memory.  */
@@ -4942,7 +4942,7 @@ emit_library_call_value_1 (int retval, r
 	    }
 	  else
 	    {
-	      slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0),
+	      slot = assign_temp (lang_hooks.types.type_for_mode (arg.mode, 0),
 				  1, 1);
 	      emit_move_insn (slot, val);
 	    }
@@ -4956,14 +4956,15 @@ emit_library_call_value_1 (int retval, r
 							      slot),
 					     call_fusage);
 
-	  mode = Pmode;
+	  arg.mode = Pmode;
 	  val = force_operand (XEXP (slot, 0), NULL_RTX);
 	}
 
-      mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
-      function_arg_info arg (mode, /*named=*/true);
-      argvec[count].mode = mode;
-      argvec[count].value = convert_modes (mode, GET_MODE (val), val, unsigned_p);
+      arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p,
+					NULL_TREE, 0);
+      argvec[count].mode = arg.mode;
+      argvec[count].value = convert_modes (arg.mode, GET_MODE (val), val,
+					   unsigned_p);
       argvec[count].reg = targetm.calls.function_arg (args_so_far, arg);
 
       argvec[count].partial
@@ -4973,7 +4974,7 @@ emit_library_call_value_1 (int retval, r
 	  || argvec[count].partial != 0
 	  || reg_parm_stack_space > 0)
 	{
-	  locate_and_pad_parm (mode, NULL_TREE,
+	  locate_and_pad_parm (arg.mode, NULL_TREE,
 #ifdef STACK_PARMS_IN_REG_PARM_AREA
 			       1,
 #else
@@ -4989,8 +4990,9 @@ emit_library_call_value_1 (int retval, r
 	/* The argument is passed entirely in registers.  See at which
 	   end it should be padded.  */
 	argvec[count].locate.where_pad =
-	  BLOCK_REG_PADDING (mode, NULL_TREE,
-			     known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD));
+	  BLOCK_REG_PADDING (arg.mode, NULL_TREE,
+			     known_le (GET_MODE_SIZE (arg.mode),
+				       UNITS_PER_WORD));
 #endif
 
       targetm.calls.function_arg_advance (args_so_far, arg);

  parent reply	other threads:[~2019-08-19 15:23 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19 15:15 [00/13] Pass an argument descriptor to target hooks Richard Sandiford
2019-08-19 15:16 ` [01/13] Add pass_va_arg_by_reference Richard Sandiford
2019-08-19 20:04   ` Jeff Law
2019-08-19 15:17 ` [02/13] Add must_pass_va_arg_in_stack Richard Sandiford
2019-08-19 20:05   ` Jeff Law
2019-08-19 15:18 ` [03/13] Use function_arg_info for TARGET_ARG_PARTIAL_BYTES Richard Sandiford
2019-08-19 20:42   ` Jeff Law
2019-08-19 15:19 ` [04/13] Use function_arg_info for TARGET_PASS_BY_REFERENCE Richard Sandiford
2019-08-19 20:43   ` Jeff Law
2019-08-19 15:20 ` [05/13] Use function_arg_info for TARGET_SETUP_INCOMING_ARGS Richard Sandiford
2019-08-19 20:50   ` Jeff Law
2019-08-19 15:21 ` [06/13] Use function_arg_info for TARGET_FUNCTION_(INCOMING_)ARG Richard Sandiford
2019-08-19 21:07   ` Jeff Law
2019-08-19 15:22 ` [07/13] Use function_arg_info for TARGET_FUNCTION_ARG_ADVANCE Richard Sandiford
2019-08-19 21:11   ` Jeff Law
2019-08-19 15:23 ` [08/13] Use function_arg_info for TARGET_CALLEE_COPIES Richard Sandiford
2019-08-19 21:16   ` Jeff Law
2019-08-19 15:24 ` [09/13] Use function_arg_info for TARGET_MUST_PASS_IN_STACK Richard Sandiford
2019-08-19 22:04   ` Jeff Law
2019-08-19 15:47 ` [10/13] Add a apply_pass_by_reference_rules helper Richard Sandiford
2019-08-19 22:19   ` Jeff Law
2019-08-19 15:51 ` [11/13] Make function.c use function_arg_info internally Richard Sandiford
2019-08-19 22:47   ` Jeff Law
2019-08-19 15:52 ` Richard Sandiford [this message]
2019-08-19 22:49   ` [12/13] Make calls.c " Jeff Law
2019-08-19 15:52 ` [13/13] Add a pass_by_reference flag to function_arg_info Richard Sandiford
2019-08-19 22:54   ` Jeff Law

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=mptef1hb2mw.fsf@arm.com \
    --to=richard.sandiford@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).