14 #ifndef LLVM_ADT_POINTERUNION_H 15 #define LLVM_ADT_POINTERUNION_H 39 template <
typename T1,
typename T2,
typename RET_EQ,
typename RET_NE>
44 template <
typename T,
typename RET_EQ,
typename RET_NE>
49 template <
typename T1,
typename T2,
typename RET_EQ,
typename RET_NE>
56 namespace pointer_union_detail {
71 template <
typename T,
typename ...Us>
struct TypeIndex<
T,
T, Us...> {
74 template <
typename T,
typename U,
typename... Us>
99 return static_cast<Derived &
>(*this) = Derived(t);
103 template <
typename Derived,
typename ValTy,
int I,
typename ...Types>
106 template <
typename Derived,
typename ValTy,
int I>
116 template <
typename Derived,
typename ValTy,
int I,
typename Type,
125 : Base(ValTy(const_cast<void *>(
129 using Base::operator=;
134 return static_cast<Derived &
>(*this);
155 template <
typename... PTs>
158 PointerUnion<PTs...>,
160 void *, pointer_union_detail::bitsRequired(sizeof...(PTs)), int,
161 pointer_union_detail::PointerUnionUIntTraits<PTs...>>,
169 using Base =
typename PointerUnion::PointerUnionMembers;
179 bool isNull()
const {
return !this->Val.getPointer(); }
181 explicit operator bool()
const {
return !isNull(); }
184 template <
typename T>
int is()
const {
186 static_assert(Index <
sizeof...(PTs),
187 "PointerUnion::is<T> given type not in the union");
188 return this->Val.getInt() ==
Index;
194 template <
typename T>
T get()
const {
195 assert(is<T>() &&
"Invalid accessor called");
210 return const_cast<PointerUnion *
>(
this)->getAddrOfPtr1();
216 assert(is<First>() &&
"Val is not the first pointer");
219 this->Val.getPointer() &&
220 "Can't get the address because PointerLikeTypeTraits changes the ptr");
221 return const_cast<First *
>(
222 reinterpret_cast<const First *
>(this->Val.getAddrOfPointer()));
227 this->Val.initWithPointer(
nullptr);
232 using Base::operator=;
237 V.Val = decltype(V.Val)::getFromOpaqueValue(VP);
242 template <
typename ...PTs>
247 template <
typename ...PTs>
252 template <
typename ...PTs>
259 template <
typename ...PTs>
284 return Union(FirstInfo::getTombstoneKey());
299 #endif // LLVM_ADT_POINTERUNION_H
First const * getAddrOfPtr1() const
If the union is set to the first pointer type get an address pointing to it.
static Union getEmptyKey()
This class represents lattice values for constants.
static Union getTombstoneKey()
constexpr int bitsRequired(unsigned n)
Determine the number of bits required to store integers with values < n.
constexpr int lowBitsAvailable()
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwises returns null...
typename PointerUnionTypeSelectorReturn< RET_EQ >::Return Return
static void * getAsVoidPointer(const PointerUnion< PTs... > &P)
Get a type based on whether two types are the same or not.
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
static unsigned getHashValue(const Union &UnionVal)
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
typename PointerUnionTypeSelector< T1, T2, RET_EQ, RET_NE >::Return Return
static void * getAsVoidPointer(void *P)
PointerUnion(std::nullptr_t)
Derived & operator=(Type V)
typename PointerUnionTypeSelectorReturn< RET_NE >::Return Return
const PointerUnion & operator=(std::nullptr_t)
Assignment from nullptr which just clears the union.
First * getAddrOfPtr1()
If the union is set to the first pointer type get an address pointing to it.
Find the index of a type in a list of types.
Provide PointerLikeTypeTraits for void* that is used by PointerUnion for the template arguments...
PointerUnionMembers(ValTy Val)
static bool isEqual(const Union &LHS, const Union &RHS)
bool operator!=(uint64_t V1, const APInt &V2)
int is() const
Test if the Union currently holds the type matching T.
static PointerUnion< PTs... > getFromVoidPointer(void *P)
static PointerUnion getFromOpaqueValue(void *VP)
Implement assignment in terms of construction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
PointerUnionMembers(Type V)
Find the first type in a list of types.
static void * getFromVoidPointer(void *P)
bool operator==(uint64_t V1, const APInt &V2)
void * getOpaqueValue() const
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...