This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 6/6] Example of converting global state to per-pass state
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Fri, 19 Apr 2013 21:23:02 -0400
- Subject: [PATCH 6/6] Example of converting global state to per-pass state
- References: <1365087283 dot 1778 dot 35 dot camel at surprise> <1366420982-1546-1-git-send-email-dmalcolm at redhat dot com>
2013-04-17 David Malcolm <dmalcolm@redhat.com>
* testsuite/gcc.dg/plugin/one_time_plugin.c (one_pass_gate): example
of converting global state to per-pass state: convert the
"static int counter" within the one_pass::execute hook from having
global lifetime to being a field of the pass instance
---
gcc/ChangeLog | 7 +++++++
gcc/testsuite/gcc.dg/plugin/one_time_plugin.c | 7 ++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8554fb3..88b95b8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2013-04-19 David Malcolm <dmalcolm@redhat.com>
+ * testsuite/gcc.dg/plugin/one_time_plugin.c (one_pass_gate): example
+ of converting global state to per-pass state: convert the
+ "static int counter" within the one_pass::execute hook from having
+ global lifetime to being a field of the pass instance
+
+2013-04-17 David Malcolm <dmalcolm@redhat.com>
+
* testsuite/gcc.dg/plugin/one_time_plugin.c (one_pass_gate): convert
to a virtual function: one_pass::gate
(one_pass_exec): convert to a virtual function: one_pass::impl_execute
diff --git a/gcc/testsuite/gcc.dg/plugin/one_time_plugin.c b/gcc/testsuite/gcc.dg/plugin/one_time_plugin.c
index 2be2d80..53446f9 100644
--- a/gcc/testsuite/gcc.dg/plugin/one_time_plugin.c
+++ b/gcc/testsuite/gcc.dg/plugin/one_time_plugin.c
@@ -24,7 +24,8 @@ public:
provided(0),
destroyed(0)),
pass_todo_flags(start(0),
- finish(0)))
+ finish(0))),
+ counter(0)
{}
/* opt_pass methods: */
@@ -34,6 +35,8 @@ public:
bool has_execute () { return true; }
unsigned int impl_execute ();
+private:
+ int counter;
}; // class one_pass
bool one_pass::gate (void)
@@ -43,8 +46,6 @@ bool one_pass::gate (void)
unsigned int one_pass::impl_execute ()
{
- static int counter = 0;
-
if (counter > 0) {
printf ("Executed more than once \n");
}
--
1.7.11.7