diff options
author | Jason Merrill <jason@redhat.com> | 2017-11-14 11:02:57 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2017-11-14 11:02:57 -0500 |
commit | 21faa10189001f70361ca13133b01a815d2b342c (patch) | |
tree | 931e4ec35ba245c1ce72ae664a03ce5b25f38cb6 /gcc/cp | |
parent | 55518e0f5df1f1693e060ddd595a86ac816ec291 (diff) | |
download | gcc-21faa10189001f70361ca13133b01a815d2b342c.zip gcc-21faa10189001f70361ca13133b01a815d2b342c.tar.gz gcc-21faa10189001f70361ca13133b01a815d2b342c.tar.bz2 |
Support GTY((cache)) on hash_map.
gcc/
* hash-traits.h (ggc_remove): Add ggc_maybe_mx member function.
(ggc_cache_remove): Override it instead of ggc_mx.
* hash-table.h (gt_ggc_mx): Call it instead of ggc_mx.
(gt_cleare_cache): Call ggc_mx instead of gt_ggc_mx.
* hash-map-traits.h (simple_hashmap_traits): Add maybe_mx member.
(simple_cache_map_traits): Override maybe_mx.
* hash-map.h (hash_entry): Add ggc_maybe_mx and keep_cache_entry.
(hash_map): Friend gt_cleare_cache.
(gt_cleare_cache): New.
* tree.h (tree_cache_traits): New hash_map traits class.
(tree_cache_map): New typedef.
gcc/cp/
* decl.c (decomp_type_table): Use tree_cache_map.
* init.c (nsdmi_inst): Likewise.
* pt.c (defarg_ints): Likewise.
* cp-objcp-common.c (cp_get_debug_type): Likewise.
From-SVN: r254731
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/cp-objcp-common.c | 61 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 1 | ||||
-rw-r--r-- | gcc/cp/decl.c | 5 | ||||
-rw-r--r-- | gcc/cp/init.c | 4 | ||||
-rw-r--r-- | gcc/cp/pt.c | 4 |
6 files changed, 35 insertions, 48 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ce0c874..8ba5b78 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2017-11-14 Jason Merrill <jason@redhat.com> + + Use GTY((cache)) on some hash tables. + * decl.c (decomp_type_table): Use tree_cache_map. + * init.c (nsdmi_inst): Likewise. + * pt.c (defarg_ints): Likewise. + * cp-objcp-common.c (cp_get_debug_type): Likewise. + 2017-11-13 Jason Merrill <jason@redhat.com> Capture adjustments for P0588R1. diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index e051d66..9a398e0 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -122,19 +122,7 @@ cxx_types_compatible_p (tree x, tree y) return same_type_ignoring_top_level_qualifiers_p (x, y); } -struct debug_type_hasher : ggc_cache_ptr_hash<tree_map> -{ - static hashval_t hash (tree_map *m) { return tree_map_hash (m); } - static bool equal (tree_map *a, tree_map *b) { return tree_map_eq (a, b); } - - static int - keep_cache_entry (tree_map *&e) - { - return ggc_marked_p (e->base.from); - } -}; - -static GTY((cache)) hash_table<debug_type_hasher> *debug_type_hash; +static GTY((cache)) tree_cache_map *debug_type_map; /* Return a type to use in the debug info instead of TYPE, or NULL_TREE to keep TYPE. */ @@ -142,38 +130,29 @@ static GTY((cache)) hash_table<debug_type_hasher> *debug_type_hash; tree cp_get_debug_type (const_tree type) { + tree dtype = NULL_TREE; + if (TYPE_PTRMEMFUNC_P (type) && !typedef_variant_p (type)) + dtype = build_offset_type (TYPE_PTRMEMFUNC_OBJECT_TYPE (type), + TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))); + + /* We cannot simply return the debug type here because the function uses + the type canonicalization hashtable, which is GC-ed, so its behavior + depends on the actual collection points. Since we are building these + types on the fly for the debug info only, they would not be attached + to any GC root and always be swept, so we would make the contents of + the debug info depend on the collection points. */ + if (dtype) { - if (debug_type_hash == NULL) - debug_type_hash = hash_table<debug_type_hasher>::create_ggc (512); - - /* We cannot simply use build_offset_type here because the function uses - the type canonicalization hashtable, which is GC-ed, so its behavior - depends on the actual collection points. Since we are building these - types on the fly for the debug info only, they would not be attached - to any GC root and always be swept, so we would make the contents of - the debug info depend on the collection points. */ - struct tree_map in, *h, **slot; - - in.base.from = CONST_CAST_TREE (type); - in.hash = htab_hash_pointer (type); - slot = debug_type_hash->find_slot_with_hash (&in, in.hash, INSERT); - if (*slot) - return (*slot)->to; - - tree t = build_offset_type (TYPE_PTRMEMFUNC_OBJECT_TYPE (type), - TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))); - - h = ggc_alloc<tree_map> (); - h->base.from = CONST_CAST_TREE (type); - h->hash = htab_hash_pointer (type); - h->to = t; - *slot = h; - - return t; + tree ktype = CONST_CAST_TREE (type); + if (debug_type_map == NULL) + debug_type_map = tree_cache_map::create_ggc (512); + else if (tree *slot = debug_type_map->get (ktype)) + return *slot; + debug_type_map->put (ktype, dtype); } - return NULL_TREE; + return dtype; } /* Return -1 if dwarf ATTR shouldn't be added for DECL, or the attribute diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index b994206..6051348 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5124,7 +5124,6 @@ extern GTY(()) vec<tree, va_gc> *static_decls; /* An array of vtable-needing types that have no key function, or have an emitted key function. */ extern GTY(()) vec<tree, va_gc> *keyed_classes; - /* Here's where we control how name mangling takes place. */ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 2e356a0..c4eb28d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7283,12 +7283,13 @@ get_tuple_decomp_init (tree decl, unsigned i) /* It's impossible to recover the decltype of a tuple decomposition variable based on the actual type of the variable, so store it in a hash table. */ -static GTY(()) hash_map<tree,tree> *decomp_type_table; + +static GTY((cache)) tree_cache_map *decomp_type_table; static void store_decomp_type (tree v, tree t) { if (!decomp_type_table) - decomp_type_table = hash_map<tree,tree>::create_ggc (13); + decomp_type_table = tree_cache_map::create_ggc (13); decomp_type_table->put (v, t); } diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 1084ab1..c76460d 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -535,7 +535,7 @@ perform_target_ctor (tree init) /* Return the non-static data initializer for FIELD_DECL MEMBER. */ -static GTY(()) hash_map<tree, tree> *nsdmi_inst; +static GTY((cache)) tree_cache_map *nsdmi_inst; tree get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) @@ -590,7 +590,7 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) if (init != error_mark_node) { if (!nsdmi_inst) - nsdmi_inst = hash_map<tree,tree>::create_ggc (37); + nsdmi_inst = tree_cache_map::create_ggc (37); nsdmi_inst->put (member, init); } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4ca5974..562b927 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -12014,7 +12014,7 @@ tsubst_aggr_type (tree t, } } -static GTY(()) hash_map<tree, tree> *defarg_inst; +static GTY((cache)) tree_cache_map *defarg_inst; /* Substitute into the default argument ARG (a default argument for FN), which has the indicated TYPE. */ @@ -12101,7 +12101,7 @@ tsubst_default_argument (tree fn, int parmnum, tree type, tree arg, if (arg != error_mark_node && !cp_unevaluated_operand) { if (!defarg_inst) - defarg_inst = hash_map<tree,tree>::create_ggc (37); + defarg_inst = tree_cache_map::create_ggc (37); defarg_inst->put (parm, arg); } |