33#define DEBUG_TYPE "time-passes"
42 cl::desc(
"Time each pass, printing elapsed time for each on exit"));
46 cl::desc(
"Time each pass run, printing elapsed time for each run on exit"),
61 using PassInstanceID =
void *;
82 static PassTimingInfo *TheTimeInfo;
90void PassTimingInfo::init() {
105void PassTimingInfo::print(
raw_ostream *OutStream) {
106 assert(PassTG &&
"PassTG is null, did you call PassTimingInfo::Init()?");
111 unsigned &num = PassIDCountMap[PassID];
114 std::string PassDescNumbered =
115 num <= 1 ? PassDesc.
str() :
formatv(
"{0} #{1}", PassDesc, num).str();
116 assert(PassTG &&
"PassTG is null, did you call PassTimingInfo::Init()?");
117 return new Timer(PassID, PassDescNumbered, *PassTG);
120Timer *PassTimingInfo::getPassTimer(
Pass *
P, PassInstanceID
Pass) {
121 if (
P->getAsPMDataManager())
126 std::unique_ptr<Timer> &
T = TimingData[
Pass];
132 PassArgument = PI->getPassArgument();
138PassTimingInfo *PassTimingInfo::TheTimeInfo;
143 legacy::PassTimingInfo::init();
144 if (legacy::PassTimingInfo::TheTimeInfo)
145 return legacy::PassTimingInfo::TheTimeInfo->getPassTimer(
P,
P);
152 if (legacy::PassTimingInfo::TheTimeInfo)
153 legacy::PassTimingInfo::TheTimeInfo->print(OutStream);
162Timer &TimePassesHandler::getPassTimer(
StringRef PassID,
bool IsPass) {
163 TimerGroup &TG = IsPass ? PassTG : AnalysisTG;
165 TimerVector &Timers = TimingData[PassID];
166 if (Timers.size() == 0)
167 Timers.emplace_back(
new Timer(PassID, PassID, TG));
168 return *Timers.front();
173 TimerVector &Timers = TimingData[PassID];
174 unsigned Count = Timers.size() + 1;
176 std::string FullDesc =
formatv(
"{0} #{1}", PassID, Count).str();
179 Timers.emplace_back(
T);
180 assert(Count == Timers.size() &&
"Timers vector not adjusted correctly.");
198 std::unique_ptr<raw_ostream> MaybeCreated;
211 dbgs() <<
"Dumping timers for " << getTypeName<TimePassesHandler>()
212 <<
":\n\tRunning:\n";
213 for (
auto &
I : TimingData) {
215 const TimerVector& MyTimers =
I.getValue();
216 for (
unsigned idx = 0; idx < MyTimers.size(); idx++) {
217 const Timer* MyTimer = MyTimers[idx].get();
219 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " << PassID <<
"(" << idx <<
")\n";
222 dbgs() <<
"\tTriggered:\n";
223 for (
auto &
I : TimingData) {
225 const TimerVector& MyTimers =
I.getValue();
226 for (
unsigned idx = 0; idx < MyTimers.size(); idx++) {
227 const Timer* MyTimer = MyTimers[idx].get();
229 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " << PassID <<
"(" << idx <<
")\n";
236 {
"PassManager",
"PassAdaptor",
"AnalysisManagerProxy",
237 "ModuleInlinerWrapperPass",
"DevirtSCCRepeatedPass"});
240void TimePassesHandler::startPassTimer(
StringRef PassID) {
245 if (!PassActiveTimerStack.empty()) {
246 assert(PassActiveTimerStack.back()->isRunning());
247 PassActiveTimerStack.back()->stopTimer();
249 Timer &MyTimer = getPassTimer(PassID,
true);
250 PassActiveTimerStack.push_back(&MyTimer);
255void TimePassesHandler::stopPassTimer(
StringRef PassID) {
258 assert(!PassActiveTimerStack.empty() &&
"empty stack in popTimer");
259 Timer *MyTimer = PassActiveTimerStack.pop_back_val();
260 assert(MyTimer &&
"timer should be present");
265 if (!PassActiveTimerStack.empty()) {
266 assert(!PassActiveTimerStack.back()->isRunning());
267 PassActiveTimerStack.back()->startTimer();
271void TimePassesHandler::startAnalysisTimer(
StringRef PassID) {
274 if (!AnalysisActiveTimerStack.empty()) {
275 assert(AnalysisActiveTimerStack.back()->isRunning());
276 AnalysisActiveTimerStack.back()->stopTimer();
279 Timer &MyTimer = getPassTimer(PassID,
false);
280 AnalysisActiveTimerStack.push_back(&MyTimer);
285void TimePassesHandler::stopAnalysisTimer(
StringRef PassID) {
286 assert(!AnalysisActiveTimerStack.empty() &&
"empty stack in popTimer");
287 Timer *MyTimer = AnalysisActiveTimerStack.pop_back_val();
288 assert(MyTimer &&
"timer should be present");
293 if (!AnalysisActiveTimerStack.empty()) {
294 assert(!AnalysisActiveTimerStack.back()->isRunning());
295 AnalysisActiveTimerStack.back()->startTimer();
307 this->stopPassTimer(
P);
311 this->stopPassTimer(
P);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
PassInstrumentationCallbacks PIC
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
This header defines classes/functions to handle pass execution timing information with interfaces for...
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
static const char PassName[]
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
PassInfo class - An instance of this class exists for every pass known by the system,...
Pass interface - Implemented by all 'passes'.
static const PassInfo * lookupPassInfo(const void *TI)
A set of analyses that are preserved following a run of a transformation pass.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
This class implements -time-passes functionality for new pass manager.
LLVM_ABI void registerCallbacks(PassInstrumentationCallbacks &PIC)
LLVM_ABI TimePassesHandler()
static constexpr StringRef PassGroupDesc
static constexpr StringRef PassGroupName
LLVM_ABI void print()
Prints out timing information and then resets the timers.
LLVM_ABI void setOutStream(raw_ostream &OutStream)
Set a custom output stream for subsequent reporting.
The TimerGroup class is used to group together related timers into a single report that is printed wh...
LLVM_ABI void print(raw_ostream &OS, bool ResetAfterPrint=false)
Print any started timers in this group, optionally resetting timers after printing them.
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
bool hasTriggered() const
Check if startTimer() has ever been called on this timer.
bool isRunning() const
Check if the timer is currently running.
LLVM_ABI void stopTimer()
Stop the timer.
LLVM_ABI void startTimer()
Start the timer running.
This class implements an extremely fast bulk output stream that can only output to a stream.
initializer< Ty > init(const Ty &Val)
LocationClass< Ty > location(Ty &L)
cb< typename detail::callback_traits< F >::result_type, typename detail::callback_traits< F >::arg_type > callback(F CB)
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::unique_ptr< raw_ostream > CreateInfoOutputFile()
Return a stream to print our output on.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
static cl::opt< bool, true > EnableTimingPerRun("time-passes-per-run", cl::location(TimePassesPerRun), cl::Hidden, cl::desc("Time each pass run, printing elapsed time for each run on exit"), cl::callback([](const bool &) { TimePassesIsEnabled=true;}))
LLVM_ABI bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
LLVM_ABI bool TimePassesPerRun
If TimePassesPerRun is true, there would be one line of report for each pass invocation.
LLVM_ABI void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
static bool shouldIgnorePass(StringRef PassID)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI bool isSpecialPass(StringRef PassID, const std::vector< StringRef > &Specials)
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"))
static LLVM_ABI TimerGroup & getNamedTimerGroup(StringRef GroupName, StringRef GroupDescription)
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
void registerBeforeAnalysisCallback(CallableT C)
void registerAfterPassInvalidatedCallback(CallableT C, bool ToFront=false)
void registerAfterAnalysisCallback(CallableT C, bool ToFront=false)
void registerBeforeNonSkippedPassCallback(CallableT C)
void registerAfterPassCallback(CallableT C, bool ToFront=false)