]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/print-rtl.c
PR c++/87554 - ICE with extern template and reference member.
[thirdparty/gcc.git] / gcc / print-rtl.c
index d0ba896f3e2201a6a86e876b10cea725fc510b15..fbb108568b3f899c10ce9b7fe12486d0751258d3 100644 (file)
@@ -1,5 +1,5 @@
 /* Print RTL for GCC.
-   Copyright (C) 1987-2016 Free Software Foundation, Inc.
+   Copyright (C) 1987-2019 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -35,11 +35,12 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GENERATOR_FILE
 #include "alias.h"
 #include "tree.h"
-#include "cfg.h"
+#include "basic-block.h"
 #include "print-tree.h"
 #include "flags.h"
 #include "predict.h"
 #include "function.h"
+#include "cfg.h"
 #include "basic-block.h"
 #include "diagnostic.h"
 #include "tree-pretty-print.h"
@@ -51,6 +52,7 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 
 #include "print-rtl.h"
+#include "rtl-iter.h"
 
 /* String printed at beginning of each RTL when it is dumped.
    This string is set to ASM_COMMENT_START when the RTL is dumped in
@@ -74,12 +76,101 @@ int flag_dump_unnumbered_links = 0;
 
 /* Constructor for rtx_writer.  */
 
-rtx_writer::rtx_writer (FILE *outf, int ind, bool simple, bool compact)
+rtx_writer::rtx_writer (FILE *outf, int ind, bool simple, bool compact,
+                       rtx_reuse_manager *reuse_manager)
 : m_outfile (outf), m_sawclose (0), m_indent (ind),
-  m_in_call_function_usage (false), m_simple (simple), m_compact (compact)
+  m_in_call_function_usage (false), m_simple (simple), m_compact (compact),
+  m_rtx_reuse_manager (reuse_manager)
 {
 }
 
+#ifndef GENERATOR_FILE
+
+/* rtx_reuse_manager's ctor.  */
+
+rtx_reuse_manager::rtx_reuse_manager ()
+: m_next_id (0)
+{
+}
+
+/* Determine if X is of a kind suitable for dumping via reuse_rtx.  */
+
+static bool
+uses_rtx_reuse_p (const_rtx x)
+{
+  if (x == NULL)
+    return false;
+
+  switch (GET_CODE (x))
+    {
+    case DEBUG_EXPR:
+    case VALUE:
+    case SCRATCH:
+      return true;
+
+    /* We don't use reuse_rtx for consts.  */
+    CASE_CONST_UNIQUE:
+    default:
+      return false;
+    }
+}
+
+/* Traverse X and its descendents, determining if we see any rtx more than
+   once.  Any rtx suitable for "reuse_rtx" that is seen more than once is
+   assigned an ID.  */
+
+void
+rtx_reuse_manager::preprocess (const_rtx x)
+{
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, NONCONST)
+    if (uses_rtx_reuse_p (*iter))
+      {
+       if (int *count = m_rtx_occurrence_count.get (*iter))
+         {
+           if (*(count++) == 1)
+             m_rtx_reuse_ids.put (*iter, m_next_id++);
+         }
+       else
+         m_rtx_occurrence_count.put (*iter, 1);
+      }
+}
+
+/* Return true iff X has been assigned a reuse ID.  If it has,
+   and OUT is non-NULL, then write the reuse ID to *OUT.  */
+
+bool
+rtx_reuse_manager::has_reuse_id (const_rtx x, int *out)
+{
+  int *id = m_rtx_reuse_ids.get (x);
+  if (id)
+    {
+      if (out)
+       *out = *id;
+      return true;
+    }
+  else
+    return false;
+}
+
+/* Determine if set_seen_def has been called for the given reuse ID.  */
+
+bool
+rtx_reuse_manager::seen_def_p (int reuse_id)
+{
+  return bitmap_bit_p (m_defs_seen, reuse_id);
+}
+
+/* Record that the definition of the given reuse ID has been seen.  */
+
+void
+rtx_reuse_manager::set_seen_def (int reuse_id)
+{
+  bitmap_set_bit (m_defs_seen, reuse_id);
+}
+
+#endif /* #ifndef GENERATOR_FILE */
+
 #ifndef GENERATOR_FILE
 void
 print_mem_expr (FILE *outfile, const_tree expr)
