1 /* Virtual array support.
2 Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
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
{
75 VARRAY_DATA_GENERIC_NOGC
,
82 VARRAY_DATA_CONST_EQUIV
,
90 /* Union of various array types that are used. */
91 typedef union varray_data_tag
GTY (()) {
92 char GTY ((length ("%0.num_elements"),
93 tag ("VARRAY_DATA_C"))) c
[1];
94 unsigned char GTY ((length ("%0.num_elements"),
95 tag ("VARRAY_DATA_UC"))) uc
[1];
96 short GTY ((length ("%0.num_elements"),
97 tag ("VARRAY_DATA_S"))) s
[1];
98 unsigned short GTY ((length ("%0.num_elements"),
99 tag ("VARRAY_DATA_US"))) us
[1];
100 int GTY ((length ("%0.num_elements"),
101 tag ("VARRAY_DATA_I"))) i
[1];
102 unsigned int GTY ((length ("%0.num_elements"),
103 tag ("VARRAY_DATA_U"))) u
[1];
104 long GTY ((length ("%0.num_elements"),
105 tag ("VARRAY_DATA_L"))) l
[1];
106 unsigned long GTY ((length ("%0.num_elements"),
107 tag ("VARRAY_DATA_UL"))) ul
[1];
108 HOST_WIDE_INT
GTY ((length ("%0.num_elements"),
109 tag ("VARRAY_DATA_HINT"))) hint
[1];
110 unsigned HOST_WIDE_INT
GTY ((length ("%0.num_elements"),
111 tag ("VARRAY_DATA_UHINT"))) uhint
[1];
112 PTR
GTY ((length ("%0.num_elements"), use_param
,
113 tag ("VARRAY_DATA_GENERIC"))) generic
[1];
114 PTR
GTY ((length ("%0.num_elements"), skip (""),
115 tag ("VARRAY_DATA_GENERIC_NOGC"))) generic_nogc
[1];
116 char *GTY ((length ("%0.num_elements"),
117 tag ("VARRAY_DATA_CPTR"))) cptr
[1];
118 rtx
GTY ((length ("%0.num_elements"),
119 tag ("VARRAY_DATA_RTX"))) rtx
[1];
120 rtvec
GTY ((length ("%0.num_elements"),
121 tag ("VARRAY_DATA_RTVEC"))) rtvec
[1];
122 tree
GTY ((length ("%0.num_elements"),
123 tag ("VARRAY_DATA_TREE"))) tree
[1];
124 struct bitmap_head_def
*GTY ((length ("%0.num_elements"),
125 tag ("VARRAY_DATA_BITMAP"))) bitmap
[1];
126 struct reg_info_def
*GTY ((length ("%0.num_elements"), skip
,
127 tag ("VARRAY_DATA_REG"))) reg
[1];
128 struct const_equiv_data
GTY ((length ("%0.num_elements"),
129 tag ("VARRAY_DATA_CONST_EQUIV"))) const_equiv
[1];
130 struct basic_block_def
*GTY ((length ("%0.num_elements"), skip
,
131 tag ("VARRAY_DATA_BB"))) bb
[1];
132 struct elt_list
*GTY ((length ("%0.num_elements"),
133 tag ("VARRAY_DATA_TE"))) te
[1];
134 struct edge_def
*GTY ((length ("%0.num_elements"),
135 tag ("VARRAY_DATA_EDGE"))) e
[1];
136 tree
*GTY ((length ("%0.num_elements"), skip (""),
137 tag ("VARRAY_DATA_TREE_PTR"))) tp
[1];
140 /* Virtual array of pointers header. */
141 struct varray_head_tag
GTY(()) {
142 size_t num_elements
; /* Maximum element number allocated. */
143 size_t elements_used
; /* The number of elements used, if
144 using VARRAY_PUSH/VARRAY_POP. */
145 enum varray_data_enum type
; /* The kind of elements in the varray. */
146 const char *name
; /* name of the varray for reporting errors */
147 varray_data
GTY ((desc ("%0.type"))) data
; /* The data elements follow,
150 typedef struct varray_head_tag
*varray_type
;
152 /* Allocate a virtual array with NUM elements, each of which is SIZE bytes
153 long, named NAME. Array elements are zeroed. */
154 extern varray_type
varray_init (size_t, enum varray_data_enum
, const char *);
156 #define VARRAY_CHAR_INIT(va, num, name) \
157 va = varray_init (num, VARRAY_DATA_C, name)
159 #define VARRAY_UCHAR_INIT(va, num, name) \
160 va = varray_init (num, VARRAY_DATA_UC, name)
162 #define VARRAY_SHORT_INIT(va, num, name) \
163 va = varray_init (num, VARRAY_DATA_S, name)
165 #define VARRAY_USHORT_INIT(va, num, name) \
166 va = varray_init (num, VARRAY_DATA_US, name)
168 #define VARRAY_INT_INIT(va, num, name) \
169 va = varray_init (num, VARRAY_DATA_I, name)
171 #define VARRAY_UINT_INIT(va, num, name) \
172 va = varray_init (num, VARRAY_DATA_U, name)
174 #define VARRAY_LONG_INIT(va, num, name) \
175 va = varray_init (num, VARRAY_DATA_L, name)
177 #define VARRAY_ULONG_INIT(va, num, name) \
178 va = varray_init (num, VARRAY_DATA_UL, name)
180 #define VARRAY_WIDE_INT_INIT(va, num, name) \
181 va = varray_init (num, VARRAY_DATA_HINT, name)
183 #define VARRAY_UWIDE_INT_INIT(va, num, name) \
184 va = varray_init (num, VARRAY_DATA_UHINT, name)
186 #define VARRAY_GENERIC_PTR_INIT(va, num, name) \
187 va = varray_init (num, VARRAY_DATA_GENERIC, name)
189 #define VARRAY_GENERIC_PTR_NOGC_INIT(va, num, name) \
190 va = varray_init (num, VARRAY_DATA_GENERIC_NOGC, name)
192 #define VARRAY_CHAR_PTR_INIT(va, num, name) \
193 va = varray_init (num, VARRAY_DATA_CPTR, name)
195 #define VARRAY_RTX_INIT(va, num, name) \
196 va = varray_init (num, VARRAY_DATA_RTX, name)
198 #define VARRAY_RTVEC_INIT(va, num, name) \
199 va = varray_init (num, VARRAY_DATA_RTVEC, name)
201 #define VARRAY_TREE_INIT(va, num, name) \
202 va = varray_init (num, VARRAY_DATA_TREE, name)
204 #define VARRAY_BITMAP_INIT(va, num, name) \
205 va = varray_init (num, VARRAY_DATA_BITMAP, name)
207 #define VARRAY_REG_INIT(va, num, name) \
208 va = varray_init (num, VARRAY_DATA_REG, name)
210 #define VARRAY_CONST_EQUIV_INIT(va, num, name) \
211 va = varray_init (num, VARRAY_DATA_CONST_EQUIV, name)
213 #define VARRAY_BB_INIT(va, num, name) \
214 va = varray_init (num, VARRAY_DATA_BB, name)
216 #define VARRAY_ELT_LIST_INIT(va, num, name) \
217 va = varray_init (num, VARRAY_DATA_TE, name)
219 #define VARRAY_EDGE_INIT(va, num, name) \
220 va = varray_init (num, VARRAY_DATA_EDGE, name)
222 #define VARRAY_TREE_PTR_INIT(va, num, name) \
223 va = varray_init (num, VARRAY_DATA_TREE_PTR, name)
225 /* Free up memory allocated by the virtual array, but do not free any of the
226 elements involved. */
227 #define VARRAY_FREE(vp) \
228 do { if (vp) { free (vp); vp = (varray_type) 0; } } while (0)
230 /* Grow/shrink the virtual array VA to N elements. */
231 extern varray_type
varray_grow (varray_type
, size_t);
233 #define VARRAY_GROW(VA, N) ((VA) = varray_grow (VA, N))
235 #define VARRAY_SIZE(VA) ((VA)->num_elements)
237 #define VARRAY_ACTIVE_SIZE(VA) ((VA)->elements_used)
238 #define VARRAY_POP_ALL(VA) ((VA)->elements_used = 0)
240 #define VARRAY_CLEAR(VA) varray_clear(VA)
242 extern void varray_clear (varray_type
);
243 extern void varray_copy (varray_type v1
, varray_type v2
);
245 extern void dump_varray_statistics (void);
247 /* Check for VARRAY_xxx macros being in bound. */
248 #if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
249 extern void varray_check_failed (varray_type
, size_t, const char *, int,
250 const char *) ATTRIBUTE_NORETURN
;
251 extern void varray_underflow (varray_type
, const char *, int, const char *)
253 #define VARRAY_CHECK(VA, N, T) __extension__ \
254 (*({ varray_type const _va = (VA); \
255 const size_t _n = (N); \
256 if (_n >= _va->num_elements) \
257 varray_check_failed (_va, _n, __FILE__, __LINE__, __FUNCTION__); \
258 &_va->data.T[_n]; }))
260 #define VARRAY_POP(VA) do { \
261 varray_type const _va = (VA); \
262 if (_va->elements_used == 0) \
263 varray_underflow (_va, __FILE__, __LINE__, __FUNCTION__); \
265 _va->elements_used--; \
269 #define VARRAY_CHECK(VA, N, T) ((VA)->data.T[N])
270 /* Pop the top element of VA. */
271 #define VARRAY_POP(VA) do { ((VA)->elements_used--); } while (0)
274 /* Push X onto VA. T is the name of the field in varray_data
275 corresponding to the type of X. */
276 #define VARRAY_PUSH(VA, T, X) \
279 if ((VA)->elements_used >= (VA)->num_elements) \
280 VARRAY_GROW ((VA), 2 * (VA)->num_elements); \
281 (VA)->data.T[(VA)->elements_used++] = (X); \
285 #define VARRAY_CHAR(VA, N) VARRAY_CHECK (VA, N, c)
286 #define VARRAY_UCHAR(VA, N) VARRAY_CHECK (VA, N, uc)
287 #define VARRAY_SHORT(VA, N) VARRAY_CHECK (VA, N, s)
288 #define VARRAY_USHORT(VA, N) VARRAY_CHECK (VA, N, us)
289 #define VARRAY_INT(VA, N) VARRAY_CHECK (VA, N, i)
290 #define VARRAY_UINT(VA, N) VARRAY_CHECK (VA, N, u)
291 #define VARRAY_LONG(VA, N) VARRAY_CHECK (VA, N, l)
292 #define VARRAY_ULONG(VA, N) VARRAY_CHECK (VA, N, ul)
293 #define VARRAY_WIDE_INT(VA, N) VARRAY_CHECK (VA, N, hint)
294 #define VARRAY_UWIDE_INT(VA, N) VARRAY_CHECK (VA, N, uhint)
295 #define VARRAY_GENERIC_PTR(VA,N) VARRAY_CHECK (VA, N, generic)
296 #define VARRAY_GENERIC_PTR_NOGC(VA,N) VARRAY_CHECK (VA, N, generic_nogc)
297 #define VARRAY_CHAR_PTR(VA,N) VARRAY_CHECK (VA, N, cptr)
298 #define VARRAY_RTX(VA, N) VARRAY_CHECK (VA, N, rtx)
299 #define VARRAY_RTVEC(VA, N) VARRAY_CHECK (VA, N, rtvec)
300 #define VARRAY_TREE(VA, N) VARRAY_CHECK (VA, N, tree)
301 #define VARRAY_BITMAP(VA, N) VARRAY_CHECK (VA, N, bitmap)
302 #define VARRAY_REG(VA, N) VARRAY_CHECK (VA, N, reg)
303 #define VARRAY_CONST_EQUIV(VA, N) VARRAY_CHECK (VA, N, const_equiv)
304 #define VARRAY_BB(VA, N) VARRAY_CHECK (VA, N, bb)
305 #define VARRAY_ELT_LIST(VA, N) VARRAY_CHECK (VA, N, te)
306 #define VARRAY_EDGE(VA, N) VARRAY_CHECK (VA, N, e)
307 #define VARRAY_TREE_PTR(VA, N) VARRAY_CHECK (VA, N, tp)
309 /* Push a new element on the end of VA, extending it if necessary. */
310 #define VARRAY_PUSH_CHAR(VA, X) VARRAY_PUSH (VA, c, X)
311 #define VARRAY_PUSH_UCHAR(VA, X) VARRAY_PUSH (VA, uc, X)
312 #define VARRAY_PUSH_SHORT(VA, X) VARRAY_PUSH (VA, s, X)
313 #define VARRAY_PUSH_USHORT(VA, X) VARRAY_PUSH (VA, us, X)
314 #define VARRAY_PUSH_INT(VA, X) VARRAY_PUSH (VA, i, X)
315 #define VARRAY_PUSH_UINT(VA, X) VARRAY_PUSH (VA, u, X)
316 #define VARRAY_PUSH_LONG(VA, X) VARRAY_PUSH (VA, l, X)
317 #define VARRAY_PUSH_ULONG(VA, X) VARRAY_PUSH (VA, ul, X)
318 #define VARRAY_PUSH_WIDE_INT(VA, X) VARRAY_PUSH (VA, hint, X)
319 #define VARRAY_PUSH_UWIDE_INT(VA, X) VARRAY_PUSH (VA, uhint, X)
320 #define VARRAY_PUSH_GENERIC_PTR(VA, X) VARRAY_PUSH (VA, generic, X)
321 #define VARRAY_PUSH_GENERIC_PTR_NOGC(VA, X) VARRAY_PUSH (VA, generic_nogc, X)
322 #define VARRAY_PUSH_CHAR_PTR(VA, X) VARRAY_PUSH (VA, cptr, X)
323 #define VARRAY_PUSH_RTX(VA, X) VARRAY_PUSH (VA, rtx, X)
324 #define VARRAY_PUSH_RTVEC(VA, X) VARRAY_PUSH (VA, rtvec, X)
325 #define VARRAY_PUSH_TREE(VA, X) VARRAY_PUSH (VA, tree, X)
326 #define VARRAY_PUSH_BITMAP(VA, X) VARRAY_PUSH (VA, bitmap, X)
327 #define VARRAY_PUSH_REG(VA, X) VARRAY_PUSH (VA, reg, X)
328 #define VARRAY_PUSH_CONST_EQUIV(VA, X) VARRAY_PUSH (VA, const_equiv, X)
329 #define VARRAY_PUSH_BB(VA, X) VARRAY_PUSH (VA, bb, X)
330 #define VARRAY_PUSH_EDGE(VA, X) VARRAY_PUSH (VA, e, X)
331 #define VARRAY_PUSH_TREE_PTR(VA, X) VARRAY_PUSH (VA, tp, X)
333 /* Return the last element of VA. */
334 #define VARRAY_TOP(VA, T) VARRAY_CHECK(VA, (VA)->elements_used - 1, T)
336 #define VARRAY_TOP_CHAR(VA) VARRAY_TOP (VA, c)
337 #define VARRAY_TOP_UCHAR(VA) VARRAY_TOP (VA, uc)
338 #define VARRAY_TOP_SHORT(VA) VARRAY_TOP (VA, s)
339 #define VARRAY_TOP_USHORT(VA) VARRAY_TOP (VA, us)
340 #define VARRAY_TOP_INT(VA) VARRAY_TOP (VA, i)
341 #define VARRAY_TOP_UINT(VA) VARRAY_TOP (VA, u)
342 #define VARRAY_TOP_LONG(VA) VARRAY_TOP (VA, l)
343 #define VARRAY_TOP_ULONG(VA) VARRAY_TOP (VA, ul)
344 #define VARRAY_TOP_WIDE_INT(VA) VARRAY_TOP (VA, hint)
345 #define VARRAY_TOP_UWIDE_INT(VA) VARRAY_TOP (VA, uhint)
346 #define VARRAY_TOP_GENERIC_PTR(VA) VARRAY_TOP (VA, generic)
347 #define VARRAY_TOP_GENERIC_PTR_NOGC(VA) VARRAY_TOP (VA, generic_nogc)
348 #define VARRAY_TOP_CHAR_PTR(VA) VARRAY_TOP (VA, cptr)
349 #define VARRAY_TOP_RTX(VA) VARRAY_TOP (VA, rtx)
350 #define VARRAY_TOP_RTVEC(VA) VARRAY_TOP (VA, rtvec)
351 #define VARRAY_TOP_TREE(VA) VARRAY_TOP (VA, tree)
352 #define VARRAY_TOP_BITMAP(VA) VARRAY_TOP (VA, bitmap)
353 #define VARRAY_TOP_REG(VA) VARRAY_TOP (VA, reg)
354 #define VARRAY_TOP_CONST_EQUIV(VA) VARRAY_TOP (VA, const_equiv)
355 #define VARRAY_TOP_BB(VA) VARRAY_TOP (VA, bb)
356 #define VARRAY_TOP_EDGE(VA) VARRAY_TOP (VA, e)
357 #define VARRAY_TOP_TREE_PTR(VA) VARRAY_TOP (VA, tp)
359 #endif /* ! GCC_VARRAY_H */