This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[boehms-gc] Some gengtype/GC changes
- From: "Laurynas Biveinis" <laurynas dot biveinis at gmail dot com>
- To: "Gcc Patch List" <gcc-patches at gcc dot gnu dot org>
- Cc: "Daniel Berlin" <dberlin at dberlin dot org>
- Date: Tue, 15 Aug 2006 22:45:31 +0300
- Subject: [boehms-gc] Some gengtype/GC changes
Hi,
The patch below does the following:
1) Makes gengtype output type enumerations and allocation routines for
more data types. I can only guess that gengtype used to do data type
tracing from GC roots to know what data types are interesting for GC
and output only their stuff. This does not work now, because I want
typed allocation routines for the things that are allocated in local
variables too. So I just relaxed the skipping conditions in the
outputting loops.
2) Add cleared typed allocation routines.
3) ggc-page, ggc-zone might be broken now.
4) All in all, this makes way for another, mostly boring, patch that
makes use of the typed allocation routines. Things that are missing:
- arrays;
- variable-length structures;
- data types that were not interesting to GTY infrastructure before,
e.g. my earlier mail today about lambda_trans_matrix.
Now I will attack them. Any advice how to deal with them is welcome in
advance :)
Questions:
1) What does
if (s->gc_used == GC_MAYBE_POINTED_TO
&& s->u.s.line.file == NULL)
continue;
do?
Index: gcc/gengtype.c
===================================================================
--- gcc/gengtype.c (revision 116135)
+++ gcc/gengtype.c (working copy)
@@ -2441,25 +2441,22 @@
oprintf (header_file, "\n/* Enumeration of known types. */\n");
oprintf (header_file, "enum gt_types_enum {\n");
for (s = structures; s; s = s->next)
- if (s->gc_used == GC_POINTED_TO
- || s->gc_used == GC_MAYBE_POINTED_TO)
- {
- if (s->gc_used == GC_MAYBE_POINTED_TO
- && s->u.s.line.file == NULL)
- continue;
+ {
+ if (s->gc_used == GC_MAYBE_POINTED_TO
+ && s->u.s.line.file == NULL)
+ continue;
- oprintf (header_file, " gt_ggc_e_");
- output_mangled_typename (header_file, s);
- oprintf (header_file, ", \n");
- }
+ oprintf (header_file, " gt_ggc_e_");
+ output_mangled_typename (header_file, s);
+ oprintf (header_file, ", \n");
+ }
for (s = param_structs; s; s = s->next)
- if (s->gc_used == GC_POINTED_TO)
- {
- oprintf (header_file, " gt_e_");
- output_mangled_typename (header_file, s);
- oprintf (header_file, ", \n");
- }
+ {
+ oprintf (header_file, " gt_e_");
+ output_mangled_typename (header_file, s);
+ oprintf (header_file, ", \n");
+ }
oprintf (header_file, " gt_types_enum_last\n");
oprintf (header_file, "};\n");
@@ -2476,35 +2473,42 @@
oprintf (header_file,
"\n/* Typed allocation for known structs and unions. */\n");
for (s = structures; s; s = s->next)
- if (s->gc_used == GC_POINTED_TO
- || (s->gc_used == GC_MAYBE_POINTED_TO && s->u.s.line.file != NULL))
- {
- options_p o;
- int have_size = 0;
- const char *type_kind;
+ {
+ options_p o;
+ int have_size = 0;
+ const char *type_kind;
- for (o = s->u.s.opt; o; o = o->next)
- if (strcmp (o->name, "size_not_fixed") == 0)
- have_size = 1;
-
- if (s->kind == TYPE_STRUCT)
- type_kind = "struct ";
- else if (s->kind == TYPE_UNION)
- type_kind = "union ";
- else
- type_kind = "";
+ for (o = s->u.s.opt; o; o = o->next)
+ if (strcmp (o->name, "size_not_fixed") == 0)
+ have_size = 1;
- oprintf (header_file, "#define ggc_alloc_%s(%s) \\\n",
- s->u.s.tag, (have_size ? "SIZE" : ""));
- oprintf (header_file, " ggc_alloc_typed(gt_ggc_e_");
- output_mangled_typename (header_file, s);
- if (have_size)
- oprintf (header_file, ", SIZE)\n");
- else
- oprintf (header_file, ", sizeof (%s%s))\n",
- type_kind, s->u.s.tag);
- }
+ if (s->kind == TYPE_STRUCT)
+ type_kind = "struct ";
+ else if (s->kind == TYPE_UNION)
+ type_kind = "union ";
+ else
+ type_kind = "";
+ oprintf (header_file, "#define ggc_alloc_%s(%s) \\\n",
+ s->u.s.tag, (have_size ? "SIZE" : ""));
+ oprintf (header_file, " ggc_alloc_typed(gt_ggc_e_");
+ output_mangled_typename (header_file, s);
+ if (have_size)
+ oprintf (header_file, ", SIZE)\n");
+ else
+ oprintf (header_file, ", sizeof (%s%s))\n",
+ type_kind, s->u.s.tag);
+
+ oprintf (header_file, "#define ggc_alloc_cleared_%s(%s) \\\n",
+ s->u.s.tag, (have_size ? "SIZE" : ""));
+ oprintf (header_file, " ggc_alloc_cleared_typed(gt_ggc_e_");
+ output_mangled_typename (header_file, s);
+ if (have_size)
+ oprintf (header_file, ", SIZE)\n");
+ else
+ oprintf (header_file, ", sizeof (%s%s))\n",
+ type_kind, s->u.s.tag);
+ }
oprintf (header_file,
"\n/* Typed allocation for known typedefs. */\n");
for (p = typedefs; p != NULL; p = p->next)
@@ -2513,20 +2517,23 @@
if (strcmp (p->name, s->u.s.tag) == 0)
continue;
- if (s->gc_used == GC_POINTED_TO
- || (s->gc_used == GC_MAYBE_POINTED_TO && s->u.s.line.file != NULL))
- {
- if (s->kind != TYPE_STRUCT
- && s->kind != TYPE_UNION)
- continue;
+ if (s->kind != TYPE_STRUCT
+ && s->kind != TYPE_UNION)
+ continue;
- oprintf (header_file, "#define ggc_alloc_%s(%s) \\\n",
- p->name, s->kind == TYPE_STRUCT ? "" : "__SIZE");
- oprintf (header_file, " ggc_alloc_typed(gt_ggc_e_");
- output_mangled_typename (header_file, s);
- oprintf (header_file, ", sizeof (%s%s))\n",
- s->kind == TYPE_STRUCT ? "struct " : "", s->u.s.tag);
- }
+ oprintf (header_file, "#define ggc_alloc_%s(%s) \\\n",
+ p->name, s->kind == TYPE_STRUCT ? "" : "__SIZE");
+ oprintf (header_file, " ggc_alloc_typed(gt_ggc_e_");
+ output_mangled_typename (header_file, s);
+ oprintf (header_file, ", sizeof (%s%s))\n",
+ s->kind == TYPE_STRUCT ? "struct " : "", s->u.s.tag);
+
+ oprintf (header_file, "#define ggc_alloc_cleared_%s(%s) \\\n",
+ p->name, s->kind == TYPE_STRUCT ? "" : "__SIZE");
+ oprintf (header_file, " ggc_alloc_cleared_typed(gt_ggc_e_");
+ output_mangled_typename (header_file, s);
+ oprintf (header_file, ", sizeof (%s%s))\n",
+ s->kind == TYPE_STRUCT ? "struct " : "", s->u.s.tag);
}
}
Index: gcc/ggc.h
===================================================================
--- gcc/ggc.h (revision 116135)
+++ gcc/ggc.h (working copy)
@@ -209,6 +209,9 @@
#define ggc_alloc_typed(s,z) ggc_alloc_typed_stat (s,z MEM_STAT_INFO)
/* Like ggc_alloc, but allocates cleared memory. */
extern void *ggc_alloc_cleared_stat (size_t MEM_STAT_DECL);
+extern void *ggc_alloc_cleared_typed_stat (enum gt_types_enum,
+ size_t MEM_STAT_DECL);
+#define ggc_alloc_cleared_typed(s, z)
ggc_alloc_cleared_typed_stat(s,z MEM_STAT_INFO)
#define ggc_alloc_cleared(s) ggc_alloc_cleared_stat (s MEM_STAT_INFO)
/* Resize a block. */
extern void *ggc_realloc_stat (void *, size_t MEM_STAT_DECL);
Index: gcc/ggc-boehm.c
===================================================================
--- gcc/ggc-boehm.c (revision 116135)
+++ gcc/ggc-boehm.c (working copy)
@@ -86,6 +86,14 @@
return result;
}
+void *ggc_alloc_cleared_typed_stat (enum gt_types_enum type,
+ size_t size MEM_STAT_DECL)
+{
+ void * result = ggc_alloc_typed_stat(type, size);
+ memset (result, 0, size);
+ return result;
+}
+
enum gt_types_enum
get_block_type(void * block)
{
--
Laurynas