@@ -89,6 +180,23 @@ print_mem_expr (FILE *outfile, const_tree expr)
 }
 #endif
 
+/* Print X to FILE.  */
+
+static void
+print_poly_int (FILE *file, poly_int64 x)
+{
+  HOST_WIDE_INT const_x;
+  if (x.is_constant (&const_x))
+    fprintf (file, HOST_WIDE_INT_PRINT_DEC, const_x);
+  else
+    {
+      fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC, x.coeffs[0]);
+      for (int i = 1; i < NUM_POLY_INT_COEFFS; ++i)
+       fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC, x.coeffs[i]);
+      fprintf (file, "]");
+    }
+}
+
 /* Subroutine of print_rtx_operand for handling code '0'.
    0 indicates a field for internal use that should not be printed.
    However there are various special cases, such as the third field
@@ -156,7 +264,6 @@ 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));
          break;
@@ -167,6 +274,17 @@ rtx_writer::print_rtx_operand_code_0 (const_rtx in_rtx ATTRIBUTE_UNUSED,
          fputc ('\t', m_outfile);
          break;
 
+       case NOTE_INSN_BEGIN_STMT:
+       case NOTE_INSN_INLINE_ENTRY:
+#ifndef GENERATOR_FILE
+         {
+           expanded_location xloc
+             = expand_location (NOTE_MARKER_LOCATION (in_rtx));
+           fprintf (m_outfile, " %s:%i", xloc.file, xloc.line);
+         }
+#endif
+         break;
+
        default:
          break;
        }
@@ -245,14 +363,27 @@ rtx_writer::print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx)
       m_sawclose = 0;
     }
   fputs (" [", m_outfile);
-  if (NULL != XVEC (in_rtx, idx))
+  if (XVEC (in_rtx, idx) != NULL)
     {
       m_indent += 2;
       if (XVECLEN (in_rtx, 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;
     }
@@ -280,7 +411,8 @@ rtx_writer::print_rtx_operand_code_i (const_rtx in_rtx, int idx)
       if (INSN_HAS_LOCATION (in_insn))
        {
          expanded_location xloc = insn_location (in_insn);
-         fprintf (m_outfile, " \"%s\":%i", xloc.file, xloc.line);
+         fprintf (m_outfile, " \"%s\":%i:%i", xloc.file, xloc.line,
+                  xloc.column);
        }
 #endif
     }
@@ -390,11 +522,11 @@ rtx_writer::print_rtx_operand_code_r (const_rtx in_rtx)
       fputc ('#', m_outfile);
     else if (m_compact)
       {
-       /* In compact mode, print pseudos with a '%' sigil following
-          by the regno, offset by (LAST_VIRTUAL_REGISTER + 1), so that the
-          first non-virtual pseudo is dumped as "%0".  */
+       /* In compact mode, print pseudos with '< and '>' wrapping the regno,
+          offseting it by (LAST_VIRTUAL_REGISTER + 1), so that the
+          first non-virtual pseudo is dumped as "<0>".  */
        gcc_assert (regno > LAST_VIRTUAL_REGISTER);
-       fprintf (m_outfile, " %%%d", regno - (LAST_VIRTUAL_REGISTER + 1));
+       fprintf (m_outfile, " <%d>", regno - (LAST_VIRTUAL_REGISTER + 1));
       }
     else
       fprintf (m_outfile, " %d", regno);
@@ -408,9 +540,11 @@ rtx_writer::print_rtx_operand_code_r (const_rtx in_rtx)
       if (REG_EXPR (in_rtx))
        print_mem_expr (m_outfile, REG_EXPR (in_rtx));
 
-      if (REG_OFFSET (in_rtx))
-       fprintf (m_outfile, "+" HOST_WIDE_INT_PRINT_DEC,
-                REG_OFFSET (in_rtx));
+      if (maybe_ne (REG_OFFSET (in_rtx), 0))
+       {
+         fprintf (m_outfile, "+");
+         print_poly_int (m_outfile, REG_OFFSET (in_rtx));
+       }
       fputs (" ]", m_outfile);
     }
   if (regno != ORIGINAL_REGNO (in_rtx))
