]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use std::unique_ptr for optinfo_item
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 29 Aug 2024 22:48:16 +0000 (18:48 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 29 Aug 2024 22:48:16 +0000 (18:48 -0400)
As preliminary work towards an overhaul of how optinfo_items
interact with dump_pretty_printer, replace uses of optinfo_item * with
std::unique_ptr<optinfo_item> to make ownership clearer.

No functional change intended.

gcc/ChangeLog:
* config/aarch64/aarch64.cc: Define INCLUDE_MEMORY.
* config/arm/arm.cc: Likewise.
* config/i386/i386.cc: Likewise.
* config/loongarch/loongarch.cc: Likewise.
* config/riscv/riscv-vector-costs.cc: Likewise.
* config/riscv/riscv.cc: Likewise.
* config/rs6000/rs6000.cc: Likewise.
* dump-context.h (dump_context::emit_item): Convert "item" param
from * to const &.
(dump_pretty_printer::stash_item): Convert "item" param from
optinfo_ * to std::unique_ptr<optinfo_item>.
(dump_pretty_printer::emit_item): Likewise.
* dumpfile.cc: Include "make-unique.h".
(make_item_for_dump_gimple_stmt): Replace uses of optinfo_item *
with std::unique_ptr<optinfo_item>.
(dump_context::dump_gimple_stmt): Likewise.
(make_item_for_dump_gimple_expr): Likewise.
(dump_context::dump_gimple_expr): Likewise.
(make_item_for_dump_generic_expr): Likewise.
(dump_context::dump_generic_expr): Likewise.
(make_item_for_dump_symtab_node): Likewise.
(dump_pretty_printer::emit_items): Likewise.
(dump_pretty_printer::emit_any_pending_textual_chunks): Likewise.
(dump_pretty_printer::emit_item): Likewise.
(dump_pretty_printer::stash_item): Likewise.
(dump_pretty_printer::decode_format): Likewise.
(dump_context::dump_printf_va): Fix overlong line.
(make_item_for_dump_dec): Replace uses of optinfo_item * with
std::unique_ptr<optinfo_item>.
(dump_context::dump_dec): Likewise.
(dump_context::dump_symtab_node): Likewise.
(dump_context::begin_scope): Likewise.
(dump_context::emit_item): Likewise.
* gimple-loop-interchange.cc: Define INCLUDE_MEMORY.
* gimple-loop-jam.cc: Likewise.
* gimple-loop-versioning.cc: Likewise.
* graphite-dependences.cc: Likewise.
* graphite-isl-ast-to-gimple.cc: Likewise.
* graphite-optimize-isl.cc: Likewise.
* graphite-poly.cc: Likewise.
* graphite-scop-detection.cc: Likewise.
* graphite-sese-to-poly.cc: Likewise.
* graphite.cc: Likewise.
* opt-problem.cc: Likewise.
* optinfo.cc (optinfo::add_item): Convert "item" param from
optinfo_ * to std::unique_ptr<optinfo_item>.
(optinfo::emit_for_opt_problem): Update for change to
dump_context::emit_item.
* optinfo.h: Add #error to fail immediately if INCLUDE_MEMORY
wasn't defined, rather than fail to find std::unique_ptr.
(optinfo::add_item): Convert "item" param from optinfo_ * to
std::unique_ptr<optinfo_item>.
* sese.cc: Define INCLUDE_MEMORY.
* targhooks.cc: Likewise.
* tree-data-ref.cc: Likewise.
* tree-if-conv.cc: Likewise.
* tree-loop-distribution.cc: Likewise.
* tree-parloops.cc: Likewise.
* tree-predcom.cc: Likewise.
* tree-ssa-live.cc: Likewise.
* tree-ssa-loop-ivcanon.cc: Likewise.
* tree-ssa-loop-ivopts.cc: Likewise.
* tree-ssa-loop-prefetch.cc: Likewise.
* tree-ssa-loop-unswitch.cc: Likewise.
* tree-ssa-phiopt.cc: Likewise.
* tree-ssa-threadbackward.cc: Likewise.
* tree-ssa-threadupdate.cc: Likewise.
* tree-vect-data-refs.cc: Likewise.
* tree-vect-generic.cc: Likewise.
* tree-vect-loop-manip.cc: Likewise.
* tree-vect-loop.cc: Likewise.
* tree-vect-patterns.cc: Likewise.
* tree-vect-slp-patterns.cc: Likewise.
* tree-vect-slp.cc: Likewise.
* tree-vect-stmts.cc: Likewise.
* tree-vectorizer.cc: Likewise.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/dump_plugin.c: Define INCLUDE_MEMORY.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
47 files changed:
gcc/config/aarch64/aarch64.cc
gcc/config/arm/arm.cc
gcc/config/i386/i386.cc
gcc/config/loongarch/loongarch.cc
gcc/config/riscv/riscv-vector-costs.cc
gcc/config/riscv/riscv.cc
gcc/config/rs6000/rs6000.cc
gcc/dump-context.h
gcc/dumpfile.cc
gcc/gimple-loop-interchange.cc
gcc/gimple-loop-jam.cc
gcc/gimple-loop-versioning.cc
gcc/graphite-dependences.cc
gcc/graphite-isl-ast-to-gimple.cc
gcc/graphite-optimize-isl.cc
gcc/graphite-poly.cc
gcc/graphite-scop-detection.cc
gcc/graphite-sese-to-poly.cc
gcc/graphite.cc
gcc/opt-problem.cc
gcc/optinfo.cc
gcc/optinfo.h
gcc/sese.cc
gcc/targhooks.cc
gcc/testsuite/gcc.dg/plugin/dump_plugin.c
gcc/tree-data-ref.cc
gcc/tree-if-conv.cc
gcc/tree-loop-distribution.cc
gcc/tree-parloops.cc
gcc/tree-predcom.cc
gcc/tree-ssa-live.cc
gcc/tree-ssa-loop-ivcanon.cc
gcc/tree-ssa-loop-ivopts.cc
gcc/tree-ssa-loop-prefetch.cc
gcc/tree-ssa-loop-unswitch.cc
gcc/tree-ssa-phiopt.cc
gcc/tree-ssa-threadbackward.cc
gcc/tree-ssa-threadupdate.cc
gcc/tree-vect-data-refs.cc
gcc/tree-vect-generic.cc
gcc/tree-vect-loop-manip.cc
gcc/tree-vect-loop.cc
gcc/tree-vect-patterns.cc
gcc/tree-vect-slp-patterns.cc
gcc/tree-vect-slp.cc
gcc/tree-vect-stmts.cc
gcc/tree-vectorizer.cc

index 033ea61d3a8ee34714861dcaad1a797671ba7494..27e24ba70abe3837d54bd2e7fa65d444054f8809 100644 (file)
@@ -22,6 +22,7 @@
 
 #define INCLUDE_STRING
 #define INCLUDE_ALGORITHM
+#define INCLUDE_MEMORY
 #define INCLUDE_VECTOR
 #include "config.h"
 #include "system.h"
index d54564a6c359ea48aac50b494e89fad53f428eed..17485447693b1f37f5a04619578a6e761fa8b2d1 100644 (file)
@@ -23,6 +23,7 @@
 #define IN_TARGET_CODE 1
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #define INCLUDE_STRING
 #include "system.h"
 #include "coretypes.h"
index 224a78cc8327d387fd34095bec440b100932f252..a1f65d41fdd54dacad670e84699f61c0c1950808 100644 (file)
@@ -17,6 +17,7 @@ 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/>.  */
 
+#define INCLUDE_MEMORY
 #define INCLUDE_STRING
 #define IN_TARGET_CODE 1
 
index c7a02103ef516662ce51395c83a58c2b136b874d..f956ee4b119bb7bc7b796451113d86f2ff5d3161 100644 (file)
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #define IN_TARGET_CODE 1
 
+#define INCLUDE_MEMORY
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
index a80e167597beb66ce6cee19721d401d71486bfa9..25570bd40040917da16653358cceca7340470f90 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #define IN_TARGET_CODE 1
 
+#define INCLUDE_MEMORY
 #define INCLUDE_STRING
 #include "config.h"
 #include "system.h"
index 3f5dfb838425c1348abdca0c606e091b63d0f1ce..496dd177fe7fba34543ea3240d5c6b0a81acfb2f 100644 (file)
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #define IN_TARGET_CODE 1
 
+#define INCLUDE_MEMORY
 #define INCLUDE_STRING
 #include "config.h"
 #include "system.h"
index 94c0db4521e2c5549041937d4c1a77ef07db4e64..08579bc83e6f4e429808f8e6e971297f5264d364 100644 (file)
@@ -22,6 +22,7 @@
 #define IN_TARGET_CODE 1
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index b2aed2853a3762fe9a00ddc8a9c8f5348d68574a..5992956380b13bbedd29efbe2cd111cf39de95a9 100644 (file)
@@ -120,7 +120,7 @@ class dump_context
   void end_any_optinfo ();
 
   void emit_optinfo (const optinfo *info);
-  void emit_item (optinfo_item *item, dump_flags_t dump_kind);
+  void emit_item (const optinfo_item &item, dump_flags_t dump_kind);
 
   bool apply_dump_filter_p (dump_flags_t dump_kind, dump_flags_t filter) const;
 
@@ -186,11 +186,12 @@ private:
   bool decode_format (text_info *text, const char *spec,
                      const char **buffer_ptr);
 
-  void stash_item (const char **buffer_ptr, optinfo_item *item);
+  void stash_item (const char **buffer_ptr,
+                  std::unique_ptr<optinfo_item> item);
 
   void emit_any_pending_textual_chunks (optinfo *dest);
 
-  void emit_item (optinfo_item *item, optinfo *dest);
+  void emit_item (std::unique_ptr<optinfo_item> item, optinfo *dest);
 
   dump_context *m_context;
   dump_flags_t m_dump_kind;
index 6353c0857449eab857d3306b5f2372c287004ff7..2971c69bb0a1231421848df97ba376d3170a3641 100644 (file)
@@ -41,6 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "optinfo-emit-json.h"
 #include "stringpool.h" /* for get_identifier.  */
 #include "spellcheck.h"
+#include "make-unique.h"
 
 /* If non-NULL, return one past-the-end of the matching SUBPART of
    the WHOLE string.  */
@@ -628,7 +629,7 @@ dump_context::dump_loc_immediate (dump_flags_t dump_kind,
 
 /* Make an item for the given dump call, equivalent to print_gimple_stmt.  */
 
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
 make_item_for_dump_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags)
 {
   pretty_printer pp;
@@ -636,9 +637,10 @@ make_item_for_dump_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags)
   pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
   pp_newline (&pp);
 
-  optinfo_item *item
-    = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
-                       xstrdup (pp_formatted_text (&pp)));
+  std::unique_ptr<optinfo_item> item
+    = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_GIMPLE,
+                                gimple_location (stmt),
+                                xstrdup (pp_formatted_text (&pp)));
   return item;
 }
 
