From afed345982d5923b04d41885e868c9ca345ff3f9 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 3 Aug 2015 20:14:21 +0000 Subject: Refactoring of timevar API gcc/ChangeLog: * main.c (main): Pass in NULL for toplev's external_timer. * timevar.c: Include coretypes.h. (class timer::named_items): New. (timer::named_items::named_items): New. (timer::named_items::~named_items): New. (timer::named_items::push): New. (timer::named_items::pop): New. (timer::named_items::print): New. (timer::timer): Initialize field "m_jit_client_items". (timer::~timer): New. (timer::push): Move bulk of implementation to... (timer::push_internal): ...here. New function. (timer::pop): Move bulk of implementation to... (timer::pop_internal): ...here. New function. (timer::push_client_item): New. (timer::pop_client_item): New. (timer::print_row): New function, taken from timer::print. (timer::print): Print "GCC items" header if we also have client items. Move row-printing to timer::print_row. Print any client items. (timer::get_topmost_item_name): New method. * timevar.def (TV_JIT_ACQUIRING_MUTEX): New. (TV_JIT_CLIENT_CODE): New. * timevar.h (timer::push_client_item): New declaration. (timer::pop_client_item): New declaration. (timer::get_topmost_item_name): New method. (timer::push_internal): New declaration. (timer::pop_internal): New declaration. (timer::print_row): New declaration. (timer::named_items): New declaration. (timer::m_jit_client_items): New field. (timer): Add friend class named_items. (auto_timevar::auto_timevar): Add timer param. (auto_timevar::~auto_timevar): Use field "m_timer". (auto_timevar::m_timer): New field. * toplev.c (initialize_rtl): Add g_timer as param when constructing auto_timevar instance. (toplev::toplev): Add "external_timer" param, and use it to initialize the "g_timer" global if non-NULL. (toplev::~toplev): If this created "g_timer", delete it. * toplev.h (toplev::toplev): Replace "use_TV_TOTAL" bool param with "external_timer" timer *. gcc/jit/ChangeLog: * docs/topics/compatibility.rst (LIBGCCJIT_ABI_4): New. * docs/topics/contexts.rst (GCC_JIT_BOOL_OPTION_DUMP_SUMMARY): We no longer show a profile. * docs/topics/index.rst (Topic Reference): Add performance.rst. * docs/topics/performance.rst: New file. * docs/_build/texinfo/libgccjit.texi: Regenerate. * jit-playback.c (gcc::jit::playback::context::compile): Add timer param when constructing the "toplev" instance. (gcc::jit::playback::context::acquire_mutex): Add timer param when constructing auto_timevar instance. (gcc::jit::playback::context::make_fake_args): If we have a timer, add "-ftime-report". (gcc::jit::playback::context::invoke_driver): Add timer param when constructing auto_timevar instance. (gcc::jit::playback::context::dlopen_built_dso): Likewise. * jit-playback.h (gcc::jit::playback::context::get_timer): New accessor. * jit-recording.c: Include timevar.h. (gcc::jit::recording::context::context): Initialize field "m_timer". * jit-recording.h: Add forward declaration of class timer. (gcc::jit::recording::context::set_timer): New method. (gcc::jit::recording::context::get_timer): New method. (gcc::jit::recording::context::m_timer): New field. * libgccjit++.h (gccjit::timer): New class. (gccjit::auto_time): New class. (gccjit::context::set_timer): New method. (gccjit::context::get_timer): New. (gccjit::timer::timer): New. (gccjit::timer::push): New. (gccjit::timer::pop): New. (timer::print): New. (timer::get_inner_timer): New. (timer::release): New. (auto_time::auto_time): New. (auto_time::~auto_time): New. * libgccjit.c: Include timevar.h. (struct gcc_jit_timer): New. (gcc_jit_timer_new): New function. (gcc_jit_timer_release): New function. (gcc_jit_context_set_timer): New function. (gcc_jit_context_get_timer): New function. (gcc_jit_timer_push): New function. (gcc_jit_timer_pop): New function. (gcc_jit_timer_print): New function. * libgccjit.h (LIBGCCJIT_HAVE_TIMING_API): New macro. (gcc_jit_timer): New typedef. (gcc_jit_timer_new): New function. (gcc_jit_timer_release): New function. (gcc_jit_context_set_timer): New function. (gcc_jit_context_get_timer): New function. (gcc_jit_timer_push): New function. (gcc_jit_timer_pop): New function. (gcc_jit_timer_print): New function. * libgccjit.map (LIBGCCJIT_ABI_4): New. (gcc_jit_timer_new): New function. (gcc_jit_timer_release): New function. (gcc_jit_context_set_timer): New function. (gcc_jit_context_get_timer): New function. (gcc_jit_timer_push): New function. (gcc_jit_timer_pop): New function. (gcc_jit_timer_print): New function. gcc/testsuite/ChangeLog: * jit.dg/test-benchmark.c (test_jit): Add param "timer" and use it to push/pop timing items. (main): For each optimization level, create a gcc_jit_timer, and time all of the iteration within that level cumulatively. * jit.dg/test-error-gcc_jit_timer_pop-mismatch.c: New test case. * jit.dg/test-error-gcc_jit_timer_pop-too-many.c: New test case. From-SVN: r226530 --- gcc/testsuite/jit.dg/test-benchmark.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'gcc/testsuite/jit.dg/test-benchmark.c') diff --git a/gcc/testsuite/jit.dg/test-benchmark.c b/gcc/testsuite/jit.dg/test-benchmark.c index 324ba93..4952fff 100644 --- a/gcc/testsuite/jit.dg/test-benchmark.c +++ b/gcc/testsuite/jit.dg/test-benchmark.c @@ -141,11 +141,13 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) /* Run one iteration of the test. */ static void -test_jit (const char *argv0, int opt_level) +test_jit (const char *argv0, int opt_level, gcc_jit_timer *timer) { gcc_jit_context *ctxt; gcc_jit_result *result; + gcc_jit_timer_push (timer, "test_jit"); + ctxt = gcc_jit_context_acquire (); if (!ctxt) { @@ -153,6 +155,8 @@ test_jit (const char *argv0, int opt_level) return; } + gcc_jit_context_set_timer (ctxt, timer); + /* Set up options. */ gcc_jit_context_set_str_option ( ctxt, @@ -182,13 +186,22 @@ test_jit (const char *argv0, int opt_level) GCC_JIT_BOOL_OPTION_DUMP_SUMMARY, 1); + gcc_jit_timer_push (timer, "create_code"); create_code (ctxt, NULL); + gcc_jit_timer_pop (timer, "create_code"); + gcc_jit_timer_push (timer, "compile"); result = gcc_jit_context_compile (ctxt); + gcc_jit_timer_pop (timer, "compile"); + + gcc_jit_timer_push (timer, "verify_code"); verify_code (ctxt, result); + gcc_jit_timer_pop (timer, "verify_code"); gcc_jit_context_release (ctxt); gcc_jit_result_release (result); + + gcc_jit_timer_pop (timer, "test_jit"); } /* Taken from timevar.c. */ @@ -217,16 +230,19 @@ main (int argc, char **argv) int i; double start_time, end_time, elapsed_time; start_time = get_wallclock_time (); + gcc_jit_timer *timer = gcc_jit_timer_new (); for (i = 1; i <= num_iterations; i++) { snprintf (test, sizeof (test), "%s iteration %d of %d", extract_progname (argv[0]), i, num_iterations); - test_jit (argv[0], opt_level); + test_jit (argv[0], opt_level, timer); } end_time = get_wallclock_time (); elapsed_time = end_time - start_time; + gcc_jit_timer_print (timer, stderr); + gcc_jit_timer_release (timer); pass ("%s: survived %i iterations at optlevel %i", argv[0], num_iterations, opt_level); note (("%s: %i iterations at optlevel %i" -- cgit v1.1