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<
78 std::is_copy_constructible<typename std::decay<T>::type>>::value,
81 using U =
typename std::decay<T>::type;
82 Storage = llvm::make_unique<StorageImpl<U>>(std::forward<T>(
Value));
93 Storage = std::move(Other.Storage);
99 void reset() { Storage.reset(); }
103 template <
class T>
friend T any_cast(Any &Value);
104 template <
class T>
friend T any_cast(Any &&Value);
105 template <
class T>
friend const T *
any_cast(
const Any *Value);
106 template <
class T>
friend T *
any_cast(Any *Value);
107 template <
typename T>
friend bool any_isa(
const Any &Value);
109 std::unique_ptr<StorageBase> Storage;
119 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
125 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
126 return static_cast<T>(*
any_cast<U>(&Value));
131 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
132 return static_cast<T>(*
any_cast<U>(&Value));
137 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
138 return static_cast<T>(std::move(*any_cast<U>(&
Value)));
143 typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
144 assert(Value && any_isa<T>(*Value) &&
"Bad any cast!");
145 if (!Value || !any_isa<U>(*Value))
147 return &
static_cast<Any::StorageImpl<U> &
>(*Value->Storage).Value;
151 using U =
typename std::decay<T>::type;
152 assert(Value && any_isa<U>(*Value) &&
"Bad any cast!");
153 if (!Value || !any_isa<U>(*Value))
155 return &
static_cast<Any::StorageImpl<U> &
>(*Value->Storage).Value;
160 #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.