tree-ssa-sccvn.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* Tree SCC value numbering
  2. Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. Contributed by Daniel Berlin <dberlin@dberlin.org>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify
  6. under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. GCC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef TREE_SSA_SCCVN_H
  17. #define TREE_SSA_SCCVN_H
  18. /* In tree-ssa-sccvn.c */
  19. bool expressions_equal_p (tree, tree);
  20. /* TOP of the VN lattice. */
  21. extern tree VN_TOP;
  22. /* N-ary operations in the hashtable consist of length operands, an
  23. opcode, and a type. Result is the value number of the operation,
  24. and hashcode is stored to avoid having to calculate it
  25. repeatedly. */
  26. typedef struct vn_nary_op_s
  27. {
  28. /* Unique identify that all expressions with the same value have. */
  29. unsigned int value_id;
  30. ENUM_BITFIELD(tree_code) opcode : 16;
  31. unsigned length : 16;
  32. hashval_t hashcode;
  33. tree result;
  34. tree type;
  35. tree op[1];
  36. } *vn_nary_op_t;
  37. typedef const struct vn_nary_op_s *const_vn_nary_op_t;
  38. /* Return the size of a vn_nary_op_t with LENGTH operands. */
  39. static inline size_t
  40. sizeof_vn_nary_op (unsigned int length)
  41. {
  42. return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree);
  43. }
  44. /* Phi nodes in the hashtable consist of their non-VN_TOP phi
  45. arguments, and the basic block the phi is in. Result is the value
  46. number of the operation, and hashcode is stored to avoid having to
  47. calculate it repeatedly. Phi nodes not in the same block are never
  48. considered equivalent. */
  49. typedef struct vn_phi_s
  50. {
  51. /* Unique identifier that all expressions with the same value have. */
  52. unsigned int value_id;
  53. hashval_t hashcode;
  54. vec<tree> phiargs;
  55. basic_block block;
  56. tree type;
  57. tree result;
  58. } *vn_phi_t;
  59. typedef const struct vn_phi_s *const_vn_phi_t;
  60. /* Reference operands only exist in reference operations structures.
  61. They consist of an opcode, type, and some number of operands. For
  62. a given opcode, some, all, or none of the operands may be used.
  63. The operands are there to store the information that makes up the
  64. portion of the addressing calculation that opcode performs. */
  65. typedef struct vn_reference_op_struct
  66. {
  67. ENUM_BITFIELD(tree_code) opcode : 16;
  68. /* 1 for instrumented calls. */
  69. unsigned with_bounds : 1;
  70. /* Constant offset this op adds or -1 if it is variable. */
  71. HOST_WIDE_INT off;
  72. tree type;
  73. tree op0;
  74. tree op1;
  75. tree op2;
  76. } vn_reference_op_s;
  77. typedef vn_reference_op_s *vn_reference_op_t;
  78. typedef const vn_reference_op_s *const_vn_reference_op_t;
  79. /* A reference operation in the hashtable is representation as
  80. the vuse, representing the memory state at the time of
  81. the operation, and a collection of operands that make up the
  82. addressing calculation. If two vn_reference_t's have the same set
  83. of operands, they access the same memory location. We also store
  84. the resulting value number, and the hashcode. */
  85. typedef struct vn_reference_s
  86. {
  87. /* Unique identifier that all expressions with the same value have. */
  88. unsigned int value_id;
  89. hashval_t hashcode;
  90. tree vuse;
  91. alias_set_type set;
  92. tree type;
  93. vec<vn_reference_op_s> operands;
  94. tree result;
  95. tree result_vdef;
  96. } *vn_reference_t;
  97. typedef const struct vn_reference_s *const_vn_reference_t;
  98. typedef struct vn_constant_s
  99. {
  100. unsigned int value_id;
  101. hashval_t hashcode;
  102. tree constant;
  103. } *vn_constant_t;
  104. enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI };
  105. enum vn_kind vn_get_stmt_kind (gimple);
  106. /* Hash the type TYPE using bits that distinguishes it in the
  107. types_compatible_p sense. */
  108. static inline hashval_t
  109. vn_hash_type (tree type)
  110. {
  111. return (INTEGRAL_TYPE_P (type)
  112. + (INTEGRAL_TYPE_P (type)
  113. ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0));
  114. }
  115. /* Hash the constant CONSTANT with distinguishing type incompatible
  116. constants in the types_compatible_p sense. */
  117. static inline hashval_t
  118. vn_hash_constant_with_type (tree constant)
  119. {
  120. inchash::hash hstate;
  121. inchash::add_expr (constant, hstate);
  122. hstate.merge_hash (vn_hash_type (TREE_TYPE (constant)));
  123. return hstate.end ();
  124. }
  125. /* Compare the constants C1 and C2 with distinguishing type incompatible
  126. constants in the types_compatible_p sense. */
  127. static inline bool
  128. vn_constant_eq_with_type (tree c1, tree c2)
  129. {
  130. return (expressions_equal_p (c1, c2)
  131. && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2)));
  132. }
  133. typedef struct vn_ssa_aux
  134. {
  135. /* Value number. This may be an SSA name or a constant. */
  136. tree valnum;
  137. /* Representative expression, if not a direct constant. */
  138. tree expr;
  139. /* Unique identifier that all expressions with the same value have. */
  140. unsigned int value_id;
  141. /* SCC information. */
  142. unsigned int dfsnum;
  143. unsigned int low;
  144. unsigned visited : 1;
  145. unsigned on_sccstack : 1;
  146. /* Whether the representative expression contains constants. */
  147. unsigned has_constants : 1;
  148. /* Whether the SSA_NAME has been value numbered already. This is
  149. only saying whether visit_use has been called on it at least
  150. once. It cannot be used to avoid visitation for SSA_NAME's
  151. involved in non-singleton SCC's. */
  152. unsigned use_processed : 1;
  153. /* Whether the SSA_NAME has no defining statement and thus an
  154. insertion of such with EXPR as definition is required before
  155. a use can be created of it. */
  156. unsigned needs_insertion : 1;
  157. } *vn_ssa_aux_t;
  158. typedef enum { VN_NOWALK, VN_WALK, VN_WALKREWRITE } vn_lookup_kind;
  159. /* Return the value numbering info for an SSA_NAME. */
  160. extern vn_ssa_aux_t VN_INFO (tree);
  161. extern vn_ssa_aux_t VN_INFO_GET (tree);
  162. tree vn_get_expr_for (tree);
  163. bool run_scc_vn (vn_lookup_kind);
  164. void free_scc_vn (void);
  165. tree vn_nary_op_lookup (tree, vn_nary_op_t *);
  166. tree vn_nary_op_lookup_stmt (gimple, vn_nary_op_t *);
  167. tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code,
  168. tree, tree *, vn_nary_op_t *);
  169. vn_nary_op_t vn_nary_op_insert (tree, tree);
  170. vn_nary_op_t vn_nary_op_insert_stmt (gimple, tree);
  171. vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code,
  172. tree, tree *, tree, unsigned int);
  173. void vn_reference_fold_indirect (vec<vn_reference_op_s> *,
  174. unsigned int *);
  175. bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree,
  176. vec<vn_reference_op_s> );
  177. tree vn_reference_lookup_pieces (tree, alias_set_type, tree,
  178. vec<vn_reference_op_s> ,
  179. vn_reference_t *, vn_lookup_kind);
  180. tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *);
  181. void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t);
  182. vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree,
  183. vec<vn_reference_op_s> ,
  184. tree, unsigned int);
  185. bool vn_nary_op_eq (const_vn_nary_op_t const vno1,
  186. const_vn_nary_op_t const vno2);
  187. bool vn_nary_may_trap (vn_nary_op_t);
  188. bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const);
  189. unsigned int get_max_value_id (void);
  190. unsigned int get_next_value_id (void);
  191. unsigned int get_constant_value_id (tree);
  192. unsigned int get_or_alloc_constant_value_id (tree);
  193. bool value_id_constant_p (unsigned int);
  194. tree fully_constant_vn_reference_p (vn_reference_t);
  195. /* Valueize NAME if it is an SSA name, otherwise just return it. */
  196. static inline tree
  197. vn_valueize (tree name)
  198. {
  199. if (TREE_CODE (name) == SSA_NAME)
  200. {
  201. tree tem = VN_INFO (name)->valnum;
  202. return tem == VN_TOP ? name : tem;
  203. }
  204. return name;
  205. }
  206. #endif /* TREE_SSA_SCCVN_H */