]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-ssa-sccvn.h
Update copyright years.
[thirdparty/gcc.git] / gcc / tree-ssa-sccvn.h
CommitLineData
9e9e6e3e 1/* Tree SCC value numbering
fbd26352 2 Copyright (C) 2007-2019 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
51e85e64 31/* A predicated value. */
32struct 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
f6c33c78 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
48typedef struct vn_nary_op_s
49{
c42ece58 50 vn_nary_op_s *next;
51e85e64 51 vn_nary_op_s *unwind_to;
f6c33c78 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;
51e85e64 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;
f6c33c78 64 tree type;
7384c678 65 tree op[1];
f6c33c78 66} *vn_nary_op_t;
67typedef const struct vn_nary_op_s *const_vn_nary_op_t;
68
7384c678 69/* Return the size of a vn_nary_op_t with LENGTH operands. */
70
71static inline size_t
72sizeof_vn_nary_op (unsigned int length)
73{
70cd63a3 74 return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree);
7384c678 75}
76
f6c33c78 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
83typedef struct vn_phi_s
84{
c42ece58 85 vn_phi_s *next;
f6c33c78 86 /* Unique identifier that all expressions with the same value have. */
87 unsigned int value_id;
88 hashval_t hashcode;
f6c33c78 89 basic_block block;
15edd328 90 /* Controlling condition lhs/rhs. */
91 tree cclhs;
92 tree ccrhs;
82a7a70c 93 tree type;
f6c33c78 94 tree result;
ca5aa39a 95 /* The number of args is determined by EDGE_COUT (block->preds). */
96 tree phiargs[1];
f6c33c78 97} *vn_phi_t;
98typedef 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
106typedef struct vn_reference_op_struct
107{
058a1b7a 108 ENUM_BITFIELD(tree_code) opcode : 16;
842c7753 109 /* Dependence info, used for [TARGET_]MEM_REF only. */
110 unsigned short clique;
111 unsigned short base;
8894566e 112 unsigned reverse : 1;
113 /* For storing TYPE_ALIGN for array ref element size computation. */
114 unsigned align : 6;
182cf5a9 115 /* Constant offset this op adds or -1 if it is variable. */
fe60c82c 116 poly_int64_pod off;
f6c33c78 117 tree type;
118 tree op0;
119 tree op1;
120 tree op2;
121} vn_reference_op_s;
122typedef vn_reference_op_s *vn_reference_op_t;
123typedef const vn_reference_op_s *const_vn_reference_op_t;
124
8894566e 125inline unsigned
126vn_ref_op_align_unit (vn_reference_op_t op)
127{
128 return op->align ? ((unsigned)1 << (op->align - 1)) / BITS_PER_UNIT : 0;
129}
f6c33c78 130
dd277d48 131/* A reference operation in the hashtable is representation as
132 the vuse, representing the memory state at the time of
f6c33c78 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
dd277d48 136 the resulting value number, and the hashcode. */
f6c33c78 137
138typedef struct vn_reference_s
139{
c42ece58 140 vn_reference_s *next;
f6c33c78 141 /* Unique identifier that all expressions with the same value have. */
142 unsigned int value_id;
143 hashval_t hashcode;
dd277d48 144 tree vuse;
3918bd18 145 alias_set_type set;
146 tree type;
f1f41a6c 147 vec<vn_reference_op_s> operands;
f6c33c78 148 tree result;
b736e424 149 tree result_vdef;
f6c33c78 150} *vn_reference_t;
151typedef const struct vn_reference_s *const_vn_reference_t;
152
153typedef struct vn_constant_s
154{
155 unsigned int value_id;
156 hashval_t hashcode;
157 tree constant;
158} *vn_constant_t;
75a70cf9 159
024fee2c 160enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI };
42acab1c 161enum vn_kind vn_get_stmt_kind (gimple *);
024fee2c 162
82a7a70c 163/* Hash the type TYPE using bits that distinguishes it in the
164 types_compatible_p sense. */
165
166static inline hashval_t
167vn_hash_type (tree type)
168{
169 return (INTEGRAL_TYPE_P (type)
170 + (INTEGRAL_TYPE_P (type)
171 ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0));
172}
173
75a70cf9 174/* Hash the constant CONSTANT with distinguishing type incompatible
175 constants in the types_compatible_p sense. */
176
177static inline hashval_t
178vn_hash_constant_with_type (tree constant)
179{
f32e91d5 180 inchash::hash hstate;
181 inchash::add_expr (constant, hstate);
182 hstate.merge_hash (vn_hash_type (TREE_TYPE (constant)));
183 return hstate.end ();
75a70cf9 184}
185
186/* Compare the constants C1 and C2 with distinguishing type incompatible
187 constants in the types_compatible_p sense. */
188
189static inline bool
190vn_constant_eq_with_type (tree c1, tree c2)
191{
192 return (expressions_equal_p (c1, c2)
193 && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2)));
194}
195
9e9e6e3e 196typedef struct vn_ssa_aux
197{
51e85e64 198 /* SSA name this vn_ssa_aux is associated with in the lattice. */
199 tree name;
9e9e6e3e 200 /* Value number. This may be an SSA name or a constant. */
201 tree valnum;
eb074ef3 202 /* Statements to insert if needs_insertion is true. */
203 gimple_seq expr;
6d6adc82 204
f6c33c78 205 /* Unique identifier that all expressions with the same value have. */
206 unsigned int value_id;
207
51e85e64 208 /* Whether the SSA_NAME has been processed at least once. */
6d6adc82 209 unsigned visited : 1;
1d9353f3 210
211 /* Whether the SSA_NAME has no defining statement and thus an
212 insertion of such with EXPR as definition is required before
213 a use can be created of it. */
214 unsigned needs_insertion : 1;
9e9e6e3e 215} *vn_ssa_aux_t;
216
6dc50383 217enum vn_lookup_kind { VN_NOWALK, VN_WALK, VN_WALKREWRITE };
8f190c8a 218
9e9e6e3e 219/* Return the value numbering info for an SSA_NAME. */
adc83a75 220bool has_VN_INFO (tree);
9e9e6e3e 221extern vn_ssa_aux_t VN_INFO (tree);
75a70cf9 222tree vn_get_expr_for (tree);
222ac318 223void scc_vn_restore_ssa_info (void);
f6c33c78 224tree vn_nary_op_lookup (tree, vn_nary_op_t *);
42acab1c 225tree vn_nary_op_lookup_stmt (gimple *, vn_nary_op_t *);
f6c33c78 226tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code,
7384c678 227 tree, tree *, vn_nary_op_t *);
f6c33c78 228vn_nary_op_t vn_nary_op_insert (tree, tree);
229vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code,
7384c678 230 tree, tree *, tree, unsigned int);
3918bd18 231bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree,
f1f41a6c 232 vec<vn_reference_op_s> );
e1bba980 233vec<vn_reference_op_s> vn_reference_operands_for_lookup (tree);
3918bd18 234tree vn_reference_lookup_pieces (tree, alias_set_type, tree,
f1f41a6c 235 vec<vn_reference_op_s> ,
8ecc6b38 236 vn_reference_t *, vn_lookup_kind);
0b3619e6 237tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *, bool);
1a91d914 238void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t);
3918bd18 239vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree,
f1f41a6c 240 vec<vn_reference_op_s> ,
f6c33c78 241 tree, unsigned int);
242
3e871d4d 243bool vn_nary_op_eq (const_vn_nary_op_t const vno1,
244 const_vn_nary_op_t const vno2);
2ac47fdf 245bool vn_nary_may_trap (vn_nary_op_t);
3e871d4d 246bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const);
f6c33c78 247unsigned int get_max_value_id (void);
248unsigned int get_next_value_id (void);
8c8a7011 249unsigned int get_constant_value_id (tree);
f6c33c78 250unsigned int get_or_alloc_constant_value_id (tree);
251bool value_id_constant_p (unsigned int);
c26ce8a9 252tree fully_constant_vn_reference_p (vn_reference_t);
97f2a90b 253tree vn_nary_simplify (vn_nary_op_t);
51385f30 254
51e85e64 255unsigned do_rpo_vn (function *, edge, bitmap);
256void run_rpo_vn (vn_lookup_kind);
257unsigned eliminate_with_rpo_vn (bitmap);
258void free_rpo_vn (void);
51385f30 259
51e85e64 260/* Valueize NAME if it is an SSA name, otherwise just return it. This hook
261 is initialized by run_scc_vn. */
262extern tree (*vn_valueize) (tree);
c716ac28 263
51e85e64 264/* Context that valueization should operate on. */
265extern basic_block vn_context_bb;
c716ac28 266
c716ac28 267
9e9e6e3e 268#endif /* TREE_SSA_SCCVN_H */