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

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

diff --git a/gcc/dump-context.h b/gcc/dump-context.h
index a191e3a..4868e26 100644
--- a/gcc/dump-context.h
+++ b/gcc/dump-context.h
@@ -78,6 +78,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 4720ba4..c1fbe23 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -737,6 +737,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).  */
 
@@ -975,6 +994,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).  */
 
@@ -1752,6 +1779,17 @@ test_capture_of_dump_calls (const line_table_case &case_)
     }
   }
 
+  /* 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 5bb7f3c..078643d 100644
--- a/gcc/dumpfile.h
+++ b/gcc/dumpfile.h
@@ -436,6 +436,7 @@ extern void dump_gimple_expr_loc (dump_flags_t, const dump_location_t &,
 				  dump_flags_t, gimple *, int);
 extern void dump_gimple_expr (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 77770de..038377a 100644
--- a/gcc/optinfo.cc
+++ b/gcc/optinfo.cc
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "pretty-print.h"
 #include "gimple-pretty-print.h"
 #include "cgraph.h"
+#include "print-rtl.h"
 #include "selftest.h"
 
 /* optinfo_item's ctor.  */
@@ -256,6 +257,19 @@ optinfo::add_symtab_node (symtab_node *node)
   m_items.safe_push (item);
 }
 
+/* FIXME.  */
+
+void
+optinfo::add_rtl (const_rtx x)
+{
+  pretty_printer pp;
+  print_value (&pp, x, 1 /* int verbose */);
+  optinfo_item *item
+    = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
+			xstrdup (pp_formatted_text (&pp)), true);
+  m_items.safe_push (item);
+}
+
 /* Append the decimal represenation of a wide_int_ref to this
    optinfo.  */
 
diff --git a/gcc/optinfo.h b/gcc/optinfo.h
index 34799fc..7b70ecf 100644
--- a/gcc/optinfo.h
+++ b/gcc/optinfo.h
@@ -135,6 +135,7 @@ class optinfo
   void add_gimple_expr (gimple *stmt, int spc, 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

