diff mbox series

[pushed,1/4] Use std::unique_ptr for optinfo_item

Message ID 20240829225813.2567570-1-dmalcolm@redhat.com
State New
Headers show
Series [pushed,1/4] Use std::unique_ptr for optinfo_item | expand

Commit Message

David Malcolm Aug. 29, 2024, 10:58 p.m. UTC
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.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Successfully built stage1 cc1 on all configs via config-list.mk.
Pushed to trunk as r15-3309-g464a3d2fe53362.

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>
---
 gcc/config/aarch64/aarch64.cc             |   1 +
 gcc/config/arm/arm.cc                     |   1 +
 gcc/config/i386/i386.cc                   |   1 +
 gcc/config/loongarch/loongarch.cc         |   1 +
 gcc/config/riscv/riscv-vector-costs.cc    |   1 +
 gcc/config/riscv/riscv.cc                 |   1 +
 gcc/config/rs6000/rs6000.cc               |   1 +
 gcc/dump-context.h                        |   7 +-
 gcc/dumpfile.cc                           | 156 +++++++++++-----------
 gcc/gimple-loop-interchange.cc            |   1 +
 gcc/gimple-loop-jam.cc                    |   1 +
 gcc/gimple-loop-versioning.cc             |   1 +
 gcc/graphite-dependences.cc               |   1 +
 gcc/graphite-isl-ast-to-gimple.cc         |   1 +
 gcc/graphite-optimize-isl.cc              |   1 +
 gcc/graphite-poly.cc                      |   1 +
 gcc/graphite-scop-detection.cc            |   1 +
 gcc/graphite-sese-to-poly.cc              |   1 +
 gcc/graphite.cc                           |   1 +
 gcc/opt-problem.cc                        |   1 +
 gcc/optinfo.cc                            |   8 +-
 gcc/optinfo.h                             |  11 +-
 gcc/sese.cc                               |   1 +
 gcc/targhooks.cc                          |   1 +
 gcc/testsuite/gcc.dg/plugin/dump_plugin.c |   1 +
 gcc/tree-data-ref.cc                      |   1 +
 gcc/tree-if-conv.cc                       |   1 +
 gcc/tree-loop-distribution.cc             |   1 +
 gcc/tree-parloops.cc                      |   1 +
 gcc/tree-predcom.cc                       |   1 +
 gcc/tree-ssa-live.cc                      |   1 +
 gcc/tree-ssa-loop-ivcanon.cc              |   1 +
 gcc/tree-ssa-loop-ivopts.cc               |   1 +
 gcc/tree-ssa-loop-prefetch.cc             |   1 +
 gcc/tree-ssa-loop-unswitch.cc             |   1 +
 gcc/tree-ssa-phiopt.cc                    |   1 +
 gcc/tree-ssa-threadbackward.cc            |   1 +
 gcc/tree-ssa-threadupdate.cc              |   1 +
 gcc/tree-vect-data-refs.cc                |   1 +
 gcc/tree-vect-generic.cc                  |   1 +
 gcc/tree-vect-loop-manip.cc               |   1 +
 gcc/tree-vect-loop.cc                     |   1 +
 gcc/tree-vect-patterns.cc                 |   1 +
 gcc/tree-vect-slp-patterns.cc             |   1 +
 gcc/tree-vect-slp.cc                      |   1 +
 gcc/tree-vect-stmts.cc                    |   1 +
 gcc/tree-vectorizer.cc                    |   1 +
 47 files changed, 137 insertions(+), 88 deletions(-)
diff mbox series

Patch

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index bfd7bcdef7cb..765189317be2 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -22,6 +22,7 @@ 
 
 #define INCLUDE_STRING
 #define INCLUDE_ALGORITHM
+#define INCLUDE_MEMORY
 #define INCLUDE_VECTOR
 #include "config.h"
 #include "system.h"
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 92cd168e6593..458e1af1fba4 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -23,6 +23,7 @@ 
 #define IN_TARGET_CODE 1
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #define INCLUDE_STRING
 #include "system.h"
 #include "coretypes.h"
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index f044826269ca..ece33f16ebc5 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -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
 
diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index c7a02103ef51..f956ee4b119b 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -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"
diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc
index a80e167597be..25570bd40040 100644
--- a/gcc/config/riscv/riscv-vector-costs.cc
+++ b/gcc/config/riscv/riscv-vector-costs.cc
@@ -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"
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 1f60d8f9711c..3f42b98914fe 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -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"
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index f2bd9edea8a1..9efd29b43f79 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -22,6 +22,7 @@ 
 #define IN_TARGET_CODE 1
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
diff --git a/gcc/dump-context.h b/gcc/dump-context.h
index b2aed2853a37..5992956380b1 100644
--- a/gcc/dump-context.h
+++ b/gcc/dump-context.h
@@ -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;
diff --git a/gcc/dumpfile.cc b/gcc/dumpfile.cc
index 6353c0857449..2971c69bb0a1 100644
--- a/gcc/dumpfile.cc
+++ b/gcc/dumpfile.cc
@@ -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.  */
diff --git a/gcc/gimple-loop-interchange.cc b/gcc/gimple-loop-interchange.cc
index b4228044a387..a4ea818bbdfd 100644
--- a/gcc/gimple-loop-interchange.cc
+++ b/gcc/gimple-loop-interchange.cc
@@ -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"
diff --git a/gcc/gimple-loop-jam.cc b/gcc/gimple-loop-jam.cc
index 306d5ceaef48..bf01e0ba6467 100644
--- a/gcc/gimple-loop-jam.cc
+++ b/gcc/gimple-loop-jam.cc
@@ -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"
diff --git a/gcc/gimple-loop-versioning.cc b/gcc/gimple-loop-versioning.cc
index adea207659be..107b00200247 100644
--- a/gcc/gimple-loop-versioning.cc
+++ b/gcc/gimple-loop-versioning.cc
@@ -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"
diff --git a/gcc/graphite-dependences.cc b/gcc/graphite-dependences.cc
index a35f71254f84..41e1114173bf 100644
--- a/gcc/graphite-dependences.cc
+++ b/gcc/graphite-dependences.cc
@@ -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"
 
diff --git a/gcc/graphite-isl-ast-to-gimple.cc b/gcc/graphite-isl-ast-to-gimple.cc
index a27402ba6b70..ff539b14045c 100644
--- a/gcc/graphite-isl-ast-to-gimple.cc
+++ b/gcc/graphite-isl-ast-to-gimple.cc
@@ -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"
 
diff --git a/gcc/graphite-optimize-isl.cc b/gcc/graphite-optimize-isl.cc
index 2222dd685425..ff3dd6b7ab63 100644
--- a/gcc/graphite-optimize-isl.cc
+++ b/gcc/graphite-optimize-isl.cc
@@ -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"
 
diff --git a/gcc/graphite-poly.cc b/gcc/graphite-poly.cc
index c78ff986c325..76aba03d6332 100644
--- a/gcc/graphite-poly.cc
+++ b/gcc/graphite-poly.cc
@@ -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"
 
diff --git a/gcc/graphite-scop-detection.cc b/gcc/graphite-scop-detection.cc
index 9e44f100a1df..de7c111118ba 100644
--- a/gcc/graphite-scop-detection.cc
+++ b/gcc/graphite-scop-detection.cc
@@ -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"
 
diff --git a/gcc/graphite-sese-to-poly.cc b/gcc/graphite-sese-to-poly.cc
index 5ce898505a30..1e7818a9ca3e 100644
--- a/gcc/graphite-sese-to-poly.cc
+++ b/gcc/graphite-sese-to-poly.cc
@@ -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"
 
diff --git a/gcc/graphite.cc b/gcc/graphite.cc
index 80e6a5da6b29..65b970f9444e 100644
--- a/gcc/graphite.cc
+++ b/gcc/graphite.cc
@@ -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"
diff --git a/gcc/opt-problem.cc b/gcc/opt-problem.cc
index f40f48196dea..d76ddaf57adf 100644
--- a/gcc/opt-problem.cc
+++ b/gcc/opt-problem.cc
@@ -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"
diff --git a/gcc/optinfo.cc b/gcc/optinfo.cc
index 7a8256171744..48a270cbfea8 100644
--- a/gcc/optinfo.cc
+++ b/gcc/optinfo.cc
@@ -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);
diff --git a/gcc/optinfo.h b/gcc/optinfo.h
index 986ef75756fc..db92294f3cab 100644
--- a/gcc/optinfo.h
+++ b/gcc/optinfo.h
@@ -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;
 
