]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
hash-table.h: support non-zero empty values in empty_slow (v2)
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 11 Dec 2019 02:18:23 +0000 (21:18 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 14 Jan 2020 17:44:04 +0000 (12:44 -0500)
gcc/cp/ChangeLog:
* cp-gimplify.c (source_location_table_entry_hash::empty_zero_p):
New static constant.
* cp-tree.h (named_decl_hash::empty_zero_p): Likewise.
(struct named_label_hash::empty_zero_p): Likewise.
* decl2.c (mangled_decl_hash::empty_zero_p): Likewise.

gcc/ChangeLog:
* attribs.c (excl_hash_traits::empty_zero_p): New static constant.
* gcov.c (function_start_pair_hash::empty_zero_p): Likewise.
* graphite.c (struct sese_scev_hash::empty_zero_p): Likewise.
* hash-map-tests.c (selftest::test_nonzero_empty_key): New selftest.
(selftest::hash_map_tests_c_tests): Call it.
* hash-map-traits.h (simple_hashmap_traits::empty_zero_p):
New static constant, using the value of = H::empty_zero_p.
(unbounded_hashmap_traits::empty_zero_p): Likewise, using the value
from default_hash_traits <Value>.
* hash-map.h (hash_map::empty_zero_p): Likewise, using the value
from Traits.
* hash-set-tests.c (value_hash_traits::empty_zero_p): Likewise.
* hash-table.h (hash_table::alloc_entries): Guard the loop of
calls to mark_empty with !Descriptor::empty_zero_p.
(hash_table::empty_slow): Conditionalize the memset call with a
check that Descriptor::empty_zero_p; otherwise, loop through the
entries calling mark_empty on them.
* hash-traits.h (int_hash::empty_zero_p): New static constant.
(pointer_hash::empty_zero_p): Likewise.
(pair_hash::empty_zero_p): Likewise.
* ipa-devirt.c (default_hash_traits <type_pair>::empty_zero_p):
Likewise.
* ipa-prop.c (ipa_bit_ggc_hash_traits::empty_zero_p): Likewise.
(ipa_vr_ggc_hash_traits::empty_zero_p): Likewise.
* profile.c (location_triplet_hash::empty_zero_p): Likewise.
* sanopt.c (sanopt_tree_triplet_hash::empty_zero_p): Likewise.
(sanopt_tree_couple_hash::empty_zero_p): Likewise.
* tree-hasher.h (int_tree_hasher::empty_zero_p): Likewise.
* tree-ssa-sccvn.c (vn_ssa_aux_hasher::empty_zero_p): Likewise.
* tree-vect-slp.c (bst_traits::empty_zero_p): Likewise.
* tree-vectorizer.h
(default_hash_traits<scalar_cond_masked_key>::empty_zero_p):
Likewise.

22 files changed:
gcc/ChangeLog
gcc/attribs.c
gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/cp/cp-tree.h
gcc/cp/decl2.c
gcc/gcov.c
gcc/graphite.c
gcc/hash-map-tests.c
gcc/hash-map-traits.h
gcc/hash-map.h
gcc/hash-set-tests.c
gcc/hash-table.h
gcc/hash-traits.h
gcc/ipa-devirt.c
gcc/ipa-prop.c
gcc/profile.c
gcc/sanopt.c
gcc/tree-hasher.h
gcc/tree-ssa-sccvn.c
gcc/tree-vect-slp.c
gcc/tree-vectorizer.h

index f3301b164644911b0d5dbeff54580252fb07614f..4f586fee17c4a10509a46340fe8e8dbf851e51b6 100644 (file)
@@ -1,3 +1,39 @@
+2020-01-14  David Malcolm  <dmalcolm@redhat.com>
+
+       * attribs.c (excl_hash_traits::empty_zero_p): New static constant.
+       * gcov.c (function_start_pair_hash::empty_zero_p): Likewise.
+       * graphite.c (struct sese_scev_hash::empty_zero_p): Likewise.
+       * hash-map-tests.c (selftest::test_nonzero_empty_key): New selftest.
+       (selftest::hash_map_tests_c_tests): Call it.
+       * hash-map-traits.h (simple_hashmap_traits::empty_zero_p):
+       New static constant, using the value of = H::empty_zero_p.
+       (unbounded_hashmap_traits::empty_zero_p): Likewise, using the value
+       from default_hash_traits <Value>.
+       * hash-map.h (hash_map::empty_zero_p): Likewise, using the value
+       from Traits.
+       * hash-set-tests.c (value_hash_traits::empty_zero_p): Likewise.
+       * hash-table.h (hash_table::alloc_entries): Guard the loop of
+       calls to mark_empty with !Descriptor::empty_zero_p.
+       (hash_table::empty_slow): Conditionalize the memset call with a
+       check that Descriptor::empty_zero_p; otherwise, loop through the
+       entries calling mark_empty on them.
+       * hash-traits.h (int_hash::empty_zero_p): New static constant.
+       (pointer_hash::empty_zero_p): Likewise.
+       (pair_hash::empty_zero_p): Likewise.
+       * ipa-devirt.c (default_hash_traits <type_pair>::empty_zero_p):
+       Likewise.
+       * ipa-prop.c (ipa_bit_ggc_hash_traits::empty_zero_p): Likewise.
+       (ipa_vr_ggc_hash_traits::empty_zero_p): Likewise.
+       * profile.c (location_triplet_hash::empty_zero_p): Likewise.
+       * sanopt.c (sanopt_tree_triplet_hash::empty_zero_p): Likewise.
+       (sanopt_tree_couple_hash::empty_zero_p): Likewise.
+       * tree-hasher.h (int_tree_hasher::empty_zero_p): Likewise.
+       * tree-ssa-sccvn.c (vn_ssa_aux_hasher::empty_zero_p): Likewise.
+       * tree-vect-slp.c (bst_traits::empty_zero_p): Likewise.
+       * tree-vectorizer.h
+       (default_hash_traits<scalar_cond_masked_key>::empty_zero_p):
+       Likewise.
+
 2020-01-14  Kewen Lin  <linkw@gcc.gnu.org>
 
        * cfgloopanal.c (average_num_loop_insns): Free bbs when early return,
index ca89443eb3edf63971c737f8e123a3de379ec1f8..c66d4ae2c066652239c4f3fddc6362df87ba6c75 100644 (file)
@@ -2048,6 +2048,8 @@ struct excl_hash_traits: typed_noop_remove<excl_pair>
     x = value_type (NULL, NULL);
   }
 
