public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [RFA jit v2 1/2] introduce class toplev
  2014-01-01  0:00     ` David Malcolm
@ 2014-01-01  0:00       ` Tom Tromey
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2014-01-01  0:00 UTC (permalink / raw)
  To: David Malcolm; +Cc: jit, gcc-patches

David> OK.  Are you able to push this to my branch, or do you need me to do
David> this?

Thanks, I was able to push them.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA jit v2 2/2] introduce auto_timevar
  2014-01-01  0:00 ` [RFA jit v2 2/2] introduce auto_timevar Tom Tromey
@ 2014-01-01  0:00   ` David Malcolm
  0 siblings, 0 replies; 7+ messages in thread
From: David Malcolm @ 2014-01-01  0:00 UTC (permalink / raw)
  To: Tom Tromey; +Cc: jit, gcc-patches

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?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFA jit v2 1/2] introduce class toplev
  2014-01-01  0:00 [RFA jit v2 0/2] minor refactorings for reuse Tom Tromey
  2014-01-01  0:00 ` [RFA jit v2 2/2] introduce auto_timevar Tom Tromey
@ 2014-01-01  0:00 ` Tom Tromey
  2014-01-01  0:00   ` Tom Tromey
  1 sibling, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2014-01-01  0:00 UTC (permalink / raw)
  To: jit; +Cc: gcc-patches, Tom Tromey

This patch introduces a new "class toplev" and changes toplev_main and
toplev_finalize to be methods of this class.  Additionally, now the
timevars are automatically stopped when the object is destroyed.  This
cleans up "compile" a bit and makes it simpler to reuse the toplev
logic in other code.
---
 gcc/ChangeLog.jit      | 14 +++++++++++++
 gcc/diagnostic.c       |  2 +-
 gcc/jit/ChangeLog.jit  |  5 +++++
 gcc/jit/internal-api.c | 25 +++++-----------------
 gcc/main.c             |  9 ++++----
 gcc/toplev.c           | 56 +++++++++++++++++++++++++++++---------------------
 gcc/toplev.h           | 20 ++++++++++++------
 7 files changed, 76 insertions(+), 55 deletions(-)

diff --git a/gcc/ChangeLog.jit b/gcc/ChangeLog.jit
index 77ac44c..c590ab1 100644
--- a/gcc/ChangeLog.jit
+++ b/gcc/ChangeLog.jit
@@ -1,3 +1,17 @@
+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
+	use_TV_TOTAL.
+	(toplev::toplev, toplev::~toplev, toplev::start_timevars): New
+	functions.
+	(toplev::main): Rename from toplev_main.  Update.
+	(toplev::finalize): Rename from toplev_finalize.  Update.
+	* toplev.h (class toplev): New.
+	(struct toplev_options): Remove.
+	(toplev_main, toplev_finalize): Don't declare.
+
 2014-03-11  David Malcolm  <dmalcolm@redhat.com>
 
 	* gcse.c (gcse_c_finalize): New, to clear test_insn between
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 36094a1..56dc3ac 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -333,7 +333,7 @@ diagnostic_show_locus (diagnostic_context * context,
 static const char * const bt_stop[] =
 {
   "main",
-  "toplev_main",
+  "toplev::main",
   "execute_one_pass",
   "compile_file",
 };
diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index efb1931..e45d38c 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,3 +1,8 @@
+2014-03-19  Tom Tromey  <tromey@redhat.com>
+
+	* internal-api.c (compile): Use toplev, not toplev_options.
+	Simplify.
+
 2014-03-19  David Malcolm  <dmalcolm@redhat.com>
 
 	* internal-api.c (gcc::jit::recording::memento_of_get_pointer::
diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c
index e3ddc4d..95978bf 100644
--- a/gcc/jit/internal-api.c
+++ b/gcc/jit/internal-api.c
@@ -3650,7 +3650,7 @@ compile ()
 
   /* Call into the rest of gcc.
      For now, we have to assemble command-line options to pass into
-     toplev_main, so that they can be parsed. */
+     toplev::main, so that they can be parsed. */
 
   /* Pass in user-provided "progname", if any, so that it makes it
      into GCC's "progname" global, used in various diagnostics. */
@@ -3724,25 +3724,15 @@ compile ()
       ADD_ARG ("-fdump-ipa-all");
     }
 
-  toplev_options toplev_opts;
-  toplev_opts.use_TV_TOTAL = false;
+  toplev toplev (false);
 
-  if (time_report || !quiet_flag  || flag_detailed_statistics)
-    timevar_init ();
-
-  timevar_start (TV_TOTAL);
-
-  toplev_main (num_args, const_cast <char **> (fake_args), &toplev_opts);
-  toplev_finalize ();
+  toplev.main (num_args, const_cast <char **> (fake_args));
+  toplev.finalize ();
 
   active_playback_ctxt = NULL;
 
   if (errors_occurred ())
-    {
-      timevar_stop (TV_TOTAL);
-      timevar_print (stderr);
-      return NULL;
-    }
+    return NULL;
 
   if (get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE))
    dump_generated_code ();
@@ -3765,8 +3755,6 @@ compile ()
     if (ret)
       {
 	timevar_pop (TV_ASSEMBLE);
-	timevar_stop (TV_TOTAL);
-	timevar_print (stderr);
 	return NULL;
       }
   }
@@ -3795,9 +3783,6 @@ compile ()
     timevar_pop (TV_LOAD);
   }
 
-  timevar_stop (TV_TOTAL);
-  timevar_print (stderr);
-
   return result_obj;
 }
 
diff --git a/gcc/main.c b/gcc/main.c
index b893308..4bba041 100644
--- a/gcc/main.c
+++ b/gcc/main.c
@@ -1,5 +1,5 @@
 /* main.c: defines main() for cc1, cc1plus, etc.
-   Copyright (C) 2007-2013 Free Software Foundation, Inc.
+   Copyright (C) 2007-2014 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -26,15 +26,14 @@ along with GCC; see the file COPYING3.  If not see
 
 int main (int argc, char **argv);
 
-/* We define main() to call toplev_main(), which is defined in toplev.c.
+/* We define main() to call toplev::main(), which is defined in toplev.c.
    We do this in a separate file in order to allow the language front-end
    to define a different main(), if it so desires.  */
 
 int
 main (int argc, char **argv)
 {
-  toplev_options toplev_opts;
-  toplev_opts.use_TV_TOTAL = true;
+  toplev toplev (true);
 
-  return toplev_main (argc, argv, &toplev_opts);
+  return toplev.main (argc, argv);
 }
diff --git a/gcc/toplev.c b/gcc/toplev.c
index f1ac560..5284621 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1,5 +1,5 @@
 /* Top level of GCC compilers (cc1, cc1plus, etc.)
-   Copyright (C) 1987-2013 Free Software Foundation, Inc.
+   Copyright (C) 1987-2014 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -95,7 +95,7 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 
 static void general_init (const char *);
-static void do_compile (const toplev_options *toplev_opts);
+static void do_compile ();
 static void process_options (void);
 static void backend_init (void);
 static int lang_dependent_init (const char *);
@@ -1854,18 +1854,8 @@ finalize (bool no_backend)
 
 /* Initialize the compiler, and compile the input file.  */
 static void
-do_compile (const toplev_options *toplev_opts)
+do_compile ()
 {
-  /* Initialize timing first.  The C front ends read the main file in
-     the post_options hook, and C++ does file timings.  */
-  if (toplev_opts->use_TV_TOTAL)
-    {
-      if (time_report || !quiet_flag  || flag_detailed_statistics)
-        timevar_init ();
-
-      timevar_start (TV_TOTAL);
-    }
-
   process_options ();
 
   /* Don't do any more if an error has already occurred.  */
@@ -1910,13 +1900,28 @@ do_compile (const toplev_options *toplev_opts)
 
       timevar_stop (TV_PHASE_FINALIZE);
     }
+}
 
-  if (toplev_opts->use_TV_TOTAL)
-    {
-      /* Stop timing and print the times.  */
-      timevar_stop (TV_TOTAL);
-      timevar_print (stderr);
-    }
+toplev::toplev (bool use)
+  : use_TV_TOTAL (use)
+{
+  if (!use_TV_TOTAL)
+    start_timevars ();
+}
+
+toplev::~toplev ()
+{
+  timevar_stop (TV_TOTAL);
+  timevar_print (stderr);
+}
+
+void
+toplev::start_timevars ()
+{
+  if (time_report || !quiet_flag  || flag_detailed_statistics)
+    timevar_init ();
+
+  timevar_start (TV_TOTAL);
 }
 
 /* Entry point of cc1, cc1plus, jc1, f771, etc.
@@ -1926,7 +1931,7 @@ do_compile (const toplev_options *toplev_opts)
    It is not safe to call this function more than once.  */
 
 int
-toplev_main (int argc, char **argv, const toplev_options *toplev_opts)
+toplev::main (int argc, char **argv)
 {
   /* Parsing and gimplification sometimes need quite large stack.
      Increase stack size limits if possible.  */
@@ -1976,7 +1981,11 @@ toplev_main (int argc, char **argv, const toplev_options *toplev_opts)
 
   /* Exit early if we can (e.g. -help).  */
   if (!exit_after_options)
-    do_compile (toplev_opts);
+    {
+      if (use_TV_TOTAL)
+	start_timevars ();
+      do_compile ();
+    }
 
   if (warningcount || errorcount || werrorcount)
     print_ignored_options ();
@@ -1994,8 +2003,9 @@ toplev_main (int argc, char **argv, const toplev_options *toplev_opts)
 }
 
 /* For those that want to, this function aims to clean up enough state that
-   you can call toplev_main again. */
-void toplev_finalize (void)
+   you can call toplev::main again. */
+void
+toplev::finalize (void)
 {
   cgraph_c_finalize ();
   cgraphbuild_c_finalize ();
diff --git a/gcc/toplev.h b/gcc/toplev.h
index a99fee1..23ae842 100644
--- a/gcc/toplev.h
+++ b/gcc/toplev.h
@@ -24,16 +24,24 @@ along with GCC; see the file COPYING3.  If not see
 extern struct cl_decoded_option *save_decoded_options;
 extern unsigned int save_decoded_options_count;
 
-/* Options for invoking toplev_main.  */
-struct toplev_options
+/* Invoking the compiler.  */
+class toplev
 {
-  /* Should do_compile use TV_TOTAL, or is some other wrapper
-     using it? */
+public:
+  toplev (bool use);
+  ~toplev ();
+
+  int main (int argc, char **argv);
+
+  void finalize ();
+
+private:
+
+  void start_timevars ();
+
   bool use_TV_TOTAL;
 };
 
-extern int toplev_main (int, char **, const toplev_options *toplev_opts);
-extern void toplev_finalize (void);
 extern void rest_of_decl_compilation (tree, int, int);
 extern void rest_of_type_compilation (tree, int);
 extern void init_optimization_passes (void);
-- 
1.8.5.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFA jit v2 2/2] introduce auto_timevar
  2014-01-01  0:00 [RFA jit v2 0/2] minor refactorings for reuse Tom Tromey
@ 2014-01-01  0:00 ` Tom Tromey
  2014-01-01  0:00   ` David Malcolm
  2014-01-01  0:00 ` [RFA jit v2 1/2] introduce class toplev Tom Tromey
  1 sibling, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2014-01-01  0:00 UTC (permalink / raw)
  To: jit; +Cc: gcc-patches, Tom Tromey

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  <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 */
-- 
1.8.5.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA jit v2 1/2] introduce class toplev
  2014-01-01  0:00   ` Tom Tromey
@ 2014-01-01  0:00     ` David Malcolm
  2014-01-01  0:00       ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: David Malcolm @ 2014-01-01  0:00 UTC (permalink / raw)
  To: Tom Tromey; +Cc: jit, gcc-patches

