OSDN Git Service

Remove obstacks.
[pf3gnuchains/gcc-fork.git] / gcc / ggc.h
1 /* Garbage collection for the GNU compiler.
2    Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
3
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.  */
20
21 #include "gansidecl.h"
22 #include "varray.h"
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
27 /* These structures are defined in various headers throughout the
28    compiler.  However, rather than force everyone who includes this
29    header to include all the headers in which they are declared, we
30    just forward-declare them here.  */
31 struct eh_status;
32 struct emit_status;
33 struct expr_status;
34 struct hash_table;
35 struct label_node;
36 struct rtx_def;
37 struct rtvec_def;
38 struct stmt_status;
39 union  tree_node;
40 struct varasm_status;
41
42 /* Constants for general use.  */
43 extern char *empty_string;
44
45 /* Trees that have been marked, but whose children still need marking.  */
46 extern varray_type ggc_pending_trees;
47
48 /* Manipulate global roots that are needed between calls to gc.  */
49 void ggc_add_root PARAMS ((void *base, int nelt, int size, void (*)(void *)));
50 void ggc_add_rtx_root PARAMS ((struct rtx_def **, int nelt));
51 void ggc_add_tree_root PARAMS ((union tree_node **, int nelt));
52 void ggc_add_string_root PARAMS ((char **, int nelt));
53 void ggc_add_rtx_varray_root PARAMS ((struct varray_head_tag **, int nelt));
54 void ggc_add_tree_varray_root PARAMS ((struct varray_head_tag **, int nelt));
55 void ggc_add_tree_hash_table_root PARAMS ((struct hash_table **, int nelt));
56 void ggc_del_root PARAMS ((void *base));
57
58 /* Mark nodes from the gc_add_root callback.  These functions follow
59    pointers to mark other objects too.  */
60 extern void ggc_mark_rtx_varray PARAMS ((struct varray_head_tag *));
61 extern void ggc_mark_tree_varray PARAMS ((struct varray_head_tag *));
62 extern void ggc_mark_tree_hash_table PARAMS ((struct hash_table *));
63 extern void ggc_mark_roots PARAMS ((void));
64
65 extern void ggc_mark_rtx_children PARAMS ((struct rtx_def *));
66 extern void ggc_mark_rtvec_children PARAMS ((struct rtvec_def *));
67
68 /* If EXPR is not NULL and previously unmarked, mark it and evaluate
69    to true.  Otherwise evaluate to false.  */
70 #define ggc_test_and_set_mark(EXPR) \
71   ((EXPR) != NULL && ! ggc_set_mark (EXPR))
72
73 #define ggc_mark_rtx(EXPR)                      \
74   do {                                          \
75     rtx r__ = (EXPR);                           \
76     if (ggc_test_and_set_mark (r__))            \
77       ggc_mark_rtx_children (r__);              \
78   } while (0)
79
80 #define ggc_mark_tree(EXPR)                             \
81   do {                                                  \
82     tree t__ = (EXPR);                                  \
83     if (ggc_test_and_set_mark (t__))                    \
84       VARRAY_PUSH_TREE (ggc_pending_trees, t__);        \
85   } while (0)
86
87 #define ggc_mark_rtvec(EXPR)                    \
88   do {                                          \
89     rtvec v__ = (EXPR);                         \
90     if (ggc_test_and_set_mark (v__))            \
91       ggc_mark_rtvec_children (v__);            \
92   } while (0)
93
94 #define ggc_mark_string(EXPR)                   \
95   do {                                          \
96     const char *s__ = (EXPR);                   \
97     if (s__ != NULL)                            \
98       ggc_set_mark (s__);                       \
99   } while (0)
100
101 #define ggc_mark(EXPR)                          \
102   do {                                          \
103     const void *a__ = (EXPR);                   \
104     if (a__ != NULL)                            \
105       ggc_set_mark (a__);                       \
106   } while (0)
107
108 /* Mark, but only if it was allocated in collectable memory.  */
109 extern void ggc_mark_if_gcable PARAMS ((const void *));
110
111 /* A GC implementation must provide these functions.  */
112
113 /* Initialize the garbage collector.   */
114 extern void init_ggc PARAMS ((void));
115
116 /* Start a new GGC context.  Memory allocated in previous contexts
117    will not be collected while the new context is active.  */
118 extern void ggc_push_context PARAMS ((void));
119
120 /* Finish a GC context.  Any uncollected memory in the new context
121    will be merged with the old context.  */
122 extern void ggc_pop_context PARAMS ((void));
123
124 /* Allocation.  */
125
126 /* The internal primitive.  */
127 void *ggc_alloc PARAMS ((size_t));
128 /* Like ggc_alloc, but allocates cleared memory.  */
129 void *ggc_alloc_cleared PARAMS ((size_t));
130
131 #define ggc_alloc_rtx(NSLOTS)                                             \
132   ((struct rtx_def *) ggc_alloc (sizeof (struct rtx_def)                  \
133                                  + ((NSLOTS) - 1) * sizeof (rtunion)))
134
135 #define ggc_alloc_rtvec(NELT)                                             \
136   ((struct rtvec_def *) ggc_alloc (sizeof (struct rtvec_def)              \
137                                    + ((NELT) - 1) * sizeof (rtx)))
138
139 #define ggc_alloc_tree(LENGTH) ((union tree_node *) ggc_alloc (LENGTH))
140
141 /* Allocate a gc-able string.  If CONTENTS is null, then the memory will
142    be uninitialized.  If LENGTH is -1, then CONTENTS is assumed to be a
143    null-terminated string and the memory sized accordingly.  Otherwise,
144    the memory is filled with LENGTH bytes from CONTENTS.  */
145 char *ggc_alloc_string PARAMS ((const char *contents, int length));
146
147 /* Make a copy of S, in GC-able memory.  */
148 #define ggc_strdup(S) ggc_alloc_string((S), -1)
149
150 /* Invoke the collector.  This is really just a hint, but in the case of
151    the simple collector, the only time it will happen.  */
152 void ggc_collect PARAMS ((void));
153
154 /* Actually set the mark on a particular region of memory, but don't
155    follow pointers.  This function is called by ggc_mark_*.  It
156    returns zero if the object was not previously marked; non-zero if
157    the object was already marked, or if, for any other reason,
158    pointers in this data structure should not be traversed.  */
159 int ggc_set_mark PARAMS ((const void *));
160
161 /* Callbacks to the languages.  */
162
163 /* This is the language's opportunity to mark nodes held through
164    the lang_specific hooks in the tree.  */
165 void lang_mark_tree PARAMS ((union tree_node *));
166
167 /* The FALSE_LABEL_STACK, declared in except.h, has language-dependent
168    semantics.  If a front-end needs to mark the false label stack, it
169    should set this pointer to a non-NULL value.  Otherwise, no marking
170    will be done.  */
171 extern void (*lang_mark_false_label_stack) PARAMS ((struct label_node *));
172
173 /* Mark functions for various structs scattered about.  */
174
175 void mark_eh_status PARAMS ((struct eh_status *));
176 void mark_emit_status PARAMS ((struct emit_status *));
177 void mark_expr_status PARAMS ((struct expr_status *));
178 void mark_stmt_status PARAMS ((struct stmt_status *));
179 void mark_varasm_status PARAMS ((struct varasm_status *));
180 void mark_optab PARAMS ((void *));
181
182 /* Statistics.  */
183
184 /* This structure contains the statistics common to all collectors.
185    Particular collectors can extend this structure.  */
186 typedef struct ggc_statistics 
187 {
188   /* The Ith element is the number of nodes allocated with code I.  */
189   unsigned num_trees[256];
190   /* The Ith element is the number of bytes allocated by nodes with 
191      code I.  */
192   size_t size_trees[256];
193   /* The Ith element is the number of nodes allocated with code I.  */
194   unsigned num_rtxs[256];
195   /* The Ith element is the number of bytes allocated by nodes with 
196      code I.  */
197   size_t size_rtxs[256];
198   /* The total size of the tree nodes allocated.  */
199   size_t total_size_trees;
200   /* The total size of the RTL nodes allocated.  */
201   size_t total_size_rtxs;
202   /* The total number of tree nodes allocated.  */
203   unsigned total_num_trees;
204   /* The total number of RTL nodes allocated.  */
205   unsigned total_num_rtxs;
206 } ggc_statistics;
207
208 /* Return the number of bytes allocated at the indicated address.  */
209 size_t ggc_get_size PARAMS ((const void *));
210
211 /* Used by the various collectors to gather and print statistics that
212    do not depend on the collector in use.  */
213 void ggc_print_common_statistics PARAMS ((FILE *, ggc_statistics *));
214
215 /* Print allocation statistics.  */
216 extern void ggc_print_statistics PARAMS ((void));