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