OSDN Git Service

Use ## for comment.
[pf3gnuchains/gcc-fork.git] / gcc / ggc.h
1 /* Garbage collection for the GNU compiler.
2    Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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
9 version.
10
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
14 for more details.
15
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
19 02111-1307, USA.  */
20
21 #include "varray.h"
22 #include "gtype-desc.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 /* 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))
31
32 /* Manipulate global roots that are needed between calls to gc.  */
33 extern void ggc_add_root                PARAMS ((void *base, int nelt,
34                                                  int size, void (*)(void *)));
35
36 /* Structures for the easy way to mark roots.
37    In an array, terminated by having base == NULL.*/
38 struct ggc_root_tab {
39   void *base;
40   size_t nelt;
41   size_t stride;
42   void (*cb) PARAMS ((void *));
43 };
44 #define LAST_GGC_ROOT_TAB { NULL, 0, 0, NULL }
45 /* Pointers to arrays of ggc_root_tab, terminated by NULL.  */
46 extern const struct ggc_root_tab * const gt_ggc_rtab[];
47 extern const struct ggc_root_tab * const gt_ggc_deletable_rtab[];
48
49 /* Structure for hash table cache marking.  */
50 struct htab;
51 struct ggc_cache_tab {
52   struct htab * *base;
53   size_t nelt;
54   size_t stride;
55   void (*cb) PARAMS ((void *));
56   int (*marked_p) PARAMS ((const void *));
57 };
58 #define LAST_GGC_CACHE_TAB { NULL, 0, 0, NULL, NULL }
59 /* Pointers to arrays of ggc_cache_tab, terminated by NULL.  */
60 extern const struct ggc_cache_tab * const gt_ggc_cache_rtab[];
61
62 extern void ggc_mark_roots              PARAMS ((void));
63
64 extern void ggc_mark_rtx_children       PARAMS ((struct rtx_def *));
65
66 /* If EXPR is not NULL and previously unmarked, mark it and evaluate
67    to true.  Otherwise evaluate to false.  */
68 #define ggc_test_and_set_mark(EXPR) \
69   ((EXPR) != NULL && ((void *) (EXPR)) != (void *) 1 && ! ggc_set_mark (EXPR))
70
71 #define ggc_mark_rtx(EXPR)                      \
72   do {                                          \
73     rtx const r__ = (EXPR);                     \
74     if (ggc_test_and_set_mark (r__))            \
75       ggc_mark_rtx_children (r__);              \
76   } while (0)
77
78 #define ggc_mark_tree gt_ggc_m_tree_node
79
80 #define ggc_mark(EXPR)                          \
81   do {                                          \
82     const void *const a__ = (EXPR);             \
83     if (a__ != NULL && a__ != (void *) 1)       \
84       ggc_set_mark (a__);                       \
85   } while (0)
86
87 /* A GC implementation must provide these functions.  */
88
89 /* Initialize the garbage collector.  */
90 extern void init_ggc            PARAMS ((void));
91 extern void init_stringpool     PARAMS ((void));
92
93 /* Start a new GGC context.  Memory allocated in previous contexts
94    will not be collected while the new context is active.  */
95 extern void ggc_push_context    PARAMS ((void));
96
97 /* Finish a GC context.  Any uncollected memory in the new context
98    will be merged with the old context.  */
99 extern void ggc_pop_context     PARAMS ((void));
100
101 /* Allocation.  */
102
103 /* The internal primitive.  */
104 extern void *ggc_alloc          PARAMS ((size_t));
105 /* Like ggc_alloc, but allocates cleared memory.  */
106 extern void *ggc_alloc_cleared  PARAMS ((size_t));
107 /* Resize a block.  */
108 extern void *ggc_realloc        PARAMS ((void *, size_t));
109 /* Like ggc_alloc_cleared, but performs a multiplication.  */
110 extern void *ggc_calloc         PARAMS ((size_t, size_t));
111
112 #define ggc_alloc_rtx(NSLOTS)                                             \
113   ((struct rtx_def *) ggc_alloc (sizeof (struct rtx_def)                  \
114                                  + ((NSLOTS) - 1) * sizeof (rtunion)))
115
116 #define ggc_alloc_rtvec(NELT)                                             \
117   ((struct rtvec_def *) ggc_alloc (sizeof (struct rtvec_def)              \
118                                    + ((NELT) - 1) * sizeof (rtx)))
119
120 #define ggc_alloc_tree(LENGTH) ((union tree_node *) ggc_alloc (LENGTH))
121
122 #define htab_create_ggc(SIZE, HASH, EQ, DEL) \
123   htab_create_alloc (SIZE, HASH, EQ, DEL, ggc_calloc, NULL)
124
125 /* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS.
126    If LENGTH is -1, then CONTENTS is assumed to be a
127    null-terminated string and the memory sized accordingly.  */
128 extern const char *ggc_alloc_string     PARAMS ((const char *contents,
129                                                  int length));
130
131 /* Make a copy of S, in GC-able memory.  */
132 #define ggc_strdup(S) ggc_alloc_string((S), -1)
133
134 /* Invoke the collector.  Garbage collection occurs only when this
135    function is called, not during allocations.  */
136 extern void ggc_collect                 PARAMS ((void));
137
138 /* Actually set the mark on a particular region of memory, but don't
139    follow pointers.  This function is called by ggc_mark_*.  It
140    returns zero if the object was not previously marked; non-zero if
141    the object was already marked, or if, for any other reason,
142    pointers in this data structure should not be traversed.  */
143 extern int ggc_set_mark                 PARAMS ((const void *));
144
145 /* Return 1 if P has been marked, zero otherwise.
146    P must have been allocated by the GC allocator; it mustn't point to
147    static objects, stack variables, or memory allocated with malloc.  */
148 extern int ggc_marked_p                 PARAMS ((const void *));
149
150 /* Statistics.  */
151
152 /* This structure contains the statistics common to all collectors.
153    Particular collectors can extend this structure.  */
154 typedef struct ggc_statistics
155 {
156   /* The Ith element is the number of nodes allocated with code I.  */
157   unsigned num_trees[256];
158   /* The Ith element is the number of bytes allocated by nodes with
159      code I.  */
160   size_t size_trees[256];
161   /* The Ith element is the number of nodes allocated with code I.  */
162   unsigned num_rtxs[256];
163   /* The Ith element is the number of bytes allocated by nodes with
164      code I.  */
165   size_t size_rtxs[256];
166   /* The total size of the tree nodes allocated.  */
167   size_t total_size_trees;
168   /* The total size of the RTL nodes allocated.  */
169   size_t total_size_rtxs;
170   /* The total number of tree nodes allocated.  */
171   unsigned total_num_trees;
172   /* The total number of RTL nodes allocated.  */
173   unsigned total_num_rtxs;
174 } ggc_statistics;
175
176 /* Return the number of bytes allocated at the indicated address.  */
177 extern size_t ggc_get_size              PARAMS ((const void *));
178
179 /* Used by the various collectors to gather and print statistics that
180    do not depend on the collector in use.  */
181 extern void ggc_print_common_statistics PARAMS ((FILE *, ggc_statistics *));
182
183 /* Print allocation statistics.  */
184 extern void ggc_print_statistics        PARAMS ((void));
185 extern void stringpool_statistics       PARAMS ((void));