Commit 2162235e by David Malcolm Committed by David Malcolm

Move global state in timevar.c to a new "timer" class

gcc/ChangeLog:
	* timevar.c (timevar_enable): Delete in favor of...
	(g_timer): New global.
	(struct timevar_def): Move to timevar.h inside class timer.
	(struct timevar_stack_def): Likewise.
	(timevars): Delete global in favor of field "m_timevars" within
	class timer in timevar.h
	(stack): Likewise, in favor of field "m_stack".
	(unused_stack_instances): Likewise, in favor of field
	"m_unused_stack_instances".
	(start_time): Likewise, in favor of field "m_start_time".
	(get_time): Eliminate check for timevar_enable.
	(timer::timer): New function, built from part of timevar_init.
	(timevar_init): Rewrite idempotency test from using
	"timevar_enable" bool to using dynamic allocation of "g_timer".
	Move rest of implementation into timer's constructor.
	(timevar_push_1): Rename to...
	(timer::push): ...this, adding "m_" prefixes to variables that
	are now fields of timer.
	(timevar_pop_1): Likewise, rename to...
	(timer::pop): ...this, and add "m_" prefixes.
	(timevar_start): Replace test for "timevar_enable" with one for
	"g_timer", and move bulk of implementation to...
	(timer::start): ...here, adding "m_" prefixes.
	(timevar_stop): Likewise, from here...
	(timer::stop): ...to here.
	(timevar_cond_start): Likewise, from here...
	(timer::cond_start): ...to here.
	(timevar_cond_stop): Likewise, from here...
	(timer::cond_stop): ...to here.
	(validate_phases): Rename to...
	(timer::validate_phases): ...this, and add "m_" prefixes.  Make
	locals "total" and "tv" const.
	(timevar_print): Rename to...
	(timer::print): ...this, and add "m_" prefixes.  Make locals
	"total" and "tv" const.  Eliminate test for timevar_enable.
	* timevar.h (timevar_enable): Eliminate.
	(g_timer): New declaration.
	(timevar_push_1): Eliminate.
	(timevar_pop_1): Eliminate.
	(timevar_print): Eliminate.
	(class timer): New class.
	(timevar_push): Rewrite to use g_timer.
	(timevar_pop): Likewise.
	* toplev.c (toplev::~toplev): Likewise.

