Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions llvm/include/llvm/CodeGen/ByteProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef LLVM_CODEGEN_BYTEPROVIDER_H
#define LLVM_CODEGEN_BYTEPROVIDER_H

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

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

// Only allow classes with member function getOpcode
template <typename U>
static auto test(int) -> decltype(std::declval<U>().getOpcode(), yes());

template <typename> static no test(...);

public:
using remove_pointer_t = typename std::remove_pointer<T>::type;
static constexpr bool value =
std::is_same<decltype(test<remove_pointer_t>(0)), yes>::value;
};
template <typename U>
static constexpr bool has_getOpcode =
is_detected<check_has_getOpcode, U>::value;

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

static ByteProvider getSrc(std::optional<ISelOp> Val, int64_t ByteOffset,
int64_t VectorOffset) {
static_assert(is_op<ISelOp>().value,
static_assert(has_getOpcode<ISelOp>,
"ByteProviders must contain an operation in selection DAG.");
return ByteProvider(Val, ByteOffset, VectorOffset);
}
Expand Down
Loading