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())
129 PassArgument = PI->getPassArgument();
132 std::unique_ptr<Timer> &T = TimingData[
Pass];
136 if (T && T->getName() != TimerName)
140 T.reset(newPassTimer(TimerName,
PassName));
144PassTimingInfo *PassTimingInfo::TheTimeInfo;
149 legacy::PassTimingInfo::init();
150 if (legacy::PassTimingInfo::TheTimeInfo)
151 return legacy::PassTimingInfo::TheTimeInfo->getPassTimer(
P,
P);
158 if (legacy::PassTimingInfo::TheTimeInfo)
159 legacy::PassTimingInfo::TheTimeInfo->print(OutStream);
169 TimerGroup &TG = IsPass ? PassTG : AnalysisTG;
171 TimerVector &Timers = TimingData[
PassID];
172 if (Timers.size() == 0)
174 return *Timers.front();
179 TimerVector &Timers = TimingData[PassID];
180 unsigned Count = Timers.size() + 1;
182 std::string FullDesc =
formatv(
"{0} #{1}", PassID,
Count).str();
184 Timer *
T =
new Timer(PassID, FullDesc, TG);
185 Timers.emplace_back(
T);
186 assert(
Count == Timers.size() &&
"Timers vector not adjusted correctly.");
192 : Enabled(Enabled), PerRun(PerRun) {}
204 std::unique_ptr<raw_ostream> MaybeCreated;
212 PassTG.print(*OS,
true);
213 AnalysisTG.print(*OS,
true);
218 <<
":\n\tRunning:\n";
219 for (
auto &
I : TimingData) {
221 const TimerVector& MyTimers =
I.getValue();
222 for (
unsigned idx = 0; idx < MyTimers.size(); idx++) {
223 const Timer* MyTimer = MyTimers[idx].get();
225 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " <<
PassID <<
"(" << idx <<
")\n";
228 dbgs() <<
"\tTriggered:\n";
229 for (
auto &
I : TimingData) {
230 StringRef PassID =
I.getKey();
231 const TimerVector& MyTimers =
I.getValue();
232 for (
unsigned idx = 0; idx < MyTimers.size(); idx++) {
233 const Timer* MyTimer = MyTimers[idx].get();
235 dbgs() <<
"\tTimer " << MyTimer <<
" for pass " << PassID <<
"(" << idx <<
")\n";
242 {
"PassManager",
"PassAdaptor",
"AnalysisManagerProxy",
243 "ModuleInlinerWrapperPass",
"DevirtSCCRepeatedPass"});
246void TimePassesHandler::startPassTimer(
StringRef PassID) {
251 if (!PassActiveTimerStack.empty()) {
252 assert(PassActiveTimerStack.back()->isRunning());
253 PassActiveTimerStack.back()->stopTimer();
255 Timer &MyTimer = getPassTimer(PassID,
true);
256 PassActiveTimerStack.push_back(&MyTimer);
261void TimePassesHandler::stopPassTimer(
StringRef PassID) {
264 assert(!PassActiveTimerStack.empty() &&
"empty stack in popTimer");
265 Timer *MyTimer = PassActiveTimerStack.pop_back_val();
266 assert(MyTimer &&
"timer should be present");
271 if (!PassActiveTimerStack.empty()) {
272 assert(!PassActiveTimerStack.back()->isRunning());
273 PassActiveTimerStack.back()->startTimer();
277void TimePassesHandler::startAnalysisTimer(
StringRef PassID) {
280 if (!AnalysisActiveTimerStack.empty()) {
281 assert(AnalysisActiveTimerStack.back()->isRunning());
282 AnalysisActiveTimerStack.back()->stopTimer();
285 Timer &MyTimer = getPassTimer(PassID,
false);
286 AnalysisActiveTimerStack.push_back(&MyTimer);
291void TimePassesHandler::stopAnalysisTimer(
StringRef PassID) {
292 assert(!AnalysisActiveTimerStack.empty() &&
"empty stack in popTimer");
293 Timer *MyTimer = AnalysisActiveTimerStack.pop_back_val();
294 assert(MyTimer &&
"timer should be present");
299 if (!AnalysisActiveTimerStack.empty()) {
300 assert(!AnalysisActiveTimerStack.back()->isRunning());
301 AnalysisActiveTimerStack.back()->startTimer();
309 PIC.registerBeforeNonSkippedPassCallback(
311 PIC.registerAfterPassCallback(
313 this->stopPassTimer(
P);
315 PIC.registerAfterPassInvalidatedCallback(
317 this->stopPassTimer(
P);
319 PIC.registerBeforeAnalysisCallback(
321 PIC.registerAfterAnalysisCallback(
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#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 ...
static bool shouldIgnorePass(StringRef PassID)
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 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;}))
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[]
A type-erased reference to the IR unit a pass or analysis is running on, together with the kind of IR...
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,...
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
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",...
Represent a constant reference to a string, i.e.
std::string str() const
Get the contents as an std::string.
constexpr bool empty() const
Check if the string is empty.
LLVM_ABI void print()
Prints out timing information and then resets the timers.
LLVM_ABI TimePassesHandler()
LLVM_ABI void setOutStream(raw_ostream &OutStream)
Set a custom output stream for subsequent reporting.
LLVM_ABI void registerCallbacks(PassInstrumentationCallbacks &PIC)
static constexpr StringRef PassGroupDesc
static constexpr StringRef PassGroupName
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.
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.
LLVM_GET_TYPE_NAME_CONSTEXPR StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
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.
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)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
static LLVM_ABI TimerGroup & getNamedTimerGroup(StringRef GroupName, StringRef GroupDescription)