@@ -63,9 +63,16 @@ class PassTimingInfo {
6363private:
6464 StringMap<unsigned > PassIDCountMap; // /< Map that counts instances of passes
6565 DenseMap<PassInstanceID, std::unique_ptr<Timer>> TimingData; // /< timers for pass instances
66- TimerGroup *PassTG = nullptr ;
66+ TimerGroup TG ;
6767
6868public:
69+ // / Default constructor for yet-inactive timeinfo.
70+ // / Use \p init() to activate it.
71+ PassTimingInfo ();
72+
73+ // / Print out timing information and release timers.
74+ ~PassTimingInfo ();
75+
6976 // / Initializes the static \p TheTimeInfo member to a non-null value when
7077 // / -time-passes is enabled. Leaves it null otherwise.
7178 // /
@@ -87,6 +94,14 @@ class PassTimingInfo {
8794
8895static ManagedStatic<sys::SmartMutex<true >> TimingInfoMutex;
8996
97+ PassTimingInfo::PassTimingInfo () : TG(" pass" , " Pass execution timing report" ) {}
98+
99+ PassTimingInfo::~PassTimingInfo () {
100+ // Deleting the timers accumulates their info into the TG member.
101+ // Then TG member is (implicitly) deleted, actually printing the report.
102+ TimingData.clear ();
103+ }
104+
90105void PassTimingInfo::init () {
91106 if (TheTimeInfo || !TimePassesIsEnabled)
92107 return ;
@@ -95,16 +110,12 @@ void PassTimingInfo::init() {
95110 // This guarantees that the object will be constructed after static globals,
96111 // thus it will be destroyed before them.
97112 static ManagedStatic<PassTimingInfo> TTI;
98- if (!TTI->PassTG )
99- TTI->PassTG = &NamedRegionTimer::getNamedTimerGroup (
100- TimePassesHandler::PassGroupName, TimePassesHandler::PassGroupDesc);
101113 TheTimeInfo = &*TTI;
102114}
103115
104116// / Prints out timing information and then resets the timers.
105117void PassTimingInfo::print (raw_ostream *OutStream) {
106- assert (PassTG && " PassTG is null, did you call PassTimingInfo::Init()?" );
107- PassTG->print (OutStream ? *OutStream : *CreateInfoOutputFile (), true );
118+ TG.print (OutStream ? *OutStream : *CreateInfoOutputFile (), true );
108119}
109120
110121Timer *PassTimingInfo::newPassTimer (StringRef PassID, StringRef PassDesc) {
@@ -113,8 +124,7 @@ Timer *PassTimingInfo::newPassTimer(StringRef PassID, StringRef PassDesc) {
113124 // Appending description with a pass-instance number for all but the first one
114125 std::string PassDescNumbered =
115126 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);
127+ return new Timer (PassID, PassDescNumbered, TG);
118128}
119129
120130Timer *PassTimingInfo::getPassTimer (Pass *P, PassInstanceID Pass) {
@@ -183,7 +193,9 @@ Timer &TimePassesHandler::getPassTimer(StringRef PassID, bool IsPass) {
183193}
184194
185195TimePassesHandler::TimePassesHandler (bool Enabled, bool PerRun)
186- : Enabled(Enabled), PerRun(PerRun) {}
196+ : PassTG(" pass" , " Pass execution timing report" ),
197+ AnalysisTG (" analysis" , " Analysis execution timing report" ),
198+ Enabled(Enabled), PerRun(PerRun) {}
187199
188200TimePassesHandler::TimePassesHandler ()
189201 : TimePassesHandler(TimePassesIsEnabled, TimePassesPerRun) {}
0 commit comments