]> gcc.gnu.org Git - gcc.git/blame - gcc/ggc-common.c
Add missing ChangeLog entry
[gcc.git] / gcc / ggc-common.c
CommitLineData
b49a6a90 1/* Simple garbage collection for the GNU compiler.
a611912f 2 Copyright (C) 1999 Free Software Foundation, Inc.
b49a6a90
AS
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21/* Generic garbage collection (GC) functions and data, not specific to
22 any particular GC implementation. */
23
24#include "config.h"
25#include "system.h"
26#include "ggc.h"
27#include "hash.h"
28#include "rtl.h"
29#include "tree.h"
30#include "varray.h"
31
32
33/* Maintain global roots that are preserved during GC. */
34
35struct ggc_root *roots;
36
37/* Type-correct function to pass to ggc_add_root. It just forwards
38 *ELT (which is an rtx) to ggc_mark_tree_varray. */
39
40static void
41ggc_mark_rtx_ptr (elt)
42 void *elt;
43{
44 ggc_mark_rtx (*(rtx *)elt);
45}
46
47/* Type-correct function to pass to ggc_add_root. It just forwards
48 *ELT (which is a tree) to ggc_mark_tree. */
49
50static void
51ggc_mark_tree_ptr (elt)
52 void *elt;
53{
54 ggc_mark_tree (*(tree *)elt);
55}
56
57/* Type-correct function to pass to ggc_add_root. It just forwards
58 ELT (which is really a varray_type *) to ggc_mark_tree_varray. */
59
60static void
61ggc_mark_tree_varray_ptr (elt)
62 void *elt;
63{
64 ggc_mark_tree_varray (*(varray_type *)elt);
65}
66
67/* Type-correct function to pass to ggc_add_root. It just forwards
68 ELT (which is really a struct hash_table **) to
69 ggc_mark_tree_hash_table. */
70
71static void
72ggc_mark_tree_hash_table_ptr (elt)
73 void *elt;
74{
75 ggc_mark_tree_hash_table (*(struct hash_table **) elt);
76}
77
78static void
79ggc_mark_string_ptr (elt)
80 void *elt;
81{
82 ggc_mark_string (*(char **)elt);
83}
84
85void
86ggc_add_root (base, nelt, size, cb)
87 void *base;
88 int nelt, size;
89 void (*cb) PROTO ((void *));
90{
91 struct ggc_root *x = (struct ggc_root *) xmalloc (sizeof (*x));
92
93 x->next = roots;
94 x->base = base;
95 x->nelt = nelt;
96 x->size = size;
97 x->cb = cb;
98
99 roots = x;
100}
101
102void
103ggc_add_rtx_root (base, nelt)
104 rtx *base;
105 int nelt;
106{
107 ggc_add_root (base, nelt, sizeof(rtx), ggc_mark_rtx_ptr);
108}
109
110void
111ggc_add_tree_root (base, nelt)
112 tree *base;
113 int nelt;
114{
115 ggc_add_root (base, nelt, sizeof(tree), ggc_mark_tree_ptr);
116}
117
118/* Add V (a varray full of trees) to the list of GC roots. */
119
120void
121ggc_add_tree_varray_root (base, nelt)
122 varray_type *base;
123 int nelt;
124{
125 ggc_add_root (base, nelt, sizeof (varray_type),
126 ggc_mark_tree_varray_ptr);
127}
128
129/* Add HT (a hash-table where ever key is a tree) to the list of GC
130 roots. */
131
132void
133ggc_add_tree_hash_table_root (base, nelt)
134 struct hash_table **base;
135 int nelt;
136{
137 ggc_add_root (base, nelt, sizeof (struct hash_table *),
138 ggc_mark_tree_hash_table_ptr);
139}
140
141void
142ggc_add_string_root (base, nelt)
143 char **base;
144 int nelt;
145{
146 ggc_add_root (base, nelt, sizeof (char *), ggc_mark_string_ptr);
147}
148
149
150void
151ggc_del_root (base)
152 void *base;
153{
154 struct ggc_root *x, **p;
155
156 p = &roots, x = roots;
157 while (x)
158 {
159 if (x->base == base)
160 {
161 *p = x->next;
162 free (x);
163 return;
164 }
165 p = &x->next;
166 x = x->next;
167 }
168
169 abort();
170}
171
172void
173ggc_mark_rtx (r)
174 rtx r;
175{
176 const char *fmt;
177 int i;
178
179 if (r == NULL_RTX || ggc_set_mark_rtx (r))
180 return;
181
182 /* ??? If (some of) these are really pass-dependant info, do we have
183 any right poking our noses in? */
184 switch (GET_CODE (r))
185 {
186 case JUMP_INSN:
187 ggc_mark_rtx (JUMP_LABEL (r));
188 break;
189 case CODE_LABEL:
190 ggc_mark_rtx (LABEL_REFS (r));
191 break;
192 case LABEL_REF:
193 ggc_mark_rtx (LABEL_NEXTREF (r));
194 ggc_mark_rtx (CONTAINING_INSN (r));
195 break;
196 case ADDRESSOF:
197 ggc_mark_tree (ADDRESSOF_DECL (r));
198 break;
199 case CONST_DOUBLE:
200 ggc_mark_rtx (CONST_DOUBLE_CHAIN (r));
201 break;
202 case NOTE:
203 switch (NOTE_LINE_NUMBER (r))
204 {
205 case NOTE_INSN_RANGE_START:
206 case NOTE_INSN_RANGE_END:
207 case NOTE_INSN_LIVE:
208 ggc_mark_rtx (NOTE_RANGE_INFO (r));
209 break;
210
1a4450c7
MM
211 case NOTE_INSN_BLOCK_BEG:
212 case NOTE_INSN_BLOCK_END:
213 ggc_mark_tree (NOTE_BLOCK (r));
214 break;
215
b49a6a90
AS
216 default:
217 if (NOTE_LINE_NUMBER (r) >= 0)
218 ggc_mark_string (NOTE_SOURCE_FILE (r));
219 break;
220 }
221 break;
222
223 default:
224 break;
225 }
226
227 for (fmt = GET_RTX_FORMAT (GET_CODE (r)), i = 0; *fmt ; ++fmt, ++i)
228 {
229 switch (*fmt)
230 {
231 case 'e': case 'u':
232 ggc_mark_rtx (XEXP (r, i));
233 break;
234 case 'V': case 'E':
235 ggc_mark_rtvec (XVEC (r, i));
236 break;
237 case 'S': case 's':
238 ggc_mark_string (XSTR (r, i));
239 break;
240 }
241 }
242}
243
244void
245ggc_mark_rtvec (v)
246 rtvec v;
247{
248 int i;
249
250 if (v == NULL || ggc_set_mark_rtvec (v))
251 return;
252
253 i = GET_NUM_ELEM (v);
254 while (--i >= 0)
255 ggc_mark_rtx (RTVEC_ELT (v, i));
256}
257
258void
259ggc_mark_tree (t)
260 tree t;
261{
262 /* FIXME what if t == NULL_TREE ? */
263 if (t == NULL || ggc_set_mark_tree (t))
264 return;
265
266 /* Bits from common. */
267 ggc_mark_tree (TREE_TYPE (t));
268 ggc_mark_tree (TREE_CHAIN (t));
269
270 /* Some nodes require special handling. */
271 switch (TREE_CODE (t))
272 {
273 case TREE_LIST:
274 ggc_mark_tree (TREE_PURPOSE (t));
275 ggc_mark_tree (TREE_VALUE (t));
276 return;
277
278 case TREE_VEC:
279 {
280 int i = TREE_VEC_LENGTH (t);
281 while (--i >= 0)
282 ggc_mark_tree (TREE_VEC_ELT (t, i));
283 return;
284 }
285
286 case SAVE_EXPR:
287 ggc_mark_tree (TREE_OPERAND (t, 0));
288 ggc_mark_tree (SAVE_EXPR_CONTEXT (t));
289 ggc_mark_rtx (SAVE_EXPR_RTL (t));
290 return;
291
292 case RTL_EXPR:
293 ggc_mark_rtx (RTL_EXPR_SEQUENCE (t));
294 ggc_mark_rtx (RTL_EXPR_RTL (t));
295 return;
296
297 case CALL_EXPR:
298 ggc_mark_tree (TREE_OPERAND (t, 0));
299 ggc_mark_tree (TREE_OPERAND (t, 1));
300 ggc_mark_rtx (CALL_EXPR_RTL (t));
301 return;
302
303 case COMPLEX_CST:
304 ggc_mark_tree (TREE_REALPART (t));
305 ggc_mark_tree (TREE_IMAGPART (t));
306 break;
307
308 case STRING_CST:
309 ggc_mark_string (TREE_STRING_POINTER (t));
310 break;
311
312 case PARM_DECL:
313 ggc_mark_rtx (DECL_INCOMING_RTL (t));
314 break;
315
316 case IDENTIFIER_NODE:
317 ggc_mark_string (IDENTIFIER_POINTER (t));
318 lang_mark_tree (t);
319 return;
320
321 default:
322 break;
323 }
324
325 /* But in general we can handle them by class. */
326 switch (TREE_CODE_CLASS (TREE_CODE (t)))
327 {
328 case 'd': /* A decl node. */
4d9452a1 329 ggc_mark_string (DECL_SOURCE_FILE (t));
b49a6a90
AS
330 ggc_mark_tree (DECL_SIZE (t));
331 ggc_mark_tree (DECL_NAME (t));
332 ggc_mark_tree (DECL_CONTEXT (t));
333 ggc_mark_tree (DECL_ARGUMENTS (t));
334 ggc_mark_tree (DECL_RESULT (t));
335 ggc_mark_tree (DECL_INITIAL (t));
336 ggc_mark_tree (DECL_ABSTRACT_ORIGIN (t));
337 ggc_mark_tree (DECL_ASSEMBLER_NAME (t));
338 ggc_mark_tree (DECL_SECTION_NAME (t));
339 ggc_mark_tree (DECL_MACHINE_ATTRIBUTES (t));
340 ggc_mark_rtx (DECL_RTL (t));
4d9452a1 341 ggc_mark_rtx (DECL_LIVE_RANGE_RTL (t));
b49a6a90
AS
342 ggc_mark_tree (DECL_VINDEX (t));
343 lang_mark_tree (t);
344 break;
345
346 case 't': /* A type node. */
347 ggc_mark_tree (TYPE_SIZE (t));
348 ggc_mark_tree (TYPE_SIZE_UNIT (t));
349 ggc_mark_tree (TYPE_ATTRIBUTES (t));
350 ggc_mark_tree (TYPE_VALUES (t));
351 ggc_mark_tree (TYPE_POINTER_TO (t));
352 ggc_mark_tree (TYPE_REFERENCE_TO (t));
353 ggc_mark_tree (TYPE_NAME (t));
354 ggc_mark_tree (TYPE_MIN_VALUE (t));
355 ggc_mark_tree (TYPE_MAX_VALUE (t));
356 ggc_mark_tree (TYPE_NEXT_VARIANT (t));
357 ggc_mark_tree (TYPE_MAIN_VARIANT (t));
358 ggc_mark_tree (TYPE_BINFO (t));
359 ggc_mark_tree (TYPE_NONCOPIED_PARTS (t));
360 ggc_mark_tree (TYPE_CONTEXT (t));
361 lang_mark_tree (t);
362 break;
363
364 case 'b': /* A lexical block. */
365 ggc_mark_tree (BLOCK_VARS (t));
366 ggc_mark_tree (BLOCK_TYPE_TAGS (t));
367 ggc_mark_tree (BLOCK_SUBBLOCKS (t));
368 ggc_mark_tree (BLOCK_SUPERCONTEXT (t));
369 ggc_mark_tree (BLOCK_ABSTRACT_ORIGIN (t));
370 ggc_mark_rtx (BLOCK_END_NOTE (t));
371 break;
372
373 case 'c': /* A constant. */
374 ggc_mark_rtx (TREE_CST_RTL (t));
375 break;
376
377 case 'r': case '<': case '1':
378 case '2': case 'e': case 's': /* Expressions. */
379 {
380 int i = tree_code_length[TREE_CODE (t)];
381 while (--i >= 0)
382 ggc_mark_tree (TREE_OPERAND (t, i));
383 break;
384 }
385
386 case 'x':
387 lang_mark_tree (t);
388 break;
389 }
390}
391
392/* Mark all the elements of the varray V, which contains trees. */
393
394void
395ggc_mark_tree_varray (v)
396 varray_type v;
397{
398 int i;
399
400 if (v)
401 for (i = v->num_elements - 1; i >= 0; --i)
402 ggc_mark_tree (VARRAY_TREE (v, i));
403}
404
405/* Mark the hash table-entry HE. It's key field is really a tree. */
406
407static boolean
408ggc_mark_tree_hash_table_entry (he, k)
409 struct hash_entry *he;
410 hash_table_key k ATTRIBUTE_UNUSED;
411{
412 ggc_mark_tree ((tree) he->key);
413 return true;
414}
415
416/* Mark all the elements of the hash-table H, which contains trees. */
417
418void
419ggc_mark_tree_hash_table (ht)
420 struct hash_table *ht;
421{
422 hash_traverse (ht, ggc_mark_tree_hash_table_entry, /*info=*/0);
423}
424
This page took 0.074753 seconds and 5 git commands to generate.