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 *;
89 static PassTimingInfo *TheTimeInfo;
97PassTimingInfo::PassTimingInfo() : TG(
"pass",
"Pass execution timing report") {}
99PassTimingInfo::~PassTimingInfo() {
105void PassTimingInfo::init() {
117void PassTimingInfo::print(
raw_ostream *OutStream) {
122 unsigned &num = PassIDCountMap[PassID];
125 std::string PassDescNumbered =
126 num <= 1 ? PassDesc.
str() :
formatv(
"{0} #{1}", PassDesc, num).str();
127 return new Timer(PassID, PassDescNumbered, TG);
130Timer *PassTimingInfo::getPassTimer(
Pass *
P, PassInstanceID
Pass) {
131 if (
P->getAsPMDataManager())
136 std::unique_ptr<Timer> &
T = TimingData[
Pass];
142 PassArgument = PI->getPassArgument();
148PassTimingInfo *PassTimingInfo::TheTimeInfo;
153 legacy::PassTimingInfo::init();
154 if (legacy::PassTimingInfo::TheTimeInfo)
155 return legacy::PassTimingInfo::TheTimeInfo->getPassTimer(
P,
P);
162 if (legacy::PassTimingInfo::TheTimeInfo)
163 legacy::PassTimingInfo::TheTimeInfo->print(OutStream);
172Timer &TimePassesHandler::getPassTimer(
StringRef PassID,
bool IsPass) {
173 TimerGroup &TG = IsPass ? PassTG : AnalysisTG;
175 TimerVector &Timers = TimingData[PassID];
176 if (Timers.size() == 0)
177 Timers.emplace_back(
new Timer(PassID, PassID, TG));
178 return *Timers.front();
183 TimerVector &Timers = TimingData[PassID];
184 unsigned Count = Timers.size() + 1;
186 std::string FullDesc =
formatv(
"{0} #{1}", PassID, Count).str();
189 Timers.emplace_back(
T);
190 assert(Count == Timers.size() &&
"Timers vector not adjusted correctly.");
196 : PassTG(
"pass",
"Pass execution timing report"),
197 AnalysisTG(
"analysis",
"Analysis execution timing report"),
210 std::unique_ptr<raw_ostream> MaybeCreated;
223 dbgs() <<
"Dumping timers for " << getTypeName<TimePassesHandler>()
224 <<
":\n\tRunning:\n";
225 for (
auto &
I : TimingData) {
227 const TimerVector& MyTimers =
I.getValue();
228 for (
unsigned idx = 0; idx < MyTimers.size(); idx++) {
229 const Timer* MyTimer = MyTimers[idx].get();
231 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " << PassID <<
"(" << idx <<
")\n";
234 dbgs() <<
"\tTriggered:\n";
235 for (
auto &
I : TimingData) {
237 const TimerVector& MyTimers =
I.getValue();
238 for (
unsigned idx = 0; idx < MyTimers.size(); idx++) {
239 const Timer* MyTimer = MyTimers[idx].get();
241 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " << PassID <<
"(" << idx <<
")\n";
248 {
"PassManager",
"PassAdaptor",
"AnalysisManagerProxy",
249 "ModuleInlinerWrapperPass",
"DevirtSCCRepeatedPass"});
252void TimePassesHandler::startPassTimer(
StringRef PassID) {
257 if (!PassActiveTimerStack.empty()) {
258 assert(PassActiveTimerStack.back()->isRunning());
259 PassActiveTimerStack.back()->stopTimer();
261 Timer &MyTimer = getPassTimer(PassID,
true);
262 PassActiveTimerStack.push_back(&MyTimer);
267void TimePassesHandler::stopPassTimer(
StringRef PassID) {
270 assert(!PassActiveTimerStack.empty() &&
"empty stack in popTimer");
271 Timer *MyTimer = PassActiveTimerStack.pop_back_val();
272 assert(MyTimer &&
"timer should be present");
277 if (!PassActiveTimerStack.empty()) {
278 assert(!PassActiveTimerStack.back()->isRunning());
279 PassActiveTimerStack.back()->startTimer();
283void TimePassesHandler::startAnalysisTimer(
StringRef PassID) {
286 if (!AnalysisActiveTimerStack.empty()) {
287 assert(AnalysisActiveTimerStack.back()->isRunning());
288 AnalysisActiveTimerStack.back()->stopTimer();
291 Timer &MyTimer = getPassTimer(PassID,
false);
292 AnalysisActiveTimerStack.push_back(&MyTimer);
297void TimePassesHandler::stopAnalysisTimer(
StringRef PassID) {
298 assert(!AnalysisActiveTimerStack.empty() &&
"empty stack in popTimer");
299 Timer *MyTimer = AnalysisActiveTimerStack.pop_back_val();
300 assert(MyTimer &&
"timer should be present");
305 if (!AnalysisActiveTimerStack.empty()) {
306 assert(!AnalysisActiveTimerStack.back()->isRunning());
307 AnalysisActiveTimerStack.back()->startTimer();
319 this->stopPassTimer(
P);
323 this->stopPassTimer(
P);
#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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
void registerCallbacks(PassInstrumentationCallbacks &PIC)
void print()
Prints out timing information and then resets the timers.
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...
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.
void stopTimer()
Stop the timer.
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.
std::unique_ptr< raw_ostream > CreateInfoOutputFile()
Return a stream to print our output on.
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;}))
bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
bool TimePassesPerRun
If TimePassesPerRun is true, there would be one line of report for each pass invocation.
void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
static bool shouldIgnorePass(StringRef PassID)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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"))
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)