[llvm] Introduce a "log level" support for DEBUG_TYPE (PR #150855)
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 27 15:14:06 PDT 2025
================
@@ -38,25 +40,46 @@
using namespace llvm;
+/// Parse a debug type string into a pair of the debug type and the debug level.
+/// The expected format is "type[:level]", where the level is an optional
+/// integer.
+static std::pair<std::string, int> parseDebugType(StringRef DbgType) {
+ auto [Type, LevelStr] = DbgType.split(':');
+ int Level;
+ if (!to_integer(LevelStr, Level, 10))
+ Level = 0;
+ return std::make_pair(Type.str(), Level);
+}
+
// Even though LLVM might be built with NDEBUG, define symbols that the code
// built without NDEBUG can depend on via the llvm/Support/Debug.h header.
namespace llvm {
/// Exported boolean set by the -debug option.
bool DebugFlag = false;
-static ManagedStatic<std::vector<std::string>> CurrentDebugType;
+/// The current debug type and an optional debug level.
+/// The debug level is the verbosity of the debug output.
+/// The default level is 0, which is the most verbose.
+/// The level can be set to 1, 2, 3, etc. to control the verbosity of the
+/// output. The level can be set to -1 to disable the output.
+static ManagedStatic<std::vector<std::pair<std::string, int>>> 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
/// with the -debug-only=X option.
-bool isCurrentDebugType(const char *DebugType) {
+bool isCurrentDebugType(const char *DebugType, int Level) {
if (CurrentDebugType->empty())
return true;
// See if DebugType is in list. Note: do not use find() as that forces us to
// unnecessarily create an std::string instance.
for (auto &d : *CurrentDebugType) {
- if (d == DebugType)
- return true;
+ if (d.first == DebugType) {
+ if (d.second < 0)
+ return false;
+ if (d.second == 0)
+ return true;
+ return d.second >= Level;
----------------
joker-eph wrote:
This is the exact same thing, you're hallucinating.
https://github.com/llvm/llvm-project/pull/150855
More information about the llvm-commits
mailing list