From b086d5308de0d25444243f482f2f3d1dfd3a9a62 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Tue, 2 Sep 2014 22:46:00 +0000 Subject: 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. From-SVN: r214834 --- gcc/hash-set.h | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) (limited to 'gcc/hash-set.h') diff --git a/gcc/hash-set.h b/gcc/hash-set.h index 47bae9e..0a500cb 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 static bool is_empty (T *e) { return e == NULL; } + + /* ggc walking routine, mark all objects refered to by this one. */ + + template + 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 + static void + pch_nx (T &x) + { + extern void gt_pch_nx (T &); + gt_pch_nx (x); + } }; template @@ -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 + static void + pch_nx_helper (T &x, gt_pointer_operator op, void *cookie) + { + gt_pch_nx (&x, op, cookie); + } + + template + 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 (); + 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 friend void gt_ggc_mx (hash_set *); + template friend void gt_pch_nx (hash_set *); + template friend void gt_pch_nx (hash_set *, gt_pointer_operator, void *); + hash_table m_table; }; +/* ggc marking routines. */ + +template +static inline void +gt_ggc_mx (hash_set *h) +{ + gt_ggc_mx (&h->m_table); +} + +template +static inline void +gt_pch_nx (hash_set *h) +{ + gt_pch_nx (&h->m_table); +} + +template +static inline void +gt_pch_nx (hash_set *h, gt_pointer_operator op, void *cookie) +{ + op (&h->m_table.m_entries, cookie); +} + #endif -- cgit v1.1