diff options
author | tbsaunde <tbsaunde@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-09-02 22:46:00 +0000 |
---|---|---|
committer | tbsaunde <tbsaunde@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-09-02 22:46:00 +0000 |
commit | 8f359205089fa4570dd9db058aed35e391ceb357 (patch) | |
tree | cb4aa8d407cf40f28ef0fcd771f1109d53f44f3c /gcc/hash-set.h | |
parent | c4de79b608465ea31bd920224bd7fdff2deeaecf (diff) | |
download | gcc-8f359205089fa4570dd9db058aed35e391ceb357.tar.gz |
support ggc hash_map and hash_set
gcc/ChangeLog:
* alloc-pool.c: Include coretypes.h.
* cgraph.h, dbxout.c, dwarf2out.c, except.c, except.h, function.c,
function.h, symtab.c, tree-cfg.c, tree-eh.c: Use hash_map and
hash_set instead of htab.
* ggc-page.c (in_gc): New variable.
(ggc_free): Do nothing if a collection is taking place.
(ggc_collect): Set in_gc appropriately.
* ggc.h (gt_ggc_mx(const char *)): New function.
(gt_pch_nx(const char *)): Likewise.
(gt_ggc_mx(int)): Likewise.
(gt_pch_nx(int)): Likewise.
* hash-map.h (hash_map::hash_entry::ggc_mx): Likewise.
(hash_map::hash_entry::pch_nx): Likewise.
(hash_map::hash_entry::pch_nx_helper): Likewise.
(hash_map::hash_map): Adjust.
(hash_map::create_ggc): New function.
(gt_ggc_mx): Likewise.
(gt_pch_nx): Likewise.
* hash-set.h (default_hashset_traits::ggc_mx): Likewise.
(default_hashset_traits::pch_nx): Likewise.
(hash_set::hash_entry::ggc_mx): Likewise.
(hash_set::hash_entry::pch_nx): Likewise.
(hash_set::hash_entry::pch_nx_helper): Likewise.
(hash_set::hash_set): Adjust.
(hash_set::create_ggc): New function.
(hash_set::elements): Likewise.
(gt_ggc_mx): Likewise.
(gt_pch_nx): Likewise.
* hash-table.h (hash_table::hash_table): Adjust.
(hash_table::m_ggc): New member.
(hash_table::~hash_table): Adjust.
(hash_table::expand): Likewise.
(hash_table::empty): Likewise.
(gt_ggc_mx): New function.
(hashtab_entry_note_pointers): Likewise.
(gt_pch_nx): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@214834 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/hash-set.h')
-rw-r--r-- | gcc/hash-set.h | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/gcc/hash-set.h b/gcc/hash-set.h index 47bae9ed77d..0a500cb441a 100644 --- a/gcc/hash-set.h +++ b/gcc/hash-set.h @@ -81,6 +81,26 @@ struct default_hashset_traits /* Return true if the passed in entry is marked as empty. */ template<typename T> static bool is_empty (T *e) { return e == NULL; } + + /* ggc walking routine, mark all objects refered to by this one. */ + + template<typename T> + static void + ggc_mx (T &x) + { + extern void gt_ggc_mx (T &); + gt_ggc_mx (x); + } + + /* pch walking routine, note all objects refered to by this element. */ + + template<typename T> + static void + pch_nx (T &x) + { + extern void gt_pch_nx (T &); + gt_pch_nx (x); + } }; template<typename Key, typename Traits = default_hashset_traits> @@ -128,10 +148,50 @@ class hash_set { return Traits::is_empty (e.m_key); } + + static void ggc_mx (hash_entry &e) + { + Traits::ggc_mx (e.m_key); + } + + static void pch_nx (hash_entry &e) + { + Traits::pch_nx (e.m_key); + } + + static void pch_nx (hash_entry &e, gt_pointer_operator op, void *c) + { + pch_nx_helper (e.m_key, op, c); + } + + private: + template<typename T> + static void + pch_nx_helper (T &x, gt_pointer_operator op, void *cookie) + { + gt_pch_nx (&x, op, cookie); + } + + template<typename T> + static void + pch_nx_helper (T *&x, gt_pointer_operator op, void *cookie) + { + op (&x, cookie); + } }; public: - explicit hash_set (size_t n = 13) : m_table (n) {} + explicit hash_set (size_t n = 13, bool ggc = false) : m_table (n, ggc) {} + + /* Create a hash_set in gc memory with space for at least n elements. */ + + static hash_set * + create_ggc (size_t n) + { + hash_set *set = ggc_alloc<hash_set> (); + new (set) hash_set (n, true); + return set; + } /* If key k isn't already in the map add it to the map, and return false. Otherwise return true. */ @@ -166,8 +226,40 @@ public: f ((*iter).m_key, a); } + /* Return the number of elements in the set. */ + + size_t elements () const { return m_table.elements (); } + private: + + template<typename T, typename U> friend void gt_ggc_mx (hash_set<T, U> *); + template<typename T, typename U> friend void gt_pch_nx (hash_set<T, U> *); + template<typename T, typename U> friend void gt_pch_nx (hash_set<T, U> *, gt_pointer_operator, void *); + hash_table<hash_entry> m_table; }; +/* ggc marking routines. */ + +template<typename K, typename H> +static inline void +gt_ggc_mx (hash_set<K, H> *h) +{ + gt_ggc_mx (&h->m_table); +} + +template<typename K, typename H> +static inline void +gt_pch_nx (hash_set<K, H> *h) +{ + gt_pch_nx (&h->m_table); +} + +template<typename K, typename H> +static inline void +gt_pch_nx (hash_set<K, H> *h, gt_pointer_operator op, void *cookie) +{ + op (&h->m_table.m_entries, cookie); +} + #endif |