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/jit/libgccjit.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) (limited to 'gcc/jit/libgccjit.c') diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c index eee513f..eb9200c 100644 --- a/gcc/jit/libgccjit.c +++ b/gcc/jit/libgccjit.c @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "opts.h" #include "safe-ctype.h" #include "typed-splay-tree.h" +#include "timevar.h" #include "libgccjit.h" #include "jit-common.h" @@ -89,6 +90,10 @@ struct gcc_jit_case : public gcc::jit::recording::case_ { }; +struct gcc_jit_timer : public timer +{ +}; + /********************************************************************** Error-handling. @@ -2828,3 +2833,107 @@ gcc_jit_result_release (gcc_jit_result *result) result->log ("deleting result: %p", (void *)result); delete result; } + +/********************************************************************** + Timing support. + **********************************************************************/ + +/* Create a gcc_jit_timer instance, and start timing. */ + +gcc_jit_timer * +gcc_jit_timer_new (void) +{ + gcc_jit_timer *timer = new gcc_jit_timer (); + timer->start (TV_TOTAL); + timer->push (TV_JIT_CLIENT_CODE); + return timer; +} + +/* Release a gcc_jit_timer instance. */ + +void +gcc_jit_timer_release (gcc_jit_timer *timer) +{ + RETURN_IF_FAIL (timer, NULL, NULL, "NULL timer"); + + delete timer; +} + +/* Associate a gcc_jit_timer instance with a context. */ + +void +gcc_jit_context_set_timer (gcc_jit_context *ctxt, + gcc_jit_timer *timer) +{ + RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL ctxt"); + RETURN_IF_FAIL (timer, ctxt, NULL, "NULL timer"); + + ctxt->set_timer (timer); +} + +/* Get the timer associated with a context (if any). */ + +gcc_jit_timer * +gcc_jit_context_get_timer (gcc_jit_context *ctxt) +{ + RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL ctxt"); + + return (gcc_jit_timer *)ctxt->get_timer (); +} + +/* Push the given item onto the timing stack. */ + +void +gcc_jit_timer_push (gcc_jit_timer *timer, + const char *item_name) +{ + RETURN_IF_FAIL (timer, NULL, NULL, "NULL timer"); + RETURN_IF_FAIL (item_name, NULL, NULL, "NULL item_name"); + timer->push_client_item (item_name); +} + +/* Pop the top item from the timing stack. */ + +void +gcc_jit_timer_pop (gcc_jit_timer *timer, + const char *item_name) +{ + RETURN_IF_FAIL (timer, NULL, NULL, "NULL timer"); + + if (item_name) + { + const char *top_item_name = timer->get_topmost_item_name (); + + RETURN_IF_FAIL_PRINTF1 + (top_item_name, NULL, NULL, + "pop of empty timing stack (attempting to pop: \"%s\")", + item_name); + + RETURN_IF_FAIL_PRINTF2 + (0 == strcmp (item_name, top_item_name), NULL, NULL, + "mismatching item_name:" + " top of timing stack: \"%s\"," + " attempting to pop: \"%s\"", + top_item_name, + item_name); + } + + timer->pop_client_item (); +} + +/* Print timing information to the given stream about activity since + the timer was started. */ + +void +gcc_jit_timer_print (gcc_jit_timer *timer, + FILE *f_out) +{ + RETURN_IF_FAIL (timer, NULL, NULL, "NULL timer"); + RETURN_IF_FAIL (f_out, NULL, NULL, "NULL f_out"); + + timer->pop (TV_JIT_CLIENT_CODE); + timer->stop (TV_TOTAL); + timer->print (f_out); + timer->start (TV_TOTAL); + timer->push (TV_JIT_CLIENT_CODE); +} -- cgit v1.1