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