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
5548public:
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