1 /* Garbage collection for the GNU compiler.
2 Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "gtype-desc.h"
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. */
27 /* Constants for general use. */
28 extern const char empty_string
[]; /* empty string */
29 extern const char digit_vector
[]; /* "0" .. "9" */
30 #define digit_string(d) (digit_vector + ((d) * 2))
32 /* Manipulate global roots that are needed between calls to gc.
33 THIS ROUTINE IS OBSOLETE, do not use it for new code. */
34 extern void ggc_add_root
PARAMS ((void *base
, int nelt
,
35 int size
, void (*)(void *)));
37 /* Structures for the easy way to mark roots.
38 In an array, terminated by having base == NULL.*/
43 void (*cb
) PARAMS ((void *));
45 #define LAST_GGC_ROOT_TAB { NULL, 0, 0, NULL }
46 /* Pointers to arrays of ggc_root_tab, terminated by NULL. */
47 extern const struct ggc_root_tab
* const gt_ggc_rtab
[];
48 extern const struct ggc_root_tab
* const gt_ggc_deletable_rtab
[];
50 /* Structure for hash table cache marking. */
52 struct ggc_cache_tab
{
56 void (*cb
) PARAMS ((void *));
57 int (*marked_p
) PARAMS ((const void *));
59 #define LAST_GGC_CACHE_TAB { NULL, 0, 0, NULL, NULL }
60 /* Pointers to arrays of ggc_cache_tab, terminated by NULL. */
61 extern const struct ggc_cache_tab
* const gt_ggc_cache_rtab
[];
63 extern void ggc_mark_roots
PARAMS ((void));
65 extern void ggc_mark_rtx_children
PARAMS ((struct rtx_def
*));
67 /* If EXPR is not NULL and previously unmarked, mark it and evaluate
68 to true. Otherwise evaluate to false. */
69 #define ggc_test_and_set_mark(EXPR) \
70 ((EXPR) != NULL && ((void *) (EXPR)) != (void *) 1 && ! ggc_set_mark (EXPR))
72 #define ggc_mark_rtx(EXPR) \
74 rtx const r__ = (EXPR); \
75 if (ggc_test_and_set_mark (r__)) \
76 ggc_mark_rtx_children (r__); \
79 #define ggc_mark_tree gt_ggc_m_tree_node
81 #define ggc_mark(EXPR) \
83 const void *const a__ = (EXPR); \
84 if (a__ != NULL && a__ != (void *) 1) \
88 /* A GC implementation must provide these functions. */
90 /* Initialize the garbage collector. */
91 extern void init_ggc
PARAMS ((void));
92 extern void init_stringpool
PARAMS ((void));
94 /* Start a new GGC context. Memory allocated in previous contexts
95 will not be collected while the new context is active. */
96 extern void ggc_push_context
PARAMS ((void));
98 /* Finish a GC context. Any uncollected memory in the new context
99 will be merged with the old context. */
100 extern void ggc_pop_context
PARAMS ((void));
104 /* The internal primitive. */
105 extern void *ggc_alloc
PARAMS ((size_t));
106 /* Like ggc_alloc, but allocates cleared memory. */
107 extern void *ggc_alloc_cleared
PARAMS ((size_t));
108 /* Resize a block. */
109 extern void *ggc_realloc
PARAMS ((void *, size_t));
110 /* Like ggc_alloc_cleared, but performs a multiplication. */
111 extern void *ggc_calloc
PARAMS ((size_t, size_t));
113 #define ggc_alloc_rtx(NSLOTS) \
114 ((struct rtx_def *) ggc_alloc (sizeof (struct rtx_def) \
115 + ((NSLOTS) - 1) * sizeof (rtunion)))
117 #define ggc_alloc_rtvec(NELT) \
118 ((struct rtvec_def *) ggc_alloc (sizeof (struct rtvec_def) \
119 + ((NELT) - 1) * sizeof (rtx)))
121 #define ggc_alloc_tree(LENGTH) ((union tree_node *) ggc_alloc (LENGTH))
123 #define htab_create_ggc(SIZE, HASH, EQ, DEL) \
124 htab_create_alloc (SIZE, HASH, EQ, DEL, ggc_calloc, NULL)
126 /* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS.
127 If LENGTH is -1, then CONTENTS is assumed to be a
128 null-terminated string and the memory sized accordingly. */
129 extern const char *ggc_alloc_string
PARAMS ((const char *contents
,
132 /* Make a copy of S, in GC-able memory. */
133 #define ggc_strdup(S) ggc_alloc_string((S), -1)
135 /* Invoke the collector. Garbage collection occurs only when this
136 function is called, not during allocations. */
137 extern void ggc_collect
PARAMS ((void));
139 /* Actually set the mark on a particular region of memory, but don't
140 follow pointers. This function is called by ggc_mark_*. It
141 returns zero if the object was not previously marked; non-zero if
142 the object was already marked, or if, for any other reason,
143 pointers in this data structure should not be traversed. */
144 extern int ggc_set_mark
PARAMS ((const void *));
146 /* Return 1 if P has been marked, zero otherwise.
147 P must have been allocated by the GC allocator; it mustn't point to
148 static objects, stack variables, or memory allocated with malloc. */
149 extern int ggc_marked_p
PARAMS ((const void *));
153 /* This structure contains the statistics common to all collectors.
154 Particular collectors can extend this structure. */
155 typedef struct ggc_statistics
157 /* The Ith element is the number of nodes allocated with code I. */
158 unsigned num_trees
[256];
159 /* The Ith element is the number of bytes allocated by nodes with
161 size_t size_trees
[256];
162 /* The Ith element is the number of nodes allocated with code I. */
163 unsigned num_rtxs
[256];
164 /* The Ith element is the number of bytes allocated by nodes with
166 size_t size_rtxs
[256];
167 /* The total size of the tree nodes allocated. */
168 size_t total_size_trees
;
169 /* The total size of the RTL nodes allocated. */
170 size_t total_size_rtxs
;
171 /* The total number of tree nodes allocated. */
172 unsigned total_num_trees
;
173 /* The total number of RTL nodes allocated. */
174 unsigned total_num_rtxs
;
177 /* Return the number of bytes allocated at the indicated address. */
178 extern size_t ggc_get_size
PARAMS ((const void *));
180 /* Used by the various collectors to gather and print statistics that
181 do not depend on the collector in use. */
182 extern void ggc_print_common_statistics
PARAMS ((FILE *, ggc_statistics
*));
184 /* Print allocation statistics. */
185 extern void ggc_print_statistics
PARAMS ((void));
186 extern void stringpool_statistics
PARAMS ((void));