OSDN Git Service

809edeca1a3d5fa33f913d89c85a00fe769eb192
[pf3gnuchains/gcc-fork.git] / gcc / ggc.h
1 /* Garbage collection for the GNU compiler.
2    Copyright (C) 1998, 1999 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
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GNU CC is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License 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
18    the Free Software Foundation, 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
20
21 #include "gansidecl.h"
22
23 /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with
24    an external gc library that might be linked in.  */
25
26 /* Language-specific code defines this variable to be either one (if
27    it wants garbage collection), or zero (if it does not).  */
28 extern int ggc_p;
29
30 /* These structures are defined in various headers throughout the
31    compiler.  However, rather than force everyone who includes this
32    header to include all the headers in which they are declared, we
33    just forward-declare them here.  */
34 struct eh_status;
35 struct emit_status;
36 struct expr_status;
37 struct hash_table;
38 struct label_node;
39 struct rtvec_def;
40 struct stmt_status;
41 union  tree_node;
42 struct varasm_status;
43 struct varray_head_tag;
44
45 /* Constants for general use.  */
46 extern char *empty_string;
47
48 /* Manipulate global roots that are needed between calls to gc.  */
49 void ggc_add_root PROTO ((void *base, int nelt, int size, void (*)(void *)));
50 void ggc_add_rtx_root PROTO ((struct rtx_def **, int nelt));
51 void ggc_add_tree_root PROTO ((union tree_node **, int nelt));
52 void ggc_add_string_root PROTO ((char **, int nelt));
53 void ggc_add_tree_varray_root PROTO ((struct varray_head_tag **, int nelt));
54 void ggc_add_tree_hash_table_root PROTO ((struct hash_table **, int nelt));
55 void ggc_del_root PROTO ((void *base));
56
57 /* Mark nodes from the gc_add_root callback.  These functions follow
58    pointers to mark other objects too.  */
59 extern void ggc_mark_tree_varray PROTO ((struct varray_head_tag *));
60 extern void ggc_mark_tree_hash_table PROTO ((struct hash_table *));
61 extern void ggc_mark_roots PROTO((void));
62
63 extern void ggc_mark_rtx_children PROTO ((struct rtx_def *));
64 extern void ggc_mark_rtvec_children PROTO ((struct rtvec_def *));
65 extern void ggc_mark_tree_children PROTO ((union tree_node *));
66
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 && ! ggc_set_mark (EXPR))
71
72 #define ggc_mark_rtx(EXPR)                      \
73   do {                                          \
74     rtx r__ = (EXPR);                           \
75     if (ggc_test_and_set_mark (r__))            \
76       ggc_mark_rtx_children (r__);              \
77   } while (0)
78
79 #define ggc_mark_tree(EXPR)                     \
80   do {                                          \
81     tree t__ = (EXPR);                          \
82     if (ggc_test_and_set_mark (t__))            \
83       ggc_mark_tree_children (t__);             \
84   } while (0)
85
86 #define ggc_mark_rtvec(EXPR)                    \
87   do {                                          \
88     rtvec v__ = (EXPR);                         \
89     if (ggc_test_and_set_mark (v__))            \
90       ggc_mark_rtvec_children (v__);            \
91   } while (0)
92
93 #define ggc_mark_string(EXPR)                   \
94   do {                                          \
95     char *s__ = (EXPR);                         \
96     if (s__ != NULL)                            \
97       ggc_set_mark (s__);                       \
98   } while (0)
99
100 #define ggc_mark(EXPR)                          \
101   do {                                          \
102     void *a__ = (EXPR);                         \
103     if (a__ != NULL)                            \
104       ggc_set_mark (a__);                       \
105   } while (0)
106
107 /* Mark, but only if it was allocated in collectable memory.  */
108 extern void ggc_mark_if_gcable PROTO ((void *));
109
110 /* A GC implementation must provide these functions.  */
111
112 /* Initialize the garbage collector.   */
113 extern void init_ggc PROTO ((void));
114
115 /* Start a new GGC context.  Memory allocated in previous contexts
116    will not be collected while the new context is active.  */
117 extern void ggc_push_context PROTO ((void));
118
119 /* Finish a GC context.  Any uncollected memory in the new context
120    will be merged with the old context.  */
121 extern void ggc_pop_context PROTO ((void));
122
123 /* Allocation.  */
124
125 /* The internal primitive.  */
126 void *ggc_alloc_obj PROTO ((size_t, int));
127
128 #define ggc_alloc_rtx(NSLOTS)                                                \
129   ((struct rtx_def *) ggc_alloc_obj (sizeof (struct rtx_def)                 \
130                                      + ((NSLOTS) - 1) * sizeof (rtunion), 1))
131
132 #define ggc_alloc_rtvec(NELT)                                             \
133   ((struct rtvec_def *) ggc_alloc_obj (sizeof (struct rtvec_def)          \
134                                        + ((NELT) - 1) * sizeof (rtx), 1))
135
136 #define ggc_alloc_tree(LENGTH)                          \
137   ((union tree_node *) ggc_alloc_obj ((LENGTH), 1))
138
139 #define ggc_alloc(SIZE)  ggc_alloc_obj((SIZE), 0)
140
141 char *ggc_alloc_string PROTO ((const char *contents, int length));
142
143 /* Invoke the collector.  This is really just a hint, but in the case of
144    the simple collector, the only time it will happen.  */
145 void ggc_collect PROTO ((void));
146
147 /* Actually set the mark on a particular region of memory, but don't
148    follow pointers.  This function is called by ggc_mark_*.  It
149    returns zero if the object was not previously marked; non-zero if
150    the object was already marked, or if, for any other reason,
151    pointers in this data structure should not be traversed.  */
152 int ggc_set_mark PROTO ((void *));
153
154 /* Callbacks to the languages.  */
155
156 /* This is the language's opportunity to mark nodes held through
157    the lang_specific hooks in the tree.  */
158 void lang_mark_tree PROTO ((union tree_node *));
159
160 /* The FALSE_LABEL_STACK, declared in except.h, has
161    language-dependent semantics.  Each front-end should define this
162    function appropriately.  */
163 void lang_mark_false_label_stack PROTO ((struct label_node *));
164
165 /* Mark functions for various structs scattered about.  */
166
167 void mark_eh_status PROTO ((struct eh_status *));
168 void mark_emit_status PROTO ((struct emit_status *));
169 void mark_expr_status PROTO ((struct expr_status *));
170 void mark_stmt_status PROTO ((struct stmt_status *));
171 void mark_varasm_status PROTO ((struct varasm_status *));
172 void mark_optab PROTO ((void *));
173
174 /* Statistics.  */
175
176 /* This structure contains the statistics common to all collectors.
177    Particular collectors can extend this structure.  */
178 typedef struct ggc_statistics 
179 {
180   /* The Ith element is the number of nodes allocated with code I.  */
181   unsigned num_trees[256];
182   /* The Ith element is the number of bytes allocated by nodes with 
183      code I.  */
184   size_t size_trees[256];
185   /* The Ith element is the number of nodes allocated with code I.  */
186   unsigned num_rtxs[256];
187   /* The Ith element is the number of bytes allocated by nodes with 
188      code I.  */
189   size_t size_rtxs[256];
190   /* The total size of the tree nodes allocated.  */
191   size_t total_size_trees;
192   /* The total size of the RTL nodes allocated.  */
193   size_t total_size_rtxs;
194   /* The total number of tree nodes allocated.  */
195   unsigned total_num_trees;
196   /* The total number of RTL nodes allocated.  */
197   unsigned total_num_rtxs;
198 } ggc_statistics;
199
200 /* Return the number of bytes allocated at the indicated address.  */
201 size_t ggc_get_size PROTO ((void *));
202
203 /* Used by the various collectors to gather and print statistics that
204    do not depend on the collector in use.  */
205 void ggc_print_statistics PROTO ((FILE *, ggc_statistics *));