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