[patch][plugin] Invoke FINISH_UNIT callbacks earlier
Olatunji Ruwase
tjruwase@google.com
Thu Jul 2 22:40:00 GMT 2009
Hello,
FINISH_UNIT callbacks are currently invoked quite late (after finalize()).
This patch invokes these callbacks earlier allowing the plugin to do
more useful for example create a fake function as shown in the
included testcase.
Patch bootstraps and shows no testsuite regression on x86_64-unknown-linux-gnu
Thanks
tunji
-------------- next part --------------
2009-07-02 Olatunji Ruwase <tjruwase@google.com>
* toplev.c: Invoke FINISH_UNIT callbacks earlier, before
useful structures are destroyed e.g by finalize.
2009-07-02 Olatunji Ruwase <tjruwase@google.com>
* gcc.dg/plugin/finish_unit_plugin.c: New test.
* gcc.dg/plugin/finish_unit-test-1.c: New test.
* gcc.dg/plugin/plugin.exp: Added finish_unit_plugin.c test.
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c (revision 149190)
+++ gcc/toplev.c (working copy)
@@ -1089,6 +1089,9 @@ compile_file (void)
}
#endif
+ /* Invoke registered plugin callbacks. */
+ invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
+
/* This must be at the end. Some target ports emit end of file directives
into the assembly file here, and hence we can not output anything to the
assembly file after this point. */
@@ -2346,9 +2349,6 @@ do_compile (void)
compile_file ();
finalize ();
-
- /* Invoke registered plugin callbacks. */
- invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
}
/* Stop timing and print the times. */
Index: gcc/testsuite/gcc.dg/plugin/plugin.exp
===================================================================
--- gcc/testsuite/gcc.dg/plugin/plugin.exp (revision 149190)
+++ gcc/testsuite/gcc.dg/plugin/plugin.exp (working copy)
@@ -51,6 +51,7 @@ set plugin_test_list [list \
{ ggcplug.c ggcplug-test-1.c } \
{ one_time_plugin.c one_time-test-1.c } \
{ start_unit_plugin.c start_unit-test-1.c } \
+ { finish_unit_plugin.c finish_unit-test-1.c } \
]
foreach plugin_test $plugin_test_list {
Index: gcc/testsuite/gcc.dg/plugin/finish_unit-test-1.c
===================================================================
--- gcc/testsuite/gcc.dg/plugin/finish_unit-test-1.c (revision 0)
+++ gcc/testsuite/gcc.dg/plugin/finish_unit-test-1.c (revision 0)
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+int main (int argc, char **argv)
+{
+ return 0;
+}
Index: gcc/testsuite/gcc.dg/plugin/finish_unit_plugin.c
===================================================================
--- gcc/testsuite/gcc.dg/plugin/finish_unit_plugin.c (revision 0)
+++ gcc/testsuite/gcc.dg/plugin/finish_unit_plugin.c (revision 0)
@@ -0,0 +1,28 @@
+/* This plugin creates a fake function in the FINISH_UNIT callback, in
+ * other words right after compilation of the translation unit.
+*/
+#include "gcc-plugin.h"
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "toplev.h"
+#include "basic-block.h"
+#include "gimple.h"
+#include "tree.h"
+#include "tree-pass.h"
+#include "intl.h"
+
+int plugin_is_GPL_compatible;
+
+static void finish_unit_callback (void *gcc_data, void *user_data)
+{
+ cgraph_build_static_cdtor ('I', NULL, DEFAULT_INIT_PRIORITY);
+}
+
+int plugin_init (struct plugin_name_args *plugin_info,
+ struct plugin_gcc_version *version)
+{
+ register_callback ("finish_unit", PLUGIN_FINISH_UNIT, &finish_unit_callback, NULL);
+ return 0;
+}
More information about the Gcc-patches
mailing list