aboutsummaryrefslogtreecommitdiff
path: root/gcc/hash-map.h
diff options
context:
space:
mode:
authorTrevor Saunders <tsaunders@mozilla.com>2014-09-02 22:46:00 +0000
committerTrevor Saunders <tbsaunde@gcc.gnu.org>2014-09-02 22:46:00 +0000
commitb086d5308de0d25444243f482f2f3d1dfd3a9a62 (patch)
treecb4aa8d407cf40f28ef0fcd771f1109d53f44f3c /gcc/hash-map.h
parent70f0f8b2b1c9bf53b9158e4264bc1e93b963c31e (diff)
downloadgcc-b086d5308de0d25444243f482f2f3d1dfd3a9a62.zip
gcc-b086d5308de0d25444243f482f2f3d1dfd3a9a62.tar.gz
gcc-b086d5308de0d25444243f482f2f3d1dfd3a9a62.tar.bz2
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
Diffstat (limited to 'gcc/hash-map.h')
-rw-r--r--gcc/hash-map.h79
1 files changed, 77 insertions, 2 deletions
diff --git a/gcc/hash-map.h b/gcc/hash-map.h
index d2eed33..c65e1e5 100644
--- a/gcc/hash-map.h
+++ b/gcc/hash-map.h
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see
#ifndef hash_map_h
#define hash_map_h
+#include <new>
#include "hash-table.h"
/* implement default behavior for traits when types allow it. */
@@ -103,7 +104,7 @@ private:
template<typename Key, typename Value,
typename Traits = default_hashmap_traits>
-class hash_map
+class GTY((user)) hash_map
{
struct hash_entry
{
@@ -135,10 +136,56 @@ class 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 void ggc_mx (hash_entry &e)
+ {
+ gt_ggc_mx (e.m_key);
+ gt_ggc_mx (e.m_value);
+ }
+
+ static void pch_nx (hash_entry &e)
+ {
+ gt_pch_nx (e.m_key);
+ gt_pch_nx (e.m_value);
+ }
+
+ static void pch_nx (hash_entry &e, gt_pointer_operator op, void *c)
+ {
+ pch_nx_helper (e.m_key, op, c);
+ pch_nx_helper (e.m_value, 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);
+ }
+
+ static void
+ pch_nx_helper (int, gt_pointer_operator, void *)
+ {
+ }
+
+ template<typename T>
+ static void
+ pch_nx_helper (T *&x, gt_pointer_operator op, void *cookie)
+ {
+ op (&x, cookie);
+ }
};
public:
- explicit hash_map (size_t n = 13) : m_table (n) {}
+ explicit hash_map (size_t n = 13, bool ggc = false) : m_table (n, ggc) {}
+
+ /* Create a hash_map in ggc memory. */
+ static hash_map *create_ggc (size_t size)
+ {
+ hash_map *map = ggc_alloc<hash_map> ();
+ new (map) hash_map (size, true);
+ return map;
+ }
/* If key k isn't already in the map add key k with value v to the map, and
return false. Otherwise set the value of the entry for key k to be v and
@@ -208,7 +255,35 @@ public:
}
private:
+
+ template<typename T, typename U, typename V> friend void gt_ggc_mx (hash_map<T, U, V> *);
+ template<typename T, typename U, typename V> friend void gt_pch_nx (hash_map<T, U, V> *);
+ template<typename T, typename U, typename V> friend void gt_pch_nx (hash_map<T, U, V> *, gt_pointer_operator, void *);
+
hash_table<hash_entry> m_table;
};
+/* ggc marking routines. */
+
+template<typename K, typename V, typename H>
+static inline void
+gt_ggc_mx (hash_map<K, V, H> *h)
+{
+ gt_ggc_mx (&h->m_table);
+}
+
+template<typename K, typename V, typename H>
+static inline void
+gt_pch_nx (hash_map<K, V, H> *h)
+{
+ gt_pch_nx (&h->m_table);
+}
+
+template<typename K, typename V, typename H>
+static inline void
+gt_pch_nx (hash_map<K, V, H> *h, gt_pointer_operator op, void *cookie)
+{
+ op (&h->m_table.m_entries, cookie);
+}
+
#endif