From 7b96fb6e6d6c5d0e574440ecf0b842d71d5a8049 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 12 Jun 2019 11:03:33 +0200 Subject: [PATCH 1/2] Add ::sanitize into hash-traits and disable it for obvious types. --- gcc/attribs.c | 5 +++++ gcc/cp/cp-tree.h | 2 ++ gcc/cp/decl2.c | 1 + gcc/gcov.c | 2 ++ gcc/graphite.c | 1 + gcc/hash-map-traits.h | 26 ++++++++++++++++++++++++++ gcc/hash-map.h | 1 + gcc/hash-table.h | 5 +++-- gcc/hash-traits.h | 25 +++++++++++++++++++++++++ gcc/ipa-devirt.c | 2 ++ gcc/ipa-prop.c | 3 +++ gcc/profile.c | 1 + gcc/sanopt.c | 2 ++ gcc/tree-hasher.h | 1 + gcc/tree-ssa-sccvn.c | 1 + gcc/tree-vect-slp.c | 1 + 16 files changed, 77 insertions(+), 2 deletions(-) diff --git a/gcc/attribs.c b/gcc/attribs.c index 4441922543f..06a6b56b634 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -2057,6 +2057,11 @@ struct excl_hash_traits: typed_noop_remove { return !*x.first && !*x.second; } + + static bool sanitize () + { + return true; + } }; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1f4e1e15554..d0ce3b68693 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -869,6 +869,7 @@ struct named_decl_hash : ggc_remove /* Nothing is deletable. Everything is insertable. */ static bool is_deleted (value_type) { return false; } static void mark_deleted (value_type) { gcc_unreachable (); } + inline static bool sanitize () { return true; } }; /* Simplified unique_ptr clone to release a tree vec on exit. */ @@ -1815,6 +1816,7 @@ struct named_label_hash : ggc_remove /* Nothing is deletable. Everything is insertable. */ inline static bool is_deleted (value_type) { return false; } inline static void mark_deleted (value_type) { gcc_unreachable (); } + inline static bool sanitize () { return true; } }; /* Global state pertinent to the current function. */ diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 338db4ab6de..f4f5e878eb7 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -131,6 +131,7 @@ struct mangled_decl_hash : ggc_remove { e = reinterpret_cast (1); } + inline static bool sanitize () { return true; } }; /* A hash table of decls keyed by mangled name. Used to figure out if diff --git a/gcc/gcov.c b/gcc/gcov.c index b06a6714c2e..015cac6247a 100644 --- a/gcc/gcov.c +++ b/gcc/gcov.c @@ -1234,6 +1234,8 @@ struct function_start_pair_hash : typed_noop_remove { return ref.start_line == ~2U; } + + inline static bool sanitize () { return true; } }; /* Process a single input file. */ diff --git a/gcc/graphite.c b/gcc/graphite.c index 67202e276e2..c85f88e9e34 100644 --- a/gcc/graphite.c +++ b/gcc/graphite.c @@ -237,6 +237,7 @@ struct sese_scev_hash : typed_noop_remove 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; } + static bool sanitize () { return true; } }; static hash_map *seir_cache; diff --git a/gcc/hash-map-traits.h b/gcc/hash-map-traits.h index af66018e92c..a52c272d7e2 100644 --- a/gcc/hash-map-traits.h +++ b/gcc/hash-map-traits.h @@ -40,6 +40,7 @@ struct simple_hashmap_traits template static inline bool is_deleted (const T &); template static inline void mark_empty (T &); template static inline void mark_deleted (T &); + static inline bool sanitize (); }; template @@ -98,6 +99,13 @@ simple_hashmap_traits ::mark_deleted (T &entry) H::mark_deleted (entry.m_key); } +template +inline bool +simple_hashmap_traits ::sanitize () +{ + return H::sanitize (); +} + template struct simple_cache_map_traits: public simple_hashmap_traits { @@ -117,6 +125,7 @@ struct unbounded_hashmap_traits template static inline bool is_deleted (const T &); template static inline void mark_empty (T &); template static inline void mark_deleted (T &); + template static inline bool sanitize (); }; template @@ -159,6 +168,14 @@ unbounded_hashmap_traits ::mark_deleted (T &entry) default_hash_traits ::mark_deleted (entry.m_value); } +template +template +inline bool +unbounded_hashmap_traits ::sanitize () +{ + return T::sanitize (); +} + /* Implement traits for a hash_map from integer type Key to Value in cases where Key has no spare values for recording empty and deleted slots. */ @@ -169,6 +186,7 @@ struct unbounded_int_hashmap_traits : unbounded_hashmap_traits typedef Key key_type; static inline hashval_t hash (Key); static inline bool equal_keys (Key, Key); + static inline bool sanitize (); }; template @@ -185,4 +203,12 @@ unbounded_int_hashmap_traits ::equal_keys (Key k1, Key k2) return k1 == k2; } +template +inline bool +unbounded_int_hashmap_traits ::sanitize () +{ + return false; +} + + #endif // HASH_MAP_TRAITS_H diff --git a/gcc/hash-map.h b/gcc/hash-map.h index a8eb42d5a03..151632730e7 100644 --- a/gcc/hash-map.h +++ b/gcc/hash-map.h @@ -55,6 +55,7 @@ class GTY((user)) hash_map static void mark_empty (hash_entry &e) { Traits::mark_empty (e); } static bool is_empty (const hash_entry &e) { return Traits::is_empty (e); } + static bool sanitize () { return Traits::sanitize (); } static void ggc_mx (hash_entry &e) { diff --git a/gcc/hash-table.h b/gcc/hash-table.h index 4f5e150a0ac..de5ebc8ba6d 100644 --- a/gcc/hash-table.h +++ b/gcc/hash-table.h @@ -600,7 +600,8 @@ hash_table::hash_table (size_t size, bool ggc, mem_alloc_origin origin MEM_STAT_DECL) : m_n_elements (0), m_n_deleted (0), m_searches (0), m_collisions (0), - m_ggc (ggc), m_sanitize_eq_and_hash (sanitize_eq_and_hash) + m_ggc (ggc), + m_sanitize_eq_and_hash (sanitize_eq_and_hash && Descriptor::sanitize ()) #if GATHER_STATISTICS , m_gather_mem_stats (gather_mem_stats) #endif @@ -633,7 +634,7 @@ hash_table::hash_table (const hash_table &h, MEM_STAT_DECL) : m_n_elements (h.m_n_elements), m_n_deleted (h.m_n_deleted), m_searches (0), m_collisions (0), m_ggc (ggc), - m_sanitize_eq_and_hash (sanitize_eq_and_hash) + m_sanitize_eq_and_hash (sanitize_eq_and_hash && Descriptor::sanitize ()) #if GATHER_STATISTICS , m_gather_mem_stats (gather_mem_stats) #endif diff --git a/gcc/hash-traits.h b/gcc/hash-traits.h index 2d17e2c982a..37a97c31491 100644 --- a/gcc/hash-traits.h +++ b/gcc/hash-traits.h @@ -91,6 +91,7 @@ struct int_hash : typed_noop_remove static inline void mark_empty (Type &); static inline bool is_deleted (Type); static inline bool is_empty (Type); + static inline bool sanitize (); }; template @@ -136,6 +137,13 @@ int_hash ::is_empty (Type x) return x == Empty; } +template +inline bool +int_hash ::sanitize () +{ + return false; +} + /* Pointer hasher based on pointer equality. Other types of pointer hash can inherit this and override the hash and equal functions with some other form of equality (such as string equality). */ @@ -153,6 +161,7 @@ struct pointer_hash static inline void mark_empty (Type *&); static inline bool is_deleted (Type *); static inline bool is_empty (Type *); + static inline bool sanitize (); }; template @@ -200,6 +209,13 @@ pointer_hash ::is_empty (Type *e) return e == NULL; } +template +inline bool +pointer_hash ::sanitize () +{ + return true; +} + /* Hasher for "const char *" strings, using string rather than pointer equality. */ @@ -326,6 +342,7 @@ struct pair_hash static inline void mark_empty (value_type &); static inline bool is_deleted (const value_type &); static inline bool is_empty (const value_type &); + static inline bool sanitize (); }; template @@ -378,6 +395,14 @@ pair_hash ::is_empty (const value_type &x) return T1::is_empty (x.first); } +template +inline bool +pair_hash ::sanitize () +{ + return T1::sanitize (); +} + + template struct default_hash_traits : T {}; template diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index a4c8b0de86f..26f0d332e00 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -170,6 +170,8 @@ struct default_hash_traits { e.first = NULL; } + + static bool sanitize () { return true; } }; static bool odr_types_equivalent_p (tree, tree, bool, bool *, diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index d86c2f3db55..57cd864b74d 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -99,6 +99,8 @@ struct ipa_bit_ggc_hash_traits : public ggc_cache_remove { p = reinterpret_cast (1); } + + static bool sanitize () { return true; } }; /* Hash table for avoid repeated allocations of equal ipa_bits. */ @@ -144,6 +146,7 @@ struct ipa_vr_ggc_hash_traits : public ggc_cache_remove { p = reinterpret_cast (1); } + inline static bool sanitize () { return true; } }; /* Hash table for avoid repeated allocations of equal value_ranges. */ diff --git a/gcc/profile.c b/gcc/profile.c index 9aff9ef2b21..668888f89ab 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -884,6 +884,7 @@ struct location_triplet_hash : typed_noop_remove { return ref.lineno == -2; } + inline static bool sanitize () { return true; } }; diff --git a/gcc/sanopt.c b/gcc/sanopt.c index 5cb98e1b50e..d2f9ba5a56c 100644 --- a/gcc/sanopt.c +++ b/gcc/sanopt.c @@ -147,6 +147,7 @@ struct sanopt_tree_triplet_hash : typed_noop_remove { return ref.t1 == NULL; } + inline static bool sanitize () { return true; } }; /* Tree couple for ptr_check_map. */ @@ -202,6 +203,7 @@ struct sanopt_tree_couple_hash : typed_noop_remove { return ref.ptr == NULL; } + inline static bool sanitize () { return true; } }; /* This is used to carry various hash maps and variables used diff --git a/gcc/tree-hasher.h b/gcc/tree-hasher.h index a64f297fb2a..24da6c0a416 100644 --- a/gcc/tree-hasher.h +++ b/gcc/tree-hasher.h @@ -42,6 +42,7 @@ struct int_tree_hasher static bool is_empty (const value_type &v) { return v.to == NULL; } static void mark_empty (value_type &v) { v.to = NULL; } static void remove (value_type &) {} + inline static bool sanitize () { return true; } }; /* Hash a UID in a int_tree_map. */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index b4f626000dd..69d365dc5d2 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -335,6 +335,7 @@ struct vn_ssa_aux_hasher : typed_noop_remove 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; } + inline static bool sanitize () { return true; } }; hashval_t diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index 930cd79784e..10ad0632853 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -1023,6 +1023,7 @@ struct bst_traits 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 (); } + inline static bool sanitize () { return true; } }; inline hashval_t bst_traits::hash (value_type x) -- 2.21.0