@@ -650,17 +652,15 @@ dump_context::dump_gimple_stmt (const dump_metadata_t &metadata,
                                dump_flags_t extra_dump_flags,
                                gimple *gs, int spc)
 {
-  optinfo_item *item
+  auto item
     = make_item_for_dump_gimple_stmt (gs, spc, dump_flags | extra_dump_flags);
-  emit_item (item, metadata.get_dump_flags ());
+  emit_item (*item.get (), metadata.get_dump_flags ());
 
   if (optinfo_enabled_p ())
     {
       optinfo &info = ensure_pending_optinfo (metadata);
-      info.add_item (item);
+      info.add_item (std::move (item));
     }
-  else
-    delete item;
 }
 
 /* Similar to dump_gimple_stmt, except additionally print source location.  */
@@ -677,7 +677,7 @@ dump_context::dump_gimple_stmt_loc (const dump_metadata_t &metadata,
 
 /* Make an item for the given dump call, equivalent to print_gimple_expr.  */
 
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
 make_item_for_dump_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags)
 {
   dump_flags |= TDF_RHS_ONLY;
@@ -685,9 +685,10 @@ make_item_for_dump_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags)
   pp_needs_newline (&pp) = true;
   pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
 
-  optinfo_item *item
-    = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
-                       xstrdup (pp_formatted_text (&pp)));
+  std::unique_ptr<optinfo_item> item
+    = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_GIMPLE,
+                                gimple_location (stmt),
+                                xstrdup (pp_formatted_text (&pp)));
   return item;
 }
 
