Mercurial > hg > CbC > CbC_gcc
diff gcc/timevar.h @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | f6334be47118 |
children | 84e7813d76e9 |
line wrap: on
line diff
--- a/gcc/timevar.h Sun Aug 21 07:07:55 2011 +0900 +++ b/gcc/timevar.h Fri Oct 27 22:46:09 2017 +0900 @@ -1,6 +1,5 @@ /* Timing variables for measuring compiler performance. - Copyright (C) 2000, 2003, 2004, 2005, 2007, 2009, 2010 - Free Software Foundation, Inc. + Copyright (C) 2000-2017 Free Software Foundation, Inc. Contributed by Alex Samuel <samuel@codesourcery.com> This file is part of GCC. @@ -63,7 +62,7 @@ double wall; /* Garbage collector memory. */ - unsigned ggc_mem; + size_t ggc_mem; }; /* An enumeration of timing variable identifiers. Constructed from @@ -80,38 +79,183 @@ 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; -/* Execute the sequence: timevar_pop (TV), return (E); */ -#define POP_TIMEVAR_AND_RETURN(TV, E) do { timevar_pop (TV); return (E); }while(0) - 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 void timevar_print (FILE *); +extern bool timevar_cond_start (timevar_id_t); +extern void timevar_cond_stop (timevar_id_t, bool); + +/* 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 push_client_item (const char *item_name); + void pop_client_item (); + + void print (FILE *fp); + + const char *get_topmost_item_name () const; + + private: + /* Private member functions. */ + void validate_phases (FILE *fp) const; + + struct timevar_def; + void push_internal (struct timevar_def *tv); + void pop_internal (); + static void print_row (FILE *fp, + const timevar_time_def *total, + const char *name, const timevar_time_def &elapsed); + static bool all_zero (const timevar_time_def &elapsed); + + private: + typedef hash_map<timevar_def *, timevar_time_def> child_map_t; + + /* 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; + + child_map_t *children; + }; + + /* 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; + }; + + /* A class for managing a collection of named timing items, for use + e.g. by libgccjit for timing client code. This class is declared + inside timevar.c to avoid everything using timevar.h + from needing vec and hash_map. */ + class named_items; + + 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; + + /* If non-NULL, for use when timing libgccjit's client code. */ + named_items *m_jit_client_items; + + friend class named_items; +}; /* 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 +// constructor and pops the timevar in its destructor. +class auto_timevar +{ + public: + auto_timevar (timer *t, timevar_id_t tv) + : m_timer (t), + m_tv (tv) + { + if (m_timer) + m_timer->push (m_tv); + } + + explicit auto_timevar (timevar_id_t tv) + : m_timer (g_timer) + , m_tv (tv) + { + if (m_timer) + m_timer->push (m_tv); + } + + ~auto_timevar () + { + if (m_timer) + m_timer->pop (m_tv); + } + + private: + + // Private to disallow copies. + auto_timevar (const auto_timevar &); + + timer *m_timer; + timevar_id_t m_tv; +}; + extern void print_time (const char *, long); #endif /* ! GCC_TIMEVAR_H */