From 9d8e12c9d7e915f848f4ee9d5fe6a4c82b6394fe Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 21 Jun 2018 16:07:12 -0400
Subject: [PATCH 37/44] FIXME: Add a dump_rtl entrypoint

---
 gcc/dump-context.h |  2 ++
 gcc/dumpfile.c     | 38 ++++++++++++++++++++++++++++++++++++++
 gcc/dumpfile.h     |  1 +
 gcc/optinfo.cc     | 13 +++++++++++++
 gcc/optinfo.h      |  1 +
 5 files changed, 55 insertions(+)

diff --git a/gcc/dump-context.h b/gcc/dump-context.h
index 753f714..a64970e 100644
--- a/gcc/dump-context.h
+++ b/gcc/dump-context.h
@@ -68,6 +68,8 @@ class dump_context
 
   void dump_symtab_node (dump_flags_t dump_kind, symtab_node *node);
 
+  void dump_rtl (dump_flags_t dump_kind, const_rtx x);
+
   /* Managing nested scopes.  */
   unsigned int get_scope_depth () const;
   void begin_scope (const char *name, const dump_location_t &loc);
diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index b6a2313..d665369 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -683,6 +683,25 @@ dump_context::dump_symtab_node (dump_flags_t dump_kind, symtab_node *node)
     }
 }
 
+/* FIXME.  */
+
+void
+dump_context::dump_rtl (dump_flags_t dump_kind, const_rtx x)
+{
+  if (dump_file)
+    print_rtl (dump_file, x);
+
+  if (alt_dump_file)
+    print_rtl (alt_dump_file, x);
+
+  if (optinfo_enabled_p ())
+    {
+      optinfo &info = ensure_pending_optinfo ();
+      info.handle_dump_file_kind (dump_kind);
+      info.add_rtl (x);
+    }
+}
+
 /* Get the current dump scope-nesting depth.
    For use by remarks and -fopt-info (for showing nesting via indentation).  */
 
@@ -878,6 +897,14 @@ dump_symtab_node (dump_flags_t dump_kind, symtab_node *node)
   dump_context::get ().dump_symtab_node (dump_kind, node);
 }
 
+/* FIXME.  */
+
+void
+dump_rtl (dump_flags_t dump_kind, const_rtx x)
+{
+  dump_context::get ().dump_rtl (dump_kind, x);
+}
+
 /* Get the current dump scope-nesting depth.
    For use by -fopt-info (for showing nesting via indentation).  */
 
@@ -1603,6 +1630,17 @@ test_capture_of_dump_calls ()
     ASSERT_TRUE (tmp.get_pending_optinfo () == NULL);
   }
 
+  /* RTL.  */
+  {
+    temp_dump_context tmp (true);
+    dump_rtl (MSG_NOTE, const0_rtx);
+
+    optinfo *info = tmp.get_pending_optinfo ();
+    ASSERT_TRUE (info != NULL);
+    ASSERT_EQ (info->num_items (), 1);
+    assert_is_text (info->get_item (0), "0");
+  }
+
   /* poly_int.  */
   {
     temp_dump_context tmp (true);
diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h
index f81385f..ca88dd9 100644
--- a/gcc/dumpfile.h
+++ b/gcc/dumpfile.h
@@ -433,6 +433,7 @@ extern void dump_gimple_stmt_loc (dump_flags_t, const dump_location_t &,
 				  dump_flags_t, gimple *, int);
 extern void dump_gimple_stmt (dump_flags_t, dump_flags_t, gimple *, int);
 extern void dump_symtab_node (dump_flags_t, symtab_node *);
+extern void dump_rtl (dump_flags_t, const_rtx);
 
 template<unsigned int N, typename C>
 void dump_dec (dump_flags_t, const poly_int<N, C> &);
diff --git a/gcc/optinfo.cc b/gcc/optinfo.cc
index 8692837..f4588a2 100644
--- a/gcc/optinfo.cc
+++ b/gcc/optinfo.cc
@@ -31,6 +31,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "optinfo-emit-diagnostics.h"
 #include "optinfo-emit-json.h"
 #include "dump-context.h"
+#include "pretty-print.h"
+#include "print-rtl.h"
 #include "selftest.h"
 
 /* Remove any trailing whitespace characters from this text item.
@@ -190,6 +192,17 @@ optinfo::add_symtab_node (symtab_node *node)
   m_items.safe_push (new optinfo_item_symtab_node (node));
 }
 
+/* FIXME.  */
+
+void
+optinfo::add_rtl (const_rtx x)
+{
+  pretty_printer pp;
+  print_value (&pp, x, 1 /* int verbose */);
+  char *text = xstrdup (pp_formatted_text (&pp));
+  m_items.safe_push (new optinfo_item_text (text, true));
+}
+
 /* Append the decimal represenation of a wide_int_ref to this
    optinfo.  */
 
diff --git a/gcc/optinfo.h b/gcc/optinfo.h
index 007a7ff..b3dbabd 100644
--- a/gcc/optinfo.h
+++ b/gcc/optinfo.h
@@ -140,6 +140,7 @@ class optinfo
   void add_stmt (gimple *stmt, dump_flags_t dump_flags);
   void add_tree (tree node, dump_flags_t dump_flags);
   void add_symtab_node (symtab_node *node);
+  void add_rtl (const_rtx x);
   void add_dec (const wide_int_ref &wi, signop sgn);
 
   template<unsigned int N, typename C>
-- 
1.8.5.3

