Skip to content

Commit 320ab02

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.5-bogner
1 parent a531800 commit 320ab02

File tree

1 file changed

+52
-63
lines changed

1 file changed

+52
-63
lines changed

llvm/lib/Support/Timer.cpp

Lines changed: 52 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
using namespace llvm;
4040

4141
//===----------------------------------------------------------------------===//
42-
// Forward declarations for Managed Timer Globals (mtg) getters.
42+
// Forward declarations for Managed Timer Globals getters.
4343
//
4444
// Globals have been placed at the end of the file to restrict direct
4545
// access. Use of getters also has the benefit of making it a bit more explicit
@@ -49,29 +49,21 @@ namespace {
4949
class Name2PairMap;
5050
}
5151

52-
namespace mtg {
53-
static std::string &LibSupportInfoOutputFilename();
54-
static const std::string &InfoOutputFilename();
55-
static bool TrackSpace();
56-
static bool SortTimers();
57-
static SignpostEmitter &Signposts();
58-
static sys::SmartMutex<true> &TimerLock();
59-
static TimerGroup &DefaultTimerGroup();
52+
static std::string &libSupportInfoOutputFilename();
53+
static bool trackSpace();
54+
static bool sortTimers();
55+
static SignpostEmitter &signposts();
56+
static sys::SmartMutex<true> &timerLock();
57+
static TimerGroup &defaultTimerGroup();
6058
static TimerGroup *claimDefaultTimerGroup();
61-
static Name2PairMap &NamedGroupedTimers();
62-
} // namespace mtg
59+
static Name2PairMap &namedGroupedTimers();
6360

6461
//===----------------------------------------------------------------------===//
6562
//
6663
//===----------------------------------------------------------------------===//
67-
void llvm::initTimerOptions() {
68-
mtg::TrackSpace();
69-
mtg::InfoOutputFilename();
70-
mtg::SortTimers();
71-
}
7264

