From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5341 invoked by alias); 14 Oct 2014 15:55:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 5320 invoked by uid 89); 14 Oct 2014 15:55:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 14 Oct 2014 15:55:53 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9EFtpcF026444 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Oct 2014 11:55:52 -0400 Received: from [10.3.233.121] (vpn-233-121.phx2.redhat.com [10.3.233.121]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9EFtppI019647; Tue, 14 Oct 2014 11:55:51 -0400 Message-ID: <1413301915.9513.68.camel@surprise> Subject: Re: [PATCH 3/5] timevar.h: Add an auto_timevar class From: David Malcolm To: Richard Biener Cc: jit@gcc.gnu.org, GCC Patches Date: Tue, 14 Oct 2014 15:58:00 -0000 In-Reply-To: References: <1413222308-25753-1-git-send-email-dmalcolm@redhat.com> <1413222308-25753-4-git-send-email-dmalcolm@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg01255.txt.bz2 On Tue, 2014-10-14 at 11:03 +0200, Richard Biener wrote: > On Mon, Oct 13, 2014 at 7:45 PM, David Malcolm wrote: > > This is used in a couple of places in jit/jit-playback.c to ensure > > that we pop the timevar on every exit path from a function. > > > > I could rewrite them if need be, but it does simplify things. > > Sorry to be bikeshedding but auto_timevar sounds odd - this is > just a one-element timevar stack. Sorry that the usage examples didn't make it through in my original email; these are in patch 06/10 in gcc/jit/jit-playback.c and look like this: playback::context:: compile () { ... lots of code... { auto_timevar assemble_timevar (TV_ASSEMBLE); ... lots of code, with multiple return paths... } } the idea being that the timevar_pop happens implicitly at the exit from the scope (e.g. via one of the error-handling returns). FWIW I rather like the current name: I think of it as an RAII-style way of not having to manually call timevar_pop. The "auto_" prefix to me evokes both such RAII types as "auto_ptr" and "auto_vec", and the fact that it's intended to be on the stack i.e. have "auto" storage class. > Don't have a real better name though :/ Maybe timevar_pushpop ? > > Otherwise this looks ok. > > Thanks, > Richard. > > > Written by Tom Tromey. > > > > gcc/ChangeLog: > > * timevar.h (class auto_timevar): New class. > > --- > > gcc/timevar.h | 24 ++++++++++++++++++++++++ > > 1 file changed, 24 insertions(+) > > > > diff --git a/gcc/timevar.h b/gcc/timevar.h > > index 6703cc9..f018e39 100644 > > --- a/gcc/timevar.h > > +++ b/gcc/timevar.h > > @@ -110,6 +110,30 @@ timevar_pop (timevar_id_t tv) > > timevar_pop_1 (tv); > > } > > > > +// This is a simple timevar wrapper class that pushes a timevar in its > > +// constructor and pops the timevar in its destructor. > > +class auto_timevar > > +{ > > + public: > > + auto_timevar (timevar_id_t tv) > > + : m_tv (tv) > > + { > > + timevar_push (m_tv); > > + } > > + > > + ~auto_timevar () > > + { > > + timevar_pop (m_tv); > > + } > > + > > + private: > > + > > + // Private to disallow copies. > > + auto_timevar (const auto_timevar &); > > + > > + timevar_id_t m_tv; > > +}; > > + > > extern void print_time (const char *, long); > > > > #endif /* ! GCC_TIMEVAR_H */ > > -- > > 1.8.5.3 > >