diff mbox

[PTX] Adjust mode splitting

Message ID 5654C622.9050406@acm.org
State New
Headers show

Commit Message

Nathan Sidwell Nov. 24, 2015, 8:18 p.m. UTC
The PTX backend has a lot of helper functions that are almost but not quite the 
same.  I've committed this patch to adjust maybe_split_mode, and thereby  remove 
nvptx_split_reg_p.

maybe_split_mode always returned 1 or 2, and (some) users checked the return 
value to learn whether splitting should be done or  not.  Rather than have it 
return a count, I've changed it to return the inner mode, or VOIDmode  for no 
splitting.

nathan
diff mbox

Patch

2015-11-24  Nathan Sidwell  <nathan@acm.org>

	* config/nvptx/nvptx.c (maybe_split_mode): Return new mode or
	VOIDmode, don't alter incoming mode.
	(nvptx_split_reg_p): Delete.
	(write_one_arg, walk_args_for_param, nvptx_declare_function_name,
	write_func_decl_from_insn, nvptx_output_call_insn): Adjust
	maybe_split_mode calls.
	(nvptx_print_operand): Use maybe_split_mode.

Index: config/nvptx/nvptx.c
===================================================================
--- config/nvptx/nvptx.c	(revision 230835)
+++ config/nvptx/nvptx.c	(working copy)
@@ -206,37 +206,19 @@  nvptx_ptx_type_from_mode (machine_mode m
     }
 }
 
-/* Return the number of pieces to use when dealing with a pseudo of *PMODE.
-   Alter *PMODE if we return a number greater than one.  */
+/* If MODE should be treated as two registers of an inner mode, return
+   that inner mode.  Otherwise return VOIDmode.  */
 
-static int
-maybe_split_mode (machine_mode *pmode)
+static machine_mode
+maybe_split_mode (machine_mode mode)
 {
-  machine_mode mode = *pmode;
-
   if (COMPLEX_MODE_P (mode))
-    {
-      *pmode = GET_MODE_INNER (mode);
-      return 2;
-    }
-  else if (mode == TImode)
-    {
-      *pmode = DImode;
-      return 2;
-    }
-  return 1;
-}
+    return GET_MODE_INNER (mode);
 
-/* Like maybe_split_mode, but only return whether or not the mode
-   needs to be split.  */
-static bool
-nvptx_split_reg_p (machine_mode mode)
-{
-  if (COMPLEX_MODE_P (mode))
-    return true;
   if (mode == TImode)
-    return true;
-  return false;
+    return DImode;
+
+  return VOIDmode;
 }
 
 /* Emit forking instructions for MASK.  */
