On Thu, 2016-10-20 at 17:43 +0200, Bernd Schmidt wrote:
> On 10/20/2016 04:51 PM, David Malcolm wrote:
> >    (0|scratch:DI)
> > 
> > with the insn as a whole looking like:
> > 
> >        (cinsn (set (mem/v:BLK (0|scratch:DI) [0  A8])
> >                       (unspec:BLK [
> >                               (mem/v:BLK (reuse_rtx 0) [0  A8])
> >                           ] UNSPEC_MEMORY_BLOCKAGE)) "test.c":2
> >                    (nil))
> 
> LGTM. I'd try to expose match_dup though, it's the standard name for
> this sort of thing. Hopefully it won't have to be added to a lot of
> switch statements to shut up warnings.
> 

I'm working on the above, both for dumping, and for reading it back
in.

Here's an enabling patch, which starts adding some selftests
for print-rtl.c.  I put them in rtl-tests.c to take advantage of
some existing rtx-creation tests, and to avoid putting them in
print-rtl.c itself (since that gets built for both build and host,
and changes to it trigger big rebuilds).

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/ChangeLog:
        * print-rtl-function.c (flag_compact): Move extern decl to...
        * print-rtl.h (flag_compact): ...here.
        * rtl-tests.c (selftests::assert_rtl_dump_eq): New function.
        (ASSERT_RTL_DUMP_EQ): New macro.
        (selftest::test_dumping_regs): New function.
        (selftest::test_dumping_insns): New function.
        (selftest::test_uncond_jump): Add uses of ASSERT_RTL_DUMP_EQ on
        the insns.
        (selftest::rtl_tests_c_tests): Call the new test functions.
---
 gcc/print-rtl-function.c |  2 --
 gcc/print-rtl.h          |  2 ++
 gcc/rtl-tests.c          | 90 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 2 deletions(-)

diff --git a/gcc/print-rtl-function.c b/gcc/print-rtl-function.c
index f46304b..7ce1b90 100644
--- a/gcc/print-rtl-function.c
+++ b/gcc/print-rtl-function.c
@@ -34,8 +34,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "memmodel.h"
 #include "emit-rtl.h"
 
-extern bool flag_compact;
-
 /* Print an "(edge-from)" or "(edge-to)" directive describing E
    to OUTFILE.  */
 
diff --git a/gcc/print-rtl.h b/gcc/print-rtl.h
index 7a1dcaf..8dfba8b 100644
--- a/gcc/print-rtl.h
+++ b/gcc/print-rtl.h
@@ -20,6 +20,8 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_PRINT_RTL_H
 #define GCC_PRINT_RTL_H
 
+extern bool flag_compact;
+
 #ifdef BUFSIZ
 extern void print_rtl (FILE *, const_rtx);
 #endif
diff --git a/gcc/rtl-tests.c b/gcc/rtl-tests.c
index 723efa5..6d472d1 100644
--- a/gcc/rtl-tests.c
+++ b/gcc/rtl-tests.c
@@ -57,6 +57,85 @@ verify_print_pattern (const char *expected, rtx pat)
   ASSERT_STREQ (expected, pp_formatted_text (&pp));
 }
 
