From 6c8b9ae60cd4b848071f659f91766b0847e2fe15 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 16 May 2018 14:39:56 -0400
Subject: [PATCH 63/67] Move item classes to new optinfo-internal.h header

---
 gcc/optinfo-emit-diagnostics.cc |   1 +
 gcc/optinfo-emit-fopt-info.cc   |   1 +
 gcc/optinfo-emit-json.cc        |   1 +
 gcc/optinfo-internal.h          | 110 ++++++++++++++++++++++++++++++++++++++++
 gcc/optinfo.cc                  |   1 +
 gcc/optinfo.h                   |  87 +------------------------------
 6 files changed, 116 insertions(+), 85 deletions(-)
 create mode 100644 gcc/optinfo-internal.h

diff --git a/gcc/optinfo-emit-diagnostics.cc b/gcc/optinfo-emit-diagnostics.cc
index 90fe5f5..950b8e1 100644
--- a/gcc/optinfo-emit-diagnostics.cc
+++ b/gcc/optinfo-emit-diagnostics.cc
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "optinfo.h"
 #include "optinfo-emit-diagnostics.h"
+#include "optinfo-internal.h"
 
 /* FIXME.  */
 
diff --git a/gcc/optinfo-emit-fopt-info.cc b/gcc/optinfo-emit-fopt-info.cc
index 1c6ec56..10bfdec 100644
--- a/gcc/optinfo-emit-fopt-info.cc
+++ b/gcc/optinfo-emit-fopt-info.cc
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "optinfo.h"
 #include "optinfo-emit-fopt-info.h"
+#include "optinfo-internal.h"
 
 /* Emit OPTINFO via -fopt-info.  */
 
diff --git a/gcc/optinfo-emit-json.cc b/gcc/optinfo-emit-json.cc
index b1dcdf8..1e1b77e 100644
--- a/gcc/optinfo-emit-json.cc
+++ b/gcc/optinfo-emit-json.cc
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "optinfo.h"
 #include "optinfo-emit-json.h"
+#include "optinfo-internal.h"
 #include "json.h"
 #include "pretty-print.h"
 #include "tree-pretty-print.h"
diff --git a/gcc/optinfo-internal.h b/gcc/optinfo-internal.h
new file mode 100644
index 0000000..bdf0bfd
--- /dev/null
+++ b/gcc/optinfo-internal.h
@@ -0,0 +1,110 @@
+/* Implementation details of optinfo.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   Contributed by David Malcolm <dmalcolm@redhat.com>.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_OPTINFO_INTERNAL_H
+#define GCC_OPTINFO_INTERNAL_H
+
+/* Multiple dispatch: there are various kinds of items within an optinfo,
+   and various destinations to send optinfo to.
+
+   Handling this for now by exposing all of the item subclasses,
+   and having the destinations handle them with "switch" statements.  */
+
+/* Base class for items within an optinfo.  */
+
+class optinfo_item
+{
+ public:
+  virtual ~optinfo_item () {}
+
+  virtual enum optinfo_item_kind get_kind () const = 0;
+};
+
+/* optinfo_item subclasses.  */
+
+/* Item within an optinfo: text, either owned by the item
+   (for optinfo_printf), or borrowed (for string literals).  */
+
+class optinfo_item_text : public optinfo_item
+{
+ public:
+  optinfo_item_text (char *text, bool owned)
+  : m_text (text), m_owned (owned)
+  {}
+  ~optinfo_item_text ()
+  {
+    if (m_owned)
+      free (m_text);
+  }
+
+  enum optinfo_item_kind get_kind () const FINAL OVERRIDE
+  {
+    return OPTINFO_ITEM_KIND_TEXT;
+  }
+
+  const char *get_text () const { return m_text; }
+
+ private:
+  char *m_text;
+  bool m_owned;
+};
+
+/* Item within an optinfo: a tree, with dump flags.
+   Note that this is not GTY-marked, as it's assumed that instances
+   are short-lived.  */
+
+class optinfo_item_tree : public optinfo_item
+{
+ public:
+  optinfo_item_tree (optinfo_tree node_with_flags)
+    : m_node_with_flags (node_with_flags)
+  {}
+  enum optinfo_item_kind get_kind () const FINAL OVERRIDE
+  {
+    return OPTINFO_ITEM_KIND_TREE;
+  }
+
+  tree get_node () const { return m_node_with_flags.m_node; }
+  dump_flags_t get_flags () const { return m_node_with_flags.m_flags; }
+
+ private:
+  optinfo_tree m_node_with_flags;
+};
+
+/* Item within an optinfo: a gimple statement.
+   Note that this is not GTY-marked, as it's assumed that instances
+   are short-lived.  */
+
+class optinfo_item_gimple : public optinfo_item
+{
+ public:
+  optinfo_item_gimple (gimple *stmt) : m_stmt (stmt) {}
+  enum optinfo_item_kind get_kind () const FINAL OVERRIDE
+  {
+    return OPTINFO_ITEM_KIND_GIMPLE;
+  }
+
+  gimple *get_stmt () const { return m_stmt; }
+
+ private:
+  gimple *m_stmt;
+};
+
+#endif /* #ifndef GCC_OPTINFO_INTERNAL_H */
diff --git a/gcc/optinfo.cc b/gcc/optinfo.cc
index ab2dad2..f689249 100644
--- a/gcc/optinfo.cc
+++ b/gcc/optinfo.cc
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "optinfo-emit-diagnostics.h"
 #include "optinfo-emit-json.h"
 #include "optinfo-emit-fopt-info.h"