diff --git a/gcc/sese.cc b/gcc/sese.cc
index e5c460571c55..e9b17fafa011 100644
--- a/gcc/sese.cc
+++ b/gcc/sese.cc
@@ -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"
diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc
index 793932a77c60..dc040df9fcd1 100644
--- a/gcc/targhooks.cc
+++ b/gcc/targhooks.cc
@@ -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"
diff --git a/gcc/testsuite/gcc.dg/plugin/dump_plugin.c b/gcc/testsuite/gcc.dg/plugin/dump_plugin.c
index 12573d66af21..fc76d69adb1d 100644
--- a/gcc/testsuite/gcc.dg/plugin/dump_plugin.c
+++ b/gcc/testsuite/gcc.dg/plugin/dump_plugin.c
@@ -1,5 +1,6 @@ 
 /* Plugin for testing dumpfile.c.  */
 
+#define INCLUDE_MEMORY
 #include "gcc-plugin.h"
 #include "config.h"
 #include "system.h"
diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index bd61069b6316..48798f458b80 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -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"
diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index 57992b6decaf..25248c138083 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -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"
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index f87393ee94d6..86e39e4575d9 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -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"
diff --git a/gcc/tree-parloops.cc b/gcc/tree-parloops.cc
index 888a834faf91..f4468658732b 100644
--- a/gcc/tree-parloops.cc
+++ b/gcc/tree-parloops.cc
@@ -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"
diff --git a/gcc/tree-predcom.cc b/gcc/tree-predcom.cc
index 9844fee1e974..eed878b8f54b 100644
--- a/gcc/tree-predcom.cc
+++ b/gcc/tree-predcom.cc
@@ -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"
diff --git a/gcc/tree-ssa-live.cc b/gcc/tree-ssa-live.cc
index 60dfc05dcd94..0739faa022ef 100644
--- a/gcc/tree-ssa-live.cc
+++ b/gcc/tree-ssa-live.cc
@@ -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"
diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc
index 5ef24a919176..a8d25ad0efc4 100644
--- a/gcc/tree-ssa-loop-ivcanon.cc
+++ b/gcc/tree-ssa-loop-ivcanon.cc
@@ -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"
diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc
index c3218a3e8eed..dfe1b2541562 100644
--- a/gcc/tree-ssa-loop-ivopts.cc
+++ b/gcc/tree-ssa-loop-ivopts.cc
@@ -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"
diff --git a/gcc/tree-ssa-loop-prefetch.cc b/gcc/tree-ssa-loop-prefetch.cc
index bb5d5dec7795..52ea3bad07eb 100644
--- a/gcc/tree-ssa-loop-prefetch.cc
+++ b/gcc/tree-ssa-loop-prefetch.cc
@@ -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"
diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc
index 14b0df1aefe7..7601d91e8070 100644
--- a/gcc/tree-ssa-loop-unswitch.cc
+++ b/gcc/tree-ssa-loop-unswitch.cc
@@ -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"
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index f05ca727503b..3754fc05c8f2 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -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"
diff --git a/gcc/tree-ssa-threadbackward.cc b/gcc/tree-ssa-threadbackward.cc
index ea8d7b882d08..4bc72ec23755 100644
--- a/gcc/tree-ssa-threadbackward.cc
+++ b/gcc/tree-ssa-threadbackward.cc
@@ -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"
diff --git a/gcc/tree-ssa-threadupdate.cc b/gcc/tree-ssa-threadupdate.cc
index fa61ba9512b7..c88cc1d6aac9 100644
--- a/gcc/tree-ssa-threadupdate.cc
+++ b/gcc/tree-ssa-threadupdate.cc
@@ -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"
diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index 5b0d548f8479..fe7fdec4ba0d 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -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"
diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc
index 4bcab71c1683..3041fb8fcf23 100644
--- a/gcc/tree-vect-generic.cc
+++ b/gcc/tree-vect-generic.cc
@@ -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"
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 57dbcbe862cd..cb7843f6f72e 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -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"
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 6456220cdc9b..1fb7bbd4d258 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -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"
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index f52de2b6972d..bbb86fb4677d 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -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"
diff --git a/gcc/tree-vect-slp-patterns.cc b/gcc/tree-vect-slp-patterns.cc
index 4a582ec9512e..8adae8a6ec0d 100644
--- a/gcc/tree-vect-slp-patterns.cc
+++ b/gcc/tree-vect-slp-patterns.cc
@@ -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"
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 43ecd2689701..4e84dc778761 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -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"
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 385e63163c24..6333d8e30ccd 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -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"
diff --git a/gcc/tree-vectorizer.cc b/gcc/tree-vectorizer.cc
index 1fb4fb36ed44..0efabcbb2580 100644
--- a/gcc/tree-vectorizer.cc
+++ b/gcc/tree-vectorizer.cc
@@ -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"