llvm.org GIT mirror llvm / b8bd68f
[PassTiming] cleaning up legacy PassTimingInfo interface. NFCI. During D51276 discussion it was decided that legacy PassTimingInfo interface can not be reused for new pass manager's implementation of -time-passes. This is a cleanup in preparation for D51276 to make legacy interface as concise as possible, moving the PassTimingInfo from the header into the anonymous legacy namespace in .cpp. It is rather close to a revert of rL340872 in a sense that it hides the interface and gets rid of templates. However as compared to a complete revert it resides in a different translation unit and has an additional pass-instance counting funcitonality (PassIDCountMap). Reviewers: philip.pfaffe Differential Revision: https://reviews.llvm.org/D52356 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343104 91177308-0d34-0410-b5e6-96231b3b80d8 Fedor Sergeev 11 months ago
5 changed file(s) with 67 addition(s) and 99 deletion(s). Raw diff Collapse all Expand all
9797 // Create wrappers for C Binding types (see CBindingWrapping.h).
9898 DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef)
9999
100 /// If -time-passes has been specified, report the timings immediately and then
101 /// reset the timers to zero.
102 void reportAndResetTimings();
103100 } // End llvm namespace
104101
105102 #endif
1515 #ifndef LLVM_IR_PASSTIMINGINFO_H
1616 #define LLVM_IR_PASSTIMINGINFO_H
1717
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/Timer.h"
22 #include
23
2418 namespace llvm {
2519
2620 class Pass;
27 class TimerGroup;
21 class Timer;
2822
29 /// Provides a generic interface for collecting pass timing information.
30 /// Legacy pass managers should specialize with \p PassInfo*.
31 /// New pass managers should specialize with \p StringRef.
32 template class PassTimingInfo {
33 public:
34 using PassInstanceID = void *;
23 /// If -time-passes has been specified, report the timings immediately and then
24 /// reset the timers to zero.
25 void reportAndResetTimings();
3526
36 private:
37 StringMap PassIDCountMap; ///< Map that counts instances of passes
38 DenseMap TimingData; ///< timers for pass instances
39 TimerGroup TG;
40
41 public:
42 /// Default constructor for yet-inactive timeinfo.
43 /// Use \p init() to activate it.
44 PassTimingInfo();
45
46 /// Print out timing information and release timers.
47 ~PassTimingInfo();
48
49 /// Initializes the static \p TheTimeInfo member to a non-null value when
50 /// -time-passes is enabled. Leaves it null otherwise.
51 ///
52 /// This method may be called multiple times.
53 static void init();
54
55 /// Prints out timing information and then resets the timers.
56 void print();
57
58 /// Returns the timer for the specified pass if it exists.
59 Timer *getPassTimer(PassInfoT, PassInstanceID);
60
61 static PassTimingInfo *TheTimeInfo;
62
63 private:
64 Timer *newPassTimer(StringRef PassID, StringRef PassDesc);
65 };
66
27 /// Request the timer for this legacy-pass-manager's pass instance.
6728 Timer *getPassTimer(Pass *);
68 Timer *getPassTimer(StringRef);
6929
7030 /// If the user specifies the -time-passes argument on an LLVM tool command line
7131 /// then the value of this boolean will be true, otherwise false.
99 // This file implements the LLVM Pass Timing infrastructure for both
1010 // new and legacy pass managers.
1111 //
12 // TimingInfo Class - This class is used to calculate information about the
12 // PassTimingInfo Class - This class is used to calculate information about the
1313 // amount of time each pass takes to execute. This only happens when
1414 // -time-passes is enabled on the command line.
1515 //
3333
3434 namespace llvm {
3535
36 //===----------------------------------------------------------------------===//
37 // TimingInfo implementation
36 bool TimePassesIsEnabled = false;
3837
39 bool TimePassesIsEnabled = false;
4038 static cl::opt EnableTiming(
4139 "time-passes", cl::location(TimePassesIsEnabled), cl::Hidden,
4240 cl::desc("Time each pass, printing elapsed time for each on exit"));
4341
4442 namespace {
43 namespace legacy {
44
45 //===----------------------------------------------------------------------===//
46 // TimingInfo implementation
47
48 /// Provides an interface for collecting pass timing information.
49 ///
50 /// It was intended to be generic but now we decided to split
51 /// interfaces completely. This is now exclusively for legacy-pass-manager use.
52 class PassTimingInfo {
53 public:
54 using PassInstanceID = void *;
55
56 private:
57 StringMap PassIDCountMap; ///< Map that counts instances of passes
58 DenseMap TimingData; ///< timers for pass instances
59 TimerGroup TG;
60
61 public:
62 /// Default constructor for yet-inactive timeinfo.
63 /// Use \p init() to activate it.
64 PassTimingInfo();
65
66 /// Print out timing information and release timers.
67 ~PassTimingInfo();
68
69 /// Initializes the static \p TheTimeInfo member to a non-null value when
70 /// -time-passes is enabled. Leaves it null otherwise.
71 ///
72 /// This method may be called multiple times.
73 static void init();
74
75 /// Prints out timing information and then resets the timers.
76 void print();
77
78 /// Returns the timer for the specified pass if it exists.
79 Timer *getPassTimer(Pass *, PassInstanceID);
80
81 static PassTimingInfo *TheTimeInfo;
82
83 private:
84 Timer *newPassTimer(StringRef PassID, StringRef PassDesc);
85 };
86
4587 static ManagedStatic> TimingInfoMutex;
46 }
4788
48 template
49 PassTimingInfo::PassTimingInfo()
89 PassTimingInfo::PassTimingInfo()
5090 : TG("pass", "... Pass execution timing report ...") {}
5191
52 template PassTimingInfo::~PassTimingInfo() {
92 PassTimingInfo::~PassTimingInfo() {
5393 // Deleting the timers accumulates their info into the TG member.
5494 // Then TG member is (implicitly) deleted, actually printing the report.
5595 for (auto &I : TimingData)
5696 delete I.getSecond();
5797 }
5898
59 template void PassTimingInfo::init() {
99 void PassTimingInfo::init() {
60100 if (!TimePassesIsEnabled || TheTimeInfo)
61101 return;
62102
68108 }
69109
70110 /// Prints out timing information and then resets the timers.
71 template void PassTimingInfo::print() {
72 TG.print(*CreateInfoOutputFile());
73 }
111 void PassTimingInfo::print() { TG.print(*CreateInfoOutputFile()); }
74112
75 template
76 Timer *PassTimingInfo::newPassTimer(StringRef PassID,
77 StringRef PassDesc) {
113 Timer *PassTimingInfo::newPassTimer(StringRef PassID, StringRef PassDesc) {
78114 unsigned &num = PassIDCountMap[PassID];
79115 num++;
80116 // Appending description with a pass-instance number for all but the first one
83119 return new Timer(PassID, PassDescNumbered, TG);
84120 }
85121
86 /// Returns the timer for the specified pass instance \p Pass.
87 /// Instances of the same pass type (uniquely identified by \p PassID) are
88 /// numbered by the order of appearance.
89 template <>
90 Timer *PassTimingInfo::getPassTimer(StringRef PassID,
91 PassInstanceID Pass) {
92 init();
93 sys::SmartScopedLock Lock(*TimingInfoMutex);
94 Timer *&T = TimingData[Pass];
95 if (!T)
96 T = newPassTimer(PassID, PassID);
97 return T;
98 }
99
100 template <>
101 Timer *PassTimingInfo::getPassTimer(Pass *P, PassInstanceID Pass) {
122 Timer *PassTimingInfo::getPassTimer(Pass *P, PassInstanceID Pass) {
102123 if (P->getAsPMDataManager())
103124 return nullptr;
104125
116137 return T;
117138 }
118139
119 template
120 PassTimingInfo *PassTimingInfo::TheTimeInfo;
121
122 template class PassTimingInfo;
123 template class PassTimingInfo;
140 PassTimingInfo *PassTimingInfo::TheTimeInfo;
141 } // namespace legacy
142 } // namespace
124143
125144 Timer *getPassTimer(Pass *P) {
126 PassTimingInfo::init();
127 if (PassTimingInfo::TheTimeInfo)
128 return PassTimingInfo::TheTimeInfo->getPassTimer(P, P);
129 return nullptr;
130 }
131
132 Timer *getPassTimer(StringRef PassName) {
133 PassTimingInfo::init();
134 if (PassTimingInfo::TheTimeInfo)
135 return PassTimingInfo::TheTimeInfo->getPassTimer(PassName,
136 nullptr);
145 legacy::PassTimingInfo::init();
146 if (legacy::PassTimingInfo::TheTimeInfo)
147 return legacy::PassTimingInfo::TheTimeInfo->getPassTimer(P, P);
137148 return nullptr;
138149 }
139150
140151 /// If timing is enabled, report the times collected up to now and then reset
141152 /// them.
142153 void reportAndResetTimings() {
143 if (PassTimingInfo::TheTimeInfo)
144 PassTimingInfo::TheTimeInfo->print();
145 if (PassTimingInfo::TheTimeInfo)
146 PassTimingInfo::TheTimeInfo->print();
154 if (legacy::PassTimingInfo::TheTimeInfo)
155 legacy::PassTimingInfo::TheTimeInfo->print();
147156 }
148157
149158 } // namespace llvm
3232 #include "llvm/IR/LegacyPassManager.h"
3333 #include "llvm/IR/Mangler.h"
3434 #include "llvm/IR/Module.h"
35 #include "llvm/IR/PassTimingInfo.h"
3536 #include "llvm/IR/Verifier.h"
3637 #include "llvm/InitializePasses.h"
3738 #include "llvm/LTO/LTO.h"
2828 #include "llvm/IR/LLVMContext.h"
2929 #include "llvm/IR/LegacyPassManager.h"
3030 #include "llvm/IR/Mangler.h"
31 #include "llvm/IR/PassTimingInfo.h"
3132 #include "llvm/IR/Verifier.h"
3233 #include "llvm/IRReader/IRReader.h"
3334 #include "llvm/LTO/LTO.h"