* Re: [RFA jit 1/2] introduce class toplev
2014-01-01 0:00 ` David Malcolm
@ 2014-01-01 0:00 ` Tom Tromey
0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2014-01-01 0:00 UTC (permalink / raw)
To: David Malcolm; +Cc: jit, gcc-patches
>> gcc/ChangeLog.jit | 14 +++++++++++++
David> I see the Changelog.jit file listed here...
>> gcc/diagnostic.c | 2 +-
>> gcc/jit/ChangeLog.jit | 5 +++++
David> ...and here, but I don't see the content below, or within the header of
David> the email. Is this available somewhere?
Sorry about that. My mail-sending script went awry somehow -- I will
resend with the plain old git send-email tomorrow.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA jit 1/2] introduce class toplev
2014-01-01 0:00 ` [RFA jit 1/2] introduce class toplev Tom Tromey
@ 2014-01-01 0:00 ` David Malcolm
2014-01-01 0:00 ` Tom Tromey
0 siblings, 1 reply; 6+ messages in thread
From: David Malcolm @ 2014-01-01 0:00 UTC (permalink / raw)
To: Tom Tromey; +Cc: jit, gcc-patches
On Tue, 2014-03-18 at 08:57 -0600, Tom Tromey wrote:
> 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.
Thanks.
> ---
> gcc/ChangeLog.jit | 14 +++++++++++++
I see the Changelog.jit file listed here...
> gcc/diagnostic.c | 2 +-
> gcc/jit/ChangeLog.jit | 5 +++++
...and here, but I don't see the content below, or within the header of
the email. Is this available somewhere?
[...snip...]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFA jit 0/2] minor refactorings for reuse
@ 2014-01-01 0:00 Tom Tromey
2014-01-01 0:00 ` [RFA jit 2/2] introduce scoped_timevar Tom Tromey
2014-01-01 0:00 ` [RFA jit 1/2] introduce class toplev Tom Tromey
0 siblings, 2 replies; 6+ messages in thread
From: Tom Tromey @ 2014-01-01 0:00 UTC (permalink / raw)
To: jit; +Cc: gcc-patches
I wanted to do something like playback::context::compile, but in my
project I can't really reuse all the JIT code -- really I just wanted
to be able to use toplev_main and toplev_finalize.
Looking into the code, though, I saw a few spots that could be cleaned
up a little, so I wouldn't have to worry as much about keeping my
hacks in sync with the JIT branch.
The first patch here changes the toplev code into a class and arranges
for the timevars to be managed there.
The second patch just introduces scoped timevars to make them less
error-prone to use.
I built and tested this using the JIT test suite.
Let me know what you think,
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFA jit 2/2] introduce scoped_timevar
2014-01-01 0:00 [RFA jit 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 1/2] introduce class toplev Tom Tromey
1 sibling, 1 reply; 6+ 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 scoped_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 | 24 +++++++++++++++++++++++-
4 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c
index 6a4d2ae..8285c64 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 */
{
+ scoped_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;
+ scoped_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..eb8bf0d 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,28 @@ timevar_pop (timevar_id_t tv)
timevar_pop_1 (tv);
}
+class scoped_timevar
+{
+ public:
+ scoped_timevar (timevar_id_t tv)
+ : m_tv (tv)
+ {
+ timevar_push (m_tv);
+ }
+
+ ~scoped_timevar ()
+ {
+ timevar_push (m_tv);
+ }
+
+ private:
+
+ // Private to disallow copies.
+ scoped_timevar (const scoped_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] 6+ messages in thread
* [RFA jit 1/2] introduce class toplev
2014-01-01 0:00 [RFA jit 0/2] minor refactorings for reuse Tom Tromey
2014-01-01 0:00 ` [RFA jit 2/2] introduce scoped_timevar Tom Tromey
@ 2014-01-01 0:00 ` Tom Tromey
2014-01-01 0:00 ` David Malcolm
1 sibling, 1 reply; 6+ 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/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/internal-api.c b/gcc/jit/internal-api.c
index 8e0395d..6a4d2ae 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] 6+ messages in thread
* Re: [RFA jit 2/2] introduce scoped_timevar
2014-01-01 0:00 ` [RFA jit 2/2] introduce scoped_timevar Tom Tromey
@ 2014-01-01 0:00 ` David Malcolm
0 siblings, 0 replies; 6+ messages in thread
From: David Malcolm @ 2014-01-01 0:00 UTC (permalink / raw)
To: Tom Tromey; +Cc: jit, gcc-patches
On Tue, 2014-03-18 at 08:57 -0600, Tom Tromey wrote:
> This introduces a new scoped_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 | 24 +++++++++++++++++++++++-
> 4 files changed, 36 insertions(+), 12 deletions(-)
Thanks. Looks good to me, but, like the other patch, are the
ChangeLog.jit entries available somewhere?
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-03-19 2:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-01 0:00 [RFA jit 0/2] minor refactorings for reuse Tom Tromey
2014-01-01 0:00 ` [RFA jit 2/2] introduce scoped_timevar Tom Tromey
2014-01-01 0:00 ` David Malcolm
2014-01-01 0:00 ` [RFA jit 1/2] introduce class toplev 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).