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 static void ggc_mark_rtx_ptr PARAMS ((void *));
34 static void ggc_mark_tree_ptr PARAMS ((void *));
35 static void ggc_mark_tree_varray_ptr PARAMS ((void *));
36 static void ggc_mark_tree_hash_table_ptr PARAMS ((void *));
37 static void ggc_mark_string_ptr PARAMS ((void *));
38 static boolean ggc_mark_tree_hash_table_entry PARAMS ((struct hash_entry *,
41 /* Maintain global roots that are preserved during GC. */
43 /* Global roots that are preserved during calls to gc. */
47 struct ggc_root *next;
51 void (*cb) PROTO ((void *));
54 static struct ggc_root *roots;
56 /* Type-correct function to pass to ggc_add_root. It just forwards
57 *ELT (which is an rtx) to ggc_mark_tree_varray. */
60 ggc_mark_rtx_ptr (elt)
63 ggc_mark_rtx (*(rtx *)elt);
66 /* Type-correct function to pass to ggc_add_root. It just forwards
67 *ELT (which is a tree) to ggc_mark_tree. */
70 ggc_mark_tree_ptr (elt)
73 ggc_mark_tree (*(tree *)elt);
76 /* Type-correct function to pass to ggc_add_root. It just forwards
77 ELT (which is really a varray_type *) to ggc_mark_tree_varray. */
80 ggc_mark_tree_varray_ptr (elt)
83 ggc_mark_tree_varray (*(varray_type *)elt);
86 /* Type-correct function to pass to ggc_add_root. It just forwards
87 ELT (which is really a struct hash_table **) to
88 ggc_mark_tree_hash_table. */
91 ggc_mark_tree_hash_table_ptr (elt)
94 ggc_mark_tree_hash_table (*(struct hash_table **) elt);
98 ggc_mark_string_ptr (elt)
101 ggc_mark_string (*(char **)elt);
105 ggc_add_root (base, nelt, size, cb)
108 void (*cb) PROTO ((void *));
110 struct ggc_root *x = (struct ggc_root *) xmalloc (sizeof (*x));
122 ggc_add_rtx_root (base, nelt)
126 ggc_add_root (base, nelt, sizeof(rtx), ggc_mark_rtx_ptr);
130 ggc_add_tree_root (base, nelt)
134 ggc_add_root (base, nelt, sizeof(tree), ggc_mark_tree_ptr);
137 /* Add V (a varray full of trees) to the list of GC roots. */
140 ggc_add_tree_varray_root (base, nelt)
144 ggc_add_root (base, nelt, sizeof (varray_type),
145 ggc_mark_tree_varray_ptr);
148 /* Add HT (a hash-table where ever key is a tree) to the list of GC
152 ggc_add_tree_hash_table_root (base, nelt)
153 struct hash_table **base;
156 ggc_add_root (base, nelt, sizeof (struct hash_table *),
157 ggc_mark_tree_hash_table_ptr);
161 ggc_add_string_root (base, nelt)
165 ggc_add_root (base, nelt, sizeof (char *), ggc_mark_string_ptr);
173 struct ggc_root *x, **p;
175 p = &roots, x = roots;
196 for (x = roots; x != NULL; x = x->next)
199 int s = x->size, n = x->nelt;
200 void (*cb) PROTO ((void *)) = x->cb;
203 for (i = 0; i < n; ++i, elt += s)
209 ggc_mark_rtx_children (r)
215 /* ??? If (some of) these are really pass-dependant info, do we have
216 any right poking our noses in? */
217 switch (GET_CODE (r))
220 ggc_mark_rtx (JUMP_LABEL (r));
223 ggc_mark_rtx (LABEL_REFS (r));
226 ggc_mark_rtx (LABEL_NEXTREF (r));
227 ggc_mark_rtx (CONTAINING_INSN (r));
230 ggc_mark_tree (ADDRESSOF_DECL (r));
233 ggc_mark_rtx (CONST_DOUBLE_CHAIN (r));
236 switch (NOTE_LINE_NUMBER (r))
238 case NOTE_INSN_RANGE_START:
239 case NOTE_INSN_RANGE_END:
241 ggc_mark_rtx (NOTE_RANGE_INFO (r));
244 case NOTE_INSN_BLOCK_BEG:
245 case NOTE_INSN_BLOCK_END:
246 ggc_mark_tree (NOTE_BLOCK (r));
250 if (NOTE_LINE_NUMBER (r) >= 0)
251 ggc_mark_string (NOTE_SOURCE_FILE (r));
260 for (fmt = GET_RTX_FORMAT (GET_CODE (r)), i = 0; *fmt ; ++fmt, ++i)
265 ggc_mark_rtx (XEXP (r, i));
268 ggc_mark_rtvec (XVEC (r, i));
271 ggc_mark_string (XSTR (r, i));
283 if (v == NULL || ggc_set_mark_rtvec (v))
286 i = GET_NUM_ELEM (v);
288 ggc_mark_rtx (RTVEC_ELT (v, i));
292 ggc_mark_tree_children (t)
295 /* Bits from common. */
296 ggc_mark_tree (TREE_TYPE (t));
297 ggc_mark_tree (TREE_CHAIN (t));
299 /* Some nodes require special handling. */
300 switch (TREE_CODE (t))
303 ggc_mark_tree (TREE_PURPOSE (t));
304 ggc_mark_tree (TREE_VALUE (t));
309 int i = TREE_VEC_LENGTH (t);
311 ggc_mark_tree (TREE_VEC_ELT (t, i));
316 ggc_mark_tree (TREE_OPERAND (t, 0));
317 ggc_mark_tree (SAVE_EXPR_CONTEXT (t));
318 ggc_mark_rtx (SAVE_EXPR_RTL (t));
322 ggc_mark_rtx (RTL_EXPR_SEQUENCE (t));
323 ggc_mark_rtx (RTL_EXPR_RTL (t));
327 ggc_mark_tree (TREE_OPERAND (t, 0));
328 ggc_mark_tree (TREE_OPERAND (t, 1));
329 ggc_mark_rtx (CALL_EXPR_RTL (t));
333 ggc_mark_tree (TREE_REALPART (t));
334 ggc_mark_tree (TREE_IMAGPART (t));
338 ggc_mark_string (TREE_STRING_POINTER (t));
342 ggc_mark_rtx (DECL_INCOMING_RTL (t));
345 case IDENTIFIER_NODE:
346 ggc_mark_string (IDENTIFIER_POINTER (t));
354 /* But in general we can handle them by class. */
355 switch (TREE_CODE_CLASS (TREE_CODE (t)))
357 case 'd': /* A decl node. */
358 ggc_mark_string (DECL_SOURCE_FILE (t));
359 ggc_mark_tree (DECL_SIZE (t));
360 ggc_mark_tree (DECL_NAME (t));
361 ggc_mark_tree (DECL_CONTEXT (t));
362 ggc_mark_tree (DECL_ARGUMENTS (t));
363 ggc_mark_tree (DECL_RESULT (t));
364 ggc_mark_tree (DECL_INITIAL (t));
365 ggc_mark_tree (DECL_ABSTRACT_ORIGIN (t));
366 ggc_mark_tree (DECL_ASSEMBLER_NAME (t));
367 ggc_mark_tree (DECL_SECTION_NAME (t));
368 ggc_mark_tree (DECL_MACHINE_ATTRIBUTES (t));
369 ggc_mark_rtx (DECL_RTL (t));
370 ggc_mark_rtx (DECL_LIVE_RANGE_RTL (t));
371 ggc_mark_tree (DECL_VINDEX (t));
375 case 't': /* A type node. */
376 ggc_mark_tree (TYPE_SIZE (t));
377 ggc_mark_tree (TYPE_SIZE_UNIT (t));
378 ggc_mark_tree (TYPE_ATTRIBUTES (t));
379 ggc_mark_tree (TYPE_VALUES (t));
380 ggc_mark_tree (TYPE_POINTER_TO (t));
381 ggc_mark_tree (TYPE_REFERENCE_TO (t));
382 ggc_mark_tree (TYPE_NAME (t));
383 ggc_mark_tree (TYPE_MIN_VALUE (t));
384 ggc_mark_tree (TYPE_MAX_VALUE (t));
385 ggc_mark_tree (TYPE_NEXT_VARIANT (t));
386 ggc_mark_tree (TYPE_MAIN_VARIANT (t));
387 ggc_mark_tree (TYPE_BINFO (t));
388 ggc_mark_tree (TYPE_NONCOPIED_PARTS (t));
389 ggc_mark_tree (TYPE_CONTEXT (t));
393 case 'b': /* A lexical block. */
394 ggc_mark_tree (BLOCK_VARS (t));
395 ggc_mark_tree (BLOCK_TYPE_TAGS (t));
396 ggc_mark_tree (BLOCK_SUBBLOCKS (t));
397 ggc_mark_tree (BLOCK_SUPERCONTEXT (t));
398 ggc_mark_tree (BLOCK_ABSTRACT_ORIGIN (t));
399 ggc_mark_rtx (BLOCK_END_NOTE (t));
402 case 'c': /* A constant. */
403 ggc_mark_rtx (TREE_CST_RTL (t));
406 case 'r': case '<': case '1':
407 case '2': case 'e': case 's': /* Expressions. */
409 int i = tree_code_length[TREE_CODE (t)];
411 ggc_mark_tree (TREE_OPERAND (t, i));
421 /* Mark all the elements of the varray V, which contains trees. */
424 ggc_mark_tree_varray (v)
430 for (i = v->num_elements - 1; i >= 0; --i)
431 ggc_mark_tree (VARRAY_TREE (v, i));
434 /* Mark the hash table-entry HE. It's key field is really a tree. */
437 ggc_mark_tree_hash_table_entry (he, k)
438 struct hash_entry *he;
439 hash_table_key k ATTRIBUTE_UNUSED;
441 ggc_mark_tree ((tree) he->key);
445 /* Mark all the elements of the hash-table H, which contains trees. */
448 ggc_mark_tree_hash_table (ht)
449 struct hash_table *ht;
451 hash_traverse (ht, ggc_mark_tree_hash_table_entry, /*info=*/0);