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. */
32 static void ggc_mark_rtx_ptr
PARAMS ((void *));
33 static void ggc_mark_tree_ptr
PARAMS ((void *));
34 static void ggc_mark_tree_varray_ptr
PARAMS ((void *));
35 static void ggc_mark_tree_hash_table_ptr
PARAMS ((void *));
36 static void ggc_mark_string_ptr
PARAMS ((void *));
37 static boolean ggc_mark_tree_hash_table_entry
PARAMS ((struct hash_entry
*,
40 /* Maintain global roots that are preserved during GC. */
42 /* Global roots that are preserved during calls to gc. */
46 struct ggc_root
*next
;
50 void (*cb
) PROTO ((void *));
53 static struct ggc_root
*roots
;
55 /* Type-correct function to pass to ggc_add_root. It just forwards
56 *ELT (which is an rtx) to ggc_mark_tree_varray. */
59 ggc_mark_rtx_ptr (elt
)
62 ggc_mark_rtx (*(rtx
*)elt
);
65 /* Type-correct function to pass to ggc_add_root. It just forwards
66 *ELT (which is a tree) to ggc_mark_tree. */
69 ggc_mark_tree_ptr (elt
)
72 ggc_mark_tree (*(tree
*)elt
);
75 /* Type-correct function to pass to ggc_add_root. It just forwards
76 ELT (which is really a varray_type *) to ggc_mark_tree_varray. */
79 ggc_mark_tree_varray_ptr (elt
)
82 ggc_mark_tree_varray (*(varray_type
*)elt
);
85 /* Type-correct function to pass to ggc_add_root. It just forwards
86 ELT (which is really a struct hash_table **) to
87 ggc_mark_tree_hash_table. */
90 ggc_mark_tree_hash_table_ptr (elt
)
93 ggc_mark_tree_hash_table (*(struct hash_table
**) elt
);
97 ggc_mark_string_ptr (elt
)
100 ggc_mark_string (*(char **)elt
);
104 ggc_add_root (base
, nelt
, size
, cb
)
107 void (*cb
) PROTO ((void *));
109 struct ggc_root
*x
= (struct ggc_root
*) xmalloc (sizeof (*x
));
121 ggc_add_rtx_root (base
, nelt
)
125 ggc_add_root (base
, nelt
, sizeof(rtx
), ggc_mark_rtx_ptr
);
129 ggc_add_tree_root (base
, nelt
)
133 ggc_add_root (base
, nelt
, sizeof(tree
), ggc_mark_tree_ptr
);
136 /* Add V (a varray full of trees) to the list of GC roots. */
139 ggc_add_tree_varray_root (base
, nelt
)
143 ggc_add_root (base
, nelt
, sizeof (varray_type
),
144 ggc_mark_tree_varray_ptr
);
147 /* Add HT (a hash-table where ever key is a tree) to the list of GC
151 ggc_add_tree_hash_table_root (base
, nelt
)
152 struct hash_table
**base
;
155 ggc_add_root (base
, nelt
, sizeof (struct hash_table
*),
156 ggc_mark_tree_hash_table_ptr
);
160 ggc_add_string_root (base
, nelt
)
164 ggc_add_root (base
, nelt
, sizeof (char *), ggc_mark_string_ptr
);
172 struct ggc_root
*x
, **p
;
174 p
= &roots
, x
= roots
;
195 for (x
= roots
; x
!= NULL
; x
= x
->next
)
198 int s
= x
->size
, n
= x
->nelt
;
199 void (*cb
) PROTO ((void *)) = x
->cb
;
202 for (i
= 0; i
< n
; ++i
, elt
+= s
)
208 ggc_mark_rtx_children (r
)
214 /* ??? If (some of) these are really pass-dependant info, do we have
215 any right poking our noses in? */
216 switch (GET_CODE (r
))
219 ggc_mark_rtx (JUMP_LABEL (r
));
222 ggc_mark_rtx (LABEL_REFS (r
));
225 ggc_mark_rtx (LABEL_NEXTREF (r
));
226 ggc_mark_rtx (CONTAINING_INSN (r
));
229 ggc_mark_tree (ADDRESSOF_DECL (r
));
232 ggc_mark_rtx (CONST_DOUBLE_CHAIN (r
));
235 switch (NOTE_LINE_NUMBER (r
))
237 case NOTE_INSN_RANGE_START
:
238 case NOTE_INSN_RANGE_END
:
240 ggc_mark_rtx (NOTE_RANGE_INFO (r
));
243 case NOTE_INSN_BLOCK_BEG
:
244 case NOTE_INSN_BLOCK_END
:
245 ggc_mark_tree (NOTE_BLOCK (r
));
249 if (NOTE_LINE_NUMBER (r
) >= 0)
250 ggc_mark_string (NOTE_SOURCE_FILE (r
));
259 for (fmt
= GET_RTX_FORMAT (GET_CODE (r
)), i
= 0; *fmt
; ++fmt
, ++i
)
264 ggc_mark_rtx (XEXP (r
, i
));
267 ggc_mark_rtvec (XVEC (r
, i
));
270 ggc_mark_string (XSTR (r
, i
));
282 if (v
== NULL
|| ggc_set_mark_rtvec (v
))
285 i
= GET_NUM_ELEM (v
);
287 ggc_mark_rtx (RTVEC_ELT (v
, i
));
291 ggc_mark_tree_children (t
)
294 /* Bits from common. */
295 ggc_mark_tree (TREE_TYPE (t
));
296 ggc_mark_tree (TREE_CHAIN (t
));
298 /* Some nodes require special handling. */
299 switch (TREE_CODE (t
))
302 ggc_mark_tree (TREE_PURPOSE (t
));
303 ggc_mark_tree (TREE_VALUE (t
));
308 int i
= TREE_VEC_LENGTH (t
);
310 ggc_mark_tree (TREE_VEC_ELT (t
, i
));
315 ggc_mark_tree (TREE_OPERAND (t
, 0));
316 ggc_mark_tree (SAVE_EXPR_CONTEXT (t
));
317 ggc_mark_rtx (SAVE_EXPR_RTL (t
));
321 ggc_mark_rtx (RTL_EXPR_SEQUENCE (t
));
322 ggc_mark_rtx (RTL_EXPR_RTL (t
));
326 ggc_mark_tree (TREE_OPERAND (t
, 0));
327 ggc_mark_tree (TREE_OPERAND (t
, 1));
328 ggc_mark_rtx (CALL_EXPR_RTL (t
));
332 ggc_mark_tree (TREE_REALPART (t
));
333 ggc_mark_tree (TREE_IMAGPART (t
));
337 ggc_mark_string (TREE_STRING_POINTER (t
));
341 ggc_mark_rtx (DECL_INCOMING_RTL (t
));
344 case IDENTIFIER_NODE
:
345 ggc_mark_string (IDENTIFIER_POINTER (t
));
353 /* But in general we can handle them by class. */
354 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
356 case 'd': /* A decl node. */
357 ggc_mark_string (DECL_SOURCE_FILE (t
));
358 ggc_mark_tree (DECL_SIZE (t
));
359 ggc_mark_tree (DECL_NAME (t
));
360 ggc_mark_tree (DECL_CONTEXT (t
));
361 ggc_mark_tree (DECL_ARGUMENTS (t
));
362 ggc_mark_tree (DECL_RESULT (t
));
363 ggc_mark_tree (DECL_INITIAL (t
));
364 ggc_mark_tree (DECL_ABSTRACT_ORIGIN (t
));
365 ggc_mark_tree (DECL_ASSEMBLER_NAME (t
));
366 ggc_mark_tree (DECL_SECTION_NAME (t
));
367 ggc_mark_tree (DECL_MACHINE_ATTRIBUTES (t
));
368 ggc_mark_rtx (DECL_RTL (t
));
369 ggc_mark_rtx (DECL_LIVE_RANGE_RTL (t
));
370 ggc_mark_tree (DECL_VINDEX (t
));
374 case 't': /* A type node. */
375 ggc_mark_tree (TYPE_SIZE (t
));
376 ggc_mark_tree (TYPE_SIZE_UNIT (t
));
377 ggc_mark_tree (TYPE_ATTRIBUTES (t
));
378 ggc_mark_tree (TYPE_VALUES (t
));
379 ggc_mark_tree (TYPE_POINTER_TO (t
));
380 ggc_mark_tree (TYPE_REFERENCE_TO (t
));
381 ggc_mark_tree (TYPE_NAME (t
));
382 ggc_mark_tree (TYPE_MIN_VALUE (t
));
383 ggc_mark_tree (TYPE_MAX_VALUE (t
));
384 ggc_mark_tree (TYPE_NEXT_VARIANT (t
));
385 ggc_mark_tree (TYPE_MAIN_VARIANT (t
));
386 ggc_mark_tree (TYPE_BINFO (t
));
387 ggc_mark_tree (TYPE_NONCOPIED_PARTS (t
));
388 ggc_mark_tree (TYPE_CONTEXT (t
));
392 case 'b': /* A lexical block. */
393 ggc_mark_tree (BLOCK_VARS (t
));
394 ggc_mark_tree (BLOCK_TYPE_TAGS (t
));
395 ggc_mark_tree (BLOCK_SUBBLOCKS (t
));
396 ggc_mark_tree (BLOCK_SUPERCONTEXT (t
));
397 ggc_mark_tree (BLOCK_ABSTRACT_ORIGIN (t
));
398 ggc_mark_rtx (BLOCK_END_NOTE (t
));
401 case 'c': /* A constant. */
402 ggc_mark_rtx (TREE_CST_RTL (t
));
405 case 'r': case '<': case '1':
406 case '2': case 'e': case 's': /* Expressions. */
408 int i
= tree_code_length
[TREE_CODE (t
)];
410 ggc_mark_tree (TREE_OPERAND (t
, i
));
420 /* Mark all the elements of the varray V, which contains trees. */
423 ggc_mark_tree_varray (v
)
429 for (i
= v
->num_elements
- 1; i
>= 0; --i
)
430 ggc_mark_tree (VARRAY_TREE (v
, i
));
433 /* Mark the hash table-entry HE. It's key field is really a tree. */
436 ggc_mark_tree_hash_table_entry (he
, k
)
437 struct hash_entry
*he
;
438 hash_table_key k ATTRIBUTE_UNUSED
;
440 ggc_mark_tree ((tree
) he
->key
);
444 /* Mark all the elements of the hash-table H, which contains trees. */
447 ggc_mark_tree_hash_table (ht
)
448 struct hash_table
*ht
;
450 hash_traverse (ht
, ggc_mark_tree_hash_table_entry
, /*info=*/0);