36 #define DEBUG_TYPE "time-passes" 44 cl::desc(
"Time each pass, printing elapsed time for each on exit"));
56 class PassTimingInfo {
58 using PassInstanceID =
void *;
86 static PassTimingInfo *TheTimeInfo;
94 PassTimingInfo::PassTimingInfo()
95 : TG(
"pass",
"... Pass execution timing report ...") {}
97 PassTimingInfo::~PassTimingInfo() {
104 if (!TimePassesIsEnabled || TheTimeInfo)
120 unsigned &num = PassIDCountMap[PassID];
123 std::string PassDescNumbered =
124 num <= 1 ? PassDesc.
str() :
formatv(
"{0} #{1}", PassDesc, num).str();
125 return new Timer(PassID, PassDescNumbered, TG);
134 std::unique_ptr<Timer> &
T = TimingData[
Pass];
140 PassArgument = PI->getPassArgument();
141 T.reset(newPassTimer(PassArgument.
empty() ? PassName : PassArgument, PassName));
146 PassTimingInfo *PassTimingInfo::TheTimeInfo;
152 if (legacy::PassTimingInfo::TheTimeInfo)
153 return legacy::PassTimingInfo::TheTimeInfo->getPassTimer(P, P);
160 if (legacy::PassTimingInfo::TheTimeInfo)
161 legacy::PassTimingInfo::TheTimeInfo->print(OutStream);
172 unsigned Count = nextPassID(PassID);
175 std::string FullDesc =
formatv(
"{0} #{1}", PassID, Count).str();
177 PassInvocationID UID{PassID, Count};
179 auto Pair = TimingData.try_emplace(UID, T);
180 assert(Pair.second &&
"should always create a new timer");
181 return *(Pair.first->second.get());
185 : TG(
"pass",
"... Pass execution timing report ..."), Enabled(Enabled) {}
198 dbgs() <<
"Dumping timers for " << getTypeName<TimePassesHandler>()
199 <<
":\n\tRunning:\n";
200 for (
auto &
I : TimingData) {
201 const Timer *MyTimer =
I.second.get();
203 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " <<
I.first.first <<
"(" 204 <<
I.first.second <<
")\n";
206 dbgs() <<
"\tTriggered:\n";
207 for (
auto &
I : TimingData) {
208 const Timer *MyTimer =
I.second.get();
210 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " <<
I.first.first <<
"(" 211 <<
I.first.second <<
")\n";
215 void TimePassesHandler::startTimer(
StringRef PassID) {
216 Timer &MyTimer = getPassTimer(PassID);
217 TimerStack.push_back(&MyTimer);
222 void TimePassesHandler::stopTimer(
StringRef PassID) {
223 assert(TimerStack.size() > 0 &&
"empty stack in popTimer");
224 Timer *MyTimer = TimerStack.pop_back_val();
225 assert(MyTimer &&
"timer should be present");
226 if (MyTimer->isRunning())
227 MyTimer->stopTimer();
231 size_t prefix_pos = PassID.
find(
'<');
236 Prefix.
endswith(
"AnalysisManagerProxy");
239 bool TimePassesHandler::runBeforePass(
StringRef PassID) {
252 void TimePassesHandler::runAfterPass(
StringRef PassID) {
267 [
this](
StringRef P,
Any) {
return this->runBeforePass(P); });
271 [
this](
StringRef P) { this->runAfterPass(P); });
Pass interface - Implemented by all 'passes'.
void registerAfterAnalysisCallback(CallableT C)
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
void registerCallbacks(PassInstrumentationCallbacks &PIC)
static cl::opt< bool, true > EnableTiming("time-passes", cl::location(TimePassesIsEnabled), cl::Hidden, cl::desc("Time each pass, printing elapsed time for each on exit"))
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
virtual PMDataManager * getAsPMDataManager()
void setOutStream(raw_ostream &OutStream)
Set a custom output stream for subsequent reporting.
void print()
Prints out timing information and then resets the timers.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
bool isRunning() const
Check if the timer is currently running.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
This header defines classes/functions to handle pass execution timing information with interfaces for...
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
TimePassesHandler(bool Enabled=TimePassesIsEnabled)
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero...
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
std::unique_ptr< raw_fd_ostream > CreateInfoOutputFile()
Return a file stream to print our output on.
static const PassInfo * lookupPassInfo(const void *TI)
initializer< Ty > init(const Ty &Val)
AnalysisID getPassID() const
getPassID - Return the PassID number that corresponds to this pass.
void print(raw_ostream &OS, bool ResetAfterPrint=false)
Print any started timers in this group, optionally resetting timers after printing them...
void registerBeforeAnalysisCallback(CallableT C)
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
void registerBeforePassCallback(CallableT C)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
PassInfo class - An instance of this class exists for every pass known by the system, and can be obtained from a live Pass by calling its getPassInfo() method.
print lazy value Lazy Value Info Printer Pass
void startTimer()
Start the timer running.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
void registerAfterPassInvalidatedCallback(CallableT C)
The TimerGroup class is used to group together related timers into a single report that is printed wh...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void registerAfterPassCallback(CallableT C)
This class implements an extremely fast bulk output stream that can only output to a stream...
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
StringRef - Represent a constant reference to a string, i.e.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
static bool matchPassManager(StringRef PassID)
LocationClass< Ty > location(Ty &L)
bool hasTriggered() const
Check if startTimer() has ever been called on this timer.