7365
std::unique_ptr<raw_ostream> llvm::CreateInfoOutputFile() {
74-
const std::string &OutputFilename = mtg::LibSupportInfoOutputFilename();
66+
const std::string &OutputFilename = libSupportInfoOutputFilename();
7567
if (OutputFilename.empty())
7668
return std::make_unique<raw_fd_ostream>(2, false); // stderr.
7769
if (OutputFilename == "-")
@@ -97,7 +89,7 @@ std::unique_ptr<raw_ostream> llvm::CreateInfoOutputFile() {
9789
//===----------------------------------------------------------------------===//
9890

9991
void Timer::init(StringRef TimerName, StringRef TimerDescription) {
100-
init(TimerName, TimerDescription, mtg::DefaultTimerGroup());
92+
init(TimerName, TimerDescription, defaultTimerGroup());
10193
}
10294

10395
void Timer::init(StringRef TimerName, StringRef TimerDescription,
@@ -116,7 +108,7 @@ Timer::~Timer() {
116108
}
117109

118110
static inline size_t getMemUsage() {
119-
if (!mtg::TrackSpace())
111+
if (!trackSpace())
120112
return 0;
121113
return sys::Process::GetMallocUsage();
122114
}
@@ -157,7 +149,7 @@ TimeRecord TimeRecord::getCurrentTime(bool Start) {
157149
void Timer::startTimer() {
158150
assert(!Running && "Cannot start a running timer");
159151
Running = Triggered = true;
160-
mtg::Signposts().startInterval(this, getName());
152+
signposts().startInterval(this, getName());
161153
StartTime = TimeRecord::getCurrentTime(true);
162154
}
163155

@@ -166,7 +158,7 @@ void Timer::stopTimer() {
166158
Running = false;
167159
Time += TimeRecord::getCurrentTime(false);
168160
Time -= StartTime;
169-
mtg::Signposts().endInterval(this, getName());
161+
signposts().endInterval(this, getName());
170162
}
171163

172164
void Timer::clear() {
@@ -218,7 +210,7 @@ class Name2PairMap {
218210

219211
Timer &get(StringRef Name, StringRef Description, StringRef GroupName,
220212
StringRef GroupDescription) {
221-
sys::SmartScopedLock<true> L(mtg::TimerLock());
213+
sys::SmartScopedLock<true> L(timerLock());
222214

223215
std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
224216

@@ -237,17 +229,17 @@ class Name2PairMap {
237229
NamedRegionTimer::NamedRegionTimer(StringRef Name, StringRef Description,
238230
StringRef GroupName,
239231
StringRef GroupDescription, bool Enabled)
240-
: TimeRegion(!Enabled ? nullptr
241-
: &mtg::NamedGroupedTimers().get(Name, Description,
242-
GroupName,
243-
GroupDescription)) {}
232+
: TimeRegion(!Enabled
233+
? nullptr
234+
: &namedGroupedTimers().get(Name, Description, GroupName,
235+
GroupDescription)) {}
244236

245237
//===----------------------------------------------------------------------===//
246238
// TimerGroup Implementation
247239
//===----------------------------------------------------------------------===//
248240

249241
/// This is the global list of TimerGroups, maintained by the TimerGroup
250-
/// ctor/dtor and is protected by the TimerLock lock.
242+
/// ctor/dtor and is protected by the timerLock lock.
251243
static TimerGroup *TimerGroupList = nullptr;
252244

253245
TimerGroup::TimerGroup(StringRef Name, StringRef Description,
@@ -264,7 +256,7 @@ TimerGroup::TimerGroup(StringRef Name, StringRef Description,
264256
}
265257

266258
TimerGroup::TimerGroup(StringRef Name, StringRef Description)
267-
: TimerGroup(Name, Description, mtg::TimerLock()) {}
259+
: TimerGroup(Name, Description, timerLock()) {}
268260

269261
TimerGroup::TimerGroup(StringRef Name, StringRef Description,
270262
const StringMap<TimeRecord> &Records)
@@ -283,15 +275,15 @@ TimerGroup::~TimerGroup() {
283275
removeTimer(*FirstTimer);
284276

285277
// Remove the group from the TimerGroupList.
286-
sys::SmartScopedLock<true> L(mtg::TimerLock());
278+
sys::SmartScopedLock<true> L(timerLock());
287279
*Prev = Next;
288280
if (Next)
289281
Next->Prev = Prev;
290282
}
291283

292284

293285
void TimerGroup::removeTimer(Timer &T) {
294-
sys::SmartScopedLock<true> L(mtg::TimerLock());
286+
sys::SmartScopedLock<true> L(timerLock());
295287

296288
// If the timer was started, move its data to TimersToPrint.
297289
if (T.hasTriggered())
@@ -314,7 +306,7 @@ void TimerGroup::removeTimer(Timer &T) {
314306
}
315307

316308
void TimerGroup::addTimer(Timer &T) {
317-
sys::SmartScopedLock<true> L(mtg::TimerLock());
309+
sys::SmartScopedLock<true> L(timerLock());
318310

319311
// Add the timer to our list.
320312
if (FirstTimer)
@@ -326,7 +318,7 @@ void TimerGroup::addTimer(Timer &T) {
326318

327319
void TimerGroup::PrintQueuedTimers(raw_ostream &OS) {
328320
// Perhaps sort the timers in descending order by amount of time taken.
329-
if (mtg::SortTimers())
321+
if (sortTimers())
330322
llvm::sort(TimersToPrint);
331323

332324
TimeRecord Total;
@@ -344,7 +336,7 @@ void TimerGroup::PrintQueuedTimers(raw_ostream &OS) {
344336
// If this is not an collection of ungrouped times, print the total time.
345337
// Ungrouped timers don't really make sense to add up. We still print the
346338
// TOTAL line to make the percentages make sense.
347-
if (this != &mtg::DefaultTimerGroup())
339+
if (this != &defaultTimerGroup())
348340
OS << format(" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n",
349341
Total.getProcessTime(), Total.getWallTime());
350342
OS << '\n';
@@ -396,7 +388,7 @@ void TimerGroup::prepareToPrintList(bool ResetTime) {
396388
void TimerGroup::print(raw_ostream &OS, bool ResetAfterPrint) {
397389
{
398390
// After preparing the timers we can free the lock
399-
sys::SmartScopedLock<true> L(mtg::TimerLock());
391+
sys::SmartScopedLock<true> L(timerLock());
400392
prepareToPrintList(ResetAfterPrint);
401393
}
402394

@@ -406,20 +398,20 @@ void TimerGroup::print(raw_ostream &OS, bool ResetAfterPrint) {
406398
}
407399

408400
void TimerGroup::clear() {
409-
sys::SmartScopedLock<true> L(mtg::TimerLock());
401+
sys::SmartScopedLock<true> L(timerLock());
410402
for (Timer *T = FirstTimer; T; T = T->Next)
411403
T->clear();
412404
}
413405

414406
void TimerGroup::printAll(raw_ostream &OS) {
415-
sys::SmartScopedLock<true> L(mtg::TimerLock());
407+
sys::SmartScopedLock<true> L(timerLock());
416408

417409
for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
418410
TG->print(OS);
419411
}
420412

421413
void TimerGroup::clearAll() {
422-
sys::SmartScopedLock<true> L(mtg::TimerLock());
414+
sys::SmartScopedLock<true> L(timerLock());
423415
for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
424416
TG->clear();
425417
}
@@ -436,7 +428,7 @@ void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R,
436428
}
437429

438430
const char *TimerGroup::printJSONValues(raw_ostream &OS, const char *delim) {
439-
sys::SmartScopedLock<true> L(mtg::TimerLock());
431+
sys::SmartScopedLock<true> L(timerLock());
440432

441433
prepareToPrintList(false);
442434
for (const PrintRecord &R : TimersToPrint) {
@@ -463,19 +455,19 @@ const char *TimerGroup::printJSONValues(raw_ostream &OS, const char *delim) {
463455
}
464456

465457
const char *TimerGroup::printAllJSONValues(raw_ostream &OS, const char *delim) {
466-
sys::SmartScopedLock<true> L(mtg::TimerLock());
458+
sys::SmartScopedLock<true> L(timerLock());
467459
for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
468460
delim = TG->printJSONValues(OS, delim);
469461
return delim;
470462
}
471463

472464
void TimerGroup::constructForStatistics() {
473-
mtg::LibSupportInfoOutputFilename();
474-
mtg::NamedGroupedTimers();
465+
libSupportInfoOutputFilename();
466+
namedGroupedTimers();
475467
}
476468

477469
std::unique_ptr<TimerGroup> TimerGroup::aquireDefaultGroup() {
478-
return std::unique_ptr<TimerGroup>(mtg::claimDefaultTimerGroup());
470+
return std::unique_ptr<TimerGroup>(claimDefaultTimerGroup());
479471
}
480472

481473
//===----------------------------------------------------------------------===//
@@ -505,7 +497,7 @@ class llvm::TimerGlobals {
505497

506498
private:
507499
// Order of these members and initialization below is important. For example
508-
// the DefaultTimerGroup uses the TimerLock. Most of these also depend on the
500+
// the defaultTimerGroup uses the timerLock. Most of these also depend on the
509501
// options above.
510502
std::once_flag InitDeferredFlag;
511503
std::unique_ptr<SignpostEmitter> SignpostsPtr;
@@ -524,15 +516,15 @@ class llvm::TimerGlobals {
524516
}
525517

526518
public:
527-
SignpostEmitter &Signposts() { return *initDeferred().SignpostsPtr; }
528-
sys::SmartMutex<true> &TimerLock() { return *initDeferred().TimerLockPtr; }
529-
TimerGroup &DefaultTimerGroup() {
519+
SignpostEmitter &signposts() { return *initDeferred().SignpostsPtr; }
520+
sys::SmartMutex<true> &timerLock() { return *initDeferred().TimerLockPtr; }
521+
TimerGroup &defaultTimerGroup() {
530522
return *initDeferred().DefaultTimerGroupPtr;
531523
}
532524
TimerGroup *claimDefaultTimerGroup() {
533525
return initDeferred().DefaultTimerGroupPtr.release();
534526
}
535-
Name2PairMap &NamedGroupedTimers() {
527+
Name2PairMap &namedGroupedTimers() {
536528
return *initDeferred().NamedGroupedTimersPtr;
537529
}
538530

@@ -556,26 +548,23 @@ class llvm::TimerGlobals {
556548

557549
static ManagedStatic<TimerGlobals> ManagedTimerGlobals;
558550

559-
static std::string &mtg::LibSupportInfoOutputFilename() {
551+
static std::string &libSupportInfoOutputFilename() {
560552
return ManagedTimerGlobals->LibSupportInfoOutputFilename;
561553
}
562-
static const std::string &mtg::InfoOutputFilename() {
563-
return ManagedTimerGlobals->InfoOutputFilename.getValue();
564-
}
565-
static bool mtg::TrackSpace() { return ManagedTimerGlobals->TrackSpace; }
566-
static bool mtg::SortTimers() { return ManagedTimerGlobals->SortTimers; }
567-
static SignpostEmitter &mtg::Signposts() {
568-
return ManagedTimerGlobals->Signposts();
554+
static bool trackSpace() { return ManagedTimerGlobals->TrackSpace; }
555+
static bool sortTimers() { return ManagedTimerGlobals->SortTimers; }
556+
static SignpostEmitter &signposts() { return ManagedTimerGlobals->signposts(); }
557+
static sys::SmartMutex<true> &timerLock() {
558+
return ManagedTimerGlobals->timerLock();
569559
}
570-
static sys::SmartMutex<true> &mtg::TimerLock() {
571-
return ManagedTimerGlobals->TimerLock();
560+
static TimerGroup &defaultTimerGroup() {
561+
return ManagedTimerGlobals->defaultTimerGroup();
572562
}
573-
static TimerGroup &mtg::DefaultTimerGroup() {
574-
return ManagedTimerGlobals->DefaultTimerGroup();
575-
}
576-
static TimerGroup *mtg::claimDefaultTimerGroup() {
563+
static TimerGroup *claimDefaultTimerGroup() {
577564
return ManagedTimerGlobals->claimDefaultTimerGroup();
578565
}
579-
static Name2PairMap &mtg::NamedGroupedTimers() {
580-
return ManagedTimerGlobals->NamedGroupedTimers();
566+
static Name2PairMap &namedGroupedTimers() {
567+
return ManagedTimerGlobals->namedGroupedTimers();
581568
}
569+
570+
void llvm::initTimerOptions() { *ManagedTimerGlobals; }

0 commit comments

Comments
 (0)