Skip to content

Commit 3e6ee89

Browse files
[AMDGPU] Simplify template metaprogramming in IsMCExpr##member (NFC) (#160005)
Without this patch, we compute a type trait in a roundabout manner: - Compute a boolean value in the primary template. - Pass the value to std::enable_if_t. - Return std::true_type (or std::false_type on the fallback path). - Compare the return type to std::true_type. That is, when the expression for the first boolean value above is well formed, we already have the answer we are looking for. This patch bypasses the entire sequence by having the primary template return std::bool_constant and adjusting RESULT to extract the ::value of the boolean type.
1 parent 7bf39a5 commit 3e6ee89

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,15 @@ using namespace llvm::AMDGPU;
5656
std::true_type>; \
5757
}; \
5858
class IsMCExpr##member { \
59-
template <typename U, \
60-
typename std::enable_if_t< \
61-
HasMember##member::RESULT && \
62-
std::is_same_v<decltype(U::member), const MCExpr *>, \
63-
U> * = nullptr> \
64-
static constexpr std::true_type HasMCExprType(decltype(U::member) *); \
59+
template <typename U> \
60+
static constexpr auto HasMCExprType(int) -> std::bool_constant< \
61+
HasMember##member::RESULT && \
62+
std::is_same_v<decltype(U::member), const MCExpr *>>; \
6563
template <typename U> static constexpr std::false_type HasMCExprType(...); \
6664
\
6765
public: \
6866
static constexpr bool RESULT = \
69-
std::is_same_v<decltype(HasMCExprType<AMDGPUMCKernelCodeT>(nullptr)), \
70-
std::true_type>; \
67+
decltype(HasMCExprType<AMDGPUMCKernelCodeT>(0))::value; \
7168
}; \
7269
class GetMember##member { \
7370
public: \

0 commit comments

Comments
 (0)