[llvm] [AMDGPU] Simplify GetMember...::Get (NFC) (PR #137536)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 27 11:13:00 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/137536
We can use "constexpr if" to combine the two variants of functions.
>From 0359aedd53838e52351fb0066c5af76182a33517 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 27 Apr 2025 10:56:44 -0700
Subject: [PATCH] [AMDGPU] Simplify GetMember...::Get (NFC)
We can use "constexpr if" to combine the two variants of functions.
---
.../AMDGPU/Utils/AMDKernelCodeTUtils.cpp | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
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;
More information about the llvm-commits
mailing list