2006-03-25 Thomas Koenig <Thomas.Koenig@online.de>
[official-gcc.git] / gcc / tree-ssa-operands.h
blobdaf2dce05f7477e27e45013f3290f43f2f998307
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_operands_active (void);
170 extern void add_to_addressable_set (tree, bitmap *);
172 enum ssa_op_iter_type {
173 ssa_op_iter_none = 0,
174 ssa_op_iter_tree,
175 ssa_op_iter_use,
176 ssa_op_iter_def,
177 ssa_op_iter_maymustdef
179 /* This structure is used in the operand iterator loops. It contains the
180 items required to determine which operand is retrieved next. During
181 optimization, this structure is scalarized, and any unused fields are
182 optimized away, resulting in little overhead. */
184 typedef struct ssa_operand_iterator_d
186 def_optype_p defs;
187 use_optype_p uses;
188 vuse_optype_p vuses;
189 maydef_optype_p maydefs;
190 maydef_optype_p mayuses;
191 mustdef_optype_p mustdefs;
192 mustdef_optype_p mustkills;
193 enum ssa_op_iter_type iter_type;
194 int phi_i;
195 int num_phi;
196 tree phi_stmt;
197 bool done;
198 } ssa_op_iter;
200 /* These flags are used to determine which operands are returned during
201 execution of the loop. */
202 #define SSA_OP_USE 0x01 /* Real USE operands. */
203 #define SSA_OP_DEF 0x02 /* Real DEF operands. */
204 #define SSA_OP_VUSE 0x04 /* VUSE operands. */
205 #define SSA_OP_VMAYUSE 0x08 /* USE portion of V_MAY_DEFS. */
206 #define SSA_OP_VMAYDEF 0x10 /* DEF portion of V_MAY_DEFS. */
207 #define SSA_OP_VMUSTDEF 0x20 /* V_MUST_DEF definitions. */
208 #define SSA_OP_VMUSTKILL 0x40 /* V_MUST_DEF kills. */
210 /* These are commonly grouped operand flags. */
211 #define SSA_OP_VIRTUAL_USES (SSA_OP_VUSE | SSA_OP_VMAYUSE)
212 #define SSA_OP_VIRTUAL_DEFS (SSA_OP_VMAYDEF | SSA_OP_VMUSTDEF)
213 #define SSA_OP_VIRTUAL_KILLS (SSA_OP_VMUSTKILL)
214 #define SSA_OP_ALL_VIRTUALS (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_KILLS \
215 | SSA_OP_VIRTUAL_DEFS)
216 #define SSA_OP_ALL_USES (SSA_OP_VIRTUAL_USES | SSA_OP_USE)
217 #define SSA_OP_ALL_DEFS (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF)
218 #define SSA_OP_ALL_KILLS (SSA_OP_VIRTUAL_KILLS)
219 #define SSA_OP_ALL_OPERANDS (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS \
220 | SSA_OP_ALL_KILLS)
222 /* This macro executes a loop over the operands of STMT specified in FLAG,
223 returning each operand as a 'tree' in the variable TREEVAR. ITER is an
224 ssa_op_iter structure used to control the loop. */
225 #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS) \
226 for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS); \
227 !op_iter_done (&(ITER)); \
228 TREEVAR = op_iter_next_tree (&(ITER)))
230 /* This macro executes a loop over the operands of STMT specified in FLAG,
231 returning each operand as a 'use_operand_p' in the variable USEVAR.
232 ITER is an ssa_op_iter structure used to control the loop. */
233 #define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS) \
234 for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS); \
235 !op_iter_done (&(ITER)); \
236 USEVAR = op_iter_next_use (&(ITER)))
238 /* This macro executes a loop over the operands of STMT specified in FLAG,
239 returning each operand as a 'def_operand_p' in the variable DEFVAR.
240 ITER is an ssa_op_iter structure used to control the loop. */
241 #define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS) \
242 for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS); \
243 !op_iter_done (&(ITER)); \
244 DEFVAR = op_iter_next_def (&(ITER)))
246 /* This macro executes a loop over the V_MAY_DEF operands of STMT. The def
247 and use for each V_MAY_DEF is returned in DEFVAR and USEVAR.
248 ITER is an ssa_op_iter structure used to control the loop. */
249 #define FOR_EACH_SSA_MAYDEF_OPERAND(DEFVAR, USEVAR, STMT, ITER) \
250 for (op_iter_init_maydef (&(ITER), STMT, &(USEVAR), &(DEFVAR)); \
251 !op_iter_done (&(ITER)); \
252 op_iter_next_maymustdef (&(USEVAR), &(DEFVAR), &(ITER)))
254 /* This macro executes a loop over the V_MUST_DEF operands of STMT. The def
255 and kill for each V_MUST_DEF is returned in DEFVAR and KILLVAR.
256 ITER is an ssa_op_iter structure used to control the loop. */
257 #define FOR_EACH_SSA_MUSTDEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER) \
258 for (op_iter_init_mustdef (&(ITER), STMT, &(KILLVAR), &(DEFVAR)); \
259 !op_iter_done (&(ITER)); \
260 op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
262 /* This macro executes a loop over the V_{MUST,MAY}_DEF of STMT. The def
263 and kill for each V_{MUST,MAY}_DEF is returned in DEFVAR and KILLVAR.
264 ITER is an ssa_op_iter structure used to control the loop. */
265 #define FOR_EACH_SSA_MUST_AND_MAY_DEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER)\
266 for (op_iter_init_must_and_may_def (&(ITER), STMT, &(KILLVAR), &(DEFVAR));\
267 !op_iter_done (&(ITER)); \
268 op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
270 /* This macro will execute a loop over all the arguments of a PHI which
271 match FLAGS. A use_operand_p is always returned via USEVAR. FLAGS
272 can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES. */
273 #define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS) \
274 for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS); \
275 !op_iter_done (&(ITER)); \
276 (USEVAR) = op_iter_next_use (&(ITER)))
279 /* This macro will execute a loop over a stmt, regardless of whether it is
280 a real stmt or a PHI node, looking at the USE nodes matching FLAGS. */
281 #define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS) \
282 for ((USEVAR) = (TREE_CODE (STMT) == PHI_NODE \
283 ? op_iter_init_phiuse (&(ITER), STMT, FLAGS) \
284 : op_iter_init_use (&(ITER), STMT, FLAGS)); \
285 !op_iter_done (&(ITER)); \
286 (USEVAR) = op_iter_next_use (&(ITER)))
288 /* This macro will execute a loop over a stmt, regardless of whether it is
289 a real stmt or a PHI node, looking at the DEF nodes matching FLAGS. */
290 #define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS) \
291 for ((DEFVAR) = (TREE_CODE (STMT) == PHI_NODE \
292 ? op_iter_init_phidef (&(ITER), STMT, FLAGS) \
293 : op_iter_init_def (&(ITER), STMT, FLAGS)); \
294 !op_iter_done (&(ITER)); \
295 (DEFVAR) = op_iter_next_def (&(ITER)))
297 /* This macro returns an operand in STMT as a tree if it is the ONLY
298 operand matching FLAGS. If there are 0 or more than 1 operand matching
299 FLAGS, then NULL_TREE is returned. */
300 #define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS) \
301 single_ssa_tree_operand (STMT, FLAGS)
303 /* This macro returns an operand in STMT as a use_operand_p if it is the ONLY
304 operand matching FLAGS. If there are 0 or more than 1 operand matching
305 FLAGS, then NULL_USE_OPERAND_P is returned. */
306 #define SINGLE_SSA_USE_OPERAND(STMT, FLAGS) \
307 single_ssa_use_operand (STMT, FLAGS)
309 /* This macro returns an operand in STMT as a def_operand_p if it is the ONLY
310 operand matching FLAGS. If there are 0 or more than 1 operand matching
311 FLAGS, then NULL_DEF_OPERAND_P is returned. */
312 #define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS) \
313 single_ssa_def_operand (STMT, FLAGS)
315 /* This macro returns TRUE if there are no operands matching FLAGS in STMT. */
316 #define ZERO_SSA_OPERANDS(STMT, FLAGS) zero_ssa_operands (STMT, FLAGS)
318 /* This macro counts the number of operands in STMT matching FLAGS. */
319 #define NUM_SSA_OPERANDS(STMT, FLAGS) num_ssa_operands (STMT, FLAGS)
321 #endif /* GCC_TREE_SSA_OPERANDS_H */