comparison gcc/ggc.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Garbage collection for the GNU compiler. 1 /* Garbage collection for the GNU compiler.
2 2
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 3 Copyright (C) 1998-2017 Free Software Foundation, Inc.
4 2008, 2009, 2010 Free Software Foundation, Inc.
5 4
6 This file is part of GCC. 5 This file is part of GCC.
7 6
8 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free 8 the terms of the GNU General Public License as published by the Free
19 along with GCC; see the file COPYING3. If not see 18 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */ 19 <http://www.gnu.org/licenses/>. */
21 20
22 #ifndef GCC_GGC_H 21 #ifndef GCC_GGC_H
23 #define GCC_GGC_H 22 #define GCC_GGC_H
24 #include "statistics.h"
25 23
26 /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with 24 /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with
27 an external gc library that might be linked in. */ 25 an external gc library that might be linked in. */
28 26
29 /* Constants for general use. */
30 extern const char empty_string[]; /* empty string */
31
32 /* Internal functions and data structures used by the GTY 27 /* Internal functions and data structures used by the GTY
33 machinery, including the generated gt*.[hc] files. */ 28 machinery, including the generated gt*.[hc] files. */
34
35 /* The first parameter is a pointer to a pointer, the second a cookie. */
36 typedef void (*gt_pointer_operator) (void *, void *);
37 29
38 #include "gtype-desc.h" 30 #include "gtype-desc.h"
39 31
40 /* One of these applies its third parameter (with cookie in the fourth 32 /* One of these applies its third parameter (with cookie in the fourth
41 parameter) to each pointer in the object pointed to by the first 33 parameter) to each pointer in the object pointed to by the first
50 the fourth parameter. */ 42 the fourth parameter. */
51 typedef void (*gt_handle_reorder) (void *, void *, gt_pointer_operator, 43 typedef void (*gt_handle_reorder) (void *, void *, gt_pointer_operator,
52 void *); 44 void *);
53 45
54 /* Used by the gt_pch_n_* routines. Register an object in the hash table. */ 46 /* Used by the gt_pch_n_* routines. Register an object in the hash table. */
55 extern int gt_pch_note_object (void *, void *, gt_note_pointers, 47 extern int gt_pch_note_object (void *, void *, gt_note_pointers);
56 enum gt_types_enum);
57 48
58 /* Used by the gt_pch_n_* routines. Register that an object has a reorder 49 /* Used by the gt_pch_n_* routines. Register that an object has a reorder
59 function. */ 50 function. */
60 extern void gt_pch_note_reorder (void *, void *, gt_handle_reorder); 51 extern void gt_pch_note_reorder (void *, void *, gt_handle_reorder);
52
53 /* generated function to clear caches in gc memory. */
54 extern void gt_clear_caches ();
61 55
62 /* Mark the object in the first parameter and anything it points to. */ 56 /* Mark the object in the first parameter and anything it points to. */
63 typedef void (*gt_pointer_walker) (void *); 57 typedef void (*gt_pointer_walker) (void *);
64 58
65 /* Structures for the easy way to mark roots. 59 /* Structures for the easy way to mark roots.
73 }; 67 };
74 #define LAST_GGC_ROOT_TAB { NULL, 0, 0, NULL, NULL } 68 #define LAST_GGC_ROOT_TAB { NULL, 0, 0, NULL, NULL }
75 /* Pointers to arrays of ggc_root_tab, terminated by NULL. */ 69 /* Pointers to arrays of ggc_root_tab, terminated by NULL. */
76 extern const struct ggc_root_tab * const gt_ggc_rtab[]; 70 extern const struct ggc_root_tab * const gt_ggc_rtab[];
77 extern const struct ggc_root_tab * const gt_ggc_deletable_rtab[]; 71 extern const struct ggc_root_tab * const gt_ggc_deletable_rtab[];
78 extern const struct ggc_root_tab * const gt_pch_cache_rtab[];
79 extern const struct ggc_root_tab * const gt_pch_scalar_rtab[]; 72 extern const struct ggc_root_tab * const gt_pch_scalar_rtab[];
80
81 /* Structure for hash table cache marking. */
82 struct htab;
83 struct ggc_cache_tab {
84 struct htab * *base;
85 size_t nelt;
86 size_t stride;
87 gt_pointer_walker cb;
88 gt_pointer_walker pchw;
89 int (*marked_p) (const void *);
90 };
91 #define LAST_GGC_CACHE_TAB { NULL, 0, 0, NULL, NULL, NULL }
92 /* Pointers to arrays of ggc_cache_tab, terminated by NULL. */
93 extern const struct ggc_cache_tab * const gt_ggc_cache_rtab[];
94 73
95 /* If EXPR is not NULL and previously unmarked, mark it and evaluate 74 /* If EXPR is not NULL and previously unmarked, mark it and evaluate
96 to true. Otherwise evaluate to false. */ 75 to true. Otherwise evaluate to false. */
97 #define ggc_test_and_set_mark(EXPR) \ 76 #define ggc_test_and_set_mark(EXPR) \
98 ((EXPR) != NULL && ((void *) (EXPR)) != (void *) 1 && ! ggc_set_mark (EXPR)) 77 ((EXPR) != NULL && ((void *) (EXPR)) != (void *) 1 && ! ggc_set_mark (EXPR))
120 extern void gt_pch_n_S (const void *); 99 extern void gt_pch_n_S (const void *);
121 extern void gt_ggc_m_S (const void *); 100 extern void gt_ggc_m_S (const void *);
122 101
123 /* End of GTY machinery API. */ 102 /* End of GTY machinery API. */
124 103
125 struct alloc_zone;
126
127 /* Initialize the string pool. */ 104 /* Initialize the string pool. */
128 extern void init_stringpool (void); 105 extern void init_stringpool (void);
129 106
130 /* Initialize the garbage collector. */ 107 /* Initialize the garbage collector. */
131 extern void init_ggc (void); 108 extern void init_ggc (void);
141 118
142 119
143 /* Allocation. */ 120 /* Allocation. */
144 121
145 /* The internal primitive. */ 122 /* The internal primitive. */
146 extern void *ggc_internal_alloc_stat (size_t MEM_STAT_DECL); 123 extern void *ggc_internal_alloc (size_t, void (*)(void *), size_t,
147 124 size_t CXX_MEM_STAT_INFO)
148 #define ggc_internal_alloc(s) ggc_internal_alloc_stat (s MEM_STAT_INFO) 125 ATTRIBUTE_MALLOC;
149 126
150 /* Allocate an object of the specified type and size. */ 127 inline void *
151 extern void *ggc_alloc_typed_stat (enum gt_types_enum, size_t MEM_STAT_DECL); 128 ggc_internal_alloc (size_t s CXX_MEM_STAT_INFO)
152 129 {
153 #define ggc_alloc_typed(s, z) ggc_alloc_typed_stat (s, z MEM_STAT_INFO) 130 return ggc_internal_alloc (s, NULL, 0, 1 PASS_MEM_STAT);
131 }
132
133 extern size_t ggc_round_alloc_size (size_t requested_size);
154 134
155 /* Allocates cleared memory. */ 135 /* Allocates cleared memory. */
156 extern void *ggc_internal_cleared_alloc_stat (size_t MEM_STAT_DECL); 136 extern void *ggc_internal_cleared_alloc (size_t, void (*)(void *),
137 size_t, size_t
138 CXX_MEM_STAT_INFO) ATTRIBUTE_MALLOC;
139
140 inline void *
141 ggc_internal_cleared_alloc (size_t s CXX_MEM_STAT_INFO)
142 {
143 return ggc_internal_cleared_alloc (s, NULL, 0, 1 PASS_MEM_STAT);
144 }
157 145
158 /* Resize a block. */ 146 /* Resize a block. */
159 extern void *ggc_realloc_stat (void *, size_t MEM_STAT_DECL); 147 extern void *ggc_realloc (void *, size_t CXX_MEM_STAT_INFO);
160 148
161 /* Free a block. To be used when known for certain it's not reachable. */ 149 /* Free a block. To be used when known for certain it's not reachable. */
162 extern void ggc_free (void *); 150 extern void ggc_free (void *);
163 151
164 extern void ggc_record_overhead (size_t, size_t, void * MEM_STAT_DECL);
165 extern void ggc_free_overhead (void *);
166 extern void ggc_prune_overhead_list (void);
167
168 extern void dump_ggc_loc_statistics (bool); 152 extern void dump_ggc_loc_statistics (bool);
169 153
170 /* Reallocators. */ 154 /* Reallocator. */
171 #define GGC_RESIZEVEC(T, P, N) \ 155 #define GGC_RESIZEVEC(T, P, N) \
172 ((T *) ggc_realloc_stat ((P), (N) * sizeof (T) MEM_STAT_INFO)) 156 ((T *) ggc_realloc ((P), (N) * sizeof (T) MEM_STAT_INFO))
173 157
174 #define GGC_RESIZEVAR(T, P, N) \ 158 template<typename T>
175 ((T *) ggc_realloc_stat ((P), (N) MEM_STAT_INFO)) 159 void
176 160 finalize (void *p)
177 static inline void * 161 {
178 ggc_internal_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL) 162 static_cast<T *> (p)->~T ();
179 { 163 }
180 return ggc_internal_alloc_stat (c * s PASS_MEM_STAT); 164
181 } 165 template<typename T>
182 166 inline bool
183 static inline void * 167 need_finalization_p ()
184 ggc_internal_cleared_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL) 168 {
185 { 169 #if GCC_VERSION >= 4003
186 return ggc_internal_cleared_alloc_stat (c * s PASS_MEM_STAT); 170 return !__has_trivial_destructor (T);
187 } 171 #else
188 172 return true;
189 #define ggc_internal_cleared_vec_alloc(s, c) \ 173 #endif
190 (ggc_internal_cleared_vec_alloc_stat ((s), (c) MEM_STAT_INFO)) 174 }
191 175
192 static inline void * 176 template<typename T>
193 ggc_alloc_atomic_stat (size_t s MEM_STAT_DECL) 177 inline T *
194 { 178 ggc_alloc (ALONE_CXX_MEM_STAT_INFO)
195 return ggc_internal_alloc_stat (s PASS_MEM_STAT); 179 {
196 } 180 if (need_finalization_p<T> ())
197 181 return static_cast<T *> (ggc_internal_alloc (sizeof (T), finalize<T>, 0, 1
198 #define ggc_alloc_atomic(S) (ggc_alloc_atomic_stat ((S) MEM_STAT_INFO)) 182 PASS_MEM_STAT));
199 183 else
200 #define ggc_alloc_cleared_atomic(S) \ 184 return static_cast<T *> (ggc_internal_alloc (sizeof (T), NULL, 0, 1
201 (ggc_internal_cleared_alloc_stat ((S) MEM_STAT_INFO)) 185 PASS_MEM_STAT));
202 186 }
203 extern void * ggc_cleared_alloc_htab_ignore_args (size_t, size_t); 187
204 188 template<typename T>
205 extern void * ggc_cleared_alloc_ptr_array_two_args (size_t, size_t); 189 inline T *
206 190 ggc_cleared_alloc (ALONE_CXX_MEM_STAT_INFO)
207 #define htab_create_ggc(SIZE, HASH, EQ, DEL) \ 191 {
208 htab_create_typed_alloc (SIZE, HASH, EQ, DEL, \ 192 if (need_finalization_p<T> ())
209 ggc_cleared_alloc_htab_ignore_args, \ 193 return static_cast<T *> (ggc_internal_cleared_alloc (sizeof (T),
210 ggc_cleared_alloc_ptr_array_two_args, \ 194 finalize<T>, 0, 1
211 ggc_free) 195 PASS_MEM_STAT));
212 196 else
213 #define splay_tree_new_ggc(COMPARE, ALLOC_TREE, ALLOC_NODE) \ 197 return static_cast<T *> (ggc_internal_cleared_alloc (sizeof (T), NULL, 0, 1
214 splay_tree_new_typed_alloc (COMPARE, NULL, NULL, &ALLOC_TREE, &ALLOC_NODE, \ 198 PASS_MEM_STAT));
215 &ggc_splay_dont_free, NULL) 199 }
216 200
217 extern void *ggc_splay_alloc (enum gt_types_enum, int, void *); 201 template<typename T>
218 202 inline T *
219 extern void ggc_splay_dont_free (void *, void *); 203 ggc_vec_alloc (size_t c CXX_MEM_STAT_INFO)
204 {
205 if (need_finalization_p<T> ())
206 return static_cast<T *> (ggc_internal_alloc (c * sizeof (T), finalize<T>,
207 sizeof (T), c PASS_MEM_STAT));
208 else
209 return static_cast<T *> (ggc_internal_alloc (c * sizeof (T), NULL, 0, 0
210 PASS_MEM_STAT));
211 }
212
213 template<typename T>
214 inline T *
215 ggc_cleared_vec_alloc (size_t c CXX_MEM_STAT_INFO)
216 {
217 if (need_finalization_p<T> ())
218 return static_cast<T *> (ggc_internal_cleared_alloc (c * sizeof (T),
219 finalize<T>,
220 sizeof (T), c
221 PASS_MEM_STAT));
222 else
223 return static_cast<T *> (ggc_internal_cleared_alloc (c * sizeof (T), NULL,
224 0, 0 PASS_MEM_STAT));
225 }
226
227 inline void *
228 ggc_alloc_atomic (size_t s CXX_MEM_STAT_INFO)
229 {
230 return ggc_internal_alloc (s PASS_MEM_STAT);
231 }
220 232
221 /* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS. 233 /* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS.
222 If LENGTH is -1, then CONTENTS is assumed to be a 234 If LENGTH is -1, then CONTENTS is assumed to be a
223 null-terminated string and the memory sized accordingly. */ 235 null-terminated string and the memory sized accordingly. */
224 extern const char *ggc_alloc_string_stat (const char *contents, int length 236 extern const char *ggc_alloc_string (const char *contents, int length
225 MEM_STAT_DECL); 237 CXX_MEM_STAT_INFO);
226
227 #define ggc_alloc_string(c, l) ggc_alloc_string_stat (c, l MEM_STAT_INFO)
228 238
229 /* Make a copy of S, in GC-able memory. */ 239 /* Make a copy of S, in GC-able memory. */
230 #define ggc_strdup(S) ggc_alloc_string_stat ((S), -1 MEM_STAT_INFO) 240 #define ggc_strdup(S) ggc_alloc_string ((S), -1 MEM_STAT_INFO)
231 241
232 /* Invoke the collector. Garbage collection occurs only when this 242 /* Invoke the collector. Garbage collection occurs only when this
233 function is called, not during allocations. */ 243 function is called, not during allocations. */
234 extern void ggc_collect (void); 244 extern void ggc_collect (void);
235 245
246 /* Assume that all GGC memory is reachable and grow the limits for next collection. */
247 extern void ggc_grow (void);
248
236 /* Register an additional root table. This can be useful for some 249 /* Register an additional root table. This can be useful for some
237 plugins. Does nothing if the passed pointer is NULL. */ 250 plugins. Does nothing if the passed pointer is NULL. */
238 extern void ggc_register_root_tab (const struct ggc_root_tab *); 251 extern void ggc_register_root_tab (const struct ggc_root_tab *);
239
240 /* Register an additional cache table. This can be useful for some
241 plugins. Does nothing if the passed pointer is NULL. */
242 extern void ggc_register_cache_tab (const struct ggc_cache_tab *);
243 252
244 /* Read objects previously saved with gt_pch_save from F. */ 253 /* Read objects previously saved with gt_pch_save from F. */
245 extern void gt_pch_restore (FILE *f); 254 extern void gt_pch_restore (FILE *f);
246 255
247 /* Statistics. */ 256 /* Statistics. */
252 extern void stringpool_statistics (void); 261 extern void stringpool_statistics (void);
253 262
254 /* Heuristics. */ 263 /* Heuristics. */
255 extern void init_ggc_heuristics (void); 264 extern void init_ggc_heuristics (void);
256 265
257 /* Zone collection. */ 266 #define ggc_alloc_rtvec_sized(NELT) \
258 267 (rtvec_def *) ggc_internal_alloc (sizeof (struct rtvec_def) \
259 /* For regular rtl allocations. */ 268 + ((NELT) - 1) * sizeof (rtx)) \
260 extern struct alloc_zone rtl_zone;
261
262 /* For regular tree allocations. */
263 extern struct alloc_zone tree_zone;
264
265 /* For IDENTIFIER_NODE allocations. */
266 extern struct alloc_zone tree_id_zone;
267
268 #define ggc_alloc_rtvec_sized(NELT) \
269 (ggc_alloc_zone_vec_rtvec_def (sizeof (rtx), \
270 sizeof (struct rtvec_def) + ((NELT) - 1), \
271 &rtl_zone))
272
273 #if defined (GGC_ZONE) && !defined (GENERATOR_FILE)
274
275 /* Allocate an object into the specified allocation zone. */
276 extern void *ggc_internal_alloc_zone_stat (size_t,
277 struct alloc_zone * MEM_STAT_DECL);
278
279 extern void *ggc_internal_cleared_alloc_zone_stat (size_t,
280 struct alloc_zone * MEM_STAT_DECL);
281
282 static inline void *
283 ggc_internal_zone_alloc_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL)
284 {
285 return ggc_internal_alloc_zone_stat (s, z PASS_MEM_STAT);
286 }
287
288 static inline void *
289 ggc_internal_zone_cleared_alloc_stat (struct alloc_zone * z, size_t s
290 MEM_STAT_DECL)
291 {
292 return ggc_internal_cleared_alloc_zone_stat (s, z PASS_MEM_STAT);
293 }
294
295 static inline void *
296 ggc_internal_zone_vec_alloc_stat (struct alloc_zone * z, size_t s, size_t n
297 MEM_STAT_DECL)
298 {
299 return ggc_internal_alloc_zone_stat (s * n, z PASS_MEM_STAT);
300 }
301
302
303 #else
304
305 static inline void *
306 ggc_internal_zone_alloc_stat (struct alloc_zone * z ATTRIBUTE_UNUSED,
307 size_t s MEM_STAT_DECL)
308 {
309 return ggc_internal_alloc_stat (s PASS_MEM_STAT);
310 }
311
312 static inline void *
313 ggc_internal_zone_cleared_alloc_stat (struct alloc_zone * z ATTRIBUTE_UNUSED,
314 size_t s MEM_STAT_DECL)
315 {
316 return ggc_internal_cleared_alloc_stat (s PASS_MEM_STAT);
317 }
318
319 static inline void *
320 ggc_internal_zone_vec_alloc_stat (struct alloc_zone * z ATTRIBUTE_UNUSED,
321 size_t s, size_t n MEM_STAT_DECL)
322 {
323 return ggc_internal_vec_alloc_stat (s, n PASS_MEM_STAT);
324 }
325
326 #endif
327 269
328 /* Memory statistics passing versions of some allocators. Too few of them to 270 /* Memory statistics passing versions of some allocators. Too few of them to
329 make gengtype produce them, so just define the needed ones here. */ 271 make gengtype produce them, so just define the needed ones here. */
330 static inline struct rtx_def * 272 inline struct rtx_def *
331 ggc_alloc_zone_rtx_def_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL) 273 ggc_alloc_rtx_def_stat (size_t s CXX_MEM_STAT_INFO)
332 { 274 {
333 return (struct rtx_def *) ggc_internal_zone_alloc_stat (z, s PASS_MEM_STAT); 275 return (struct rtx_def *) ggc_internal_alloc (s PASS_MEM_STAT);
334 } 276 }
335 277
336 static inline union tree_node * 278 inline union tree_node *
337 ggc_alloc_zone_tree_node_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL) 279 ggc_alloc_tree_node_stat (size_t s CXX_MEM_STAT_INFO)
338 { 280 {
339 return (union tree_node *) ggc_internal_zone_alloc_stat (z, s PASS_MEM_STAT); 281 return (union tree_node *) ggc_internal_alloc (s PASS_MEM_STAT);
340 } 282 }
341 283
342 static inline union tree_node * 284 inline union tree_node *
343 ggc_alloc_zone_cleared_tree_node_stat (struct alloc_zone * z, size_t s 285 ggc_alloc_cleared_tree_node_stat (size_t s CXX_MEM_STAT_INFO)
344 MEM_STAT_DECL) 286 {
345 { 287 return (union tree_node *) ggc_internal_cleared_alloc (s PASS_MEM_STAT);
346 return (union tree_node *) 288 }
347 ggc_internal_zone_cleared_alloc_stat (z, s PASS_MEM_STAT); 289
348 } 290 inline gimple *
349 291 ggc_alloc_cleared_gimple_statement_stat (size_t s CXX_MEM_STAT_INFO)
350 static inline union gimple_statement_d * 292 {
351 ggc_alloc_cleared_gimple_statement_d_stat (size_t s MEM_STAT_DECL) 293 return (gimple *) ggc_internal_cleared_alloc (s PASS_MEM_STAT);
352 { 294 }
353 return (union gimple_statement_d *) 295
354 ggc_internal_cleared_alloc_stat (s PASS_MEM_STAT); 296 inline void
297 gt_ggc_mx (const char *s)
298 {
299 ggc_test_and_set_mark (const_cast<char *> (s));
300 }
301
302 inline void
303 gt_pch_nx (const char *)
304 {
305 }
306
307 inline void
308 gt_ggc_mx (int)
309 {
310 }
311
312 inline void
313 gt_pch_nx (int)
314 {
315 }
316
317 inline void
318 gt_pch_nx (unsigned int)
319 {
355 } 320 }
356 321
357 #endif 322 #endif