LLVM: lib/IR/PassTimingInfo.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
29#include
30
31using namespace llvm;
32
33#define DEBUG_TYPE "time-passes"
34
35using namespace llvm;
36
39
42 cl::desc("Time each pass, printing elapsed time for each on exit"));
43
46 cl::desc("Time each pass run, printing elapsed time for each run on exit"),
48
49namespace {
51
52
53
54
55
56
57
58
59class PassTimingInfo {
60public:
61 using PassInstanceID = void *;
62
63private:
64 StringMap PassIDCountMap;
67
68public:
69
70
71
72
73 static void init();
74
75
76
78
79
81
82 static PassTimingInfo *TheTimeInfo;
83
84private:
86};
87
89
90void PassTimingInfo::init() {
92 return;
93
94
95
96
98 if (->PassTG)
101 TheTimeInfo = &*TTI;
102}
103
104
105void PassTimingInfo::print(raw_ostream *OutStream) {
106 assert(PassTG && "PassTG is null, did you call PassTimingInfo::Init()?");
108}
109
111 unsigned &num = PassIDCountMap[PassID];
112 num++;
113
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);
118}
119
120Timer *PassTimingInfo::getPassTimer(Pass *P, PassInstanceID Pass) {
121 if (P->getAsPMDataManager())
122 return nullptr;
123
124 init();
126 std::unique_ptr &T = TimingData[Pass];
127
128 if (!T) {
132 PassArgument = PI->getPassArgument();
134 }
135 return T.get();
136}
137
138PassTimingInfo *PassTimingInfo::TheTimeInfo;
139}
140}
141
143 legacy::PassTimingInfo::init();
144 if (legacy::PassTimingInfo::TheTimeInfo)
145 return legacy::PassTimingInfo::TheTimeInfo->getPassTimer(P, P);
146 return nullptr;
147}
148
149
150
152 if (legacy::PassTimingInfo::TheTimeInfo)
153 legacy::PassTimingInfo::TheTimeInfo->print(OutStream);
154}
155
156
157
158
159
160
161
162Timer &TimePassesHandler::getPassTimer(StringRef PassID, bool IsPass) {
163 TimerGroup &TG = IsPass ? PassTG : AnalysisTG;
164 if (!PerRun) {
165 TimerVector &Timers = TimingData[PassID];
166 if (Timers.size() == 0)
167 Timers.emplace_back(new Timer(PassID, PassID, TG));
168 return *Timers.front();
169 }
170
171
172
173 TimerVector &Timers = TimingData[PassID];
174 unsigned Count = Timers.size() + 1;
175
176 std::string FullDesc = formatv("{0} #{1}", PassID, Count).str();
177
178 Timer *T = new Timer(PassID, FullDesc, TG);
179 Timers.emplace_back(T);
180 assert(Count == Timers.size() && "Timers vector not adjusted correctly.");
181
182 return *T;
183}
184
186 : Enabled(Enabled), PerRun(PerRun) {}
187
190
192 OutStream = &Out;
193}
194
196 if (!Enabled)
197 return;
198 std::unique_ptr<raw_ostream> MaybeCreated;
200 if (OutStream) {
201 OS = OutStream;
202 } else {
204 OS = &*MaybeCreated;
205 }
206 PassTG.print(*OS, true);
207 AnalysisTG.print(*OS, true);
208}
209
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();
218 if (MyTimer && MyTimer->isRunning())
219 dbgs() << "\tTimer " << MyTimer << " for pass " << PassID << "(" << idx << ")\n";
220 }
221 }
222 dbgs() << "\tTriggered:\n";
223 for (auto &I : TimingData) {
224 StringRef PassID = I.getKey();
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";
230 }
231 }
232}
233
236 {"PassManager", "PassAdaptor", "AnalysisManagerProxy",
237 "ModuleInlinerWrapperPass", "DevirtSCCRepeatedPass"});
238}
239
240void TimePassesHandler::startPassTimer(StringRef PassID) {
242 return;
243
244
245 if (!PassActiveTimerStack.empty()) {
246 assert(PassActiveTimerStack.back()->isRunning());
247 PassActiveTimerStack.back()->stopTimer();
248 }
249 Timer &MyTimer = getPassTimer(PassID, true);
250 PassActiveTimerStack.push_back(&MyTimer);
253}
254
255void TimePassesHandler::stopPassTimer(StringRef PassID) {
257 return;
258 assert(!PassActiveTimerStack.empty() && "empty stack in popTimer");
259 Timer *MyTimer = PassActiveTimerStack.pop_back_val();
260 assert(MyTimer && "timer should be present");
263
264
265 if (!PassActiveTimerStack.empty()) {
266 assert(!PassActiveTimerStack.back()->isRunning());
267 PassActiveTimerStack.back()->startTimer();
268 }
269}
270
271void TimePassesHandler::startAnalysisTimer(StringRef PassID) {
272
273
274 if (!AnalysisActiveTimerStack.empty()) {
275 assert(AnalysisActiveTimerStack.back()->isRunning());
276 AnalysisActiveTimerStack.back()->stopTimer();
277 }
278
279 Timer &MyTimer = getPassTimer(PassID, false);
280 AnalysisActiveTimerStack.push_back(&MyTimer);
283}
284
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");
291
292
293 if (!AnalysisActiveTimerStack.empty()) {
294 assert(!AnalysisActiveTimerStack.back()->isRunning());
295 AnalysisActiveTimerStack.back()->startTimer();
296 }
297}
298
300 if (!Enabled)
301 return;
302
303 PIC.registerBeforeNonSkippedPassCallback(
304 [this](StringRef P, Any) { this->startPassTimer(P); });
305 PIC.registerAfterPassCallback(
307 this->stopPassTimer(P);
308 });
309 PIC.registerAfterPassInvalidatedCallback(
311 this->stopPassTimer(P);
312 });
313 PIC.registerBeforeAnalysisCallback(
314 [this](StringRef P, Any) { this->startAnalysisTimer(P); });
315 PIC.registerAfterAnalysisCallback(
316 [this](StringRef P, Any) { this->stopAnalysisTimer(P); });
317}
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)
Definition PassTimingInfo.cpp:234
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[]
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",...
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.
LLVM_ABI void print()
Prints out timing information and then resets the timers.
Definition PassTimingInfo.cpp:195
LLVM_ABI TimePassesHandler()
Definition PassTimingInfo.cpp:188
LLVM_ABI void setOutStream(raw_ostream &OutStream)
Set a custom output stream for subsequent reporting.
Definition PassTimingInfo.cpp:191
LLVM_ABI void registerCallbacks(PassInstrumentationCallbacks &PIC)
Definition PassTimingInfo.cpp:299
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.
Definition PassTimingInfo.cpp:50
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.
Definition PassTimingInfo.cpp:38
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.
Definition PassTimingInfo.cpp:151
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.
Definition PassTimingInfo.cpp:142
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionAddr VTableAddr Count
LLVM_ABI bool isSpecialPass(StringRef PassID, const std::vector< StringRef > &Specials)
static LLVM_ABI TimerGroup & getNamedTimerGroup(StringRef GroupName, StringRef GroupDescription)