1 /* Garbage collection for the GNU compiler.
2 Copyright (C) 1998, 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 #include "gansidecl.h"
23 /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with
24 an external gc library that might be linked in. */
26 /* Language-specific code defines this variable to be either one (if
27 it wants garbage collection), or zero (if it does not). */
30 /* These structures are defined in various headers throughout the
31 compiler. However, rather than force everyone who includes this
32 header to include all the headers in which they are declared, we
33 just forward-declare them here. */
43 struct varray_head_tag
;
45 /* Constants for general use. */
46 extern char *empty_string
;
48 /* Manipulate global roots that are needed between calls to gc. */
49 void ggc_add_root
PROTO ((void *base
, int nelt
, int size
, void (*)(void *)));
50 void ggc_add_rtx_root
PROTO ((struct rtx_def
**, int nelt
));
51 void ggc_add_tree_root
PROTO ((union tree_node
**, int nelt
));
52 void ggc_add_string_root
PROTO ((char **, int nelt
));
53 void ggc_add_tree_varray_root
PROTO ((struct varray_head_tag
**, int nelt
));
54 void ggc_add_tree_hash_table_root
PROTO ((struct hash_table
**, int nelt
));
55 void ggc_del_root
PROTO ((void *base
));
57 /* Mark nodes from the gc_add_root callback. These functions follow
58 pointers to mark other objects too. */
59 extern void ggc_mark_rtvec
PROTO ((struct rtvec_def
*));
60 extern void ggc_mark_tree_varray
PROTO ((struct varray_head_tag
*));
61 extern void ggc_mark_tree_hash_table
PROTO ((struct hash_table
*));
62 extern void ggc_mark_string
PROTO ((char *));
63 extern void ggc_mark
PROTO ((void *));
64 extern void ggc_mark_roots
PROTO((void));
66 extern void ggc_mark_rtx_children
PROTO ((struct rtx_def
*));
67 extern void ggc_mark_tree_children
PROTO ((union tree_node
*));
69 /* Mark the string, but only if it was allocated in collectable
71 extern void ggc_mark_string_if_gcable
PROTO ((char *));
73 #define ggc_mark_rtx(RTX_EXPR) \
75 rtx r__ = (RTX_EXPR); \
76 if (r__ != NULL && ! ggc_set_mark_rtx (r__)) \
77 ggc_mark_rtx_children (r__); \
80 #define ggc_mark_tree(TREE_EXPR) \
82 tree t__ = (TREE_EXPR); \
83 if (t__ != NULL && ! ggc_set_mark_tree (t__)) \
84 ggc_mark_tree_children (t__); \
87 /* A GC implementation must provide these functions. */
89 /* Initialize the garbage collector. */
90 extern void init_ggc
PROTO ((void));
92 /* Start a new GGC context. Memory allocated in previous contexts
93 will not be collected while the new context is active. */
94 extern void ggc_push_context
PROTO ((void));
96 /* Finish a GC context. Any uncollected memory in the new context
97 will be merged with the old context. */
98 extern void ggc_pop_context
PROTO ((void));
101 struct rtx_def
*ggc_alloc_rtx
PROTO ((int nslots
));
102 struct rtvec_def
*ggc_alloc_rtvec
PROTO ((int nelt
));
103 union tree_node
*ggc_alloc_tree
PROTO ((int length
));
104 char *ggc_alloc_string
PROTO ((const char *contents
, int length
));
105 void *ggc_alloc
PROTO ((size_t));
107 /* Invoke the collector. This is really just a hint, but in the case of
108 the simple collector, the only time it will happen. */
109 void ggc_collect
PROTO ((void));
111 /* Actually set the mark on a particular region of memory, but don't
112 follow pointers. These functions are called by ggc_mark_*. They
113 return zero if the object was not previously marked; they return
114 non-zero if the object was already marked, or if, for any other
115 reason, pointers in this data structure should not be traversed. */
116 int ggc_set_mark_rtx
PROTO ((struct rtx_def
*));
117 int ggc_set_mark_rtvec
PROTO ((struct rtvec_def
*));
118 int ggc_set_mark_tree
PROTO ((union tree_node
*));
120 /* Callbacks to the languages. */
122 /* This is the language's opportunity to mark nodes held through
123 the lang_specific hooks in the tree. */
124 void lang_mark_tree
PROTO ((union tree_node
*));
126 /* The FALSE_LABEL_STACK, declared in except.h, has
127 language-dependent semantics. Each front-end should define this
128 function appropriately. */
129 void lang_mark_false_label_stack
PROTO ((struct label_node
*));
131 /* Mark functions for various structs scattered about. */
133 void mark_eh_status
PROTO ((struct eh_status
*));
134 void mark_emit_status
PROTO ((struct emit_status
*));
135 void mark_expr_status
PROTO ((struct expr_status
*));
136 void mark_stmt_status
PROTO ((struct stmt_status
*));
137 void mark_varasm_status
PROTO ((struct varasm_status
*));
138 void mark_optab
PROTO ((void *));