From patchwork Wed Mar 19 17:52:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 331811 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 74A1A2C007E for ; Thu, 20 Mar 2014 04:52:59 +1100 (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=XhelpJfcmoKBITEoLM+E+h1AV89MDoJ8R1dRgFIOrBWBAb2zzIg2f Plc7A0B5SZMihtBwJe/lq7GdHd2sM2+fFfylh1bS3l3qB8vAjym+FF6CzdesTXHY wVM+cU0gwCkqZGM2NvyV+WxX7lSs3bbVMmYxDkkoNq25wOpXj/1YUc= 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=7na5BrCl5DW6z7Bv1Ce3ltAT9gg=; b=x9WpTyWr/Av8VMuubfWR kX7iRHYKxjPUEK/8ydiNOjOFJUx6DYHKJImLvksLfLlTVuqZXImeHlPHGGORcthp DrWatHTIaFhhf5RZBnUUKM7UnKzm5P/0haNxlM9Cx6eTFiqOvgb26m12ZVon6X0V k9FfJAQYa4Px4X3IWboR0+8= Received: (qmail 10050 invoked by alias); 19 Mar 2014 17:52:40 -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 9989 invoked by uid 89); 19 Mar 2014 17:52:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 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 ESMTP; Wed, 19 Mar 2014 17:52:31 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2JHqUU9029803 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 19 Mar 2014 13:52:30 -0400 Received: from barimba.redhat.com (ovpn-113-169.phx2.redhat.com [10.3.113.169]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2JHqNuo001374; Wed, 19 Mar 2014 13:52:29 -0400 From: Tom Tromey To: jit@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org, Tom Tromey Subject: [RFA jit v2 2/2] introduce auto_timevar Date: Wed, 19 Mar 2014 11:52:19 -0600 Message-Id: <1395251539-16155-3-git-send-email-tromey@redhat.com> In-Reply-To: <1395251539-16155-1-git-send-email-tromey@redhat.com> References: <1395251539-16155-1-git-send-email-tromey@redhat.com> This introduces a new auto_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 | 26 +++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog.jit b/gcc/ChangeLog.jit index c590ab1..ee1df88 100644 --- a/gcc/ChangeLog.jit +++ b/gcc/ChangeLog.jit @@ -1,5 +1,9 @@ 2014-03-19 Tom Tromey + * timevar.h (auto_timevar): New class. + +2014-03-19 Tom Tromey + * diagnostic.c (bt_stop): Use toplev::main. * main.c (main): Update. * toplev.c (do_compile): Remove argument. Don't check diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit index e45d38c..69f2412 100644 --- a/gcc/jit/ChangeLog.jit +++ b/gcc/jit/ChangeLog.jit @@ -1,5 +1,9 @@ 2014-03-19 Tom Tromey + * internal-api.c (compile): Use auto_timevar. + +2014-03-19 Tom Tromey + * internal-api.c (compile): Use toplev, not toplev_options. Simplify. diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c index 95978bf..090d351 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 */ { + auto_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; + auto_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..f018e39 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,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 */