OSDN Git Service

2005-06-30 Andrew Pinski <pinskia@physics.uc.edu>
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-operands.h
1 /* SSA operand management for trees.
2    Copyright (C) 2003, 2005 Free Software Foundation, Inc.
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
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.  */
20
21 #ifndef GCC_TREE_SSA_OPERANDS_H
22 #define GCC_TREE_SSA_OPERANDS_H
23
24 /* Interface to SSA operands.  */
25
26
27 /* This represents a pointer to a DEF operand.  */
28 typedef tree *def_operand_p;
29
30 /* This represents a pointer to a USE operand.  */
31 typedef ssa_use_operand_t *use_operand_p;
32
33 /* NULL operand types.  */
34 #define NULL_USE_OPERAND_P              NULL
35 #define NULL_DEF_OPERAND_P              NULL
36
37 /* This represents the DEF operands of a stmt.  */
38 struct def_optype_d
39 {
40   struct def_optype_d *next;
41   tree *def_ptr;
42 };
43 typedef struct def_optype_d *def_optype_p;
44
45 /* This represents the USE operands of a stmt.  */
46 struct use_optype_d 
47 {
48   struct use_optype_d *next;
49   struct ssa_use_operand_d use_ptr;
50 };
51 typedef struct use_optype_d *use_optype_p;
52
53 /* This represents the MAY_DEFS for a stmt.  */
54 struct maydef_optype_d
55 {
56   struct maydef_optype_d *next;
57   tree def_var;
58   tree use_var;
59   struct ssa_use_operand_d use_ptr;
60 };
61 typedef struct maydef_optype_d *maydef_optype_p;
62
63 /* This represents the VUSEs for a stmt.  */
64 struct vuse_optype_d
65 {
66   struct vuse_optype_d *next;
67   tree use_var;
68   struct ssa_use_operand_d use_ptr;
69 };
70 typedef struct vuse_optype_d *vuse_optype_p;
71                                                                               
72 /* This represents the V_MUST_DEFS for a stmt.  */
73 struct mustdef_optype_d
74 {
75   struct mustdef_optype_d *next;
76   tree def_var;
77   tree kill_var;
78   struct ssa_use_operand_d use_ptr;
79 };
80 typedef struct mustdef_optype_d *mustdef_optype_p;
81
82
83 #define SSA_OPERAND_MEMORY_SIZE         (2048 - sizeof (void *))
84                                                                               
85 struct ssa_operand_memory_d GTY((chain_next("%h.next")))
86 {
87   struct ssa_operand_memory_d *next;
88   char mem[SSA_OPERAND_MEMORY_SIZE];
89 };
90
91
92 /* This represents the operand cache for a stmt.  */
93 struct stmt_operands_d
94 {
95   /* Statement operands.  */
96   struct def_optype_d * def_ops;
97   struct use_optype_d * use_ops;
98                                                                               
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;
103 };
104                                                                               
105 typedef struct stmt_operands_d *stmt_operands_p;
106                                                                               
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))
111
112 #define USE_STMT(USE)           (USE)->stmt
113
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)
119
120 #define USE_OP_PTR(OP)          (&((OP)->use_ptr))
121 #define USE_OP(OP)              (USE_FROM_PTR (USE_OP_PTR (OP)))
122
123 #define DEF_OP_PTR(OP)          ((OP)->def_ptr)
124 #define DEF_OP(OP)              (DEF_FROM_PTR (DEF_OP_PTR (OP)))
125
126 #define VUSE_OP_PTR(OP)         USE_OP_PTR(OP)
127 #define VUSE_OP(OP)             ((OP)->use_var)
128
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)
133
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)
138
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))
142
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)
152
153
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);
159
160 extern void copy_virtual_operands (tree, tree);
161 extern void create_ssa_artficial_load_stmt (tree, tree);
162
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);
167
168 extern bool ssa_call_clobbered_cache_valid;
169 extern bool ssa_ro_call_cache_valid;
170
171 extern bool ssa_operands_active (void);
172
173 enum ssa_op_iter_type {
174   ssa_op_iter_none = 0,
175   ssa_op_iter_tree,
176   ssa_op_iter_use,
177   ssa_op_iter_def,
178   ssa_op_iter_maymustdef
179 };
180 /* This structure is used in the operand iterator loops.  It contains the 
181    items required to determine which operand is retrieved next.  During
182    optimization, this structure is scalarized, and any unused fields are 
183    optimized away, resulting in little overhead.  */
184
185 typedef struct ssa_operand_iterator_d
186 {
187   def_optype_p defs;
188   use_optype_p uses;
189   vuse_optype_p vuses;
190   maydef_optype_p maydefs;
191   maydef_optype_p mayuses;
192   mustdef_optype_p mustdefs;
193   mustdef_optype_p mustkills;
194   enum ssa_op_iter_type iter_type;
195   int phi_i;
196   int num_phi;
197   tree phi_stmt;
198   bool done;
199 } ssa_op_iter;
200
201 /* These flags are used to determine which operands are returned during 
202    execution of the loop.  */
203 #define SSA_OP_USE              0x01    /* Real USE operands.  */
204 #define SSA_OP_DEF              0x02    /* Real DEF operands.  */
205 #define SSA_OP_VUSE             0x04    /* VUSE operands.  */
206 #define SSA_OP_VMAYUSE          0x08    /* USE portion of V_MAY_DEFS.  */
207 #define SSA_OP_VMAYDEF          0x10    /* DEF portion of V_MAY_DEFS.  */
208 #define SSA_OP_VMUSTDEF         0x20    /* V_MUST_DEF definitions.  */
209 #define SSA_OP_VMUSTKILL        0x40    /* V_MUST_DEF kills.  */
210
211 /* These are commonly grouped operand flags.  */
212 #define SSA_OP_VIRTUAL_USES     (SSA_OP_VUSE | SSA_OP_VMAYUSE)
213 #define SSA_OP_VIRTUAL_DEFS     (SSA_OP_VMAYDEF | SSA_OP_VMUSTDEF)
214 #define SSA_OP_VIRTUAL_KILLS    (SSA_OP_VMUSTKILL)
215 #define SSA_OP_ALL_VIRTUALS     (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_KILLS \
216                                  | SSA_OP_VIRTUAL_DEFS)
217 #define SSA_OP_ALL_USES         (SSA_OP_VIRTUAL_USES | SSA_OP_USE)
218 #define SSA_OP_ALL_DEFS         (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF)
219 #define SSA_OP_ALL_KILLS        (SSA_OP_VIRTUAL_KILLS)
220 #define SSA_OP_ALL_OPERANDS     (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS      \
221                                  | SSA_OP_ALL_KILLS)
222
223 /* This macro executes a loop over the operands of STMT specified in FLAG, 
224    returning each operand as a 'tree' in the variable TREEVAR.  ITER is an
225    ssa_op_iter structure used to control the loop.  */
226 #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS)   \
227   for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS);      \
228        !op_iter_done (&(ITER));                                 \
229        TREEVAR = op_iter_next_tree (&(ITER)))
230
231 /* This macro executes a loop over the operands of STMT specified in FLAG, 
232    returning each operand as a 'use_operand_p' in the variable USEVAR.  
233    ITER is an ssa_op_iter structure used to control the loop.  */
234 #define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS)     \
235   for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS);        \
236        !op_iter_done (&(ITER));                                 \
237        USEVAR = op_iter_next_use (&(ITER)))
238
239 /* This macro executes a loop over the operands of STMT specified in FLAG, 
240    returning each operand as a 'def_operand_p' in the variable DEFVAR.  
241    ITER is an ssa_op_iter structure used to control the loop.  */
242 #define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS)     \
243   for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS);        \
244        !op_iter_done (&(ITER));                                 \
245        DEFVAR = op_iter_next_def (&(ITER)))
246
247 /* This macro executes a loop over the V_MAY_DEF operands of STMT.  The def
248    and use for each V_MAY_DEF is returned in DEFVAR and USEVAR. 
249    ITER is an ssa_op_iter structure used to control the loop.  */
250 #define FOR_EACH_SSA_MAYDEF_OPERAND(DEFVAR, USEVAR, STMT, ITER) \
251   for (op_iter_init_maydef (&(ITER), STMT, &(USEVAR), &(DEFVAR));       \
252        !op_iter_done (&(ITER));                                 \
253        op_iter_next_maymustdef (&(USEVAR), &(DEFVAR), &(ITER)))
254
255 /* This macro executes a loop over the V_MUST_DEF operands of STMT.  The def
256    and kill for each V_MUST_DEF is returned in DEFVAR and KILLVAR. 
257    ITER is an ssa_op_iter structure used to control the loop.  */
258 #define FOR_EACH_SSA_MUSTDEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER)       \
259   for (op_iter_init_mustdef (&(ITER), STMT, &(KILLVAR), &(DEFVAR));     \
260        !op_iter_done (&(ITER));                                 \
261        op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
262
263 /* This macro executes a loop over the V_{MUST,MAY}_DEF of STMT.  The def
264    and kill for each V_{MUST,MAY}_DEF is returned in DEFVAR and KILLVAR. 
265    ITER is an ssa_op_iter structure used to control the loop.  */
266 #define FOR_EACH_SSA_MUST_AND_MAY_DEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER)\
267   for (op_iter_init_must_and_may_def (&(ITER), STMT, &(KILLVAR), &(DEFVAR));\
268        !op_iter_done (&(ITER));                                 \
269        op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
270
271 /* This macro will execute a loop over all the arguments of a PHI which
272    match FLAGS.   A use_operand_p is always returned via USEVAR.  FLAGS
273    can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES.  */
274 #define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS)             \
275   for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS);   \
276        !op_iter_done (&(ITER));                                 \
277        (USEVAR) = op_iter_next_use (&(ITER)))
278
279
280 /* This macro will execute a loop over a stmt, regardless of whether it is
281    a real stmt or a PHI node, looking at the USE nodes matching FLAGS.  */
282 #define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS)     \
283   for ((USEVAR) = (TREE_CODE (STMT) == PHI_NODE                 \
284                    ? op_iter_init_phiuse (&(ITER), STMT, FLAGS) \
285                    : op_iter_init_use (&(ITER), STMT, FLAGS));  \
286        !op_iter_done (&(ITER));                                 \
287        (USEVAR) = op_iter_next_use (&(ITER)))
288
289 /* This macro will execute a loop over a stmt, regardless of whether it is
290    a real stmt or a PHI node, looking at the DEF nodes matching FLAGS.  */
291 #define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS)     \
292   for ((DEFVAR) = (TREE_CODE (STMT) == PHI_NODE                 \
293                    ? op_iter_init_phidef (&(ITER), STMT, FLAGS) \
294                    : op_iter_init_def (&(ITER), STMT, FLAGS));  \
295        !op_iter_done (&(ITER));                                 \
296        (DEFVAR) = op_iter_next_def (&(ITER)))
297   
298 /* This macro returns an operand in STMT as a tree if it is the ONLY
299    operand matching FLAGS.  If there are 0 or more than 1 operand matching
300    FLAGS, then NULL_TREE is returned.  */
301 #define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS)                    \
302   single_ssa_tree_operand (STMT, FLAGS)
303                                                                                 
304 /* This macro returns an operand in STMT as a use_operand_p if it is the ONLY
305    operand matching FLAGS.  If there are 0 or more than 1 operand matching
306    FLAGS, then NULL_USE_OPERAND_P is returned.  */
307 #define SINGLE_SSA_USE_OPERAND(STMT, FLAGS)                     \
308   single_ssa_use_operand (STMT, FLAGS)
309                                                                                 
310 /* This macro returns an operand in STMT as a def_operand_p if it is the ONLY
311    operand matching FLAGS.  If there are 0 or more than 1 operand matching
312    FLAGS, then NULL_DEF_OPERAND_P is returned.  */
313 #define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS)                     \
314   single_ssa_def_operand (STMT, FLAGS)
315
316 /* This macro returns TRUE if there are no operands matching FLAGS in STMT.  */
317 #define ZERO_SSA_OPERANDS(STMT, FLAGS)  zero_ssa_operands (STMT, FLAGS)
318
319 /* This macro counts the number of operands in STMT matching FLAGS.  */
320 #define NUM_SSA_OPERANDS(STMT, FLAGS)   num_ssa_operands (STMT, FLAGS)
321
322 #endif  /* GCC_TREE_SSA_OPERANDS_H  */