+/* Verify that X is dumped as EXPECTED_DUMP, using compact mode.
+   Use LOC as the effective location when reporting errors.  */
+
+static void
+assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x)
+{
+  named_temp_file tmp_out (".rtl");
+  FILE *outfile = fopen (tmp_out.get_filename (), "w");
+  flag_compact = true;
+  print_rtl (outfile, x);
+  flag_compact = false;
+  fclose (outfile);
+
+  char *dump = read_file (SELFTEST_LOCATION, tmp_out.get_filename ());
+  ASSERT_STREQ_AT (loc, expected_dump, dump);
+  free (dump);
+}
+
+/* Verify that RTX is dumped as EXPECTED_DUMP, using compact mode.  */
+
+#define ASSERT_RTL_DUMP_EQ(EXPECTED_DUMP, RTX) \
+  assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX))
+
+/* Verify that regs are dumped as expected (in compact mode).  */
+
+static void
+test_dumping_regs ()
+{
+  /* Test dumping of hard regs.  This is inherently target-specific due
+     to the name.  */
+#ifdef I386_OPTS_H
+  ASSERT_RTL_DUMP_EQ ("(reg:SI ax)", gen_raw_REG (SImode, 0));
+#endif
+
+  /* Test dumping of virtual regs.  The various virtual regs are inited as
+     Pmode, so this is target-specific.  The tests below assume DImode, so
+     only run the tests for targets where Pmode is DImode.  */
+  if (Pmode == DImode)
+    {
+      ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-incoming-args)",
+                         virtual_incoming_args_rtx);
+      ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-stack-vars)",
+                         virtual_stack_vars_rtx);
+      ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-stack-dynamic)",
+                         virtual_stack_dynamic_rtx);
+      ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-outgoing-args)",
+                         virtual_outgoing_args_rtx);
+      ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-cfa)",
+                         virtual_cfa_rtx);
+      ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-preferred-stack-boundary)",
+                         virtual_preferred_stack_boundary_rtx);
+    }
+
+  /* Test dumping of non-virtual pseudos.  */
+  ASSERT_RTL_DUMP_EQ ("(reg:SI %0)",
+    gen_raw_REG (SImode, LAST_VIRTUAL_REGISTER + 1));
+  ASSERT_RTL_DUMP_EQ ("(reg:SI %1)",
+    gen_raw_REG (SImode, LAST_VIRTUAL_REGISTER + 2));
+}
+
+/* Verify that insns are dumped as expected (in compact mode).  */
+
+static void
+test_dumping_insns ()
+{
+  /* Barriers.  */
+  rtx_barrier *barrier = as_a <rtx_barrier *> (rtx_alloc (BARRIER));
+  SET_NEXT_INSN (barrier) = NULL;
+  ASSERT_RTL_DUMP_EQ ("(cbarrier)\n", barrier);
+
+  /* Labels.  */
+  rtx_insn *label = gen_label_rtx ();
+  CODE_LABEL_NUMBER (label) = 42;
+  ASSERT_RTL_DUMP_EQ ("(clabel 0 42 \"\")\n", label);
+
+  LABEL_NAME (label)= "some_label";
+  ASSERT_RTL_DUMP_EQ ("(clabel 0 42 (\"some_label\"))\n", label);
+}
+
 /* Unit testing of "single_set".  */
 
 static void
@@ -92,6 +171,10 @@ test_uncond_jump ()
 
   verify_print_pattern ("pc=L0", jump_pat);
 
+  ASSERT_RTL_DUMP_EQ ("(set (pc)\n"
+                     "    (label_ref 0))",
+                     jump_pat);
+
   rtx_insn *jump_insn = emit_jump_insn (jump_pat);
   ASSERT_FALSE (any_condjump_p (jump_insn));
   ASSERT_TRUE (any_uncondjump_p (jump_insn));
@@ -99,6 +182,11 @@ test_uncond_jump ()
   ASSERT_TRUE (simplejump_p (jump_insn));
   ASSERT_TRUE (onlyjump_p (jump_insn));
   ASSERT_TRUE (control_flow_insn_p (jump_insn));
+
+  ASSERT_RTL_DUMP_EQ ("(cjump_insn (set (pc)\n"
+                     "        (label_ref 0))\n"
+                     "     (nil))\n",
+                     jump_insn);
 }
 
 /* Run all of the selftests within this file.  */
@@ -106,6 +194,8 @@ test_uncond_jump ()
 void
 rtl_tests_c_tests ()
 {
+  test_dumping_regs ();
+  test_dumping_insns ();
   test_single_set ();
   test_uncond_jump ();
 
-- 
1.8.5.3

Reply via email to