This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 03/16] gcc: Use timevars within driver


This patch allows a "timer" instance to be passed to the driver
and adds some timevars for activities within the driver.

This is for use by libgccjit when embedding the driver, though
in theory we could use this to time the driver as a whole.

gcc/ChangeLog:
	* Makefile.in (GCC_OBJS): Add timevar.o.
	* gcc-main.c (main): Add NULL for "timer" when constructing
	the driver.
	* gcc.c: Include timevar.h.
	(driver::driver): Add timer param.
	(driver::main): Account various things to TV_DRIVER_SETUP.
	(driver::do_spec_on_infiles): Account time spent here to
	TV_DRIVER_SPEC.
	(driver::maybe_run_linker): Account time spent here to
	TV_DRIVER_LINK.
	* gcc.h: Add forward decl of class timer.
	(driver::driver): Add timer param.
	(driver::m_timer): New field.
	* timevar.def (TV_DRIVER): New.
	(TV_DRIVER_SETUP): New.
	(TV_DRIVER_SPEC): New.
	(TV_DRIVER_LINK): New.

gcc/jit/ChangeLog:
	* jit-playback.c (gcc:jit::playback::context::convert_to_dso):
	Account the driver to TV_DRIVER rather than to TV_ASSEMBLE.
	(gcc:jit::playback::context::invoke_embedded_driver): Pass
	the context's timer (if any) to the driver.
---
 gcc/Makefile.in        |  2 +-
 gcc/gcc-main.c         |  3 ++-
 gcc/gcc.c              | 14 ++++++++++++--
 gcc/gcc.h              |  5 ++++-
 gcc/jit/jit-playback.c |  5 +++--
 gcc/timevar.def        |  4 ++++
 6 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index ab9b637..2388975 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1140,7 +1140,7 @@ CXX_TARGET_OBJS=@cxx_target_objs@
 FORTRAN_TARGET_OBJS=@fortran_target_objs@
 
 # Object files for gcc many-languages driver.
-GCC_OBJS = gcc.o gcc-main.o ggc-none.o
+GCC_OBJS = gcc.o gcc-main.o ggc-none.o timevar.o
 
 c-family-warn = $(STRICT_WARN)
 
diff --git a/gcc/gcc-main.c b/gcc/gcc-main.c
index a0aaa3c..59533a5 100644
--- a/gcc/gcc-main.c
+++ b/gcc/gcc-main.c
@@ -41,7 +41,8 @@ int
 main (int argc, char **argv)
 {
   driver d (false, /* can_finalize */
-	    false); /* debug */
+	    false, /* debug */
+	    NULL); /* timer */
 
   return d.main (argc, argv);
 }
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 683392d..7314317 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -43,6 +43,7 @@ compilation is specified by a string called a "spec".  */
 #include "params.h"
 #include "vec.h"
 #include "filenames.h"
+#include "timevar.h"
 
 
 
@@ -7023,9 +7024,10 @@ compare_files (char *cmpfile[])
   return ret;
 }
 
-driver::driver (bool can_finalize, bool debug) :
+driver::driver (bool can_finalize, bool debug, timer *t) :
   explicit_link_files (NULL),
-  decoded_options (NULL)
+  decoded_options (NULL),
+  m_timer (t)
 {
   env.init (can_finalize, debug);
 }
@@ -7043,6 +7045,9 @@ driver::main (int argc, char **argv)
 {
   bool early_exit;
 
+  if (m_timer)
+    m_timer->push (TV_DRIVER_SETUP);
+
   set_progname (argv[0]);
   expand_at_files (&argc, &argv);
   decode_argv (argc, const_cast <const char **> (argv));
@@ -7054,6 +7059,9 @@ driver::main (int argc, char **argv)
   maybe_putenv_OFFLOAD_TARGETS ();
   handle_unrecognized_options ();
 
+  if (m_timer)
+    m_timer->pop (TV_DRIVER_SETUP);
+
   if (!maybe_print_and_exit ())
     return 0;
 
@@ -7780,6 +7788,7 @@ driver::prepare_infiles ()
 void
 driver::do_spec_on_infiles () const
 {
+  auto_timevar tv (m_timer, TV_DRIVER_SPEC);
   size_t i;
 
   for (i = 0; (int) i < n_infiles; i++)
@@ -7926,6 +7935,7 @@ driver::do_spec_on_infiles () const
 void
 driver::maybe_run_linker (const char *argv0) const
 {
+  auto_timevar tv (m_timer, TV_DRIVER_LINK);
   size_t i;
   int linker_was_run = 0;
   int num_linker_inputs;
diff --git a/gcc/gcc.h b/gcc/gcc.h
index e1abe43..cfff8ef 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -23,6 +23,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "version.h"
 #include "diagnostic-core.h"
 
+class timer;
+
 /* The top-level "main" within the driver would be ~1000 lines long.
    This class breaks it up into smaller functions and contains some
    state shared by them.  */
@@ -30,7 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 class driver
 {
  public:
-  driver (bool can_finalize, bool debug);
+  driver (bool can_finalize, bool debug, timer *t);
   ~driver ();
   int main (int argc, char **argv);
   void finalize ();
@@ -57,6 +59,7 @@ class driver
   char *explicit_link_files;
   struct cl_decoded_option *decoded_options;
   unsigned int decoded_options_count;
+  timer *m_timer;
 };
 
 /* The mapping of a spec function name to the C function that
diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index 6282abd..ff5a42f 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -2298,7 +2298,7 @@ convert_to_dso (const char *ctxt_progname)
   invoke_driver (ctxt_progname,
 		 m_tempdir->get_path_s_file (),
 		 m_tempdir->get_path_so_file (),
-		 TV_ASSEMBLE,
+		 TV_DRIVER,
 		 true, /* bool shared, */
 		 true);/* bool run_linker */
 }
@@ -2368,7 +2368,8 @@ playback::context::
 invoke_embedded_driver (const vec <const char *> *argvec)
 {
   driver d (true, /* can_finalize */
-	    false); /* debug */
+	    false, /* debug */
+	    get_timer ()); /* timer */
   int result = d.main (argvec->length (),
 		       const_cast <char **> (argvec->address ()));
   d.finalize ();
diff --git a/gcc/timevar.def b/gcc/timevar.def
index 905b469..d04a729 100644
--- a/gcc/timevar.def
+++ b/gcc/timevar.def
@@ -286,7 +286,11 @@ DEFTIMEVAR (TV_REPAIR_LOOPS	     , "repair loop structures")
 
 /* Stuff used by libgccjit.so.  */
 DEFTIMEVAR (TV_JIT_REPLAY	     , "replay of JIT client activity")
+DEFTIMEVAR (TV_DRIVER                , "driver")
 DEFTIMEVAR (TV_ASSEMBLE	     , "assemble JIT code")
+DEFTIMEVAR (TV_DRIVER_SETUP          , "driver: setup")
+DEFTIMEVAR (TV_DRIVER_SPEC	     , "driver: do spec on infiles")
+DEFTIMEVAR (TV_DRIVER_LINK	     , "driver: run linker")
 DEFTIMEVAR (TV_LINK		     , "link JIT code")
 DEFTIMEVAR (TV_LOAD		     , "load JIT result")
 DEFTIMEVAR (TV_JIT_ACQUIRING_MUTEX   , "acquiring JIT mutex")
-- 
1.8.5.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]