OSDN Git Service

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