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