@@ -700,17 +701,15 @@ dump_context::dump_gimple_expr (const dump_metadata_t &metadata,
                                dump_flags_t extra_dump_flags,
                                gimple *gs, int spc)
 {
-  optinfo_item *item
+  std::unique_ptr<optinfo_item> item
     = make_item_for_dump_gimple_expr (gs, spc, dump_flags | extra_dump_flags);
-  emit_item (item, metadata.get_dump_flags ());
+  emit_item (*item.get (), metadata.get_dump_flags ());
 
   if (optinfo_enabled_p ())
     {
       optinfo &info = ensure_pending_optinfo (metadata);
-      info.add_item (item);
+      info.add_item (std::move (item));
     }
-  else
-    delete item;
 }
 
 /* Similar to dump_gimple_expr, except additionally print source location.  */
@@ -728,7 +727,7 @@ dump_context::dump_gimple_expr_loc (const dump_metadata_t &metadata,
 
 /* Make an item for the given dump call, equivalent to print_generic_expr.  */
 
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
 make_item_for_dump_generic_expr (tree node, dump_flags_t dump_flags)
 {
   pretty_printer pp;
@@ -740,9 +739,9 @@ make_item_for_dump_generic_expr (tree node, dump_flags_t dump_flags)
   if (EXPR_HAS_LOCATION (node))
     loc = EXPR_LOCATION (node);
 
-  optinfo_item *item
-    = new optinfo_item (OPTINFO_ITEM_KIND_TREE, loc,
-                       xstrdup (pp_formatted_text (&pp)));
+  std::unique_ptr<optinfo_item> item
+    = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TREE, loc,
+                                xstrdup (pp_formatted_text (&pp)));
   return item;
 }
 
