[llvm] a0a2ddf - Revert "ManagedStatic: remove from DebugCounter"

Nicolai Hähnle via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 25 10:45:32 PDT 2022


Author: Nicolai Hähnle
Date: 2022-08-25T19:45:04+02:00
New Revision: a0a2ddfcc5cdd3488c5e67f461ac8e04264ab8f8

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

LOG: Revert "ManagedStatic: remove from DebugCounter"

This reverts commit 51d82502d98d3c5d60606e63b6c23bb5759fdb91.

There is a regression in the flang-aarch64-dylib buildbot which is most
likely caused by this change. Reverting until I can investigate.

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 9fa4620ade3c..cd9474a4d918 100644
--- a/llvm/include/llvm/Support/DebugCounter.h
+++ b/llvm/include/llvm/Support/DebugCounter.h
@@ -55,6 +55,8 @@ class raw_ostream;
 
 class DebugCounter {
 public:
+  ~DebugCounter();
+
   /// Returns a reference to the singleton instance.
   static DebugCounter &instance();
 
@@ -147,6 +149,7 @@ class DebugCounter {
   // contexts where we're certain we won't spawn threads.
   static void enableAllCounters() { instance().Enabled = true; }
 
+private:
   static bool isCountingEnabled() {
 // Compile to nothing when debugging is off
 #ifdef NDEBUG
@@ -156,7 +159,6 @@ class DebugCounter {
 #endif
   }
 
-private:
   unsigned addCounter(const std::string &Name, const std::string &Desc) {
     unsigned Result = RegisteredCounters.insert(Name);
     Counters[Result] = {};

diff  --git a/llvm/lib/Support/DebugCounter.cpp b/llvm/lib/Support/DebugCounter.cpp
index 5f29d8967ff3..bc2df37e773d 100644
--- a/llvm/lib/Support/DebugCounter.cpp
+++ b/llvm/lib/Support/DebugCounter.cpp
@@ -4,6 +4,7 @@
 
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/ManagedStatic.h"
 
 using namespace llvm;
 
@@ -43,46 +44,38 @@ class DebugCounterList : public cl::list<std::string, DebugCounter> {
   }
 };
 
-// All global objects associated to the DebugCounter, including the DebugCounter
-// itself, are owned by a single global instance of the DebugCounterOwner
-// struct. This makes it easier to control the order in which constructors and
-// destructors are run.
-struct DebugCounterOwner {
-  DebugCounter DC;
-  DebugCounterList DebugCounterOption{
-      "debug-counter", cl::Hidden,
-      cl::desc("Comma separated list of debug counter skip and count"),
-      cl::CommaSeparated, cl::location(DC)};
-  cl::opt<bool> PrintDebugCounter{
-      "print-debug-counter", cl::Hidden, cl::init(false), cl::Optional,
-      cl::desc("Print out debug counter info after all counters accumulated")};
-
-  DebugCounterOwner() {
-    // Our destructor uses the debug stream. By referencing it here, we
-    // ensure that its destructor runs after our destructor.
-    (void)dbgs();
-  }
-
-  // Print information when destroyed, iff command line option is specified.
-  ~DebugCounterOwner() {
-    if (DC.isCountingEnabled() && PrintDebugCounter)
-      DC.print(dbgs());
-  }
-
-  static DebugCounterOwner &instance() {
-    static DebugCounterOwner O;
-    return O;
+struct CreateDebugCounterOption {
+  static void *call() {
+    return new DebugCounterList(
+        "debug-counter", cl::Hidden,
+        cl::desc("Comma separated list of debug counter skip and count"),
+        cl::CommaSeparated, cl::location(DebugCounter::instance()));
   }
 };
+} // namespace
+
+static ManagedStatic<DebugCounterList, CreateDebugCounterOption>
+    DebugCounterOption;
+static bool PrintDebugCounter;
+
+void llvm::initDebugCounterOptions() {
+  *DebugCounterOption;
+  static cl::opt<bool, true> RegisterPrintDebugCounter(
+      "print-debug-counter", cl::Hidden, cl::location(PrintDebugCounter),
+      cl::init(false), cl::Optional,
+      cl::desc("Print out debug counter info after all counters accumulated"));
+}
 
-} // anonymous namespace
-
-void llvm::initDebugCounterOptions() { (void)DebugCounter::instance(); }
+static ManagedStatic<DebugCounter> DC;
 
-DebugCounter &DebugCounter::instance() {
-  return DebugCounterOwner::instance().DC;
+// Print information when destroyed, iff command line option is specified.
+DebugCounter::~DebugCounter() {
+  if (isCountingEnabled() && PrintDebugCounter)
+    print(dbgs());
 }
 
+DebugCounter &DebugCounter::instance() { return *DC; }
+
 // This is called by the command line parser when it sees a value for the
 // debug-counter option defined above.
 void DebugCounter::push_back(const std::string &Val) {


        


More information about the llvm-commits mailing list