+  static const bool empty_zero_p = false;
+
   static void mark_empty (value_type &x)
   {
     x = value_type ("", "");
index 3fd35b437b43a020d8f95577a03fdff4f5d86663..004ce0fdcdf1eafae742552b52b21429e4bbcb30 100644 (file)
@@ -1,3 +1,11 @@
+2020-01-14  David Malcolm  <dmalcolm@redhat.com>
+
+       * cp-gimplify.c (source_location_table_entry_hash::empty_zero_p):
+       New static constant.
+       * cp-tree.h (named_decl_hash::empty_zero_p): Likewise.
+       (struct named_label_hash::empty_zero_p): Likewise.
+       * decl2.c (mangled_decl_hash::empty_zero_p): Likewise.
+
 2020-01-14  Jason Merrill  <jason@redhat.com>
 
        PR c++/92594 - ICE with inherited trivial default ctor.
index 3d764bb6928968c517851ef451372aa47d60fe13..f3aeb7475da51baf539b3eda37e1a14567087b64 100644 (file)
@@ -3045,6 +3045,8 @@ struct source_location_table_entry_hash
     ref.var = NULL_TREE;
   }
 
+  static const bool empty_zero_p = true;
+
   static void
   mark_empty (source_location_table_entry &ref)
   {
index 01fcf663a29446edb05d68c486d8e91e7809aa56..4e26acc22a5d899266bd978bbd3617b8e6778ee7 100644 (file)
@@ -900,6 +900,7 @@ struct named_decl_hash : ggc_remove <tree>
   inline static hashval_t hash (const value_type decl);
   inline static bool equal (const value_type existing, compare_type candidate);
 
+  static const bool empty_zero_p = true;
   static inline void mark_empty (value_type &p) {p = NULL_TREE;}
   static inline bool is_empty (value_type p) {return !p;}
 
@@ -1870,6 +1871,7 @@ struct named_label_hash : ggc_remove <named_label_entry *>
   inline static hashval_t hash (value_type);
   inline static bool equal (const value_type, compare_type);
 
+  static const bool empty_zero_p = true;
   inline static void mark_empty (value_type &p) {p = NULL;}
   inline static bool is_empty (value_type p) {return !p;}
 
index a641667991f7725b14af3ec448831ab1ef34af24..042d6fa12df2866ab20d31bb6d3183604d6c3649 100644 (file)
@@ -120,6 +120,7 @@ struct mangled_decl_hash : ggc_remove <tree>
     return candidate == name;
   }
 