@@ -754,17 +753,15 @@ dump_context::dump_generic_expr (const dump_metadata_t &metadata,
                                 dump_flags_t extra_dump_flags,
                                 tree t)
 {
-  optinfo_item *item
+  std::unique_ptr<optinfo_item> item
     = make_item_for_dump_generic_expr (t, dump_flags | extra_dump_flags);
-  emit_item (item, metadata.get_dump_flags ());
+  emit_item (*item.get (), metadata.get_dump_flags ());
 
   if (optinfo_enabled_p ())
     {
       optinfo &info = ensure_pending_optinfo (metadata);
-      info.add_item (item);
+      info.add_item (std::move (item));
     }
-  else
-    delete item;
 }
 
 
@@ -783,13 +780,13 @@ dump_context::dump_generic_expr_loc (const dump_metadata_t &metadata,
 
 /* Make an item for the given dump call.  */
 
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
 make_item_for_dump_symtab_node (symtab_node *node)
 {
   location_t loc = DECL_SOURCE_LOCATION (node->decl);
-  optinfo_item *item
-    = new optinfo_item (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
-                       xstrdup (node->dump_name ()));
+  std::unique_ptr<optinfo_item> item
+    = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
+                                xstrdup (node->dump_name ()));
   return item;
 }
 
@@ -834,7 +831,9 @@ dump_pretty_printer::emit_items (optinfo *dest)
        {
          emit_any_pending_textual_chunks (dest);
          /* This chunk has a stashed item: use it.  */
-         emit_item (m_stashed_items[stashed_item_idx++].item, dest);
+         std::unique_ptr <optinfo_item> item
+           (m_stashed_items[stashed_item_idx++].item);
+         emit_item (std::move (item), dest);
        }
       else
        /* This chunk is purely textual.  Print it (to
@@ -866,10 +865,10 @@ dump_pretty_printer::emit_any_pending_textual_chunks (optinfo *dest)
     return;
 
   char *formatted_text = xstrdup (pp_formatted_text (this));
-  optinfo_item *item
-    = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
-                       formatted_text);
-  emit_item (item, dest);
+  std::unique_ptr<optinfo_item> item
+    = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
+                                formatted_text);
+  emit_item (std::move (item), dest);
 
   /* Clear the pending text by unwinding formatted_text back to the start
      of the buffer (without deallocating).  */
@@ -881,25 +880,25 @@ dump_pretty_printer::emit_any_pending_textual_chunks (optinfo *dest)
    to DEST; otherwise delete ITEM.  */
 
 void
-dump_pretty_printer::emit_item (optinfo_item *item, optinfo *dest)
+dump_pretty_printer::emit_item (std::unique_ptr<optinfo_item> item,
+                               optinfo *dest)
 {
-  m_context->emit_item (item, m_dump_kind);
+  m_context->emit_item (*item.get (), m_dump_kind);
   if (dest)
-    dest->add_item (item);
-  else
-    delete item;
+    dest->add_item (std::move (item));
 }
 
 /* Record that ITEM (generated in phase 2 of formatting) is to be used for
    the chunk at BUFFER_PTR in phase 3 (by emit_items).  */
 
 void
