* tree-cfg.c (tree_find_edge_insert_loc): Handle naked RETURN_EXPR.
[official-gcc.git] / gcc / tree-ssa-operands.h
blobc1ec3650ee100aca26577add5c06025e31070f10
1 /* SSA operand management for trees.
2 Copyright (C) 2003, 2005 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA. */
21 #ifndef GCC_TREE_SSA_OPERANDS_H
22 #define GCC_TREE_SSA_OPERANDS_H
24 /* Interface to SSA operands. */
27 /* This represents a pointer to a DEF operand. */
28 typedef tree *def_operand_p;
30 /* This represents a pointer to a USE operand. */
31 typedef ssa_use_operand_t *use_operand_p;
33 /* NULL operand types. */
34 #define NULL_USE_OPERAND_P NULL
35 #define NULL_DEF_OPERAND_P NULL
37 /* This represents the DEF operands of a stmt. */
38 struct def_optype_d
40 struct def_optype_d *next;
41 tree *def_ptr;
43 typedef struct def_optype_d *def_optype_p;
45 /* This represents the USE operands of a stmt. */
46 struct use_optype_d
48 struct use_optype_d *next;
49 struct ssa_use_operand_d use_ptr;
51 typedef struct use_optype_d *use_optype_p;
53 /* This represents the MAY_DEFS for a stmt. */
54 struct maydef_optype_d
56 struct maydef_optype_d *next;
57 tree def_var;
58 tree use_var;
59 struct ssa_use_operand_d use_ptr;
61 typedef struct maydef_optype_d *maydef_optype_p;
63 /* This represents the VUSEs for a stmt. */
64 struct vuse_optype_d
66 struct vuse_optype_d *next;
67 tree use_var;
68 struct ssa_use_operand_d use_ptr;
70 typedef struct vuse_optype_d *vuse_optype_p;
72 /* This represents the V_MUST_DEFS for a stmt. */
73 struct mustdef_optype_d
75 struct mustdef_optype_d *next;
76 tree def_var;
77 tree kill_var;
78 struct ssa_use_operand_d use_ptr;
80 typedef struct mustdef_optype_d *mustdef_optype_p;
83 #define SSA_OPERAND_MEMORY_SIZE (2048 - sizeof (void *))
85 struct ssa_operand_memory_d GTY((chain_next("%h.next")))
87 struct ssa_operand_memory_d *next;
88 char mem[SSA_OPERAND_MEMORY_SIZE];
92 /* This represents the operand cache for a stmt. */
93 struct stmt_operands_d
95 /* Statement operands. */
96 struct def_optype_d * def_ops;
97 struct use_optype_d * use_ops;
99 /* Virtual operands (V_MAY_DEF, VUSE, and V_MUST_DEF). */
100 struct maydef_optype_d * maydef_ops;
101 struct vuse_optype_d * vuse_ops;
102 struct mustdef_optype_d * mustdef_ops;
105 typedef struct stmt_operands_d *stmt_operands_p;
107 #define USE_FROM_PTR(PTR) get_use_from_ptr (PTR)
108 #define DEF_FROM_PTR(PTR) get_def_from_ptr (PTR)
109 #define SET_USE(USE, V) set_ssa_use_from_ptr (USE, V)
110 #define SET_DEF(DEF, V) ((*(DEF)) = (V))
112 #define USE_STMT(USE) (USE)->stmt
114 #define DEF_OPS(STMT) (stmt_ann (STMT)->operands.def_ops)
115 #define USE_OPS(STMT) (stmt_ann (STMT)->operands.use_ops)
116 #define VUSE_OPS(STMT) (stmt_ann (STMT)->operands.vuse_ops)
117 #define MAYDEF_OPS(STMT) (stmt_ann (STMT)->operands.maydef_ops)
118 #define MUSTDEF_OPS(STMT) (stmt_ann (STMT)->operands.mustdef_ops)
120 #define USE_OP_PTR(OP) (&((OP)->use_ptr))
121 #define USE_OP(OP) (USE_FROM_PTR (USE_OP_PTR (OP)))
123 #define DEF_OP_PTR(OP) ((OP)->def_ptr)
124 #define DEF_OP(OP) (DEF_FROM_PTR (DEF_OP_PTR (OP)))
126 #define VUSE_OP_PTR(OP) USE_OP_PTR(OP)
127 #define VUSE_OP(OP) ((OP)->use_var)
129 #define MAYDEF_RESULT_PTR(OP) (&((OP)->def_var))
130 #define MAYDEF_RESULT(OP) ((OP)->def_var)
131 #define MAYDEF_OP_PTR(OP) USE_OP_PTR (OP)
132 #define MAYDEF_OP(OP) ((OP)->use_var)
134 #define MUSTDEF_RESULT_PTR(OP) (&((OP)->def_var))
135 #define MUSTDEF_RESULT(OP) ((OP)->def_var)
136 #define MUSTDEF_KILL_PTR(OP) USE_OP_PTR (OP)
137 #define MUSTDEF_KILL(OP) ((OP)->kill_var)
139 #define PHI_RESULT_PTR(PHI) get_phi_result_ptr (PHI)
140 #define PHI_RESULT(PHI) DEF_FROM_PTR (PHI_RESULT_PTR (PHI))
141 #define SET_PHI_RESULT(PHI, V) SET_DEF (PHI_RESULT_PTR (PHI), (V))
143 #define PHI_ARG_DEF_PTR(PHI, I) get_phi_arg_def_ptr ((PHI), (I))
144 #define PHI_ARG_DEF(PHI, I) USE_FROM_PTR (PHI_ARG_DEF_PTR ((PHI), (I)))
145 #define SET_PHI_ARG_DEF(PHI, I, V) \
146 SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V))
147 #define PHI_ARG_DEF_FROM_EDGE(PHI, E) \
148 PHI_ARG_DEF ((PHI), (E)->dest_idx)
149 #define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E) \
150 PHI_ARG_DEF_PTR ((PHI), (E)->dest_idx)
151 #define PHI_ARG_INDEX_FROM_USE(USE) phi_arg_index_from_use (USE)
154 extern void init_ssa_operands (void);
155 extern void fini_ssa_operands (void);
156 extern void free_ssa_operands (stmt_operands_p);
157 extern void update_stmt_operands (tree);
158 extern bool verify_imm_links (FILE *f, tree var);
160 extern void copy_virtual_operands (tree, tree);
161 extern void create_ssa_artficial_load_stmt (tree, tree);
163 extern void dump_immediate_uses (FILE *file);
164 extern void dump_immediate_uses_for (FILE *file, tree var);
165 extern void debug_immediate_uses (void);
166 extern void debug_immediate_uses_for (tree var);
168 extern bool ssa_call_clobbered_cache_valid;
169 extern bool ssa_ro_call_cache_valid;
171 extern bool ssa_operands_active (void);
173 extern void add_to_addressable_set (tree, bitmap *);
175 enum ssa_op_iter_type {
176 ssa_op_iter_none = 0,
177 ssa_op_iter_tree,
178 ssa_op_iter_use,
179 ssa_op_iter_def,
180 ssa_op_iter_maymustdef
182 /* This structure is used in the operand iterator loops. It contains the
183 items required to determine which operand is retrieved next. During
184 optimization, this structure is scalarized, and any unused fields are
185 optimized away, resulting in little overhead. */
187 typedef struct ssa_operand_iterator_d
189 def_optype_p defs;
190 use_optype_p uses;
191 vuse_optype_p vuses;
192 maydef_optype_p maydefs;
193 maydef_optype_p mayuses;
194 mustdef_optype_p mustdefs;
195 mustdef_optype_p mustkills;
196 enum ssa_op_iter_type iter_type;
197 int phi_i;
198 int num_phi;
199 tree phi_stmt;
200 bool done;
201 } ssa_op_iter;
203 /* These flags are used to determine which operands are returned during
204 execution of the loop. */
205 #define SSA_OP_USE 0x01 /* Real USE operands. */
206 #define SSA_OP_DEF 0x02 /* Real DEF operands. */
207 #define SSA_OP_VUSE 0x04 /* VUSE operands. */
208 #define SSA_OP_VMAYUSE 0x08 /* USE portion of V_MAY_DEFS. */
209 #define SSA_OP_VMAYDEF 0x10 /* DEF portion of V_MAY_DEFS. */
210 #define SSA_OP_VMUSTDEF 0x20 /* V_MUST_DEF definitions. */
211 #define SSA_OP_VMUSTKILL 0x40 /* V_MUST_DEF kills. */
213 /* These are commonly grouped operand flags. */
214 #define SSA_OP_VIRTUAL_USES (SSA_OP_VUSE | SSA_OP_VMAYUSE)
215 #define SSA_OP_VIRTUAL_DEFS (SSA_OP_VMAYDEF | SSA_OP_VMUSTDEF)
216 #define SSA_OP_VIRTUAL_KILLS (SSA_OP_VMUSTKILL)
217 #define SSA_OP_ALL_VIRTUALS (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_KILLS \
218 | SSA_OP_VIRTUAL_DEFS)
219 #define SSA_OP_ALL_USES (SSA_OP_VIRTUAL_USES | SSA_OP_USE)
220 #define SSA_OP_ALL_DEFS (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF)
221 #define SSA_OP_ALL_KILLS (SSA_OP_VIRTUAL_KILLS)
222 #define SSA_OP_ALL_OPERANDS (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS \
223 | SSA_OP_ALL_KILLS)
225 /* This macro executes a loop over the operands of STMT specified in FLAG,
226 returning each operand as a 'tree' in the variable TREEVAR. ITER is an
227 ssa_op_iter structure used to control the loop. */
228 #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS) \
229 for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS); \
230 !op_iter_done (&(ITER)); \
231 TREEVAR = op_iter_next_tree (&(ITER)))
233 /* This macro executes a loop over the operands of STMT specified in FLAG,
234 returning each operand as a 'use_operand_p' in the variable USEVAR.
235 ITER is an ssa_op_iter structure used to control the loop. */
236 #define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS) \
237 for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS); \
238 !op_iter_done (&(ITER)); \
239 USEVAR = op_iter_next_use (&(ITER)))
241 /* This macro executes a loop over the operands of STMT specified in FLAG,
242 returning each operand as a 'def_operand_p' in the variable DEFVAR.
243 ITER is an ssa_op_iter structure used to control the loop. */
244 #define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS) \
245 for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS); \
246 !op_iter_done (&(ITER)); \
247 DEFVAR = op_iter_next_def (&(ITER)))
249 /* This macro executes a loop over the V_MAY_DEF operands of STMT. The def
250 and use for each V_MAY_DEF is returned in DEFVAR and USEVAR.
251 ITER is an ssa_op_iter structure used to control the loop. */
252 #define FOR_EACH_SSA_MAYDEF_OPERAND(DEFVAR, USEVAR, STMT, ITER) \
253 for (op_iter_init_maydef (&(ITER), STMT, &(USEVAR), &(DEFVAR)); \
254 !op_iter_done (&(ITER)); \
255 op_iter_next_maymustdef (&(USEVAR), &(DEFVAR), &(ITER)))
257 /* This macro executes a loop over the V_MUST_DEF operands of STMT. The def
258 and kill for each V_MUST_DEF is returned in DEFVAR and KILLVAR.
259 ITER is an ssa_op_iter structure used to control the loop. */
260 #define FOR_EACH_SSA_MUSTDEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER) \
261 for (op_iter_init_mustdef (&(ITER), STMT, &(KILLVAR), &(DEFVAR)); \
262 !op_iter_done (&(ITER)); \
263 op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
265 /* This macro executes a loop over the V_{MUST,MAY}_DEF of STMT. The def
266 and kill for each V_{MUST,MAY}_DEF is returned in DEFVAR and KILLVAR.
267 ITER is an ssa_op_iter structure used to control the loop. */
268 #define FOR_EACH_SSA_MUST_AND_MAY_DEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER)\
269 for (op_iter_init_must_and_may_def (&(ITER), STMT, &(KILLVAR), &(DEFVAR));\
270 !op_iter_done (&(ITER)); \
271 op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
273 /* This macro will execute a loop over all the arguments of a PHI which
274 match FLAGS. A use_operand_p is always returned via USEVAR. FLAGS
275 can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES. */
276 #define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS) \
277 for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS); \
278 !op_iter_done (&(ITER)); \
279 (USEVAR) = op_iter_next_use (&(ITER)))
282 /* This macro will execute a loop over a stmt, regardless of whether it is
283 a real stmt or a PHI node, looking at the USE nodes matching FLAGS. */
284 #define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS) \
285 for ((USEVAR) = (TREE_CODE (STMT) == PHI_NODE \
286 ? op_iter_init_phiuse (&(ITER), STMT, FLAGS) \
287 : op_iter_init_use (&(ITER), STMT, FLAGS)); \
288 !op_iter_done (&(ITER)); \
289 (USEVAR) = op_iter_next_use (&(ITER)))
291 /* This macro will execute a loop over a stmt, regardless of whether it is
292 a real stmt or a PHI node, looking at the DEF nodes matching FLAGS. */
293 #define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS) \
294 for ((DEFVAR) = (TREE_CODE (STMT) == PHI_NODE \
295 ? op_iter_init_phidef (&(ITER), STMT, FLAGS) \
296 : op_iter_init_def (&(ITER), STMT, FLAGS)); \
297 !op_iter_done (&(ITER)); \
298 (DEFVAR) = op_iter_next_def (&(ITER)))
300 /* This macro returns an operand in STMT as a tree if it is the ONLY
301 operand matching FLAGS. If there are 0 or more than 1 operand matching
302 FLAGS, then NULL_TREE is returned. */
303 #define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS) \
304 single_ssa_tree_operand (STMT, FLAGS)
306 /* This macro returns an operand in STMT as a use_operand_p if it is the ONLY
307 operand matching FLAGS. If there are 0 or more than 1 operand matching
308 FLAGS, then NULL_USE_OPERAND_P is returned. */
309 #define SINGLE_SSA_USE_OPERAND(STMT, FLAGS) \
310 single_ssa_use_operand (STMT, FLAGS)
312 /* This macro returns an operand in STMT as a def_operand_p if it is the ONLY
313 operand matching FLAGS. If there are 0 or more than 1 operand matching
314 FLAGS, then NULL_DEF_OPERAND_P is returned. */
315 #define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS) \
316 single_ssa_def_operand (STMT, FLAGS)
318 /* This macro returns TRUE if there are no operands matching FLAGS in STMT. */
319 #define ZERO_SSA_OPERANDS(STMT, FLAGS) zero_ssa_operands (STMT, FLAGS)
321 /* This macro counts the number of operands in STMT matching FLAGS. */
322 #define NUM_SSA_OPERANDS(STMT, FLAGS) num_ssa_operands (STMT, FLAGS)
324 #endif /* GCC_TREE_SSA_OPERANDS_H */