]>
Commit | Line | Data |
---|---|---|
1 | /* Virtual array support. | |
2 | Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Solutions. | |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify it | |
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 | ||
12 | GNU CC is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to the Free | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #ifndef _VARRAY_H_ | |
23 | #define _VARRAY_H_ | |
24 | ||
25 | #ifndef HOST_WIDE_INT | |
26 | #include "machmode.h" | |
27 | #endif | |
28 | ||
29 | #ifndef __GCC_SYSTEM_H__ | |
30 | #include "system.h" | |
31 | #endif | |
32 | ||
33 | /* Auxiliary structure used inside the varray structure, used for | |
34 | function integration data. */ | |
35 | ||
36 | struct const_equiv_data { | |
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. */ | |
50 | struct rtx_def *rtx; | |
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 | ||
57 | /* Union of various array types that are used. */ | |
58 | typedef union varray_data_tag { | |
59 | char c[1]; | |
60 | unsigned char uc[1]; | |
61 | short s[1]; | |
62 | unsigned short us[1]; | |
63 | int i[1]; | |
64 | unsigned int u[1]; | |
65 | long l[1]; | |
66 | unsigned long ul[1]; | |
67 | HOST_WIDE_INT hint[1]; | |
68 | unsigned HOST_WIDE_INT uhint[1]; | |
69 | PTR generic[1]; | |
70 | char *cptr[1]; | |
71 | struct rtx_def *rtx[1]; | |
72 | struct rtvec_def *rtvec[1]; | |
73 | union tree_node *tree[1]; | |
74 | struct bitmap_head_def *bitmap[1]; | |
75 | struct sched_info_tag *sched[1]; | |
76 | struct reg_info_def *reg[1]; | |
77 | struct const_equiv_data const_equiv[1]; | |
78 | struct basic_block_def *bb[1]; | |
79 | struct elt_list *te[1]; | |
80 | } varray_data; | |
81 | ||
82 | /* Virtual array of pointers header. */ | |
83 | typedef struct varray_head_tag { | |
84 | size_t num_elements; /* maximum element number allocated */ | |
85 | size_t elements_used; /* the number of elements used, if | |
86 | using VARRAY_PUSH/VARRAY_POP. */ | |
87 | size_t element_size; /* size of each data element */ | |
88 | const char *name; /* name of the varray for reporting errors */ | |
89 | varray_data data; /* data elements follow, must be last */ | |
90 | } *varray_type; | |
91 | ||
92 | /* Allocate a virtual array with NUM elements, each of which is SIZE bytes | |
93 | long, named NAME. Array elements are zeroed. */ | |
94 | extern varray_type varray_init PARAMS ((size_t, size_t, const char *)); | |
95 | ||
96 | #define VARRAY_CHAR_INIT(va, num, name) \ | |
97 | va = varray_init (num, sizeof (char), name) | |
98 | ||
99 | #define VARRAY_UCHAR_INIT(va, num, name) \ | |
100 | va = varray_init (num, sizeof (unsigned char), name) | |
101 | ||
102 | #define VARRAY_SHORT_INIT(va, num, name) \ | |
103 | va = varray_init (num, sizeof (short), name) | |
104 | ||
105 | #define VARRAY_USHORT_INIT(va, num, name) \ | |
106 | va = varray_init (num, sizeof (unsigned short), name) | |
107 | ||
108 | #define VARRAY_INT_INIT(va, num, name) \ | |
109 | va = varray_init (num, sizeof (int), name) | |
110 | ||
111 | #define VARRAY_UINT_INIT(va, num, name) \ | |
112 | va = varray_init (num, sizeof (unsigned int), name) | |
113 | ||
114 | #define VARRAY_LONG_INIT(va, num, name) \ | |
115 | va = varray_init (num, sizeof (long), name) | |
116 | ||
117 | #define VARRAY_ULONG_INIT(va, num, name) \ | |
118 | va = varray_init (num, sizeof (unsigned long), name) | |
119 | ||
120 | #define VARRAY_WIDE_INT_INIT(va, num, name) \ | |
121 | va = varray_init (num, sizeof (HOST_WIDE_INT), name) | |
122 | ||
123 | #define VARRAY_UWIDE_INT_INIT(va, num, name) \ | |
124 | va = varray_init (num, sizeof (unsigned HOST_WIDE_INT), name) | |
125 | ||
126 | #define VARRAY_GENERIC_PTR_INIT(va, num, name) \ | |
127 | va = varray_init (num, sizeof (PTR), name) | |
128 | ||
129 | #define VARRAY_CHAR_PTR_INIT(va, num, name) \ | |
130 | va = varray_init (num, sizeof (char *), name) | |
131 | ||
132 | #define VARRAY_RTX_INIT(va, num, name) \ | |
133 | va = varray_init (num, sizeof (struct rtx_def *), name) | |
134 | ||
135 | #define VARRAY_RTVEC_INIT(va, num, name) \ | |
136 | va = varray_init (num, sizeof (struct rtvec_def), name) | |
137 | ||
138 | #define VARRAY_TREE_INIT(va, num, name) \ | |
139 | va = varray_init (num, sizeof (union tree_node *), name) | |
140 | ||
141 | #define VARRAY_BITMAP_INIT(va, num, name) \ | |
142 | va = varray_init (num, sizeof (struct bitmap_head_def *), name) | |
143 | ||
144 | #define VARRAY_SCHED_INIT(va, num, name) \ | |
145 | va = varray_init (num, sizeof (struct sched_info_tag *), name) | |
146 | ||
147 | #define VARRAY_REG_INIT(va, num, name) \ | |
148 | va = varray_init (num, sizeof (struct reg_info_def *), name) | |
149 | ||
150 | #define VARRAY_CONST_EQUIV_INIT(va, num, name) \ | |
151 | va = varray_init (num, sizeof (struct const_equiv_data), name) | |
152 | ||
153 | #define VARRAY_BB_INIT(va, num, name) \ | |
154 | va = varray_init (num, sizeof (struct basic_block_def *), name) | |
155 | ||
156 | #define VARRAY_ELT_LIST_INIT(va, num, name) \ | |
157 | va = varray_init (num, sizeof (struct elt_list *), name) | |
158 | ||
159 | /* Free up memory allocated by the virtual array, but do not free any of the | |
160 | elements involved. */ | |
161 | #define VARRAY_FREE(vp) \ | |
162 | do { if (vp) { free (vp); vp = (varray_type)0; } } while (0) | |
163 | ||
164 | /* Grow/shrink the virtual array VA to N elements. */ | |
165 | extern varray_type varray_grow PARAMS ((varray_type, size_t)); | |
166 | ||
167 | #define VARRAY_GROW(VA, N) ((VA) = varray_grow (VA, N)) | |
168 | ||
169 | #define VARRAY_SIZE(VA) ((VA)->num_elements) | |
170 | ||
171 | /* Check for VARRAY_xxx macros being in bound. */ | |
172 | #if defined ENABLE_CHECKING && (GCC_VERSION >= 2007) | |
173 | extern void varray_check_failed PARAMS ((varray_type, size_t, | |
174 | const char *, int, | |
175 | const char *)) ATTRIBUTE_NORETURN; | |
176 | #define VARRAY_CHECK(VA, N, T) \ | |
177 | (*({ varray_type _va = VA; \ | |
178 | size_t _n = N; \ | |
179 | if (_n >= _va->num_elements) \ | |
180 | varray_check_failed (_va, _n, __FILE__, __LINE__, \ | |
181 | __PRETTY_FUNCTION__); \ | |
182 | &_va->data.T[_n]; })) | |
183 | #else | |
184 | #define VARRAY_CHECK(VA, N, T) ((VA)->data.T[N]) | |
185 | #endif | |
186 | ||
187 | /* Push X onto VA. T is the name of the field in varray_data | |
188 | corresponding to the type of X. */ | |
189 | #define VARRAY_PUSH(VA, T, X) \ | |
190 | do \ | |
191 | { \ | |
192 | if ((VA)->elements_used >= (VA)->num_elements) \ | |
193 | VARRAY_GROW ((VA), 2 * (VA)->num_elements); \ | |
194 | (VA)->data.T[(VA)->elements_used++] = (X); \ | |
195 | } \ | |
196 | while (0) | |
197 | ||
198 | /* Pop the top element of VA. */ | |
199 | #define VARRAY_POP(VA) \ | |
200 | ((VA)->elements_used--) | |
201 | ||
202 | /* Return the top element of VA. */ | |
203 | #define VARRAY_TOP(VA, T) \ | |
204 | ((VA)->data.T[(VA)->elements_used - 1]) | |
205 | ||
206 | #define VARRAY_CHAR(VA, N) VARRAY_CHECK (VA, N, c) | |
207 | #define VARRAY_UCHAR(VA, N) VARRAY_CHECK (VA, N, uc) | |
208 | #define VARRAY_SHORT(VA, N) VARRAY_CHECK (VA, N, s) | |
209 | #define VARRAY_USHORT(VA, N) VARRAY_CHECK (VA, N, us) | |
210 | #define VARRAY_INT(VA, N) VARRAY_CHECK (VA, N, i) | |
211 | #define VARRAY_UINT(VA, N) VARRAY_CHECK (VA, N, u) | |
212 | #define VARRAY_LONG(VA, N) VARRAY_CHECK (VA, N, l) | |
213 | #define VARRAY_ULONG(VA, N) VARRAY_CHECK (VA, N, ul) | |
214 | #define VARRAY_WIDE_INT(VA, N) VARRAY_CHECK (VA, N, hint) | |
215 | #define VARRAY_UWIDE_INT(VA, N) VARRAY_CHECK (VA, N, uhint) | |
216 | #define VARRAY_GENERIC_PTR(VA,N) VARRAY_CHECK (VA, N, generic) | |
217 | #define VARRAY_CHAR_PTR(VA,N) VARRAY_CHECK (VA, N, cptr) | |
218 | #define VARRAY_RTX(VA, N) VARRAY_CHECK (VA, N, rtx) | |
219 | #define VARRAY_RTVEC(VA, N) VARRAY_CHECK (VA, N, rtvec) | |
220 | #define VARRAY_TREE(VA, N) VARRAY_CHECK (VA, N, tree) | |
221 | #define VARRAY_BITMAP(VA, N) VARRAY_CHECK (VA, N, bitmap) | |
222 | #define VARRAY_SCHED(VA, N) VARRAY_CHECK (VA, N, sched) | |
223 | #define VARRAY_REG(VA, N) VARRAY_CHECK (VA, N, reg) | |
224 | #define VARRAY_CONST_EQUIV(VA, N) VARRAY_CHECK (VA, N, const_equiv) | |
225 | #define VARRAY_BB(VA, N) VARRAY_CHECK (VA, N, bb) | |
226 | #define VARRAY_ELT_LIST(VA, N) VARRAY_CHECK (VA, N, te) | |
227 | ||
228 | /* Push a new element on the end of VA, extending it if necessary. */ | |
229 | #define VARRAY_PUSH_CHAR(VA, X) VARRAY_PUSH (VA, c, X) | |
230 | #define VARRAY_PUSH_UCHAR(VA, X) VARRAY_PUSH (VA, uc, X) | |
231 | #define VARRAY_PUSH_SHORT(VA, X) VARRAY_PUSH (VA, s, X) | |
232 | #define VARRAY_PUSH_USHORT(VA, X) VARRAY_PUSH (VA, us, X) | |
233 | #define VARRAY_PUSH_INT(VA, X) VARRAY_PUSH (VA, i, X) | |
234 | #define VARRAY_PUSH_UINT(VA, X) VARRAY_PUSH (VA, u, X) | |
235 | #define VARRAY_PUSH_LONG(VA, X) VARRAY_PUSH (VA, l, X) | |
236 | #define VARRAY_PUSH_ULONG(VA, X) VARRAY_PUSH (VA, ul, X) | |
237 | #define VARRAY_PUSH_WIDE_INT(VA, X) VARRAY_PUSH (VA, hint, X) | |
238 | #define VARRAY_PUSH_UWIDE_INT(VA, X) VARRAY_PUSH (VA, uhint, X) | |
239 | #define VARRAY_PUSH_GENERIC_PTR(VA,N) VARRAY_PUSH (VA, generic, X) | |
240 | #define VARRAY_PUSH_CHAR_PTR(VA,N) VARRAY_PUSH (VA, cptr, X) | |
241 | #define VARRAY_PUSH_RTX(VA, X) VARRAY_PUSH (VA, rtx, X) | |
242 | #define VARRAY_PUSH_RTVEC(VA, X) VARRAY_PUSH (VA, rtvec, X) | |
243 | #define VARRAY_PUSH_TREE(VA, X) VARRAY_PUSH (VA, tree, X) | |
244 | #define VARRAY_PUSH_BITMAP(VA, X) VARRAY_PUSH (VA, bitmap, X) | |
245 | #define VARRAY_PUSH_SCHED(VA, X) VARRAY_PUSH (VA, sched, X) | |
246 | #define VARRAY_PUSH_REG(VA, X) VARRAY_PUSH (VA, reg, X) | |
247 | #define VARRAY_PUSH_CONST_EQUIV(VA, X) VARRAY_PUSH (VA, const_equiv, X) | |
248 | #define VARRAY_PUSH_BB(VA, X) VARRAY_PUSH (VA, bb, X) | |
249 | ||
250 | /* Return the last element of VA. */ | |
251 | #define VARRAY_TOP_CHAR(VA) VARRAY_TOP (VA, c) | |
252 | #define VARRAY_TOP_UCHAR(VA) VARRAY_TOP (VA, uc) | |
253 | #define VARRAY_TOP_SHORT(VA) VARRAY_TOP (VA, s) | |
254 | #define VARRAY_TOP_USHORT(VA) VARRAY_TOP (VA, us) | |
255 | #define VARRAY_TOP_INT(VA) VARRAY_TOP (VA, i) | |
256 | #define VARRAY_TOP_UINT(VA) VARRAY_TOP (VA, u) | |
257 | #define VARRAY_TOP_LONG(VA) VARRAY_TOP (VA, l) | |
258 | #define VARRAY_TOP_ULONG(VA) VARRAY_TOP (VA, ul) | |
259 | #define VARRAY_TOP_WIDE_INT(VA) VARRAY_TOP (VA, hint) | |
260 | #define VARRAY_TOP_UWIDE_INT(VA) VARRAY_TOP (VA, uhint) | |
261 | #define VARRAY_TOP_GENERIC_PTR(VA,N) VARRAY_TOP (VA, generic) | |
262 | #define VARRAY_TOP_CHAR_PTR(VA,N) VARRAY_TOP (VA, cptr) | |
263 | #define VARRAY_TOP_RTX(VA) VARRAY_TOP (VA, rtx) | |
264 | #define VARRAY_TOP_RTVEC(VA) VARRAY_TOP (VA, rtvec) | |
265 | #define VARRAY_TOP_TREE(VA) VARRAY_TOP (VA, tree) | |
266 | #define VARRAY_TOP_BITMAP(VA) VARRAY_TOP (VA, bitmap) | |
267 | #define VARRAY_TOP_SCHED(VA) VARRAY_TOP (VA, sched) | |
268 | #define VARRAY_TOP_REG(VA) VARRAY_TOP (VA, reg) | |
269 | #define VARRAY_TOP_CONST_EQUIV(VA) VARRAY_TOP (VA, const_equiv) | |
270 | #define VARRAY_TOP_BB(VA) VARRAY_TOP (VA, bb) | |
271 | ||
272 | #endif /* _VARRAY_H_ */ |