]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | /* SSA operand management for trees. |
f93089d2 | 2 | Copyright (C) 2003, 2005 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
8 | Software Foundation; either version 2, or (at your option) any later | |
9 | version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING. If not, write to the Free | |
366ccddb KC |
18 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA |
19 | 02110-1301, USA. */ | |
6de9cd9a DN |
20 | |
21 | #ifndef GCC_TREE_SSA_OPERANDS_H | |
22 | #define GCC_TREE_SSA_OPERANDS_H | |
23 | ||
24 | /* Interface to SSA operands. */ | |
25 | ||
d00ad49b AM |
26 | |
27 | /* This represents a pointer to a DEF operand. */ | |
f47c96aa | 28 | typedef tree *def_operand_p; |
d00ad49b AM |
29 | |
30 | /* This represents a pointer to a USE operand. */ | |
f47c96aa | 31 | typedef ssa_use_operand_t *use_operand_p; |
d00ad49b | 32 | |
f47c96aa | 33 | /* NULL operand types. */ |
f430bae8 | 34 | #define NULL_USE_OPERAND_P NULL |
f47c96aa | 35 | #define NULL_DEF_OPERAND_P NULL |
d00ad49b AM |
36 | |
37 | /* This represents the DEF operands of a stmt. */ | |
f47c96aa | 38 | struct def_optype_d |
6de9cd9a | 39 | { |
f47c96aa AM |
40 | struct def_optype_d *next; |
41 | tree *def_ptr; | |
42 | }; | |
43 | typedef struct def_optype_d *def_optype_p; | |
f430bae8 | 44 | |
d00ad49b | 45 | /* This represents the USE operands of a stmt. */ |
f47c96aa | 46 | struct use_optype_d |
1a24f92f | 47 | { |
f47c96aa AM |
48 | struct use_optype_d *next; |
49 | struct ssa_use_operand_d use_ptr; | |
50 | }; | |
51 | typedef struct use_optype_d *use_optype_p; | |
1a24f92f | 52 | |
38635499 | 53 | typedef struct vuse_element_d |
6de9cd9a | 54 | { |
f47c96aa AM |
55 | tree use_var; |
56 | struct ssa_use_operand_d use_ptr; | |
38635499 DN |
57 | } vuse_element_t; |
58 | ||
59 | typedef struct vuse_vec_d | |
60 | { | |
61 | int num_vuse; | |
62 | vuse_element_t uses[1]; | |
63 | } vuse_vec_t; | |
64 | typedef struct vuse_vec_d *vuse_vec_p; | |
65 | ||
66 | #define VUSE_VECT_NUM_ELEM(V) (V).num_vuse | |
67 | #define VUSE_VECT_ELEMENT_NC(V,X) (V).uses[(X)] | |
68 | #define VUSE_ELEMENT_PTR_NC(V,X) (&(VUSE_VECT_ELEMENT_NC ((V),(X)).use_ptr)) | |
69 | #define VUSE_ELEMENT_VAR_NC(V,X) (VUSE_VECT_ELEMENT_NC ((V),(X)).use_var) | |
70 | ||
71 | #ifdef ENABLE_CHECKING | |
72 | #define VUSE_VECT_ELEMENT(V,X) \ | |
73 | (gcc_assert ((X) >= 0 && (X) < VUSE_VECT_NUM_ELEM (V)), \ | |
74 | VUSE_VECT_ELEMENT_NC (V,X)) | |
75 | ||
76 | #define VUSE_ELEMENT_PTR(V,X) \ | |
77 | (gcc_assert ((X) >= 0 && (X) < VUSE_VECT_NUM_ELEM (V)), \ | |
78 | VUSE_ELEMENT_PTR_NC (V, X)) | |
79 | ||
80 | #define SET_VUSE_VECT_ELEMENT(V,X,N) \ | |
81 | (gcc_assert ((X) >= 0 && (X) < VUSE_VECT_NUM_ELEM (V)), \ | |
82 | VUSE_VECT_ELEMENT_NC (V,X) = (N)) | |
83 | ||
84 | #define SET_VUSE_ELEMENT_VAR(V,X,N) \ | |
85 | (gcc_assert ((X) >= 0 && (X) < VUSE_VECT_NUM_ELEM (V)), \ | |
86 | VUSE_VECT_ELEMENT_NC ((V),(X)).use_var = (N)) | |
87 | ||
88 | #define SET_VUSE_ELEMENT_PTR(V,X,N) \ | |
89 | (gcc_assert ((X) >= 0 && (X) < VUSE_VECT_NUM_ELEM (V)), \ | |
90 | VUSE_ELEMENT_PTR_NC (V, X) = (N)) | |
91 | #else | |
92 | #define VUSE_VECT_ELEMENT(V,X) VUSE_VECT_ELEMENT_NC(V,X) | |
93 | #define VUSE_ELEMENT_PTR(V,X) VUSE_ELEMENT_PTR_NC(V,X) | |
94 | #define SET_VUSE_VECT_ELEMENT(V,X,N) VUSE_VECT_ELEMENT_NC(V,X) = (N) | |
95 | #define SET_VUSE_ELEMENT_PTR(V,X,N) VUSE_ELEMENT_PTR_NC(V,X) = (N) | |
96 | #define SET_VUSE_ELEMENT_VAR(V,X,N) VUSE_VECT_ELEMENT_NC ((V),(X)).use_var = (N) | |
97 | #endif | |
98 | ||
99 | #define VUSE_ELEMENT_VAR(V,X) (VUSE_VECT_ELEMENT ((V),(X)).use_var) | |
100 | ||
79f99d42 AM |
101 | /* This represents the virtual ops of a stmt. */ |
102 | struct voptype_d | |
38635499 | 103 | { |
79f99d42 | 104 | struct voptype_d *next; |
38635499 DN |
105 | tree def_var; |
106 | vuse_vec_t usev; | |
f47c96aa | 107 | }; |
79f99d42 | 108 | typedef struct voptype_d *voptype_p; |
f430bae8 | 109 | |
79f99d42 AM |
110 | /* This structure represents a variable sized buffer which is allocated by the |
111 | operand memory manager. Operands are subalocated out of this block. The | |
112 | MEM array varies in size. */ | |
113 | ||
f47c96aa | 114 | struct ssa_operand_memory_d GTY((chain_next("%h.next"))) |
a32b97a2 | 115 | { |
f47c96aa | 116 | struct ssa_operand_memory_d *next; |
79f99d42 | 117 | char mem[1]; |
f47c96aa | 118 | }; |
a32b97a2 | 119 | |
79f99d42 AM |
120 | /* Number of different size free buckets for virtual operands. */ |
121 | #define NUM_VOP_FREE_BUCKETS 29 | |
122 | ||
456cde30 JH |
123 | /* Per-function operand caches. */ |
124 | struct ssa_operands GTY(()) { | |
125 | struct ssa_operand_memory_d *operand_memory; | |
126 | unsigned operand_memory_index; | |
127 | ||
128 | bool ops_active; | |
129 | ||
130 | struct def_optype_d * GTY ((skip (""))) free_defs; | |
131 | struct use_optype_d * GTY ((skip (""))) free_uses; | |
79f99d42 | 132 | struct voptype_d * GTY ((skip (""))) vop_free_buckets[NUM_VOP_FREE_BUCKETS]; |
38635499 | 133 | VEC(tree,heap) * GTY ((skip (""))) mpt_table; |
456cde30 | 134 | }; |
a32b97a2 | 135 | |
a80769d7 | 136 | /* This represents the operand cache for a stmt. */ |
f47c96aa | 137 | struct stmt_operands_d |
1a24f92f AM |
138 | { |
139 | /* Statement operands. */ | |
f47c96aa AM |
140 | struct def_optype_d * def_ops; |
141 | struct use_optype_d * use_ops; | |
142 | ||
38635499 | 143 | /* Virtual operands (VDEF, VUSE). */ |
79f99d42 AM |
144 | struct voptype_d * vdef_ops; |
145 | struct voptype_d * vuse_ops; | |
38635499 DN |
146 | |
147 | /* Sets of memory symbols loaded and stored. */ | |
148 | bitmap stores; | |
149 | bitmap loads; | |
f47c96aa AM |
150 | }; |
151 | ||
152 | typedef struct stmt_operands_d *stmt_operands_p; | |
153 | ||
154 | #define USE_FROM_PTR(PTR) get_use_from_ptr (PTR) | |
155 | #define DEF_FROM_PTR(PTR) get_def_from_ptr (PTR) | |
156 | #define SET_USE(USE, V) set_ssa_use_from_ptr (USE, V) | |
157 | #define SET_DEF(DEF, V) ((*(DEF)) = (V)) | |
158 | ||
159 | #define USE_STMT(USE) (USE)->stmt | |
160 | ||
161 | #define DEF_OPS(STMT) (stmt_ann (STMT)->operands.def_ops) | |
162 | #define USE_OPS(STMT) (stmt_ann (STMT)->operands.use_ops) | |
163 | #define VUSE_OPS(STMT) (stmt_ann (STMT)->operands.vuse_ops) | |
38635499 DN |
164 | #define VDEF_OPS(STMT) (stmt_ann (STMT)->operands.vdef_ops) |
165 | ||
166 | #define LOADED_SYMS(STMT) (stmt_ann (STMT)->operands.loads) | |
167 | #define STORED_SYMS(STMT) (stmt_ann (STMT)->operands.stores) | |
f47c96aa AM |
168 | |
169 | #define USE_OP_PTR(OP) (&((OP)->use_ptr)) | |
170 | #define USE_OP(OP) (USE_FROM_PTR (USE_OP_PTR (OP))) | |
171 | ||
172 | #define DEF_OP_PTR(OP) ((OP)->def_ptr) | |
173 | #define DEF_OP(OP) (DEF_FROM_PTR (DEF_OP_PTR (OP))) | |
174 | ||
38635499 DN |
175 | #define VUSE_OP_PTR(OP,X) VUSE_ELEMENT_PTR ((OP)->usev, (X)) |
176 | #define VUSE_OP(OP,X) VUSE_ELEMENT_VAR ((OP)->usev, (X)) | |
177 | #define SET_VUSE_OP(OP,X,N) SET_VUSE_ELEMENT_VAR ((OP)->usev, (X), (N)) | |
178 | #define VUSE_NUM(OP) VUSE_VECT_NUM_ELEM ((OP)->usev) | |
179 | #define VUSE_VECT(OP) &((OP)->usev) | |
f47c96aa | 180 | |
38635499 DN |
181 | #define VDEF_RESULT_PTR(OP) (&((OP)->def_var)) |
182 | #define VDEF_RESULT(OP) ((OP)->def_var) | |
183 | #define VDEF_OP_PTR(OP,X) VUSE_OP_PTR (OP, X) | |
184 | #define VDEF_OP(OP,X) VUSE_OP (OP, X) | |
185 | #define SET_VDEF_OP(OP,X,N) SET_VUSE_OP (OP, X, N) | |
186 | #define VDEF_NUM(OP) VUSE_VECT_NUM_ELEM ((OP)->usev) | |
187 | #define VDEF_VECT(OP) &((OP)->usev) | |
d00ad49b AM |
188 | |
189 | #define PHI_RESULT_PTR(PHI) get_phi_result_ptr (PHI) | |
190 | #define PHI_RESULT(PHI) DEF_FROM_PTR (PHI_RESULT_PTR (PHI)) | |
191 | #define SET_PHI_RESULT(PHI, V) SET_DEF (PHI_RESULT_PTR (PHI), (V)) | |
192 | ||
193 | #define PHI_ARG_DEF_PTR(PHI, I) get_phi_arg_def_ptr ((PHI), (I)) | |
194 | #define PHI_ARG_DEF(PHI, I) USE_FROM_PTR (PHI_ARG_DEF_PTR ((PHI), (I))) | |
195 | #define SET_PHI_ARG_DEF(PHI, I, V) \ | |
196 | SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V)) | |
197 | #define PHI_ARG_DEF_FROM_EDGE(PHI, E) \ | |
3a2f1f06 | 198 | PHI_ARG_DEF ((PHI), (E)->dest_idx) |
d00ad49b | 199 | #define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E) \ |
3a2f1f06 | 200 | PHI_ARG_DEF_PTR ((PHI), (E)->dest_idx) |
f430bae8 | 201 | #define PHI_ARG_INDEX_FROM_USE(USE) phi_arg_index_from_use (USE) |
d00ad49b | 202 | |
a32b97a2 | 203 | |
79f99d42 AM |
204 | extern struct voptype_d *realloc_vdef (struct voptype_d *, int); |
205 | extern struct voptype_d *realloc_vuse (struct voptype_d *, int); | |
38635499 | 206 | |
6de9cd9a DN |
207 | extern void init_ssa_operands (void); |
208 | extern void fini_ssa_operands (void); | |
6844185d | 209 | extern void free_ssa_operands (stmt_operands_p); |
f430bae8 AM |
210 | extern void update_stmt_operands (tree); |
211 | extern bool verify_imm_links (FILE *f, tree var); | |
212 | ||
5f240ec4 | 213 | extern void copy_virtual_operands (tree, tree); |
cfaab3a9 | 214 | extern void create_ssa_artificial_load_stmt (tree, tree); |
6de9cd9a | 215 | |
f430bae8 AM |
216 | extern void dump_immediate_uses (FILE *file); |
217 | extern void dump_immediate_uses_for (FILE *file, tree var); | |
218 | extern void debug_immediate_uses (void); | |
219 | extern void debug_immediate_uses_for (tree var); | |
38635499 DN |
220 | extern void dump_decl_set (FILE *, bitmap); |
221 | extern void debug_decl_set (bitmap); | |
f430bae8 | 222 | |
f47c96aa AM |
223 | extern bool ssa_operands_active (void); |
224 | ||
e8ca4159 | 225 | extern void add_to_addressable_set (tree, bitmap *); |
cfaab3a9 DN |
226 | extern void push_stmt_changes (tree *); |
227 | extern void pop_stmt_changes (tree *); | |
228 | extern void discard_stmt_changes (tree *); | |
e8ca4159 | 229 | |
f47c96aa AM |
230 | enum ssa_op_iter_type { |
231 | ssa_op_iter_none = 0, | |
232 | ssa_op_iter_tree, | |
233 | ssa_op_iter_use, | |
234 | ssa_op_iter_def, | |
38635499 | 235 | ssa_op_iter_vdef |
f47c96aa | 236 | }; |
38635499 | 237 | |
4c124b4c | 238 | /* This structure is used in the operand iterator loops. It contains the |
2a7e31df | 239 | items required to determine which operand is retrieved next. During |
4c124b4c AM |
240 | optimization, this structure is scalarized, and any unused fields are |
241 | optimized away, resulting in little overhead. */ | |
242 | ||
243 | typedef struct ssa_operand_iterator_d | |
244 | { | |
f47c96aa AM |
245 | def_optype_p defs; |
246 | use_optype_p uses; | |
79f99d42 AM |
247 | voptype_p vuses; |
248 | voptype_p vdefs; | |
249 | voptype_p mayuses; | |
f47c96aa AM |
250 | enum ssa_op_iter_type iter_type; |
251 | int phi_i; | |
252 | int num_phi; | |
253 | tree phi_stmt; | |
4c124b4c | 254 | bool done; |
38635499 DN |
255 | int vuse_index; |
256 | int mayuse_index; | |
4c124b4c AM |
257 | } ssa_op_iter; |
258 | ||
259 | /* These flags are used to determine which operands are returned during | |
260 | execution of the loop. */ | |
261 | #define SSA_OP_USE 0x01 /* Real USE operands. */ | |
262 | #define SSA_OP_DEF 0x02 /* Real DEF operands. */ | |
263 | #define SSA_OP_VUSE 0x04 /* VUSE operands. */ | |
38635499 DN |
264 | #define SSA_OP_VMAYUSE 0x08 /* USE portion of VDEFS. */ |
265 | #define SSA_OP_VDEF 0x10 /* DEF portion of VDEFS. */ | |
4c124b4c AM |
266 | |
267 | /* These are commonly grouped operand flags. */ | |
268 | #define SSA_OP_VIRTUAL_USES (SSA_OP_VUSE | SSA_OP_VMAYUSE) | |
38635499 DN |
269 | #define SSA_OP_VIRTUAL_DEFS (SSA_OP_VDEF) |
270 | #define SSA_OP_ALL_VIRTUALS (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_DEFS) | |
4c124b4c AM |
271 | #define SSA_OP_ALL_USES (SSA_OP_VIRTUAL_USES | SSA_OP_USE) |
272 | #define SSA_OP_ALL_DEFS (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF) | |
38635499 | 273 | #define SSA_OP_ALL_OPERANDS (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS) |
4c124b4c AM |
274 | |
275 | /* This macro executes a loop over the operands of STMT specified in FLAG, | |
276 | returning each operand as a 'tree' in the variable TREEVAR. ITER is an | |
277 | ssa_op_iter structure used to control the loop. */ | |
278 | #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS) \ | |
279 | for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS); \ | |
280 | !op_iter_done (&(ITER)); \ | |
281 | TREEVAR = op_iter_next_tree (&(ITER))) | |
282 | ||
283 | /* This macro executes a loop over the operands of STMT specified in FLAG, | |
284 | returning each operand as a 'use_operand_p' in the variable USEVAR. | |
285 | ITER is an ssa_op_iter structure used to control the loop. */ | |
286 | #define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS) \ | |
287 | for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS); \ | |
288 | !op_iter_done (&(ITER)); \ | |
289 | USEVAR = op_iter_next_use (&(ITER))) | |
290 | ||
291 | /* This macro executes a loop over the operands of STMT specified in FLAG, | |
292 | returning each operand as a 'def_operand_p' in the variable DEFVAR. | |
293 | ITER is an ssa_op_iter structure used to control the loop. */ | |
294 | #define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS) \ | |
295 | for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS); \ | |
296 | !op_iter_done (&(ITER)); \ | |
297 | DEFVAR = op_iter_next_def (&(ITER))) | |
298 | ||
38635499 DN |
299 | /* This macro executes a loop over the VDEF operands of STMT. The def |
300 | and use for each VDEF is returned in DEFVAR and USEVAR. | |
db30731a | 301 | ITER is an ssa_op_iter structure used to control the loop. */ |
38635499 DN |
302 | #define FOR_EACH_SSA_VDEF_OPERAND(DEFVAR, USEVAR, STMT, ITER) \ |
303 | for (op_iter_init_vdef (&(ITER), STMT, &(USEVAR), &(DEFVAR)); \ | |
db30731a | 304 | !op_iter_done (&(ITER)); \ |
38635499 | 305 | op_iter_next_vdef (&(USEVAR), &(DEFVAR), &(ITER))) |
f47c96aa | 306 | |
395bda42 KH |
307 | /* This macro will execute a loop over all the arguments of a PHI which |
308 | match FLAGS. A use_operand_p is always returned via USEVAR. FLAGS | |
309 | can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES. */ | |
29d51cdb | 310 | #define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS) \ |
f47c96aa AM |
311 | for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS); \ |
312 | !op_iter_done (&(ITER)); \ | |
313 | (USEVAR) = op_iter_next_use (&(ITER))) | |
314 | ||
315 | ||
316 | /* This macro will execute a loop over a stmt, regardless of whether it is | |
317 | a real stmt or a PHI node, looking at the USE nodes matching FLAGS. */ | |
318 | #define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS) \ | |
319 | for ((USEVAR) = (TREE_CODE (STMT) == PHI_NODE \ | |
320 | ? op_iter_init_phiuse (&(ITER), STMT, FLAGS) \ | |
321 | : op_iter_init_use (&(ITER), STMT, FLAGS)); \ | |
322 | !op_iter_done (&(ITER)); \ | |
323 | (USEVAR) = op_iter_next_use (&(ITER))) | |
324 | ||
325 | /* This macro will execute a loop over a stmt, regardless of whether it is | |
326 | a real stmt or a PHI node, looking at the DEF nodes matching FLAGS. */ | |
327 | #define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS) \ | |
328 | for ((DEFVAR) = (TREE_CODE (STMT) == PHI_NODE \ | |
329 | ? op_iter_init_phidef (&(ITER), STMT, FLAGS) \ | |
330 | : op_iter_init_def (&(ITER), STMT, FLAGS)); \ | |
331 | !op_iter_done (&(ITER)); \ | |
332 | (DEFVAR) = op_iter_next_def (&(ITER))) | |
333 | ||
334 | /* This macro returns an operand in STMT as a tree if it is the ONLY | |
335 | operand matching FLAGS. If there are 0 or more than 1 operand matching | |
336 | FLAGS, then NULL_TREE is returned. */ | |
337 | #define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS) \ | |
338 | single_ssa_tree_operand (STMT, FLAGS) | |
339 | ||
340 | /* This macro returns an operand in STMT as a use_operand_p if it is the ONLY | |
341 | operand matching FLAGS. If there are 0 or more than 1 operand matching | |
342 | FLAGS, then NULL_USE_OPERAND_P is returned. */ | |
343 | #define SINGLE_SSA_USE_OPERAND(STMT, FLAGS) \ | |
344 | single_ssa_use_operand (STMT, FLAGS) | |
345 | ||
346 | /* This macro returns an operand in STMT as a def_operand_p if it is the ONLY | |
347 | operand matching FLAGS. If there are 0 or more than 1 operand matching | |
348 | FLAGS, then NULL_DEF_OPERAND_P is returned. */ | |
349 | #define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS) \ | |
350 | single_ssa_def_operand (STMT, FLAGS) | |
29d51cdb SB |
351 | |
352 | /* This macro returns TRUE if there are no operands matching FLAGS in STMT. */ | |
f47c96aa AM |
353 | #define ZERO_SSA_OPERANDS(STMT, FLAGS) zero_ssa_operands (STMT, FLAGS) |
354 | ||
395bda42 | 355 | /* This macro counts the number of operands in STMT matching FLAGS. */ |
f47c96aa AM |
356 | #define NUM_SSA_OPERANDS(STMT, FLAGS) num_ssa_operands (STMT, FLAGS) |
357 | ||
38635499 DN |
358 | extern tree get_mpt_for (tree); |
359 | extern void dump_memory_partitions (FILE *); | |
360 | extern void debug_memory_partitions (void); | |
361 | ||
6de9cd9a | 362 | #endif /* GCC_TREE_SSA_OPERANDS_H */ |