diff mbox series

[09/25] Elide repeated RTL elements.

Message ID 626ff7cb294733fe61c5e7b05de436400bd9c262.1536144068.git.ams@codesourcery.com
State New
Headers show
Series AMD GCN Port | expand

Commit Message

Andrew Stubbs Sept. 5, 2018, 11:49 a.m. UTC
GCN's 64-lane vectors tend to make RTL dumps very long.  This patch makes them
far more bearable by eliding long sequences of the same element into "repeated"
messages.

2018-09-05  Andrew Stubbs  <ams@codesourcery.com>
	    Jan Hubicka  <jh@suse.cz>
	    Martin Jambor  <mjambor@suse.cz>

	* print-rtl.c (print_rtx_operand_codes_E_and_V): Print how many times
	the same elements are repeated rather than printing all of them.
---
 gcc/print-rtl.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Jeff Law Sept. 11, 2018, 10:45 p.m. UTC | #1
On 9/5/18 5:49 AM, ams@codesourcery.com wrote:
> 
> GCN's 64-lane vectors tend to make RTL dumps very long.  This patch makes them
> far more bearable by eliding long sequences of the same element into "repeated"
> messages.
> 
> 2018-09-05  Andrew Stubbs  <ams@codesourcery.com>
> 	    Jan Hubicka  <jh@suse.cz>
> 	    Martin Jambor  <mjambor@suse.cz>
> 
> 	* print-rtl.c (print_rtx_operand_codes_E_and_V): Print how many times
> 	the same elements are repeated rather than printing all of them.
Does this need a corresponding change to the RTL front-end so that it
can read the new form?

jeff
Andrew Stubbs Sept. 12, 2018, 8:46 a.m. UTC | #2
On 11/09/18 23:45, Jeff Law wrote:
> Does this need a corresponding change to the RTL front-end so that it
> can read the new form?

There's an RTL front-end? When did that happen... clearly I've not been 
paying attention.

If it's expected that dumps can be fed back in unmodified then yes, it 
needs to recognise the new output.

I'll look into it.

Andrew
Jeff Law Sept. 12, 2018, 3:14 p.m. UTC | #3
On 9/12/18 2:46 AM, Andrew Stubbs wrote:
> On 11/09/18 23:45, Jeff Law wrote:
>> Does this need a corresponding change to the RTL front-end so that it
>> can read the new form?
> 
> There's an RTL front-end? When did that happen... clearly I've not been
> paying attention.
Within the last couple years.  It's primarily for testing purposes so
that we can take RTL, feed it back into a pass and then look at the
results.  There's some tests in the testsuite you can poke at to see how
it works -- they're probably also a good starting point for a test that
we can properly reconstruct RTL with elided elements.


> 
> If it's expected that dumps can be fed back in unmodified then yes, it
> needs to recognise the new output.
I don't think it goes in strictly unmodified, but ISTM we need to be
able to handle this case.

Thanks,
Jeff
Andrew Stubbs Sept. 19, 2018, 4:38 p.m. UTC | #4
On 11/09/18 23:45, Jeff Law wrote:
> On 9/5/18 5:49 AM, ams@codesourcery.com wrote:
>>
>> GCN's 64-lane vectors tend to make RTL dumps very long.  This patch makes them
>> far more bearable by eliding long sequences of the same element into "repeated"
>> messages.
>>
>> 2018-09-05  Andrew Stubbs  <ams@codesourcery.com>
>> 	    Jan Hubicka  <jh@suse.cz>
>> 	    Martin Jambor  <mjambor@suse.cz>
>>
>> 	* print-rtl.c (print_rtx_operand_codes_E_and_V): Print how many times
>> 	the same elements are repeated rather than printing all of them.
> Does this need a corresponding change to the RTL front-end so that it
> can read the new form?

Here's an updated patch incorporating the RTL front-end changes. I had 
to change from "repeated 2x" to "repeated x2" because the former is not 
a valid C token, and apparently that's important.

I've confirmed that it can read RTL and that subsequent dumps look correct.

OK?

Andrew
Elide repeated RTL elements.

GCN's 64-lane vectors tend to make RTL dumps very long.  This patch makes them
far more bearable by eliding long sequences of the same element into "repeated"
messages.

This also takes care of reading repeated sequences in the RTL front-end.

2018-09-19  Andrew Stubbs  <ams@codesourcery.com>
	    Jan Hubicka  <jh@suse.cz>
	    Martin Jambor  <mjambor@suse.cz>

	gcc.
	* print-rtl.c (print_rtx_operand_codes_E_and_V): Print how many times
	the same elements are repeated rather than printing all of them.
	* read-rtl.c (rtx_reader::read_rtx_operand): Recognize and expand
	"repeated" elements.

diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c
index 5dd2e31..1228483 100644
--- a/gcc/print-rtl.c
+++ b/gcc/print-rtl.c
@@ -370,7 +370,20 @@ rtx_writer::print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx)
 	m_sawclose = 1;
 
       for (int j = 0; j < XVECLEN (in_rtx, idx); j++)
-	print_rtx (XVECEXP (in_rtx, idx, j));
+	{
+	  int j1;
+
+	  print_rtx (XVECEXP (in_rtx, idx, j));
+	  for (j1 = j + 1; j1 < XVECLEN (in_rtx, idx); j1++)
+	    if (XVECEXP (in_rtx, idx, j) != XVECEXP (in_rtx, idx, j1))
+	      break;
+
+	  if (j1 != j + 1)
+	    {
+	      fprintf (m_outfile, " repeated x%i", j1 - j);
+	      j = j1 - 1;
+	    }
+	}
 
       m_indent -= 2;
     }
diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c
index 723c3e1..7ede18f 100644
--- a/gcc/read-rtl.c
+++ b/gcc/read-rtl.c
@@ -1690,6 +1690,8 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
 	struct obstack vector_stack;
 	int list_counter = 0;
 	rtvec return_vec = NULL_RTVEC;
+	rtx saved_rtx = NULL_RTX;
+	int repeat_count = 0;
 
 	require_char_ws ('[');
 
@@ -1700,8 +1702,34 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
 	    if (c == EOF)
 	      fatal_expected_char (']', c);
 	    unread_char (c);
+
+	    rtx value;
+	    if (repeat_count <= 0 && c == 'r')
+	      {
+		/* Process "repeated Nx" directive.  */
+		read_name (&name);
+		if (strcmp (name.string, "repeated"))
+		  fatal_with_file_and_line ("invalid directive \"%s\"\n",
+					    name.string);
+		read_name (&name);
+		if (!sscanf (name.string, "x%d", &repeat_count))
+		  fatal_with_file_and_line ("invalid repeat count \"%s\"\n",
+					    name.string);
+
+		/* We already saw one of the instances.  */
+		repeat_count--;
+	      }
+	    if (repeat_count > 0)
+	      {
+		repeat_count--;
+		value = saved_rtx;
+	      }
+	    else
+	      value = read_nested_rtx ();
+
 	    list_counter++;
-	    obstack_ptr_grow (&vector_stack, read_nested_rtx ());
+	    obstack_ptr_grow (&vector_stack, value);
+	    saved_rtx = value;
 	  }
 	if (list_counter > 0)
 	  {
Andrew Stubbs Sept. 20, 2018, 10:52 a.m. UTC | #5
On 19/09/18 17:38, Andrew Stubbs wrote:
> Here's an updated patch incorporating the RTL front-end changes. I had 
> to change from "repeated 2x" to "repeated x2" because the former is not 
> a valid C token, and apparently that's important.

Here's a patch with self tests added, for both reading and writing.

It also fixes a bug when the repeat was the last item in a list.

OK?

Andrew
Elide repeated RTL elements.

GCN's 64-lane vectors tend to make RTL dumps very long.  This patch makes them
far more bearable by eliding long sequences of the same element into "repeated"
messages.

This also takes care of reading repeated sequences in the RTL front-end.

There are self tests for both reading and writing.

2018-09-20  Andrew Stubbs  <ams@codesourcery.com>
	    Jan Hubicka  <jh@suse.cz>
	    Martin Jambor  <mjambor@suse.cz>

	gcc/
	* print-rtl.c (print_rtx_operand_codes_E_and_V): Print how many times
	the same elements are repeated rather than printing all of them.
	* read-rtl.c (rtx_reader::read_rtx_operand): Recognize and expand
	"repeated" elements.
	* read-rtl-function.c (test_loading_repeat): New function.
	(read_rtl_function_c_tests): Call test_loading_repeat.
	* rtl-tests.c (test_dumping_repeat): New function.
	(rtl_tests_c_tests): Call test_dumping_repeat.

	gcc/testsuite/
	* selftests/repeat.rtl: New file.

diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c
index 5dd2e31..1228483 100644
--- a/gcc/print-rtl.c
+++ b/gcc/print-rtl.c
@@ -370,7 +370,20 @@ rtx_writer::print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx)
 	m_sawclose = 1;
 
       for (int j = 0; j < XVECLEN (in_rtx, idx); j++)
