]>
Commit | Line | Data |
---|---|---|
89fb70a3 | 1 | /* Tree SCC value numbering |
8d9254fc | 2 | Copyright (C) 2007-2020 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 | ||
78ea9abc RB |
31 | /* A predicated value. */ |
32 | struct vn_pval | |
33 | { | |
34 | vn_pval *next; | |
35 | /* The value of the expression this is attached to is RESULT in | |
36 | case the expression is computed dominated by one of the blocks | |
37 | in valid_dominated_by_p. */ | |
38 | tree result; | |
39 | unsigned n; | |
40 | int valid_dominated_by_p[1]; | |
41 | }; | |
42 | ||
c9145754 DB |
43 | /* N-ary operations in the hashtable consist of length operands, an |
44 | opcode, and a type. Result is the value number of the operation, | |
45 | and hashcode is stored to avoid having to calculate it | |
46 | repeatedly. */ | |
47 | ||
48 | typedef struct vn_nary_op_s | |
49 | { | |
b89ffb98 | 50 | vn_nary_op_s *next; |
78ea9abc | 51 | vn_nary_op_s *unwind_to; |
c9145754 DB |
52 | /* Unique identify that all expressions with the same value have. */ |
53 | unsigned int value_id; | |
54 | ENUM_BITFIELD(tree_code) opcode : 16; | |
55 | unsigned length : 16; | |
56 | hashval_t hashcode; | |
78ea9abc RB |
57 | unsigned predicated_values : 1; |
58 | union { | |
59 | /* If ! predicated_values this is the value of the expression. */ | |
60 | tree result; | |
61 | /* If predicated_values this is a list of values of the expression. */ | |
62 | vn_pval *values; | |
63 | } u; | |
c9145754 | 64 | tree type; |
5a7d7f9c | 65 | tree op[1]; |
c9145754 DB |
66 | } *vn_nary_op_t; |
67 | typedef const struct vn_nary_op_s *const_vn_nary_op_t; | |
68 | ||
5a7d7f9c RG |
69 | /* Return the size of a vn_nary_op_t with LENGTH operands. */ |
70 | ||
71 | static inline size_t | |
72 | sizeof_vn_nary_op (unsigned int length) | |
73 | { | |
91af9dc9 | 74 | return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree); |
5a7d7f9c RG |
75 | } |
76 | ||
c9145754 DB |
77 | /* Phi nodes in the hashtable consist of their non-VN_TOP phi |
78 | arguments, and the basic block the phi is in. Result is the value | |
79 | number of the operation, and hashcode is stored to avoid having to | |
80 | calculate it repeatedly. Phi nodes not in the same block are never | |
81 | considered equivalent. */ | |
82 | ||
83 | typedef struct vn_phi_s | |
84 | { | |
b89ffb98 | 85 | vn_phi_s *next; |
c9145754 DB |
86 | /* Unique identifier that all expressions with the same value have. */ |
87 | unsigned int value_id; | |
88 | hashval_t hashcode; | |
c9145754 | 89 | basic_block block; |
8ee1b0a0 RB |
90 | /* Controlling condition lhs/rhs. */ |
91 | tree cclhs; | |
92 | tree ccrhs; | |
24d63016 | 93 | tree type; |
c9145754 | 94 | tree result; |
851fd366 RB |
95 | /* The number of args is determined by EDGE_COUT (block->preds). */ |
96 | tree phiargs[1]; | |
c9145754 DB |
97 | } *vn_phi_t; |
98 | typedef const struct vn_phi_s *const_vn_phi_t; | |
99 | ||
100 | /* Reference operands only exist in reference operations structures. | |
101 | They consist of an opcode, type, and some number of operands. For | |
102 | a given opcode, some, all, or none of the operands may be used. | |
103 | The operands are there to store the information that makes up the | |
104 | portion of the addressing calculation that opcode performs. */ | |
105 | ||
106 | typedef struct vn_reference_op_struct | |
107 | { | |
d5e254e1 | 108 | ENUM_BITFIELD(tree_code) opcode : 16; |
1fefbb66 RB |
109 | /* Dependence info, used for [TARGET_]MEM_REF only. */ |
110 | unsigned short clique; | |
111 | unsigned short base; | |
cef5388d RB |
112 | unsigned reverse : 1; |
113 | /* For storing TYPE_ALIGN for array ref element size computation. */ | |
114 | unsigned align : 6; | |
70f34814 | 115 | /* Constant offset this op adds or -1 if it is variable. */ |
b9c25734 | 116 | poly_int64_pod off; |
c9145754 DB |
117 | tree type; |
118 | tree op0; | |
119 | tree op1; | |
120 | tree op2; | |
121 | } vn_reference_op_s; | |
122 | typedef vn_reference_op_s *vn_reference_op_t; | |
123 | typedef const vn_reference_op_s *const_vn_reference_op_t; | |
124 | ||
cef5388d RB |
125 | inline unsigned |
126 | vn_ref_op_align_unit (vn_reference_op_t op) | |
127 | { | |
128 | return op->align ? ((unsigned)1 << (op->align - 1)) / BITS_PER_UNIT : 0; | |
129 | } | |
c9145754 | 130 | |
5006671f RG |
131 | /* A reference operation in the hashtable is representation as |
132 | the vuse, representing the memory state at the time of | |
c9145754 DB |
133 | the operation, and a collection of operands that make up the |
134 | addressing calculation. If two vn_reference_t's have the same set | |
135 | of operands, they access the same memory location. We also store | |
5006671f | 136 | the resulting value number, and the hashcode. */ |
c9145754 DB |
137 | |
138 | typedef struct vn_reference_s | |
139 | { | |
b89ffb98 | 140 | vn_reference_s *next; |
c9145754 DB |
141 | /* Unique identifier that all expressions with the same value have. */ |
142 | unsigned int value_id; | |
143 | hashval_t hashcode; | |
5006671f | 144 | tree vuse; |
b45d2719 | 145 | alias_set_type set; |
3d6fd7ce | 146 | alias_set_type base_set; |
b45d2719 | 147 | tree type; |
9771b263 | 148 | vec<vn_reference_op_s> operands; |
c9145754 | 149 | tree result; |
00115921 | 150 | tree result_vdef; |
c9145754 DB |
151 | } *vn_reference_t; |
152 | typedef const struct vn_reference_s *const_vn_reference_t; | |
153 | ||
154 | typedef struct vn_constant_s | |
155 | { | |
156 | unsigned int value_id; | |
157 | hashval_t hashcode; | |
158 | tree constant; | |
159 | } *vn_constant_t; | |
726a989a | 160 | |
17742d62 | 161 | enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI }; |
355fe088 | 162 | enum vn_kind vn_get_stmt_kind (gimple *); |
17742d62 | 163 | |
24d63016 RB |
164 | /* Hash the type TYPE using bits that distinguishes it in the |
165 | types_compatible_p sense. */ | |
166 | ||
167 | static inline hashval_t | |
168 | vn_hash_type (tree type) | |
169 | { | |
170 | return (INTEGRAL_TYPE_P (type) | |
171 | + (INTEGRAL_TYPE_P (type) | |
172 | ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0)); | |
173 | } | |
174 | ||
726a989a RB |
175 | /* Hash the constant CONSTANT with distinguishing type incompatible |
176 | constants in the types_compatible_p sense. */ | |
177 | ||
178 | static inline hashval_t | |
179 | vn_hash_constant_with_type (tree constant) | |
180 | { | |
4e44a6e8 AK |
181 | inchash::hash hstate; |
182 | inchash::add_expr (constant, hstate); | |
183 | hstate.merge_hash (vn_hash_type (TREE_TYPE (constant))); | |
184 | return hstate.end (); | |
726a989a RB |
185 | } |
186 | ||
187 | /* Compare the constants C1 and C2 with distinguishing type incompatible | |
188 | constants in the types_compatible_p sense. */ | |
189 | ||
190 | static inline bool | |
191 | vn_constant_eq_with_type (tree c1, tree c2) | |
192 | { | |
193 | return (expressions_equal_p (c1, c2) | |
194 | && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2))); | |
195 | } | |
196 | ||
390c0dd6 RB |
197 | /* Instead of having a local availability lattice for each basic-block |
198 | and availability at X defined as union of the local availabilities | |
199 | at X and its dominators we're turning this upside down and track | |
200 | availability per value given values are usually made available at very | |
201 | few points. | |
202 | So we have a chain of LOCATION, LEADER entries where LOCATION is | |
203 | specifying the basic-block LEADER is made available for VALUE. | |
204 | We prepend to this chain in RPO order thus for iteration we can simply | |
205 | remove the last entries. | |
206 | LOCATION is the basic-block index and LEADER is its SSA name version. */ | |
207 | struct vn_avail | |
208 | { | |
209 | vn_avail *next; | |
210 | /* The basic-block LEADER is made available. */ | |
211 | int location; | |
212 | /* The LEADER for the value we are chained on. */ | |
213 | int leader; | |
214 | }; | |
215 | ||
89fb70a3 DB |
216 | typedef struct vn_ssa_aux |
217 | { | |
78ea9abc RB |
218 | /* SSA name this vn_ssa_aux is associated with in the lattice. */ |
219 | tree name; | |
89fb70a3 DB |
220 | /* Value number. This may be an SSA name or a constant. */ |
221 | tree valnum; | |
34050b6b RB |
222 | /* Statements to insert if needs_insertion is true. */ |
223 | gimple_seq expr; | |
71ae8557 | 224 | |
390c0dd6 RB |
225 | /* AVAIL entries, last in RPO order is first. This is only tracked |
226 | for SSA names also serving as values (NAME == VALNUM). */ | |
227 | vn_avail *avail; | |
228 | ||
c9145754 DB |
229 | /* Unique identifier that all expressions with the same value have. */ |
230 | unsigned int value_id; | |
231 | ||
78ea9abc | 232 | /* Whether the SSA_NAME has been processed at least once. */ |
71ae8557 | 233 | unsigned visited : 1; |
3d45dd59 RG |
234 | |
235 | /* Whether the SSA_NAME has no defining statement and thus an | |
236 | insertion of such with EXPR as definition is required before | |
237 | a use can be created of it. */ | |
238 | unsigned needs_insertion : 1; | |
89fb70a3 DB |
239 | } *vn_ssa_aux_t; |
240 | ||
a79683d5 | 241 | enum vn_lookup_kind { VN_NOWALK, VN_WALK, VN_WALKREWRITE }; |
1ec87690 | 242 | |
89fb70a3 | 243 | /* Return the value numbering info for an SSA_NAME. */ |
7af1c0ad | 244 | bool has_VN_INFO (tree); |
89fb70a3 | 245 | extern vn_ssa_aux_t VN_INFO (tree); |
726a989a | 246 | tree vn_get_expr_for (tree); |
65f52ee9 | 247 | void scc_vn_restore_ssa_info (void); |
355fe088 | 248 | tree vn_nary_op_lookup_stmt (gimple *, vn_nary_op_t *); |
c9145754 | 249 | tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code, |
5a7d7f9c | 250 | tree, tree *, vn_nary_op_t *); |
c9145754 | 251 | vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code, |
5a7d7f9c | 252 | tree, tree *, tree, unsigned int); |
3d6fd7ce RB |
253 | bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, alias_set_type, |
254 | tree, vec<vn_reference_op_s> ); | |
3c5b29f5 | 255 | vec<vn_reference_op_s> vn_reference_operands_for_lookup (tree); |
3d6fd7ce | 256 | tree vn_reference_lookup_pieces (tree, alias_set_type, alias_set_type, tree, |
9771b263 | 257 | vec<vn_reference_op_s> , |
3bc27de7 | 258 | vn_reference_t *, vn_lookup_kind); |
ee7904e9 | 259 | tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *, bool, |
b07e4e7c | 260 | tree * = NULL, tree = NULL_TREE); |
538dd0b7 | 261 | void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t); |
3d6fd7ce RB |
262 | vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, alias_set_type, |
263 | tree, vec<vn_reference_op_s>, | |
c9145754 DB |
264 | tree, unsigned int); |
265 | ||
bf190e8d LC |
266 | bool vn_nary_op_eq (const_vn_nary_op_t const vno1, |
267 | const_vn_nary_op_t const vno2); | |
890065bf | 268 | bool vn_nary_may_trap (vn_nary_op_t); |
3bab7385 | 269 | bool vn_reference_may_trap (vn_reference_t); |
bf190e8d | 270 | bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const); |
c9145754 DB |
271 | unsigned int get_max_value_id (void); |
272 | unsigned int get_next_value_id (void); | |
bb9e4199 | 273 | unsigned int get_constant_value_id (tree); |
c9145754 DB |
274 | unsigned int get_or_alloc_constant_value_id (tree); |
275 | bool value_id_constant_p (unsigned int); | |
12bd5a1e | 276 | tree fully_constant_vn_reference_p (vn_reference_t); |
351168fe | 277 | tree vn_nary_simplify (vn_nary_op_t); |
c9e93168 | 278 | |
78ea9abc RB |
279 | unsigned do_rpo_vn (function *, edge, bitmap); |
280 | void run_rpo_vn (vn_lookup_kind); | |
281 | unsigned eliminate_with_rpo_vn (bitmap); | |
282 | void free_rpo_vn (void); | |
c9e93168 | 283 | |
78ea9abc RB |
284 | /* Valueize NAME if it is an SSA name, otherwise just return it. This hook |
285 | is initialized by run_scc_vn. */ | |
286 | extern tree (*vn_valueize) (tree); | |
dd6f2cf9 | 287 | |
78ea9abc RB |
288 | /* Context that valueization should operate on. */ |
289 | extern basic_block vn_context_bb; | |
dd6f2cf9 | 290 | |
dd6f2cf9 | 291 | |
89fb70a3 | 292 | #endif /* TREE_SSA_SCCVN_H */ |