17
17
#ifndef LLVM_CODEGEN_BYTEPROVIDER_H
18
18
#define LLVM_CODEGEN_BYTEPROVIDER_H
19
19
20
+ #include " llvm/ADT/STLExtras.h"
20
21
#include " llvm/Support/DataTypes.h"
21
22
#include < optional>
22
23
#include < type_traits>
@@ -35,22 +36,14 @@ template <typename ISelOp> class ByteProvider {
35
36
36
37
// TODO -- use constraint in c++20
37
38
// 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()) ;
42
43
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;
54
47
55
48
public:
56
49
// For constant zero providers Src is set to nullopt. For actual providers
@@ -66,7 +59,7 @@ template <typename ISelOp> class ByteProvider {
66
59
67
60
static ByteProvider getSrc (std::optional<ISelOp> Val, int64_t ByteOffset,
68
61
int64_t VectorOffset) {
69
- static_assert (is_op <ISelOp>(). value ,
62
+ static_assert (has_getOpcode <ISelOp>,
70
63
" ByteProviders must contain an operation in selection DAG." );
71
64
return ByteProvider (Val, ByteOffset, VectorOffset);
72
65
}
0 commit comments