[llvm] [Offload] Enable more refined debug printing (PR #163431)
Alex Duran via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 14 12:54:41 PDT 2025
================
@@ -75,17 +108,49 @@ inline std::atomic<uint32_t> &getInfoLevelInternal() {
inline uint32_t getInfoLevel() { return getInfoLevelInternal().load(); }
-inline uint32_t getDebugLevel() {
- static uint32_t DebugLevel = 0;
- static std::once_flag Flag{};
- std::call_once(Flag, []() {
- if (char *EnvStr = getenv("LIBOMPTARGET_DEBUG"))
- DebugLevel = std::stoi(EnvStr);
- });
-
- return DebugLevel;
+inline DebugOptionTy &getDebugOption() {
+ static DebugOptionTy DebugOption = []() {
+ DebugOptionTy OptVal{0, 0};
+ char *EnvStr = getenv("LIBOMPTARGET_DEBUG");
+ if (!EnvStr || *EnvStr == '0')
+ return OptVal; // undefined or explicitly defined as zero
+ OptVal.Level = std::atoi(EnvStr);
+ if (OptVal.Level)
+ return OptVal; // defined as numeric value
+ // Check string value of the option
+ std::istringstream Tokens(EnvStr);
+ for (std::string Token; std::getline(Tokens, Token, ',');) {
+ if (Token == "rtl")
+ OptVal.Type |= DEBUG_INFOTYPE_RTL;
+ else if (Token == "device")
+ OptVal.Type |= DEBUG_INFOTYPE_DEVICE;
+ else if (Token == "module")
+ OptVal.Type |= DEBUG_INFOTYPE_MODULE;
+ else if (Token == "kernel")
+ OptVal.Type |= DEBUG_INFOTYPE_KERNEL;
+ else if (Token == "memory")
+ OptVal.Type |= DEBUG_INFOTYPE_MEMORY;
+ else if (Token == "map")
+ OptVal.Type |= DEBUG_INFOTYPE_MAP;
+ else if (Token == "copy")
+ OptVal.Type |= DEBUG_INFOTYPE_COPY;
+ else if (Token == "interop")
+ OptVal.Type |= DEBUG_INFOTYPE_INTEROP;
+ else if (Token == "tool")
+ OptVal.Type |= DEBUG_INFOTYPE_TOOL;
+ else if (Token == "api")
+ OptVal.Type |= DEBUG_INFOTYPE_API;
+ else if (Token == "all")
+ OptVal.Type |= DEBUG_INFOTYPE_ALL;
----------------
adurang wrote:
nit: could we make this a table lookup instead of a giant if-else-if'?
https://github.com/llvm/llvm-project/pull/163431
More information about the llvm-commits
mailing list