]>
Commit | Line | Data |
---|---|---|
0a25f1f5 | 1 | /* Garbage collection for the GNU compiler. |
9311a396 | 2 | Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. |
0a25f1f5 | 3 | |
770ae6cc RK |
4 | This file is part of GNU CC. |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU General Public License as published by the | |
8 | Free Software Foundation; either version 2, or (at your option) any | |
9 | later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, but WITHOUT | |
12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
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 | |
17 | along with GNU CC; see the file COPYING. If not, write to the Free | |
18 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
19 | 02111-1307, USA. */ | |
0a25f1f5 RH |
20 | |
21 | #include "gansidecl.h" | |
bedda2da | 22 | #include "varray.h" |
0a25f1f5 RH |
23 | |
24 | /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with | |
25 | an external gc library that might be linked in. */ | |
26 | ||
a3770a81 RH |
27 | /* Language-specific code defines this variable to be either one (if |
28 | it wants garbage collection), or zero (if it does not). */ | |
29 | extern int ggc_p; | |
30 | ||
87ff9c8e RH |
31 | /* These structures are defined in various headers throughout the |
32 | compiler. However, rather than force everyone who includes this | |
33 | header to include all the headers in which they are declared, we | |
34 | just forward-declare them here. */ | |
87ff9c8e RH |
35 | struct eh_status; |
36 | struct emit_status; | |
fa51b01b | 37 | struct expr_status; |
b49a6a90 AS |
38 | struct hash_table; |
39 | struct label_node; | |
4c85a96d | 40 | struct rtx_def; |
b49a6a90 | 41 | struct rtvec_def; |
87ff9c8e | 42 | struct stmt_status; |
b49a6a90 | 43 | union tree_node; |
87ff9c8e RH |
44 | struct varasm_status; |
45 | ||
21a427cc AS |
46 | /* Constants for general use. */ |
47 | extern char *empty_string; | |
48 | ||
bedda2da MM |
49 | /* Trees that have been marked, but whose children still need marking. */ |
50 | extern varray_type ggc_pending_trees; | |
51 | ||
b49a6a90 | 52 | /* Manipulate global roots that are needed between calls to gc. */ |
3fe41456 KG |
53 | void ggc_add_root PARAMS ((void *base, int nelt, int size, void (*)(void *))); |
54 | void ggc_add_rtx_root PARAMS ((struct rtx_def **, int nelt)); | |
55 | void ggc_add_tree_root PARAMS ((union tree_node **, int nelt)); | |
56 | void ggc_add_string_root PARAMS ((char **, int nelt)); | |
ef8288f7 | 57 | void ggc_add_rtx_varray_root PARAMS ((struct varray_head_tag **, int nelt)); |
3fe41456 KG |
58 | void ggc_add_tree_varray_root PARAMS ((struct varray_head_tag **, int nelt)); |
59 | void ggc_add_tree_hash_table_root PARAMS ((struct hash_table **, int nelt)); | |
60 | void ggc_del_root PARAMS ((void *base)); | |
0a25f1f5 | 61 | |
b49a6a90 AS |
62 | /* Mark nodes from the gc_add_root callback. These functions follow |
63 | pointers to mark other objects too. */ | |
ef8288f7 | 64 | extern void ggc_mark_rtx_varray PARAMS ((struct varray_head_tag *)); |
3fe41456 KG |
65 | extern void ggc_mark_tree_varray PARAMS ((struct varray_head_tag *)); |
66 | extern void ggc_mark_tree_hash_table PARAMS ((struct hash_table *)); | |
67 | extern void ggc_mark_roots PARAMS ((void)); | |
96df4529 | 68 | |
3fe41456 KG |
69 | extern void ggc_mark_rtx_children PARAMS ((struct rtx_def *)); |
70 | extern void ggc_mark_rtvec_children PARAMS ((struct rtvec_def *)); | |
96df4529 | 71 | |
52a92176 AS |
72 | /* If EXPR is not NULL and previously unmarked, mark it and evaluate |
73 | to true. Otherwise evaluate to false. */ | |
74 | #define ggc_test_and_set_mark(EXPR) \ | |
75 | ((EXPR) != NULL && ! ggc_set_mark (EXPR)) | |
76 | ||
77 | #define ggc_mark_rtx(EXPR) \ | |
78 | do { \ | |
79 | rtx r__ = (EXPR); \ | |
80 | if (ggc_test_and_set_mark (r__)) \ | |
81 | ggc_mark_rtx_children (r__); \ | |
005537df RH |
82 | } while (0) |
83 | ||
bedda2da MM |
84 | #define ggc_mark_tree(EXPR) \ |
85 | do { \ | |
86 | tree t__ = (EXPR); \ | |
87 | if (ggc_test_and_set_mark (t__)) \ | |
88 | VARRAY_PUSH_TREE (ggc_pending_trees, t__); \ | |
005537df | 89 | } while (0) |
74c937ca | 90 | |
52a92176 AS |
91 | #define ggc_mark_rtvec(EXPR) \ |
92 | do { \ | |
93 | rtvec v__ = (EXPR); \ | |
94 | if (ggc_test_and_set_mark (v__)) \ | |
95 | ggc_mark_rtvec_children (v__); \ | |
96df4529 AS |
96 | } while (0) |
97 | ||
005537df RH |
98 | #define ggc_mark_string(EXPR) \ |
99 | do { \ | |
3cce094d | 100 | const char *s__ = (EXPR); \ |
005537df RH |
101 | if (s__ != NULL) \ |
102 | ggc_set_mark (s__); \ | |
96df4529 | 103 | } while (0) |
b49a6a90 | 104 | |
005537df RH |
105 | #define ggc_mark(EXPR) \ |
106 | do { \ | |
3cce094d | 107 | const void *a__ = (EXPR); \ |
005537df RH |
108 | if (a__ != NULL) \ |
109 | ggc_set_mark (a__); \ | |
110 | } while (0) | |
111 | ||
112 | /* Mark, but only if it was allocated in collectable memory. */ | |
3cce094d | 113 | extern void ggc_mark_if_gcable PARAMS ((const void *)); |
005537df | 114 | |
b49a6a90 AS |
115 | /* A GC implementation must provide these functions. */ |
116 | ||
117 | /* Initialize the garbage collector. */ | |
3fe41456 | 118 | extern void init_ggc PARAMS ((void)); |
0a25f1f5 | 119 | |
21cd906e MM |
120 | /* Start a new GGC context. Memory allocated in previous contexts |
121 | will not be collected while the new context is active. */ | |
3fe41456 | 122 | extern void ggc_push_context PARAMS ((void)); |
b49a6a90 | 123 | |
21cd906e MM |
124 | /* Finish a GC context. Any uncollected memory in the new context |
125 | will be merged with the old context. */ | |
3fe41456 | 126 | extern void ggc_pop_context PARAMS ((void)); |
21cd906e | 127 | |
0a25f1f5 | 128 | /* Allocation. */ |
005537df RH |
129 | |
130 | /* The internal primitive. */ | |
3fe41456 | 131 | void *ggc_alloc_obj PARAMS ((size_t, int)); |
005537df RH |
132 | |
133 | #define ggc_alloc_rtx(NSLOTS) \ | |
134 | ((struct rtx_def *) ggc_alloc_obj (sizeof (struct rtx_def) \ | |
135 | + ((NSLOTS) - 1) * sizeof (rtunion), 1)) | |
136 | ||
137 | #define ggc_alloc_rtvec(NELT) \ | |
138 | ((struct rtvec_def *) ggc_alloc_obj (sizeof (struct rtvec_def) \ | |
139 | + ((NELT) - 1) * sizeof (rtx), 1)) | |
140 | ||
141 | #define ggc_alloc_tree(LENGTH) \ | |
142 | ((union tree_node *) ggc_alloc_obj ((LENGTH), 1)) | |
143 | ||
144 | #define ggc_alloc(SIZE) ggc_alloc_obj((SIZE), 0) | |
145 | ||
3fe41456 | 146 | char *ggc_alloc_string PARAMS ((const char *contents, int length)); |
0a25f1f5 RH |
147 | |
148 | /* Invoke the collector. This is really just a hint, but in the case of | |
149 | the simple collector, the only time it will happen. */ | |
3fe41456 | 150 | void ggc_collect PARAMS ((void)); |
0a25f1f5 | 151 | |
b49a6a90 | 152 | /* Actually set the mark on a particular region of memory, but don't |
005537df RH |
153 | follow pointers. This function is called by ggc_mark_*. It |
154 | returns zero if the object was not previously marked; non-zero if | |
155 | the object was already marked, or if, for any other reason, | |
156 | pointers in this data structure should not be traversed. */ | |
3cce094d | 157 | int ggc_set_mark PARAMS ((const void *)); |
0a25f1f5 | 158 | |
0a25f1f5 RH |
159 | /* Callbacks to the languages. */ |
160 | ||
161 | /* This is the language's opportunity to mark nodes held through | |
162 | the lang_specific hooks in the tree. */ | |
3fe41456 | 163 | void lang_mark_tree PARAMS ((union tree_node *)); |
0a25f1f5 | 164 | |
87ff9c8e RH |
165 | /* The FALSE_LABEL_STACK, declared in except.h, has |
166 | language-dependent semantics. Each front-end should define this | |
167 | function appropriately. */ | |
3fe41456 | 168 | void lang_mark_false_label_stack PARAMS ((struct label_node *)); |
87ff9c8e | 169 | |
0a25f1f5 RH |
170 | /* Mark functions for various structs scattered about. */ |
171 | ||
3fe41456 KG |
172 | void mark_eh_status PARAMS ((struct eh_status *)); |
173 | void mark_emit_status PARAMS ((struct emit_status *)); | |
174 | void mark_expr_status PARAMS ((struct expr_status *)); | |
175 | void mark_stmt_status PARAMS ((struct stmt_status *)); | |
176 | void mark_varasm_status PARAMS ((struct varasm_status *)); | |
177 | void mark_optab PARAMS ((void *)); | |
3277221c MM |
178 | |
179 | /* Statistics. */ | |
180 | ||
181 | /* This structure contains the statistics common to all collectors. | |
182 | Particular collectors can extend this structure. */ | |
183 | typedef struct ggc_statistics | |
184 | { | |
185 | /* The Ith element is the number of nodes allocated with code I. */ | |
186 | unsigned num_trees[256]; | |
187 | /* The Ith element is the number of bytes allocated by nodes with | |
188 | code I. */ | |
189 | size_t size_trees[256]; | |
190 | /* The Ith element is the number of nodes allocated with code I. */ | |
191 | unsigned num_rtxs[256]; | |
192 | /* The Ith element is the number of bytes allocated by nodes with | |
193 | code I. */ | |
194 | size_t size_rtxs[256]; | |
3277221c MM |
195 | /* The total size of the tree nodes allocated. */ |
196 | size_t total_size_trees; | |
3277221c MM |
197 | /* The total size of the RTL nodes allocated. */ |
198 | size_t total_size_rtxs; | |
63408827 RH |
199 | /* The total number of tree nodes allocated. */ |
200 | unsigned total_num_trees; | |
201 | /* The total number of RTL nodes allocated. */ | |
202 | unsigned total_num_rtxs; | |
3277221c MM |
203 | } ggc_statistics; |
204 | ||
205 | /* Return the number of bytes allocated at the indicated address. */ | |
3cce094d | 206 | size_t ggc_get_size PARAMS ((const void *)); |
3277221c MM |
207 | |
208 | /* Used by the various collectors to gather and print statistics that | |
209 | do not depend on the collector in use. */ | |
3fe41456 | 210 | void ggc_print_statistics PARAMS ((FILE *, ggc_statistics *)); |
c6991660 KG |
211 | |
212 | /* Print allocation statistics. */ | |
213 | extern void ggc_page_print_statistics PARAMS ((void)); |