+  static const bool empty_zero_p = true;
   static inline void mark_empty (value_type &p) {p = NULL_TREE;}
   static inline bool is_empty (value_type p) {return !p;}
 
index 1dca304977758b8c37d9d948f6a39f3a76744a78..a291bac3e9ea49ac0ae3e7609435471939569ec7 100644 (file)
@@ -1225,6 +1225,8 @@ struct function_start_pair_hash : typed_noop_remove <function_start>
     ref.start_line = ~1U;
   }
 
+  static const bool empty_zero_p = false;
+
   static void
   mark_empty (function_start &ref)
   {
index 0ac46766b15b1ed937976fc7f5db8d59cf02affb..27f1e486e1fc7c0c680515a7fec865eeffa73057 100644 (file)
@@ -233,6 +233,7 @@ struct sese_scev_hash : typed_noop_remove <seir_cache_key>
            && operand_equal_p (key1.expr, key2.expr, 0));
   }
   static void mark_deleted (seir_cache_key &key) { key.expr = NULL_TREE; }
+  static const bool empty_zero_p = false;
   static void mark_empty (seir_cache_key &key) { key.entry_dest = 0; }
   static bool is_deleted (const seir_cache_key &key) { return !key.expr; }
   static bool is_empty (const seir_cache_key &key) { return key.entry_dest == 0; }
index 743fb26d5717b79aaae42dbdd920a45c04cf7863..635740290658d9109cafd90b929b067beb229433 100644 (file)
@@ -280,6 +280,27 @@ test_map_of_type_with_ctor_and_dtor ()
   }
 }
 
+/* Test calling empty on a hash_map that has a key type with non-zero
+   "empty" value.  */
+
+static void
+test_nonzero_empty_key ()
+{
+  typedef int_hash<int, INT_MIN, INT_MAX> IntHash;
+  hash_map<int, int, simple_hashmap_traits<IntHash, int> > x;
+
+  for (int i = 1; i != 32; ++i)
+    x.put (i, i);
+
+  ASSERT_EQ (x.get (0), NULL);
+  ASSERT_EQ (*x.get (1), 1);
+
+  x.empty ();
+
+  ASSERT_EQ (x.get (0), NULL);
+  ASSERT_EQ (x.get (1), NULL);
+}
+
 /* Run all of the selftests within this file.  */
 
 void
@@ -288,6 +309,7 @@ hash_map_tests_c_tests ()
   test_map_of_strings_to_int ();
   test_map_of_int_to_strings ();
   test_map_of_type_with_ctor_and_dtor ();
+  test_nonzero_empty_key ();
 }
 
 } // namespace selftest
index 4764380b364ecf7f6e431aa7def26e5d9e68248a..3b16be35f7ddec871fc88d0790a9675428817b39 100644 (file)
@@ -36,6 +36,7 @@ struct simple_hashmap_traits
   static inline hashval_t hash (const key_type &);
   static inline bool equal_keys (const key_type &, const key_type &);
   template <typename T> static inline void remove (T &);
+  static const bool empty_zero_p = H::empty_zero_p;
   template <typename T> static inline bool is_empty (const T &);
   template <typename T> static inline bool is_deleted (const T &);
   template <typename T> static inline void mark_empty (T &);
