]>
Commit | Line | Data |
---|---|---|
89fb70a3 | 1 | /* Tree SCC value numbering |
85ec4feb | 2 | Copyright (C) 2007-2018 Free Software Foundation, Inc. |
89fb70a3 DB |
3 | Contributed by Daniel Berlin <dberlin@dberlin.org> |
4 | ||
9dcd6f09 NC |
5 | This file is part of GCC. |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify | |
8 | under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GCC; see the file COPYING3. If not see | |
19 | <http://www.gnu.org/licenses/>. */ | |
89fb70a3 DB |
20 | |
21 | #ifndef TREE_SSA_SCCVN_H | |
22 | #define TREE_SSA_SCCVN_H | |
23 | ||
b2ad0284 BRF |
24 | /* In tree-ssa-sccvn.c */ |
25 | bool expressions_equal_p (tree, tree); | |
26 | ||
27 | ||
89fb70a3 DB |
28 | /* TOP of the VN lattice. */ |
29 | extern tree VN_TOP; | |
30 | ||
c9145754 DB |
31 | /* N-ary operations in the hashtable consist of length operands, an |
32 | opcode, and a type. Result is the value number of the operation, | |
33 | and hashcode is stored to avoid having to calculate it | |
34 | repeatedly. */ | |
35 | ||
36 | typedef struct vn_nary_op_s | |
37 | { | |
38 | /* Unique identify that all expressions with the same value have. */ | |
39 | unsigned int value_id; | |
40 | ENUM_BITFIELD(tree_code) opcode : 16; | |
41 | unsigned length : 16; | |
42 | hashval_t hashcode; | |
43 | tree result; | |
44 | tree type; | |
5a7d7f9c | 45 | tree op[1]; |
c9145754 DB |
46 | } *vn_nary_op_t; |
47 | typedef const struct vn_nary_op_s *const_vn_nary_op_t; | |
48 | ||
5a7d7f9c RG |
49 | /* Return the size of a vn_nary_op_t with LENGTH operands. */ |
50 | ||
51 | static inline size_t | |
52 | sizeof_vn_nary_op (unsigned int length) | |
53 | { | |
91af9dc9 | 54 | return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree); |
5a7d7f9c RG |
55 | } |
56 | ||
c9145754 DB |
57 | /* Phi nodes in the hashtable consist of their non-VN_TOP phi |
58 | arguments, and the basic block the phi is in. Result is the value | |
59 | number of the operation, and hashcode is stored to avoid having to | |
60 | calculate it repeatedly. Phi nodes not in the same block are never | |
61 | considered equivalent. */ | |
62 | ||
63 | typedef struct vn_phi_s | |
64 | { | |
65 | /* Unique identifier that all expressions with the same value have. */ | |
66 | unsigned int value_id; | |
67 | hashval_t hashcode; | |
9771b263 | 68 | vec<tree> phiargs; |
c9145754 | 69 | basic_block block; |
8ee1b0a0 RB |
70 | /* Controlling condition lhs/rhs. */ |
71 | tree cclhs; | |
72 | tree ccrhs; | |
24d63016 | 73 | tree type; |
c9145754 DB |
74 | tree result; |
75 | } *vn_phi_t; | |
76 | typedef const struct vn_phi_s *const_vn_phi_t; | |
77 | ||
78 | /* Reference operands only exist in reference operations structures. | |
79 | They consist of an opcode, type, and some number of operands. For | |
80 | a given opcode, some, all, or none of the operands may be used. | |
81 | The operands are there to store the information that makes up the | |
82 | portion of the addressing calculation that opcode performs. */ | |
83 | ||
84 | typedef struct vn_reference_op_struct | |
85 | { | |
d5e254e1 | 86 | ENUM_BITFIELD(tree_code) opcode : 16; |
1fefbb66 RB |
87 | /* Dependence info, used for [TARGET_]MEM_REF only. */ |
88 | unsigned short clique; | |
89 | unsigned short base; | |
cef5388d RB |
90 | unsigned reverse : 1; |
91 | /* For storing TYPE_ALIGN for array ref element size computation. */ | |
92 | unsigned align : 6; | |
70f34814 | 93 | /* Constant offset this op adds or -1 if it is variable. */ |
b9c25734 | 94 | poly_int64_pod off; |
c9145754 DB |
95 | tree type; |
96 | tree op0; | |
97 | tree op1; | |
98 | tree op2; | |
99 | } vn_reference_op_s; | |
100 | typedef vn_reference_op_s *vn_reference_op_t; | |
101 | typedef const vn_reference_op_s *const_vn_reference_op_t; | |
102 | ||
cef5388d RB |
103 | inline unsigned |
104 | vn_ref_op_align_unit (vn_reference_op_t op) | |
105 | { | |
106 | return op->align ? ((unsigned)1 << (op->align - 1)) / BITS_PER_UNIT : 0; | |
107 | } | |
c9145754 | 108 | |
5006671f RG |
109 | /* A reference operation in the hashtable is representation as |
110 | the vuse, representing the memory state at the time of | |
c9145754 DB |
111 | the operation, and a collection of operands that make up the |
112 | addressing calculation. If two vn_reference_t's have the same set | |
113 | of operands, they access the same memory location. We also store | |
5006671f | 114 | the resulting value number, and the hashcode. */ |
c9145754 DB |
115 | |
116 | typedef struct vn_reference_s | |
117 | { | |
118 | /* Unique identifier that all expressions with the same value have. */ | |
119 | unsigned int value_id; | |
120 | hashval_t hashcode; | |
5006671f | 121 | tree vuse; |
b45d2719 RG |
122 | alias_set_type set; |
123 | tree type; | |
9771b263 | 124 | vec<vn_reference_op_s> operands; |
c9145754 | 125 | tree result; |
00115921 | 126 | tree result_vdef; |
c9145754 DB |
127 | } *vn_reference_t; |
128 | typedef const struct vn_reference_s *const_vn_reference_t; | |
129 | ||
130 | typedef struct vn_constant_s | |
131 | { | |
132 | unsigned int value_id; | |
133 | hashval_t hashcode; | |
134 | tree constant; | |
135 | } *vn_constant_t; | |
726a989a | 136 | |
17742d62 | 137 | enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI }; |
355fe088 | 138 | enum vn_kind vn_get_stmt_kind (gimple *); |
17742d62 | 139 | |
24d63016 RB |
140 | /* Hash the type TYPE using bits that distinguishes it in the |
141 | types_compatible_p sense. */ | |
142 | ||
143 | static inline hashval_t | |
144 | vn_hash_type (tree type) | |
145 | { | |
146 | return (INTEGRAL_TYPE_P (type) | |
147 | + (INTEGRAL_TYPE_P (type) | |
148 | ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0)); | |
149 | } | |
150 | ||
726a989a RB |
151 | /* Hash the constant CONSTANT with distinguishing type incompatible |
152 | constants in the types_compatible_p sense. */ | |
153 | ||
154 | static inline hashval_t | |
155 | vn_hash_constant_with_type (tree constant) | |
156 | { | |
4e44a6e8 AK |
157 | inchash::hash hstate; |
158 | inchash::add_expr (constant, hstate); | |
159 | hstate.merge_hash (vn_hash_type (TREE_TYPE (constant))); | |
160 | return hstate.end (); | |
726a989a RB |
161 | } |
162 | ||
163 | /* Compare the constants C1 and C2 with distinguishing type incompatible | |
164 | constants in the types_compatible_p sense. */ | |
165 | ||
166 | static inline bool | |
167 | vn_constant_eq_with_type (tree c1, tree c2) | |
168 | { | |
169 | return (expressions_equal_p (c1, c2) | |
170 | && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2))); | |
171 | } | |
172 | ||
89fb70a3 DB |
173 | typedef struct vn_ssa_aux |
174 | { | |
89fb70a3 DB |
175 | /* Value number. This may be an SSA name or a constant. */ |
176 | tree valnum; | |
34050b6b RB |
177 | /* Statements to insert if needs_insertion is true. */ |
178 | gimple_seq expr; | |
71ae8557 | 179 | |
e93c66bc RB |
180 | /* Saved SSA name info. */ |
181 | tree_ssa_name::ssa_name_info_type info; | |
182 | ||
c9145754 DB |
183 | /* Unique identifier that all expressions with the same value have. */ |
184 | unsigned int value_id; | |
185 | ||
71ae8557 SB |
186 | /* SCC information. */ |
187 | unsigned int dfsnum; | |
188 | unsigned int low; | |
189 | unsigned visited : 1; | |
190 | unsigned on_sccstack : 1; | |
191 | ||
89fb70a3 DB |
192 | /* Whether the SSA_NAME has been value numbered already. This is |
193 | only saying whether visit_use has been called on it at least | |
194 | once. It cannot be used to avoid visitation for SSA_NAME's | |
195 | involved in non-singleton SCC's. */ | |
71ae8557 | 196 | unsigned use_processed : 1; |
3d45dd59 RG |
197 | |
198 | /* Whether the SSA_NAME has no defining statement and thus an | |
199 | insertion of such with EXPR as definition is required before | |
200 | a use can be created of it. */ | |
201 | unsigned needs_insertion : 1; | |
fa4511c2 RB |
202 | |
203 | /* Whether range-info is anti-range. */ | |
204 | unsigned range_info_anti_range_p : 1; | |
89fb70a3 DB |
205 | } *vn_ssa_aux_t; |
206 | ||
a79683d5 | 207 | enum vn_lookup_kind { VN_NOWALK, VN_WALK, VN_WALKREWRITE }; |
1ec87690 | 208 | |
89fb70a3 | 209 | /* Return the value numbering info for an SSA_NAME. */ |
7af1c0ad | 210 | bool has_VN_INFO (tree); |
89fb70a3 DB |
211 | extern vn_ssa_aux_t VN_INFO (tree); |
212 | extern vn_ssa_aux_t VN_INFO_GET (tree); | |
726a989a | 213 | tree vn_get_expr_for (tree); |
24c40f9a | 214 | void run_scc_vn (vn_lookup_kind); |
5de583cc | 215 | unsigned int vn_eliminate (bitmap); |
89fb70a3 | 216 | void free_scc_vn (void); |
65f52ee9 | 217 | void scc_vn_restore_ssa_info (void); |
c9145754 | 218 | tree vn_nary_op_lookup (tree, vn_nary_op_t *); |
355fe088 | 219 | tree vn_nary_op_lookup_stmt (gimple *, vn_nary_op_t *); |
c9145754 | 220 | tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code, |
5a7d7f9c | 221 | tree, tree *, vn_nary_op_t *); |
c9145754 DB |
222 | vn_nary_op_t vn_nary_op_insert (tree, tree); |
223 | vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code, | |
5a7d7f9c | 224 | tree, tree *, tree, unsigned int); |
b45d2719 | 225 | bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree, |
9771b263 | 226 | vec<vn_reference_op_s> ); |
3c5b29f5 | 227 | vec<vn_reference_op_s> vn_reference_operands_for_lookup (tree); |
b45d2719 | 228 | tree vn_reference_lookup_pieces (tree, alias_set_type, tree, |
9771b263 | 229 | vec<vn_reference_op_s> , |
3bc27de7 | 230 | vn_reference_t *, vn_lookup_kind); |
1c48bff1 | 231 | tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *, bool); |
538dd0b7 | 232 | void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t); |
b45d2719 | 233 | vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree, |
9771b263 | 234 | vec<vn_reference_op_s> , |
c9145754 DB |
235 | tree, unsigned int); |
236 | ||
bf190e8d LC |
237 | bool vn_nary_op_eq (const_vn_nary_op_t const vno1, |
238 | const_vn_nary_op_t const vno2); | |
890065bf | 239 | bool vn_nary_may_trap (vn_nary_op_t); |
bf190e8d | 240 | bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const); |
c9145754 DB |
241 | unsigned int get_max_value_id (void); |
242 | unsigned int get_next_value_id (void); | |
bb9e4199 | 243 | unsigned int get_constant_value_id (tree); |
c9145754 DB |
244 | unsigned int get_or_alloc_constant_value_id (tree); |
245 | bool value_id_constant_p (unsigned int); | |
12bd5a1e | 246 | tree fully_constant_vn_reference_p (vn_reference_t); |
351168fe | 247 | tree vn_nary_simplify (vn_nary_op_t); |
c9e93168 TV |
248 | |
249 | /* Valueize NAME if it is an SSA name, otherwise just return it. */ | |
250 | ||
251 | static inline tree | |
252 | vn_valueize (tree name) | |
253 | { | |
254 | if (TREE_CODE (name) == SSA_NAME) | |
255 | { | |
256 | tree tem = VN_INFO (name)->valnum; | |
257 | return tem == VN_TOP ? name : tem; | |
258 | } | |
259 | return name; | |
260 | } | |
261 | ||
dd6f2cf9 RB |
262 | /* Get at the original range info for NAME. */ |
263 | ||
264 | inline range_info_def * | |
265 | VN_INFO_RANGE_INFO (tree name) | |
266 | { | |
267 | return (VN_INFO (name)->info.range_info | |
268 | ? VN_INFO (name)->info.range_info | |
269 | : SSA_NAME_RANGE_INFO (name)); | |
270 | } | |
271 | ||
fa4511c2 RB |
272 | /* Whether the original range info of NAME is an anti-range. */ |
273 | ||
274 | inline bool | |
275 | VN_INFO_ANTI_RANGE_P (tree name) | |
276 | { | |
277 | return (VN_INFO (name)->info.range_info | |
278 | ? VN_INFO (name)->range_info_anti_range_p | |
279 | : SSA_NAME_ANTI_RANGE_P (name)); | |
280 | } | |
281 | ||
282 | /* Get at the original range info kind for NAME. */ | |
283 | ||
284 | inline value_range_type | |
285 | VN_INFO_RANGE_TYPE (tree name) | |
286 | { | |
287 | return VN_INFO_ANTI_RANGE_P (name) ? VR_ANTI_RANGE : VR_RANGE; | |
288 | } | |
289 | ||
dd6f2cf9 RB |
290 | /* Get at the original pointer info for NAME. */ |
291 | ||
292 | inline ptr_info_def * | |
293 | VN_INFO_PTR_INFO (tree name) | |
294 | { | |
295 | return (VN_INFO (name)->info.ptr_info | |
296 | ? VN_INFO (name)->info.ptr_info | |
297 | : SSA_NAME_PTR_INFO (name)); | |
298 | } | |
299 | ||
89fb70a3 | 300 | #endif /* TREE_SSA_SCCVN_H */ |