[llvm] [OpenMP][Offload] Continue to update libomptarget debug messages (PR #170425)

Michael Klemm via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 8 05:47:05 PST 2025


================
@@ -430,6 +430,60 @@ static inline raw_ostream &operator<<(raw_ostream &Os,
 #define ODBG_RESET_LEVEL()                                                     \
   static_cast<llvm::offload::debug::odbg_ostream::IfLevel>(0)
 
+// helper templates to support lambdas with different number of arguments
+
+template <typename LambdaTy> struct lambdaHelper {
+  template <typename FuncTy, typename RetTy, typename... Args>
+  static constexpr size_t CountArgs(RetTy (FuncTy::*)(Args...)) {
+    return sizeof...(Args);
+  }
+
+  template <typename FuncTy, typename RetTy, typename... Args>
+  static constexpr size_t CountArgs(RetTy (FuncTy::*)(Args...) const) {
+    return sizeof...(Args);
+  }
+
+  static constexpr size_t NArgs = CountArgs(&LambdaTy::operator());
+
+  static void dispatch(LambdaTy func, llvm::raw_ostream &Os, uint32_t Level) {
+    if constexpr (NArgs == 1)
+      func(Os);
+    else if constexpr (NArgs == 2)
+      func(Os, Level);
+    else
+      static_assert(true, "Unsupported number of arguments in debug callback");
+  }
+};
----------------
mjklemm wrote:

Is all this plumbing needed to have lamda functions with 1 or 2 parameters?  For just 1 or 2 to seems like we could use a simpler solution.

https://github.com/llvm/llvm-project/pull/170425


More information about the llvm-commits mailing list