On Wed, 2014-03-19 at 12:10 -0600, Tom Tromey wrote:
> >>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
> 
> Tom> This patch introduces a new "class toplev" and changes toplev_main and
> Tom> toplev_finalize to be methods of this class.  Additionally, now the
> Tom> timevars are automatically stopped when the object is destroyed.  This
> Tom> cleans up "compile" a bit and makes it simpler to reuse the toplev
> Tom> logic in other code.
> 
> David asked me off-list to rename the field in class toplev, so here's a
> new patch that does this.

Thanks!  (yes, I greatly prefer having member data of a class to have a
"m_" prefix, and for the ctor params to have equivalent names, without
the prefix, which this patch does, for "toplev").

> Tom
> 
> commit 66f92863ef55c26f673d02dd39027f340940a3bf
> Author: Tom Tromey <tromey@redhat.com>
> Date:   Tue Mar 18 08:07:40 2014 -0600
> 
>     introduce class toplev
>     
>     This patch introduces a new "class toplev" and changes toplev_main and
>     toplev_finalize to be methods of this class.  Additionally, now the
>     timevars are automatically stopped when the object is destroyed.  This
>     cleans up "compile" a bit and makes it simpler to reuse the toplev
>     logic in other code.

OK.  Are you able to push this to my branch, or do you need me to do
this?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFA jit v2 0/2] minor refactorings for reuse
@ 2014-01-01  0:00 Tom Tromey
  2014-01-01  0:00 ` [RFA jit v2 2/2] introduce auto_timevar Tom Tromey
  2014-01-01  0:00 ` [RFA jit v2 1/2] introduce class toplev Tom Tromey
  0 siblings, 2 replies; 7+ messages in thread
