OSDN Git Service

* config/pa/fptr.c: Update license header.
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-operands.h
1 /* SSA operand management for trees.
2    Copyright (C) 2003, 2005, 2006, 2007 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 typedef struct vuse_element_d
54 {
55   tree use_var;
56   struct ssa_use_operand_d use_ptr;
57 } vuse_element_t;
58
59 typedef struct vuse_vec_d
60 {
61   unsigned 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 (((unsigned int) (X)) < VUSE_VECT_NUM_ELEM (V)),        \
74      VUSE_VECT_ELEMENT_NC (V,X))
75
76 #define VUSE_ELEMENT_PTR(V,X)                                           \
77     (gcc_assert (((unsigned int) (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 (((unsigned int) (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 (((unsigned int) (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 (((unsigned int) (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
101 /* This represents the virtual ops of a stmt.  */
102 struct voptype_d
103 {
104   struct voptype_d *next;
105   tree def_var;
106   vuse_vec_t usev;
107 };
108 typedef struct voptype_d *voptype_p;
109
110 /* This structure represents a variable sized buffer which is allocated by the
111    operand memory manager.  Operands are suballocated out of this block.  The
112    MEM array varies in size.  */
113    
114 struct ssa_operand_memory_d GTY((chain_next("%h.next")))
115 {
116   struct ssa_operand_memory_d *next;
117   char mem[1];
118 };
119
120 /* Number of different size free buckets for virtual operands.  */
121 #define NUM_VOP_FREE_BUCKETS            29
122
123 /* Per-function operand caches.  */
124 struct ssa_operands GTY(()) {
125    struct ssa_operand_memory_d *operand_memory;
126    unsigned operand_memory_index;
127    /* Current size of the operand memory buffer.  */
128    unsigned int ssa_operand_mem_size;
129
130    bool ops_active;
131
132    struct def_optype_d * GTY ((skip (""))) free_defs;
133    struct use_optype_d * GTY ((skip (""))) free_uses;
134    struct voptype_d * GTY ((skip (""))) vop_free_buckets[NUM_VOP_FREE_BUCKETS];
135    VEC(tree,heap) * GTY ((skip (""))) mpt_table;
136 };
137
138 /* This represents the operand cache for a stmt.  */
139 struct stmt_operands_d
140 {
141   /* Statement operands.  */
142   struct def_optype_d * def_ops;
143   struct use_optype_d * use_ops;
144                                                                               
145   /* Virtual operands (VDEF, VUSE).  */
146   struct voptype_d * vdef_ops;
147   struct voptype_d * vuse_ops;
148
149   /* Sets of memory symbols loaded and stored.  */
150   bitmap stores;
151   bitmap loads;
152 };
153                                                                               
154 typedef struct stmt_operands_d *stmt_operands_p;
155                                                                               
156 #define USE_FROM_PTR(PTR)       get_use_from_ptr (PTR)
157 #define DEF_FROM_PTR(PTR)       get_def_from_ptr (PTR)
158 #define SET_USE(USE, V)         set_ssa_use_from_ptr (USE, V)
159 #define SET_DEF(DEF, V)         ((*(DEF)) = (V))
160
161 #define USE_STMT(USE)           (USE)->stmt
162
163 #define DEF_OPS(STMT)           (stmt_ann (STMT)->operands.def_ops)
164 #define USE_OPS(STMT)           (stmt_ann (STMT)->operands.use_ops)
165 #define VUSE_OPS(STMT)          (stmt_ann (STMT)->operands.vuse_ops)
166 #define VDEF_OPS(STMT)          (stmt_ann (STMT)->operands.vdef_ops)
167
168 #define LOADED_SYMS(STMT)       (stmt_ann (STMT)->operands.loads)
169 #define STORED_SYMS(STMT)       (stmt_ann (STMT)->operands.stores)
170
171 #define USE_OP_PTR(OP)          (&((OP)->use_ptr))
172 #define USE_OP(OP)              (USE_FROM_PTR (USE_OP_PTR (OP)))
173
174 #define DEF_OP_PTR(OP)          ((OP)->def_ptr)
175 #define DEF_OP(OP)              (DEF_FROM_PTR (DEF_OP_PTR (OP)))
176
177 #define VUSE_OP_PTR(OP,X)       VUSE_ELEMENT_PTR ((OP)->usev, (X)) 
178 #define VUSE_OP(OP,X)           VUSE_ELEMENT_VAR ((OP)->usev, (X))
179 #define SET_VUSE_OP(OP,X,N)     SET_VUSE_ELEMENT_VAR ((OP)->usev, (X), (N))
180 #define VUSE_NUM(OP)            VUSE_VECT_NUM_ELEM ((OP)->usev)
181 #define VUSE_VECT(OP)           &((OP)->usev)
182
183 #define VDEF_RESULT_PTR(OP)     (&((OP)->def_var))
184 #define VDEF_RESULT(OP)         ((OP)->def_var)
185 #define VDEF_OP_PTR(OP,X)       VUSE_OP_PTR (OP, X)
186 #define VDEF_OP(OP,X)           VUSE_OP (OP, X)
187 #define SET_VDEF_OP(OP,X,N)     SET_VUSE_OP (OP, X, N)
188 #define VDEF_NUM(OP)            VUSE_VECT_NUM_ELEM ((OP)->usev)
189 #define VDEF_VECT(OP)           &((OP)->usev)
190
191 #define PHI_RESULT_PTR(PHI)     get_phi_result_ptr (PHI)
192 #define PHI_RESULT(PHI)         DEF_FROM_PTR (PHI_RESULT_PTR (PHI))
193 #define SET_PHI_RESULT(PHI, V)  SET_DEF (PHI_RESULT_PTR (PHI), (V))
194
195 #define PHI_ARG_DEF_PTR(PHI, I) get_phi_arg_def_ptr ((PHI), (I))
196 #define PHI_ARG_DEF(PHI, I)     USE_FROM_PTR (PHI_ARG_DEF_PTR ((PHI), (I)))
197 #define SET_PHI_ARG_DEF(PHI, I, V)                                      \
198                                 SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V))
199 #define PHI_ARG_DEF_FROM_EDGE(PHI, E)                                   \
200                                 PHI_ARG_DEF ((PHI), (E)->dest_idx)
201 #define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E)                               \
202                                 PHI_ARG_DEF_PTR ((PHI), (E)->dest_idx)
203 #define PHI_ARG_INDEX_FROM_USE(USE)   phi_arg_index_from_use (USE)
204
205
206 extern void init_ssa_operands (void);
207 extern void fini_ssa_operands (void);
208 extern void free_ssa_operands (stmt_operands_p);
209 extern void update_stmt_operands (tree);
210 extern bool verify_imm_links (FILE *f, tree var);
211
212 extern void copy_virtual_operands (tree, tree);
213 extern void create_ssa_artificial_load_stmt (tree, tree);
214
215 extern void dump_immediate_uses (FILE *file);
216 extern void dump_immediate_uses_for (FILE *file, tree var);
217 extern void debug_immediate_uses (void);
218 extern void debug_immediate_uses_for (tree var);
219 extern void dump_decl_set (FILE *, bitmap);
220 extern void debug_decl_set (bitmap);
221
222 extern bool ssa_operands_active (void);
223
224 extern void add_to_addressable_set (tree, bitmap *);
225 extern void push_stmt_changes (tree *);
226 extern void pop_stmt_changes (tree *);
227 extern void discard_stmt_changes (tree *);
228
229 enum ssa_op_iter_type {
230   ssa_op_iter_none = 0,
231   ssa_op_iter_tree,
232   ssa_op_iter_use,
233   ssa_op_iter_def,
234   ssa_op_iter_vdef
235 };
236
237 /* This structure is used in the operand iterator loops.  It contains the 
238    items required to determine which operand is retrieved next.  During
239    optimization, this structure is scalarized, and any unused fields are 
240    optimized away, resulting in little overhead.  */
241
242 typedef struct ssa_operand_iterator_d
243 {
244   def_optype_p defs;
245   use_optype_p uses;
246   voptype_p vuses;
247   voptype_p vdefs;
248   voptype_p mayuses;
249   enum ssa_op_iter_type iter_type;
250   int phi_i;
251   int num_phi;
252   tree phi_stmt;
253   bool done;
254   unsigned int vuse_index;
255   unsigned int mayuse_index;
256 } ssa_op_iter;
257
258 /* These flags are used to determine which operands are returned during 
259    execution of the loop.  */
260 #define SSA_OP_USE              0x01    /* Real USE operands.  */
261 #define SSA_OP_DEF              0x02    /* Real DEF operands.  */
262 #define SSA_OP_VUSE             0x04    /* VUSE operands.  */
263 #define SSA_OP_VMAYUSE          0x08    /* USE portion of VDEFS.  */
264 #define SSA_OP_VDEF             0x10    /* DEF portion of VDEFS.  */
265
266 /* These are commonly grouped operand flags.  */
267 #define SSA_OP_VIRTUAL_USES     (SSA_OP_VUSE | SSA_OP_VMAYUSE)
268 #define SSA_OP_VIRTUAL_DEFS     (SSA_OP_VDEF)
269 #define SSA_OP_ALL_VIRTUALS     (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_DEFS)
270 #define SSA_OP_ALL_USES         (SSA_OP_VIRTUAL_USES | SSA_OP_USE)
271 #define SSA_OP_ALL_DEFS         (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF)
272 #define SSA_OP_ALL_OPERANDS     (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS)
273
274 /* This macro executes a loop over the operands of STMT specified in FLAG, 
275    returning each operand as a 'tree' in the variable TREEVAR.  ITER is an
276    ssa_op_iter structure used to control the loop.  */
277 #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS)   \
278   for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS);      \
279        !op_iter_done (&(ITER));                                 \
280        TREEVAR = op_iter_next_tree (&(ITER)))
281
282 /* This macro executes a loop over the operands of STMT specified in FLAG, 
283    returning each operand as a 'use_operand_p' in the variable USEVAR.  
284    ITER is an ssa_op_iter structure used to control the loop.  */
285 #define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS)     \
286   for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS);        \
287        !op_iter_done (&(ITER));                                 \
288        USEVAR = op_iter_next_use (&(ITER)))
289
290 /* This macro executes a loop over the operands of STMT specified in FLAG, 
291    returning each operand as a 'def_operand_p' in the variable DEFVAR.  
292    ITER is an ssa_op_iter structure used to control the loop.  */
293 #define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS)     \
294   for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS);        \
295        !op_iter_done (&(ITER));                                 \
296        DEFVAR = op_iter_next_def (&(ITER)))
297
298 /* This macro executes a loop over the VDEF operands of STMT.  The def
299    and use vector for each VDEF is returned in DEFVAR and USEVECT. 
300    ITER is an ssa_op_iter structure used to control the loop.  */
301 #define FOR_EACH_SSA_VDEF_OPERAND(DEFVAR, USEVECT, STMT, ITER)  \
302   for (op_iter_init_vdef (&(ITER), STMT, &(USEVECT), &(DEFVAR));        \
303        !op_iter_done (&(ITER));                                 \
304        op_iter_next_vdef (&(USEVECT), &(DEFVAR), &(ITER)))
305
306 /* This macro will execute a loop over all the arguments of a PHI which
307    match FLAGS.   A use_operand_p is always returned via USEVAR.  FLAGS
308    can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES.  */
309 #define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS)             \
310   for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS);   \
311        !op_iter_done (&(ITER));                                 \
312        (USEVAR) = op_iter_next_use (&(ITER)))
313
314
315 /* This macro will execute a loop over a stmt, regardless of whether it is
316    a real stmt or a PHI node, looking at the USE nodes matching FLAGS.  */
317 #define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS)     \
318   for ((USEVAR) = (TREE_CODE (STMT) == PHI_NODE                 \
319                    ? op_iter_init_phiuse (&(ITER), STMT, FLAGS) \
320                    : op_iter_init_use (&(ITER), STMT, FLAGS));  \
321        !op_iter_done (&(ITER));                                 \
322        (USEVAR) = op_iter_next_use (&(ITER)))
323
324 /* This macro will execute a loop over a stmt, regardless of whether it is
325    a real stmt or a PHI node, looking at the DEF nodes matching FLAGS.  */
326 #define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS)     \
327   for ((DEFVAR) = (TREE_CODE (STMT) == PHI_NODE                 \
328                    ? op_iter_init_phidef (&(ITER), STMT, FLAGS) \
329                    : op_iter_init_def (&(ITER), STMT, FLAGS));  \
330        !op_iter_done (&(ITER));                                 \
331        (DEFVAR) = op_iter_next_def (&(ITER)))
332   
333 /* This macro returns an operand in STMT as a tree if it is the ONLY
334    operand matching FLAGS.  If there are 0 or more than 1 operand matching
335    FLAGS, then NULL_TREE is returned.  */
336 #define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS)                    \
337   single_ssa_tree_operand (STMT, FLAGS)
338                                                                                 
339 /* This macro returns an operand in STMT as a use_operand_p if it is the ONLY
340    operand matching FLAGS.  If there are 0 or more than 1 operand matching
341    FLAGS, then NULL_USE_OPERAND_P is returned.  */
342 #define SINGLE_SSA_USE_OPERAND(STMT, FLAGS)                     \
343   single_ssa_use_operand (STMT, FLAGS)
344                                                                                 
345 /* This macro returns an operand in STMT as a def_operand_p if it is the ONLY
346    operand matching FLAGS.  If there are 0 or more than 1 operand matching
347    FLAGS, then NULL_DEF_OPERAND_P is returned.  */
348 #define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS)                     \
349   single_ssa_def_operand (STMT, FLAGS)
350
351 /* This macro returns TRUE if there are no operands matching FLAGS in STMT.  */
352 #define ZERO_SSA_OPERANDS(STMT, FLAGS)  zero_ssa_operands (STMT, FLAGS)
353
354 /* This macro counts the number of operands in STMT matching FLAGS.  */
355 #define NUM_SSA_OPERANDS(STMT, FLAGS)   num_ssa_operands (STMT, FLAGS)
356
357 #endif  /* GCC_TREE_SSA_OPERANDS_H  */