Skip to content

Commit 3eab094

Browse files
[CodeGen] Use llvm::is_detected (NFC) (#137561)
1 parent 89f3dc9 commit 3eab094

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

llvm/include/llvm/CodeGen/ByteProvider.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef LLVM_CODEGEN_BYTEPROVIDER_H
1818
#define LLVM_CODEGEN_BYTEPROVIDER_H
1919

20+
#include "llvm/ADT/STLExtras.h"
2021
#include "llvm/Support/DataTypes.h"
2122
#include <optional>
2223
#include <type_traits>
@@ -35,22 +36,14 @@ template <typename ISelOp> class ByteProvider {
3536

3637
// TODO -- use constraint in c++20
3738
// Does this type correspond with an operation in selection DAG
38-
template <typename T> class is_op {
39-
private:
40-
using yes = std::true_type;
41-
using no = std::false_type;
39+
// Only allow classes with member function getOpcode
40+
template <typename U>
41+
using check_has_getOpcode =
42+
decltype(std::declval<std::remove_pointer_t<U> &>().getOpcode());
4243

43-
// Only allow classes with member function getOpcode
44-
template <typename U>
45-
static auto test(int) -> decltype(std::declval<U>().getOpcode(), yes());
46-
47-
template <typename> static no test(...);
48-
49-
public:
50-
using remove_pointer_t = typename std::remove_pointer<T>::type;
51-
static constexpr bool value =
52-
std::is_same<decltype(test<remove_pointer_t>(0)), yes>::value;
53-
};
44+
template <typename U>
45+
static constexpr bool has_getOpcode =
46+
is_detected<check_has_getOpcode, U>::value;
5447

5548
public:
5649
// For constant zero providers Src is set to nullopt. For actual providers
@@ -66,7 +59,7 @@ template <typename ISelOp> class ByteProvider {
6659

6760
static ByteProvider getSrc(std::optional<ISelOp> Val, int64_t ByteOffset,
6861
int64_t VectorOffset) {
69-
static_assert(is_op<ISelOp>().value,
62+
static_assert(has_getOpcode<ISelOp>,
7063
"ByteProviders must contain an operation in selection DAG.");
7164
return ByteProvider(Val, ByteOffset, VectorOffset);
7265
}

0 commit comments

Comments
 (0)