]>
Commit | Line | Data |
---|---|---|
0a25f1f5 | 1 | /* Garbage collection for the GNU compiler. |
cd5a58e5 | 2 | Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
0a25f1f5 | 3 | |
1322177d | 4 | This file is part of GCC. |
770ae6cc | 5 | |
1322177d LB |
6 | GCC is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU General Public License as published by the Free | |
8 | Software Foundation; either version 2, or (at your option) any later | |
9 | version. | |
770ae6cc | 10 | |
1322177d LB |
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
770ae6cc RK |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
1322177d | 17 | along with GCC; see the file COPYING. If not, write to the Free |
770ae6cc RK |
18 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
19 | 02111-1307, USA. */ | |
0a25f1f5 | 20 | |
bedda2da | 21 | #include "varray.h" |
0a25f1f5 RH |
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 | ||
87ff9c8e RH |
26 | /* These structures are defined in various headers throughout the |
27 | compiler. However, rather than force everyone who includes this | |
28 | header to include all the headers in which they are declared, we | |
29 | just forward-declare them here. */ | |
87ff9c8e RH |
30 | struct eh_status; |
31 | struct emit_status; | |
fa51b01b | 32 | struct expr_status; |
b49a6a90 AS |
33 | struct hash_table; |
34 | struct label_node; | |
4c85a96d | 35 | struct rtx_def; |
b49a6a90 | 36 | struct rtvec_def; |
87ff9c8e | 37 | struct stmt_status; |
b49a6a90 | 38 | union tree_node; |
87ff9c8e RH |
39 | struct varasm_status; |
40 | ||
21a427cc | 41 | /* Constants for general use. */ |
a8a05998 ZW |
42 | extern const char empty_string[]; /* empty string */ |
43 | extern const char digit_vector[]; /* "0" .. "9" */ | |
44 | #define digit_string(d) (digit_vector + ((d) * 2)) | |
21a427cc | 45 | |
bedda2da MM |
46 | /* Trees that have been marked, but whose children still need marking. */ |
47 | extern varray_type ggc_pending_trees; | |
48 | ||
b49a6a90 | 49 | /* Manipulate global roots that are needed between calls to gc. */ |
4c160717 RK |
50 | extern void ggc_add_root PARAMS ((void *base, int nelt, |
51 | int size, void (*)(void *))); | |
52 | extern void ggc_add_rtx_root PARAMS ((struct rtx_def **, int nelt)); | |
53 | extern void ggc_add_tree_root PARAMS ((union tree_node **, | |
54 | int nelt)); | |
55 | extern void ggc_add_rtx_varray_root PARAMS ((struct varray_head_tag **, | |
56 | int nelt)); | |
57 | extern void ggc_add_tree_varray_root PARAMS ((struct varray_head_tag **, | |
58 | int nelt)); | |
59 | extern void ggc_add_tree_hash_table_root PARAMS ((struct hash_table **, | |
60 | int nelt)); | |
61 | extern void ggc_del_root PARAMS ((void *base)); | |
62 | ||
63 | /* Types used for mark test and marking functions, if specified, in call | |
64 | below. */ | |
65 | typedef int (*ggc_htab_marked_p) PARAMS ((const void *)); | |
66 | typedef void (*ggc_htab_mark) PARAMS ((const void *)); | |
67 | ||
68 | /* Add a hash table to be scanned when all roots have been processed. We | |
69 | delete any entry in the table that has not been marked. The argument is | |
70 | really htab_t. */ | |
71 | extern void ggc_add_deletable_htab PARAMS ((PTR, ggc_htab_marked_p, | |
72 | ggc_htab_mark)); | |
0a25f1f5 | 73 | |
b49a6a90 AS |
74 | /* Mark nodes from the gc_add_root callback. These functions follow |
75 | pointers to mark other objects too. */ | |
4c160717 RK |
76 | extern void ggc_mark_rtx_varray PARAMS ((struct varray_head_tag *)); |
77 | extern void ggc_mark_tree_varray PARAMS ((struct varray_head_tag *)); | |
78 | extern void ggc_mark_tree_hash_table PARAMS ((struct hash_table *)); | |
79 | extern void ggc_mark_roots PARAMS ((void)); | |
96df4529 | 80 | |
4c160717 RK |
81 | extern void ggc_mark_rtx_children PARAMS ((struct rtx_def *)); |
82 | extern void ggc_mark_rtvec_children PARAMS ((struct rtvec_def *)); | |
96df4529 | 83 | |
52a92176 AS |
84 | /* If EXPR is not NULL and previously unmarked, mark it and evaluate |
85 | to true. Otherwise evaluate to false. */ | |
86 | #define ggc_test_and_set_mark(EXPR) \ | |
87 | ((EXPR) != NULL && ! ggc_set_mark (EXPR)) | |
88 | ||
89 | #define ggc_mark_rtx(EXPR) \ | |
90 | do { \ | |
91 | rtx r__ = (EXPR); \ | |
92 | if (ggc_test_and_set_mark (r__)) \ | |
93 | ggc_mark_rtx_children (r__); \ | |
005537df RH |
94 | } while (0) |
95 | ||
bedda2da MM |
96 | #define ggc_mark_tree(EXPR) \ |
97 | do { \ | |
98 | tree t__ = (EXPR); \ | |
99 | if (ggc_test_and_set_mark (t__)) \ | |
100 | VARRAY_PUSH_TREE (ggc_pending_trees, t__); \ | |
005537df | 101 | } while (0) |
74c937ca | 102 | |
2a967f3d NB |
103 | #define ggc_mark_nonnull_tree(EXPR) \ |
104 | do { \ | |
105 | tree t__ = (EXPR); \ | |
106 | if (! ggc_set_mark (t__)) \ | |
107 | VARRAY_PUSH_TREE (ggc_pending_trees, t__); \ | |
108 | } while (0) | |
109 | ||
52a92176 AS |
110 | #define ggc_mark_rtvec(EXPR) \ |
111 | do { \ | |
112 | rtvec v__ = (EXPR); \ | |
113 | if (ggc_test_and_set_mark (v__)) \ | |
114 | ggc_mark_rtvec_children (v__); \ | |
96df4529 AS |
115 | } while (0) |
116 | ||
005537df RH |
117 | #define ggc_mark(EXPR) \ |
118 | do { \ | |
3cce094d | 119 | const void *a__ = (EXPR); \ |
005537df RH |
120 | if (a__ != NULL) \ |
121 | ggc_set_mark (a__); \ | |
122 | } while (0) | |
123 | ||
b49a6a90 AS |
124 | /* A GC implementation must provide these functions. */ |
125 | ||
126 | /* Initialize the garbage collector. */ | |
4c160717 RK |
127 | extern void init_ggc PARAMS ((void)); |
128 | extern void init_stringpool PARAMS ((void)); | |
0a25f1f5 | 129 | |
21cd906e MM |
130 | /* Start a new GGC context. Memory allocated in previous contexts |
131 | will not be collected while the new context is active. */ | |
4c160717 | 132 | extern void ggc_push_context PARAMS ((void)); |
b49a6a90 | 133 | |
21cd906e MM |
134 | /* Finish a GC context. Any uncollected memory in the new context |
135 | will be merged with the old context. */ | |
4c160717 | 136 | extern void ggc_pop_context PARAMS ((void)); |
21cd906e | 137 | |
0a25f1f5 | 138 | /* Allocation. */ |
005537df RH |
139 | |
140 | /* The internal primitive. */ | |
4c160717 | 141 | extern void *ggc_alloc PARAMS ((size_t)); |
f8a83ee3 | 142 | /* Like ggc_alloc, but allocates cleared memory. */ |
4c160717 | 143 | extern void *ggc_alloc_cleared PARAMS ((size_t)); |
005537df | 144 | |
f8a83ee3 ZW |
145 | #define ggc_alloc_rtx(NSLOTS) \ |
146 | ((struct rtx_def *) ggc_alloc (sizeof (struct rtx_def) \ | |
147 | + ((NSLOTS) - 1) * sizeof (rtunion))) | |
005537df RH |
148 | |
149 | #define ggc_alloc_rtvec(NELT) \ | |
f8a83ee3 ZW |
150 | ((struct rtvec_def *) ggc_alloc (sizeof (struct rtvec_def) \ |
151 | + ((NELT) - 1) * sizeof (rtx))) | |
005537df | 152 | |
f8a83ee3 | 153 | #define ggc_alloc_tree(LENGTH) ((union tree_node *) ggc_alloc (LENGTH)) |
005537df | 154 | |
520a57c8 ZW |
155 | /* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS. |
156 | If LENGTH is -1, then CONTENTS is assumed to be a | |
157 | null-terminated string and the memory sized accordingly. */ | |
4c160717 RK |
158 | extern const char *ggc_alloc_string PARAMS ((const char *contents, |
159 | int length)); | |
0a25f1f5 | 160 | |
f15b9af9 MM |
161 | /* Make a copy of S, in GC-able memory. */ |
162 | #define ggc_strdup(S) ggc_alloc_string((S), -1) | |
163 | ||
cd5a58e5 ZW |
164 | /* Invoke the collector. Garbage collection occurs only when this |
165 | function is called, not during allocations. */ | |
4c160717 | 166 | extern void ggc_collect PARAMS ((void)); |
0a25f1f5 | 167 | |
b49a6a90 | 168 | /* Actually set the mark on a particular region of memory, but don't |
005537df RH |
169 | follow pointers. This function is called by ggc_mark_*. It |
170 | returns zero if the object was not previously marked; non-zero if | |
171 | the object was already marked, or if, for any other reason, | |
172 | pointers in this data structure should not be traversed. */ | |
4c160717 RK |
173 | extern int ggc_set_mark PARAMS ((const void *)); |
174 | ||
175 | /* Return 1 if P has been marked, zero otherwise. | |
176 | P must have been allocated by the GC allocator; it mustn't point to | |
177 | static objects, stack variables, or memory allocated with malloc. */ | |
178 | extern int ggc_marked_p PARAMS ((const void *)); | |
0a25f1f5 | 179 | |
0a25f1f5 RH |
180 | /* Callbacks to the languages. */ |
181 | ||
182 | /* This is the language's opportunity to mark nodes held through | |
183 | the lang_specific hooks in the tree. */ | |
4c160717 | 184 | extern void lang_mark_tree PARAMS ((union tree_node *)); |
0a25f1f5 | 185 | |
f15b9af9 MM |
186 | /* The FALSE_LABEL_STACK, declared in except.h, has language-dependent |
187 | semantics. If a front-end needs to mark the false label stack, it | |
188 | should set this pointer to a non-NULL value. Otherwise, no marking | |
189 | will be done. */ | |
190 | extern void (*lang_mark_false_label_stack) PARAMS ((struct label_node *)); | |
87ff9c8e | 191 | |
0a25f1f5 RH |
192 | /* Mark functions for various structs scattered about. */ |
193 | ||
4c160717 RK |
194 | void mark_eh_status PARAMS ((struct eh_status *)); |
195 | void mark_emit_status PARAMS ((struct emit_status *)); | |
196 | void mark_expr_status PARAMS ((struct expr_status *)); | |
197 | void mark_stmt_status PARAMS ((struct stmt_status *)); | |
198 | void mark_varasm_status PARAMS ((struct varasm_status *)); | |
199 | void mark_optab PARAMS ((void *)); | |
3277221c MM |
200 | |
201 | /* Statistics. */ | |
202 | ||
203 | /* This structure contains the statistics common to all collectors. | |
204 | Particular collectors can extend this structure. */ | |
205 | typedef struct ggc_statistics | |
206 | { | |
207 | /* The Ith element is the number of nodes allocated with code I. */ | |
208 | unsigned num_trees[256]; | |
209 | /* The Ith element is the number of bytes allocated by nodes with | |
210 | code I. */ | |
211 | size_t size_trees[256]; | |
212 | /* The Ith element is the number of nodes allocated with code I. */ | |
213 | unsigned num_rtxs[256]; | |
214 | /* The Ith element is the number of bytes allocated by nodes with | |
215 | code I. */ | |
216 | size_t size_rtxs[256]; | |
3277221c MM |
217 | /* The total size of the tree nodes allocated. */ |
218 | size_t total_size_trees; | |
3277221c MM |
219 | /* The total size of the RTL nodes allocated. */ |
220 | size_t total_size_rtxs; | |
63408827 RH |
221 | /* The total number of tree nodes allocated. */ |
222 | unsigned total_num_trees; | |
223 | /* The total number of RTL nodes allocated. */ | |
224 | unsigned total_num_rtxs; | |
3277221c MM |
225 | } ggc_statistics; |
226 | ||
227 | /* Return the number of bytes allocated at the indicated address. */ | |
4c160717 | 228 | extern size_t ggc_get_size PARAMS ((const void *)); |
3277221c MM |
229 | |
230 | /* Used by the various collectors to gather and print statistics that | |
231 | do not depend on the collector in use. */ | |
4c160717 | 232 | extern void ggc_print_common_statistics PARAMS ((FILE *, ggc_statistics *)); |
c6991660 KG |
233 | |
234 | /* Print allocation statistics. */ | |
4c160717 RK |
235 | extern void ggc_print_statistics PARAMS ((void)); |
236 | extern void stringpool_statistics PARAMS ((void)); |