On Fri, 2016-11-04 at 18:51 +0100, Bernd Schmidt wrote:
> Here's something simpler. Only very lightly tested, but isn't
> something
> like this all that's needed? Could decide whether to apply it to
> expr_list etc. as well.
> 
> Index: print-rtl.c
> ===================================================================
> --- print-rtl.c       (revision 241233)
> +++ print-rtl.c       (working copy)
> @@ -697,7 +697,12 @@ print_rtx (const_rtx in_rtx)
> 
>     /* Get the format string and skip the first elements if we have
> handled
>        them already.  */
> -  for (; idx < GET_RTX_LENGTH (GET_CODE (in_rtx)); idx++)
> +  int limit = GET_RTX_LENGTH (GET_CODE (in_rtx));
> +  if (flag_compact
(as of r241586 this is now "m_compact")

> +      && INSN_CHAIN_CODE_P (GET_CODE (in_rtx))
> +      && XEXP (in_rtx, limit - 1) == NULL_RTX)
> +    limit--;
> +  for (; idx < limit; idx++)
>       print_rtx_operand (in_rtx, idx);
> 
>     switch (GET_CODE (in_rtx))

Thanks.

This seems to assume that the final code in the fmt string can be
accessed via XEXP (in_rtx, limit - 1), which if RTL checking is
enabled requires that the code be either 'e' or 'u'.

This isn't the case for JUMP_INSN, JUMP_TABLE_DATA, BARRIER
(all code '0'), CODE_LABEL (code 's') and NOTE (code 'i').

Also, we might want to omit the REG_NOTES from, say a JUMP_INSN, which
is the *penultimate* operand - for example, it doesn't omit the
trailing (nil) from the cjump_insn in test_uncond_jump.

That said, this is much simpler than my patch, so I used it as the
basis for the following: it uses the same approach as your patch, but
loops backwards from the end of the format string (rather than just once)
until it finds a non-default value, using a new function
"operand_has_default_value_p" to handle the logic for that.

With this, compact dumps omit the trailing (nil) for both regular insns
and for JUMP_INSNs, and omits the surplus newline seen in my earlier patch.

It also appears removes the trailing (nil) from expr_list.

Bootstrap&regrtest in progress.

OK for trunk if it passes?

gcc/ChangeLog:
        * print-rtl.c (operand_has_default_value_p): New function.
        (rtx_writer::print_rtx): In compact mode, omit trailing operands
        that have the default values.
        * rtl-tests.c (selftest::test_dumping_insns): Remove empty
        label string from expected dump.
        (seltest::test_uncond_jump): Remove trailing "(nil)" for REG_NOTES
        from expected dump.
---
 gcc/print-rtl.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 gcc/rtl-tests.c |  5 ++---
 2 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c
index 341ecdf..493aa68 100644
--- a/gcc/print-rtl.c
+++ b/gcc/print-rtl.c
@@ -564,6 +564,40 @@ rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx)
     }
 }
 
+/* Subroutine of rtx_writer::print_rtx.
+   In compact mode, determine if operand IDX of IN_RTX is interesting
+   to dump, or (if in a trailing position) it can be omitted.  */
+
+static bool
+operand_has_default_value_p (const_rtx in_rtx, int idx)
+{
+  const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
+
+  switch (format_ptr[idx])
+    {
+    case 'e':
+    case 'u':
+      return XEXP (in_rtx, idx) == NULL_RTX;
+
+    case 's':
+      return XSTR (in_rtx, idx) == NULL;
+
+    case '0':
+      switch (GET_CODE (in_rtx))
+       {
+       case JUMP_INSN:
+         return JUMP_LABEL (in_rtx) == NULL_RTX;
+
+       default:
+         return false;
+
+       }
+
+    default:
+      return false;
+    }
+}
+
 /* Print IN_RTX onto m_outfile.  This is the recursive part of printing.  */
 
 void
@@ -681,9 +715,18 @@ rtx_writer::print_rtx (const_rtx in_rtx)
        fprintf (m_outfile, " %d", INSN_UID (in_rtx));
     }
 
+  /* Determine which is the final operand to print.
+     In compact mode, skip trailing operands that have the default values
+     e.g. trailing "(nil)" values.  */
+  int limit = GET_RTX_LENGTH (GET_CODE (in_rtx));
+  if (m_compact)
+    while (limit > idx && operand_has_default_value_p (in_rtx, limit - 1))
+      limit--;
+
   /* Get the format string and skip the first elements if we have handled
      them already.  */
-  for (; idx < GET_RTX_LENGTH (GET_CODE (in_rtx)); idx++)
+
+  for (; idx < limit; idx++)
     print_rtx_operand (in_rtx, idx);
 
   switch (GET_CODE (in_rtx))
diff --git a/gcc/rtl-tests.c b/gcc/rtl-tests.c
index cf5239f..228226b 100644
--- a/gcc/rtl-tests.c
+++ b/gcc/rtl-tests.c
@@ -122,7 +122,7 @@ test_dumping_insns ()
   /* Labels.  */
   rtx_insn *label = gen_label_rtx ();
   CODE_LABEL_NUMBER (label) = 42;
-  ASSERT_RTL_DUMP_EQ ("(clabel 0 42 \"\")\n", label);
+  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);
@@ -176,8 +176,7 @@ test_uncond_jump ()
   ASSERT_TRUE (control_flow_insn_p (jump_insn));
 
   ASSERT_RTL_DUMP_EQ ("(cjump_insn 1 (set (pc)\n"
-                     "        (label_ref 0))\n"
-                     "     (nil))\n",
+                     "        (label_ref 0)))\n",
                      jump_insn);
 }
 
-- 
1.8.5.3

Reply via email to