diff gcc/ggc.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
line wrap: on
line diff
--- a/gcc/ggc.h	Sun Aug 21 07:07:55 2011 +0900
+++ b/gcc/ggc.h	Fri Oct 27 22:46:09 2017 +0900
@@ -1,7 +1,6 @@
 /* Garbage collection for the GNU compiler.
 
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007,
-   2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1998-2017 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -21,20 +20,13 @@
 
 #ifndef GCC_GGC_H
 #define GCC_GGC_H
-#include "statistics.h"
 
 /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with
    an external gc library that might be linked in.  */
 
-/* Constants for general use.  */
-extern const char empty_string[];	/* empty string */
-
 /* Internal functions and data structures used by the GTY
    machinery, including the generated gt*.[hc] files.  */
 
-/* The first parameter is a pointer to a pointer, the second a cookie.  */
-typedef void (*gt_pointer_operator) (void *, void *);
-
 #include "gtype-desc.h"
 
 /* One of these applies its third parameter (with cookie in the fourth
@@ -52,13 +44,15 @@
 				   void *);
 
 /* Used by the gt_pch_n_* routines.  Register an object in the hash table.  */
-extern int gt_pch_note_object (void *, void *, gt_note_pointers,
-			       enum gt_types_enum);
+extern int gt_pch_note_object (void *, void *, gt_note_pointers);
 
 /* Used by the gt_pch_n_* routines.  Register that an object has a reorder
    function.  */
 extern void gt_pch_note_reorder (void *, void *, gt_handle_reorder);
 
+/* generated function to clear caches in gc memory.  */
+extern void gt_clear_caches ();
+
 /* Mark the object in the first parameter and anything it points to.  */
 typedef void (*gt_pointer_walker) (void *);
 
@@ -75,23 +69,8 @@
 /* Pointers to arrays of ggc_root_tab, terminated by NULL.  */
 extern const struct ggc_root_tab * const gt_ggc_rtab[];
 extern const struct ggc_root_tab * const gt_ggc_deletable_rtab[];
-extern const struct ggc_root_tab * const gt_pch_cache_rtab[];
 extern const struct ggc_root_tab * const gt_pch_scalar_rtab[];
 
-/* Structure for hash table cache marking.  */
-struct htab;
-struct ggc_cache_tab {
-  struct htab * *base;
-  size_t nelt;
-  size_t stride;
-  gt_pointer_walker cb;
-  gt_pointer_walker pchw;
-  int (*marked_p) (const void *);
-};
-#define LAST_GGC_CACHE_TAB { NULL, 0, 0, NULL, NULL, NULL }
-/* Pointers to arrays of ggc_cache_tab, terminated by NULL.  */
-extern const struct ggc_cache_tab * const gt_ggc_cache_rtab[];
-
 /* If EXPR is not NULL and previously unmarked, mark it and evaluate
    to true.  Otherwise evaluate to false.  */
 #define ggc_test_and_set_mark(EXPR) \
@@ -122,8 +101,6 @@
 
 /* End of GTY machinery API.  */
 
-struct alloc_zone;
-
 /* Initialize the string pool.  */
 extern void init_stringpool (void);
 
@@ -143,104 +120,136 @@
 /* Allocation.  */
 
 /* The internal primitive.  */
-extern void *ggc_internal_alloc_stat (size_t MEM_STAT_DECL);
-
-#define ggc_internal_alloc(s) ggc_internal_alloc_stat (s MEM_STAT_INFO)
+extern void *ggc_internal_alloc (size_t, void (*)(void *), size_t,
+				 size_t CXX_MEM_STAT_INFO)
+     ATTRIBUTE_MALLOC;
 
-/* Allocate an object of the specified type and size.  */
-extern void *ggc_alloc_typed_stat (enum gt_types_enum, size_t MEM_STAT_DECL);
+inline void *
+ggc_internal_alloc (size_t s CXX_MEM_STAT_INFO)
+{
+  return ggc_internal_alloc (s, NULL, 0, 1 PASS_MEM_STAT);
+}
 
-#define ggc_alloc_typed(s, z) ggc_alloc_typed_stat (s, z MEM_STAT_INFO)
+extern size_t ggc_round_alloc_size (size_t requested_size);
 
 /* Allocates cleared memory.  */