@@ -423,8 +557,8 @@ rtx_writer::print_rtx_operand_code_r (const_rtx in_rtx)
 void
 rtx_writer::print_rtx_operand_code_u (const_rtx in_rtx, int idx)
 {
-  /* Don't print insn UIDs in compact mode, apart from in LABEL_REFs.  */
-  if (m_compact && GET_CODE (in_rtx) != LABEL_REF)
+  /* Don't print insn UIDs for PREV/NEXT_INSN in compact mode.  */
+  if (m_compact && INSN_CHAIN_CODE_P (GET_CODE (in_rtx)) && idx < 2)
     return;
 
   if (XEXP (in_rtx, idx) != NULL)
@@ -486,7 +620,7 @@ rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx)
     string:
 
       if (str == 0)
-       fputs (" \"\"", m_outfile);
+       fputs (" (nil)", m_outfile);
       else
        fprintf (m_outfile, " (\"%s\")", str);
       m_sawclose = 1;
@@ -518,6 +652,11 @@ rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx)
       print_rtx_operand_code_i (in_rtx, idx);
       break;
 
+    case 'p':
+      fprintf (m_outfile, " ");
+      print_poly_int (m_outfile, SUBREG_BYTE (in_rtx));
+      break;
+
     case 'r':
       print_rtx_operand_code_r (in_rtx);
       break;
@@ -564,6 +703,43 @@ 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.  */
+
+bool
+rtx_writer::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:
+         /* JUMP_LABELs are always omitted in compact mode, so treat
+            any value here as omittable, so that earlier operands can
+            potentially be omitted also.  */
+         return m_compact;
+
+       default:
+         return false;
+
+       }
+
+    default:
+      return false;
+    }
+}
+
 /* Print IN_RTX onto m_outfile.  This is the recursive part of printing.  */
 
 void
@@ -594,8 +770,34 @@ rtx_writer::print_rtx (const_rtx in_rtx)
        return;
     }
 
+  fputc ('(', m_outfile);
+
   /* Print name of expression code.  */
 
+  /* Handle reuse.  */
+#ifndef GENERATOR_FILE
+  if (m_rtx_reuse_manager)
+    {
+      int reuse_id;
+      if (m_rtx_reuse_manager->has_reuse_id (in_rtx, &reuse_id))
+       {
+         /* Have we already seen the defn of this rtx?  */
+         if (m_rtx_reuse_manager->seen_def_p (reuse_id))
+           {
+             fprintf (m_outfile, "reuse_rtx %i)", reuse_id);
+             m_sawclose = 1;
+             return;
+           }
+         else
+           {
+             /* First time we've seen this reused-rtx.  */
+             fprintf (m_outfile, "%i|", reuse_id);
+             m_rtx_reuse_manager->set_seen_def (reuse_id);
+           }
+       }
+    }
+#endif /* #ifndef GENERATOR_FILE */
+
   /* In compact mode, prefix the code of insns with "c",
      giving "cinsn", "cnote" etc.  */
   if (m_compact && is_a <const rtx_insn *, const struct rtx_def> (in_rtx))
@@ -604,14 +806,14 @@ rtx_writer::print_rtx (const_rtx in_rtx)
         just "clabel".  */
       rtx_code code = GET_CODE (in_rtx);
       if (code == CODE_LABEL)
-       fprintf (m_outfile, "(clabel");
+       fprintf (m_outfile, "clabel");
       else
-       fprintf (m_outfile, "(c%s", GET_RTX_NAME (code));
+       fprintf (m_outfile, "c%s", GET_RTX_NAME (code));
     }
   else if (m_simple && CONST_INT_P (in_rtx))
-    fputc ('(', m_outfile);
+    ; /* no code.  */
   else