-	print_rtx (XVECEXP (in_rtx, idx, j));
+	{
+	  int j1;
+
+	  print_rtx (XVECEXP (in_rtx, idx, j));
+	  for (j1 = j + 1; j1 < XVECLEN (in_rtx, idx); j1++)
+	    if (XVECEXP (in_rtx, idx, j) != XVECEXP (in_rtx, idx, j1))
+	      break;
+
+	  if (j1 != j + 1)
+	    {
+	      fprintf (m_outfile, " repeated x%i", j1 - j);
+	      j = j1 - 1;
+	    }
+	}
 
       m_indent -= 2;
     }
diff --git a/gcc/read-rtl-function.c b/gcc/read-rtl-function.c
index cde9d3e..8746f70 100644
--- a/gcc/read-rtl-function.c
+++ b/gcc/read-rtl-function.c
@@ -2166,6 +2166,20 @@ test_loading_mem ()
   ASSERT_EQ (6, MEM_ADDR_SPACE (mem2));
 }
 
+/* Verify that "repeated xN" is read correctly.  */
+
+static void
+test_loading_repeat ()
+{
+  rtl_dump_test t (SELFTEST_LOCATION, locate_file ("repeat.rtl"));
+
+  rtx_insn *insn_1 = get_insn_by_uid (1);
+  ASSERT_EQ (PARALLEL, GET_CODE (PATTERN (insn_1)));
+  ASSERT_EQ (64, XVECLEN (PATTERN (insn_1), 0));
+  for (int i = 0; i < 64; i++)
+    ASSERT_EQ (const0_rtx, XVECEXP (PATTERN (insn_1), 0, i));
+}
+
 /* Run all of the selftests within this file.  */
 
 void
@@ -2187,6 +2201,7 @@ read_rtl_function_c_tests ()
   test_loading_cfg ();
   test_loading_bb_index ();
   test_loading_mem ();
+  test_loading_repeat ();
 }
 
 } // namespace selftest
diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c
index 723c3e1..d698dd4 100644
--- a/gcc/read-rtl.c
+++ b/gcc/read-rtl.c
@@ -1690,6 +1690,7 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
 	struct obstack vector_stack;
 	int list_counter = 0;
 	rtvec return_vec = NULL_RTVEC;
+	rtx saved_rtx = NULL_RTX;
 
 	require_char_ws ('[');
 
@@ -1700,8 +1701,34 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
 	    if (c == EOF)
 	      fatal_expected_char (']', c);
 	    unread_char (c);
-	    list_counter++;
-	    obstack_ptr_grow (&vector_stack, read_nested_rtx ());
+
+	    rtx value;
+	    int repeat_count = 1;
+	    if (c == 'r')
+	      {
+		/* Process "repeated xN" directive.  */
+		read_name (&name);
+		if (strcmp (name.string, "repeated"))
+		  fatal_with_file_and_line ("invalid directive \"%s\"\n",
+					    name.string);
+		read_name (&name);
+		if (!sscanf (name.string, "x%d", &repeat_count))
+		  fatal_with_file_and_line ("invalid repeat count \"%s\"\n",
+					    name.string);
+
+		/* We already saw one of the instances.  */
+		repeat_count--;
+		value = saved_rtx;
+	      }
+	    else
+	      value = read_nested_rtx ();
+
+	    for (; repeat_count > 0; repeat_count--)
+	      {
+		list_counter++;
+		obstack_ptr_grow (&vector_stack, value);
+	      }
+	    saved_rtx = value;
 	  }
 	if (list_counter > 0)
 	  {
diff --git a/gcc/rtl-tests.c b/gcc/rtl-tests.c
index f67f2a3..c684f8e 100644
--- a/gcc/rtl-tests.c
+++ b/gcc/rtl-tests.c
@@ -284,6 +284,29 @@ const_poly_int_tests<N>::run ()
 	     gen_int_mode (poly_int64 (5, -1), QImode));
 }
 
+/* Check dumping of repeated RTL vectors.  */
+
+static void
+test_dumping_repeat ()
+{
+  rtx p = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (3));
+  XVECEXP (p, 0, 0) = const0_rtx;
+  XVECEXP (p, 0, 1) = const0_rtx;
+  XVECEXP (p, 0, 2) = const0_rtx;
+  ASSERT_RTL_DUMP_EQ ("(parallel [\n"
+		      "        (const_int 0) repeated x3\n"
+		      "    ])",
+		      p);
+
+  XVECEXP (p, 0, 1) = const1_rtx;
+  ASSERT_RTL_DUMP_EQ ("(parallel [\n"
+		      "        (const_int 0)\n"
+		      "        (const_int 1)\n"
+		      "        (const_int 0)\n"
+		      "    ])",
+		      p);
+}
+
 /* Run all of the selftests within this file.  */
 
 void
