]>
Commit | Line | Data |
---|---|---|
9e9e6e3e | 1 | /* Tree SCC value numbering |
3aea1f79 | 2 | Copyright (C) 2007-2014 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 */ |
25 | bool expressions_equal_p (tree, tree); | |
26 | ||
27 | ||
9e9e6e3e | 28 | /* TOP of the VN lattice. */ |
29 | extern 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 | ||
36 | typedef 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; |
47 | typedef 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 | ||
51 | static inline size_t | |
52 | sizeof_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 | ||
63 | typedef 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; |
82a7a70c | 70 | tree type; |
f6c33c78 | 71 | tree result; |
72 | } *vn_phi_t; | |
73 | typedef const struct vn_phi_s *const_vn_phi_t; | |
74 | ||
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. */ | |
80 | ||
81 | typedef struct vn_reference_op_struct | |
82 | { | |
058a1b7a | 83 | ENUM_BITFIELD(tree_code) opcode : 16; |
84 | /* 1 for instrumented calls. */ | |
85 | unsigned with_bounds : 1; | |
182cf5a9 | 86 | /* Constant offset this op adds or -1 if it is variable. */ |
87 | HOST_WIDE_INT off; | |
f6c33c78 | 88 | tree type; |
89 | tree op0; | |
90 | tree op1; | |
91 | tree op2; | |
92 | } vn_reference_op_s; | |
93 | typedef vn_reference_op_s *vn_reference_op_t; | |
94 | typedef const vn_reference_op_s *const_vn_reference_op_t; | |
95 | ||
f6c33c78 | 96 | |
dd277d48 | 97 | /* A reference operation in the hashtable is representation as |
98 | the vuse, representing the memory state at the time of | |
f6c33c78 | 99 | the operation, and a collection of operands that make up the |
100 | addressing calculation. If two vn_reference_t's have the same set | |
101 | of operands, they access the same memory location. We also store | |
dd277d48 | 102 | the resulting value number, and the hashcode. */ |
f6c33c78 | 103 | |
104 | typedef struct vn_reference_s | |
105 | { | |
106 | /* Unique identifier that all expressions with the same value have. */ | |
107 | unsigned int value_id; | |
108 | hashval_t hashcode; | |
dd277d48 | 109 | tree vuse; |
3918bd18 | 110 | alias_set_type set; |
111 | tree type; | |
f1f41a6c | 112 | vec<vn_reference_op_s> operands; |
f6c33c78 | 113 | tree result; |
b736e424 | 114 | tree result_vdef; |
f6c33c78 | 115 | } *vn_reference_t; |
116 | typedef const struct vn_reference_s *const_vn_reference_t; | |
117 | ||
118 | typedef struct vn_constant_s | |
119 | { | |
120 | unsigned int value_id; | |
121 | hashval_t hashcode; | |
122 | tree constant; | |
123 | } *vn_constant_t; | |
75a70cf9 | 124 | |
024fee2c | 125 | enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI }; |
126 | enum vn_kind vn_get_stmt_kind (gimple); | |
127 | ||
82a7a70c | 128 | /* Hash the type TYPE using bits that distinguishes it in the |
129 | types_compatible_p sense. */ | |
130 | ||
131 | static inline hashval_t | |
132 | vn_hash_type (tree type) | |
133 | { | |
134 | return (INTEGRAL_TYPE_P (type) | |
135 | + (INTEGRAL_TYPE_P (type) | |
136 | ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0)); | |
137 | } | |
138 | ||
75a70cf9 | 139 | /* Hash the constant CONSTANT with distinguishing type incompatible |
140 | constants in the types_compatible_p sense. */ | |
141 | ||
142 | static inline hashval_t | |
143 | vn_hash_constant_with_type (tree constant) | |
144 | { | |
f32e91d5 | 145 | inchash::hash hstate; |
146 | inchash::add_expr (constant, hstate); | |
147 | hstate.merge_hash (vn_hash_type (TREE_TYPE (constant))); | |
148 | return hstate.end (); | |
75a70cf9 | 149 | } |
150 | ||
151 | /* Compare the constants C1 and C2 with distinguishing type incompatible | |
152 | constants in the types_compatible_p sense. */ | |
153 | ||
154 | static inline bool | |
155 | vn_constant_eq_with_type (tree c1, tree c2) | |
156 | { | |
157 | return (expressions_equal_p (c1, c2) | |
158 | && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2))); | |
159 | } | |
160 | ||
9e9e6e3e | 161 | typedef struct vn_ssa_aux |
162 | { | |
9e9e6e3e | 163 | /* Value number. This may be an SSA name or a constant. */ |
164 | tree valnum; | |
165 | /* Representative expression, if not a direct constant. */ | |
166 | tree expr; | |
6d6adc82 | 167 | |
f6c33c78 | 168 | /* Unique identifier that all expressions with the same value have. */ |
169 | unsigned int value_id; | |
170 | ||
6d6adc82 | 171 | /* SCC information. */ |
172 | unsigned int dfsnum; | |
173 | unsigned int low; | |
174 | unsigned visited : 1; | |
175 | unsigned on_sccstack : 1; | |
176 | ||
9e9e6e3e | 177 | /* Whether the representative expression contains constants. */ |
6d6adc82 | 178 | unsigned has_constants : 1; |
9e9e6e3e | 179 | /* Whether the SSA_NAME has been value numbered already. This is |
180 | only saying whether visit_use has been called on it at least | |
181 | once. It cannot be used to avoid visitation for SSA_NAME's | |
182 | involved in non-singleton SCC's. */ | |
6d6adc82 | 183 | unsigned use_processed : 1; |
1d9353f3 | 184 | |
185 | /* Whether the SSA_NAME has no defining statement and thus an | |
186 | insertion of such with EXPR as definition is required before | |
187 | a use can be created of it. */ | |
188 | unsigned needs_insertion : 1; | |
9e9e6e3e | 189 | } *vn_ssa_aux_t; |
190 | ||
8f190c8a | 191 | typedef enum { VN_NOWALK, VN_WALK, VN_WALKREWRITE } vn_lookup_kind; |
192 | ||
9e9e6e3e | 193 | /* Return the value numbering info for an SSA_NAME. */ |
194 | extern vn_ssa_aux_t VN_INFO (tree); | |
195 | extern vn_ssa_aux_t VN_INFO_GET (tree); | |
75a70cf9 | 196 | tree vn_get_expr_for (tree); |
8f190c8a | 197 | bool run_scc_vn (vn_lookup_kind); |
9e9e6e3e | 198 | void free_scc_vn (void); |
f6c33c78 | 199 | tree vn_nary_op_lookup (tree, vn_nary_op_t *); |
75a70cf9 | 200 | tree vn_nary_op_lookup_stmt (gimple, vn_nary_op_t *); |
f6c33c78 | 201 | tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code, |
7384c678 | 202 | tree, tree *, vn_nary_op_t *); |
f6c33c78 | 203 | vn_nary_op_t vn_nary_op_insert (tree, tree); |
75a70cf9 | 204 | vn_nary_op_t vn_nary_op_insert_stmt (gimple, tree); |
f6c33c78 | 205 | vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code, |
7384c678 | 206 | tree, tree *, tree, unsigned int); |
f1f41a6c | 207 | void vn_reference_fold_indirect (vec<vn_reference_op_s> *, |
d12dee9c | 208 | unsigned int *); |
3918bd18 | 209 | bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree, |
f1f41a6c | 210 | vec<vn_reference_op_s> ); |
3918bd18 | 211 | tree vn_reference_lookup_pieces (tree, alias_set_type, tree, |
f1f41a6c | 212 | vec<vn_reference_op_s> , |
8ecc6b38 | 213 | vn_reference_t *, vn_lookup_kind); |
214 | tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *); | |
1a91d914 | 215 | void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t); |
3918bd18 | 216 | vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree, |
f1f41a6c | 217 | vec<vn_reference_op_s> , |
f6c33c78 | 218 | tree, unsigned int); |
219 | ||
3e871d4d | 220 | bool vn_nary_op_eq (const_vn_nary_op_t const vno1, |
221 | const_vn_nary_op_t const vno2); | |
2ac47fdf | 222 | bool vn_nary_may_trap (vn_nary_op_t); |
3e871d4d | 223 | bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const); |
f6c33c78 | 224 | unsigned int get_max_value_id (void); |
225 | unsigned int get_next_value_id (void); | |
8c8a7011 | 226 | unsigned int get_constant_value_id (tree); |
f6c33c78 | 227 | unsigned int get_or_alloc_constant_value_id (tree); |
228 | bool value_id_constant_p (unsigned int); | |
c26ce8a9 | 229 | tree fully_constant_vn_reference_p (vn_reference_t); |
51385f30 | 230 | |
231 | /* Valueize NAME if it is an SSA name, otherwise just return it. */ | |
232 | ||
233 | static inline tree | |
234 | vn_valueize (tree name) | |
235 | { | |
236 | if (TREE_CODE (name) == SSA_NAME) | |
237 | { | |
238 | tree tem = VN_INFO (name)->valnum; | |
239 | return tem == VN_TOP ? name : tem; | |
240 | } | |
241 | return name; | |
242 | } | |
243 | ||
9e9e6e3e | 244 | #endif /* TREE_SSA_SCCVN_H */ |