-dump_pretty_printer::stash_item (const char **buffer_ptr, optinfo_item *item)
+dump_pretty_printer::stash_item (const char **buffer_ptr,
+                                std::unique_ptr<optinfo_item> item)
 {
   gcc_assert (buffer_ptr);
-  gcc_assert (item);
+  gcc_assert (item.get ());
 
-  m_stashed_items.safe_push (stashed_item (buffer_ptr, item));
+  m_stashed_items.safe_push (stashed_item (buffer_ptr, item.release ()));
 }
 
 /* pp_format_decoder callback for dump_pretty_printer, and thus for
@@ -953,8 +952,8 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
        cgraph_node *node = va_arg (*text->m_args_ptr, cgraph_node *);
 
        /* Make an item for the node, and stash it.  */
-       optinfo_item *item = make_item_for_dump_symtab_node (node);
-       stash_item (buffer_ptr, item);
+       auto item = make_item_for_dump_symtab_node (node);
+       stash_item (buffer_ptr, std::move (item));
        return true;
       }
 
@@ -963,8 +962,8 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
        gimple *stmt = va_arg (*text->m_args_ptr, gimple *);
 
        /* Make an item for the stmt, and stash it.  */
-       optinfo_item *item = make_item_for_dump_gimple_expr (stmt, 0, TDF_SLIM);
-       stash_item (buffer_ptr, item);
+       auto item = make_item_for_dump_gimple_expr (stmt, 0, TDF_SLIM);
+       stash_item (buffer_ptr, std::move (item));
        return true;
       }
 
@@ -973,8 +972,8 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
        gimple *stmt = va_arg (*text->m_args_ptr, gimple *);
 
        /* Make an item for the stmt, and stash it.  */
-       optinfo_item *item = make_item_for_dump_gimple_stmt (stmt, 0, TDF_SLIM);
-       stash_item (buffer_ptr, item);
+       auto item = make_item_for_dump_gimple_stmt (stmt, 0, TDF_SLIM);
+       stash_item (buffer_ptr, std::move (item));
        return true;
       }
 
@@ -983,8 +982,8 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
        tree t = va_arg (*text->m_args_ptr, tree);
 
        /* Make an item for the tree, and stash it.  */
-       optinfo_item *item = make_item_for_dump_generic_expr (t, TDF_SLIM);
-       stash_item (buffer_ptr, item);
+       auto item = make_item_for_dump_generic_expr (t, TDF_SLIM);
+       stash_item (buffer_ptr, std::move (item));
        return true;
       }
 
@@ -996,7 +995,8 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
 /* Output a formatted message using FORMAT on appropriate dump streams.  */
 
 void
-dump_context::dump_printf_va (const dump_metadata_t &metadata, const char *format,
+dump_context::dump_printf_va (const dump_metadata_t &metadata,
+                             const char *format,
                              va_list *ap)
 {
   dump_pretty_printer pp (this, metadata.get_dump_flags ());
@@ -1031,7 +1031,7 @@ dump_context::dump_printf_loc_va (const dump_metadata_t &metadata,
 /* Make an item for the given dump call, equivalent to print_dec.  */
 
 template<unsigned int N, typename C>
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
 make_item_for_dump_dec (const poly_int<N, C> &value)
 {
   STATIC_ASSERT (poly_coeff_traits<C>::signedness >= 0);
@@ -1051,9 +1051,9 @@ make_item_for_dump_dec (const poly_int<N, C> &value)
        }
     }
 
-  optinfo_item *item
-    = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
-                       xstrdup (pp_formatted_text (&pp)));
+  auto item
+    = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
+                                xstrdup (pp_formatted_text (&pp)));
   return item;
 }
 
@@ -1061,35 +1061,33 @@ make_item_for_dump_dec (const poly_int<N, C> &value)
 
 template<unsigned int N, typename C>
 void
