1 /* Simple garbage collection for the GNU compiler.
2 Copyright (C) 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
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. */
21 /* Generic garbage collection (GC) functions and data, not specific to
22 any particular GC implementation. */
33 /* Maintain global roots that are preserved during GC. */
35 /* Global roots that are preserved during calls to gc. */
39 struct ggc_root *next;
43 void (*cb) PROTO ((void *));
46 static struct ggc_root *roots;
48 /* Type-correct function to pass to ggc_add_root. It just forwards
49 *ELT (which is an rtx) to ggc_mark_tree_varray. */
52 ggc_mark_rtx_ptr (elt)
55 ggc_mark_rtx (*(rtx *)elt);
58 /* Type-correct function to pass to ggc_add_root. It just forwards
59 *ELT (which is a tree) to ggc_mark_tree. */
62 ggc_mark_tree_ptr (elt)
65 ggc_mark_tree (*(tree *)elt);
68 /* Type-correct function to pass to ggc_add_root. It just forwards
69 ELT (which is really a varray_type *) to ggc_mark_tree_varray. */
72 ggc_mark_tree_varray_ptr (elt)
75 ggc_mark_tree_varray (*(varray_type *)elt);
78 /* Type-correct function to pass to ggc_add_root. It just forwards
79 ELT (which is really a struct hash_table **) to
80 ggc_mark_tree_hash_table. */
83 ggc_mark_tree_hash_table_ptr (elt)
86 ggc_mark_tree_hash_table (*(struct hash_table **) elt);
90 ggc_mark_string_ptr (elt)
93 ggc_mark_string (*(char **)elt);
97 ggc_add_root (base, nelt, size, cb)
100 void (*cb) PROTO ((void *));
102 struct ggc_root *x = (struct ggc_root *) xmalloc (sizeof (*x));
114 ggc_add_rtx_root (base, nelt)
118 ggc_add_root (base, nelt, sizeof(rtx), ggc_mark_rtx_ptr);
122 ggc_add_tree_root (base, nelt)
126 ggc_add_root (base, nelt, sizeof(tree), ggc_mark_tree_ptr);
129 /* Add V (a varray full of trees) to the list of GC roots. */
132 ggc_add_tree_varray_root (base, nelt)
136 ggc_add_root (base, nelt, sizeof (varray_type),
137 ggc_mark_tree_varray_ptr);
140 /* Add HT (a hash-table where ever key is a tree) to the list of GC
144 ggc_add_tree_hash_table_root (base, nelt)
145 struct hash_table **base;
148 ggc_add_root (base, nelt, sizeof (struct hash_table *),
149 ggc_mark_tree_hash_table_ptr);
153 ggc_add_string_root (base, nelt)
157 ggc_add_root (base, nelt, sizeof (char *), ggc_mark_string_ptr);
165 struct ggc_root *x, **p;
167 p = &roots, x = roots;
188 for (x = roots; x != NULL; x = x->next)
191 int s = x->size, n = x->nelt;
192 void (*cb) PROTO ((void *)) = x->cb;
195 for (i = 0; i < n; ++i, elt += s)
201 ggc_mark_rtx_children (r)
207 /* ??? If (some of) these are really pass-dependant info, do we have
208 any right poking our noses in? */
209 switch (GET_CODE (r))
212 ggc_mark_rtx (JUMP_LABEL (r));
215 ggc_mark_rtx (LABEL_REFS (r));
218 ggc_mark_rtx (LABEL_NEXTREF (r));
219 ggc_mark_rtx (CONTAINING_INSN (r));
222 ggc_mark_tree (ADDRESSOF_DECL (r));
225 ggc_mark_rtx (CONST_DOUBLE_CHAIN (r));
228 switch (NOTE_LINE_NUMBER (r))
230 case NOTE_INSN_RANGE_START:
231 case NOTE_INSN_RANGE_END:
233 ggc_mark_rtx (NOTE_RANGE_INFO (r));
236 case NOTE_INSN_BLOCK_BEG:
237 case NOTE_INSN_BLOCK_END:
238 ggc_mark_tree (NOTE_BLOCK (r));
242 if (NOTE_LINE_NUMBER (r) >= 0)
243 ggc_mark_string (NOTE_SOURCE_FILE (r));
252 for (fmt = GET_RTX_FORMAT (GET_CODE (r)), i = 0; *fmt ; ++fmt, ++i)
257 ggc_mark_rtx (XEXP (r, i));
260 ggc_mark_rtvec (XVEC (r, i));
263 ggc_mark_string (XSTR (r, i));
275 if (v == NULL || ggc_set_mark_rtvec (v))
278 i = GET_NUM_ELEM (v);
280 ggc_mark_rtx (RTVEC_ELT (v, i));
284 ggc_mark_tree_children (t)
287 /* Bits from common. */
288 ggc_mark_tree (TREE_TYPE (t));
289 ggc_mark_tree (TREE_CHAIN (t));
291 /* Some nodes require special handling. */
292 switch (TREE_CODE (t))
295 ggc_mark_tree (TREE_PURPOSE (t));
296 ggc_mark_tree (TREE_VALUE (t));
301 int i = TREE_VEC_LENGTH (t);
303 ggc_mark_tree (TREE_VEC_ELT (t, i));
308 ggc_mark_tree (TREE_OPERAND (t, 0));
309 ggc_mark_tree (SAVE_EXPR_CONTEXT (t));
310 ggc_mark_rtx (SAVE_EXPR_RTL (t));
314 ggc_mark_rtx (RTL_EXPR_SEQUENCE (t));
315 ggc_mark_rtx (RTL_EXPR_RTL (t));
319 ggc_mark_tree (TREE_OPERAND (t, 0));
320 ggc_mark_tree (TREE_OPERAND (t, 1));
321 ggc_mark_rtx (CALL_EXPR_RTL (t));
325 ggc_mark_tree (TREE_REALPART (t));
326 ggc_mark_tree (TREE_IMAGPART (t));
330 ggc_mark_string (TREE_STRING_POINTER (t));
334 ggc_mark_rtx (DECL_INCOMING_RTL (t));
337 case IDENTIFIER_NODE:
338 ggc_mark_string (IDENTIFIER_POINTER (t));
346 /* But in general we can handle them by class. */
347 switch (TREE_CODE_CLASS (TREE_CODE (t)))
349 case 'd': /* A decl node. */
350 ggc_mark_string (DECL_SOURCE_FILE (t));
351 ggc_mark_tree (DECL_SIZE (t));
352 ggc_mark_tree (DECL_NAME (t));
353 ggc_mark_tree (DECL_CONTEXT (t));
354 ggc_mark_tree (DECL_ARGUMENTS (t));
355 ggc_mark_tree (DECL_RESULT (t));
356 ggc_mark_tree (DECL_INITIAL (t));
357 ggc_mark_tree (DECL_ABSTRACT_ORIGIN (t));
358 ggc_mark_tree (DECL_ASSEMBLER_NAME (t));
359 ggc_mark_tree (DECL_SECTION_NAME (t));
360 ggc_mark_tree (DECL_MACHINE_ATTRIBUTES (t));
361 ggc_mark_rtx (DECL_RTL (t));
362 ggc_mark_rtx (DECL_LIVE_RANGE_RTL (t));
363 ggc_mark_tree (DECL_VINDEX (t));
367 case 't': /* A type node. */
368 ggc_mark_tree (TYPE_SIZE (t));
369 ggc_mark_tree (TYPE_SIZE_UNIT (t));
370 ggc_mark_tree (TYPE_ATTRIBUTES (t));
371 ggc_mark_tree (TYPE_VALUES (t));
372 ggc_mark_tree (TYPE_POINTER_TO (t));
373 ggc_mark_tree (TYPE_REFERENCE_TO (t));
374 ggc_mark_tree (TYPE_NAME (t));
375 ggc_mark_tree (TYPE_MIN_VALUE (t));
376 ggc_mark_tree (TYPE_MAX_VALUE (t));
377 ggc_mark_tree (TYPE_NEXT_VARIANT (t));
378 ggc_mark_tree (TYPE_MAIN_VARIANT (t));
379 ggc_mark_tree (TYPE_BINFO (t));
380 ggc_mark_tree (TYPE_NONCOPIED_PARTS (t));
381 ggc_mark_tree (TYPE_CONTEXT (t));
385 case 'b': /* A lexical block. */
386 ggc_mark_tree (BLOCK_VARS (t));
387 ggc_mark_tree (BLOCK_TYPE_TAGS (t));
388 ggc_mark_tree (BLOCK_SUBBLOCKS (t));
389 ggc_mark_tree (BLOCK_SUPERCONTEXT (t));
390 ggc_mark_tree (BLOCK_ABSTRACT_ORIGIN (t));
391 ggc_mark_rtx (BLOCK_END_NOTE (t));
394 case 'c': /* A constant. */
395 ggc_mark_rtx (TREE_CST_RTL (t));
398 case 'r': case '<': case '1':
399 case '2': case 'e': case 's': /* Expressions. */
401 int i = tree_code_length[TREE_CODE (t)];
403 ggc_mark_tree (TREE_OPERAND (t, i));
413 /* Mark all the elements of the varray V, which contains trees. */
416 ggc_mark_tree_varray (v)
422 for (i = v->num_elements - 1; i >= 0; --i)
423 ggc_mark_tree (VARRAY_TREE (v, i));
426 /* Mark the hash table-entry HE. It's key field is really a tree. */
429 ggc_mark_tree_hash_table_entry (he, k)
430 struct hash_entry *he;
431 hash_table_key k ATTRIBUTE_UNUSED;
433 ggc_mark_tree ((tree) he->key);
437 /* Mark all the elements of the hash-table H, which contains trees. */
440 ggc_mark_tree_hash_table (ht)
441 struct hash_table *ht;
443 hash_traverse (ht, ggc_mark_tree_hash_table_entry, /*info=*/0);