]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-ssa-sccvn.h
poly_int: indirect_refs_may_alias_p
[thirdparty/gcc.git] / gcc / tree-ssa-sccvn.h
CommitLineData
9e9e6e3e 1/* Tree SCC value numbering
aad93da1 2 Copyright (C) 2007-2017 Free Software Foundation, Inc.
9e9e6e3e 3 Contributed by Daniel Berlin <dberlin@dberlin.org>
4
8c4c00c1 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/>. */
9e9e6e3e 20
21#ifndef TREE_SSA_SCCVN_H
22#define TREE_SSA_SCCVN_H
23
d8eaff30 24/* In tree-ssa-sccvn.c */
25bool expressions_equal_p (tree, tree);
26
27
9e9e6e3e 28/* TOP of the VN lattice. */
29extern tree VN_TOP;
30
f6c33c78 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
36typedef 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;
7384c678 45 tree op[1];
f6c33c78 46} *vn_nary_op_t;
47typedef const struct vn_nary_op_s *const_vn_nary_op_t;
48
7384c678 49/* Return the size of a vn_nary_op_t with LENGTH operands. */
50
51static inline size_t
52sizeof_vn_nary_op (unsigned int length)
53{
70cd63a3 54 return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree);
7384c678 55}
56
f6c33c78 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
63typedef 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;
f1f41a6c 68 vec<tree> phiargs;
f6c33c78 69 basic_block block;
15edd328 70 /* Controlling condition lhs/rhs. */
71 tree cclhs;
72 tree ccrhs;
82a7a70c 73 tree type;
f6c33c78 74 tree result;
75} *vn_phi_t;
76typedef 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
84typedef struct vn_reference_op_struct
85{
058a1b7a 86 ENUM_BITFIELD(tree_code) opcode : 16;
842c7753 87 /* Dependence info, used for [TARGET_]MEM_REF only. */
88 unsigned short clique;
89 unsigned short base;
8894566e 90 /* 1 for instrumented calls. */
91 unsigned with_bounds : 1;
92 unsigned reverse : 1;
93 /* For storing TYPE_ALIGN for array ref element size computation. */
94 unsigned align : 6;
182cf5a9 95 /* Constant offset this op adds or -1 if it is variable. */
96 HOST_WIDE_INT off;
f6c33c78 97 tree type;
98 tree op0;
99 tree op1;
100 tree op2;
101} vn_reference_op_s;
102typedef vn_reference_op_s *vn_reference_op_t;
103typedef const vn_reference_op_s *const_vn_reference_op_t;
104
8894566e 105inline unsigned
106vn_ref_op_align_unit (vn_reference_op_t op)
107{
108 return op->align ? ((unsigned)1 << (op->align - 1)) / BITS_PER_UNIT : 0;
109}
f6c33c78 110
dd277d48 111/* A reference operation in the hashtable is representation as
112 the vuse, representing the memory state at the time of
f6c33c78 113 the operation, and a collection of operands that make up the
114 addressing calculation. If two vn_reference_t's have the same set
115 of operands, they access the same memory location. We also store
dd277d48 116 the resulting value number, and the hashcode. */
f6c33c78 117
118typedef struct vn_reference_s
119{
120 /* Unique identifier that all expressions with the same value have. */
121 unsigned int value_id;
122 hashval_t hashcode;
dd277d48 123 tree vuse;
3918bd18 124 alias_set_type set;
125 tree type;
f1f41a6c 126 vec<vn_reference_op_s> operands;
f6c33c78 127 tree result;
b736e424 128 tree result_vdef;
f6c33c78 129} *vn_reference_t;
130typedef const struct vn_reference_s *const_vn_reference_t;
131
132typedef struct vn_constant_s
133{
134 unsigned int value_id;
135 hashval_t hashcode;
136 tree constant;
137} *vn_constant_t;
75a70cf9 138
024fee2c 139enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI };
42acab1c 140enum vn_kind vn_get_stmt_kind (gimple *);
024fee2c 141
82a7a70c 142/* Hash the type TYPE using bits that distinguishes it in the
143 types_compatible_p sense. */
144
145static inline hashval_t
146vn_hash_type (tree type)
147{
148 return (INTEGRAL_TYPE_P (type)
149 + (INTEGRAL_TYPE_P (type)
150 ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0));
151}
152
75a70cf9 153/* Hash the constant CONSTANT with distinguishing type incompatible
154 constants in the types_compatible_p sense. */
155
156static inline hashval_t
157vn_hash_constant_with_type (tree constant)
158{
f32e91d5 159 inchash::hash hstate;
160 inchash::add_expr (constant, hstate);
161 hstate.merge_hash (vn_hash_type (TREE_TYPE (constant)));
162 return hstate.end ();
75a70cf9 163}
164
165/* Compare the constants C1 and C2 with distinguishing type incompatible
166 constants in the types_compatible_p sense. */
167
168static inline bool
169vn_constant_eq_with_type (tree c1, tree c2)
170{
171 return (expressions_equal_p (c1, c2)
172 && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2)));
173}
174
9e9e6e3e 175typedef struct vn_ssa_aux
176{
9e9e6e3e 177 /* Value number. This may be an SSA name or a constant. */
178 tree valnum;
eb074ef3 179 /* Statements to insert if needs_insertion is true. */
180 gimple_seq expr;
6d6adc82 181
4345b868 182 /* Saved SSA name info. */
183 tree_ssa_name::ssa_name_info_type info;
184
f6c33c78 185 /* Unique identifier that all expressions with the same value have. */
186 unsigned int value_id;
187
6d6adc82 188 /* SCC information. */
189 unsigned int dfsnum;
190 unsigned int low;
191 unsigned visited : 1;
192 unsigned on_sccstack : 1;
193
9e9e6e3e 194 /* Whether the SSA_NAME has been value numbered already. This is
195 only saying whether visit_use has been called on it at least
196 once. It cannot be used to avoid visitation for SSA_NAME's
197 involved in non-singleton SCC's. */
6d6adc82 198 unsigned use_processed : 1;
1d9353f3 199
200 /* Whether the SSA_NAME has no defining statement and thus an
201 insertion of such with EXPR as definition is required before
202 a use can be created of it. */
203 unsigned needs_insertion : 1;
af09d40d 204
205 /* Whether range-info is anti-range. */
206 unsigned range_info_anti_range_p : 1;
9e9e6e3e 207} *vn_ssa_aux_t;
208
6dc50383 209enum vn_lookup_kind { VN_NOWALK, VN_WALK, VN_WALKREWRITE };
8f190c8a 210
9e9e6e3e 211/* Return the value numbering info for an SSA_NAME. */
adc83a75 212bool has_VN_INFO (tree);
9e9e6e3e 213extern vn_ssa_aux_t VN_INFO (tree);
214extern vn_ssa_aux_t VN_INFO_GET (tree);
75a70cf9 215tree vn_get_expr_for (tree);
c1f41db7 216void run_scc_vn (vn_lookup_kind);
2201c330 217unsigned int vn_eliminate (bitmap);
9e9e6e3e 218void free_scc_vn (void);
222ac318 219void scc_vn_restore_ssa_info (void);
f6c33c78 220tree vn_nary_op_lookup (tree, vn_nary_op_t *);
42acab1c 221tree vn_nary_op_lookup_stmt (gimple *, vn_nary_op_t *);
f6c33c78 222tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code,
7384c678 223 tree, tree *, vn_nary_op_t *);
f6c33c78 224vn_nary_op_t vn_nary_op_insert (tree, tree);
225vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code,
7384c678 226 tree, tree *, tree, unsigned int);
3918bd18 227bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree,
f1f41a6c 228 vec<vn_reference_op_s> );
e1bba980 229vec<vn_reference_op_s> vn_reference_operands_for_lookup (tree);
3918bd18 230tree vn_reference_lookup_pieces (tree, alias_set_type, tree,
f1f41a6c 231 vec<vn_reference_op_s> ,
8ecc6b38 232 vn_reference_t *, vn_lookup_kind);
0b3619e6 233tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *, bool);
1a91d914 234void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t);
3918bd18 235vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree,
f1f41a6c 236 vec<vn_reference_op_s> ,
f6c33c78 237 tree, unsigned int);
238
3e871d4d 239bool vn_nary_op_eq (const_vn_nary_op_t const vno1,
240 const_vn_nary_op_t const vno2);
2ac47fdf 241bool vn_nary_may_trap (vn_nary_op_t);
3e871d4d 242bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const);
f6c33c78 243unsigned int get_max_value_id (void);
244unsigned int get_next_value_id (void);
8c8a7011 245unsigned int get_constant_value_id (tree);
f6c33c78 246unsigned int get_or_alloc_constant_value_id (tree);
247bool value_id_constant_p (unsigned int);
c26ce8a9 248tree fully_constant_vn_reference_p (vn_reference_t);
97f2a90b 249tree vn_nary_simplify (vn_nary_op_t);
51385f30 250
251/* Valueize NAME if it is an SSA name, otherwise just return it. */
252
253static inline tree
254vn_valueize (tree name)
255{
256 if (TREE_CODE (name) == SSA_NAME)
257 {
258 tree tem = VN_INFO (name)->valnum;
259 return tem == VN_TOP ? name : tem;
260 }
261 return name;
262}
263
c716ac28 264/* Get at the original range info for NAME. */
265
266inline range_info_def *
267VN_INFO_RANGE_INFO (tree name)
268{
269 return (VN_INFO (name)->info.range_info
270 ? VN_INFO (name)->info.range_info
271 : SSA_NAME_RANGE_INFO (name));
272}
273
af09d40d 274/* Whether the original range info of NAME is an anti-range. */
275
276inline bool
277VN_INFO_ANTI_RANGE_P (tree name)
278{
279 return (VN_INFO (name)->info.range_info
280 ? VN_INFO (name)->range_info_anti_range_p
281 : SSA_NAME_ANTI_RANGE_P (name));
282}
283
284/* Get at the original range info kind for NAME. */
285
286inline value_range_type
287VN_INFO_RANGE_TYPE (tree name)
288{
289 return VN_INFO_ANTI_RANGE_P (name) ? VR_ANTI_RANGE : VR_RANGE;
290}
291
c716ac28 292/* Get at the original pointer info for NAME. */
293
294inline ptr_info_def *
295VN_INFO_PTR_INFO (tree name)
296{
297 return (VN_INFO (name)->info.ptr_info
298 ? VN_INFO (name)->info.ptr_info
299 : SSA_NAME_PTR_INFO (name));
300}
301
9e9e6e3e 302#endif /* TREE_SSA_SCCVN_H */