[RFA jit v2 1/2] introduce class toplev
Tom Tromey
tromey@redhat.com
Wed Mar 19 17:58:00 GMT 2014
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
More information about the Gcc-patches
mailing list