Patchwork [6/6] Example of converting global state to per-pass state

login
register
mail settings
Submitter David Malcolm
Date April 20, 2013, 1:23 a.m.
Message ID <1366420982-1546-7-git-send-email-dmalcolm@redhat.com>
Download mbox | patch
Permalink /patch/238132/
State New
Headers show

Comments

David Malcolm - April 20, 2013, 1:23 a.m.
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(-)

Patch

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");
  }