[llvm] 854df54 - [Support] Optimize DebugCounter hot path (NFC) (#170260)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 2 06:53:31 PST 2025


Author: Nikita Popov
Date: 2025-12-02T15:53:26+01:00
New Revision: 854df547a023715bb6229d410d0699be2d3c3d04

URL: https://github.com/llvm/llvm-project/commit/854df547a023715bb6229d410d0699be2d3c3d04
DIFF: https://github.com/llvm/llvm-project/commit/854df547a023715bb6229d410d0699be2d3c3d04.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/include/llvm/Support/DebugCounter.h
    llvm/lib/Support/DebugCounter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/DebugCounter.h b/llvm/include/llvm/Support/DebugCounter.h
index 9904a0dd86559..028653224e62b 100644
--- a/llvm/include/llvm/Support/DebugCounter.h
+++ b/llvm/include/llvm/Support/DebugCounter.h
@@ -158,7 +158,7 @@ class DebugCounter {
 #ifdef NDEBUG
     return false;
 #else
-    return instance().Enabled || instance().ShouldPrintCounter;
+    return instance().Enabled;
 #endif
   }
 

diff  --git a/llvm/lib/Support/DebugCounter.cpp b/llvm/lib/Support/DebugCounter.cpp
index 5ab1def43313b..7fb841780ae2f 100644
--- a/llvm/lib/Support/DebugCounter.cpp
+++ b/llvm/lib/Support/DebugCounter.cpp
@@ -135,7 +135,11 @@ struct DebugCounterOwner : DebugCounter {
       cl::Optional,
       cl::location(this->ShouldPrintCounter),
       cl::init(false),
-      cl::desc("Print out debug counter info after all counters accumulated")};
+      cl::desc("Print out debug counter info after all counters accumulated"),
+      cl::callback([&](const bool &Value) {
+        if (Value)
+          enableAllCounters();
+      })};
   cl::opt<bool, true> PrintDebugCounterQueries{
       "print-debug-counter-queries",
       cl::Hidden,


        


More information about the llvm-commits mailing list