From patchwork Sat Apr 20 01:23:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 238132 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id E158C2C020D for ; Sat, 20 Apr 2013 11:24:13 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=yS32vmGaQPzfc0bv/5WXPIDNrqsWFQ8U1tsRdz3vKgkXneVrB4Pgn Rpx7JOr4li/g3rFwndmTfDzjVD8X8B4tPvMHLFPiTt2hke2msLxsz5HSuXzEzK0p ZWWTa8teb8GdnGPZrIbK6C6ZZN7RkUXw1q7QoCkPZLsTHtrzPTflU0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=KH7L7NvKYfQA73u49OfXhuUNtU0=; b=JCHU4Q7CSeBj7Vjy5xQq ywER1lVryOhWyW4SiGuq1ITihesADZe9jkMHZHdGy1UP6ffhPw/FM+H9FMFUl6Ms HhuAeBquEpl5H9hpsdXIGPNCrbM/s2X0i+UpjHIJUMWWfqcv4kfnSsQ5ZfiiwNXI zkAgxZN8Kswp06mNFZ/pGQk= Received: (qmail 18334 invoked by alias); 20 Apr 2013 01:23:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 18302 invoked by uid 89); 20 Apr 2013 01:23:11 -0000 X-Spam-SWARE-Status: No, score=-7.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sat, 20 Apr 2013 01:23:10 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3K1N9RT001329 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 19 Apr 2013 21:23:09 -0400 Received: from surprise.redhat.com (vpn-238-97.phx2.redhat.com [10.3.238.97]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3K1N3a4010184; Fri, 19 Apr 2013 21:23:08 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 6/6] Example of converting global state to per-pass state Date: Fri, 19 Apr 2013 21:23:02 -0400 Message-Id: <1366420982-1546-7-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1366420982-1546-1-git-send-email-dmalcolm@redhat.com> References: <1365087283.1778.35.camel@surprise> <1366420982-1546-1-git-send-email-dmalcolm@redhat.com> 2013-04-17 David Malcolm * 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 + * 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 + * 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"); }