OSDN Git Service

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