]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ggc.h
* Makefile.in, alias.c, basic-block.h, bb-reorder.c, bitmap.c,
[thirdparty/gcc.git] / gcc / ggc.h
CommitLineData
05513b45 1/* Garbage collection for the GNU compiler.
3915b59e 2 Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
05513b45 3
f12b58b3 4This file is part of GCC.
02e7a332 5
f12b58b3 6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 2, or (at your option) any later
9version.
02e7a332 10
f12b58b3 11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
02e7a332 13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
f12b58b3 17along with GCC; see the file COPYING. If not, write to the Free
02e7a332 18Software Foundation, 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
05513b45 20
769177ac 21#include "varray.h"
05513b45 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
a7b0c170 26/* These structures are defined in various headers throughout the
27 compiler. However, rather than force everyone who includes this
28 header to include all the headers in which they are declared, we
29 just forward-declare them here. */
a7b0c170 30struct eh_status;
31struct emit_status;
3c3bb268 32struct expr_status;
bebb7b68 33struct hash_table;
34struct label_node;
40977116 35struct rtx_def;
bebb7b68 36struct rtvec_def;
a7b0c170 37struct stmt_status;
bebb7b68 38union tree_node;
a7b0c170 39struct varasm_status;
40
0f4dbfb9 41/* Constants for general use. */
ec6cb94a 42extern const char empty_string[]; /* empty string */
43extern const char digit_vector[]; /* "0" .. "9" */
44#define digit_string(d) (digit_vector + ((d) * 2))
0f4dbfb9 45
769177ac 46/* Trees that have been marked, but whose children still need marking. */
47extern varray_type ggc_pending_trees;
48
bebb7b68 49/* Manipulate global roots that are needed between calls to gc. */
38b9004f 50void ggc_add_root PARAMS ((void *base, int nelt, int size, void (*)(void *)));
51void ggc_add_rtx_root PARAMS ((struct rtx_def **, int nelt));
52void ggc_add_tree_root PARAMS ((union tree_node **, int nelt));
cf6cce73 53void ggc_add_rtx_varray_root PARAMS ((struct varray_head_tag **, int nelt));
38b9004f 54void ggc_add_tree_varray_root PARAMS ((struct varray_head_tag **, int nelt));
55void ggc_add_tree_hash_table_root PARAMS ((struct hash_table **, int nelt));
56void ggc_del_root PARAMS ((void *base));
05513b45 57
bebb7b68 58/* Mark nodes from the gc_add_root callback. These functions follow
59 pointers to mark other objects too. */
cf6cce73 60extern void ggc_mark_rtx_varray PARAMS ((struct varray_head_tag *));
38b9004f 61extern void ggc_mark_tree_varray PARAMS ((struct varray_head_tag *));
62extern void ggc_mark_tree_hash_table PARAMS ((struct hash_table *));
63extern void ggc_mark_roots PARAMS ((void));
0046a2c2 64
38b9004f 65extern void ggc_mark_rtx_children PARAMS ((struct rtx_def *));
66extern void ggc_mark_rtvec_children PARAMS ((struct rtvec_def *));
0046a2c2 67
f7cb0e39 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__); \
71661611 78 } while (0)
79
769177ac 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__); \
71661611 85 } while (0)
e3691812 86
0d086e18 87#define ggc_mark_nonnull_tree(EXPR) \
88 do { \
89 tree t__ = (EXPR); \
90 if (! ggc_set_mark (t__)) \
91 VARRAY_PUSH_TREE (ggc_pending_trees, t__); \
92 } while (0)
93
f7cb0e39 94#define ggc_mark_rtvec(EXPR) \
95 do { \
96 rtvec v__ = (EXPR); \
97 if (ggc_test_and_set_mark (v__)) \
98 ggc_mark_rtvec_children (v__); \
0046a2c2 99 } while (0)
100
71661611 101#define ggc_mark(EXPR) \
102 do { \
9a356c3c 103 const void *a__ = (EXPR); \
71661611 104 if (a__ != NULL) \
105 ggc_set_mark (a__); \
106 } while (0)
107
bebb7b68 108/* A GC implementation must provide these functions. */
109
110/* Initialize the garbage collector. */
38b9004f 111extern void init_ggc PARAMS ((void));
44acf429 112extern void init_stringpool PARAMS ((void));
05513b45 113
c788feb1 114/* Start a new GGC context. Memory allocated in previous contexts
115 will not be collected while the new context is active. */
38b9004f 116extern void ggc_push_context PARAMS ((void));
bebb7b68 117
c788feb1 118/* Finish a GC context. Any uncollected memory in the new context
119 will be merged with the old context. */
38b9004f 120extern void ggc_pop_context PARAMS ((void));
c788feb1 121
05513b45 122/* Allocation. */
71661611 123
124/* The internal primitive. */
791ceafe 125void *ggc_alloc PARAMS ((size_t));
126/* Like ggc_alloc, but allocates cleared memory. */
127void *ggc_alloc_cleared PARAMS ((size_t));
71661611 128
791ceafe 129#define ggc_alloc_rtx(NSLOTS) \
130 ((struct rtx_def *) ggc_alloc (sizeof (struct rtx_def) \
131 + ((NSLOTS) - 1) * sizeof (rtunion)))
71661611 132
133#define ggc_alloc_rtvec(NELT) \
791ceafe 134 ((struct rtvec_def *) ggc_alloc (sizeof (struct rtvec_def) \
135 + ((NELT) - 1) * sizeof (rtx)))
71661611 136
791ceafe 137#define ggc_alloc_tree(LENGTH) ((union tree_node *) ggc_alloc (LENGTH))
71661611 138
44acf429 139/* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS.
140 If LENGTH is -1, then CONTENTS is assumed to be a
141 null-terminated string and the memory sized accordingly. */
142const char *ggc_alloc_string PARAMS ((const char *contents, int length));
05513b45 143
a4e59c31 144/* Make a copy of S, in GC-able memory. */
145#define ggc_strdup(S) ggc_alloc_string((S), -1)
146
3915b59e 147/* Invoke the collector. Garbage collection occurs only when this
148 function is called, not during allocations. */
38b9004f 149void ggc_collect PARAMS ((void));
05513b45 150
bebb7b68 151/* Actually set the mark on a particular region of memory, but don't
71661611 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. */
9a356c3c 156int ggc_set_mark PARAMS ((const void *));
05513b45 157
05513b45 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. */
38b9004f 162void lang_mark_tree PARAMS ((union tree_node *));
05513b45 163
a4e59c31 164/* The FALSE_LABEL_STACK, declared in except.h, has language-dependent
165 semantics. If a front-end needs to mark the false label stack, it
166 should set this pointer to a non-NULL value. Otherwise, no marking
167 will be done. */
168extern void (*lang_mark_false_label_stack) PARAMS ((struct label_node *));
a7b0c170 169
05513b45 170/* Mark functions for various structs scattered about. */
171
38b9004f 172void mark_eh_status PARAMS ((struct eh_status *));
173void mark_emit_status PARAMS ((struct emit_status *));
174void mark_expr_status PARAMS ((struct expr_status *));
175void mark_stmt_status PARAMS ((struct stmt_status *));
176void mark_varasm_status PARAMS ((struct varasm_status *));
177void mark_optab PARAMS ((void *));
4e00b6fd 178
179/* Statistics. */
180
181/* This structure contains the statistics common to all collectors.
182 Particular collectors can extend this structure. */
183typedef struct ggc_statistics
184{
185 /* The Ith element is the number of nodes allocated with code I. */
186 unsigned num_trees[256];
187 /* The Ith element is the number of bytes allocated by nodes with
188 code I. */
189 size_t size_trees[256];
190 /* The Ith element is the number of nodes allocated with code I. */
191 unsigned num_rtxs[256];
192 /* The Ith element is the number of bytes allocated by nodes with
193 code I. */
194 size_t size_rtxs[256];
4e00b6fd 195 /* The total size of the tree nodes allocated. */
196 size_t total_size_trees;
4e00b6fd 197 /* The total size of the RTL nodes allocated. */
198 size_t total_size_rtxs;
9ffd5d6d 199 /* The total number of tree nodes allocated. */
200 unsigned total_num_trees;
201 /* The total number of RTL nodes allocated. */
202 unsigned total_num_rtxs;
4e00b6fd 203} ggc_statistics;
204
205/* Return the number of bytes allocated at the indicated address. */
9a356c3c 206size_t ggc_get_size PARAMS ((const void *));
4e00b6fd 207
208/* Used by the various collectors to gather and print statistics that
209 do not depend on the collector in use. */
2a8997e8 210void ggc_print_common_statistics PARAMS ((FILE *, ggc_statistics *));
74647769 211
212/* Print allocation statistics. */
2a8997e8 213extern void ggc_print_statistics PARAMS ((void));
44acf429 214void stringpool_statistics PARAMS ((void));