tree-hash-traits.h 2.1 KB

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