]>
Commit | Line | Data |
---|---|---|
0a25f1f5 | 1 | /* Garbage collection for the GNU compiler. |
a611912f | 2 | Copyright (C) 1998, 1999 Free Software Foundation, Inc. |
0a25f1f5 RH |
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 | #include "gansidecl.h" | |
22 | ||
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. */ | |
25 | ||
a3770a81 RH |
26 | /* Language-specific code defines this variable to be either one (if |
27 | it wants garbage collection), or zero (if it does not). */ | |
28 | extern int ggc_p; | |
29 | ||
87ff9c8e RH |
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. */ | |
87ff9c8e RH |
34 | struct eh_status; |
35 | struct emit_status; | |
fa51b01b | 36 | struct expr_status; |
b49a6a90 AS |
37 | struct hash_table; |
38 | struct label_node; | |
39 | struct rtvec_def; | |
87ff9c8e | 40 | struct stmt_status; |
b49a6a90 | 41 | union tree_node; |
87ff9c8e | 42 | struct varasm_status; |
a3770a81 | 43 | struct varray_head_tag; |
87ff9c8e | 44 | |
21a427cc AS |
45 | /* Constants for general use. */ |
46 | extern char *empty_string; | |
47 | ||
b49a6a90 AS |
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)); | |
0a25f1f5 | 56 | |
b49a6a90 AS |
57 | /* Mark nodes from the gc_add_root callback. These functions follow |
58 | pointers to mark other objects too. */ | |
96df4529 AS |
59 | extern void ggc_mark_tree_varray PROTO ((struct varray_head_tag *)); |
60 | extern void ggc_mark_tree_hash_table PROTO ((struct hash_table *)); | |
96df4529 AS |
61 | extern void ggc_mark_roots PROTO((void)); |
62 | ||
63 | extern void ggc_mark_rtx_children PROTO ((struct rtx_def *)); | |
005537df | 64 | extern void ggc_mark_rtvec_children PROTO ((struct rtvec_def *)); |
96df4529 AS |
65 | extern void ggc_mark_tree_children PROTO ((union tree_node *)); |
66 | ||
005537df RH |
67 | #define ggc_mark_rtx(EXPR) \ |
68 | do { \ | |
69 | rtx r__ = (EXPR); \ | |
70 | if (r__ != NULL && ! ggc_set_mark (r__)) \ | |
71 | ggc_mark_rtx_children (r__); \ | |
72 | } while (0) | |
73 | ||
74 | #define ggc_mark_tree(EXPR) \ | |
75 | do { \ | |
76 | tree t__ = (EXPR); \ | |
77 | if (t__ != NULL && ! ggc_set_mark (t__)) \ | |
78 | ggc_mark_tree_children (t__); \ | |
79 | } while (0) | |
74c937ca | 80 | |
005537df RH |
81 | #define ggc_mark_rtvec(EXPR) \ |
82 | do { \ | |
83 | rtvec v__ = (EXPR); \ | |
84 | if (v__ != NULL && ! ggc_set_mark (v__)) \ | |
85 | ggc_mark_rtvec_children (v__); \ | |
96df4529 AS |
86 | } while (0) |
87 | ||
005537df RH |
88 | #define ggc_mark_string(EXPR) \ |
89 | do { \ | |
90 | char *s__ = (EXPR); \ | |
91 | if (s__ != NULL) \ | |
92 | ggc_set_mark (s__); \ | |
96df4529 | 93 | } while (0) |
b49a6a90 | 94 | |
005537df RH |
95 | #define ggc_mark(EXPR) \ |
96 | do { \ | |
97 | void *a__ = (EXPR); \ | |
98 | if (a__ != NULL) \ | |
99 | ggc_set_mark (a__); \ | |
100 | } while (0) | |
101 | ||
102 | /* Mark, but only if it was allocated in collectable memory. */ | |
103 | extern void ggc_mark_if_gcable PROTO ((void *)); | |
104 | ||
b49a6a90 AS |
105 | /* A GC implementation must provide these functions. */ |
106 | ||
107 | /* Initialize the garbage collector. */ | |
0a25f1f5 RH |
108 | extern void init_ggc PROTO ((void)); |
109 | ||
21cd906e MM |
110 | /* Start a new GGC context. Memory allocated in previous contexts |
111 | will not be collected while the new context is active. */ | |
74c937ca | 112 | extern void ggc_push_context PROTO ((void)); |
b49a6a90 | 113 | |
21cd906e MM |
114 | /* Finish a GC context. Any uncollected memory in the new context |
115 | will be merged with the old context. */ | |
74c937ca | 116 | extern void ggc_pop_context PROTO ((void)); |
21cd906e | 117 | |
0a25f1f5 | 118 | /* Allocation. */ |
005537df RH |
119 | |
120 | /* The internal primitive. */ | |
121 | void *ggc_alloc_obj PROTO ((size_t, int)); | |
122 | ||
123 | #define ggc_alloc_rtx(NSLOTS) \ | |
124 | ((struct rtx_def *) ggc_alloc_obj (sizeof (struct rtx_def) \ | |
125 | + ((NSLOTS) - 1) * sizeof (rtunion), 1)) | |
126 | ||
127 | #define ggc_alloc_rtvec(NELT) \ | |
128 | ((struct rtvec_def *) ggc_alloc_obj (sizeof (struct rtvec_def) \ | |
129 | + ((NELT) - 1) * sizeof (rtx), 1)) | |
130 | ||
131 | #define ggc_alloc_tree(LENGTH) \ | |
132 | ((union tree_node *) ggc_alloc_obj ((LENGTH), 1)) | |
133 | ||
134 | #define ggc_alloc(SIZE) ggc_alloc_obj((SIZE), 0) | |
135 | ||
0a25f1f5 RH |
136 | char *ggc_alloc_string PROTO ((const char *contents, int length)); |
137 | ||
138 | /* Invoke the collector. This is really just a hint, but in the case of | |
139 | the simple collector, the only time it will happen. */ | |
0a25f1f5 RH |
140 | void ggc_collect PROTO ((void)); |
141 | ||
b49a6a90 | 142 | /* Actually set the mark on a particular region of memory, but don't |
005537df RH |
143 | follow pointers. This function is called by ggc_mark_*. It |
144 | returns zero if the object was not previously marked; non-zero if | |
145 | the object was already marked, or if, for any other reason, | |
146 | pointers in this data structure should not be traversed. */ | |
147 | int ggc_set_mark PROTO ((void *)); | |
0a25f1f5 | 148 | |
0a25f1f5 RH |
149 | /* Callbacks to the languages. */ |
150 | ||
151 | /* This is the language's opportunity to mark nodes held through | |
152 | the lang_specific hooks in the tree. */ | |
153 | void lang_mark_tree PROTO ((union tree_node *)); | |
154 | ||
87ff9c8e RH |
155 | /* The FALSE_LABEL_STACK, declared in except.h, has |
156 | language-dependent semantics. Each front-end should define this | |
157 | function appropriately. */ | |
158 | void lang_mark_false_label_stack PROTO ((struct label_node *)); | |
159 | ||
0a25f1f5 RH |
160 | /* Mark functions for various structs scattered about. */ |
161 | ||
fa51b01b RH |
162 | void mark_eh_status PROTO ((struct eh_status *)); |
163 | void mark_emit_status PROTO ((struct emit_status *)); | |
164 | void mark_expr_status PROTO ((struct expr_status *)); | |
165 | void mark_stmt_status PROTO ((struct stmt_status *)); | |
166 | void mark_varasm_status PROTO ((struct varasm_status *)); | |
0a25f1f5 | 167 | void mark_optab PROTO ((void *)); |
3277221c MM |
168 | |
169 | /* Statistics. */ | |
170 | ||
171 | /* This structure contains the statistics common to all collectors. | |
172 | Particular collectors can extend this structure. */ | |
173 | typedef struct ggc_statistics | |
174 | { | |
175 | /* The Ith element is the number of nodes allocated with code I. */ | |
176 | unsigned num_trees[256]; | |
177 | /* The Ith element is the number of bytes allocated by nodes with | |
178 | code I. */ | |
179 | size_t size_trees[256]; | |
180 | /* The Ith element is the number of nodes allocated with code I. */ | |
181 | unsigned num_rtxs[256]; | |
182 | /* The Ith element is the number of bytes allocated by nodes with | |
183 | code I. */ | |
184 | size_t size_rtxs[256]; | |
3277221c MM |
185 | /* The total size of the tree nodes allocated. */ |
186 | size_t total_size_trees; | |
3277221c MM |
187 | /* The total size of the RTL nodes allocated. */ |
188 | size_t total_size_rtxs; | |
63408827 RH |
189 | /* The total number of tree nodes allocated. */ |
190 | unsigned total_num_trees; | |
191 | /* The total number of RTL nodes allocated. */ | |
192 | unsigned total_num_rtxs; | |
3277221c MM |
193 | } ggc_statistics; |
194 | ||
195 | /* Return the number of bytes allocated at the indicated address. */ | |
196 | size_t ggc_get_size PROTO ((void *)); | |
197 | ||
198 | /* Used by the various collectors to gather and print statistics that | |
199 | do not depend on the collector in use. */ | |
200 | void ggc_print_statistics PROTO ((FILE *, ggc_statistics *)); |