15 #ifndef LLVM_ADT_ANY_H 16 #define LLVM_ADT_ANY_H 22 #include <type_traits> 27 template <
typename T>
struct TypeId {
static const char Id; };
30 virtual ~StorageBase() =
default;
31 virtual std::unique_ptr<StorageBase> clone()
const = 0;
32 virtual const void *id()
const = 0;
35 template <
typename T>
struct StorageImpl :
public StorageBase {
36 explicit StorageImpl(
const T &
Value) :
Value(Value) {}
38 explicit StorageImpl(
T &&Value) :
Value(std::move(Value)) {}
40 std::unique_ptr<StorageBase> clone()
const override {
41 return std::make_unique<StorageImpl<T>>(
Value);
50 StorageImpl(
const StorageImpl &Other) =
delete;
57 : Storage(Other.Storage ? Other.Storage->clone() : nullptr) {}
64 typename std::enable_if<
77 std::is_copy_constructible<typename std::decay<T>::type>>::value,
80 using U =
typename std::decay<T>::type;
81 Storage = std::make_unique<StorageImpl<U>>(std::forward<T>(
Value));
92 Storage = std::move(Other.Storage);
98 void reset() { Storage.reset(); }
102 template <
class T>
friend T any_cast(Any &Value);
103 template <
class T>
friend T any_cast(Any &&Value);
104 template <
class T>
friend const T *
any_cast(
const Any *Value);
105 template <
class T>
friend T *
any_cast(Any *Value);
106 template <
typename T>
friend bool any_isa(
const Any &Value);
108 std::unique_ptr<StorageBase> Storage;
118 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
124 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
130 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
136 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
137 return static_cast<T>(std::move(*any_cast<U>(&
Value)));
142 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
143 assert(Value && any_isa<T>(*Value) &&
"Bad any cast!");
144 if (!Value || !any_isa<U>(*Value))
146 return &
static_cast<Any::StorageImpl<U> &
>(*Value->Storage).Value;
150 using U =
typename std::decay<T>::type;
151 assert(Value && any_isa<U>(*Value) &&
"Bad any cast!");
152 if (!Value || !any_isa<U>(*Value))
154 return &
static_cast<Any::StorageImpl<U> &
>(*Value->Storage).Value;
159 #endif // LLVM_ADT_ANY_H Any & operator=(Any Other)
This class represents lattice values for constants.
friend bool any_isa(const Any &Value)
friend T any_cast(const Any &Value)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.