PR libgomp/25884
[official-gcc.git] / gcc / varray.h
blob6463f2e4dbd521ba032e936a16bae7dc4046ae5f
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)
11 any later version.
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, 51 Franklin Street, Fifth Floor, Boston,
21 MA 02110-1301, USA. */
23 #ifndef GCC_VARRAY_H
24 #define GCC_VARRAY_H
26 #ifndef HOST_WIDE_INT
27 #include "machmode.h"
28 #endif
30 #ifndef GCC_SYSTEM_H
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #endif
36 /* Enum indicating what the varray contains.
37 If this is changed, `element' in varray.c needs to be updated. */
39 enum varray_data_enum {
40 VARRAY_DATA_C,
41 VARRAY_DATA_UC,
42 VARRAY_DATA_S,
43 VARRAY_DATA_US,
44 VARRAY_DATA_I,
45 VARRAY_DATA_U,
46 VARRAY_DATA_L,
47 VARRAY_DATA_UL,
48 VARRAY_DATA_HINT,
49 VARRAY_DATA_UHINT,
50 VARRAY_DATA_GENERIC,
51 VARRAY_DATA_GENERIC_NOGC,
52 VARRAY_DATA_CPTR,
53 VARRAY_DATA_RTX,
54 VARRAY_DATA_RTVEC,
55 VARRAY_DATA_TREE,
56 VARRAY_DATA_BITMAP,
57 VARRAY_DATA_REG,
58 VARRAY_DATA_BB,
59 VARRAY_DATA_TE,
60 VARRAY_DATA_EDGE,
61 VARRAY_DATA_TREE_PTR,
62 NUM_VARRAY_DATA
65 /* Union of various array types that are used. */
66 typedef union varray_data_tag GTY (()) {
67 char GTY ((length ("%0.num_elements"),
68 tag ("VARRAY_DATA_C"))) vdt_c[1];
69 unsigned char GTY ((length ("%0.num_elements"),
70 tag ("VARRAY_DATA_UC"))) vdt_uc[1];
71 short GTY ((length ("%0.num_elements"),
72 tag ("VARRAY_DATA_S"))) vdt_s[1];
73 unsigned short GTY ((length ("%0.num_elements"),
74 tag ("VARRAY_DATA_US"))) vdt_us[1];
75 int GTY ((length ("%0.num_elements"),
76 tag ("VARRAY_DATA_I"))) vdt_i[1];
77 unsigned int GTY ((length ("%0.num_elements"),
78 tag ("VARRAY_DATA_U"))) vdt_u[1];
79 long GTY ((length ("%0.num_elements"),
80 tag ("VARRAY_DATA_L"))) vdt_l[1];
81 unsigned long GTY ((length ("%0.num_elements"),
82 tag ("VARRAY_DATA_UL"))) vdt_ul[1];
83 HOST_WIDE_INT GTY ((length ("%0.num_elements"),
84 tag ("VARRAY_DATA_HINT"))) vdt_hint[1];
85 unsigned HOST_WIDE_INT GTY ((length ("%0.num_elements"),
86 tag ("VARRAY_DATA_UHINT"))) vdt_uhint[1];
87 PTR GTY ((length ("%0.num_elements"), use_param,
88 tag ("VARRAY_DATA_GENERIC"))) vdt_generic[1];
89 PTR GTY ((length ("%0.num_elements"), skip (""),
90 tag ("VARRAY_DATA_GENERIC_NOGC"))) vdt_generic_nogc[1];
91 char *GTY ((length ("%0.num_elements"),
92 tag ("VARRAY_DATA_CPTR"))) vdt_cptr[1];
93 rtx GTY ((length ("%0.num_elements"),
94 tag ("VARRAY_DATA_RTX"))) vdt_rtx[1];
95 rtvec GTY ((length ("%0.num_elements"),
96 tag ("VARRAY_DATA_RTVEC"))) vdt_rtvec[1];
97 tree GTY ((length ("%0.num_elements"),
98 tag ("VARRAY_DATA_TREE"))) vdt_tree[1];
99 struct bitmap_head_def *GTY ((length ("%0.num_elements"),
100 tag ("VARRAY_DATA_BITMAP"))) vdt_bitmap[1];
101 struct reg_info_def *GTY ((length ("%0.num_elements"), skip,
102 tag ("VARRAY_DATA_REG"))) vdt_reg[1];
103 struct basic_block_def *GTY ((length ("%0.num_elements"), skip,
104 tag ("VARRAY_DATA_BB"))) vdt_bb[1];
105 struct elt_list *GTY ((length ("%0.num_elements"),
106 tag ("VARRAY_DATA_TE"))) vdt_te[1];
107 struct edge_def *GTY ((length ("%0.num_elements"),
108 tag ("VARRAY_DATA_EDGE"))) vdt_e[1];
109 tree *GTY ((length ("%0.num_elements"), skip (""),
110 tag ("VARRAY_DATA_TREE_PTR"))) vdt_tp[1];
111 } varray_data;
113 /* Virtual array of pointers header. */
114 struct varray_head_tag GTY(()) {
115 size_t num_elements; /* Maximum element number allocated. */
116 size_t elements_used; /* The number of elements used, if
117 using VARRAY_PUSH/VARRAY_POP. */
118 enum varray_data_enum type; /* The kind of elements in the varray. */
119 const char *name; /* name of the varray for reporting errors */
120 varray_data GTY ((desc ("%0.type"))) data; /* The data elements follow,
121 must be last. */
123 typedef struct varray_head_tag *varray_type;
125 /* Allocate a virtual array with NUM elements, each of which is SIZE bytes
126 long, named NAME. Array elements are zeroed. */
127 extern varray_type varray_init (size_t, enum varray_data_enum, const char *);
129 #define VARRAY_CHAR_INIT(va, num, name) \
130 va = varray_init (num, VARRAY_DATA_C, name)
132 #define VARRAY_UCHAR_INIT(va, num, name) \
133 va = varray_init (num, VARRAY_DATA_UC, name)
135 #define VARRAY_SHORT_INIT(va, num, name) \
136 va = varray_init (num, VARRAY_DATA_S, name)
138 #define VARRAY_USHORT_INIT(va, num, name) \
139 va = varray_init (num, VARRAY_DATA_US, name)
141 #define VARRAY_INT_INIT(va, num, name) \
142 va = varray_init (num, VARRAY_DATA_I, name)
144 #define VARRAY_UINT_INIT(va, num, name) \
145 va = varray_init (num, VARRAY_DATA_U, name)
147 #define VARRAY_LONG_INIT(va, num, name) \
148 va = varray_init (num, VARRAY_DATA_L, name)
150 #define VARRAY_ULONG_INIT(va, num, name) \
151 va = varray_init (num, VARRAY_DATA_UL, name)
153 #define VARRAY_WIDE_INT_INIT(va, num, name) \
154 va = varray_init (num, VARRAY_DATA_HINT, name)
156 #define VARRAY_UWIDE_INT_INIT(va, num, name) \
157 va = varray_init (num, VARRAY_DATA_UHINT, name)
159 #define VARRAY_GENERIC_PTR_INIT(va, num, name) \
160 va = varray_init (num, VARRAY_DATA_GENERIC, name)
162 #define VARRAY_GENERIC_PTR_NOGC_INIT(va, num, name) \
163 va = varray_init (num, VARRAY_DATA_GENERIC_NOGC, name)
165 #define VARRAY_CHAR_PTR_INIT(va, num, name) \
166 va = varray_init (num, VARRAY_DATA_CPTR, name)
168 #define VARRAY_RTX_INIT(va, num, name) \
169 va = varray_init (num, VARRAY_DATA_RTX, name)
171 #define VARRAY_RTVEC_INIT(va, num, name) \
172 va = varray_init (num, VARRAY_DATA_RTVEC, name)
174 #define VARRAY_TREE_INIT(va, num, name) \
175 va = varray_init (num, VARRAY_DATA_TREE, name)
177 #define VARRAY_BITMAP_INIT(va, num, name) \
178 va = varray_init (num, VARRAY_DATA_BITMAP, name)
180 #define VARRAY_REG_INIT(va, num, name) \
181 va = varray_init (num, VARRAY_DATA_REG, name)
183 #define VARRAY_BB_INIT(va, num, name) \
184 va = varray_init (num, VARRAY_DATA_BB, name)
186 #define VARRAY_ELT_LIST_INIT(va, num, name) \
187 va = varray_init (num, VARRAY_DATA_TE, name)
189 #define VARRAY_EDGE_INIT(va, num, name) \
190 va = varray_init (num, VARRAY_DATA_EDGE, name)
192 #define VARRAY_TREE_PTR_INIT(va, num, name) \
193 va = varray_init (num, VARRAY_DATA_TREE_PTR, name)
195 /* Free up memory allocated by the virtual array, but do not free any of the
196 elements involved. */
197 #define VARRAY_FREE(vp) \
198 do { if (vp) { free (vp); vp = (varray_type) 0; } } while (0)
200 /* Grow/shrink the virtual array VA to N elements. */
201 extern varray_type varray_grow (varray_type, size_t);
203 #define VARRAY_GROW(VA, N) ((VA) = varray_grow (VA, N))
205 #define VARRAY_SIZE(VA) ((VA)->num_elements)
207 #define VARRAY_ACTIVE_SIZE(VA) ((VA)->elements_used)
208 #define VARRAY_POP_ALL(VA) ((VA)->elements_used = 0)
210 #define VARRAY_CLEAR(VA) varray_clear(VA)
212 extern void varray_clear (varray_type);
213 extern void dump_varray_statistics (void);
215 /* Check for VARRAY_xxx macros being in bound. */
216 #if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
217 extern void varray_check_failed (varray_type, size_t, const char *, int,
218 const char *) ATTRIBUTE_NORETURN;
219 extern void varray_underflow (varray_type, const char *, int, const char *)
220 ATTRIBUTE_NORETURN;
221 #define VARRAY_CHECK(VA, N, T) __extension__ \
222 (*({ varray_type const _va = (VA); \
223 const size_t _n = (N); \
224 if (_n >= _va->num_elements) \
225 varray_check_failed (_va, _n, __FILE__, __LINE__, __FUNCTION__); \
226 &_va->data.T[_n]; }))
228 #define VARRAY_POP(VA) do { \
229 varray_type const _va = (VA); \
230 if (_va->elements_used == 0) \
231 varray_underflow (_va, __FILE__, __LINE__, __FUNCTION__); \
232 else \
233 _va->elements_used--; \
234 } while (0)
236 #else
237 #define VARRAY_CHECK(VA, N, T) ((VA)->data.T[N])
238 /* Pop the top element of VA. */
239 #define VARRAY_POP(VA) do { ((VA)->elements_used--); } while (0)
240 #endif
242 /* Push X onto VA. T is the name of the field in varray_data
243 corresponding to the type of X. */
244 #define VARRAY_PUSH(VA, T, X) \
245 do \
247 if ((VA)->elements_used >= (VA)->num_elements) \
248 VARRAY_GROW ((VA), 2 * (VA)->num_elements); \
249 (VA)->data.T[(VA)->elements_used++] = (X); \
251 while (0)
253 #define VARRAY_CHAR(VA, N) VARRAY_CHECK (VA, N, vdt_c)
254 #define VARRAY_UCHAR(VA, N) VARRAY_CHECK (VA, N, vdt_uc)
255 #define VARRAY_SHORT(VA, N) VARRAY_CHECK (VA, N, vdt_s)
256 #define VARRAY_USHORT(VA, N) VARRAY_CHECK (VA, N, vdt_us)
257 #define VARRAY_INT(VA, N) VARRAY_CHECK (VA, N, vdt_i)
258 #define VARRAY_UINT(VA, N) VARRAY_CHECK (VA, N, vdt_u)
259 #define VARRAY_LONG(VA, N) VARRAY_CHECK (VA, N, vdt_l)
260 #define VARRAY_ULONG(VA, N) VARRAY_CHECK (VA, N, vdt_ul)
261 #define VARRAY_WIDE_INT(VA, N) VARRAY_CHECK (VA, N, vdt_hint)
262 #define VARRAY_UWIDE_INT(VA, N) VARRAY_CHECK (VA, N, vdt_uhint)
263 #define VARRAY_GENERIC_PTR(VA,N) VARRAY_CHECK (VA, N, vdt_generic)
264 #define VARRAY_GENERIC_PTR_NOGC(VA,N) VARRAY_CHECK (VA, N, vdt_generic_nogc)
265 #define VARRAY_CHAR_PTR(VA,N) VARRAY_CHECK (VA, N, vdt_cptr)
266 #define VARRAY_RTX(VA, N) VARRAY_CHECK (VA, N, vdt_rtx)
267 #define VARRAY_RTVEC(VA, N) VARRAY_CHECK (VA, N, vdt_rtvec)
268 #define VARRAY_TREE(VA, N) VARRAY_CHECK (VA, N, vdt_tree)
269 #define VARRAY_BITMAP(VA, N) VARRAY_CHECK (VA, N, vdt_bitmap)
270 #define VARRAY_REG(VA, N) VARRAY_CHECK (VA, N, vdt_reg)
271 #define VARRAY_BB(VA, N) VARRAY_CHECK (VA, N, vdt_bb)
272 #define VARRAY_ELT_LIST(VA, N) VARRAY_CHECK (VA, N, vdt_te)
273 #define VARRAY_EDGE(VA, N) VARRAY_CHECK (VA, N, vdt_e)
274 #define VARRAY_TREE_PTR(VA, N) VARRAY_CHECK (VA, N, vdt_tp)
276 /* Push a new element on the end of VA, extending it if necessary. */
277 #define VARRAY_PUSH_CHAR(VA, X) VARRAY_PUSH (VA, vdt_c, X)
278 #define VARRAY_PUSH_UCHAR(VA, X) VARRAY_PUSH (VA, vdt_uc, X)
279 #define VARRAY_PUSH_SHORT(VA, X) VARRAY_PUSH (VA, vdt_s, X)
280 #define VARRAY_PUSH_USHORT(VA, X) VARRAY_PUSH (VA, vdt_us, X)
281 #define VARRAY_PUSH_INT(VA, X) VARRAY_PUSH (VA, vdt_i, X)
282 #define VARRAY_PUSH_UINT(VA, X) VARRAY_PUSH (VA, vdt_u, X)
283 #define VARRAY_PUSH_LONG(VA, X) VARRAY_PUSH (VA, vdt_l, X)
284 #define VARRAY_PUSH_ULONG(VA, X) VARRAY_PUSH (VA, vdt_ul, X)
285 #define VARRAY_PUSH_WIDE_INT(VA, X) VARRAY_PUSH (VA, vdt_hint, X)
286 #define VARRAY_PUSH_UWIDE_INT(VA, X) VARRAY_PUSH (VA, vdt_uhint, X)
287 #define VARRAY_PUSH_GENERIC_PTR(VA, X) VARRAY_PUSH (VA, vdt_generic, X)
288 #define VARRAY_PUSH_GENERIC_PTR_NOGC(VA, X) VARRAY_PUSH (VA, vdt_generic_nogc, X)
289 #define VARRAY_PUSH_CHAR_PTR(VA, X) VARRAY_PUSH (VA, vdt_cptr, X)
290 #define VARRAY_PUSH_RTX(VA, X) VARRAY_PUSH (VA, vdt_rtx, X)
291 #define VARRAY_PUSH_RTVEC(VA, X) VARRAY_PUSH (VA, vdt_rtvec, X)
292 #define VARRAY_PUSH_TREE(VA, X) VARRAY_PUSH (VA, vdt_tree, X)
293 #define VARRAY_PUSH_BITMAP(VA, X) VARRAY_PUSH (VA, vdt_bitmap, X)
294 #define VARRAY_PUSH_REG(VA, X) VARRAY_PUSH (VA, vdt_reg, X)
295 #define VARRAY_PUSH_BB(VA, X) VARRAY_PUSH (VA, vdt_bb, X)
296 #define VARRAY_PUSH_EDGE(VA, X) VARRAY_PUSH (VA, vdt_e, X)
297 #define VARRAY_PUSH_TREE_PTR(VA, X) VARRAY_PUSH (VA, vdt_tp, X)
299 /* Return the last element of VA. */
300 #define VARRAY_TOP(VA, T) VARRAY_CHECK(VA, (VA)->elements_used - 1, T)
302 #define VARRAY_TOP_CHAR(VA) VARRAY_TOP (VA, vdt_c)
303 #define VARRAY_TOP_UCHAR(VA) VARRAY_TOP (VA, vdt_uc)
304 #define VARRAY_TOP_SHORT(VA) VARRAY_TOP (VA, vdt_s)
305 #define VARRAY_TOP_USHORT(VA) VARRAY_TOP (VA, vdt_us)
306 #define VARRAY_TOP_INT(VA) VARRAY_TOP (VA, vdt_i)
307 #define VARRAY_TOP_UINT(VA) VARRAY_TOP (VA, vdt_u)
308 #define VARRAY_TOP_LONG(VA) VARRAY_TOP (VA, vdt_l)
309 #define VARRAY_TOP_ULONG(VA) VARRAY_TOP (VA, vdt_ul)
310 #define VARRAY_TOP_WIDE_INT(VA) VARRAY_TOP (VA, vdt_hint)
311 #define VARRAY_TOP_UWIDE_INT(VA) VARRAY_TOP (VA, vdt_uhint)
312 #define VARRAY_TOP_GENERIC_PTR(VA) VARRAY_TOP (VA, vdt_generic)
313 #define VARRAY_TOP_GENERIC_PTR_NOGC(VA) VARRAY_TOP (VA, vdt_generic_nogc)
314 #define VARRAY_TOP_CHAR_PTR(VA) VARRAY_TOP (VA, vdt_cptr)
315 #define VARRAY_TOP_RTX(VA) VARRAY_TOP (VA, vdt_rtx)
316 #define VARRAY_TOP_RTVEC(VA) VARRAY_TOP (VA, vdt_rtvec)
317 #define VARRAY_TOP_TREE(VA) VARRAY_TOP (VA, vdt_tree)
318 #define VARRAY_TOP_BITMAP(VA) VARRAY_TOP (VA, vdt_bitmap)
319 #define VARRAY_TOP_REG(VA) VARRAY_TOP (VA, vdt_reg)
320 #define VARRAY_TOP_BB(VA) VARRAY_TOP (VA, vdt_bb)
321 #define VARRAY_TOP_EDGE(VA) VARRAY_TOP (VA, vdt_e)
322 #define VARRAY_TOP_TREE_PTR(VA) VARRAY_TOP (VA, vdt_tp)
324 #endif /* ! GCC_VARRAY_H */