]> gcc.gnu.org Git - gcc.git/blame - gcc/ggc.h
Update copyright years in gcc/
[gcc.git] / gcc / ggc.h
CommitLineData
0a25f1f5 1/* Garbage collection for the GNU compiler.
ae2392a9 2
d1e082c2 3 Copyright (C) 1998-2013 Free Software Foundation, Inc.
0a25f1f5 4
1322177d 5This file is part of GCC.
770ae6cc 6
1322177d
LB
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
1322177d 10version.
770ae6cc 11
1322177d
LB
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
770ae6cc
RK
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
0a25f1f5 20
d07605f5
AP
21#ifndef GCC_GGC_H
22#define GCC_GGC_H
b9dcdee4 23#include "statistics.h"
d07605f5 24
0a25f1f5
RH
25/* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with
26 an external gc library that might be linked in. */
27
21a427cc 28/* Constants for general use. */
a8a05998 29extern const char empty_string[]; /* empty string */
21a427cc 30
17211ab5 31/* Internal functions and data structures used by the GTY
a9429e29 32 machinery, including the generated gt*.[hc] files. */
17211ab5 33
17211ab5
GK
34#include "gtype-desc.h"
35
36/* One of these applies its third parameter (with cookie in the fourth
37 parameter) to each pointer in the object pointed to by the first
38 parameter, using the second parameter. */
20c1dc5e
AJ
39typedef void (*gt_note_pointers) (void *, void *, gt_pointer_operator,
40 void *);
17211ab5
GK
41
42/* One of these is called before objects are re-ordered in memory.
43 The first parameter is the original object, the second is the
44 subobject that has had its pointers reordered, the third parameter
45 can compute the new values of a pointer when given the cookie in
46 the fourth parameter. */
20c1dc5e
AJ
47typedef void (*gt_handle_reorder) (void *, void *, gt_pointer_operator,
48 void *);
17211ab5
GK
49
50/* Used by the gt_pch_n_* routines. Register an object in the hash table. */
08cee789 51extern int gt_pch_note_object (void *, void *, gt_note_pointers,
9771b263 52 enum gt_types_enum = gt_types_enum_last);
17211ab5 53
20c1dc5e 54/* Used by the gt_pch_n_* routines. Register that an object has a reorder
17211ab5 55 function. */
20c1dc5e 56extern void gt_pch_note_reorder (void *, void *, gt_handle_reorder);
17211ab5
GK
57
58/* Mark the object in the first parameter and anything it points to. */
20c1dc5e 59typedef void (*gt_pointer_walker) (void *);
e2500fed 60
589005ff 61/* Structures for the easy way to mark roots.
0ee55ad8 62 In an array, terminated by having base == NULL. */
e2500fed
GK
63struct ggc_root_tab {
64 void *base;
65 size_t nelt;
66 size_t stride;
17211ab5
GK
67 gt_pointer_walker cb;
68 gt_pointer_walker pchw;
e2500fed 69};
17211ab5 70#define LAST_GGC_ROOT_TAB { NULL, 0, 0, NULL, NULL }
e2500fed
GK
71/* Pointers to arrays of ggc_root_tab, terminated by NULL. */
72extern const struct ggc_root_tab * const gt_ggc_rtab[];
73extern const struct ggc_root_tab * const gt_ggc_deletable_rtab[];
17211ab5
GK
74extern const struct ggc_root_tab * const gt_pch_cache_rtab[];
75extern const struct ggc_root_tab * const gt_pch_scalar_rtab[];
e2500fed
GK
76
77/* Structure for hash table cache marking. */
78struct htab;
79struct ggc_cache_tab {
80 struct htab * *base;
81 size_t nelt;
82 size_t stride;
17211ab5
GK
83 gt_pointer_walker cb;
84 gt_pointer_walker pchw;
20c1dc5e 85 int (*marked_p) (const void *);
e2500fed 86};
17211ab5 87#define LAST_GGC_CACHE_TAB { NULL, 0, 0, NULL, NULL, NULL }
e2500fed
GK
88/* Pointers to arrays of ggc_cache_tab, terminated by NULL. */
89extern const struct ggc_cache_tab * const gt_ggc_cache_rtab[];
90
52a92176
AS
91/* If EXPR is not NULL and previously unmarked, mark it and evaluate
92 to true. Otherwise evaluate to false. */
93#define ggc_test_and_set_mark(EXPR) \
e2500fed 94 ((EXPR) != NULL && ((void *) (EXPR)) != (void *) 1 && ! ggc_set_mark (EXPR))
52a92176 95
005537df
RH
96#define ggc_mark(EXPR) \
97 do { \
d8750784 98 const void *const a__ = (EXPR); \
e2500fed 99 if (a__ != NULL && a__ != (void *) 1) \
005537df
RH
100 ggc_set_mark (a__); \
101 } while (0)
102
17211ab5
GK
103/* Actually set the mark on a particular region of memory, but don't
104 follow pointers. This function is called by ggc_mark_*. It
6356f892 105 returns zero if the object was not previously marked; nonzero if
17211ab5
GK
106 the object was already marked, or if, for any other reason,
107 pointers in this data structure should not be traversed. */
20c1dc5e 108extern int ggc_set_mark (const void *);
17211ab5
GK
109
110/* Return 1 if P has been marked, zero otherwise.
111 P must have been allocated by the GC allocator; it mustn't point to
112 static objects, stack variables, or memory allocated with malloc. */
20c1dc5e 113extern int ggc_marked_p (const void *);
17211ab5 114
17211ab5 115/* PCH and GGC handling for strings, mostly trivial. */
20c1dc5e 116extern void gt_pch_n_S (const void *);
dae4174e 117extern void gt_ggc_m_S (const void *);
17211ab5 118
a9429e29 119/* End of GTY machinery API. */
17211ab5 120
47aeffac
SB
121struct alloc_zone;
122
a9429e29
LB
123/* Initialize the string pool. */
124extern void init_stringpool (void);
125
eebedaa5 126/* Initialize the garbage collector. */
20c1dc5e 127extern void init_ggc (void);
0a25f1f5 128
dae4174e
TT
129/* When true, identifier nodes are considered as GC roots. When
130 false, identifier nodes are treated like any other GC-allocated
131 object, and the identifier hash table is treated as a weak
132 hash. */
133extern bool ggc_protect_identifiers;
134
a9429e29
LB
135/* Write out all GCed objects to F. */
136extern void gt_pch_save (FILE *f);
137
138\f
139/* Allocation. */
140
005537df 141/* The internal primitive. */
c8b8af71
SB
142extern void *ggc_internal_alloc_stat (size_t MEM_STAT_DECL)
143 ATTRIBUTE_MALLOC;
a9429e29 144
b9bd6f74
TT
145extern size_t ggc_round_alloc_size (size_t requested_size);
146
a9429e29
LB
147#define ggc_internal_alloc(s) ggc_internal_alloc_stat (s MEM_STAT_INFO)
148
6614fd40 149/* Allocate an object of the specified type and size. */
c8b8af71
SB
150extern void *ggc_alloc_typed_stat (enum gt_types_enum, size_t MEM_STAT_DECL)
151 ATTRIBUTE_MALLOC;
a9429e29
LB
152
153#define ggc_alloc_typed(s, z) ggc_alloc_typed_stat (s, z MEM_STAT_INFO)
154
155/* Allocates cleared memory. */
c8b8af71
SB
156extern void *ggc_internal_cleared_alloc_stat (size_t MEM_STAT_DECL)
157 ATTRIBUTE_MALLOC;
a9429e29 158
e2500fed 159/* Resize a block. */
b9dcdee4 160extern void *ggc_realloc_stat (void *, size_t MEM_STAT_DECL);
a9429e29 161
685fe032
RH
162/* Free a block. To be used when known for certain it's not reachable. */
163extern void ggc_free (void *);
b8698a0f 164
a5573239 165extern void dump_ggc_loc_statistics (bool);
005537df 166
a9429e29
LB
167/* Reallocators. */
168#define GGC_RESIZEVEC(T, P, N) \
169 ((T *) ggc_realloc_stat ((P), (N) * sizeof (T) MEM_STAT_INFO))
170
171#define GGC_RESIZEVAR(T, P, N) \
172 ((T *) ggc_realloc_stat ((P), (N) MEM_STAT_INFO))
173
174static inline void *
175ggc_internal_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL)
176{
177 return ggc_internal_alloc_stat (c * s PASS_MEM_STAT);
178}
179
180static inline void *
181ggc_internal_cleared_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL)
182{
183 return ggc_internal_cleared_alloc_stat (c * s PASS_MEM_STAT);
184}
185
186#define ggc_internal_cleared_vec_alloc(s, c) \
187 (ggc_internal_cleared_vec_alloc_stat ((s), (c) MEM_STAT_INFO))
188
189static inline void *
190ggc_alloc_atomic_stat (size_t s MEM_STAT_DECL)
191{
192 return ggc_internal_alloc_stat (s PASS_MEM_STAT);
193}
194
195#define ggc_alloc_atomic(S) (ggc_alloc_atomic_stat ((S) MEM_STAT_INFO))
196
197#define ggc_alloc_cleared_atomic(S) \
198 (ggc_internal_cleared_alloc_stat ((S) MEM_STAT_INFO))
c32118f9 199
c8b8af71
SB
200extern void *ggc_cleared_alloc_htab_ignore_args (size_t, size_t)
201 ATTRIBUTE_MALLOC;
005537df 202
c8b8af71
SB
203extern void *ggc_cleared_alloc_ptr_array_two_args (size_t, size_t)
204 ATTRIBUTE_MALLOC;
005537df 205
e2500fed 206#define htab_create_ggc(SIZE, HASH, EQ, DEL) \
a9429e29
LB
207 htab_create_typed_alloc (SIZE, HASH, EQ, DEL, \
208 ggc_cleared_alloc_htab_ignore_args, \
209 ggc_cleared_alloc_ptr_array_two_args, \
210 ggc_free)
211
212#define splay_tree_new_ggc(COMPARE, ALLOC_TREE, ALLOC_NODE) \
213 splay_tree_new_typed_alloc (COMPARE, NULL, NULL, &ALLOC_TREE, &ALLOC_NODE, \
214 &ggc_splay_dont_free, NULL)
215
c8b8af71
SB
216extern void *ggc_splay_alloc (enum gt_types_enum, int, void *)
217 ATTRIBUTE_MALLOC;
e2500fed 218
20c1dc5e 219extern void ggc_splay_dont_free (void *, void *);
17211ab5 220
520a57c8
ZW
221/* 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
223 null-terminated string and the memory sized accordingly. */
a9429e29
LB
224extern 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)
0a25f1f5 228
f15b9af9 229/* Make a copy of S, in GC-able memory. */
a9429e29 230#define ggc_strdup(S) ggc_alloc_string_stat ((S), -1 MEM_STAT_INFO)
f15b9af9 231
cd5a58e5
ZW
232/* Invoke the collector. Garbage collection occurs only when this
233 function is called, not during allocations. */
20c1dc5e 234extern void ggc_collect (void);
0a25f1f5 235
ae2392a9 236/* Register an additional root table. This can be useful for some
32c9b4e9 237 plugins. Does nothing if the passed pointer is NULL. */
ae2392a9
BS
238extern void ggc_register_root_tab (const struct ggc_root_tab *);
239
32c9b4e9
DS
240/* Register an additional cache table. This can be useful for some
241 plugins. Does nothing if the passed pointer is NULL. */
242extern void ggc_register_cache_tab (const struct ggc_cache_tab *);
243
17211ab5 244/* Read objects previously saved with gt_pch_save from F. */
20c1dc5e 245extern void gt_pch_restore (FILE *f);
17211ab5 246\f
3277221c
MM
247/* Statistics. */
248
c6991660 249/* Print allocation statistics. */
20c1dc5e 250extern void ggc_print_statistics (void);
a9429e29 251
20c1dc5e 252extern void stringpool_statistics (void);
9ac121af
KG
253
254/* Heuristics. */
20c1dc5e 255extern void init_ggc_heuristics (void);
d07605f5 256
08cee789 257/* Zone collection. */
08cee789
DJ
258
259/* For regular rtl allocations. */
260extern struct alloc_zone rtl_zone;
a9429e29 261
08cee789
DJ
262/* For regular tree allocations. */
263extern struct alloc_zone tree_zone;
a9429e29 264
08cee789
DJ
265/* For IDENTIFIER_NODE allocations. */
266extern struct alloc_zone tree_id_zone;
267
a9429e29 268#define ggc_alloc_rtvec_sized(NELT) \
870d0521
AS
269 ggc_alloc_zone_rtvec_def (sizeof (struct rtvec_def) \
270 + ((NELT) - 1) * sizeof (rtx), \
271 &rtl_zone)
a9429e29
LB
272
273#if defined (GGC_ZONE) && !defined (GENERATOR_FILE)
274
08cee789 275/* Allocate an object into the specified allocation zone. */
a9429e29 276extern void *ggc_internal_alloc_zone_stat (size_t,
c8b8af71
SB
277 struct alloc_zone * MEM_STAT_DECL)
278 ATTRIBUTE_MALLOC;
a9429e29
LB
279
280extern void *ggc_internal_cleared_alloc_zone_stat (size_t,
c8b8af71
SB
281 struct alloc_zone * MEM_STAT_DECL)
282 ATTRIBUTE_MALLOC;
a9429e29
LB
283
284static inline void *
285ggc_internal_zone_alloc_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL)
286{
287 return ggc_internal_alloc_zone_stat (s, z PASS_MEM_STAT);
288}
289
290static inline void *
291ggc_internal_zone_cleared_alloc_stat (struct alloc_zone * z, size_t s
292 MEM_STAT_DECL)
293{
294 return ggc_internal_cleared_alloc_zone_stat (s, z PASS_MEM_STAT);
295}
296
297static inline void *
298ggc_internal_zone_vec_alloc_stat (struct alloc_zone * z, size_t s, size_t n
299 MEM_STAT_DECL)
300{
301 return ggc_internal_alloc_zone_stat (s * n, z PASS_MEM_STAT);
302}
303
304
08cee789
DJ
305#else
306
a9429e29
LB
307static inline void *
308ggc_internal_zone_alloc_stat (struct alloc_zone * z ATTRIBUTE_UNUSED,
309 size_t s MEM_STAT_DECL)
310{
311 return ggc_internal_alloc_stat (s PASS_MEM_STAT);
312}
313
314static inline void *
315ggc_internal_zone_cleared_alloc_stat (struct alloc_zone * z ATTRIBUTE_UNUSED,
316 size_t s MEM_STAT_DECL)
317{
318 return ggc_internal_cleared_alloc_stat (s PASS_MEM_STAT);
319}
320
321static inline void *
322ggc_internal_zone_vec_alloc_stat (struct alloc_zone * z ATTRIBUTE_UNUSED,
323 size_t s, size_t n MEM_STAT_DECL)
324{
325 return ggc_internal_vec_alloc_stat (s, n PASS_MEM_STAT);
326}
08cee789
DJ
327
328#endif
329
a9429e29
LB
330/* Memory statistics passing versions of some allocators. Too few of them to
331 make gengtype produce them, so just define the needed ones here. */
332static inline struct rtx_def *
333ggc_alloc_zone_rtx_def_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL)
334{
335 return (struct rtx_def *) ggc_internal_zone_alloc_stat (z, s PASS_MEM_STAT);
336}
337
338static inline union tree_node *
339ggc_alloc_zone_tree_node_stat (struct alloc_zone * z, size_t s MEM_STAT_DECL)
340{
341 return (union tree_node *) ggc_internal_zone_alloc_stat (z, s PASS_MEM_STAT);
342}
343
344static inline union tree_node *
345ggc_alloc_zone_cleared_tree_node_stat (struct alloc_zone * z, size_t s
346 MEM_STAT_DECL)
347{
348 return (union tree_node *)
349 ggc_internal_zone_cleared_alloc_stat (z, s PASS_MEM_STAT);
350}
351
352static inline union gimple_statement_d *
353ggc_alloc_cleared_gimple_statement_d_stat (size_t s MEM_STAT_DECL)
354{
355 return (union gimple_statement_d *)
356 ggc_internal_cleared_alloc_stat (s PASS_MEM_STAT);
357}
358
d07605f5 359#endif
This page took 4.95909 seconds and 5 git commands to generate.