-dump_context::dump_dec (const dump_metadata_t &metadata, const poly_int<N, C> &value)
+dump_context::dump_dec (const dump_metadata_t &metadata,
+                       const poly_int<N, C> &value)
 {
-  optinfo_item *item = make_item_for_dump_dec (value);
-  emit_item (item, metadata.get_dump_flags ());
+  auto item = make_item_for_dump_dec (value);
+  emit_item (*item.get (), metadata.get_dump_flags ());
 
   if (optinfo_enabled_p ())
     {
       optinfo &info = ensure_pending_optinfo (metadata);
-      info.add_item (item);
+      info.add_item (std::move (item));
     }
-  else
-    delete item;
 }
 
 /* Output the name of NODE on appropriate dump streams.  */
 
 void
-dump_context::dump_symtab_node (const dump_metadata_t &metadata, symtab_node *node)
+dump_context::dump_symtab_node (const dump_metadata_t &metadata,
+                               symtab_node *node)
 {
-  optinfo_item *item = make_item_for_dump_symtab_node (node);
-  emit_item (item, metadata.get_dump_flags ());
+  auto item = make_item_for_dump_symtab_node (node);
+  emit_item (*item.get (), metadata.get_dump_flags ());
 
   if (optinfo_enabled_p ())
     {
       optinfo &info = ensure_pending_optinfo (metadata);
-      info.add_item (item);
+      info.add_item (std::move (item));
     }
-  else
-    delete item;
 }
 
 /* Get the current dump scope-nesting depth.
@@ -1132,10 +1130,10 @@ dump_context::begin_scope (const char *name,
   pretty_printer pp;
   pp_printf (&pp, "%s %s %s", "===", name, "===");
   pp_newline (&pp);
-  optinfo_item *item
-    = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
-                       xstrdup (pp_formatted_text (&pp)));
-  emit_item (item, MSG_NOTE);
+  std::unique_ptr<optinfo_item> item
+    = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
+                                xstrdup (pp_formatted_text (&pp)));
+  emit_item (*item.get (), MSG_NOTE);
 
   if (optinfo_enabled_p ())
     {
@@ -1143,11 +1141,9 @@ dump_context::begin_scope (const char *name,
        = begin_next_optinfo (dump_metadata_t (MSG_NOTE, impl_location),
                              user_location);
       info.m_kind = OPTINFO_KIND_SCOPE;
-      info.add_item (item);
+      info.add_item (std::move (item));
       end_any_optinfo ();
     }
-  else
-    delete item;
 }
 
 /* Pop a nested dump scope.  */
@@ -1226,17 +1222,17 @@ dump_context::emit_optinfo (const optinfo *info)
    consolidation into optinfo instances).  */
 
 void
-dump_context::emit_item (optinfo_item *item, dump_flags_t dump_kind)
+dump_context::emit_item (const optinfo_item &item, dump_flags_t dump_kind)
 {
   if (dump_file && apply_dump_filter_p (dump_kind, pflags))
-    fprintf (dump_file, "%s", item->get_text ());
+    fprintf (dump_file, "%s", item.get_text ());
 
   if (alt_dump_file && apply_dump_filter_p (dump_kind, alt_flags))
-    fprintf (alt_dump_file, "%s", item->get_text ());
+    fprintf (alt_dump_file, "%s", item.get_text ());
 
   /* Support for temp_dump_context in selftests.  */
   if (m_test_pp && apply_dump_filter_p (dump_kind, m_test_pp_flags))
-    pp_string (m_test_pp, item->get_text ());
+    pp_string (m_test_pp, item.get_text ());
 }
 
 /* The current singleton dump_context, and its default.  */
index b4228044a3873f5dad872e1a0449372277acdb97..a4ea818bbdfdf198a3ccc6c8eb1063420461841c 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 306d5ceaef48c6fad30bd160a3b0f0bcf314a260..bf01e0ba646772e5cab3d47305e43ac734db50f3 100644 (file)
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "tree-pass.h"
index adea207659bee816fd9d062884b3a57442d90877..107b00200247bba4139f5c5e217a8b3ab188d942 100644 (file)
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index a35f71254f8428e135d27726b648702dc6ddb7b2..41e1114173bfd259ca3c4cec267d3d5ccbf96b7a 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #define INCLUDE_ISL
+#define INCLUDE_MEMORY
 
 #include "config.h"
 
index a27402ba6b703a04d87c738112737007a29b0fe5..ff539b14045c3011af4be97400b1b6cc5bfa08f6 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #define INCLUDE_ISL
+#define INCLUDE_MEMORY
 
 #include "config.h"
 
