15#ifndef LLVM_ADT_POINTERUNION_H
16#define LLVM_ADT_POINTERUNION_H
30namespace pointer_union_detail {
55 template <
typename Derived,
typename ValTy,
int I,
typename ...Types>
58 template <
typename Derived,
typename ValTy,
int I>
68 template <
typename Derived,
typename ValTy,
int I,
typename Type,
77 :
Base(ValTy(const_cast<void *>(
81 using Base::operator=;
86 return static_cast<Derived &
>(*this);
93template <
typename... PTs>
struct CastInfoPointerUnionImpl;
111template <
typename... PTs>
114 PointerUnion<PTs...>,
116 void *, pointer_union_detail::bitsRequired(sizeof...(PTs)), int,
117 pointer_union_detail::PointerUnionUIntTraits<PTs...>>,
120 "PointerUnion alternative types cannot be repeated");
127 using Base =
typename PointerUnion::PointerUnionMembers;
142 bool isNull()
const {
return !this->Val.getPointer(); }
150 template <
typename T>
inline bool is()
const {
return isa<T>(*
this); }
155 template <
typename T>
inline T get()
const {
156 assert(isa<T>(*
this) &&
"Invalid accessor called");
157 return cast<T>(*
this);
163 return llvm::dyn_cast_if_present<T>(*
this);
175 assert(isa<First>(*
this) &&
"Val is not the first pointer");
178 this->Val.getPointer() &&
179 "Can't get the address because PointerLikeTypeTraits changes the ptr");
180 return const_cast<First *
>(
181 reinterpret_cast<const First *
>(this->Val.getAddrOfPointer()));
186 this->Val.initWithPointer(
nullptr);
191 using Base::operator=;
201template <
typename ...PTs>
206template <
typename ...PTs>
211template <
typename ...PTs>
234 assert(isPossible<To>(
F) &&
"cast to an incompatible type!");
240template <
typename To,
typename... PTs>
243 CastInfo<To, PointerUnion<PTs...>>> {
248 return Impl::template isPossible<To>(f);
251 static To
doCast(
From &f) {
return Impl::template doCast<To>(f); }
256template <
typename To,
typename... PTs>
259 CastInfo<To, PointerUnion<PTs...>>> {
264template <
typename ...PTs>
267 return P.getOpaqueValue();
289 return Union(FirstInfo::getTombstoneKey());
Given that RA is a live value
This file defines DenseMapInfo traits for DenseMap.
This file defines the PointerIntPair class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
T get() const
Returns the value of the specified pointer type.
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
First const * getAddrOfPtr1() const
If the union is set to the first pointer type get an address pointing to it.
bool is() const
Test if the Union currently holds the type matching T.
void * getOpaqueValue() const
PointerUnion(std::nullptr_t)
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.
static PointerUnion getFromOpaqueValue(void *VP)
The instances of the Type class are immutable: once they are created, they are never changed.
PointerUnionMembers()=default
PointerUnionMembers(Type V)
Derived & operator=(Type V)
PointerUnionMembers()=default
Provide PointerLikeTypeTraits for void* that is used by PointerUnion for the template arguments.
static void * getFromVoidPointer(void *P)
static constexpr int NumLowBitsAvailable
static void * getAsVoidPointer(void *P)
constexpr int bitsRequired(unsigned n)
Determine the number of bits required to store integers with values < n.
constexpr int lowBitsAvailable()
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
bool operator!=(uint64_t V1, const APInt &V2)
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
std::tuple_element_t< I, std::tuple< Ts... > > TypeAtIndex
Find the type at a given index in a list of types.
We can't (at least, at this moment with C++14) declare CastInfo as a friend of PointerUnion like this...
static To doCast(From &F)
static bool isPossible(From &F)
static bool isPossible(From &f)
static To doCast(From &f)
This struct provides a method for customizing the way a cast is performed.
Provides a cast trait that strips const from types to make it easier to implement a const-version of ...
This cast trait just provides the default implementation of doCastIfPossible to make CastInfo special...
static Union getEmptyKey()
static unsigned getHashValue(const Union &UnionVal)
static Union getTombstoneKey()
static bool isEqual(const Union &LHS, const Union &RHS)
An information struct used to provide DenseMap with the various necessary components for a given valu...
Find the first index where a type appears in a list of types.
static PointerUnion< PTs... > getFromVoidPointer(void *P)
static void * getAsVoidPointer(const PointerUnion< PTs... > &P)
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Determine if all types in Ts are distinct.
Find the first type in a list of types.