On 11/15/19 6:22 PM, David Malcolm wrote:
This patch adds a class "auto_client_timevar", similar to auto_timevar,
but for plugins to use on their own timing items that aren't in
timevar.def
gcc/ChangeLog:
* timevar.h (class auto_client_timevar): New class.
---
gcc/timevar.h | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/gcc/timevar.h b/gcc/timevar.h
index ef404d0..d053ab7 100644
--- a/gcc/timevar.h
+++ b/gcc/timevar.h
@@ -256,6 +256,39 @@ class auto_timevar
timevar_id_t m_tv;
};
+/* An RAII class analogous to auto_timevar, but for a client item,
+ for use by plugins. */
+
+class auto_client_timevar
+{
+ public:
+ auto_client_timevar (timer *t, const char *item_name)
+ : m_timer (t)
+ {
+ if (m_timer)
+ m_timer->push_client_item (item_name);
+ }
+
+ explicit auto_client_timevar (const char *item_name)
+ : m_timer (g_timer)
+ {
+ if (m_timer)
+ m_timer->push_client_item (item_name);
+ }
+
+ ~auto_client_timevar ()
+ {
+ if (m_timer)
+ m_timer->pop_client_item ();
+ }
+
+ private:
+ // Private to disallow copies.
+ auto_client_timevar (const auto_client_timevar &);
I don't know why it's important to disallow making copies of
these classes (they look safe to copy) but usually it goes
along with assignment so I would suggest adding a comment
with a rationale and (perhaps also) disabling assignment.
Martin
PS I see auto_timevar is also assignable but not copyable.
It's a common mistake to make to forget about one or the other
(or both) so if it's intentional it helps to document it.
+
+ timer *m_timer;
+};
+
extern void print_time (const char *, long);
#endif /* ! GCC_TIMEVAR_H */