1 /* Virtual array support.
2 Copyright (C) 1998, 1999, 2000, 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
32 #include "coretypes.h"
36 /* Auxiliary structure used inside the varray structure, used for
37 function integration data. */
39 struct const_equiv_data
GTY(()) {
40 /* Map pseudo reg number in calling function to equivalent constant. We
41 cannot in general substitute constants into parameter pseudo registers,
42 since some machine descriptions (many RISCs) won't always handle
43 the resulting insns. So if an incoming parameter has a constant
44 equivalent, we record it here, and if the resulting insn is
45 recognizable, we go with it.
47 We also use this mechanism to convert references to incoming arguments
48 and stacked variables. copy_rtx_and_substitute will replace the virtual
49 incoming argument and virtual stacked variables registers with new
50 pseudos that contain pointers into the replacement area allocated for
51 this inline instance. These pseudos are then marked as being equivalent
52 to the appropriate address and substituted if valid. */
55 /* Record the valid age for each entry. The entry is invalid if its
56 age is less than const_age. */
60 /* Enum indicating what the varray contains.
61 If this is changed, `element' in varray.c needs to be updated. */
63 enum varray_data_enum
{
81 VARRAY_DATA_CONST_EQUIV
,
87 /* Union of various array types that are used. */
88 typedef union varray_data_tag
GTY (()) {
89 char GTY ((length ("%0.num_elements"),
90 tag ("VARRAY_DATA_C"))) c
[1];
91 unsigned char GTY ((length ("%0.num_elements"),
92 tag ("VARRAY_DATA_UC"))) uc
[1];
93 short GTY ((length ("%0.num_elements"),
94 tag ("VARRAY_DATA_S"))) s
[1];
95 unsigned short GTY ((length ("%0.num_elements"),
96 tag ("VARRAY_DATA_US"))) us
[1];
97 int GTY ((length ("%0.num_elements"),
98 tag ("VARRAY_DATA_I"))) i
[1];
99 unsigned int GTY ((length ("%0.num_elements"),
100 tag ("VARRAY_DATA_U"))) u
[1];
101 long GTY ((length ("%0.num_elements"),
102 tag ("VARRAY_DATA_L"))) l
[1];
103 unsigned long GTY ((length ("%0.num_elements"),
104 tag ("VARRAY_DATA_UL"))) ul
[1];
105 HOST_WIDE_INT
GTY ((length ("%0.num_elements"),
106 tag ("VARRAY_DATA_HINT"))) hint
[1];
107 unsigned HOST_WIDE_INT
GTY ((length ("%0.num_elements"),
108 tag ("VARRAY_DATA_UHINT"))) uhint
[1];
109 PTR
GTY ((length ("%0.num_elements"), use_param (""),
110 tag ("VARRAY_DATA_GENERIC"))) generic
[1];
111 char *GTY ((length ("%0.num_elements"),
112 tag ("VARRAY_DATA_CPTR"))) cptr
[1];
113 rtx
GTY ((length ("%0.num_elements"),
114 tag ("VARRAY_DATA_RTX"))) rtx
[1];
115 rtvec
GTY ((length ("%0.num_elements"),
116 tag ("VARRAY_DATA_RTVEC"))) rtvec
[1];
117 tree
GTY ((length ("%0.num_elements"),
118 tag ("VARRAY_DATA_TREE"))) tree
[1];
119 struct bitmap_head_def
*GTY ((length ("%0.num_elements"),
120 tag ("VARRAY_DATA_BITMAP"))) bitmap
[1];
121 struct reg_info_def
*GTY ((length ("%0.num_elements"), skip (""),
122 tag ("VARRAY_DATA_REG"))) reg
[1];
123 struct const_equiv_data
GTY ((length ("%0.num_elements"),
124 tag ("VARRAY_DATA_CONST_EQUIV"))) const_equiv
[1];
125 struct basic_block_def
*GTY ((length ("%0.num_elements"), skip (""),
126 tag ("VARRAY_DATA_BB"))) bb
[1];
127 struct elt_list
*GTY ((length ("%0.num_elements"),
128 tag ("VARRAY_DATA_TE"))) te
[1];
131 /* Virtual array of pointers header. */
132 struct varray_head_tag
GTY(()) {
133 size_t num_elements
; /* Maximum element number allocated. */
134 size_t elements_used
; /* The number of elements used, if
135 using VARRAY_PUSH/VARRAY_POP. */
136 enum varray_data_enum type
; /* The kind of elements in the varray. */
137 const char *name
; /* name of the varray for reporting errors */
138 varray_data
GTY ((desc ("%0.type"))) data
; /* The data elements follow,
141 typedef struct varray_head_tag
*varray_type
;
143 /* Allocate a virtual array with NUM elements, each of which is SIZE bytes
144 long, named NAME. Array elements are zeroed. */
145 extern varray_type
varray_init (size_t, enum varray_data_enum
, const char *);
147 #define VARRAY_CHAR_INIT(va, num, name) \
148 va = varray_init (num, VARRAY_DATA_C, name)
150 #define VARRAY_UCHAR_INIT(va, num, name) \
151 va = varray_init (num, VARRAY_DATA_UC, name)
153 #define VARRAY_SHORT_INIT(va, num, name) \
154 va = varray_init (num, VARRAY_DATA_S, name)
156 #define VARRAY_USHORT_INIT(va, num, name) \
157 va = varray_init (num, VARRAY_DATA_US, name)
159 #define VARRAY_INT_INIT(va, num, name) \
160 va = varray_init (num, VARRAY_DATA_I, name)
162 #define VARRAY_UINT_INIT(va, num, name) \
163 va = varray_init (num, VARRAY_DATA_U, name)
165 #define VARRAY_LONG_INIT(va, num, name) \
166 va = varray_init (num, VARRAY_DATA_L, name)
168 #define VARRAY_ULONG_INIT(va, num, name) \
169 va = varray_init (num, VARRAY_DATA_UL, name)
171 #define VARRAY_WIDE_INT_INIT(va, num, name) \
172 va = varray_init (num, VARRAY_DATA_HINT, name)
174 #define VARRAY_UWIDE_INT_INIT(va, num, name) \
175 va = varray_init (num, VARRAY_DATA_UHINT, name)
177 #define VARRAY_GENERIC_PTR_INIT(va, num, name) \
178 va = varray_init (num, VARRAY_DATA_GENERIC, name)
180 #define VARRAY_CHAR_PTR_INIT(va, num, name) \
181 va = varray_init (num, VARRAY_DATA_CPTR, name)
183 #define VARRAY_RTX_INIT(va, num, name) \
184 va = varray_init (num, VARRAY_DATA_RTX, name)
186 #define VARRAY_RTVEC_INIT(va, num, name) \
187 va = varray_init (num, VARRAY_DATA_RTVEC, name)
189 #define VARRAY_TREE_INIT(va, num, name) \
190 va = varray_init (num, VARRAY_DATA_TREE, name)
192 #define VARRAY_BITMAP_INIT(va, num, name) \
193 va = varray_init (num, VARRAY_DATA_BITMAP, name)
195 #define VARRAY_REG_INIT(va, num, name) \
196 va = varray_init (num, VARRAY_DATA_REG, name)
198 #define VARRAY_CONST_EQUIV_INIT(va, num, name) \
199 va = varray_init (num, VARRAY_DATA_CONST_EQUIV, name)
201 #define VARRAY_BB_INIT(va, num, name) \
202 va = varray_init (num, VARRAY_DATA_BB, name)
204 #define VARRAY_ELT_LIST_INIT(va, num, name) \
205 va = varray_init (num, VARRAY_DATA_TE, name)
207 /* Free up memory allocated by the virtual array, but do not free any of the
208 elements involved. */
209 #define VARRAY_FREE(vp) \
210 do { if (vp) { free (vp); vp = (varray_type) 0; } } while (0)
212 /* Grow/shrink the virtual array VA to N elements. */
213 extern varray_type
varray_grow (varray_type
, size_t);
215 #define VARRAY_GROW(VA, N) ((VA) = varray_grow (VA, N))
217 #define VARRAY_SIZE(VA) ((VA)->num_elements)
219 #define VARRAY_ACTIVE_SIZE(VA) ((VA)->elements_used)
220 #define VARRAY_POP_ALL(VA) ((VA)->elements_used = 0)
222 #define VARRAY_CLEAR(VA) varray_clear(VA)
224 extern void varray_clear (varray_type
);
226 /* Check for VARRAY_xxx macros being in bound. */
227 #if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
228 extern void varray_check_failed (varray_type
, size_t, const char *, int,
229 const char *) ATTRIBUTE_NORETURN
;
230 #define VARRAY_CHECK(VA, N, T) __extension__ \
231 (*({ varray_type const _va = (VA); \
232 const size_t _n = (N); \
233 if (_n >= _va->num_elements) \
234 varray_check_failed (_va, _n, __FILE__, __LINE__, __FUNCTION__); \
235 &_va->data.T[_n]; }))
237 #define VARRAY_CHECK(VA, N, T) ((VA)->data.T[N])
240 /* Push X onto VA. T is the name of the field in varray_data
241 corresponding to the type of X. */
242 #define VARRAY_PUSH(VA, T, X) \
245 if ((VA)->elements_used >= (VA)->num_elements) \
246 VARRAY_GROW ((VA), 2 * (VA)->num_elements); \
247 (VA)->data.T[(VA)->elements_used++] = (X); \
251 /* Pop the top element of VA. */
252 #define VARRAY_POP(VA) \
253 ((VA)->elements_used--)
255 /* Return the top element of VA. */
256 #define VARRAY_TOP(VA, T) \
257 ((VA)->data.T[(VA)->elements_used - 1])
259 #define VARRAY_CHAR(VA, N) VARRAY_CHECK (VA, N, c)
260 #define VARRAY_UCHAR(VA, N) VARRAY_CHECK (VA, N, uc)
261 #define VARRAY_SHORT(VA, N) VARRAY_CHECK (VA, N, s)
262 #define VARRAY_USHORT(VA, N) VARRAY_CHECK (VA, N, us)
263 #define VARRAY_INT(VA, N) VARRAY_CHECK (VA, N, i)
264 #define VARRAY_UINT(VA, N) VARRAY_CHECK (VA, N, u)
265 #define VARRAY_LONG(VA, N) VARRAY_CHECK (VA, N, l)
266 #define VARRAY_ULONG(VA, N) VARRAY_CHECK (VA, N, ul)
267 #define VARRAY_WIDE_INT(VA, N) VARRAY_CHECK (VA, N, hint)
268 #define VARRAY_UWIDE_INT(VA, N) VARRAY_CHECK (VA, N, uhint)
269 #define VARRAY_GENERIC_PTR(VA,N) VARRAY_CHECK (VA, N, generic)
270 #define VARRAY_CHAR_PTR(VA,N) VARRAY_CHECK (VA, N, cptr)
271 #define VARRAY_RTX(VA, N) VARRAY_CHECK (VA, N, rtx)
272 #define VARRAY_RTVEC(VA, N) VARRAY_CHECK (VA, N, rtvec)
273 #define VARRAY_TREE(VA, N) VARRAY_CHECK (VA, N, tree)
274 #define VARRAY_BITMAP(VA, N) VARRAY_CHECK (VA, N, bitmap)
275 #define VARRAY_REG(VA, N) VARRAY_CHECK (VA, N, reg)
276 #define VARRAY_CONST_EQUIV(VA, N) VARRAY_CHECK (VA, N, const_equiv)
277 #define VARRAY_BB(VA, N) VARRAY_CHECK (VA, N, bb)
278 #define VARRAY_ELT_LIST(VA, N) VARRAY_CHECK (VA, N, te)
280 /* Push a new element on the end of VA, extending it if necessary. */
281 #define VARRAY_PUSH_CHAR(VA, X) VARRAY_PUSH (VA, c, X)
282 #define VARRAY_PUSH_UCHAR(VA, X) VARRAY_PUSH (VA, uc, X)
283 #define VARRAY_PUSH_SHORT(VA, X) VARRAY_PUSH (VA, s, X)
284 #define VARRAY_PUSH_USHORT(VA, X) VARRAY_PUSH (VA, us, X)
285 #define VARRAY_PUSH_INT(VA, X) VARRAY_PUSH (VA, i, X)
286 #define VARRAY_PUSH_UINT(VA, X) VARRAY_PUSH (VA, u, X)
287 #define VARRAY_PUSH_LONG(VA, X) VARRAY_PUSH (VA, l, X)
288 #define VARRAY_PUSH_ULONG(VA, X) VARRAY_PUSH (VA, ul, X)
289 #define VARRAY_PUSH_WIDE_INT(VA, X) VARRAY_PUSH (VA, hint, X)
290 #define VARRAY_PUSH_UWIDE_INT(VA, X) VARRAY_PUSH (VA, uhint, X)
291 #define VARRAY_PUSH_GENERIC_PTR(VA, X) VARRAY_PUSH (VA, generic, X)
292 #define VARRAY_PUSH_CHAR_PTR(VA, X) VARRAY_PUSH (VA, cptr, X)
293 #define VARRAY_PUSH_RTX(VA, X) VARRAY_PUSH (VA, rtx, X)
294 #define VARRAY_PUSH_RTVEC(VA, X) VARRAY_PUSH (VA, rtvec, X)
295 #define VARRAY_PUSH_TREE(VA, X) VARRAY_PUSH (VA, tree, X)
296 #define VARRAY_PUSH_BITMAP(VA, X) VARRAY_PUSH (VA, bitmap, X)
297 #define VARRAY_PUSH_REG(VA, X) VARRAY_PUSH (VA, reg, X)
298 #define VARRAY_PUSH_CONST_EQUIV(VA, X) VARRAY_PUSH (VA, const_equiv, X)
299 #define VARRAY_PUSH_BB(VA, X) VARRAY_PUSH (VA, bb, X)
301 /* Return the last element of VA. */
302 #define VARRAY_TOP_CHAR(VA) VARRAY_TOP (VA, c)
303 #define VARRAY_TOP_UCHAR(VA) VARRAY_TOP (VA, uc)
304 #define VARRAY_TOP_SHORT(VA) VARRAY_TOP (VA, s)
305 #define VARRAY_TOP_USHORT(VA) VARRAY_TOP (VA, us)
306 #define VARRAY_TOP_INT(VA) VARRAY_TOP (VA, i)
307 #define VARRAY_TOP_UINT(VA) VARRAY_TOP (VA, u)
308 #define VARRAY_TOP_LONG(VA) VARRAY_TOP (VA, l)
309 #define VARRAY_TOP_ULONG(VA) VARRAY_TOP (VA, ul)
310 #define VARRAY_TOP_WIDE_INT(VA) VARRAY_TOP (VA, hint)
311 #define VARRAY_TOP_UWIDE_INT(VA) VARRAY_TOP (VA, uhint)
312 #define VARRAY_TOP_GENERIC_PTR(VA) VARRAY_TOP (VA, generic)
313 #define VARRAY_TOP_CHAR_PTR(VA) VARRAY_TOP (VA, cptr)
314 #define VARRAY_TOP_RTX(VA) VARRAY_TOP (VA, rtx)
315 #define VARRAY_TOP_RTVEC(VA) VARRAY_TOP (VA, rtvec)
316 #define VARRAY_TOP_TREE(VA) VARRAY_TOP (VA, tree)
317 #define VARRAY_TOP_BITMAP(VA) VARRAY_TOP (VA, bitmap)
318 #define VARRAY_TOP_REG(VA) VARRAY_TOP (VA, reg)
319 #define VARRAY_TOP_CONST_EQUIV(VA) VARRAY_TOP (VA, const_equiv)
320 #define VARRAY_TOP_BB(VA) VARRAY_TOP (VA, bb)
322 #endif /* ! GCC_VARRAY_H */