tree-ssa-sccvn.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* Tree SCC value numbering
  2. Copyright (C) 2007-2019 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. /* A predicated value. */
  23. struct vn_pval
  24. {
  25. vn_pval *next;
  26. /* The value of the expression this is attached to is RESULT in
  27. case the expression is computed dominated by one of the blocks
  28. in valid_dominated_by_p. */
  29. tree result;
  30. unsigned n;
  31. int valid_dominated_by_p[1];
  32. };
  33. /* N-ary operations in the hashtable consist of length operands, an
  34. opcode, and a type. Result is the value number of the operation,
  35. and hashcode is stored to avoid having to calculate it
  36. repeatedly. */
  37. typedef struct vn_nary_op_s
  38. {
  39. vn_nary_op_s *next;
  40. vn_nary_op_s *unwind_to;
  41. /* Unique identify that all expressions with the same value have. */
  42. unsigned int value_id;
  43. ENUM_BITFIELD(tree_code) opcode : 16;
  44. unsigned length : 16;
  45. hashval_t hashcode;
  46. unsigned predicated_values : 1;
  47. union {
  48. /* If ! predicated_values this is the value of the expression. */
  49. tree result;
  50. /* If predicated_values this is a list of values of the expression. */
  51. vn_pval *values;
  52. } u;
  53. tree type;
  54. tree op[1];
  55. } *vn_nary_op_t;
  56. typedef const struct vn_nary_op_s *const_vn_nary_op_t;
  57. /* Return the size of a vn_nary_op_t with LENGTH operands. */
  58. static inline size_t
  59. sizeof_vn_nary_op (unsigned int length)
  60. {
  61. return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree);
  62. }
  63. /* Phi nodes in the hashtable consist of their non-VN_TOP phi
  64. arguments, and the basic block the phi is in. Result is the value
  65. number of the operation, and hashcode is stored to avoid having to
  66. calculate it repeatedly. Phi nodes not in the same block are never
  67. considered equivalent. */
  68. typedef struct vn_phi_s
  69. {
  70. vn_phi_s *next;
  71. /* Unique identifier that all expressions with the same value have. */
  72. unsigned int value_id;
  73. hashval_t hashcode;
  74. basic_block block;
  75. /* Controlling condition lhs/rhs. */
  76. tree cclhs;
  77. tree ccrhs;
  78. tree type;
  79. tree result;
  80. /* The number of args is determined by EDGE_COUT (block->preds). */
  81. tree phiargs[1];
  82. } *vn_phi_t;
  83. typedef const struct vn_phi_s *const_vn_phi_t;
  84. /* Reference operands only exist in reference operations structures.
  85. They consist of an opcode, type, and some number of operands. For
  86. a given opcode, some, all, or none of the operands may be used.
  87. The operands are there to store the information that makes up the
  88. portion of the addressing calculation that opcode performs. */
  89. typedef struct vn_reference_op_struct
  90. {
  91. ENUM_BITFIELD(tree_code) opcode : 16;
  92. /* Dependence info, used for [TARGET_]MEM_REF only. */
  93. unsigned short clique;
  94. unsigned short base;
  95. unsigned reverse : 1;
  96. /* For storing TYPE_ALIGN for array ref element size computation. */
  97. unsigned align : 6;
  98. /* Constant offset this op adds or -1 if it is variable. */
  99. poly_int64_pod off;
  100. tree type;
  101. tree op0;
  102. tree op1;
  103. tree op2;
  104. } vn_reference_op_s;
  105. typedef vn_reference_op_s *vn_reference_op_t;
  106. typedef const vn_reference_op_s *const_vn_reference_op_t;
  107. inline unsigned
  108. vn_ref_op_align_unit (vn_reference_op_t op)
  109. {
  110. return op->align ? ((unsigned)1 << (op->align - 1)) / BITS_PER_UNIT : 0;
  111. }
  112. /* A reference operation in the hashtable is representation as
  113. the vuse, representing the memory state at the time of
  114. the operation, and a collection of operands that make up the
  115. addressing calculation. If two vn_reference_t's have the same set
  116. of operands, they access the same memory location. We also store
  117. the resulting value number, and the hashcode. */
  118. typedef struct vn_reference_s
  119. {
  120. vn_reference_s *next;
  121. /* Unique identifier that all expressions with the same value have. */
  122. unsigned int value_id;
  123. hashval_t hashcode;
  124. tree vuse;
  125. alias_set_type set;
  126. tree type;
  127. vec<vn_reference_op_s> operands;
  128. tree result;
  129. tree result_vdef;
  130. } *vn_reference_t;
  131. typedef const struct vn_reference_s *const_vn_reference_t;
  132. typedef struct vn_constant_s
  133. {
  134. unsigned int value_id;
  135. hashval_t hashcode;
  136. tree constant;
  137. } *vn_constant_t;
  138. enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI };
  139. enum vn_kind vn_get_stmt_kind (gimple *);
  140. /* Hash the type TYPE using bits that distinguishes it in the
  141. types_compatible_p sense. */
  142. static inline hashval_t
  143. vn_hash_type (tree type)
  144. {
  145. return (INTEGRAL_TYPE_P (type)
  146. + (INTEGRAL_TYPE_P (type)
  147. ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0));
  148. }
  149. /* Hash the constant CONSTANT with distinguishing type incompatible
  150. constants in the types_compatible_p sense. */
  151. static inline hashval_t
  152. vn_hash_constant_with_type (tree constant)
  153. {
  154. inchash::hash hstate;
  155. inchash::add_expr (constant, hstate);
  156. hstate.merge_hash (vn_hash_type (TREE_TYPE (constant)));
  157. return hstate.end ();
  158. }
  159. /* Compare the constants C1 and C2 with distinguishing type incompatible
  160. constants in the types_compatible_p sense. */
  161. static inline bool
  162. vn_constant_eq_with_type (tree c1, tree c2)
  163. {
  164. return (expressions_equal_p (c1, c2)
  165. && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2)));
  166. }
  167. typedef struct vn_ssa_aux
  168. {
  169. /* SSA name this vn_ssa_aux is associated with in the lattice. */
  170. tree name;
  171. /* Value number. This may be an SSA name or a constant. */
  172. tree valnum;
  173. /* Statements to insert if needs_insertion is true. */
  174. gimple_seq expr;
  175. /* Unique identifier that all expressions with the same value have. */
  176. unsigned int value_id;
  177. /* Whether the SSA_NAME has been processed at least once. */
  178. unsigned visited : 1;
  179. /* Whether the SSA_NAME has no defining statement and thus an
  180. insertion of such with EXPR as definition is required before
  181. a use can be created of it. */
  182. unsigned needs_insertion : 1;
  183. } *vn_ssa_aux_t;
  184. enum vn_lookup_kind { VN_NOWALK, VN_WALK, VN_WALKREWRITE };
  185. /* Return the value numbering info for an SSA_NAME. */
  186. bool has_VN_INFO (tree);
  187. extern vn_ssa_aux_t VN_INFO (tree);
  188. tree vn_get_expr_for (tree);
  189. void scc_vn_restore_ssa_info (void);
  190. tree vn_nary_op_lookup (tree, vn_nary_op_t *);
  191. tree vn_nary_op_lookup_stmt (gimple *, vn_nary_op_t *);
  192. tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code,
  193. tree, tree *, vn_nary_op_t *);
  194. vn_nary_op_t vn_nary_op_insert (tree, tree);
  195. vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code,
  196. tree, tree *, tree, unsigned int);
  197. bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree,
  198. vec<vn_reference_op_s> );
  199. vec<vn_reference_op_s> vn_reference_operands_for_lookup (tree);
  200. tree vn_reference_lookup_pieces (tree, alias_set_type, tree,
  201. vec<vn_reference_op_s> ,
  202. vn_reference_t *, vn_lookup_kind);
  203. tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *, bool,
  204. tree * = NULL);
  205. void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t);
  206. vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree,
  207. vec<vn_reference_op_s> ,
  208. tree, unsigned int);
  209. bool vn_nary_op_eq (const_vn_nary_op_t const vno1,
  210. const_vn_nary_op_t const vno2);
  211. bool vn_nary_may_trap (vn_nary_op_t);
  212. bool vn_reference_may_trap (vn_reference_t);
  213. bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const);
  214. unsigned int get_max_value_id (void);
  215. unsigned int get_next_value_id (void);
  216. unsigned int get_constant_value_id (tree);
  217. unsigned int get_or_alloc_constant_value_id (tree);
  218. bool value_id_constant_p (unsigned int);
  219. tree fully_constant_vn_reference_p (vn_reference_t);
  220. tree vn_nary_simplify (vn_nary_op_t);
  221. unsigned do_rpo_vn (function *, edge, bitmap);
  222. void run_rpo_vn (vn_lookup_kind);
  223. unsigned eliminate_with_rpo_vn (bitmap);
  224. void free_rpo_vn (void);
  225. /* Valueize NAME if it is an SSA name, otherwise just return it. This hook
  226. is initialized by run_scc_vn. */
  227. extern tree (*vn_valueize) (tree);
  228. /* Context that valueization should operate on. */
  229. extern basic_block vn_context_bb;
  230. #endif /* TREE_SSA_SCCVN_H */