-    fprintf (m_outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
+    fprintf (m_outfile, "%s", GET_RTX_NAME (GET_CODE (in_rtx)));
 
   if (! m_simple)
     {
@@ -672,10 +874,8 @@ rtx_writer::print_rtx (const_rtx in_rtx)
     idx = 5;
 #endif
 
-  /* For insns, print the INSN_UID.
-     In compact mode, we only print the INSN_UID of CODE_LABELs.  */
-  if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx))
-      && (!m_compact || GET_CODE (in_rtx) == CODE_LABEL))
+  /* For insns, print the INSN_UID.  */
+  if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx)))
     {
       if (flag_dump_unnumbered)
        fprintf (m_outfile, " #");
@@ -683,9 +883,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))
@@ -704,10 +913,16 @@ rtx_writer::print_rtx (const_rtx in_rtx)
        fputc (' ', m_outfile);
 
       if (MEM_OFFSET_KNOWN_P (in_rtx))
-       fprintf (m_outfile, "+" HOST_WIDE_INT_PRINT_DEC, MEM_OFFSET (in_rtx));
+       {
+         fprintf (m_outfile, "+");
+         print_poly_int (m_outfile, MEM_OFFSET (in_rtx));
+       }
 
       if (MEM_SIZE_KNOWN_P (in_rtx))
-       fprintf (m_outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
+       {
+         fprintf (m_outfile, " S");
+         print_poly_int (m_outfile, MEM_SIZE (in_rtx));
+       }
 
       if (MEM_ALIGN (in_rtx) != 1)
        fprintf (m_outfile, " A%u", MEM_ALIGN (in_rtx));
@@ -737,6 +952,17 @@ rtx_writer::print_rtx (const_rtx in_rtx)
       fprintf (m_outfile, " ");
       cwi_output_hex (m_outfile, in_rtx);
       break;
+
+    case CONST_POLY_INT:
+      fprintf (m_outfile, " [");
+      print_dec (CONST_POLY_INT_COEFFS (in_rtx)[0], m_outfile, SIGNED);
+      for (unsigned int i = 1; i < NUM_POLY_INT_COEFFS; ++i)
+       {
+         fprintf (m_outfile, ", ");
+         print_dec (CONST_POLY_INT_COEFFS (in_rtx)[i], m_outfile, SIGNED);
+       }
+      fprintf (m_outfile, "]");
+      break;
 #endif
 
     case CODE_LABEL:
@@ -760,13 +986,22 @@ rtx_writer::print_rtx (const_rtx in_rtx)
   m_sawclose = 1;
 }
 
+/* Emit a closing parenthesis and newline.  */
+
+void
+rtx_writer::finish_directive ()
+{
+  fprintf (m_outfile, ")\n");
+  m_sawclose = 0;
+}
+
 /* Print an rtx on the current line of FILE.  Initially indent IND
    characters.  */
 
 void
 print_inline_rtx (FILE *outf, const_rtx x, int ind)
 {
-  rtx_writer w (outf, ind, false, false);
+  rtx_writer w (outf, ind, false, false, NULL);
   w.print_rtx (x);
 }
 
@@ -775,7 +1010,7 @@ print_inline_rtx (FILE *outf, const_rtx x, int ind)
 DEBUG_FUNCTION void
 debug_rtx (const_rtx x)
 {
-  rtx_writer w (stderr, 0, false, false);
+  rtx_writer w (stderr, 0, false, false, NULL);
   w.print_rtx (x);
   fprintf (stderr, "\n");
 }
@@ -797,6 +1032,23 @@ debug (const rtx_def *ptr)
     fprintf (stderr, "<nil>\n");
 }
 
+/* Like debug_rtx but with no newline, as debug_helper will add one.
+
+   Note: No debug_slim(rtx_insn *) variant implemented, as this
+   function can serve for both rtx and rtx_insn.  */
+
+static void
+debug_slim (const_rtx x)
+{
+  rtx_writer w (stderr, 0, false, false, NULL);
+  w.print_rtx (x);
+}
+
+DEFINE_DEBUG_VEC (rtx_def *)
+DEFINE_DEBUG_VEC (rtx_insn *)
+DEFINE_DEBUG_HASH_SET (rtx_def *)
+DEFINE_DEBUG_HASH_SET (rtx_insn *)
+
 /* Count of rtx's to print with debug_rtx_list.
    This global exists because gdb user defined commands have no arguments.  */
 
