On Fri, 2016-10-21 at 12:04 +0200, Bernd Schmidt wrote:
> On 10/21/2016 02:36 AM, David Malcolm wrote:
> > + ASSERT_RTL_DUMP_EQ ("(cjump_insn (set (pc)\n"
> > + " (label_ref 0))\n"
> > + " (nil))\n",
> > + jump_insn);
> > }
>
> I do wonder about the (nil)s and whether we can eliminate them.
The following patch does so, by adding a flag param to
rtx_writer::print_rtx allowing omitting the (nil) when in compact mode.
Successfully bootstrapped®rtested on x86_64-pc-linux-gnu.
OK for trunk?
gcc/ChangeLog:
* print-rtl.c (rtx_writer::print_rtx_operand_code_0): Don't print
trailing "(nil)" for NOTE_VAR_LOCATION and for ENTRY_VALUE_EXP.
(rtx_writer::print_rtx_operand_code_e): Likewise for
CALL_INSN_FUNCTION_USAGE and for REG_NOTES.
(rtx_writer::print_rtx_operand_codes_E_and_V): Always print nils
within a vec.
(rtx_writer::print_rtx): Add param "print_nil" to support not
printing some trailing "(nil)" values when in compact mode.
Don't print them for PAT_VAR_LOCATION_LOC.
(print_inline_rtx): Update for new param.
(debug_rtx): Likewise.
(rtx_writer::print_rtl): Likewise.
(rtx_writer::print_rtl_single_with_indent): Likewise.
* print-rtl.h (rtx_writer::print_rtx): Add "print_nil" param.
* rtl-tests.c (selftests::test_uncond_jump): Remove trailing
"(nil)" from expected output.
---
gcc/print-rtl.c | 44 +++++++++++++++++++++++++++++---------------
gcc/print-rtl.h | 2 +-
gcc/rtl-tests.c | 2 +-
3 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c
index 341ecdf..643eb57 100644
--- a/gcc/print-rtl.c
+++ b/gcc/print-rtl.c
@@ -158,7 +158,7 @@ rtx_writer::print_rtx_operand_code_0 (const_rtx in_rtx
ATTRIBUTE_UNUSED,
case NOTE_INSN_VAR_LOCATION:
case NOTE_INSN_CALL_ARG_LOCATION:
fputc (' ', m_outfile);
- print_rtx (NOTE_VAR_LOCATION (in_rtx));
+ print_rtx (NOTE_VAR_LOCATION (in_rtx), false);
break;
case NOTE_INSN_CFI:
@@ -201,7 +201,7 @@ rtx_writer::print_rtx_operand_code_0 (const_rtx in_rtx
ATTRIBUTE_UNUSED,
m_indent += 2;
if (!m_sawclose)
fprintf (m_outfile, " ");
- print_rtx (ENTRY_VALUE_EXP (in_rtx));
+ print_rtx (ENTRY_VALUE_EXP (in_rtx), false);
m_indent -= 2;
}
#endif
@@ -224,11 +224,17 @@ rtx_writer::print_rtx_operand_code_e (const_rtx in_rtx,
int idx)
if (idx == 7 && CALL_P (in_rtx))
{
m_in_call_function_usage = true;
- print_rtx (XEXP (in_rtx, idx));
+ print_rtx (XEXP (in_rtx, idx), false);
m_in_call_function_usage = false;
}
else
- print_rtx (XEXP (in_rtx, idx));
+ {
+ bool print_nil = true;
+ /* Avoid printing trailing "(nil)" for REG_NOTES. */
+ if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx)) && idx == 6)
+ print_nil = false;
+ print_rtx (XEXP (in_rtx, idx), print_nil);
+ }
m_indent -= 2;
}
@@ -252,7 +258,7 @@ 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));
+ print_rtx (XVECEXP (in_rtx, idx, j), true);
m_indent -= 2;
}
@@ -564,10 +570,15 @@ rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx)
}
}
-/* Print IN_RTX onto m_outfile. This is the recursive part of printing. */
+/* Print IN_RTX onto m_outfile. This is the recursive part of printing.
+ PRINT_NIL controls the printing of "(nil)" in compact mode.
+ In compact mode, if IN_RTX is NULL, then "(nil)" is printed if PRINT_NIL
+ is true, and nothing is printed if PRINT_NIL is false.
+ In non-compact mode, "(nil)" is always printed for NULL, and PRINT_NIL
+ is ignored. */
void
-rtx_writer::print_rtx (const_rtx in_rtx)
+rtx_writer::print_rtx (const_rtx in_rtx, bool print_nil)
{
int idx = 0;
@@ -582,8 +593,11 @@ rtx_writer::print_rtx (const_rtx in_rtx)
if (in_rtx == 0)
{
- fputs ("(nil)", m_outfile);
- m_sawclose = 1;
+ if (print_nil || !m_compact)
+ {
+ fputs ("(nil)", m_outfile);
+ m_sawclose = 1;
+ }
return;
}
else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
@@ -657,7 +671,7 @@ rtx_writer::print_rtx (const_rtx in_rtx)
else
print_mem_expr (m_outfile, PAT_VAR_LOCATION_DECL (in_rtx));
fputc (' ', m_outfile);
- print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
+ print_rtx (PAT_VAR_LOCATION_LOC (in_rtx), false);
if (PAT_VAR_LOCATION_STATUS (in_rtx)
== VAR_INIT_STATUS_UNINITIALIZED)
fprintf (m_outfile, " [uninit]");
@@ -765,7 +779,7 @@ void
print_inline_rtx (FILE *outf, const_rtx x, int ind)
{
rtx_writer w (outf, ind, false, false);
- w.print_rtx (x);
+ w.print_rtx (x, true);
}
/* Call this function from the debugger to see what X looks like. */
@@ -774,7 +788,7 @@ DEBUG_FUNCTION void
debug_rtx (const_rtx x)
{
rtx_writer w (stderr, 0, false, false);
- w.print_rtx (x);
+ w.print_rtx (x, true);
fprintf (stderr, "\n");
}
@@ -900,14 +914,14 @@ rtx_writer::print_rtl (const_rtx rtx_first)
tmp_rtx = NEXT_INSN (tmp_rtx))
{
fputs (print_rtx_head, m_outfile);
- print_rtx (tmp_rtx);
+ print_rtx (tmp_rtx, true);
fprintf (m_outfile, "\n");
}
break;
default:
fputs (print_rtx_head, m_outfile);
- print_rtx (rtx_first);
+ print_rtx (rtx_first, true);
}
}
@@ -948,7 +962,7 @@ rtx_writer::print_rtl_single_with_indent (const_rtx x, int
ind)
int old_indent = m_indent;
m_indent = ind;
m_sawclose = 0;
- print_rtx (x);
+ print_rtx (x, true);
putc ('\n', m_outfile);
m_indent = old_indent;
return 1;
diff --git a/gcc/print-rtl.h b/gcc/print-rtl.h
index 8496ffa..64043dd 100644
--- a/gcc/print-rtl.h
+++ b/gcc/print-rtl.h
@@ -27,7 +27,7 @@ class rtx_writer
public:
rtx_writer (FILE *outfile, int ind, bool simple, bool compact);
- void print_rtx (const_rtx in_rtx);
+ void print_rtx (const_rtx in_rtx, bool print_nil);
void print_rtl (const_rtx rtx_first);
int print_rtl_single_with_indent (const_rtx x, int ind);
diff --git a/gcc/rtl-tests.c b/gcc/rtl-tests.c
index cf5239f..006ef92 100644
--- a/gcc/rtl-tests.c
+++ b/gcc/rtl-tests.c
@@ -177,7 +177,7 @@ test_uncond_jump ()
ASSERT_RTL_DUMP_EQ ("(cjump_insn 1 (set (pc)\n"
" (label_ref 0))\n"
- " (nil))\n",
+ " )\n",
jump_insn);
}
--
1.8.5.3