-extern void *ggc_internal_cleared_alloc_stat (size_t MEM_STAT_DECL);
+extern void *ggc_internal_cleared_alloc (size_t, void (*)(void *),
+					 size_t, size_t
+					 CXX_MEM_STAT_INFO) ATTRIBUTE_MALLOC;
+
+inline void *
+ggc_internal_cleared_alloc (size_t s CXX_MEM_STAT_INFO)
+{
+  return ggc_internal_cleared_alloc (s, NULL, 0, 1 PASS_MEM_STAT);
+}
 
 /* Resize a block.  */
-extern void *ggc_realloc_stat (void *, size_t MEM_STAT_DECL);
+extern void *ggc_realloc (void *, size_t CXX_MEM_STAT_INFO);
 
 /* Free a block.  To be used when known for certain it's not reachable.  */
 extern void ggc_free (void *);
 
-extern void ggc_record_overhead (size_t, size_t, void * MEM_STAT_DECL);
-extern void ggc_free_overhead (void *);
-extern void ggc_prune_overhead_list (void);
-
 extern void dump_ggc_loc_statistics (bool);
 
-/* Reallocators.  */
+/* Reallocator.  */
 #define GGC_RESIZEVEC(T, P, N) \
-    ((T *) ggc_realloc_stat ((P), (N) * sizeof (T) MEM_STAT_INFO))
+    ((T *) ggc_realloc ((P), (N) * sizeof (T) MEM_STAT_INFO))
 
-#define GGC_RESIZEVAR(T, P, N)                          \
-    ((T *) ggc_realloc_stat ((P), (N) MEM_STAT_INFO))
-
-static inline void *
-ggc_internal_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL)
+template<typename T>
+void
+finalize (void *p)
 {
-    return ggc_internal_alloc_stat (c * s PASS_MEM_STAT);
+  static_cast<T *> (p)->~T ();
 }
 
-static inline void *
-ggc_internal_cleared_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL)
+template<typename T>
+inline bool
+need_finalization_p ()
 {
-    return ggc_internal_cleared_alloc_stat (c * s PASS_MEM_STAT);
+#if GCC_VERSION >= 4003
+  return !__has_trivial_destructor (T);
+#else
+  return true;
+#endif
+}
+
+template<typename T>
+inline T *
+ggc_alloc (ALONE_CXX_MEM_STAT_INFO)
+{
+  if (need_finalization_p<T> ())
+    return static_cast<T *> (ggc_internal_alloc (sizeof (T), finalize<T>, 0, 1
+						 PASS_MEM_STAT));
+  else
+    return static_cast<T *> (ggc_internal_alloc (sizeof (T), NULL, 0, 1
+						 PASS_MEM_STAT));
 }
 
-#define ggc_internal_cleared_vec_alloc(s, c) \
-    (ggc_internal_cleared_vec_alloc_stat ((s), (c) MEM_STAT_INFO))
-
-static inline void *
-ggc_alloc_atomic_stat (size_t s MEM_STAT_DECL)
+template<typename T>
+inline T *
+ggc_cleared_alloc (ALONE_CXX_MEM_STAT_INFO)
 {
-    return ggc_internal_alloc_stat (s PASS_MEM_STAT);
+  if (need_finalization_p<T> ())
+    return static_cast<T *> (ggc_internal_cleared_alloc (sizeof (T),
+							 finalize<T>, 0, 1
+							 PASS_MEM_STAT));
+  else
+    return static_cast<T *> (ggc_internal_cleared_alloc (sizeof (T), NULL, 0, 1
+							 PASS_MEM_STAT));
 }
 
-#define ggc_alloc_atomic(S)  (ggc_alloc_atomic_stat ((S) MEM_STAT_INFO))
-
-#define ggc_alloc_cleared_atomic(S)             \
-    (ggc_internal_cleared_alloc_stat ((S) MEM_STAT_INFO))
-
-extern void * ggc_cleared_alloc_htab_ignore_args (size_t, size_t);
-
-extern void * ggc_cleared_alloc_ptr_array_two_args (size_t, size_t);
+template<typename T>
+inline T *
+ggc_vec_alloc (size_t c CXX_MEM_STAT_INFO)
+{
+  if (need_finalization_p<T> ())
+    return static_cast<T *> (ggc_internal_alloc (c * sizeof (T), finalize<T>,
+						 sizeof (T), c PASS_MEM_STAT));
+  else
+    return static_cast<T *> (ggc_internal_alloc (c * sizeof (T), NULL, 0, 0
+						 PASS_MEM_STAT));
+}
 