index 2222dd685425ece0dfedb0dcc368e2cc143bb779..ff3dd6b7ab634f2c5b0fcf04f13f8317514732f7 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #define INCLUDE_ISL
+#define INCLUDE_MEMORY
 
 #include "config.h"
 
index c78ff986c3259204fc8eee7c1fd8b3c3df7167f2..76aba03d63320ce457f280028593432e15def930 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #define INCLUDE_ISL
+#define INCLUDE_MEMORY
 
 #include "config.h"
 
index 9e44f100a1dfa19ad083be951973d732bd193096..de7c111118bae6ccd315b67a2af47b4cb67c95d4 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #define INCLUDE_ISL
+#define INCLUDE_MEMORY
 
 #include "config.h"
 
index 5ce898505a3063952a8f1a526c46199dcc5d97aa..1e7818a9ca3e29e4ee15f340f81cdfa5ff36dc84 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #define INCLUDE_ISL
+#define INCLUDE_MEMORY
 
 #include "config.h"
 
index 80e6a5da6b2980fcc274d1a01bced90b8b78453d..65b970f9444ef4aa096b8c611df877113d58264b 100644 (file)
@@ -28,6 +28,7 @@ along with GCC; see the file COPYING3.  If not see
    the related work.  */
 
 #define INCLUDE_ISL
+#define INCLUDE_MEMORY
 
 #include "config.h"
 #include "system.h"
index f40f48196dea25217f7875fb21a6a8964a70cfef..d76ddaf57adf6a010c69e084e3931edad87b531e 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 7a8256171744f0f4b030d11e4ae0127f334aaecc..48a270cbfea83685f300fe3b9f39e670ffdafcef 100644 (file)
@@ -84,10 +84,10 @@ optinfo::~optinfo ()
 /* Add ITEM to this optinfo.  */
 
 void
-optinfo::add_item (optinfo_item *item)
+optinfo::add_item (std::unique_ptr<optinfo_item> item)
 {
-  gcc_assert (item);
-  m_items.safe_push (item);
+  gcc_assert (item.get ());
+  m_items.safe_push (item.release ());
 }
 
 /* Get MSG_* flags corresponding to KIND.  */
@@ -123,7 +123,7 @@ optinfo::emit_for_opt_problem () const
   unsigned i;
   optinfo_item *item;
   FOR_EACH_VEC_ELT (m_items, i, item)
-    dump_context::get ().emit_item (item, dump_kind);
+    dump_context::get ().emit_item (*item, dump_kind);
 
   /* Re-emit to "non-immediate" destinations.  */
   dump_context::get ().emit_optinfo (this);
index 986ef75756fc7373fd2f12ca1ad66bcabc5896bf..db92294f3cab3678ec733df2ef16448f070849a1 100644 (file)
@@ -21,6 +21,15 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_OPTINFO_H
 #define GCC_OPTINFO_H
 
+/* This header uses std::unique_ptr, but <memory> can't be directly
+   included due to issues with macros.  Hence <memory> must be included
+   from system.h by defining INCLUDE_MEMORY in any source file using
+   optinfo.h.  */
+
+#ifndef INCLUDE_MEMORY
+# error "You must define INCLUDE_MEMORY before including system.h to use optinfo.h"
+#endif
+
 /* An "optinfo" is a bundle of information describing part of an
    optimization, which can be emitted to zero or more of several
    destinations, such as:
@@ -119,7 +128,7 @@ class optinfo
   location_t get_location_t () const { return m_loc.get_location_t (); }
   profile_count get_count () const { return m_loc.get_count (); }
 
-  void add_item (optinfo_item *item);
+  void add_item (std::unique_ptr<optinfo_item> item);
 
   void emit_for_opt_problem () const;
 
index e5c460571c5508a39ad043ce6c4fa4fbbecd0d4a..e9b17fafa01164f218a8442497bcf765f877927e 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 793932a77c60b0cd4bb670de50b7f7fdf2de2159..dc040df9fcd1182b62d83088ee7fb3a248c99f51 100644 (file)
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3.  If not see
    comment can thus be removed at that point.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
index 12573d66af211cdfb71b4f75c5fff6fa4fedb7d7..fc76d69adb1d397943e9592dea3e7c88c73b9a57 100644 (file)
@@ -1,5 +1,6 @@
 /* Plugin for testing dumpfile.c.  */
 
+#define INCLUDE_MEMORY
 #include "gcc-plugin.h"
 #include "config.h"
 #include "system.h"
