Index: llvm/include/llvm/Support/Signposts.h =================================================================== --- llvm/include/llvm/Support/Signposts.h +++ llvm/include/llvm/Support/Signposts.h @@ -17,9 +17,10 @@ #ifndef LLVM_SUPPORT_SIGNPOSTS_H #define LLVM_SUPPORT_SIGNPOSTS_H +#include "llvm/ADT/StringRef.h" + namespace llvm { class SignpostEmitterImpl; -class Timer; /// Manages the emission of signposts into the recording method supported by /// the OS. @@ -32,10 +33,10 @@ bool isEnabled() const; - /// Begin a signposted interval for the given timer. - void startTimerInterval(Timer *T); - /// End a signposted interval for the given timer. - void endTimerInterval(Timer *T); + /// Begin a signposted interval for a given object. + void startInterval(const void *O, StringRef Name); + /// End a signposted interval for a given object. + void endInterval(const void *O, StringRef Name); }; } // end namespace llvm Index: llvm/lib/Support/Signposts.cpp =================================================================== --- llvm/lib/Support/Signposts.cpp +++ llvm/lib/Support/Signposts.cpp @@ -4,6 +4,7 @@ // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. +// class StringRef // //===----------------------------------------------------------------------===// @@ -33,21 +34,20 @@ namespace llvm { class SignpostEmitterImpl { - using LogPtrTy = - std::unique_ptr>; + using LogPtrTy = std::unique_ptr>; using LogTy = LogPtrTy::element_type; LogPtrTy SignpostLog; - DenseMap Signposts; + DenseMap Signposts; LogTy &getLogger() const { return *SignpostLog; } - os_signpost_id_t getSignpostForTimer(const Timer *T) { - const auto &I = Signposts.find(T); + os_signpost_id_t getSignpostForObject(const void *O) { + const auto &I = Signposts.find(O); if (I != Signposts.end()) return I->second; const auto &Inserted = Signposts.insert( - std::make_pair(T, os_signpost_id_make_with_pointer(getLogger(), T))); + std::make_pair(O, os_signpost_id_make_with_pointer(getLogger(), O))); return Inserted.first->second; } @@ -56,20 +56,19 @@ bool isEnabled() const { return os_signpost_enabled(*SignpostLog); } - void startTimerInterval(Timer *T) { + void startInterval(const void *O, llvm::StringRef Name) { if (isEnabled()) { - // Both strings used here are required to be constant literal strings - os_signpost_interval_begin(getLogger(), getSignpostForTimer(T), - "Pass Timers", "Begin %s", - T->getName().c_str()); + // Both strings used here are required to be constant literal strings. + os_signpost_interval_begin(getLogger(), getSignpostForObject(O), + "LLVM Timers", "Begin %s", Name.data()); } } - void endTimerInterval(Timer *T) { + void endInterval(const void *O, llvm::StringRef Name) { if (isEnabled()) { - // Both strings used here are required to be constant literal strings - os_signpost_interval_end(getLogger(), getSignpostForTimer(T), - "Pass Timers", "End %s", T->getName().c_str()); + // Both strings used here are required to be constant literal strings. + os_signpost_interval_end(getLogger(), getSignpostForObject(O), + "LLVM Timers", "End %s", Name.data()); } } }; @@ -85,7 +84,7 @@ SignpostEmitter::SignpostEmitter() { #if HAVE_ANY_SIGNPOST_IMPL Impl = new SignpostEmitterImpl(); -#else // if HAVE_ANY_SIGNPOST_IMPL +#else // if HAVE_ANY_SIGNPOST_IMPL Impl = nullptr; #endif // if !HAVE_ANY_SIGNPOST_IMPL } @@ -104,18 +103,18 @@ #endif // if !HAVE_ANY_SIGNPOST_IMPL } -void SignpostEmitter::startTimerInterval(Timer *T) { +void SignpostEmitter::startInterval(const void *O, StringRef Name) { #if HAVE_ANY_SIGNPOST_IMPL if (Impl == nullptr) return; - return Impl->startTimerInterval(T); + return Impl->startInterval(O, Name); #endif // if !HAVE_ANY_SIGNPOST_IMPL } -void SignpostEmitter::endTimerInterval(Timer *T) { +void SignpostEmitter::endInterval(const void *O, StringRef Name) { #if HAVE_ANY_SIGNPOST_IMPL if (Impl == nullptr) return; - Impl->endTimerInterval(T); + Impl->endInterval(O, Name); #endif // if !HAVE_ANY_SIGNPOST_IMPL } Index: llvm/lib/Support/Timer.cpp =================================================================== --- llvm/lib/Support/Timer.cpp +++ llvm/lib/Support/Timer.cpp @@ -143,7 +143,7 @@ void Timer::startTimer() { assert(!Running && "Cannot start a running timer"); Running = Triggered = true; - Signposts->startTimerInterval(this); + Signposts->startInterval(this, getName()); StartTime = TimeRecord::getCurrentTime(true); } @@ -152,7 +152,7 @@ Running = false; Time += TimeRecord::getCurrentTime(false); Time -= StartTime; - Signposts->endTimerInterval(this); + Signposts->endInterval(this, getName()); } void Timer::clear() {