[llvm] fcd0664 - [AMDGPU] Simplify GetMember...::Get (NFC) (#137536)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 27 14:09:19 PDT 2025


Author: Kazu Hirata
Date: 2025-04-27T14:09:16-07:00
New Revision: fcd066412624a80ef2bacbe83c5aef99240083e2

URL: https://github.com/llvm/llvm-project/commit/fcd066412624a80ef2bacbe83c5aef99240083e2
DIFF: https://github.com/llvm/llvm-project/commit/fcd066412624a80ef2bacbe83c5aef99240083e2.diff

LOG: [AMDGPU] Simplify GetMember...::Get (NFC) (#137536)

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

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp
index 8997911aa8ae1..0f4edd000d495 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp
@@ -72,17 +72,11 @@ 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)                                  \
+        return C.member;                                                       \
+      else                                                                     \
+        return Phony;                                                          \
     }                                                                          \
   };                                                                           \
   const MCExpr *GetMember##member::Phony = nullptr;


        


More information about the llvm-commits mailing list