OSDN Git Service

* tree-ssa-operands.h (struct ssa_operands): New.
[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 /* Per-function operand caches.  */
92 struct ssa_operands GTY(()) {
93    struct ssa_operand_memory_d *operand_memory;
94    unsigned operand_memory_index;
95
96    bool ops_active;
97
98    struct def_optype_d * GTY ((skip (""))) free_defs;
99    struct use_optype_d * GTY ((skip (""))) free_uses;
100    struct vuse_optype_d * GTY ((skip (""))) free_vuses;
101    struct maydef_optype_d * GTY ((skip (""))) free_maydefs;
102    struct mustdef_optype_d * GTY ((skip (""))) free_mustdefs;
103 };
104
105 /* This represents the operand cache for a stmt.  */
106 struct stmt_operands_d
107 {
108   /* Statement operands.  */
109   struct def_optype_d * def_ops;
110   struct use_optype_d * use_ops;
111                                                                               
112   /* Virtual operands (V_MAY_DEF, VUSE, and V_MUST_DEF).  */
113   struct maydef_optype_d * maydef_ops;
114   struct vuse_optype_d * vuse_ops;
115   struct mustdef_optype_d * mustdef_ops;
116 };
117                                                                               
118 typedef struct stmt_operands_d *stmt_operands_p;
119                                                                               
120 #define USE_FROM_PTR(PTR)       get_use_from_ptr (PTR)
121 #define DEF_FROM_PTR(PTR)       get_def_from_ptr (PTR)
122 #define SET_USE(USE, V)         set_ssa_use_from_ptr (USE, V)
123 #define SET_DEF(DEF, V)         ((*(DEF)) = (V))
124
125 #define USE_STMT(USE)           (USE)->stmt
126
127 #define DEF_OPS(STMT)           (stmt_ann (STMT)->operands.def_ops)
128 #define USE_OPS(STMT)           (stmt_ann (STMT)->operands.use_ops)
129 #define VUSE_OPS(STMT)          (stmt_ann (STMT)->operands.vuse_ops)
130 #define MAYDEF_OPS(STMT)        (stmt_ann (STMT)->operands.maydef_ops)
131 #define MUSTDEF_OPS(STMT)       (stmt_ann (STMT)->operands.mustdef_ops)
132
133 #define USE_OP_PTR(OP)          (&((OP)->use_ptr))
134 #define USE_OP(OP)              (USE_FROM_PTR (USE_OP_PTR (OP)))
135
136 #define DEF_OP_PTR(OP)          ((OP)->def_ptr)
137 #define DEF_OP(OP)              (DEF_FROM_PTR (DEF_OP_PTR (OP)))
138
139 #define VUSE_OP_PTR(OP)         USE_OP_PTR(OP)
140 #define VUSE_OP(OP)             ((OP)->use_var)
141
142 #define MAYDEF_RESULT_PTR(OP)   (&((OP)->def_var))
143 #define MAYDEF_RESULT(OP)       ((OP)->def_var)
144 #define MAYDEF_OP_PTR(OP)       USE_OP_PTR (OP)
145 #define MAYDEF_OP(OP)           ((OP)->use_var)
146
147 #define MUSTDEF_RESULT_PTR(OP)  (&((OP)->def_var))
148 #define MUSTDEF_RESULT(OP)      ((OP)->def_var)
149 #define MUSTDEF_KILL_PTR(OP)    USE_OP_PTR (OP)
150 #define MUSTDEF_KILL(OP)        ((OP)->kill_var)
151
152 #define PHI_RESULT_PTR(PHI)     get_phi_result_ptr (PHI)
153 #define PHI_RESULT(PHI)         DEF_FROM_PTR (PHI_RESULT_PTR (PHI))
154 #define SET_PHI_RESULT(PHI, V)  SET_DEF (PHI_RESULT_PTR (PHI), (V))
155
156 #define PHI_ARG_DEF_PTR(PHI, I) get_phi_arg_def_ptr ((PHI), (I))
157 #define PHI_ARG_DEF(PHI, I)     USE_FROM_PTR (PHI_ARG_DEF_PTR ((PHI), (I)))
158 #define SET_PHI_ARG_DEF(PHI, I, V)                                      \
159                                 SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V))
160 #define PHI_ARG_DEF_FROM_EDGE(PHI, E)                                   \
161                                 PHI_ARG_DEF ((PHI), (E)->dest_idx)
162 #define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E)                               \
163                                 PHI_ARG_DEF_PTR ((PHI), (E)->dest_idx)
164 #define PHI_ARG_INDEX_FROM_USE(USE)   phi_arg_index_from_use (USE)
165
166
167 extern void init_ssa_operands (void);
168 extern void fini_ssa_operands (void);
169 extern void free_ssa_operands (stmt_operands_p);
170 extern void update_stmt_operands (tree);
171 extern bool verify_imm_links (FILE *f, tree var);
172
173 extern void copy_virtual_operands (tree, tree);
174 extern void create_ssa_artficial_load_stmt (tree, tree);
175
176 extern void dump_immediate_uses (FILE *file);
177 extern void dump_immediate_uses_for (FILE *file, tree var);
178 extern void debug_immediate_uses (void);
179 extern void debug_immediate_uses_for (tree var);
180
181 extern bool ssa_operands_active (void);
182
183 extern void add_to_addressable_set (tree, bitmap *);
184
185 enum ssa_op_iter_type {
186   ssa_op_iter_none = 0,
187   ssa_op_iter_tree,
188   ssa_op_iter_use,
189   ssa_op_iter_def,
190   ssa_op_iter_maymustdef
191 };
192 /* This structure is used in the operand iterator loops.  It contains the 
193    items required to determine which operand is retrieved next.  During
194    optimization, this structure is scalarized, and any unused fields are 
195    optimized away, resulting in little overhead.  */
196
197 typedef struct ssa_operand_iterator_d
198 {
199   def_optype_p defs;
200   use_optype_p uses;
201   vuse_optype_p vuses;
202   maydef_optype_p maydefs;
203   maydef_optype_p mayuses;
204   mustdef_optype_p mustdefs;
205   mustdef_optype_p mustkills;
206   enum ssa_op_iter_type iter_type;
207   int phi_i;
208   int num_phi;
209   tree phi_stmt;
210   bool done;
211 } ssa_op_iter;
212
213 /* These flags are used to determine which operands are returned during 
214    execution of the loop.  */
215 #define SSA_OP_USE              0x01    /* Real USE operands.  */
216 #define SSA_OP_DEF              0x02    /* Real DEF operands.  */
217 #define SSA_OP_VUSE             0x04    /* VUSE operands.  */
218 #define SSA_OP_VMAYUSE          0x08    /* USE portion of V_MAY_DEFS.  */
219 #define SSA_OP_VMAYDEF          0x10    /* DEF portion of V_MAY_DEFS.  */
220 #define SSA_OP_VMUSTDEF         0x20    /* V_MUST_DEF definitions.  */
221 #define SSA_OP_VMUSTKILL        0x40    /* V_MUST_DEF kills.  */
222
223 /* These are commonly grouped operand flags.  */
224 #define SSA_OP_VIRTUAL_USES     (SSA_OP_VUSE | SSA_OP_VMAYUSE)
225 #define SSA_OP_VIRTUAL_DEFS     (SSA_OP_VMAYDEF | SSA_OP_VMUSTDEF)
226 #define SSA_OP_VIRTUAL_KILLS    (SSA_OP_VMUSTKILL)
227 #define SSA_OP_ALL_VIRTUALS     (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_KILLS \
228                                  | SSA_OP_VIRTUAL_DEFS)
229 #define SSA_OP_ALL_USES         (SSA_OP_VIRTUAL_USES | SSA_OP_USE)
230 #define SSA_OP_ALL_DEFS         (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF)
231 #define SSA_OP_ALL_KILLS        (SSA_OP_VIRTUAL_KILLS)
232 #define SSA_OP_ALL_OPERANDS     (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS      \
233                                  | SSA_OP_ALL_KILLS)
234
235 /* This macro executes a loop over the operands of STMT specified in FLAG, 
236    returning each operand as a 'tree' in the variable TREEVAR.  ITER is an
237    ssa_op_iter structure used to control the loop.  */
238 #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS)   \
239   for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS);      \
240        !op_iter_done (&(ITER));                                 \
241        TREEVAR = op_iter_next_tree (&(ITER)))
242
243 /* This macro executes a loop over the operands of STMT specified in FLAG, 
244    returning each operand as a 'use_operand_p' in the variable USEVAR.  
245    ITER is an ssa_op_iter structure used to control the loop.  */
246 #define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS)     \
247   for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS);        \
248        !op_iter_done (&(ITER));                                 \
249        USEVAR = op_iter_next_use (&(ITER)))
250
251 /* This macro executes a loop over the operands of STMT specified in FLAG, 
252    returning each operand as a 'def_operand_p' in the variable DEFVAR.  
253    ITER is an ssa_op_iter structure used to control the loop.  */
254 #define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS)     \
255   for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS);        \
256        !op_iter_done (&(ITER));                                 \
257        DEFVAR = op_iter_next_def (&(ITER)))
258
259 /* This macro executes a loop over the V_MAY_DEF operands of STMT.  The def
260    and use for each V_MAY_DEF is returned in DEFVAR and USEVAR. 
261    ITER is an ssa_op_iter structure used to control the loop.  */
262 #define FOR_EACH_SSA_MAYDEF_OPERAND(DEFVAR, USEVAR, STMT, ITER) \
263   for (op_iter_init_maydef (&(ITER), STMT, &(USEVAR), &(DEFVAR));       \
264        !op_iter_done (&(ITER));                                 \
265        op_iter_next_maymustdef (&(USEVAR), &(DEFVAR), &(ITER)))
266
267 /* This macro executes a loop over the V_MUST_DEF operands of STMT.  The def
268    and kill for each V_MUST_DEF is returned in DEFVAR and KILLVAR. 
269    ITER is an ssa_op_iter structure used to control the loop.  */
270 #define FOR_EACH_SSA_MUSTDEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER)       \
271   for (op_iter_init_mustdef (&(ITER), STMT, &(KILLVAR), &(DEFVAR));     \
272        !op_iter_done (&(ITER));                                 \
273        op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
274
275 /* This macro executes a loop over the V_{MUST,MAY}_DEF of STMT.  The def
276    and kill for each V_{MUST,MAY}_DEF is returned in DEFVAR and KILLVAR. 
277    ITER is an ssa_op_iter structure used to control the loop.  */
278 #define FOR_EACH_SSA_MUST_AND_MAY_DEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER)\
279   for (op_iter_init_must_and_may_def (&(ITER), STMT, &(KILLVAR), &(DEFVAR));\
280        !op_iter_done (&(ITER));                                 \
281        op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
282
283 /* This macro will execute a loop over all the arguments of a PHI which
284    match FLAGS.   A use_operand_p is always returned via USEVAR.  FLAGS
285    can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES.  */
286 #define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS)             \
287   for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS);   \
288        !op_iter_done (&(ITER));                                 \
289        (USEVAR) = op_iter_next_use (&(ITER)))
290
291
292 /* This macro will execute a loop over a stmt, regardless of whether it is
293    a real stmt or a PHI node, looking at the USE nodes matching FLAGS.  */
294 #define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS)     \
295   for ((USEVAR) = (TREE_CODE (STMT) == PHI_NODE                 \
296                    ? op_iter_init_phiuse (&(ITER), STMT, FLAGS) \
297                    : op_iter_init_use (&(ITER), STMT, FLAGS));  \
298        !op_iter_done (&(ITER));                                 \
299        (USEVAR) = op_iter_next_use (&(ITER)))
300
301 /* This macro will execute a loop over a stmt, regardless of whether it is
302    a real stmt or a PHI node, looking at the DEF nodes matching FLAGS.  */
303 #define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS)     \
304   for ((DEFVAR) = (TREE_CODE (STMT) == PHI_NODE                 \
305                    ? op_iter_init_phidef (&(ITER), STMT, FLAGS) \
306                    : op_iter_init_def (&(ITER), STMT, FLAGS));  \
307        !op_iter_done (&(ITER));                                 \
308        (DEFVAR) = op_iter_next_def (&(ITER)))
309   
310 /* This macro returns an operand in STMT as a tree if it is the ONLY
311    operand matching FLAGS.  If there are 0 or more than 1 operand matching
312    FLAGS, then NULL_TREE is returned.  */
313 #define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS)                    \
314   single_ssa_tree_operand (STMT, FLAGS)
315                                                                                 
316 /* This macro returns an operand in STMT as a use_operand_p if it is the ONLY
317    operand matching FLAGS.  If there are 0 or more than 1 operand matching
318    FLAGS, then NULL_USE_OPERAND_P is returned.  */
319 #define SINGLE_SSA_USE_OPERAND(STMT, FLAGS)                     \
320   single_ssa_use_operand (STMT, FLAGS)
321                                                                                 
322 /* This macro returns an operand in STMT as a def_operand_p if it is the ONLY
323    operand matching FLAGS.  If there are 0 or more than 1 operand matching
324    FLAGS, then NULL_DEF_OPERAND_P is returned.  */
325 #define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS)                     \
326   single_ssa_def_operand (STMT, FLAGS)
327
328 /* This macro returns TRUE if there are no operands matching FLAGS in STMT.  */
329 #define ZERO_SSA_OPERANDS(STMT, FLAGS)  zero_ssa_operands (STMT, FLAGS)
330
331 /* This macro counts the number of operands in STMT matching FLAGS.  */
332 #define NUM_SSA_OPERANDS(STMT, FLAGS)   num_ssa_operands (STMT, FLAGS)
333
334 #endif  /* GCC_TREE_SSA_OPERANDS_H  */