16 #ifndef LLVM_ADT_ANY_H 17 #define LLVM_ADT_ANY_H 23 #include <type_traits> 28 template <
typename T>
struct TypeId {
static const char Id; };
31 virtual ~StorageBase() =
default;
32 virtual std::unique_ptr<StorageBase> clone()
const = 0;
33 virtual const void *id()
const = 0;
36 template <
typename T>
struct StorageImpl :
public StorageBase {
37 explicit StorageImpl(
const T &
Value) : Value(Value) {}
39 explicit StorageImpl(
T &&Value) : Value(std::move(Value)) {}
41 std::unique_ptr<StorageBase> clone()
const override {
42 return llvm::make_unique<StorageImpl<T>>(Value);
51 StorageImpl(
const StorageImpl &Other) =
delete;
58 : Storage(Other.Storage ? Other.Storage->clone() : nullptr) {}
65 typename std::enable_if<
68 std::is_copy_constructible<typename std::decay<T>::type>>::value,
71 using U =
typename std::decay<T>::type;
72 Storage = llvm::make_unique<StorageImpl<U>>(std::forward<T>(
Value));
83 Storage = std::move(Other.Storage);
89 void reset() { Storage.reset(); }
93 template <
class T>
friend T any_cast(Any &Value);
94 template <
class T>
friend T any_cast(Any &&Value);
95 template <
class T>
friend const T *
any_cast(
const Any *Value);
96 template <
class T>
friend T *
any_cast(Any *Value);
97 template <
typename T>
friend bool any_isa(
const Any &Value);
99 std::unique_ptr<StorageBase> Storage;
109 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
115 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
116 return static_cast<T>(*
any_cast<U>(&Value));
121 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
122 return static_cast<T>(*
any_cast<U>(&Value));
127 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
128 return static_cast<T>(std::move(*any_cast<U>(&
Value)));
133 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
134 assert(Value && any_isa<T>(*Value) &&
"Bad any cast!");
135 if (!Value || !any_isa<U>(*Value))
137 return &
static_cast<Any::StorageImpl<U> &
>(*Value->Storage).Value;
141 using U =
typename std::decay<T>::type;
142 assert(Value && any_isa<U>(*Value) &&
"Bad any cast!");
143 if (!Value || !any_isa<U>(*Value))
145 return &
static_cast<Any::StorageImpl<U> &
>(*Value->Storage).Value;
150 #endif // LLVM_ADT_ANY_H Any & operator=(Any Other)
Compute iterated dominance frontiers using a linear time algorithm.
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.