-#define htab_create_ggc(SIZE, HASH, EQ, DEL) \
-  htab_create_typed_alloc (SIZE, HASH, EQ, DEL,	\
-			   ggc_cleared_alloc_htab_ignore_args,		\
-			   ggc_cleared_alloc_ptr_array_two_args,	\
-			   ggc_free)
+template<typename T>
+inline T *
+ggc_cleared_vec_alloc (size_t c CXX_MEM_STAT_INFO)
+{
+  if (need_finalization_p<T> ())
+    return static_cast<T *> (ggc_internal_cleared_alloc (c * sizeof (T),
+							 finalize<T>,
+							 sizeof (T), c
+							 PASS_MEM_STAT));
+  else
+    return static_cast<T *> (ggc_internal_cleared_alloc (c * sizeof (T), NULL,
+							 0, 0 PASS_MEM_STAT));
+}
 
-#define splay_tree_new_ggc(COMPARE, ALLOC_TREE, ALLOC_NODE)		     \
-  splay_tree_new_typed_alloc (COMPARE, NULL, NULL, &ALLOC_TREE, &ALLOC_NODE, \
-			      &ggc_splay_dont_free, NULL)
-
-extern void *ggc_splay_alloc (enum gt_types_enum, int, void *);
-
-extern void ggc_splay_dont_free (void *, void *);
+inline void *
+ggc_alloc_atomic (size_t s CXX_MEM_STAT_INFO)
+{
+    return ggc_internal_alloc (s PASS_MEM_STAT);
+}
 
 /* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS.
    If LENGTH is -1, then CONTENTS is assumed to be a
    null-terminated string and the memory sized accordingly.  */
-extern const char *ggc_alloc_string_stat (const char *contents, int length
-                                          MEM_STAT_DECL);
-
-#define ggc_alloc_string(c, l) ggc_alloc_string_stat (c, l MEM_STAT_INFO)
+extern const char *ggc_alloc_string (const char *contents, int length
+                                     CXX_MEM_STAT_INFO);
 
 /* Make a copy of S, in GC-able memory.  */
-#define ggc_strdup(S) ggc_alloc_string_stat ((S), -1 MEM_STAT_INFO)
+#define ggc_strdup(S) ggc_alloc_string ((S), -1 MEM_STAT_INFO)
 
 /* Invoke the collector.  Garbage collection occurs only when this
    function is called, not during allocations.  */
 extern void ggc_collect	(void);
 
+/* Assume that all GGC memory is reachable and grow the limits for next collection. */
+extern void ggc_grow (void);
+
 /* Register an additional root table.  This can be useful for some
    plugins.  Does nothing if the passed pointer is NULL. */
 extern void ggc_register_root_tab (const struct ggc_root_tab *);
 
-/* Register an additional cache table.  This can be useful for some
-   plugins.  Does nothing if the passed pointer is NULL. */
-extern void ggc_register_cache_tab (const struct ggc_cache_tab *);
-
 /* Read objects previously saved with gt_pch_save from F.  */
 extern void gt_pch_restore (FILE *f);
 
@@ -254,104 +263,60 @@
 /* Heuristics.  */
 extern void init_ggc_heuristics (void);
 
-/* Zone collection.  */
-
-/* For regular rtl allocations.  */
-extern struct alloc_zone rtl_zone;
-
-/* For regular tree allocations.  */
-extern struct alloc_zone tree_zone;
-
-/* For IDENTIFIER_NODE allocations.  */
-extern struct alloc_zone tree_id_zone;
+#define ggc_alloc_rtvec_sized(NELT)				\
+  (rtvec_def *) ggc_internal_alloc (sizeof (struct rtvec_def)		\
+		       + ((NELT) - 1) * sizeof (rtx))		\
 
-#define ggc_alloc_rtvec_sized(NELT)                                     \
-    (ggc_alloc_zone_vec_rtvec_def (sizeof (rtx),                        \
-                                   sizeof (struct rtvec_def) + ((NELT) - 1), \
-                                   &rtl_zone))
-
-#if defined (GGC_ZONE) && !defined (GENERATOR_FILE)
+/* Memory statistics passing versions of some allocators.  Too few of them to
+   make gengtype produce them, so just define the needed ones here.  */
+inline struct rtx_def *
+ggc_alloc_rtx_def_stat (size_t s CXX_MEM_STAT_INFO)
+{
+  return (struct rtx_def *) ggc_internal_alloc (s PASS_MEM_STAT);
+}
 