From: Tom Tromey @ 2014-01-01  0:00 UTC (permalink / raw)
  To: jit; +Cc: gcc-patches

Here's a second revision of my patches to the jit branch to clean up
toplev and timevar uses a bit.  The first revision was here:

    http://gcc.gnu.org/ml/gcc-patches/2014-03/msg00895.html

Compared with that revision, this one hopefully includes the
ChangeLog.jit entries; and I took Trevor's suggestion and renamed the
timevar class to "auto_timevar".

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA jit v2 1/2] introduce class toplev
  2014-01-01  0:00 ` [RFA jit v2 1/2] introduce class toplev Tom Tromey
@ 2014-01-01  0:00   ` Tom Tromey
  2014-01-01  0:00     ` David Malcolm
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2014-01-01  0:00 UTC (permalink / raw)
  To: jit; +Cc: gcc-patches

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Tom> This patch introduces a new "class toplev" and changes toplev_main and
Tom> toplev_finalize to be methods of this class.  Additionally, now the
Tom> timevars are automatically stopped when the object is destroyed.  This
Tom> cleans up "compile" a bit and makes it simpler to reuse the toplev
Tom> logic in other code.

David asked me off-list to rename the field in class toplev, so here's a
new patch that does this.

Tom

commit 66f92863ef55c26f673d02dd39027f340940a3bf
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Mar 18 08:07:40 2014 -0600

    introduce class toplev
    
    This patch introduces a new "class toplev" and changes toplev_main and
    toplev_finalize to be methods of this class.  Additionally, now the
    timevars are automatically stopped when the object is destroyed.  This
    cleans up "compile" a bit and makes it simpler to reuse the toplev
    logic in other code.

diff --git a/gcc/ChangeLog.jit b/gcc/ChangeLog.jit
index 77ac44c..c590ab1 100644
--- a/gcc/ChangeLog.jit
+++ b/gcc/ChangeLog.jit
@@ -1,3 +1,17 @@
+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
+	use_TV_TOTAL.
+	(toplev::toplev, toplev::~toplev, toplev::start_timevars): New
+	functions.
+	(toplev::main): Rename from toplev_main.  Update.
+	(toplev::finalize): Rename from toplev_finalize.  Update.
+	* toplev.h (class toplev): New.
+	(struct toplev_options): Remove.
+	(toplev_main, toplev_finalize): Don't declare.
+
 2014-03-11  David Malcolm  <dmalcolm@redhat.com>
 
 	* gcse.c (gcse_c_finalize): New, to clear test_insn between
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 36094a1..56dc3ac 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -333,7 +333,7 @@ diagnostic_show_locus (diagnostic_context * context,
 static const char * const bt_stop[] =
 {
   "main",
-  "toplev_main",
+  "toplev::main",
   "execute_one_pass",
   "compile_file",
 };
diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index efb1931..e45d38c 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,3 +1,8 @@
+2014-03-19  Tom Tromey  <tromey@redhat.com>
+
+	* internal-api.c (compile): Use toplev, not toplev_options.
+	Simplify.
+
 2014-03-19  David Malcolm  <dmalcolm@redhat.com>
 
 	* internal-api.c (gcc::jit::recording::memento_of_get_pointer::
diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c
index e3ddc4d..95978bf 100644
--- a/gcc/jit/internal-api.c
+++ b/gcc/jit/internal-api.c
@@ -3650,7 +3650,7 @@ compile ()
 
   /* Call into the rest of gcc.
      For now, we have to assemble command-line options to pass into
-     toplev_main, so that they can be parsed. */
+     toplev::main, so that they can be parsed. */
 
   /* Pass in user-provided "progname", if any, so that it makes it
      into GCC's "progname" global, used in various diagnostics. */
@@ -3724,25 +3724,15 @@ compile ()
       ADD_ARG ("-fdump-ipa-all");
     }
 
-  toplev_options toplev_opts;
-  toplev_opts.use_TV_TOTAL = false;
+  toplev toplev (false);
 
-  if (time_report || !quiet_flag  || flag_detailed_statistics)
-    timevar_init ();
-
-  timevar_start (TV_TOTAL);
-
-  toplev_main (num_args, const_cast <char **> (fake_args), &toplev_opts);
-  toplev_finalize ();
+  toplev.main (num_args, const_cast <char **> (fake_args));
+  toplev.finalize ();
 
   active_playback_ctxt = NULL;
 
   if (errors_occurred ())
-    {
-      timevar_stop (TV_TOTAL);
-      timevar_print (stderr);
-      return NULL;
-    }
+    return NULL;
 
   if (get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE))
    dump_generated_code ();
@@ -3765,8 +3755,6 @@ compile ()
     if (ret)
       {
 	timevar_pop (TV_ASSEMBLE);
-	timevar_stop (TV_TOTAL);
-	timevar_print (stderr);
 	return NULL;
       }
   }
@@ -3795,9 +3783,6 @@ compile ()
     timevar_pop (TV_LOAD);
   }
 
-  timevar_stop (TV_TOTAL);
-  timevar_print (stderr);
-
   return result_obj;
 }
 
diff --git a/gcc/main.c b/gcc/main.c
index b893308..4bba041 100644
--- a/gcc/main.c
+++ b/gcc/main.c
@@ -1,5 +1,5 @@
 /* main.c: defines main() for cc1, cc1plus, etc.
-   Copyright (C) 2007-2013 Free Software Foundation, Inc.
+   Copyright (C) 2007-2014 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -26,15 +26,14 @@ along with GCC; see the file COPYING3.  If not see
 
 int main (int argc, char **argv);
 
-/* We define main() to call toplev_main(), which is defined in toplev.c.
+/* We define main() to call toplev::main(), which is defined in toplev.c.
    We do this in a separate file in order to allow the language front-end
    to define a different main(), if it so desires.  */
 
 int
 main (int argc, char **argv)
 {
-  toplev_options toplev_opts;
-  toplev_opts.use_TV_TOTAL = true;
+  toplev toplev (true);
 
-  return toplev_main (argc, argv, &toplev_opts);
+  return toplev.main (argc, argv);
 }
diff --git a/gcc/toplev.c b/gcc/toplev.c
index f1ac560..b257ab2 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1,5 +1,5 @@
 /* Top level of GCC compilers (cc1, cc1plus, etc.)
-   Copyright (C) 1987-2013 Free Software Foundation, Inc.
+   Copyright (C) 1987-2014 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -95,7 +95,7 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 
 static void general_init (const char *);
-static void do_compile (const toplev_options *toplev_opts);
+static void do_compile ();
 static void process_options (void);
 static void backend_init (void);
 static int lang_dependent_init (const char *);
@@ -1854,18 +1854,8 @@ finalize (bool no_backend)
 
 /* Initialize the compiler, and compile the input file.  */
 static void
-do_compile (const toplev_options *toplev_opts)
+do_compile ()
 {
-  /* Initialize timing first.  The C front ends read the main file in
-     the post_options hook, and C++ does file timings.  */
-  if (toplev_opts->use_TV_TOTAL)
-    {
-      if (time_report || !quiet_flag  || flag_detailed_statistics)
-        timevar_init ();
-
-      timevar_start (TV_TOTAL);
-    }
-
   process_options ();
 
   /* Don't do any more if an error has already occurred.  */
@@ -1910,13 +1900,28 @@ do_compile (const toplev_options *toplev_opts)
 
       timevar_stop (TV_PHASE_FINALIZE);
     }
+}
 
-  if (toplev_opts->use_TV_TOTAL)
-    {
-      /* Stop timing and print the times.  */
-      timevar_stop (TV_TOTAL);
-      timevar_print (stderr);
-    }
+toplev::toplev (bool use_TV_TOTAL)
+  : m_use_TV_TOTAL (use_TV_TOTAL)
+{
+  if (!m_use_TV_TOTAL)
+    start_timevars ();
+}
+
+toplev::~toplev ()
+{
+  timevar_stop (TV_TOTAL);
+  timevar_print (stderr);
+}
+
+void
+toplev::start_timevars ()
+{
+  if (time_report || !quiet_flag  || flag_detailed_statistics)
+    timevar_init ();
+
+  timevar_start (TV_TOTAL);
 }
 
 /* Entry point of cc1, cc1plus, jc1, f771, etc.
@@ -1926,7 +1931,7 @@ do_compile (const toplev_options *toplev_opts)
    It is not safe to call this function more than once.  */
 
 int
-toplev_main (int argc, char **argv, const toplev_options *toplev_opts)
+toplev::main (int argc, char **argv)
 {
   /* Parsing and gimplification sometimes need quite large stack.
      Increase stack size limits if possible.  */
@@ -1976,7 +1981,11 @@ toplev_main (int argc, char **argv, const toplev_options *toplev_opts)
 
   /* Exit early if we can (e.g. -help).  */
   if (!exit_after_options)
-    do_compile (toplev_opts);
+    {
+      if (m_use_TV_TOTAL)
+	start_timevars ();
+      do_compile ();
+    }
 
   if (warningcount || errorcount || werrorcount)
     print_ignored_options ();
@@ -1994,8 +2003,9 @@ toplev_main (int argc, char **argv, const toplev_options *toplev_opts)
 }
 
 /* For those that want to, this function aims to clean up enough state that
-   you can call toplev_main again. */
-void toplev_finalize (void)
+   you can call toplev::main again. */
+void
+toplev::finalize (void)
 {
   cgraph_c_finalize ();
   cgraphbuild_c_finalize ();
diff --git a/gcc/toplev.h b/gcc/toplev.h
index a99fee1..4605877 100644
--- a/gcc/toplev.h
+++ b/gcc/toplev.h
@@ -24,16 +24,24 @@ along with GCC; see the file COPYING3.  If not see
 extern struct cl_decoded_option *save_decoded_options;
 extern unsigned int save_decoded_options_count;
 
-/* Options for invoking toplev_main.  */
-struct toplev_options
+/* Invoking the compiler.  */
+class toplev
 {
-  /* Should do_compile use TV_TOTAL, or is some other wrapper
-     using it? */
-  bool use_TV_TOTAL;
+public:
+  toplev (bool use_TV_TOTAL);
+  ~toplev ();
+
+  int main (int argc, char **argv);
+
+  void finalize ();
+
+private:
+
+  void start_timevars ();
+
+  bool m_use_TV_TOTAL;
 };
 
-extern int toplev_main (int, char **, const toplev_options *toplev_opts);
-extern void toplev_finalize (void);
 extern void rest_of_decl_compilation (tree, int, int);
 extern void rest_of_type_compilation (tree, int);
 extern void init_optimization_passes (void);

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-03-19 21:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-01  0:00 [RFA jit v2 0/2] minor refactorings for reuse Tom Tromey
2014-01-01  0:00 ` [RFA jit v2 2/2] introduce auto_timevar Tom Tromey
2014-01-01  0:00   ` David Malcolm
2014-01-01  0:00 ` [RFA jit v2 1/2] introduce class toplev Tom Tromey
2014-01-01  0:00   ` Tom Tromey
2014-01-01  0:00     ` David Malcolm
2014-01-01  0:00       ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).