@@ -113,6 +114,7 @@ template <typename Value>
 struct unbounded_hashmap_traits
 {
   template <typename T> static inline void remove (T &);
+  static const bool empty_zero_p = default_hash_traits <Value>::empty_zero_p;
   template <typename T> static inline bool is_empty (const T &);
   template <typename T> static inline bool is_deleted (const T &);
   template <typename T> static inline void mark_empty (T &);
index 7cb466767eab2869822dac30278ec949f2b05655..5b8fd184e32c26507206ecfd7d02fb5bf7bb8362 100644 (file)
@@ -66,6 +66,7 @@ class GTY((user)) hash_map
                return Traits::is_deleted (e);
       }
 
+    static const bool empty_zero_p = Traits::empty_zero_p;
     static void mark_empty (hash_entry &e) { Traits::mark_empty (e); }
     static bool is_empty (const hash_entry &e) { return Traits::is_empty (e); }
 
index 696e35e9be03376f64062ca63e5d812c899b371f..bb32094be20b1c908248e0060c79d39f6f3bcbc7 100644 (file)
@@ -199,6 +199,8 @@ struct value_hash_traits: int_hash<int, -1, -2>
     base_type::mark_deleted (v.val);
   }
 
+  static const bool empty_zero_p = false;
+
   static void mark_empty (value_type &v)
   {
     base_type::mark_empty (v.val);
index e0ddac5f578b884e4ed5112dc7415fbd5b397891..a1423c781125fedef803a4083771cd5c5b081f19 100644 (file)
@@ -713,8 +713,9 @@ hash_table<Descriptor, Lazy,
     nentries = ::ggc_cleared_vec_alloc<value_type> (n PASS_MEM_STAT);
 
   gcc_assert (nentries != NULL);
-  for (size_t i = 0; i < n; i++)
-    mark_empty (nentries[i]);
+  if (!Descriptor::empty_zero_p)
+    for (size_t i = 0; i < n; i++)
+      mark_empty (nentries[i]);
 
   return nentries;
 }
@@ -867,8 +868,11 @@ hash_table<Descriptor, Lazy, Allocator>::empty_slow ()
       m_size = nsize;
       m_size_prime_index = nindex;
     }
-  else
+  else if (Descriptor::empty_zero_p)
     memset ((void *) entries, 0, size * sizeof (value_type));
+  else
+    for (size_t i = 0; i < size; i++)
+      mark_empty (entries[i]);
 
   m_n_deleted = 0;
   m_n_elements = 0;
index d259a41a41811fb61d8dfa909b694f3b4a5f8418..3bca74c56ea87aefe01aa3a60dde8080e0da8f4d 100644 (file)
@@ -88,6 +88,7 @@ struct int_hash : typed_noop_remove <Type>
   static inline hashval_t hash (value_type);
   static inline bool equal (value_type existing, value_type candidate);
   static inline void mark_deleted (Type &);
+  static const bool empty_zero_p = Empty == 0;
   static inline void mark_empty (Type &);
   static inline bool is_deleted (Type);
   static inline bool is_empty (Type);
@@ -150,6 +151,7 @@ struct pointer_hash
   static inline bool equal (const value_type &existing,
                            const compare_type &candidate);
   static inline void mark_deleted (Type *&);
+  static const bool empty_zero_p = true;
   static inline void mark_empty (Type *&);
   static inline bool is_deleted (Type *);
   static inline bool is_empty (Type *);
@@ -323,6 +325,7 @@ struct pair_hash
   static inline bool equal (const value_type &, const compare_type &);
   static inline void remove (value_type &);
   static inline void mark_deleted (value_type &);
+  static const bool empty_zero_p = T1::empty_zero_p;
   static inline void mark_empty (value_type &);
   static inline bool is_deleted (const value_type &);
   static inline bool is_empty (const value_type &);
index b888186134c71bd10923e6b2da59f5cbf856f0ba..f0031957375e508e648b1a7a6d8127ceb986ac08 100644 (file)
@@ -150,6 +150,7 @@ struct default_hash_traits <type_pair>
   {
     return TYPE_UID (p.first) ^ TYPE_UID (p.second);
   }