+#include "optinfo-internal.h"
 
 /* Constructing an optinfo_location from a loop.  */
 
diff --git a/gcc/optinfo.h b/gcc/optinfo.h
index 8a2e262..e3d2f7d 100644
--- a/gcc/optinfo.h
+++ b/gcc/optinfo.h
@@ -49,11 +49,8 @@ along with GCC; see the file COPYING3.  If not see
 /* Forward decls.  */
 class pending_optinfo;
 
-/* Multiple dispatch: there are various kinds of items within an optinfo,
-   and various destinations to send optinfo to.
-
-   Handling this for now by exposing all of the item subclasses,
-   and having the destinations handle them with "switch" statements.  */
+/* optinfo-internal.h.  */
+class optinfo_item;
 
 /* An enum for discriminating between optinfo_item subclasses.  */
 
@@ -64,45 +61,6 @@ enum optinfo_item_kind
   OPTINFO_ITEM_KIND_GIMPLE
 };
 
-/* Base class for items within an optinfo.  */
-
-class optinfo_item
-{
- public:
-  virtual ~optinfo_item () {}
-
-  virtual enum optinfo_item_kind get_kind () const = 0;
-};
-
-/* optinfo_item subclasses.  */
-
-/* Item within an optinfo: text, either owned by the item
-   (for optinfo_printf), or borrowed (for string literals).  */
-
-class optinfo_item_text : public optinfo_item
-{
- public:
-  optinfo_item_text (char *text, bool owned)
-  : m_text (text), m_owned (owned)
-  {}
-  ~optinfo_item_text ()
-  {
-    if (m_owned)
-      free (m_text);
-  }
-
-  enum optinfo_item_kind get_kind () const FINAL OVERRIDE
-  {
-    return OPTINFO_ITEM_KIND_TEXT;
-  }
-
-  const char *get_text () const { return m_text; }
-
- private:
-  char *m_text;
-  bool m_owned;
-};
-
 /* Packaging up a tree with dump flags.  */
 // FIXME: should this be GTY-marked?
 
@@ -130,47 +88,6 @@ static inline optinfo_tree details (tree node)
   return optinfo_tree (node, TDF_DETAILS);
 }
 
-/* Item within an optinfo: a tree, with dump flags.
-   Note that this is not GTY-marked, as it's assumed that instances
-   are short-lived.  */
-
-class optinfo_item_tree : public optinfo_item
-{
- public:
-  optinfo_item_tree (optinfo_tree node_with_flags)
-    : m_node_with_flags (node_with_flags)
-  {}
-  enum optinfo_item_kind get_kind () const FINAL OVERRIDE
-  {
-    return OPTINFO_ITEM_KIND_TREE;
-  }
-
-  tree get_node () const { return m_node_with_flags.m_node; }
-  dump_flags_t get_flags () const { return m_node_with_flags.m_flags; }
-
- private:
-  optinfo_tree m_node_with_flags;
-};
-
-/* Item within an optinfo: a gimple statement.
-   Note that this is not GTY-marked, as it's assumed that instances
-   are short-lived.  */
-
-class optinfo_item_gimple : public optinfo_item
-{
- public:
-  optinfo_item_gimple (gimple *stmt) : m_stmt (stmt) {}
-  enum optinfo_item_kind get_kind () const FINAL OVERRIDE
-  {
-    return OPTINFO_ITEM_KIND_GIMPLE;
-  }
-
-  gimple *get_stmt () const { return m_stmt; }
-
- private:
-  gimple *m_stmt;
-};
-
 /* A class for describing a source-code location for an optinfo.
    In particular, this lets us associate optinfo instances
    with hotness information (e.g. from PGO), allowing them to
-- 
1.8.5.3