From-SVN: r223092
parent 2637afb7
2015-05-12 David Malcolm <dmalcolm@redhat.com>
* timevar.c (timevar_enable): Delete in favor of...
(g_timer): New global.
(struct timevar_def): Move to timevar.h inside class timer.
(struct timevar_stack_def): Likewise.
(timevars): Delete global in favor of field "m_timevars" within
class timer in timevar.h
(stack): Likewise, in favor of field "m_stack".
(unused_stack_instances): Likewise, in favor of field
"m_unused_stack_instances".
(start_time): Likewise, in favor of field "m_start_time".
(get_time): Eliminate check for timevar_enable.
(timer::timer): New function, built from part of timevar_init.
(timevar_init): Rewrite idempotency test from using
"timevar_enable" bool to using dynamic allocation of "g_timer".
Move rest of implementation into timer's constructor.
(timevar_push_1): Rename to...
(timer::push): ...this, adding "m_" prefixes to variables that
are now fields of timer.
(timevar_pop_1): Likewise, rename to...
(timer::pop): ...this, and add "m_" prefixes.
(timevar_start): Replace test for "timevar_enable" with one for
"g_timer", and move bulk of implementation to...
(timer::start): ...here, adding "m_" prefixes.
(timevar_stop): Likewise, from here...
(timer::stop): ...to here.
(timevar_cond_start): Likewise, from here...
(timer::cond_start): ...to here.
(timevar_cond_stop): Likewise, from here...
(timer::cond_stop): ...to here.
(validate_phases): Rename to...
(timer::validate_phases): ...this, and add "m_" prefixes. Make
locals "total" and "tv" const.
(timevar_print): Rename to...
(timer::print): ...this, and add "m_" prefixes. Make locals
"total" and "tv" const. Eliminate test for timevar_enable.
* timevar.h (timevar_enable): Eliminate.
(g_timer): New declaration.
(timevar_push_1): Eliminate.
(timevar_pop_1): Eliminate.
(timevar_print): Eliminate.
(class timer): New class.
(timevar_push): Rewrite to use g_timer.
(timevar_pop): Likewise.
* toplev.c (toplev::~toplev): Likewise.
2015-05-12 Richard Earnshaw <rearnsha@arm.com>
* arm-protos.h (arm_sched_autopref): Delete.
......
......@@ -79,35 +79,118 @@ typedef enum
timevar_id_t;
#undef DEFTIMEVAR
/* True if timevars should be used. In GCC, this happens with
the -ftime-report flag. */
extern bool timevar_enable;
/* A class to hold all state relating to timing. */
class timer;
/* The singleton instance of timing state.
This is non-NULL if timevars should be used. In GCC, this happens with
the -ftime-report flag. Hence this is NULL for the common,
needs-to-be-fast case, with an early reject happening for this being
NULL. */
extern timer *g_timer;
/* Total amount of memory allocated by garbage collector. */
extern size_t timevar_ggc_mem_total;
extern void timevar_init (void);
extern void timevar_push_1 (timevar_id_t);
extern void timevar_pop_1 (timevar_id_t);
extern void timevar_start (timevar_id_t);
extern void timevar_stop (timevar_id_t);
extern bool timevar_cond_start (timevar_id_t);
extern void timevar_cond_stop (timevar_id_t, bool);
extern void timevar_print (FILE *);
/* The public (within GCC) interface for timing. */
class timer
{
public:
timer ();
~timer ();
void start (timevar_id_t tv);
void stop (timevar_id_t tv);
void push (timevar_id_t tv);
void pop (timevar_id_t tv);
bool cond_start (timevar_id_t tv);
void cond_stop (timevar_id_t tv);
void print (FILE *fp);
private:
/* Private member functions. */
void validate_phases (FILE *fp) const;
private:
/* Private type: a timing variable. */
struct timevar_def
{
/* Elapsed time for this variable. */
struct timevar_time_def elapsed;
/* If this variable is timed independently of the timing stack,
using timevar_start, this contains the start time. */
struct timevar_time_def start_time;
/* The name of this timing variable. */
const char *name;
/* Nonzero if this timing variable is running as a standalone
timer. */
unsigned standalone : 1;
/* Nonzero if this timing variable was ever started or pushed onto
the timing stack. */
unsigned used : 1;
};
/* Private type: an element on the timing stack
Elapsed time is attributed to the topmost timing variable on the
stack. */
struct timevar_stack_def
{
/* The timing variable at this stack level. */
struct timevar_def *timevar;
/* The next lower timing variable context in the stack. */
struct timevar_stack_def *next;
};
private:
/* Data members (all private). */
/* Declared timing variables. Constructed from the contents of
timevar.def. */
timevar_def m_timevars[TIMEVAR_LAST];
/* The top of the timing stack. */
timevar_stack_def *m_stack;
/* A list of unused (i.e. allocated and subsequently popped)
timevar_stack_def instances. */
timevar_stack_def *m_unused_stack_instances;
/* The time at which the topmost element on the timing stack was
pushed. Time elapsed since then is attributed to the topmost
element. */
timevar_time_def m_start_time;
};
/* Provided for backward compatibility. */
static inline void
timevar_push (timevar_id_t tv)
{
if (timevar_enable)
timevar_push_1 (tv);
if (g_timer)
g_timer->push (tv);
}
static inline void
timevar_pop (timevar_id_t tv)
{
if (timevar_enable)
timevar_pop_1 (tv);
if (g_timer)
g_timer->pop (tv);
}
// This is a simple timevar wrapper class that pushes a timevar in its
......
......@@ -2095,8 +2095,11 @@ toplev::toplev (bool use_TV_TOTAL, bool init_signals)
toplev::~toplev ()
{
timevar_stop (TV_TOTAL);
timevar_print (stderr);
if (g_timer)
{
g_timer->stop (TV_TOTAL);
g_timer->print (stderr);
}
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment