Skip to content

Commit 854df54

Browse files
authored
[Support] Optimize DebugCounter hot path (NFC) (#170260)
When enabling ShouldPrintCounter, also set Enabled, so that we only have to check one of them. This cuts down the cost of (disabled) debug counters by half.
1 parent 5a32fd3 commit 854df54

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/include/llvm/Support/DebugCounter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class DebugCounter {
158158
#ifdef NDEBUG
159159
return false;
160160
#else
161-
return instance().Enabled || instance().ShouldPrintCounter;
161+
return instance().Enabled;
162162
#endif
163163
}
164164

llvm/lib/Support/DebugCounter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ struct DebugCounterOwner : DebugCounter {
135135
cl::Optional,
136136
cl::location(this->ShouldPrintCounter),
137137
cl::init(false),
138-
cl::desc("Print out debug counter info after all counters accumulated")};
138+
cl::desc("Print out debug counter info after all counters accumulated"),
139+
cl::callback([&](const bool &Value) {
140+
if (Value)
141+
enableAllCounters();
142+
})};
139143
cl::opt<bool, true> PrintDebugCounterQueries{
140144
"print-debug-counter-queries",
141145
cl::Hidden,

0 commit comments

Comments
 (0)