Daily bump.
[official-gcc.git] / gcc / tree-ssa-sccvn.h
blob4e63ad746c631082c104aba67ad5ddbafbdf4f0f
1 /* Tree SCC value numbering
2 Copyright (C) 2007-2017 Free Software Foundation, Inc.
3 Contributed by Daniel Berlin <dberlin@dberlin.org>
5 This file is part of GCC.
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.
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.
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/>. */
21 #ifndef TREE_SSA_SCCVN_H
22 #define TREE_SSA_SCCVN_H
24 /* In tree-ssa-sccvn.c */
25 bool expressions_equal_p (tree, tree);
28 /* TOP of the VN lattice. */
29 extern tree VN_TOP;
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. */
36 typedef struct vn_nary_op_s
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;
45 tree op[1];
46 } *vn_nary_op_t;
47 typedef const struct vn_nary_op_s *const_vn_nary_op_t;
49 /* Return the size of a vn_nary_op_t with LENGTH operands. */
51 static inline size_t
52 sizeof_vn_nary_op (unsigned int length)
54 return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree);
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. */
63 typedef struct vn_phi_s
65 /* Unique identifier that all expressions with the same value have. */
66 unsigned int value_id;
67 hashval_t hashcode;
68 vec<tree> phiargs;
69 basic_block block;
70 tree type;
71 tree result;
72 } *vn_phi_t;
73 typedef const struct vn_phi_s *const_vn_phi_t;
75 /* Reference operands only exist in reference operations structures.
76 They consist of an opcode, type, and some number of operands. For
77 a given opcode, some, all, or none of the operands may be used.
78 The operands are there to store the information that makes up the
79 portion of the addressing calculation that opcode performs. */
81 typedef struct vn_reference_op_struct
83 ENUM_BITFIELD(tree_code) opcode : 16;
84 /* Dependence info, used for [TARGET_]MEM_REF only. */
85 unsigned short clique;
86 unsigned short base;
87 /* 1 for instrumented calls. */
88 unsigned with_bounds : 1;
89 unsigned reverse : 1;
90 /* For storing TYPE_ALIGN for array ref element size computation. */
91 unsigned align : 6;
92 /* Constant offset this op adds or -1 if it is variable. */
93 HOST_WIDE_INT off;
94 tree type;
95 tree op0;
96 tree op1;
97 tree op2;
98 } vn_reference_op_s;
99 typedef vn_reference_op_s *vn_reference_op_t;
100 typedef const vn_reference_op_s *const_vn_reference_op_t;
102 inline unsigned
103 vn_ref_op_align_unit (vn_reference_op_t op)
105 return op->align ? ((unsigned)1 << (op->align - 1)) / BITS_PER_UNIT : 0;
108 /* A reference operation in the hashtable is representation as
109 the vuse, representing the memory state at the time of
110 the operation, and a collection of operands that make up the
111 addressing calculation. If two vn_reference_t's have the same set
112 of operands, they access the same memory location. We also store
113 the resulting value number, and the hashcode. */
115 typedef struct vn_reference_s
117 /* Unique identifier that all expressions with the same value have. */
118 unsigned int value_id;
119 hashval_t hashcode;
120 tree vuse;
121 alias_set_type set;
122 tree type;
123 vec<vn_reference_op_s> operands;
124 tree result;
125 tree result_vdef;
126 } *vn_reference_t;
127 typedef const struct vn_reference_s *const_vn_reference_t;
129 typedef struct vn_constant_s
131 unsigned int value_id;
132 hashval_t hashcode;
133 tree constant;
134 } *vn_constant_t;
136 enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI };
137 enum vn_kind vn_get_stmt_kind (gimple *);
139 /* Hash the type TYPE using bits that distinguishes it in the
140 types_compatible_p sense. */
142 static inline hashval_t
143 vn_hash_type (tree type)
145 return (INTEGRAL_TYPE_P (type)
146 + (INTEGRAL_TYPE_P (type)
147 ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0));
150 /* Hash the constant CONSTANT with distinguishing type incompatible
151 constants in the types_compatible_p sense. */
153 static inline hashval_t
154 vn_hash_constant_with_type (tree constant)
156 inchash::hash hstate;
157 inchash::add_expr (constant, hstate);
158 hstate.merge_hash (vn_hash_type (TREE_TYPE (constant)));
159 return hstate.end ();
162 /* Compare the constants C1 and C2 with distinguishing type incompatible
163 constants in the types_compatible_p sense. */
165 static inline bool
166 vn_constant_eq_with_type (tree c1, tree c2)
168 return (expressions_equal_p (c1, c2)
169 && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2)));
172 typedef struct vn_ssa_aux
174 /* Value number. This may be an SSA name or a constant. */
175 tree valnum;
176 /* Statements to insert if needs_insertion is true. */
177 gimple_seq expr;
179 /* Saved SSA name info. */
180 tree_ssa_name::ssa_name_info_type info;
182 /* Unique identifier that all expressions with the same value have. */
183 unsigned int value_id;
185 /* SCC information. */
186 unsigned int dfsnum;
187 unsigned int low;
188 unsigned visited : 1;
189 unsigned on_sccstack : 1;
191 /* Whether the SSA_NAME has been value numbered already. This is
192 only saying whether visit_use has been called on it at least
193 once. It cannot be used to avoid visitation for SSA_NAME's
194 involved in non-singleton SCC's. */
195 unsigned use_processed : 1;
197 /* Whether the SSA_NAME has no defining statement and thus an
198 insertion of such with EXPR as definition is required before
199 a use can be created of it. */
200 unsigned needs_insertion : 1;
202 /* Whether range-info is anti-range. */
203 unsigned range_info_anti_range_p : 1;
204 } *vn_ssa_aux_t;
206 enum vn_lookup_kind { VN_NOWALK, VN_WALK, VN_WALKREWRITE };
208 /* Return the value numbering info for an SSA_NAME. */
209 extern vn_ssa_aux_t VN_INFO (tree);
210 extern vn_ssa_aux_t VN_INFO_GET (tree);
211 tree vn_get_expr_for (tree);
212 bool run_scc_vn (vn_lookup_kind);
213 void free_scc_vn (void);
214 void scc_vn_restore_ssa_info (void);
215 tree vn_nary_op_lookup (tree, vn_nary_op_t *);
216 tree vn_nary_op_lookup_stmt (gimple *, vn_nary_op_t *);
217 tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code,
218 tree, tree *, vn_nary_op_t *);
219 vn_nary_op_t vn_nary_op_insert (tree, tree);
220 vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code,
221 tree, tree *, tree, unsigned int);
222 bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree,
223 vec<vn_reference_op_s> );
224 vec<vn_reference_op_s> vn_reference_operands_for_lookup (tree);
225 tree vn_reference_lookup_pieces (tree, alias_set_type, tree,
226 vec<vn_reference_op_s> ,
227 vn_reference_t *, vn_lookup_kind);
228 tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *, bool);
229 void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t);
230 vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree,
231 vec<vn_reference_op_s> ,
232 tree, unsigned int);
234 bool vn_nary_op_eq (const_vn_nary_op_t const vno1,
235 const_vn_nary_op_t const vno2);
236 bool vn_nary_may_trap (vn_nary_op_t);
237 bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const);
238 unsigned int get_max_value_id (void);
239 unsigned int get_next_value_id (void);
240 unsigned int get_constant_value_id (tree);
241 unsigned int get_or_alloc_constant_value_id (tree);
242 bool value_id_constant_p (unsigned int);
243 tree fully_constant_vn_reference_p (vn_reference_t);
244 tree vn_nary_simplify (vn_nary_op_t);
246 /* Valueize NAME if it is an SSA name, otherwise just return it. */
248 static inline tree
249 vn_valueize (tree name)
251 if (TREE_CODE (name) == SSA_NAME)
253 tree tem = VN_INFO (name)->valnum;
254 return tem == VN_TOP ? name : tem;
256 return name;
259 /* Get at the original range info for NAME. */
261 inline range_info_def *
262 VN_INFO_RANGE_INFO (tree name)
264 return (VN_INFO (name)->info.range_info
265 ? VN_INFO (name)->info.range_info
266 : SSA_NAME_RANGE_INFO (name));
269 /* Whether the original range info of NAME is an anti-range. */
271 inline bool
272 VN_INFO_ANTI_RANGE_P (tree name)
274 return (VN_INFO (name)->info.range_info
275 ? VN_INFO (name)->range_info_anti_range_p
276 : SSA_NAME_ANTI_RANGE_P (name));
279 /* Get at the original range info kind for NAME. */
281 inline value_range_type
282 VN_INFO_RANGE_TYPE (tree name)
284 return VN_INFO_ANTI_RANGE_P (name) ? VR_ANTI_RANGE : VR_RANGE;
287 /* Get at the original pointer info for NAME. */
289 inline ptr_info_def *
290 VN_INFO_PTR_INFO (tree name)
292 return (VN_INFO (name)->info.ptr_info
293 ? VN_INFO (name)->info.ptr_info
294 : SSA_NAME_PTR_INFO (name));
297 #endif /* TREE_SSA_SCCVN_H */