comparison gcc/ggc.h @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents 77e2b8dfacca
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
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, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007,
4 2008, 2009 Free Software Foundation, Inc. 4 2008, 2009, 2010 Free Software Foundation, Inc.
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it under 8 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 9 the terms of the GNU General Public License as published by the Free
26 /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with 26 /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with
27 an external gc library that might be linked in. */ 27 an external gc library that might be linked in. */
28 28
29 /* Constants for general use. */ 29 /* Constants for general use. */
30 extern const char empty_string[]; /* empty string */ 30 extern const char empty_string[]; /* empty string */
31 extern const char digit_vector[]; /* "0" .. "9" */
32 #define digit_string(d) (digit_vector + ((d) * 2))
33 31
34 /* Internal functions and data structures used by the GTY 32 /* Internal functions and data structures used by the GTY
35 machinery. */ 33 machinery, including the generated gt*.[hc] files. */
36 34
37 /* The first parameter is a pointer to a pointer, the second a cookie. */ 35 /* The first parameter is a pointer to a pointer, the second a cookie. */
38 typedef void (*gt_pointer_operator) (void *, void *); 36 typedef void (*gt_pointer_operator) (void *, void *);
39 37
40 #include "gtype-desc.h" 38 #include "gtype-desc.h"
116 /* Return 1 if P has been marked, zero otherwise. 114 /* Return 1 if P has been marked, zero otherwise.
117 P must have been allocated by the GC allocator; it mustn't point to 115 P must have been allocated by the GC allocator; it mustn't point to
118 static objects, stack variables, or memory allocated with malloc. */ 116 static objects, stack variables, or memory allocated with malloc. */
119 extern int ggc_marked_p (const void *); 117 extern int ggc_marked_p (const void *);
120 118
121 /* Mark the entries in the string pool. */
122 extern void ggc_mark_stringpool (void);
123
124 /* Purge the entries in the string pool. */
125 extern void ggc_purge_stringpool (void);
126
127 /* Call ggc_set_mark on all the roots. */
128
129 extern void ggc_mark_roots (void);
130
131 /* Save and restore the string pool entries for PCH. */
132
133 extern void gt_pch_save_stringpool (void);
134 extern void gt_pch_fixup_stringpool (void);
135 extern void gt_pch_restore_stringpool (void);
136
137 /* PCH and GGC handling for strings, mostly trivial. */ 119 /* PCH and GGC handling for strings, mostly trivial. */
138
139 extern void gt_pch_p_S (void *, void *, gt_pointer_operator, void *);
140 extern void gt_pch_n_S (const void *); 120 extern void gt_pch_n_S (const void *);
141 extern void gt_ggc_m_S (const void *); 121 extern void gt_ggc_m_S (const void *);
142 122
123 /* End of GTY machinery API. */
124
125 struct alloc_zone;
126
143 /* Initialize the string pool. */ 127 /* Initialize the string pool. */
144 extern void init_stringpool (void); 128 extern void init_stringpool (void);
145 129
146 /* A GC implementation must provide these functions. They are internal
147 to the GC system. */
148
149 /* Forward declare the zone structure. Only ggc_zone implements this. */
150 struct alloc_zone;
151
152 /* Initialize the garbage collector. */ 130 /* Initialize the garbage collector. */
153 extern void init_ggc (void); 131 extern void init_ggc (void);
154
155 /* Start a new GGC zone. */
156 extern struct alloc_zone *new_ggc_zone (const char *);
157
158 /* Free a complete GGC zone, destroying everything in it. */
159 extern void destroy_ggc_zone (struct alloc_zone *);
160
161 struct ggc_pch_data;
162
163 /* Return a new ggc_pch_data structure. */
164 extern struct ggc_pch_data *init_ggc_pch (void);
165
166 /* The second parameter and third parameters give the address and size
167 of an object. Update the ggc_pch_data structure with as much of
168 that information as is necessary. The bool argument should be true
169 if the object is a string. */
170 extern void ggc_pch_count_object (struct ggc_pch_data *, void *, size_t, bool,
171 enum gt_types_enum);
172
173 /* Return the total size of the data to be written to hold all
174 the objects previously passed to ggc_pch_count_object. */
175 extern size_t ggc_pch_total_size (struct ggc_pch_data *);
176
177 /* The objects, when read, will most likely be at the address
178 in the second parameter. */
179 extern void ggc_pch_this_base (struct ggc_pch_data *, void *);
180
181 /* Assuming that the objects really do end up at the address
182 passed to ggc_pch_this_base, return the address of this object.
183 The bool argument should be true if the object is a string. */
184 extern char *ggc_pch_alloc_object (struct ggc_pch_data *, void *, size_t, bool,
185 enum gt_types_enum);
186
187 /* Write out any initial information required. */
188 extern void ggc_pch_prepare_write (struct ggc_pch_data *, FILE *);
189 /* Write out this object, including any padding. The last argument should be
190 true if the object is a string. */
191 extern void ggc_pch_write_object (struct ggc_pch_data *, FILE *, void *,
192 void *, size_t, bool);
193 /* All objects have been written, write out any final information
194 required. */
195 extern void ggc_pch_finish (struct ggc_pch_data *, FILE *);
196
197 /* A PCH file has just been read in at the address specified second
198 parameter. Set up the GC implementation for the new objects. */
199 extern void ggc_pch_read (FILE *, void *);
200
201
202 /* Allocation. */
203
204 /* When set, ggc_collect will do collection. */
205 extern bool ggc_force_collect;
206 132
207 /* When true, identifier nodes are considered as GC roots. When 133 /* When true, identifier nodes are considered as GC roots. When
208 false, identifier nodes are treated like any other GC-allocated 134 false, identifier nodes are treated like any other GC-allocated
209 object, and the identifier hash table is treated as a weak 135 object, and the identifier hash table is treated as a weak
210 hash. */ 136 hash. */
211 extern bool ggc_protect_identifiers; 137 extern bool ggc_protect_identifiers;
212 138
139 /* Write out all GCed objects to F. */
140 extern void gt_pch_save (FILE *f);
141
142
143 /* Allocation. */
144
213 /* The internal primitive. */ 145 /* The internal primitive. */
214 extern void *ggc_alloc_stat (size_t MEM_STAT_DECL); 146 extern void *ggc_internal_alloc_stat (size_t MEM_STAT_DECL);
215 #define ggc_alloc(s) ggc_alloc_stat (s MEM_STAT_INFO) 147
148 #define ggc_internal_alloc(s) ggc_internal_alloc_stat (s MEM_STAT_INFO)
149
216 /* Allocate an object of the specified type and size. */ 150 /* Allocate an object of the specified type and size. */
217 extern void *ggc_alloc_typed_stat (enum gt_types_enum, size_t MEM_STAT_DECL); 151 extern void *ggc_alloc_typed_stat (enum gt_types_enum, size_t MEM_STAT_DECL);
218 #define ggc_alloc_typed(s,z) ggc_alloc_typed_stat (s,z MEM_STAT_INFO) 152
219 /* Like ggc_alloc, but allocates cleared memory. */ 153 #define ggc_alloc_typed(s, z) ggc_alloc_typed_stat (s, z MEM_STAT_INFO)
220 extern void *ggc_alloc_cleared_stat (size_t MEM_STAT_DECL); 154
221 #define ggc_alloc_cleared(s) ggc_alloc_cleared_stat (s MEM_STAT_INFO) 155 /* Allocates cleared memory. */
156 extern void *ggc_internal_cleared_alloc_stat (size_t MEM_STAT_DECL);
157
222 /* Resize a block. */ 158 /* Resize a block. */
223 extern void *ggc_realloc_stat (void *, size_t MEM_STAT_DECL); 159 extern void *ggc_realloc_stat (void *, size_t MEM_STAT_DECL);
224 #define ggc_realloc(s,z) ggc_realloc_stat (s,z MEM_STAT_INFO) 160
225 /* Like ggc_alloc_cleared, but performs a multiplication. */
226 extern void *ggc_calloc (size_t, size_t);
227 /* Free a block. To be used when known for certain it's not reachable. */ 161 /* Free a block. To be used when known for certain it's not reachable. */
228 extern void ggc_free (void *); 162 extern void ggc_free (void *);
229 163
230 extern void ggc_record_overhead (size_t, size_t, void * MEM_STAT_DECL); 164 extern void ggc_record_overhead (size_t, size_t, void * MEM_STAT_DECL);
231 extern void ggc_free_overhead (void *); 165 extern void ggc_free_overhead (void *);
232 extern void ggc_prune_overhead_list (void); 166 extern void ggc_prune_overhead_list (void);
233 167
234 extern void dump_ggc_loc_statistics (bool); 168 extern void dump_ggc_loc_statistics (bool);
235 169
236 /* Type-safe, C++-friendly versions of ggc_alloc() and gcc_calloc(). */ 170 /* Reallocators. */
237 #define GGC_NEW(T) ((T *) ggc_alloc (sizeof (T))) 171 #define GGC_RESIZEVEC(T, P, N) \
238 #define GGC_CNEW(T) ((T *) ggc_alloc_cleared (sizeof (T))) 172 ((T *) ggc_realloc_stat ((P), (N) * sizeof (T) MEM_STAT_INFO))
239 #define GGC_NEWVEC(T, N) ((T *) ggc_alloc ((N) * sizeof(T))) 173
240 #define GGC_CNEWVEC(T, N) ((T *) ggc_alloc_cleared ((N) * sizeof(T))) 174 #define GGC_RESIZEVAR(T, P, N) \
241 #define GGC_RESIZEVEC(T, P, N) ((T *) ggc_realloc ((P), (N) * sizeof (T))) 175 ((T *) ggc_realloc_stat ((P), (N) MEM_STAT_INFO))
242 #define GGC_NEWVAR(T, S) ((T *) ggc_alloc ((S))) 176
243 #define GGC_CNEWVAR(T, S) ((T *) ggc_alloc_cleared ((S))) 177 static inline void *
244 #define GGC_RESIZEVAR(T, P, N) ((T *) ggc_realloc ((P), (N))) 178 ggc_internal_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL)
245 179 {
246 #define ggc_alloc_rtvec(NELT) \ 180 return ggc_internal_alloc_stat (c * s PASS_MEM_STAT);
247 ((rtvec) ggc_alloc_zone (sizeof (struct rtvec_def) + ((NELT) - 1) \ 181 }
248 * sizeof (rtx), &rtl_zone)) 182
249 183 static inline void *
250 #define ggc_alloc_tree(LENGTH) ((tree) ggc_alloc_zone (LENGTH, &tree_zone)) 184 ggc_internal_cleared_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL)
185 {
186 return ggc_internal_cleared_alloc_stat (c * s PASS_MEM_STAT);
187 }
188
189 #define ggc_internal_cleared_vec_alloc(s, c) \
190 (ggc_internal_cleared_vec_alloc_stat ((s), (c) MEM_STAT_INFO))
191
192 static inline void *
193 ggc_alloc_atomic_stat (size_t s MEM_STAT_DECL)
194 {
195 return ggc_internal_alloc_stat (s PASS_MEM_STAT);
196 }
197
198 #define ggc_alloc_atomic(S) (ggc_alloc_atomic_stat ((S) MEM_STAT_INFO))
199
200 #define ggc_alloc_cleared_atomic(S) \
201 (ggc_internal_cleared_alloc_stat ((S) MEM_STAT_INFO))
202
203 extern void * ggc_cleared_alloc_htab_ignore_args (size_t, size_t);
204
205 extern void * ggc_cleared_alloc_ptr_array_two_args (size_t, size_t);
251 206
252 #define htab_create_ggc(SIZE, HASH, EQ, DEL) \ 207 #define htab_create_ggc(SIZE, HASH, EQ, DEL) \
253 htab_create_alloc (SIZE, HASH, EQ, DEL, ggc_calloc, ggc_free) 208 htab_create_typed_alloc (SIZE, HASH, EQ, DEL, \
254 209 ggc_cleared_alloc_htab_ignore_args, \
255 #define splay_tree_new_ggc(COMPARE) \ 210 ggc_cleared_alloc_ptr_array_two_args, \
256 splay_tree_new_with_allocator (COMPARE, NULL, NULL, \ 211 ggc_free)
257 &ggc_splay_alloc, &ggc_splay_dont_free, \ 212
258 NULL) 213 #define splay_tree_new_ggc(COMPARE, ALLOC_TREE, ALLOC_NODE) \
259 extern void *ggc_splay_alloc (int, void *); 214 splay_tree_new_typed_alloc (COMPARE, NULL, NULL, &ALLOC_TREE, &ALLOC_NODE, \
215 &ggc_splay_dont_free, NULL)
216
217 extern void *ggc_splay_alloc (enum gt_types_enum, int, void *);
218
260 extern void ggc_splay_dont_free (void *, void *); 219 extern void ggc_splay_dont_free (void *, void *);
261 220
262 /* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS. 221 /* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS.
263 If LENGTH is -1, then CONTENTS is assumed to be a 222 If LENGTH is -1, then CONTENTS is assumed to be a
264 null-terminated string and the memory sized accordingly. */ 223 null-terminated string and the memory sized accordingly. */
265 extern const char *ggc_alloc_string (const char *contents, int length); 224 extern const char *ggc_alloc_string_stat (const char *contents, int length
225 MEM_STAT_DECL);
226
227 #define ggc_alloc_string(c, l) ggc_alloc_string_stat (c, l MEM_STAT_INFO)
266 228
267 /* Make a copy of S, in GC-able memory. */ 229 /* Make a copy of S, in GC-able memory. */
268 #define ggc_strdup(S) ggc_alloc_string((S), -1) 230 #define ggc_strdup(S) ggc_alloc_string_stat ((S), -1 MEM_STAT_INFO)
269 231
270 /* Invoke the collector. Garbage collection occurs only when this 232 /* Invoke the collector. Garbage collection occurs only when this
271 function is called, not during allocations. */ 233 function is called, not during allocations. */
272 extern void ggc_collect (void); 234 extern void ggc_collect (void);
273 235
276 extern void ggc_register_root_tab (const struct ggc_root_tab *); 238 extern void ggc_register_root_tab (const struct ggc_root_tab *);
277 239
278 /* Register an additional cache table. This can be useful for some 240 /* Register an additional cache table. This can be useful for some
279 plugins. Does nothing if the passed pointer is NULL. */ 241 plugins. Does nothing if the passed pointer is NULL. */
280 extern void ggc_register_cache_tab (const struct ggc_cache_tab *); 242 extern void ggc_register_cache_tab (const struct ggc_cache_tab *);
281
282 /* Return the number of bytes allocated at the indicated address. */
283 extern size_t ggc_get_size (const void *);
284
285 /* Write out all GCed objects to F. */
286 extern void gt_pch_save (FILE *f);
287 243
288 /* Read objects previously saved with gt_pch_save from F. */ 244 /* Read objects previously saved with gt_pch_save from F. */
289 extern void gt_pch_restore (FILE *f); 245 extern void gt_pch_restore (FILE *f);
290 246
291 /* Statistics. */ 247 /* Statistics. */
292 248
293 /* This structure contains the statistics common to all collectors.
294 Particular collectors can extend this structure. */
295 typedef struct ggc_statistics
296 {
297 /* At present, we don't really gather any interesting statistics. */
298 int unused;
299 } ggc_statistics;
300
301 /* Used by the various collectors to gather and print statistics that
302 do not depend on the collector in use. */
303 extern void ggc_print_common_statistics (FILE *, ggc_statistics *);
304
305 /* Print allocation statistics. */ 249 /* Print allocation statistics. */
306 extern void ggc_print_statistics (void); 250 extern void ggc_print_statistics (void);
251
307 extern void stringpool_statistics (void); 252 extern void stringpool_statistics (void);
308 253
309 /* Heuristics. */ 254 /* Heuristics. */
310 extern int ggc_min_expand_heuristic (void);
311 extern int ggc_min_heapsize_heuristic (void);
312 extern void init_ggc_heuristics (void); 255 extern void init_ggc_heuristics (void);
313 256
314 /* Zone collection. */ 257 /* Zone collection. */
315 #if defined (GGC_ZONE) && !defined (GENERATOR_FILE)
316 258
317 /* For regular rtl allocations. */ 259 /* For regular rtl allocations. */
318 extern struct alloc_zone rtl_zone; 260 extern struct alloc_zone rtl_zone;
261
319 /* For regular tree allocations. */ 262 /* For regular tree allocations. */
320 extern struct alloc_zone tree_zone; 263 extern struct alloc_zone tree_zone;
264
321 /* For IDENTIFIER_NODE allocations. */ 265 /* For IDENTIFIER_NODE allocations. */
322 extern struct alloc_zone tree_id_zone; 266 extern struct alloc_zone tree_id_zone;
323 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
324 /* Allocate an object into the specified allocation zone. */ 275 /* Allocate an object into the specified allocation zone. */
325 extern void *ggc_alloc_zone_stat (size_t, struct alloc_zone * MEM_STAT_DECL); 276 extern void *ggc_internal_alloc_zone_stat (size_t,
326 # define ggc_alloc_zone(s,z) ggc_alloc_zone_stat (s,z MEM_STAT_INFO) 277 struct alloc_zone * MEM_STAT_DECL);
327 # define ggc_alloc_zone_pass_stat(s,z) ggc_alloc_zone_stat (s,z PASS_MEM_STAT) 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
328 #else 303 #else
329 304
330 # define ggc_alloc_zone(s, z) ggc_alloc (s) 305 static inline void *
331 # define ggc_alloc_zone_pass_stat(s, z) ggc_alloc_stat (s PASS_MEM_STAT) 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 }
332 325
333 #endif 326 #endif
334 327
328 /* Memory statistics passing versions of some allocators. Too few of them to
329 make gengtype produce them, so just define the needed ones here. */
330 static inline struct rtx_def *
331 ggc_alloc_zone_rtx_def_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL)
332 {
333 return (struct rtx_def *) ggc_internal_zone_alloc_stat (z, s PASS_MEM_STAT);
334 }
335
336 static inline union tree_node *
337 ggc_alloc_zone_tree_node_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL)
338 {
339 return (union tree_node *) ggc_internal_zone_alloc_stat (z, s PASS_MEM_STAT);
340 }
341
342 static inline union tree_node *
343 ggc_alloc_zone_cleared_tree_node_stat (struct alloc_zone * z, size_t s
344 MEM_STAT_DECL)
345 {
346 return (union tree_node *)
347 ggc_internal_zone_cleared_alloc_stat (z, s PASS_MEM_STAT);
348 }
349
350 static inline union gimple_statement_d *
351 ggc_alloc_cleared_gimple_statement_d_stat (size_t s MEM_STAT_DECL)
352 {
353 return (union gimple_statement_d *)
354 ggc_internal_cleared_alloc_stat (s PASS_MEM_STAT);
355 }
356
335 #endif 357 #endif