diff mbox

[03/12] Move decl hasher to header file

Message ID 87wpyua3fp.fsf@e105548-lin.cambridge.arm.com
State New
Headers show

Commit Message

Richard Sandiford June 23, 2015, 2:45 p.m. UTC
Like the previous patch, but for decl hashers.  There's only one copy
of this so far, but the idea seems general.


gcc/
	* tree-hash-traits.h (tree_decl_hash): New class.
	* tree-ssa-strlen.c: Include tree-hash-traits.h.
	(stridxlist_hash_traits): Use tree_decl_hash.

Comments

Jeff Law June 25, 2015, 4:34 p.m. UTC | #1
On 06/23/2015 08:45 AM, Richard Sandiford wrote:
> Like the previous patch, but for decl hashers.  There's only one copy
> of this so far, but the idea seems general.
>
>
> gcc/
> 	* tree-hash-traits.h (tree_decl_hash): New class.
> 	* tree-ssa-strlen.c: Include tree-hash-traits.h.
> 	(stridxlist_hash_traits): Use tree_decl_hash.
OK.
jeff
diff mbox

Patch

Index: gcc/tree-hash-traits.h
===================================================================
--- gcc/tree-hash-traits.h	2015-06-23 15:45:22.993947116 +0100
+++ gcc/tree-hash-traits.h	2015-06-23 15:45:22.989947161 +0100
@@ -39,4 +39,18 @@  tree_operand_hash::equal_keys (const_tre
   return operand_equal_p (t1, t2, 0);
 }
 
+/* Hasher for tree decls.  Pointer equality is enough here, but the DECL_UID
+   is a better hash than the pointer value and gives a predictable traversal
+   order.  */
+struct tree_decl_hash : ggc_ptr_hash <tree_node>
+{
+  static inline hashval_t hash (tree);
+};
+
+inline hashval_t
+tree_decl_hash::hash (tree t)
+{
+  return DECL_UID (t);
+}
+
 #endif
Index: gcc/tree-ssa-strlen.c
===================================================================
--- gcc/tree-ssa-strlen.c	2015-06-23 15:45:22.993947116 +0100
+++ gcc/tree-ssa-strlen.c	2015-06-23 15:45:22.989947161 +0100
@@ -73,6 +73,7 @@  the Free Software Foundation; either ver
 #include "ipa-ref.h"
 #include "cgraph.h"
 #include "ipa-chkp.h"
+#include "tree-hash-traits.h"
 
 /* A vector indexed by SSA_NAME_VERSION.  0 means unknown, positive value
    is an index into strinfo vector, negative value stands for
@@ -155,20 +156,7 @@  struct decl_stridxlist_map
   struct stridxlist list;
 };
 
-/* stridxlist hashtable helpers.  */
-
-struct stridxlist_hash_traits : default_hashmap_traits
-{
-  static inline hashval_t hash (tree);
-};
-
-/* Hash a from tree in a decl_stridxlist_map.  */
-
-inline hashval_t
-stridxlist_hash_traits::hash (tree item)
-{
-  return DECL_UID (item);
-}
+typedef simple_hashmap_traits <tree_decl_hash> stridxlist_hash_traits;
 
 /* Hash table for mapping decls to a chained list of offset -> idx
    mappings.  */