@@ -295,6 +318,7 @@ rtl_tests_c_tests ()
   test_single_set ();
   test_uncond_jump ();
   const_poly_int_tests<NUM_POLY_INT_COEFFS>::run ();
+  test_dumping_repeat ();
 
   /* Purge state.  */
   set_first_insn (NULL);
diff --git a/gcc/testsuite/selftests/repeat.rtl b/gcc/testsuite/selftests/repeat.rtl
new file mode 100644
index 0000000..5507d33
--- /dev/null
+++ b/gcc/testsuite/selftests/repeat.rtl
@@ -0,0 +1,11 @@
+(function "repeat_examples"
+  (insn-chain
+    (block 2
+      (edge-from entry (flags "FALLTHRU"))
+      (cinsn 1
+        (parallel [(const_int 0) repeated x64])
+        "test.c":2 (nil))
+      (edge-to exit (flags "FALLTHRU"))
+    ) ;; block 2
+  ) ;; insn-chain
+) ;; function
Andrew Stubbs Sept. 26, 2018, 4:22 p.m. UTC | #6
Ping.

On 20/09/18 11:52, Andrew Stubbs wrote:
> On 19/09/18 17:38, Andrew Stubbs wrote:
>> Here's an updated patch incorporating the RTL front-end changes. I had 
>> to change from "repeated 2x" to "repeated x2" because the former is 
>> not a valid C token, and apparently that's important.
> 
> Here's a patch with self tests added, for both reading and writing.
> 
> It also fixes a bug when the repeat was the last item in a list.
> 
> OK?
> 
> Andrew
Jeff Law Oct. 4, 2018, 6:12 p.m. UTC | #7
On 9/20/18 4:52 AM, Andrew Stubbs wrote:
> On 19/09/18 17:38, Andrew Stubbs wrote:
>> Here's an updated patch incorporating the RTL front-end changes. I had
>> to change from "repeated 2x" to "repeated x2" because the former is
>> not a valid C token, and apparently that's important.
> 
> Here's a patch with self tests added, for both reading and writing.
> 
> It also fixes a bug when the repeat was the last item in a list.
> 
> OK?
> 
> Andrew
> 
> 180920-elide-repeated-RTL-elements.patch
> 
> Elide repeated RTL elements.
> 
> GCN's 64-lane vectors tend to make RTL dumps very long.  This patch makes them
> far more bearable by eliding long sequences of the same element into "repeated"
> messages.
> 
> This also takes care of reading repeated sequences in the RTL front-end.
> 
> There are self tests for both reading and writing.
> 
> 2018-09-20  Andrew Stubbs  <ams@codesourcery.com>
> 	    Jan Hubicka  <jh@suse.cz>
> 	    Martin Jambor  <mjambor@suse.cz>
> 
> 	gcc/
> 	* print-rtl.c (print_rtx_operand_codes_E_and_V): Print how many times
> 	the same elements are repeated rather than printing all of them.
> 	* read-rtl.c (rtx_reader::read_rtx_operand): Recognize and expand
> 	"repeated" elements.
> 	* read-rtl-function.c (test_loading_repeat): New function.
> 	(read_rtl_function_c_tests): Call test_loading_repeat.
> 	* rtl-tests.c (test_dumping_repeat): New function.
> 	(rtl_tests_c_tests): Call test_dumping_repeat.
> 
> 	gcc/testsuite/
> 	* selftests/repeat.rtl: New file.
OK.  Thanks for fixing the reader and adding selftests.

Jeff
Andrew Stubbs Oct. 11, 2018, 2:01 p.m. UTC | #8
On 04/10/18 19:12, Jeff Law wrote:
> OK.  Thanks for fixing the reader and adding selftests.

Thanks, committed.

Andrew
diff mbox series

Patch

diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c
index 5dd2e31..8a04264 100644
--- a/gcc/print-rtl.c
+++ b/gcc/print-rtl.c
@@ -370,7 +370,20 @@  rtx_writer::print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx)
 	m_sawclose = 1;
 
       for (int j = 0; j < XVECLEN (in_rtx, idx); j++)
-	print_rtx (XVECEXP (in_rtx, idx, j));
+	{
+	  int j1;
+
+	  print_rtx (XVECEXP (in_rtx, idx, j));
+	  for (j1 = j + 1; j1 < XVECLEN (in_rtx, idx); j1++)
+	    if (XVECEXP (in_rtx, idx, j) != XVECEXP (in_rtx, idx, j1))
+	      break;
+
+	  if (j1 != j + 1)
+	    {
+	      fprintf (m_outfile, " repeated %ix", j1 - j);
+	      j = j1 - 1;
+	    }
+	}
 
       m_indent -= 2;
     }