This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PLUGIN] Support for registering cache tables from plugins
- From: Duncan Sands <baldrick at free dot fr>
- To: Basile STARYNKEVITCH <basile at starynkevitch dot net>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 05 Sep 2009 00:59:27 +0200
- Subject: Re: [PLUGIN] Support for registering cache tables from plugins
- References: <4AA11626.6070909@free.fr> <4AA11BDB.5070004@starynkevitch.net>
Hi Basile,
Document it a little more. Very probably, GGC cache tables are not
documented at all (if it appears in some *.texi add a reference to that
occurrence). So perhaps a little more explanation could be useful. Maybe
just a sentence mentioning weak tables or weak pointers is ok. Your
english is very probably better than mine, so I leave you to propose a
phrasing.
I've changed the plugin docs so they mention if_marked, which is
described in the gty docs. See attached patch.
Out of curiosity, what kind of plugin are you writing?
It turns gimple into LLVM IR (see http://llvm.org/docs/LangRef.html)
and runs the LLVM optimizers and codegen rather than those of gcc.
It is llvm-gcc rewritten as a plugin. Currently it can codegen the
empty function :)
Ciao,
Duncan.
Index: mainline/gcc/doc/plugins.texi
===================================================================
--- mainline.orig/gcc/doc/plugins.texi 2009-09-04 15:05:45.485080155 +0200
+++ mainline/gcc/doc/plugins.texi 2009-09-05 00:47:48.329576215 +0200
@@ -133,6 +133,7 @@
PLUGIN_GGC_MARKING, /* Extend the GGC marking. */
PLUGIN_GGC_END, /* Called at end of GGC. */
PLUGIN_REGISTER_GGC_ROOTS, /* Register an extra GGC root table. */
+ PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */
PLUGIN_ATTRIBUTES, /* Called during attribute registration */
PLUGIN_START_UNIT, /* Called before processing a translation unit. */
PLUGIN_EVENT_LAST /* Dummy event used for indexing callback
@@ -151,8 +152,8 @@
@item @code{void *user_data}: Pointer to plugin-specific data.
@end itemize
-For the PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, and
-PLUGIN_REGISTER_GGC_ROOTS pseudo-events the @code{callback} should be
+For the PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PLUGIN_REGISTER_GGC_ROOTS
+and PLUGIN_REGISTER_GGC_CACHES pseudo-events the @code{callback} should be
null, and the @code{user_data} is specific.
@section Interacting with the pass manager
@@ -222,16 +223,19 @@
(and conversely, these routines should usually not be used in plugins
outside of the @code{PLUGIN_GGC_MARKING} event).
-Some plugins may need to add extra GGC root tables, e.g. to handle
-their own @code{GTY}-ed data. This can be done with the
-@code{PLUGIN_REGISTER_GGC_ROOTS} pseudo-event with a null callback and
-the extra root table as @code{user_data}. Running the @code{gengtype
+Some plugins may need to add extra GGC root tables, e.g. to handle their own
+@code{GTY}-ed data. This can be done with the @code{PLUGIN_REGISTER_GGC_ROOTS}
+pseudo-event with a null callback and the extra root table as @code{user_data}.
+Plugins that want to use the @code{if_marked} hash table option can add the
+extra GGC cache tables generated by @code{gengtype} using the
+@code{PLUGIN_REGISTER_GGC_CACHES} pseudo-event with a null callback and the
+extra cache table as @code{user_data}. Running the @code{gengtype
-p @var{source-dir} @var{file-list} @var{plugin*.c} ...} utility
-generates this extra root table.
+generates these extra root tables.
You should understand the details of memory management inside GCC
-before using @code{PLUGIN_GGC_MARKING} or
-@code{PLUGIN_REGISTER_GGC_ROOTS}.
+before using @code{PLUGIN_GGC_MARKING}, @code{PLUGIN_REGISTER_GGC_ROOTS}
+or @code{PLUGIN_REGISTER_GGC_CACHES}.
@section Giving information about a plugin
Index: mainline/gcc/gcc-plugin.h
===================================================================
--- mainline.orig/gcc/gcc-plugin.h 2009-09-04 15:05:45.481083902 +0200
+++ mainline/gcc/gcc-plugin.h 2009-09-04 15:10:10.909100327 +0200
@@ -40,6 +40,7 @@
PLUGIN_GGC_MARKING, /* Extend the GGC marking. */
PLUGIN_GGC_END, /* Called at end of GGC. */
PLUGIN_REGISTER_GGC_ROOTS, /* Register an extra GGC root table. */
+ PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */
PLUGIN_ATTRIBUTES, /* Called during attribute registration. */
PLUGIN_START_UNIT, /* Called before processing a translation unit. */
PLUGIN_EVENT_LAST /* Dummy event used for indexing callback
@@ -144,8 +145,8 @@
*/
/* This is also called without a callback routine for the
- PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PLUGIN_REGISTER_GGC_ROOTS
- pseudo-events, with a specific user_data.
+ PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PLUGIN_REGISTER_GGC_ROOTS and
+ PLUGIN_REGISTER_GGC_CACHES pseudo-events, with a specific user_data.
*/
extern void register_callback (const char *plugin_name,
Index: mainline/gcc/ggc-common.c
===================================================================
--- mainline.orig/gcc/ggc-common.c 2009-09-04 15:05:45.465074515 +0200
+++ mainline/gcc/ggc-common.c 2009-09-04 19:13:46.657073885 +0200
@@ -105,14 +105,29 @@
void
ggc_register_root_tab (const struct ggc_root_tab* rt)
{
- if (!rt)
- return;
- if (!extra_root_vec)
- {
- int vlen = 32;
- extra_root_vec = VEC_alloc (const_ggc_root_tab_t, heap, vlen);
- }
- VEC_safe_push (const_ggc_root_tab_t, heap, extra_root_vec, rt);
+ if (rt)
+ VEC_safe_push (const_ggc_root_tab_t, heap, extra_root_vec, rt);
+}
+
+
+/* This extra vector of dynamically registered cache_tab-s is used by
+ ggc_mark_roots and gives the ability to dynamically add new GGC cache
+ tables, for instance from some plugins; this vector is a heap one
+ [since it is used by GGC internally!] */
+typedef const struct ggc_cache_tab* const_ggc_cache_tab_t;
+DEF_VEC_P(const_ggc_cache_tab_t);
+DEF_VEC_ALLOC_P(const_ggc_cache_tab_t, heap);
+static VEC(const_ggc_cache_tab_t, heap) *extra_cache_vec;
+
+
+/* Dynamically register a new GGC cache table CT. This is useful for
+ plugins. */
+
+void
+ggc_register_cache_tab (const struct ggc_cache_tab* ct)
+{
+ if (ct)
+ VEC_safe_push (const_ggc_cache_tab_t, heap, extra_cache_vec, ct);
}
@@ -123,8 +138,10 @@
{
const struct ggc_root_tab *const *rt;
const struct ggc_root_tab *rti;
+ const_ggc_root_tab_t rtp;
const struct ggc_cache_tab *const *ct;
const struct ggc_cache_tab *cti;
+ const_ggc_cache_tab_t ctp;
size_t i;
for (rt = gt_ggc_deletable_rtab; *rt; rt++)
@@ -136,18 +153,11 @@
for (i = 0; i < rti->nelt; i++)
(*rti->cb) (*(void **)((char *)rti->base + rti->stride * i));
- if (extra_root_vec
- && VEC_length(const_ggc_root_tab_t,extra_root_vec) > 0)
+ for (i = 0; VEC_iterate(const_ggc_root_tab_t, extra_root_vec, i, rtp); i++)
{
- const_ggc_root_tab_t rtp = NULL;
- for (i=0;
- VEC_iterate(const_ggc_root_tab_t, extra_root_vec, i, rtp);
- i++)
- {
- for (rti = rtp; rti->base != NULL; rti++)
- for (i = 0; i < rti->nelt; i++)
- (*rti->cb) (*(void **) ((char *)rti->base + rti->stride * i));
- }
+ for (rti = rtp; rti->base != NULL; rti++)
+ for (i = 0; i < rti->nelt; i++)
+ (*rti->cb) (*(void **) ((char *)rti->base + rti->stride * i));
}
if (ggc_protect_identifiers)
@@ -165,6 +175,18 @@
ggc_set_mark ((*cti->base)->entries);
}
+ for (i = 0; VEC_iterate(const_ggc_cache_tab_t, extra_cache_vec, i, ctp); i++)
+ {
+ for (cti = ctp; cti->base != NULL; cti++)
+ if (*cti->base)
+ {
+ ggc_set_mark (*cti->base);
+ htab_traverse_noresize (*cti->base, ggc_htab_delete,
+ CONST_CAST (void *, (const void *)cti));
+ ggc_set_mark ((*cti->base)->entries);
+ }
+ }
+
if (! ggc_protect_identifiers)
ggc_purge_stringpool ();
Index: mainline/gcc/ggc.h
===================================================================
--- mainline.orig/gcc/ggc.h 2009-09-04 15:05:45.473077288 +0200
+++ mainline/gcc/ggc.h 2009-09-04 15:10:10.909100327 +0200
@@ -275,6 +275,10 @@
plugins. Does nothing if the passed pointer is null. */
extern void ggc_register_root_tab (const struct ggc_root_tab *);
+/* Register an additional cache table. This can be useful for some
+ plugins. Does nothing if the passed pointer is null. */
+extern void ggc_register_cache_tab (const struct ggc_cache_tab *);
+
/* Return the number of bytes allocated at the indicated address. */
extern size_t ggc_get_size (const void *);
Index: mainline/gcc/plugin.c
===================================================================
--- mainline.orig/gcc/plugin.c 2009-09-04 15:05:45.493077131 +0200
+++ mainline/gcc/plugin.c 2009-09-04 15:10:10.909100327 +0200
@@ -57,6 +57,7 @@
"PLUGIN_GGC_MARKING",
"PLUGIN_GGC_END",
"PLUGIN_REGISTER_GGC_ROOTS",
+ "PLUGIN_REGISTER_GGC_CACHES",
"PLUGIN_START_UNIT",
"PLUGIN_EVENT_LAST"
};
@@ -499,6 +500,10 @@
gcc_assert (!callback);
ggc_register_root_tab ((const struct ggc_root_tab*) user_data);
break;
+ case PLUGIN_REGISTER_GGC_CACHES:
+ gcc_assert (!callback);
+ ggc_register_cache_tab ((const struct ggc_cache_tab*) user_data);
+ break;
case PLUGIN_FINISH_TYPE:
case PLUGIN_START_UNIT:
case PLUGIN_FINISH_UNIT:
@@ -566,6 +571,7 @@
case PLUGIN_PASS_MANAGER_SETUP:
case PLUGIN_EVENT_LAST:
case PLUGIN_REGISTER_GGC_ROOTS:
+ case PLUGIN_REGISTER_GGC_CACHES:
default:
gcc_assert (false);
}
Index: mainline/gcc/ChangeLog
===================================================================
--- mainline.orig/gcc/ChangeLog 2009-09-04 15:11:00.682073030 +0200
+++ mainline/gcc/ChangeLog 2009-09-05 00:36:54.912148762 +0200
@@ -1,3 +1,17 @@
+2009-09-04 Duncan Sands <baldrick@free.fr>
+
+ * gcc-plugin.h (PLUGIN_REGISTER_GGC_CACHES): New event.
+ * plugin.c (plugin_event_name): Add PLUGIN_REGISTER_GGC_CACHES.
+ (register_callback): Dispatch it.
+ (invoke_plugin_callbacks): Incorporate in sanity check.
+ * ggc.h (ggc_register_cache_tab): Add declaration.
+ * ggc-common.c (const_ggc_cache_tab_t): New typedef.
+ (extra_cache_vec): New vector of dynamically added cache tables.
+ (ggc_register_root_tab): Simplify.
+ (ggc_register_cache_tab): New function.
+ (ggc_mark_roots): Simplify dynamic roots. Handle dynamic caches.
+ * doc/plugins.texi: Document PLUGIN_REGISTER_GGC_CACHES.
+
2009-09-04 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/41112