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> 2015-05-12 Richard Earnshaw <rearnsha@arm.com>
* arm-protos.h (arm_sched_autopref): Delete. * arm-protos.h (arm_sched_autopref): Delete.
......
...@@ -99,10 +99,10 @@ static double clocks_to_msec; ...@@ -99,10 +99,10 @@ static double clocks_to_msec;
#define CLOCKS_TO_MSEC (1 / (double)CLOCKS_PER_SEC) #define CLOCKS_TO_MSEC (1 / (double)CLOCKS_PER_SEC)
#endif #endif
/* True if timevars should be used. In GCC, this happens with /* Non-NULL if timevars should be used. In GCC, this happens with
the -ftime-report flag. */ the -ftime-report flag. */
bool timevar_enable; timer *g_timer;
/* Total amount of memory allocated by garbage collector. */ /* Total amount of memory allocated by garbage collector. */
...@@ -115,57 +115,6 @@ size_t timevar_ggc_mem_total; ...@@ -115,57 +115,6 @@ size_t timevar_ggc_mem_total;
/* See timevar.h for an explanation of timing variables. */ /* See timevar.h for an explanation of timing variables. */
/* 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;
};
/* 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;
};
/* Declared timing variables. Constructed from the contents of
timevar.def. */
static struct timevar_def timevars[TIMEVAR_LAST];
/* The top of the timing stack. */
static struct timevar_stack_def *stack;
/* A list of unused (i.e. allocated and subsequently popped)
timevar_stack_def instances. */
static struct timevar_stack_def *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. */
static struct timevar_time_def start_time;
static void get_time (struct timevar_time_def *); static void get_time (struct timevar_time_def *);
static void timevar_accumulate (struct timevar_time_def *, static void timevar_accumulate (struct timevar_time_def *,
struct timevar_time_def *, struct timevar_time_def *,
...@@ -183,9 +132,6 @@ get_time (struct timevar_time_def *now) ...@@ -183,9 +132,6 @@ get_time (struct timevar_time_def *now)
now->wall = 0; now->wall = 0;
now->ggc_mem = timevar_ggc_mem_total; now->ggc_mem = timevar_ggc_mem_total;
if (!timevar_enable)
return;
{ {
#ifdef USE_TIMES #ifdef USE_TIMES
struct tms tms; struct tms tms;
...@@ -218,25 +164,24 @@ timevar_accumulate (struct timevar_time_def *timer, ...@@ -218,25 +164,24 @@ timevar_accumulate (struct timevar_time_def *timer,
timer->ggc_mem += stop_time->ggc_mem - start_time->ggc_mem; timer->ggc_mem += stop_time->ggc_mem - start_time->ggc_mem;
} }
/* Initialize timing variables. */ /* Class timer's constructor. */
void timer::timer () :
timevar_init (void) m_stack (NULL),
m_unused_stack_instances (NULL),
m_start_time ()
{ {
if (timevar_enable)
return;
timevar_enable = true;
/* Zero all elapsed times. */ /* Zero all elapsed times. */
memset (timevars, 0, sizeof (timevars)); memset (m_timevars, 0, sizeof (m_timevars));
/* Initialize the names of timing variables. */ /* Initialize the names of timing variables. */
#define DEFTIMEVAR(identifier__, name__) \ #define DEFTIMEVAR(identifier__, name__) \
timevars[identifier__].name = name__; m_timevars[identifier__].name = name__;
#include "timevar.def" #include "timevar.def"
#undef DEFTIMEVAR #undef DEFTIMEVAR
/* Initialize configuration-specific state.
Ideally this would be one-time initialization. */
#ifdef USE_TIMES #ifdef USE_TIMES
ticks_to_msec = TICKS_TO_MSEC; ticks_to_msec = TICKS_TO_MSEC;
#endif #endif
...@@ -245,6 +190,17 @@ timevar_init (void) ...@@ -245,6 +190,17 @@ timevar_init (void)
#endif #endif
} }
/* Initialize timing variables. */
void
timevar_init (void)
{
if (g_timer)
return;
g_timer = new timer ();
}
/* Push TIMEVAR onto the timing stack. No further elapsed time is /* Push TIMEVAR onto the timing stack. No further elapsed time is
attributed to the previous topmost timing variable on the stack; attributed to the previous topmost timing variable on the stack;
subsequent elapsed time is attributed to TIMEVAR, until it is subsequent elapsed time is attributed to TIMEVAR, until it is
...@@ -253,9 +209,9 @@ timevar_init (void) ...@@ -253,9 +209,9 @@ timevar_init (void)
TIMEVAR cannot be running as a standalone timer. */ TIMEVAR cannot be running as a standalone timer. */
void void
timevar_push_1 (timevar_id_t timevar) timer::push (timevar_id_t timevar)
{ {
struct timevar_def *tv = &timevars[timevar]; struct timevar_def *tv = &m_timevars[timevar];
struct timevar_stack_def *context; struct timevar_stack_def *context;
struct timevar_time_def now; struct timevar_time_def now;
...@@ -270,27 +226,27 @@ timevar_push_1 (timevar_id_t timevar) ...@@ -270,27 +226,27 @@ timevar_push_1 (timevar_id_t timevar)
/* If the stack isn't empty, attribute the current elapsed time to /* If the stack isn't empty, attribute the current elapsed time to
the old topmost element. */ the old topmost element. */
if (stack) if (m_stack)
timevar_accumulate (&stack->timevar->elapsed, &start_time, &now); timevar_accumulate (&m_stack->timevar->elapsed, &m_start_time, &now);
/* Reset the start time; from now on, time is attributed to /* Reset the start time; from now on, time is attributed to
TIMEVAR. */ TIMEVAR. */
start_time = now; m_start_time = now;
/* See if we have a previously-allocated stack instance. If so, /* See if we have a previously-allocated stack instance. If so,
take it off the list. If not, malloc a new one. */ take it off the list. If not, malloc a new one. */
if (unused_stack_instances != NULL) if (m_unused_stack_instances != NULL)
{ {
context = unused_stack_instances; context = m_unused_stack_instances;
unused_stack_instances = unused_stack_instances->next; m_unused_stack_instances = m_unused_stack_instances->next;
} }
else else
context = XNEW (struct timevar_stack_def); context = XNEW (struct timevar_stack_def);
/* Fill it in and put it on the stack. */ /* Fill it in and put it on the stack. */
context->timevar = tv; context->timevar = tv;
context->next = stack; context->next = m_stack;
stack = context; m_stack = context;
} }
/* Pop the topmost timing variable element off the timing stack. The /* Pop the topmost timing variable element off the timing stack. The
...@@ -300,30 +256,30 @@ timevar_push_1 (timevar_id_t timevar) ...@@ -300,30 +256,30 @@ timevar_push_1 (timevar_id_t timevar)
timing variable. */ timing variable. */
void void
timevar_pop_1 (timevar_id_t timevar) timer::pop (timevar_id_t timevar)
{ {
struct timevar_time_def now; struct timevar_time_def now;
struct timevar_stack_def *popped = stack; struct timevar_stack_def *popped = m_stack;
gcc_assert (&timevars[timevar] == stack->timevar); gcc_assert (&m_timevars[timevar] == m_stack->timevar);
/* What time is it? */ /* What time is it? */
get_time (&now); get_time (&now);
/* Attribute the elapsed time to the element we're popping. */ /* Attribute the elapsed time to the element we're popping. */
timevar_accumulate (&popped->timevar->elapsed, &start_time, &now); timevar_accumulate (&popped->timevar->elapsed, &m_start_time, &now);
/* Reset the start time; from now on, time is attributed to the /* Reset the start time; from now on, time is attributed to the
element just exposed on the stack. */ element just exposed on the stack. */
start_time = now; m_start_time = now;
/* Take the item off the stack. */ /* Take the item off the stack. */
stack = stack->next; m_stack = m_stack->next;
/* Don't delete the stack element; instead, add it to the list of /* Don't delete the stack element; instead, add it to the list of
unused elements for later use. */ unused elements for later use. */
popped->next = unused_stack_instances; popped->next = m_unused_stack_instances;
unused_stack_instances = popped; m_unused_stack_instances = popped;
} }
/* Start timing TIMEVAR independently of the timing stack. Elapsed /* Start timing TIMEVAR independently of the timing stack. Elapsed
...@@ -333,11 +289,19 @@ timevar_pop_1 (timevar_id_t timevar) ...@@ -333,11 +289,19 @@ timevar_pop_1 (timevar_id_t timevar)
void void
timevar_start (timevar_id_t timevar) timevar_start (timevar_id_t timevar)
{ {
struct timevar_def *tv = &timevars[timevar]; if (!g_timer)
if (!timevar_enable)
return; return;
g_timer->start (timevar);
}
/* See timevar_start above. */
void
timer::start (timevar_id_t timevar)
{
struct timevar_def *tv = &m_timevars[timevar];
/* Mark this timing variable as used. */ /* Mark this timing variable as used. */
tv->used = 1; tv->used = 1;
...@@ -355,12 +319,20 @@ timevar_start (timevar_id_t timevar) ...@@ -355,12 +319,20 @@ timevar_start (timevar_id_t timevar)
void void
timevar_stop (timevar_id_t timevar) timevar_stop (timevar_id_t timevar)
{ {
struct timevar_def *tv = &timevars[timevar]; if (!g_timer)
struct timevar_time_def now;
if (!timevar_enable)
return; return;
g_timer->stop (timevar);
}
/* See timevar_stop above. */
void
timer::stop (timevar_id_t timevar)
{
struct timevar_def *tv = &m_timevars[timevar];
struct timevar_time_def now;
/* TIMEVAR must have been started via timevar_start. */ /* TIMEVAR must have been started via timevar_start. */
gcc_assert (tv->standalone); gcc_assert (tv->standalone);
tv->standalone = 0; /* Enable a restart. */ tv->standalone = 0; /* Enable a restart. */
...@@ -379,11 +351,19 @@ timevar_stop (timevar_id_t timevar) ...@@ -379,11 +351,19 @@ timevar_stop (timevar_id_t timevar)
bool bool
timevar_cond_start (timevar_id_t timevar) timevar_cond_start (timevar_id_t timevar)
{ {
struct timevar_def *tv = &timevars[timevar]; if (!g_timer)
if (!timevar_enable)
return false; return false;
return g_timer->cond_start (timevar);
}
/* See timevar_cond_start above. */
bool
timer::cond_start (timevar_id_t timevar)
{
struct timevar_def *tv = &m_timevars[timevar];
/* Mark this timing variable as used. */ /* Mark this timing variable as used. */
tv->used = 1; tv->used = 1;
...@@ -406,13 +386,21 @@ timevar_cond_start (timevar_id_t timevar) ...@@ -406,13 +386,21 @@ timevar_cond_start (timevar_id_t timevar)
void void
timevar_cond_stop (timevar_id_t timevar, bool running) timevar_cond_stop (timevar_id_t timevar, bool running)
{ {
if (!g_timer || running)
return;
g_timer->cond_stop (timevar);
}
/* See timevar_cond_stop above. */
void
timer::cond_stop (timevar_id_t timevar)
{
struct timevar_def *tv; struct timevar_def *tv;
struct timevar_time_def now; struct timevar_time_def now;
if (!timevar_enable || running) tv = &m_timevars[timevar];
return;
tv = &timevars[timevar];
/* TIMEVAR must have been started via timevar_cond_start. */ /* TIMEVAR must have been started via timevar_cond_start. */
gcc_assert (tv->standalone); gcc_assert (tv->standalone);
...@@ -425,11 +413,11 @@ timevar_cond_stop (timevar_id_t timevar, bool running) ...@@ -425,11 +413,11 @@ timevar_cond_stop (timevar_id_t timevar, bool running)
/* Validate that phase times are consistent. */ /* Validate that phase times are consistent. */
static void void
validate_phases (FILE *fp) timer::validate_phases (FILE *fp) const
{ {
unsigned int /* timevar_id_t */ id; unsigned int /* timevar_id_t */ id;
struct timevar_time_def *total = &timevars[TV_TOTAL].elapsed; const timevar_time_def *total = &m_timevars[TV_TOTAL].elapsed;
double phase_user = 0.0; double phase_user = 0.0;
double phase_sys = 0.0; double phase_sys = 0.0;
double phase_wall = 0.0; double phase_wall = 0.0;
...@@ -439,7 +427,7 @@ validate_phases (FILE *fp) ...@@ -439,7 +427,7 @@ validate_phases (FILE *fp)
for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id) for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id)
{ {
struct timevar_def *tv = &timevars[(timevar_id_t) id]; const timevar_def *tv = &m_timevars[(timevar_id_t) id];
/* Don't evaluate timing variables that were never used. */ /* Don't evaluate timing variables that were never used. */
if (!tv->used) if (!tv->used)
...@@ -480,17 +468,14 @@ validate_phases (FILE *fp) ...@@ -480,17 +468,14 @@ validate_phases (FILE *fp)
for normalizing the others, and is displayed last. */ for normalizing the others, and is displayed last. */
void void
timevar_print (FILE *fp) timer::print (FILE *fp)
{ {
/* Only print stuff if we have some sort of time information. */ /* Only print stuff if we have some sort of time information. */
#if defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME) || defined (HAVE_WALL_TIME) #if defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME) || defined (HAVE_WALL_TIME)
unsigned int /* timevar_id_t */ id; unsigned int /* timevar_id_t */ id;
struct timevar_time_def *total = &timevars[TV_TOTAL].elapsed; const timevar_time_def *total = &m_timevars[TV_TOTAL].elapsed;
struct timevar_time_def now; struct timevar_time_def now;
if (!timevar_enable)
return;
/* Update timing information in case we're calling this from GDB. */ /* Update timing information in case we're calling this from GDB. */
if (fp == 0) if (fp == 0)
...@@ -501,17 +486,17 @@ timevar_print (FILE *fp) ...@@ -501,17 +486,17 @@ timevar_print (FILE *fp)
/* If the stack isn't empty, attribute the current elapsed time to /* If the stack isn't empty, attribute the current elapsed time to
the old topmost element. */ the old topmost element. */
if (stack) if (m_stack)
timevar_accumulate (&stack->timevar->elapsed, &start_time, &now); timevar_accumulate (&m_stack->timevar->elapsed, &m_start_time, &now);
/* Reset the start time; from now on, time is attributed to /* Reset the start time; from now on, time is attributed to
TIMEVAR. */ TIMEVAR. */
start_time = now; m_start_time = now;
fputs ("\nExecution times (seconds)\n", fp); fputs ("\nExecution times (seconds)\n", fp);
for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id) for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id)
{ {
struct timevar_def *tv = &timevars[(timevar_id_t) id]; const timevar_def *tv = &m_timevars[(timevar_id_t) id];
const double tiny = 5e-3; const double tiny = 5e-3;
/* Don't print the total execution time here; that goes at the /* Don't print the total execution time here; that goes at the
......
...@@ -79,35 +79,118 @@ typedef enum ...@@ -79,35 +79,118 @@ typedef enum
timevar_id_t; timevar_id_t;
#undef DEFTIMEVAR #undef DEFTIMEVAR
/* True if timevars should be used. In GCC, this happens with /* A class to hold all state relating to timing. */
the -ftime-report flag. */
extern bool timevar_enable; 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. */ /* Total amount of memory allocated by garbage collector. */
extern size_t timevar_ggc_mem_total; extern size_t timevar_ggc_mem_total;
extern void timevar_init (void); 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_start (timevar_id_t);
extern void timevar_stop (timevar_id_t); extern void timevar_stop (timevar_id_t);
extern bool timevar_cond_start (timevar_id_t); extern bool timevar_cond_start (timevar_id_t);
extern void timevar_cond_stop (timevar_id_t, bool); 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. */ /* Provided for backward compatibility. */
static inline void static inline void
timevar_push (timevar_id_t tv) timevar_push (timevar_id_t tv)
{ {
if (timevar_enable) if (g_timer)
timevar_push_1 (tv); g_timer->push (tv);
} }
static inline void static inline void
timevar_pop (timevar_id_t tv) timevar_pop (timevar_id_t tv)
{ {
if (timevar_enable) if (g_timer)
timevar_pop_1 (tv); g_timer->pop (tv);
} }
// This is a simple timevar wrapper class that pushes a timevar in its // 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) ...@@ -2095,8 +2095,11 @@ toplev::toplev (bool use_TV_TOTAL, bool init_signals)
toplev::~toplev () toplev::~toplev ()
{ {
timevar_stop (TV_TOTAL); if (g_timer)
timevar_print (stderr); {
g_timer->stop (TV_TOTAL);
g_timer->print (stderr);
}
} }
void 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