]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-hash-traits.h
2019-04-15 Richard Biener <rguenther@suse.de>
[thirdparty/gcc.git] / gcc / tree-hash-traits.h
CommitLineData
f4ff098a 1/* Traits for hashing trees.
fbd26352 2 Copyright (C) 2014-2019 Free Software Foundation, Inc.
f4ff098a 3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef tree_hash_traits_h
21#define tree_hash_traits_h
22
23/* Hash for trees based on operand_equal_p. */
24struct tree_operand_hash : ggc_ptr_hash <tree_node>
25{
01bd664f 26 static inline hashval_t hash (const value_type &);
27 static inline bool equal (const value_type &,
28 const compare_type &);
f4ff098a 29};
30
31inline hashval_t
01bd664f 32tree_operand_hash::hash (const value_type &t)
f4ff098a 33{
34 return iterative_hash_expr (t, 0);
35}
36
37inline bool
01bd664f 38tree_operand_hash::equal (const value_type &t1,
39 const compare_type &t2)
f4ff098a 40{
41 return operand_equal_p (t1, t2, 0);
42}
43
3c17973d 44/* Hasher for tree decls. Pointer equality is enough here, but the DECL_UID
45 is a better hash than the pointer value and gives a predictable traversal
46 order. */
47struct tree_decl_hash : ggc_ptr_hash <tree_node>
48{
49 static inline hashval_t hash (tree);
50};
51
52inline hashval_t
53tree_decl_hash::hash (tree t)
54{
55 return DECL_UID (t);
56}
57
ad7173b9 58/* Hash for SSA_NAMEs in the same function. Pointer equality is enough
59 here, but the SSA_NAME_VERSION is a better hash than the pointer
60 value and gives a predictable traversal order. */
61struct tree_ssa_name_hash : ggc_ptr_hash <tree_node>
62{
63 static inline hashval_t hash (tree);
64};
65
66inline hashval_t
67tree_ssa_name_hash::hash (tree t)
68{
69 return SSA_NAME_VERSION (t);
70}
71
22fd03a5 72/* Hasher for general trees, based on their TREE_HASH. */
73struct tree_hash : ggc_ptr_hash <tree_node>
74{
75 static hashval_t hash (tree);
76};
77
78inline hashval_t
79tree_hash::hash (tree t)
80{
81 return TREE_HASH (t);
82}
83
f4ff098a 84#endif