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

Alex Duran via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 9 08:11:45 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");
+  }
+};
----------------
adurang wrote:

Other than duplicating all the macros to have a version with 2 parameters I'm not sure how much can be simplified (but my C++ is limited so maybe there's a way).

This is a bit simpler I guess but not sure if worth to remove the generality to add further arguments at some point. Is this better?

```
 template <typename T, typename = std::void_t<>>
  struct has_two_args : std::false_type {};
  template <typename T>
  struct has_two_args<T, std::void_t<decltype(std::declval<T>().operator()(1,2))>>
      : std::true_type {};

  static void dispatch(LambdaTy func, llvm::raw_ostream &Os, uint32_t Level) {
    if constexpr (has_two_args<LambdaTy>::value)
      func(Os, Level);
    else 
      func(Os);
  }
```



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


More information about the llvm-commits mailing list