37 #define DEBUG_TYPE "time-passes" 45 cl::desc(
"Time each pass, printing elapsed time for each on exit"));
57 class PassTimingInfo {
59 using PassInstanceID =
void *;
86 static PassTimingInfo *TheTimeInfo;
94 PassTimingInfo::PassTimingInfo()
95 : TG(
"pass",
"... Pass execution timing report ...") {}
97 PassTimingInfo::~PassTimingInfo() {
104 if (!TimePassesIsEnabled || TheTimeInfo)
118 unsigned &num = PassIDCountMap[PassID];
121 std::string PassDescNumbered =
122 num <= 1 ? PassDesc.
str() :
formatv(
"{0} #{1}", PassDesc, num).str();
123 return new Timer(PassID, PassDescNumbered, TG);
132 std::unique_ptr<Timer> &
T = TimingData[
Pass];
138 PassArgument = PI->getPassArgument();
139 T.reset(newPassTimer(PassArgument.
empty() ? PassName : PassArgument, PassName));
144 PassTimingInfo *PassTimingInfo::TheTimeInfo;
150 if (legacy::PassTimingInfo::TheTimeInfo)
151 return legacy::PassTimingInfo::TheTimeInfo->getPassTimer(P, P);
158 if (legacy::PassTimingInfo::TheTimeInfo)
159 legacy::PassTimingInfo::TheTimeInfo->print();
170 unsigned Count = nextPassID(PassID);
173 std::string FullDesc =
formatv(
"{0} #{1}", PassID, Count).str();
175 PassInvocationID UID{PassID, Count};
177 auto Pair = TimingData.try_emplace(UID, T);
178 assert(Pair.second &&
"should always create a new timer");
179 return *(Pair.first->second.get());
183 : TG(
"pass",
"... Pass execution timing report ..."), Enabled(Enabled) {}
188 dbgs() <<
"Dumping timers for " << getTypeName<TimePassesHandler>()
189 <<
":\n\tRunning:\n";
190 for (
auto &
I : TimingData) {
191 const Timer *MyTimer =
I.second.get();
193 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " <<
I.first.first <<
"(" 194 <<
I.first.second <<
")\n";
196 dbgs() <<
"\tTriggered:\n";
197 for (
auto &
I : TimingData) {
198 const Timer *MyTimer =
I.second.get();
200 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " <<
I.first.first <<
"(" 201 <<
I.first.second <<
")\n";
205 void TimePassesHandler::startTimer(
StringRef PassID) {
206 Timer &MyTimer = getPassTimer(PassID);
207 TimerStack.push_back(&MyTimer);
212 void TimePassesHandler::stopTimer(
StringRef PassID) {
213 assert(TimerStack.size() > 0 &&
"empty stack in popTimer");
214 Timer *MyTimer = TimerStack.pop_back_val();
215 assert(MyTimer &&
"timer should be present");
216 if (MyTimer->isRunning())
217 MyTimer->stopTimer();
221 size_t prefix_pos = PassID.
find(
'<');
226 Prefix.
endswith(
"AnalysisManagerProxy");
229 bool TimePassesHandler::runBeforePass(
StringRef PassID) {
242 void TimePassesHandler::runAfterPass(
StringRef PassID) {
257 [
this](
StringRef P,
Any) {
return this->runBeforePass(P); });
261 [
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"))
This class represents lattice values for constants.
virtual PMDataManager * getAsPMDataManager()
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.
void reportAndResetTimings()
If -time-passes has been specified, report the timings immediately and then reset the timers to zero...
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
This header defines classes/functions to handle pass execution timing information with interfaces for...
TimePassesHandler(bool Enabled=TimePassesIsEnabled)
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
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 registerBeforeAnalysisCallback(CallableT C)
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.
void print(raw_ostream &OS)
Print any started timers in this group.
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.
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 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...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
static bool matchPassManager(StringRef PassID)
LocationClass< Ty > location(Ty &L)
bool hasTriggered() const
Check if startTimer() has ever been called on this timer.