index bd61069b6316db6503886c931d5fe42f52683848..48798f458b803fd4d4261c152245f8d9f0dc5224 100644 (file)
@@ -74,6 +74,7 @@ along with GCC; see the file COPYING3.  If not see
 */
 
 #define INCLUDE_ALGORITHM
+#define INCLUDE_MEMORY
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
index 735e47763de1ee1f1276d5e2615d486f2ac717ca..0346a1376c5f87f538e3573c05b1aa3d02be6eaf 100644 (file)
@@ -81,6 +81,7 @@ along with GCC; see the file COPYING3.  If not see
 */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 10f261a8769bcfcc83612cafcb976da9a25ba799..f0430ede2f45f23271a25cae526c2e7f163de5a9 100644 (file)
@@ -90,6 +90,7 @@ along with GCC; see the file COPYING3.  If not see
        data reuse.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 888a834faf9195f054868a084262279a82b26c1c..f4468658732b4aaa85c3afda409a15e1f6198636 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 9844fee1e974078713e4161e3d6fc21752223451..eed878b8f54ba709f884505fca9bc6c5ce8c2704 100644 (file)
@@ -205,6 +205,7 @@ along with GCC; see the file COPYING3.  If not see
    i * i with ii_last + 2 * i + 1), to generalize strength reduction.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 60dfc05dcd94e8ca842b917954c25dcfe41fa1d3..0739faa022efcac123be59b0a63ccbd5ad78bf5e 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 5ef24a919176a852a50d170493ffa6e38eb9fde6..a8d25ad0efc4ac15205c123ee565497db3c2ebb5 100644 (file)
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
        info).  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index c3218a3e8eedbb8d0a7f14c01eeb069cb6024c29..dfe1b254156201fe39baf096209eca938d01b0d1 100644 (file)
@@ -90,6 +90,7 @@ along with GCC; see the file COPYING3.  If not see
       profitable.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index bb5d5dec77952b6d12b94af6011cc4527b75277d..52ea3bad07eb5701d3af2eb2be3e841ec5da4056 100644 (file)
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 14b0df1aefe720460b254f68d4052f804de29ea1..7601d91e8070ef6f4b8ef38afdb9810e0943a334 100644 (file)
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 95bac330c8f23b001736dae534f1662ead7416d0..9a009e187ee9c7e68a4da65ffd0ee822140a9070 100644 (file)
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index ea8d7b882d0823559880176e3691e9f2191c0695..4bc72ec23755836aa995f9898ff0e303e6b69a1c 100644 (file)
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index fa61ba9512b75fbd8b005c72988cfc2f31a54f60..c88cc1d6aac93a5112484549f8fc4f185d1870d9 100644 (file)
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 5b0d548f8479ddc3ff367de17df12d083e52ae90..fe7fdec4ba0d9491a19fbd8724e0be060563d2eb 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 4bcab71c16837d722786f1a8d0f00106b002bc26..3041fb8fcf235ba86f37ef73aa089330a2fd0b77 100644 (file)
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 57dbcbe862cda5cec1794b57d5d919348eca60ec..cb7843f6f72e34b83c8c2989e0a23521b2df3610 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 6456220cdc9bb0ba35baf04c555060ea38d13bbc..1fb7bbd4d258190c4deb99f01ca2cc7d4939e5d3 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #define INCLUDE_ALGORITHM
+#define INCLUDE_MEMORY
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
index 9158af941d5f2c4e716e94cecef1f0f3afd7cf82..3162250bbdd6289742fa0bf0216f38de36086dc8 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 4a582ec9512e4fb4d8526aa79da009006ab22bb7..8adae8a6ec0d0f3e6a3da9040a089190909a50fe 100644 (file)
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index fe4981177bf02eac0e648be53e8f97d743692530..cfdf59ad3860960b8ada2188a07029007cb1eecf 100644 (file)
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "config.h"
 #define INCLUDE_ALGORITHM
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 9eb73a599339073edfda90974cdd7cfc38b89c76..03c65f0958c63406750cad4fd8d6fb554efba6f2 100644 (file)
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
index 1fb4fb36ed44d11baea2d3db8eedf9685be344e8..0efabcbb2580d32529aff0183ba4a903d80dfdde 100644 (file)
@@ -55,6 +55,7 @@ along with GCC; see the file COPYING3.  If not see
 */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"