From: Richard Sandiford <richard.sandiford@arm.com>
To: gcc-patches@gcc.gnu.org
Subject: [10/12] Add helper class for valued-based empty and deleted slots
Date: Tue, 23 Jun 2015 14:56:00 -0000 [thread overview]
Message-ID: <87381ia2zy.fsf@e105548-lin.cambridge.arm.com> (raw)
In-Reply-To: <87egl2bicm.fsf@e105548-lin.cambridge.arm.com> (Richard Sandiford's message of "Tue, 23 Jun 2015 15:38:17 +0100")
part_traits in cfgexpand.c needs to use the value rather than the key to
represent empty and deleted slots. What it's doing is pretty generic,
so this patch adds a helper class to hash-map-traits.h.
gcc/
* hash-map-traits.h (unbounded_hashmap_traits): New class.
(unbounded_int_hashmap_traits): Likewise.
* cfgexpand.c (part_traits): Use unbounded_int_hashmap_traits.
Index: gcc/hash-map-traits.h
===================================================================
--- gcc/hash-map-traits.h 2015-06-23 15:54:04.515950631 +0100
+++ gcc/hash-map-traits.h 2015-06-23 15:54:04.511950679 +0100
@@ -174,4 +174,84 @@ simple_hashmap_traits <H>::mark_deleted
H::mark_deleted (entry.m_key);
}
+/* Implement traits for a hash_map with values of type Value for cases
+ in which the key cannot represent empty and deleted slots. Instead
+ record empty and deleted entries in Value. Derived classes must
+ implement the hash and equal_keys functions. */
+
+template <typename Value>
+struct unbounded_hashmap_traits
+{
+ template <typename T> static inline void remove (T &);
+ 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 &);
+ template <typename T> static inline void mark_deleted (T &);
+};
+
+template <typename Value>
+template <typename T>
+inline void
+unbounded_hashmap_traits <Value>::remove (T &entry)
+{
+ default_hash_traits <Value>::remove (entry.m_value);
+}
+
+template <typename Value>
+template <typename T>
+inline bool
+unbounded_hashmap_traits <Value>::is_empty (const T &entry)
+{
+ return default_hash_traits <Value>::is_empty (entry.m_value);
+}
+
+template <typename Value>
+template <typename T>
+inline bool
+unbounded_hashmap_traits <Value>::is_deleted (const T &entry)
+{
+ return default_hash_traits <Value>::is_deleted (entry.m_value);
+}
+
+template <typename Value>
+template <typename T>
+inline void
+unbounded_hashmap_traits <Value>::mark_empty (T &entry)
+{
+ default_hash_traits <Value>::mark_empty (entry.m_value);
+}
+
+template <typename Value>
+template <typename T>
+inline void
+unbounded_hashmap_traits <Value>::mark_deleted (T &entry)
+{
+ default_hash_traits <Value>::mark_deleted (entry.m_value);
+}
+
+/* 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. */
+
+template <typename Key, typename Value>
+struct unbounded_int_hashmap_traits : unbounded_hashmap_traits <Value>
+{
+ static inline hashval_t hash (Key);
+ static inline bool equal_keys (Key, Key);
+};
+
+template <typename Key, typename Value>
+inline hashval_t
+unbounded_int_hashmap_traits <Key, Value>::hash (Key k)
+{
+ return k;
+}
+
+template <typename Key, typename Value>
+inline bool
+unbounded_int_hashmap_traits <Key, Value>::equal_keys (Key k1, Key k2)
+{
+ return k1 == k2;
+}
+
#endif // HASH_MAP_TRAITS_H
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c 2015-06-23 15:54:04.515950631 +0100
+++ gcc/cfgexpand.c 2015-06-23 15:54:04.511950679 +0100
@@ -612,25 +612,7 @@ stack_var_cmp (const void *a, const void
return 0;
}
-struct part_traits : default_hashmap_traits
-{
- template<typename T>
- static bool
- is_deleted (T &e)
- { return e.m_value == reinterpret_cast<void *> (1); }
-
- template<typename T> static bool is_empty (T &e) { return e.m_value == NULL; }
- template<typename T>
- static void
- mark_deleted (T &e)
- { e.m_value = reinterpret_cast<T> (1); }
-
- template<typename T>
- static void
- mark_empty (T &e)
- { e.m_value = NULL; }
-};
-
+struct part_traits : unbounded_int_hashmap_traits <size_t, bitmap> {};
typedef hash_map<size_t, bitmap, part_traits> part_hashmap;
/* If the points-to solution *PI points to variables that are in a partition
next prev parent reply other threads:[~2015-06-23 14:55 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87egl2bicm.fsf@e105548-lin.cambridge.arm.com>
2015-06-23 14:44 ` [01/12] Add hash_map traits that use existing hash_table-like traits Richard Sandiford
2015-06-25 16:34 ` Jeff Law
2015-06-23 14:45 ` [02/12] Move tree operand hashers to a new header file Richard Sandiford
2015-06-25 16:34 ` Jeff Law
2015-06-23 14:47 ` [03/12] Move decl hasher to " Richard Sandiford
2015-06-25 16:34 ` Jeff Law
2015-06-23 14:48 ` [04/12] Move ssa_name " Richard Sandiford
2015-06-25 16:35 ` Jeff Law
2015-06-23 14:49 ` [05/12] Move TREE_HASH " Richard Sandiford
2015-06-25 16:36 ` Jeff Law
2015-06-23 14:50 ` [06/12] Consolidate string hashers Richard Sandiford
2015-06-24 10:13 ` Mikhail Maltsev
2015-06-24 11:39 ` Richard Sandiford
2015-06-25 16:37 ` Jeff Law
2015-06-23 14:52 ` [07/12] Use new string hasher for MIPS Richard Sandiford
2015-06-25 16:39 ` Jeff Law
2015-06-23 14:53 ` [08/12] Add common traits for integer hash keys Richard Sandiford
2015-06-25 16:40 ` Jeff Law
2015-06-23 14:55 ` [09/12] Remove all but one use of default_hashmap_traits Richard Sandiford
2015-06-25 16:41 ` Jeff Law
2015-06-23 14:56 ` Richard Sandiford [this message]
2015-06-25 16:41 ` [10/12] Add helper class for valued-based empty and deleted slots Jeff Law
2015-06-23 14:57 ` [11/12] Remove default_hashmap_traits Richard Sandiford
2015-06-25 16:42 ` Jeff Law
2015-06-23 14:58 ` [12/12] Simplify uses of hash_map Richard Sandiford
2015-06-25 16:57 ` Jeff Law
2015-06-26 13:50 ` Rainer Orth
2015-06-26 14:38 ` Richard Sandiford
2015-06-26 14:39 ` Jan-Benedict Glaw
2015-06-26 15:34 ` Rainer Orth
2015-06-26 16:17 ` Richard Sandiford
2015-06-26 16:45 ` Richard Sandiford
2015-06-26 17:03 ` Richard Sandiford
2015-06-26 16:09 ` Mikhail Maltsev
2015-06-26 14:36 ` [BUILDROBOT] could not convert template argument ‘fill_decls_vec’ to ‘bool (*)(tree_node*&, tree_node**, auto_vec<cilk_decls>*)’ (was: [12/12] Simplify uses of hash_map) Jan-Benedict Glaw
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87381ia2zy.fsf@e105548-lin.cambridge.arm.com \
--to=richard.sandiford@arm.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).