From 76b6ddbfe234ed3d68dfaaadfc85a86119a3d0af Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Tue, 24 Nov 2015 11:46:10 +0000 Subject: [PATCH] destroy values as well as keys when removing them from hash maps gcc/ChangeLog: 2015-11-24 Trevor Saunders * hash-map-traits.h (simple_hashmap_traits ::remove): call destructors on values that are being removed. * mem-stats.h (hash_map): Pass type of values to simple_hashmap_traits. * tree-sra.c (sra_deinitialize): Remove work around for hash maps not destructing values. * genmatch.c (sinfo_hashmap_traits): Adjust. * tree-ssa-uncprop.c (val_ssa_equiv_hash_traits): Likewise. From-SVN: r230801 --- gcc/ChangeLog | 11 +++++++++++ gcc/genmatch.c | 3 ++- gcc/hash-map-traits.h | 32 +++++++++++++++++--------------- gcc/mem-stats.h | 3 ++- gcc/tree-sra.c | 6 ------ gcc/tree-ssa-uncprop.c | 3 ++- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cffa083cea4..452f724765f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2015-11-24 Trevor Saunders + + * hash-map-traits.h (simple_hashmap_traits ::remove): call + destructors on values that are being removed. + * mem-stats.h (hash_map): Pass type of values to + simple_hashmap_traits. + * tree-sra.c (sra_deinitialize): Remove work around for hash + maps not destructing values. + * genmatch.c (sinfo_hashmap_traits): Adjust. + * tree-ssa-uncprop.c (val_ssa_equiv_hash_traits): Likewise. + 2015-11-24 Richard Biener Kyrylo Tkachov diff --git a/gcc/genmatch.c b/gcc/genmatch.c index 3a20a48b497..76c8f1fa1e2 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -1397,7 +1397,8 @@ struct sinfo unsigned cnt; }; -struct sinfo_hashmap_traits : simple_hashmap_traits > +struct sinfo_hashmap_traits : simple_hashmap_traits, + sinfo *> { static inline hashval_t hash (const key_type &); static inline bool equal_keys (const key_type &, const key_type &); diff --git a/gcc/hash-map-traits.h b/gcc/hash-map-traits.h index 2225426e365..773ac1b3a9e 100644 --- a/gcc/hash-map-traits.h +++ b/gcc/hash-map-traits.h @@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see /* Implement hash_map traits for a key with hash traits H. Empty and deleted map entries are represented as empty and deleted keys. */ -template +template struct simple_hashmap_traits { typedef typename H::value_type key_type; @@ -41,56 +41,58 @@ struct simple_hashmap_traits template static inline void mark_deleted (T &); }; -template +template inline hashval_t -simple_hashmap_traits ::hash (const key_type &h) +simple_hashmap_traits ::hash (const key_type &h) { return H::hash (h); } -template +template inline bool -simple_hashmap_traits ::equal_keys (const key_type &k1, const key_type &k2) +simple_hashmap_traits ::equal_keys (const key_type &k1, + const key_type &k2) { return H::equal (k1, k2); } -template +template template inline void -simple_hashmap_traits ::remove (T &entry) +simple_hashmap_traits ::remove (T &entry) { H::remove (entry.m_key); + entry.m_value.~Value (); } -template +template template inline bool -simple_hashmap_traits ::is_empty (const T &entry) +simple_hashmap_traits ::is_empty (const T &entry) { return H::is_empty (entry.m_key); } -template +template template inline bool -simple_hashmap_traits ::is_deleted (const T &entry) +simple_hashmap_traits ::is_deleted (const T &entry) { return H::is_deleted (entry.m_key); } -template +template template inline void -simple_hashmap_traits ::mark_empty (T &entry) +simple_hashmap_traits ::mark_empty (T &entry) { H::mark_empty (entry.m_key); } -template +template template inline void -simple_hashmap_traits ::mark_deleted (T &entry) +simple_hashmap_traits ::mark_deleted (T &entry) { H::mark_deleted (entry.m_key); } diff --git a/gcc/mem-stats.h b/gcc/mem-stats.h index a6489b50068..2c68ca752eb 100644 --- a/gcc/mem-stats.h +++ b/gcc/mem-stats.h @@ -3,7 +3,8 @@ /* Forward declaration. */ template > > + typename Traits = simple_hashmap_traits, + Value> > class hash_map; #define LOCATION_LINE_EXTRA_SPACE 30 diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 2835c993588..c4fea5b0c4d 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -674,12 +674,6 @@ sra_deinitialize (void) assign_link_pool.release (); obstack_free (&name_obstack, NULL); - /* TODO: hash_map does not support traits that can release - value type of the hash_map. */ - for (hash_map >::iterator it = - base_access_vec->begin (); it != base_access_vec->end (); ++it) - (*it).second.release (); - delete base_access_vec; } diff --git a/gcc/tree-ssa-uncprop.c b/gcc/tree-ssa-uncprop.c index be6c209d7a4..23b4ca2a008 100644 --- a/gcc/tree-ssa-uncprop.c +++ b/gcc/tree-ssa-uncprop.c @@ -277,7 +277,8 @@ struct equiv_hash_elt /* Value to ssa name equivalence hashtable helpers. */ -struct val_ssa_equiv_hash_traits : simple_hashmap_traits +struct val_ssa_equiv_hash_traits : simple_hashmap_traits > { template static inline void remove (T &); }; -- 2.30.2