[llvm] 5e812e9 - Revert "ManagedStatic: remove from DebugCounter"
Nicolai Hähnle via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 26 02:03:12 PDT 2022
Author: Nicolai Hähnle
Date: 2022-08-26T11:02:58+02:00
New Revision: 5e812e95804ae4d9aa1af46362203af18c1beaf7
URL: https://github.com/llvm/llvm-project/commit/5e812e95804ae4d9aa1af46362203af18c1beaf7
DIFF: https://github.com/llvm/llvm-project/commit/5e812e95804ae4d9aa1af46362203af18c1beaf7.diff
LOG: Revert "ManagedStatic: remove from DebugCounter"
This reverts commit b5b6ef1500af29b6aba71330d8aaf82ecccb1f37.
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 9fa4620ade3c8..cd9474a4d9184 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 26293bf92a42e..bc2df37e773d4 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,42 +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());
+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() {
- static DebugCounterOwner O;
- return O.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