Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

We can use "constexpr if" to combine the two variants of functions.

We can use "constexpr if" to combine the two variants of functions.
@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Kazu Hirata (kazutakahirata)

Changes

We can use "constexpr if" to combine the two variants of functions.


Full diff: https://github.com/llvm/llvm-project/pull/137536.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp (+8-11)
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp
index 8997911aa8ae1..ec6bede1a693d 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp
@@ -72,17 +72,14 @@ using namespace llvm::AMDGPU;
   class GetMember##member {                                                    \
   public:                                                                      \
     static const MCExpr *Phony;                                                \
-    template <typename U, typename std::enable_if_t<IsMCExpr##member::RESULT,  \
-                                                    U> * = nullptr>            \
-    static const MCExpr *&Get(U &C) {                                          \
-      assert(IsMCExpr##member::RESULT &&                                       \
-             "Trying to retrieve member that does not exist.");                \
-      return C.member;                                                         \
-    }                                                                          \
-    template <typename U, typename std::enable_if_t<!IsMCExpr##member::RESULT, \
-                                                    U> * = nullptr>            \
-    static const MCExpr *&Get(U &C) {                                          \
-      return Phony;                                                            \
+    template <typename U> static const MCExpr *&Get(U &C) {                    \
+      if constexpr (IsMCExpr##member::RESULT) {                                \
+        assert(IsMCExpr##member::RESULT &&                                     \
+               "Trying to retrieve member that does not exist.");              \
+        return C.member;                                                       \
+      } else {                                                                 \
+        return Phony;                                                          \
+      }                                                                        \
     }                                                                          \
   };                                                                           \
   const MCExpr *GetMember##member::Phony = nullptr;

@kazutakahirata kazutakahirata merged commit fcd0664 into llvm:main Apr 27, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_constexpr_if_llvm_AMDGPU branch April 27, 2025 21:13
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
We can use "constexpr if" to combine the two variants of functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants