[PATCH] D71228: [Commandline] Move Debug options from Debug.cpp to Commandline.cpp
Don Hinton via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 9 14:08:22 PST 2019
hintonda created this revision.
hintonda added reviewers: beanz, pete, MaskRay, serge-sans-paille.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
This patch moves Debug options into CommandLine.cpp so they are only
constructed if `parseCommandLineOptions` is actually called. This can
help in following cases:
1. libLLVMSupport gets linked in multiple times, e.g., a library and the final application, which will fail with an assert "Option 'X' registered more than once!" This is true whether or not `parseCommandLineOptions` is called in the final application.
2. Applications that don't call `parseCommandLineOptions` at all don't have to pay for constructing unused static Options -- the Debug options all use cl::location, so the option is only needed for parsing.
This patch depends on D71169 <https://reviews.llvm.org/D71169>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71228
Files:
llvm/lib/Support/CommandLine.cpp
llvm/lib/Support/Debug.cpp
Index: llvm/lib/Support/Debug.cpp
===================================================================
--- llvm/lib/Support/Debug.cpp
+++ llvm/lib/Support/Debug.cpp
@@ -42,7 +42,7 @@
/// Exported boolean set by the -debug option.
bool DebugFlag = false;
-static ManagedStatic<std::vector<std::string>> CurrentDebugType;
+ManagedStatic<std::vector<std::string>> CurrentDebugType;
/// Return true if the specified string is the debug type
/// specified on the command line, or if none was specified on the command line
@@ -79,29 +79,7 @@
// All Debug.h functionality is a no-op in NDEBUG mode.
#ifndef NDEBUG
-// -debug - Command line option to enable the DEBUG statements in the passes.
-// This flag may only be enabled in debug builds.
-static cl::opt<bool, true>
-Debug("debug", cl::desc("Enable debug output"), cl::Hidden,
- cl::location(DebugFlag));
-
-// -debug-buffer-size - Buffer the last N characters of debug output
-//until program termination.
-static cl::opt<unsigned>
-DebugBufferSize("debug-buffer-size",
- cl::desc("Buffer the last N characters of debug output "
- "until program termination. "
- "[default 0 -- immediate print-out]"),
- cl::Hidden,
- cl::init(0));
-
-static cl::list<std::string, ManagedStatic<std::vector<std::string>>>
- DebugOnly("debug-only",
- cl::desc("Enable a specific type of debug output (comma "
- "separated list of types)"),
- cl::Hidden, cl::ZeroOrMore, cl::value_desc("debug string"),
- cl::location(CurrentDebugType), cl::CommaSeparated,
- cl::callback([](const std::string &) { DebugFlag = true; }));
+unsigned DebugBufferSize = 0;
// Signal handlers - dump debug output on termination.
static void debug_user_sig_handler(void *Cookie) {
Index: llvm/lib/Support/CommandLine.cpp
===================================================================
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -2542,3 +2542,37 @@
llvm::cl::ParseCommandLineOptions(argc, argv, StringRef(Overview),
&llvm::nulls());
}
+
+// All Debug.h functionality is a no-op in NDEBUG mode.
+#ifndef NDEBUG
+
+namespace llvm {
+extern ManagedStatic<std::vector<std::string>> CurrentDebugType;
+}
+
+extern unsigned DebugBufferSize;
+
+// -debug - Command line option to enable the DEBUG statements in the passes.
+// This flag may only be enabled in debug builds.
+static cl::opt<bool, true> Debug("debug", cl::desc("Enable debug output"),
+ cl::Hidden, cl::location(DebugFlag));
+
+// -debug-buffer-size - Buffer the last N characters of debug output
+// until program termination.
+static cl::opt<unsigned, true>
+ DebugBufferSizeOpt("debug-buffer-size",
+ cl::desc("Buffer the last N characters of debug output "
+ "until program termination. "
+ "[default 0 -- immediate print-out]"),
+ cl::Hidden,
+ cl::location(DebugBufferSize));
+
+static cl::list<std::string, ManagedStatic<std::vector<std::string>>>
+ DebugOnly("debug-only",
+ cl::desc("Enable a specific type of debug output (comma "
+ "separated list of types)"),
+ cl::Hidden, cl::ZeroOrMore, cl::value_desc("debug string"),
+ cl::location(CurrentDebugType), cl::CommaSeparated,
+ cl::callback([](const std::string &) { DebugFlag = true; }));
+
+#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71228.232942.patch
Type: text/x-patch
Size: 3636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191209/b4035d98/attachment.bin>
More information about the llvm-commits
mailing list