diff mbox

[RFA,jit,v2,2/2] introduce auto_timevar

Message ID 1395251539-16155-3-git-send-email-tromey@redhat.com
State New
Headers show

Commit Message

Tom Tromey March 19, 2014, 5:52 p.m. UTC
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(-)

Comments

David Malcolm March 19, 2014, 7:31 p.m. UTC | #1
On Wed, 2014-03-19 at 11:52 -0600, Tom Tromey wrote:
> 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(-)

OK (and it fixes a bug in the earlier version of the patch in the dtor,
which pushed rather than popped).

Are you able to push this to my branch yourself, or do you need me to do
this?
diff mbox

Patch

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  <tromey@redhat.com>
 
+	* timevar.h (auto_timevar): New class.
+
+2014-03-19  Tom Tromey  <tromey@redhat.com>
+
 	* 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  <tromey@redhat.com>
 
+	* internal-api.c (compile): Use auto_timevar.
+
+2014-03-19  Tom Tromey  <tromey@redhat.com>
+
 	* 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 <samuel@codesourcery.com>
 
    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 */