builtins.c (expand_builtin_atomic_compare_exchange): Pass old value operand as MEM...
[platform/upstream/gcc.git] / gcc / tree-ssa-operands.h
1 /* SSA operand management for trees.
2    Copyright (C) 2003, 2005, 2006, 2007, 2008, 2010
3    Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
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              ((use_operand_p)NULL)
35 #define NULL_DEF_OPERAND_P              ((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 structure represents a variable sized buffer which is allocated by the
54    operand memory manager.  Operands are suballocated out of this block.  The
55    MEM array varies in size.  */
56
57 struct GTY((chain_next("%h.next"), variable_size)) ssa_operand_memory_d {
58   struct ssa_operand_memory_d *next;
59   char mem[1];
60 };
61
62 /* Per-function operand caches.  */
63 struct GTY(()) ssa_operands {
64    struct ssa_operand_memory_d *operand_memory;
65    unsigned operand_memory_index;
66    /* Current size of the operand memory buffer.  */
67    unsigned int ssa_operand_mem_size;
68
69    bool ops_active;
70
71    struct def_optype_d * GTY ((skip (""))) free_defs;
72    struct use_optype_d * GTY ((skip (""))) free_uses;
73 };
74
75 #define USE_FROM_PTR(PTR)       get_use_from_ptr (PTR)
76 #define DEF_FROM_PTR(PTR)       get_def_from_ptr (PTR)
77 #define SET_USE(USE, V)         set_ssa_use_from_ptr (USE, V)
78 #define SET_DEF(DEF, V)         ((*(DEF)) = (V))
79
80 #define USE_STMT(USE)           (USE)->loc.stmt
81
82 #define USE_OP_PTR(OP)          (&((OP)->use_ptr))
83 #define USE_OP(OP)              (USE_FROM_PTR (USE_OP_PTR (OP)))
84
85 #define DEF_OP_PTR(OP)          ((OP)->def_ptr)
86 #define DEF_OP(OP)              (DEF_FROM_PTR (DEF_OP_PTR (OP)))
87
88 #define PHI_RESULT_PTR(PHI)     gimple_phi_result_ptr (PHI)
89 #define PHI_RESULT(PHI)         DEF_FROM_PTR (PHI_RESULT_PTR (PHI))
90 #define SET_PHI_RESULT(PHI, V)  SET_DEF (PHI_RESULT_PTR (PHI), (V))
91
92 #define PHI_ARG_DEF_PTR(PHI, I) gimple_phi_arg_imm_use_ptr ((PHI), (I))
93 #define PHI_ARG_DEF(PHI, I)     USE_FROM_PTR (PHI_ARG_DEF_PTR ((PHI), (I)))
94 #define SET_PHI_ARG_DEF(PHI, I, V)                                      \
95                                 SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V))
96 #define PHI_ARG_DEF_FROM_EDGE(PHI, E)                                   \
97                                 PHI_ARG_DEF ((PHI), (E)->dest_idx)
98 #define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E)                               \
99                                 PHI_ARG_DEF_PTR ((PHI), (E)->dest_idx)
100 #define PHI_ARG_INDEX_FROM_USE(USE)   phi_arg_index_from_use (USE)
101
102
103 extern void init_ssa_operands (struct function *fn);
104 extern void fini_ssa_operands (void);
105 extern void update_stmt_operands (gimple);
106 extern void free_stmt_operands (gimple);
107 extern bool verify_imm_links (FILE *f, tree var);
108 extern bool verify_ssa_operands (gimple stmt);
109
110 extern void dump_immediate_uses (FILE *file);
111 extern void dump_immediate_uses_for (FILE *file, tree var);
112 extern void debug_immediate_uses (void);
113 extern void debug_immediate_uses_for (tree var);
114 extern void dump_decl_set (FILE *, bitmap);
115 extern void debug_decl_set (bitmap);
116
117 extern bool ssa_operands_active (void);
118
119 extern bool virtual_operand_p (tree);
120 extern void unlink_stmt_vdef (gimple);
121
122 enum ssa_op_iter_type {
123   ssa_op_iter_none = 0,
124   ssa_op_iter_tree,
125   ssa_op_iter_use,
126   ssa_op_iter_def
127 };
128
129 /* This structure is used in the operand iterator loops.  It contains the
130    items required to determine which operand is retrieved next.  During
131    optimization, this structure is scalarized, and any unused fields are
132    optimized away, resulting in little overhead.  */
133
134 typedef struct ssa_operand_iterator_d
135 {
136   bool done;
137   enum ssa_op_iter_type iter_type;
138   def_optype_p defs;
139   use_optype_p uses;
140   int phi_i;
141   int num_phi;
142   gimple phi_stmt;
143 } ssa_op_iter;
144
145 /* These flags are used to determine which operands are returned during
146    execution of the loop.  */
147 #define SSA_OP_USE              0x01    /* Real USE operands.  */
148 #define SSA_OP_DEF              0x02    /* Real DEF operands.  */
149 #define SSA_OP_VUSE             0x04    /* VUSE operands.  */
150 #define SSA_OP_VDEF             0x08    /* VDEF operands.  */
151
152 /* These are commonly grouped operand flags.  */
153 #define SSA_OP_VIRTUAL_USES     (SSA_OP_VUSE)
154 #define SSA_OP_VIRTUAL_DEFS     (SSA_OP_VDEF)
155 #define SSA_OP_ALL_VIRTUALS     (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_DEFS)
156 #define SSA_OP_ALL_USES         (SSA_OP_VIRTUAL_USES | SSA_OP_USE)
157 #define SSA_OP_ALL_DEFS         (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF)
158 #define SSA_OP_ALL_OPERANDS     (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS)
159
160 /* This macro executes a loop over the operands of STMT specified in FLAG,
161    returning each operand as a 'tree' in the variable TREEVAR.  ITER is an
162    ssa_op_iter structure used to control the loop.  */
163 #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS)   \
164   for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS);      \
165        !op_iter_done (&(ITER));                                 \
166        (void) (TREEVAR = op_iter_next_tree (&(ITER))))
167
168 /* This macro executes a loop over the operands of STMT specified in FLAG,
169    returning each operand as a 'use_operand_p' in the variable USEVAR.
170    ITER is an ssa_op_iter structure used to control the loop.  */
171 #define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS)     \
172   for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS);        \
173        !op_iter_done (&(ITER));                                 \
174        USEVAR = op_iter_next_use (&(ITER)))
175
176 /* This macro executes a loop over the operands of STMT specified in FLAG,
177    returning each operand as a 'def_operand_p' in the variable DEFVAR.
178    ITER is an ssa_op_iter structure used to control the loop.  */
179 #define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS)     \
180   for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS);        \
181        !op_iter_done (&(ITER));                                 \
182        DEFVAR = op_iter_next_def (&(ITER)))
183
184 /* This macro will execute a loop over all the arguments of a PHI which
185    match FLAGS.   A use_operand_p is always returned via USEVAR.  FLAGS
186    can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES.  */
187 #define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS)             \
188   for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS);   \
189        !op_iter_done (&(ITER));                                 \
190        (USEVAR) = op_iter_next_use (&(ITER)))
191
192
193 /* This macro will execute a loop over a stmt, regardless of whether it is
194    a real stmt or a PHI node, looking at the USE nodes matching FLAGS.  */
195 #define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS)     \
196   for ((USEVAR) = (gimple_code (STMT) == GIMPLE_PHI             \
197                    ? op_iter_init_phiuse (&(ITER), STMT, FLAGS) \
198                    : op_iter_init_use (&(ITER), STMT, FLAGS));  \
199        !op_iter_done (&(ITER));                                 \
200        (USEVAR) = op_iter_next_use (&(ITER)))
201
202 /* This macro will execute a loop over a stmt, regardless of whether it is
203    a real stmt or a PHI node, looking at the DEF nodes matching FLAGS.  */
204 #define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS)     \
205   for ((DEFVAR) = (gimple_code (STMT) == GIMPLE_PHI             \
206                    ? op_iter_init_phidef (&(ITER), STMT, FLAGS) \
207                    : op_iter_init_def (&(ITER), STMT, FLAGS));  \
208        !op_iter_done (&(ITER));                                 \
209        (DEFVAR) = op_iter_next_def (&(ITER)))
210
211 /* This macro returns an operand in STMT as a tree if it is the ONLY
212    operand matching FLAGS.  If there are 0 or more than 1 operand matching
213    FLAGS, then NULL_TREE is returned.  */
214 #define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS)                    \
215   single_ssa_tree_operand (STMT, FLAGS)
216
217 /* This macro returns an operand in STMT as a use_operand_p if it is the ONLY
218    operand matching FLAGS.  If there are 0 or more than 1 operand matching
219    FLAGS, then NULL_USE_OPERAND_P is returned.  */
220 #define SINGLE_SSA_USE_OPERAND(STMT, FLAGS)                     \
221   single_ssa_use_operand (STMT, FLAGS)
222
223 /* This macro returns an operand in STMT as a def_operand_p if it is the ONLY
224    operand matching FLAGS.  If there are 0 or more than 1 operand matching
225    FLAGS, then NULL_DEF_OPERAND_P is returned.  */
226 #define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS)                     \
227   single_ssa_def_operand (STMT, FLAGS)
228
229 /* This macro returns TRUE if there are no operands matching FLAGS in STMT.  */
230 #define ZERO_SSA_OPERANDS(STMT, FLAGS)  zero_ssa_operands (STMT, FLAGS)
231
232 /* This macro counts the number of operands in STMT matching FLAGS.  */
233 #define NUM_SSA_OPERANDS(STMT, FLAGS)   num_ssa_operands (STMT, FLAGS)
234
235 #endif  /* GCC_TREE_SSA_OPERANDS_H  */