aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/DebugCounter.cpp
diff options
context:
space:
mode:
authorMehdi Amini <joker.eph@gmail.com>2021-07-15 23:52:44 +0000
committerMehdi Amini <joker.eph@gmail.com>2021-07-16 03:33:20 +0000
commit42f588f39c5ce6f521e3709b8871d1fdd076292f (patch)
tree5ad9009fe09e82045e3a57cf39167e223ab00a27 /llvm/lib/Support/DebugCounter.cpp
parentb4c93ece8e4f6e98a15daca10c8a3db33cf8c195 (diff)
downloadllvm-42f588f39c5ce6f521e3709b8871d1fdd076292f.zip
llvm-42f588f39c5ce6f521e3709b8871d1fdd076292f.tar.gz
llvm-42f588f39c5ce6f521e3709b8871d1fdd076292f.tar.bz2
Use ManagedStatic and lazy initialization of cl::opt in libSupport to make it free of global initializer
We can build it with -Werror=global-constructors now. This helps in situation where libSupport is embedded as a shared library, potential with dlopen/dlclose scenario, and when command-line parsing or other facilities may not be involved. Avoiding the implicit construction of these cl::opt can avoid double-registration issues and other kind of behavior. Reviewed By: lattner, jpienaar Differential Revision: https://reviews.llvm.org/D105959
Diffstat (limited to 'llvm/lib/Support/DebugCounter.cpp')
-rw-r--r--llvm/lib/Support/DebugCounter.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/llvm/lib/Support/DebugCounter.cpp b/llvm/lib/Support/DebugCounter.cpp
index 7bb231c..f553463 100644
--- a/llvm/lib/Support/DebugCounter.cpp
+++ b/llvm/lib/Support/DebugCounter.cpp
@@ -1,4 +1,7 @@
#include "llvm/Support/DebugCounter.h"
+
+#include "DebugOptions.h"
+
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ManagedStatic.h"
@@ -40,17 +43,29 @@ private:
}
}
};
+
+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::ZeroOrMore,
+ cl::location(DebugCounter::instance()));
+ }
+};
} // namespace
-// Create our command line option.
-static DebugCounterList DebugCounterOption(
- "debug-counter", cl::Hidden,
- cl::desc("Comma separated list of debug counter skip and count"),
- cl::CommaSeparated, cl::ZeroOrMore, cl::location(DebugCounter::instance()));
+static ManagedStatic<DebugCounterList, CreateDebugCounterOption>
+ DebugCounterOption;
+static bool PrintDebugCounter;
-static 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"));
+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"));
+}
static ManagedStatic<DebugCounter> DC;