@@ -922,7 +1174,7 @@ rtx_writer::print_rtl (const_rtx rtx_first)
 void
 print_rtl (FILE *outf, const_rtx rtx_first)
 {
-  rtx_writer w (outf, 0, false, false);
+  rtx_writer w (outf, 0, false, false, NULL);
   w.print_rtl (rtx_first);
 }
 
@@ -932,7 +1184,7 @@ print_rtl (FILE *outf, const_rtx rtx_first)
 int
 print_rtl_single (FILE *outf, const_rtx x)
 {
-  rtx_writer w (outf, 0, false, false);
+  rtx_writer w (outf, 0, false, false, NULL);
   return w.print_rtl_single_with_indent (x, 0);
 }
 
@@ -963,7 +1215,7 @@ rtx_writer::print_rtl_single_with_indent (const_rtx x, int ind)
 void
 print_simple_rtl (FILE *outf, const_rtx x)
 {
-  rtx_writer w (outf, 0, true, false);
+  rtx_writer w (outf, 0, true, false, NULL);
   w.print_rtl (x);
 }
 
@@ -1113,7 +1365,7 @@ print_exp (pretty_printer *pp, const_rtx x, int verbose)
       op[1] = XEXP (x, 1);
       break;
     case NOT:
-      st[0] = "!";
+      st[0] = "~";
       op[0] = XEXP (x, 0);
       break;
     case AND:
@@ -1398,6 +1650,17 @@ print_value (pretty_printer *pp, const_rtx x, int verbose)
       }
       break;
 
+    case CONST_POLY_INT:
+      pp_left_bracket (pp);
+      pp_wide_int (pp, CONST_POLY_INT_COEFFS (x)[0], SIGNED);
+      for (unsigned int i = 1; i < NUM_POLY_INT_COEFFS; ++i)
+       {
+         pp_string (pp, ", ");
+         pp_wide_int (pp, CONST_POLY_INT_COEFFS (x)[i], SIGNED);
+       }
+      pp_right_bracket (pp);
+      break;
+
     case CONST_DOUBLE:
       if (FLOAT_MODE_P (GET_MODE (x)))
        {
@@ -1444,7 +1707,8 @@ print_value (pretty_printer *pp, const_rtx x, int verbose)
       break;
     case SUBREG:
       print_value (pp, SUBREG_REG (x), verbose);
-      pp_printf (pp, "#%d", SUBREG_BYTE (x));
+      pp_printf (pp, "#");
+      pp_wide_integer (pp, SUBREG_BYTE (x));
       break;
     case SCRATCH:
     case CC0:
@@ -1492,6 +1756,7 @@ print_pattern (pretty_printer *pp, const_rtx x, int verbose)
       print_exp (pp, x, verbose);
       break;
     case CLOBBER:
+    case CLOBBER_HIGH:
     case USE:
       pp_printf (pp, "%s ", GET_RTX_NAME (GET_CODE (x)));
       print_value (pp, XEXP (x, 0), verbose);
@@ -1621,12 +1886,30 @@ print_insn (pretty_printer *pp, const rtx_insn *x, int verbose)
 
     case DEBUG_INSN:
       {
+       if (DEBUG_MARKER_INSN_P (x))
+         {
+           switch (INSN_DEBUG_MARKER_KIND (x))
+             {
+             case NOTE_INSN_BEGIN_STMT:
+               pp_string (pp, "debug begin stmt marker");
+               break;
+
+             case NOTE_INSN_INLINE_ENTRY:
+               pp_string (pp, "debug inline entry marker");
+               break;
+
+             default:
+               gcc_unreachable ();
+             }
+           break;
+         }
+
        const char *name = "?";
+       char idbuf[32];
 
        if (DECL_P (INSN_VAR_LOCATION_DECL (x)))
          {
            tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (x));
-           char idbuf[32];
            if (id)
              name = IDENTIFIER_POINTER (id);
            else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x))
@@ -1701,7 +1984,6 @@ print_insn (pretty_printer *pp, const rtx_insn *x, int verbose)
            break;
 
          case NOTE_INSN_VAR_LOCATION:
-         case NOTE_INSN_CALL_ARG_LOCATION:
            pp_left_brace (pp);
            print_pattern (pp, NOTE_VAR_LOCATION (x), verbose);
            pp_right_brace (pp);