+  static const bool empty_zero_p = true;
   static bool
   is_empty (type_pair p)
   {
index 6dc3cf6b3550842c2f7bc1603e6b2330fc668a64..12cdb95cf2ab7bea181b774af6b2213ec1c76bc8 100644 (file)
@@ -78,6 +78,7 @@ struct ipa_bit_ggc_hash_traits : public ggc_cache_remove <ipa_bits *>
     {
       return a->value == b->value && a->mask == b->mask;
     }
+  static const bool empty_zero_p = true;
   static void
   mark_empty (ipa_bits *&p)
     {
@@ -123,6 +124,7 @@ struct ipa_vr_ggc_hash_traits : public ggc_cache_remove <value_range *>
     {
       return a->equal_p (*b);
     }
+  static const bool empty_zero_p = true;
   static void
   mark_empty (value_range *&p)
     {
index e124dc6173a9e5e51c4290179017d788d4749b3b..6a2de21c3bd951c5b94235288b821a9bf8b9bf83 100644 (file)
@@ -932,6 +932,8 @@ struct location_triplet_hash : typed_noop_remove <location_triplet>
     ref.lineno = -1;
   }
 
+  static const bool empty_zero_p = false;
+
   static void
   mark_empty (location_triplet &ref)
   {
index 8a29abe99e2e789ca44368be877b217816df1f34..619aae45a15e360a57ce24e13b63bcc0d6da872d 100644 (file)
@@ -129,6 +129,8 @@ struct sanopt_tree_triplet_hash : typed_noop_remove <sanopt_tree_triplet>
     ref.t1 = reinterpret_cast<tree> (1);
   }
 
+  static const bool empty_zero_p = true;
+
   static void
   mark_empty (sanopt_tree_triplet &ref)
   {
@@ -184,6 +186,8 @@ struct sanopt_tree_couple_hash : typed_noop_remove <sanopt_tree_couple>
     ref.ptr = reinterpret_cast<tree> (1);
   }
 
+  static const bool empty_zero_p = true;
+
   static void
   mark_empty (sanopt_tree_couple &ref)
   {
index 787d1ad6a62f7f4b360d8fb9f0a0545c07788fb6..9194d6227a20d89bc588b9e4bdc90b6393f68b0d 100644 (file)
@@ -40,6 +40,7 @@ struct int_tree_hasher
     }
   static void mark_deleted (value_type &v) { v.to = reinterpret_cast<tree> (0x1); }
   static bool is_empty (const value_type &v) { return v.to == NULL; }
+  static const bool empty_zero_p = true;
   static void mark_empty (value_type &v) { v.to = NULL; }
   static void remove (value_type &) {}
 };
index 6f6b19eb165ab7635b27ae4b5f5bbb0b5902075c..3b27c50ef7546f703ff877fe9e9c2855ca294296 100644 (file)
@@ -335,6 +335,7 @@ struct vn_ssa_aux_hasher : typed_noop_remove <vn_ssa_aux_t>
   static inline hashval_t hash (const value_type &);
   static inline bool equal (const value_type &, const compare_type &);
   static inline void mark_deleted (value_type &) {}
+  static const bool empty_zero_p = true;
   static inline void mark_empty (value_type &e) { e = NULL; }
   static inline bool is_deleted (value_type &) { return false; }
   static inline bool is_empty (value_type &e) { return e == NULL; }
index 9cb724b95ae6a60709b23ddab67e410e56fe5ff3..d164937b4b02409a7f72c8f0477ae7b84c406c01 100644 (file)
@@ -1193,6 +1193,7 @@ struct bst_traits
   static inline bool equal (value_type existing, value_type candidate);
   static inline bool is_empty (value_type x) { return !x.exists (); }
   static inline bool is_deleted (value_type x) { return !x.exists (); }
+  static const bool empty_zero_p = true;
   static inline void mark_empty (value_type &x) { x.release (); }
   static inline void mark_deleted (value_type &x) { x.release (); }
   static inline void remove (value_type &x) { x.release (); }
index 375fba28d20931f0e2cd2d14fe36fb145a9604fe..ed7fcb0b825aa78537fea3994183484fdbd66f62 100644 (file)
@@ -232,6 +232,8 @@ struct default_hash_traits<scalar_cond_masked_key>
            && operand_equal_p (existing.op1, candidate.op1, 0));
   }
 
+  static const bool empty_zero_p = true;
+
   static inline void
   mark_empty (value_type &v)
   {