-/* Allocate an object into the specified allocation zone.  */
-extern void *ggc_internal_alloc_zone_stat (size_t,
-					  struct alloc_zone * MEM_STAT_DECL);
+inline union tree_node *
+ggc_alloc_tree_node_stat (size_t s CXX_MEM_STAT_INFO)
+{
+  return (union tree_node *) ggc_internal_alloc (s PASS_MEM_STAT);
+}
 
-extern void *ggc_internal_cleared_alloc_zone_stat (size_t,
-					  struct alloc_zone * MEM_STAT_DECL);
-
-static inline void *
-ggc_internal_zone_alloc_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL)
+inline union tree_node *
+ggc_alloc_cleared_tree_node_stat (size_t s CXX_MEM_STAT_INFO)
 {
-    return ggc_internal_alloc_zone_stat (s, z PASS_MEM_STAT);
+  return (union tree_node *) ggc_internal_cleared_alloc (s PASS_MEM_STAT);
 }
 
-static inline void *
-ggc_internal_zone_cleared_alloc_stat (struct alloc_zone * z, size_t s
-                                      MEM_STAT_DECL)
+inline gimple *
+ggc_alloc_cleared_gimple_statement_stat (size_t s CXX_MEM_STAT_INFO)
 {
-    return ggc_internal_cleared_alloc_zone_stat (s, z PASS_MEM_STAT);
+  return (gimple *) ggc_internal_cleared_alloc (s PASS_MEM_STAT);
 }
 
-static inline void *
-ggc_internal_zone_vec_alloc_stat (struct alloc_zone * z, size_t s, size_t n
-                                  MEM_STAT_DECL)
+inline void
+gt_ggc_mx (const char *s)
 {
-    return ggc_internal_alloc_zone_stat (s * n, z PASS_MEM_STAT);
+  ggc_test_and_set_mark (const_cast<char *> (s));
 }
 
-
-#else
-
-static inline void *
-ggc_internal_zone_alloc_stat (struct alloc_zone * z ATTRIBUTE_UNUSED,
-                              size_t s MEM_STAT_DECL)
+inline void
+gt_pch_nx (const char *)
 {
-    return ggc_internal_alloc_stat (s PASS_MEM_STAT);
 }
 
-static inline void *
-ggc_internal_zone_cleared_alloc_stat (struct alloc_zone * z ATTRIBUTE_UNUSED,
-                                      size_t s MEM_STAT_DECL)
+inline void
+gt_ggc_mx (int)
 {
-    return ggc_internal_cleared_alloc_stat (s PASS_MEM_STAT);
 }
 
-static inline void *
-ggc_internal_zone_vec_alloc_stat (struct alloc_zone * z ATTRIBUTE_UNUSED,
-                                  size_t s, size_t n MEM_STAT_DECL)
+inline void
+gt_pch_nx (int)
 {
-    return ggc_internal_vec_alloc_stat (s, n PASS_MEM_STAT);
+}
+
+inline void
+gt_pch_nx (unsigned int)
+{
 }
 
 #endif
-
-/* Memory statistics passing versions of some allocators.  Too few of them to
-   make gengtype produce them, so just define the needed ones here.  */
-static inline struct rtx_def *
-ggc_alloc_zone_rtx_def_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL)
-{
-  return (struct rtx_def *) ggc_internal_zone_alloc_stat (z, s PASS_MEM_STAT);
-}
-
-static inline union tree_node *
-ggc_alloc_zone_tree_node_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL)
-{
-  return (union tree_node *) ggc_internal_zone_alloc_stat (z, s PASS_MEM_STAT);
-}
-
-static inline union tree_node *
-ggc_alloc_zone_cleared_tree_node_stat (struct alloc_zone * z, size_t s
-                                       MEM_STAT_DECL)
-{
-  return (union tree_node *)
-    ggc_internal_zone_cleared_alloc_stat (z, s PASS_MEM_STAT);
-}
-
-static inline union gimple_statement_d *
-ggc_alloc_cleared_gimple_statement_d_stat (size_t s MEM_STAT_DECL)
-{
-  return (union gimple_statement_d *)
-    ggc_internal_cleared_alloc_stat (s PASS_MEM_STAT);
-}
-
-#endif