From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2733 invoked by alias); 18 Mar 2014 14:57:57 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 2618 invoked by uid 89); 18 Mar 2014 14:57:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.98.1 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_05,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_05,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com From: Tom Tromey To: jit@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org, Tom Tromey Subject: [RFA jit 2/2] introduce scoped_timevar Date: Wed, 01 Jan 2014 00:00:00 -0000 Message-Id: <1395154664-29657-3-git-send-email-tromey@redhat.com> In-Reply-To: <1395154664-29657-1-git-send-email-tromey@redhat.com> References: <1395154664-29657-1-git-send-email-tromey@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-SW-Source: 2014-q1/txt/msg00080.txt.bz2 This introduces a new scoped_timevar class. It pushes a given timevar in its constructor, and pops it in the destructor, giving a much simpler way to use timevars in the typical case where they can be scoped. --- gcc/ChangeLog.jit | 4 ++++ gcc/jit/ChangeLog.jit | 4 ++++ gcc/jit/internal-api.c | 16 +++++----------- gcc/timevar.h | 24 +++++++++++++++++++++++- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c index 6a4d2ae..8285c64 100644 --- a/gcc/jit/internal-api.c +++ b/gcc/jit/internal-api.c @@ -3737,8 +3737,6 @@ compile () if (get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE)) dump_generated_code (); - timevar_push (TV_ASSEMBLE); - /* Gross hacks follow: We have a .s file; we want a .so file. We could reuse parts of gcc/gcc.c to do this. @@ -3746,6 +3744,8 @@ compile () */ /* FIXME: totally faking it for now, not even using pex */ { + scoped_timevar assemble_timevar (TV_ASSEMBLE); + char cmd[1024]; snprintf (cmd, 1024, "gcc -shared %s -o %s", m_path_s_file, m_path_so_file); @@ -3753,20 +3753,16 @@ compile () printf ("cmd: %s\n", cmd); int ret = system (cmd); if (ret) - { - timevar_pop (TV_ASSEMBLE); - return NULL; - } + return NULL; } - timevar_pop (TV_ASSEMBLE); // TODO: split out assembles vs linker /* dlopen the .so file. */ { - const char *error; + scoped_timevar load_timevar (TV_LOAD); - timevar_push (TV_LOAD); + const char *error; /* Clear any existing error. */ dlerror (); @@ -3779,8 +3775,6 @@ compile () result_obj = new result (handle); else result_obj = NULL; - - timevar_pop (TV_LOAD); } return result_obj; diff --git a/gcc/timevar.h b/gcc/timevar.h index dc2a8bc..eb8bf0d 100644 --- a/gcc/timevar.h +++ b/gcc/timevar.h @@ -1,5 +1,5 @@ /* Timing variables for measuring compiler performance. - Copyright (C) 2000-2013 Free Software Foundation, Inc. + Copyright (C) 2000-2014 Free Software Foundation, Inc. Contributed by Alex Samuel This file is part of GCC. @@ -110,6 +110,28 @@ timevar_pop (timevar_id_t tv) timevar_pop_1 (tv); } +class scoped_timevar +{ + public: + scoped_timevar (timevar_id_t tv) + : m_tv (tv) + { + timevar_push (m_tv); + } + + ~scoped_timevar () + { + timevar_push (m_tv); + } + + private: + + // Private to disallow copies. + scoped_timevar (const scoped_timevar &); + + timevar_id_t m_tv; +}; + extern void print_time (const char *, long); #endif /* ! GCC_TIMEVAR_H */ -- 1.8.5.3