@@ -315,12 +297,11 @@  write_one_arg (std::stringstream &s, tre
   if (!PASS_IN_REG_P (mode, type))
     mode = Pmode;
 
-  int count = maybe_split_mode (&mode);
-
-  if (count == 2)
+  machine_mode split = maybe_split_mode (mode);
+  if (split != VOIDmode)
     {
-      write_one_arg (s, NULL_TREE, i, mode, false);
-      write_one_arg (s, NULL_TREE, i + 1, mode, false);
+      write_one_arg (s, NULL_TREE, i, split, false);
+      write_one_arg (s, NULL_TREE, i + 1, split, false);
       return i + 1;
     }
 
@@ -477,6 +458,7 @@  walk_args_for_param (FILE *file, tree ar
     {
       tree type = args_from_decl ? TREE_TYPE (args) : TREE_VALUE (args);
       machine_mode mode = TYPE_MODE (type);
+      int count = 1;
 
       if (mode == VOIDmode)
 	break;
@@ -484,18 +466,17 @@  walk_args_for_param (FILE *file, tree ar
       if (!PASS_IN_REG_P (mode, type))
 	mode = Pmode;
 
-      int count = maybe_split_mode (&mode);
-      if (count == 1)
+      machine_mode split = maybe_split_mode (mode);
+      if (split != VOIDmode)
 	{
-	  if (argtypes == NULL && !AGGREGATE_TYPE_P (type))
-	    {
-	      if (mode == SFmode)
-		mode = DFmode;
-
-	    }
+	  count = 2;
+	  mode = split;
 	}
+      else if (argtypes == NULL && !AGGREGATE_TYPE_P (type) && mode == SFmode)
+	mode = DFmode;
+
       mode = arg_promotion (mode);
-      while (count-- > 0)
+      while (count--)
 	{
 	  i++;
 	  if (write_copy)
@@ -662,18 +643,17 @@  nvptx_declare_function_name (FILE *file,
       if (regno_reg_rtx[i] != const0_rtx)
 	{
 	  machine_mode mode = PSEUDO_REGNO_MODE (i);
-	  int count = maybe_split_mode (&mode);
-	  if (count > 1)
+	  machine_mode split = maybe_split_mode (mode);
+	  if (split != VOIDmode)
 	    {
-	      while (count-- > 0)
-		fprintf (file, "\t.reg%s %%r%d$%d;\n",
-			 nvptx_ptx_type_from_mode (mode, true),
-			 i, count);
+	      fprintf (file, "\t.reg%s %%r%d$%d;\n",
+		       nvptx_ptx_type_from_mode (split, true), i, 0);
+	      fprintf (file, "\t.reg%s %%r%d$%d;\n",
+		       nvptx_ptx_type_from_mode (split, true), i, 1);
 	    }
 	  else
 	    fprintf (file, "\t.reg%s %%r%d;\n",
-		     nvptx_ptx_type_from_mode (mode, true),
-		     i);
+		     nvptx_ptx_type_from_mode (mode, true), i);
 	}
     }
 
@@ -794,7 +774,14 @@  write_func_decl_from_insn (std::stringst
 	{
 	  rtx t = XEXP (XVECEXP (pat, 0, i), 0);
 	  machine_mode mode = GET_MODE (t);
-	  int count = maybe_split_mode (&mode);
+	  machine_mode split = maybe_split_mode (mode);
+	  int count = 1;
+
+	  if (split != VOIDmode)
+	    {
+	      mode = split;
+	      count = 2;
+	    }
 
 	  while (count--)
 	    {
@@ -1863,32 +1850,29 @@  nvptx_output_call_insn (rtx_insn *insn,
     {
       rtx t = XEXP (XVECEXP (pat, 0, i), 0);
       machine_mode mode = GET_MODE (t);
-      int count = maybe_split_mode (&mode);
-
-      while (count--)
-	fprintf (asm_out_file, "\t\t.param%s %%out_arg%d%s;\n",
-		 nvptx_ptx_type_from_mode (mode, false), argno++,
-		 mode == QImode || mode == HImode ? "[1]" : "");
-    }
-  for (int i = 1, argno = 0; i < arg_end; i++)
-    {
-      rtx t = XEXP (XVECEXP (pat, 0, i), 0);
-      gcc_assert (REG_P (t));
-      machine_mode mode = GET_MODE (t);
-      int count = maybe_split_mode (&mode);
+      machine_mode split = maybe_split_mode (mode);
+      int count = 1;
+      
+      if (split != VOIDmode)
+	{
+	  mode = split;
+	  count  = 2;
+	}
 
-      if (count == 1)
-	fprintf (asm_out_file, "\t\tst.param%s [%%out_arg%d], %%r%d;\n",
-		 nvptx_ptx_type_from_mode (mode, false), argno++,
-		 REGNO (t));
-      else
+      for (int n = 0; n != count; n++)
 	{
-	  int n = 0;
-	  while (count--)
-	    fprintf (asm_out_file, "\t\tst.param%s [%%out_arg%d], %%r%d$%d;\n",
-		     nvptx_ptx_type_from_mode (mode, false), argno++,
-		     REGNO (t), n++);
+	  fprintf (asm_out_file, "\t\t.param%s %%out_arg%d%s;\n",
+		   nvptx_ptx_type_from_mode (mode, false), argno,
+		   mode == QImode || mode == HImode ? "[1]" : "");
+	  fprintf (asm_out_file, "\t\tst.param%s [%%out_arg%d], %%r%d",
+		   nvptx_ptx_type_from_mode (mode, false), argno,
+		   REGNO (t));
+	  if (split != VOIDmode)
+	    fprintf (asm_out_file, "$%d", n);
+	  fprintf (asm_out_file, ";\n");
+	  argno++;
 	}
+      
     }
 
   fprintf (asm_out_file, "\t\tcall ");
@@ -1913,13 +1897,15 @@  nvptx_output_call_insn (rtx_insn *insn,
 	{
 	  rtx t = XEXP (XVECEXP (pat, 0, i), 0);
 	  machine_mode mode = GET_MODE (t);
-	  int count = maybe_split_mode (&mode);
+	  machine_mode split = maybe_split_mode (mode);
 
-	  while (count--)
+	  if (split != VOIDmode)
 	    {
 	      fprintf (asm_out_file, "%s%%out_arg%d", comma, argno++);
 	      comma = ", ";
 	    }
+	  fprintf (asm_out_file, "%s%%out_arg%d", comma, argno++);
+	  comma = ", ";
 	}
       if (decl && DECL_STATIC_CHAIN (decl))
 	fprintf (asm_out_file, "%s%s", comma,
@@ -2155,10 +2141,10 @@  nvptx_print_operand (FILE *file, rtx x,
 	    fprintf (file, "%s", reg_names[REGNO (x)]);
 	  else
 	    fprintf (file, "%%r%d", REGNO (x));
-	  if (code != 'f' && nvptx_split_reg_p (GET_MODE (x)))
+	  if (code != 'f' && maybe_split_mode (GET_MODE (x)) != VOIDmode)
 	    {
 	      gcc_assert (GET_CODE (orig_x) == SUBREG
-			  && !nvptx_split_reg_p (GET_MODE (orig_x)));
+			  && maybe_split_mode (GET_MODE (orig_x)) == VOIDmode);
 	      fprintf (file, "$%d", SUBREG_BYTE (orig_x) / UNITS_PER_WORD);
 	    }
 	  break;