1 /* Tree SCC value numbering
2 Copyright (C) 2007-2021 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. */
31 /* A predicated value. */
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. */
40 int valid_dominated_by_p
[1];
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
48 typedef struct vn_nary_op_s
51 vn_nary_op_s
*unwind_to
;
52 /* Unique identify that all expressions with the same value have. */
53 unsigned int value_id
;
54 ENUM_BITFIELD(tree_code
) opcode
: 16;
57 unsigned predicated_values
: 1;
59 /* If ! predicated_values this is the value of the expression. */
61 /* If predicated_values this is a list of values of the expression. */
67 typedef const struct vn_nary_op_s
*const_vn_nary_op_t
;
69 /* Return the size of a vn_nary_op_t with LENGTH operands. */
72 sizeof_vn_nary_op (unsigned int length
)
74 return sizeof (struct vn_nary_op_s
) + sizeof (tree
) * length
- sizeof (tree
);
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. */
83 typedef struct vn_phi_s
86 /* Unique identifier that all expressions with the same value have. */
87 unsigned int value_id
;
90 /* Controlling condition lhs/rhs. */
95 /* The number of args is determined by EDGE_COUT (block->preds). */
98 typedef const struct vn_phi_s
*const_vn_phi_t
;
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. */
106 typedef struct vn_reference_op_struct
108 ENUM_BITFIELD(tree_code
) opcode
: 16;
109 /* Dependence info, used for [TARGET_]MEM_REF only. */
110 unsigned short clique
;
112 unsigned reverse
: 1;
113 /* For storing TYPE_ALIGN for array ref element size computation. */
115 /* Constant offset this op adds or -1 if it is variable. */
122 typedef vn_reference_op_s
*vn_reference_op_t
;
123 typedef const vn_reference_op_s
*const_vn_reference_op_t
;
126 vn_ref_op_align_unit (vn_reference_op_t op
)
128 return op
->align
? ((unsigned)1 << (op
->align
- 1)) / BITS_PER_UNIT
: 0;
131 /* A reference operation in the hashtable is representation as
132 the vuse, representing the memory state at the time of
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
136 the resulting value number, and the hashcode. */
138 typedef struct vn_reference_s
140 vn_reference_s
*next
;
141 /* Unique identifier that all expressions with the same value have. */
142 unsigned int value_id
;
146 alias_set_type base_set
;
149 vec
<vn_reference_op_s
> operands
;
153 typedef const struct vn_reference_s
*const_vn_reference_t
;
155 typedef struct vn_constant_s
157 unsigned int value_id
;
162 enum vn_kind
{ VN_NONE
, VN_CONSTANT
, VN_NARY
, VN_REFERENCE
, VN_PHI
};
163 enum vn_kind
vn_get_stmt_kind (gimple
*);
165 /* Hash the type TYPE using bits that distinguishes it in the
166 types_compatible_p sense. */
168 static inline hashval_t
169 vn_hash_type (tree type
)
171 return (INTEGRAL_TYPE_P (type
)
172 + (INTEGRAL_TYPE_P (type
)
173 ? TYPE_PRECISION (type
) + TYPE_UNSIGNED (type
) : 0));
176 /* Hash the constant CONSTANT with distinguishing type incompatible
177 constants in the types_compatible_p sense. */
179 static inline hashval_t
180 vn_hash_constant_with_type (tree constant
)
182 inchash::hash hstate
;
183 inchash::add_expr (constant
, hstate
);
184 hstate
.merge_hash (vn_hash_type (TREE_TYPE (constant
)));
185 return hstate
.end ();
188 /* Compare the constants C1 and C2 with distinguishing type incompatible
189 constants in the types_compatible_p sense. */
192 vn_constant_eq_with_type (tree c1
, tree c2
)
194 return (expressions_equal_p (c1
, c2
)
195 && types_compatible_p (TREE_TYPE (c1
), TREE_TYPE (c2
)));
198 /* Instead of having a local availability lattice for each basic-block
199 and availability at X defined as union of the local availabilities
200 at X and its dominators we're turning this upside down and track
201 availability per value given values are usually made available at very
203 So we have a chain of LOCATION, LEADER entries where LOCATION is
204 specifying the basic-block LEADER is made available for VALUE.
205 We prepend to this chain in RPO order thus for iteration we can simply
206 remove the last entries.
207 LOCATION is the basic-block index and LEADER is its SSA name version. */
211 /* The basic-block LEADER is made available. */
213 /* The LEADER for the value we are chained on. */
215 /* The previous value we pushed a avail record to. */
216 struct vn_ssa_aux
*next_undo
;
219 typedef struct vn_ssa_aux
221 /* SSA name this vn_ssa_aux is associated with in the lattice. */
223 /* Value number. This may be an SSA name or a constant. */
225 /* Statements to insert if needs_insertion is true. */
228 /* AVAIL entries, last in RPO order is first. This is only tracked
229 for SSA names also serving as values (NAME == VALNUM). */
232 /* Unique identifier that all expressions with the same value have. */
233 unsigned int value_id
;
235 /* Whether the SSA_NAME has been processed at least once. */
236 unsigned visited
: 1;
238 /* Whether the SSA_NAME has no defining statement and thus an
239 insertion of such with EXPR as definition is required before
240 a use can be created of it. */
241 unsigned needs_insertion
: 1;
244 enum vn_lookup_kind
{ VN_NOWALK
, VN_WALK
, VN_WALKREWRITE
};
246 /* Return the value numbering info for an SSA_NAME. */
247 bool has_VN_INFO (tree
);
248 extern vn_ssa_aux_t
VN_INFO (tree
);
249 tree
vn_get_expr_for (tree
);
250 void scc_vn_restore_ssa_info (void);
251 tree
vn_nary_op_lookup_stmt (gimple
*, vn_nary_op_t
*);
252 tree
vn_nary_op_lookup_pieces (unsigned int, enum tree_code
,
253 tree
, tree
*, vn_nary_op_t
*);
254 vn_nary_op_t
vn_nary_op_insert_pieces (unsigned int, enum tree_code
,
255 tree
, tree
*, tree
, unsigned int);
256 bool ao_ref_init_from_vn_reference (ao_ref
*, alias_set_type
, alias_set_type
,
257 tree
, vec
<vn_reference_op_s
> );
258 vec
<vn_reference_op_s
> vn_reference_operands_for_lookup (tree
);
259 tree
vn_reference_lookup_pieces (tree
, alias_set_type
, alias_set_type
, tree
,
260 vec
<vn_reference_op_s
> ,
261 vn_reference_t
*, vn_lookup_kind
);
262 tree
vn_reference_lookup (tree
, tree
, vn_lookup_kind
, vn_reference_t
*, bool,
263 tree
* = NULL
, tree
= NULL_TREE
);
264 void vn_reference_lookup_call (gcall
*, vn_reference_t
*, vn_reference_t
);
265 vn_reference_t
vn_reference_insert_pieces (tree
, alias_set_type
, alias_set_type
,
266 tree
, vec
<vn_reference_op_s
>,
268 void print_vn_reference_ops (FILE *, const vec
<vn_reference_op_s
>);
270 bool vn_nary_op_eq (const_vn_nary_op_t
const vno1
,
271 const_vn_nary_op_t
const vno2
);
272 bool vn_nary_may_trap (vn_nary_op_t
);
273 bool vn_reference_may_trap (vn_reference_t
);
274 bool vn_reference_eq (const_vn_reference_t
const, const_vn_reference_t
const);
276 unsigned int get_max_value_id (void);
277 unsigned int get_max_constant_value_id (void);
278 unsigned int get_next_value_id (void);
279 unsigned int get_next_constant_value_id (void);
280 unsigned int get_constant_value_id (tree
);
281 unsigned int get_or_alloc_constant_value_id (tree
);
283 /* Return true if V is a value id for a constant. */
285 value_id_constant_p (unsigned int v
)
290 tree
fully_constant_vn_reference_p (vn_reference_t
);
291 tree
vn_nary_simplify (vn_nary_op_t
);
293 unsigned do_rpo_vn (function
*, edge
, bitmap
);
294 void run_rpo_vn (vn_lookup_kind
);
295 unsigned eliminate_with_rpo_vn (bitmap
);
296 void free_rpo_vn (void);
298 /* Valueize NAME if it is an SSA name, otherwise just return it. This hook
299 is initialized by run_scc_vn. */
300 extern tree (*vn_valueize
) (tree
);
302 /* Context that valueization should operate on. */
303 extern basic_block vn_context_bb
;
306 #endif /* TREE_SSA_SCCVN_H */