Go to the documentation of this file.
15 #ifndef LLVM_ADT_POINTERUNION_H
16 #define LLVM_ADT_POINTERUNION_H
30 namespace 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);
111 template <
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(); }
144 explicit operator bool()
const {
return !
isNull(); }
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<T>(*
this);
175 assert(is<First>() &&
"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=;
201 template <
typename ...PTs>
206 template <
typename ...PTs>
211 template <
typename ...PTs>
226 template <
typename... PTs>
struct CastInfoPointerUnionImpl {
234 assert(isPossible<To>(
F) &&
"cast to an incompatible type !");
240 template <
typename To,
typename... PTs>
243 CastInfo<To, PointerUnion<PTs...>>> {
248 return Impl::template isPossible<To>(
f);
256 template <
typename To,
typename... PTs>
259 CastInfo<To, PointerUnion<PTs...>>> {
264 template <
typename ...PTs>
267 return P.getOpaqueValue();
289 return Union(FirstInfo::getTombstoneKey());
304 #endif // LLVM_ADT_POINTERUNION_H
static bool isPossible(From &F)
static bool isPossible(From &f)
Derived & operator=(Type V)
This cast trait just provides the default implementation of doCastIfPossible to make CastInfo special...
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
This is an optimization pass for GlobalISel generic memory operations.
This struct provides a method for customizing the way a cast is performed.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
static Union getTombstoneKey()
The instances of the Type class are immutable: once they are created, they are never changed.
We can't (at least, at this moment with C++14) declare CastInfo as a friend of PointerUnion like this...
bool operator!=(uint64_t V1, const APInt &V2)
static void * getAsVoidPointer(const PointerUnion< PTs... > &P)
void * getOpaqueValue() const
T get() const
Returns the value of the specified pointer type.
bool is() const
Test if the Union currently holds the type matching T.
An information struct used to provide DenseMap with the various necessary components for a given valu...
Itanium Name Demangler i e convert the string _Z1fv into f()". You can also use the CRTP base ManglingParser to perform some simple analysis on the mangled name
static constexpr int NumLowBitsAvailable
static unsigned getHashValue(const Union &UnionVal)
Find the first index where a type appears in a list of types.
PointerUnionMembers(Type V)
constexpr int lowBitsAvailable()
AMD64 Optimization Manual has some nice information about optimizing integer multiplication by a constant How much of it applies to Intel s X86 implementation There are definite trade offs to xmm0 cvttss2siq rdx jb L3 subss xmm0 rax cvttss2siq rdx xorq rdx rax ret instead of xmm1 cvttss2siq rcx movaps xmm2 subss xmm2 cvttss2siq rax rdx xorq rax ucomiss xmm0 cmovb rax ret Seems like the jb branch has high likelihood of being taken It would have saved a few instructions It s not possible to reference and DH registers in an instruction requiring REX prefix divb and mulb both produce results in AH If isel emits a CopyFromReg which gets turned into a movb and that can be allocated a r8b r15b To get around isel emits a CopyFromReg from AX and then right shift it down by and truncate it It s not pretty but it works We need some register allocation magic to make the hack go which would often require a callee saved register Callees usually need to keep this value live for most of their body so it doesn t add a significant burden on them We currently implement this in however this is suboptimal because it means that it would be quite awkward to implement the optimization for callers A better implementation would be to relax the LLVM IR rules for sret arguments to allow a function with an sret argument to have a non void return type
Provide PointerLikeTypeTraits for void* that is used by PointerUnion for the template arguments.
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
bool operator<(int64_t V1, const APSInt &V2)
constexpr int bitsRequired(unsigned n)
Determine the number of bits required to store integers with values < n.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator==(uint64_t V1, const APInt &V2)
static PointerUnion getFromOpaqueValue(void *VP)
static bool isEqual(const Union &LHS, const Union &RHS)
static void * getFromVoidPointer(void *P)
First * getAddrOfPtr1()
If the union is set to the first pointer type get an address pointing to it.
std::tuple_element_t< I, std::tuple< Ts... > > TypeAtIndex
Find the type at a given index in a list of types.
static PointerUnion< PTs... > getFromVoidPointer(void *P)
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
PointerUnion(std::nullptr_t)
const First * getAddrOfPtr1() const
If the union is set to the first pointer type get an address pointing to it.
Provides a cast trait that strips const from types to make it easier to implement a const-version of ...
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
static To doCast(From &f)
static Union getEmptyKey()
const PointerUnion & operator=(std::nullptr_t)
Assignment from nullptr which just clears the union.
PointerUnionMembers(ValTy Val)
static void * getAsVoidPointer(void *P)
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
Determine if all types in Ts are distinct.
Find the first type in a list of types.
static To doCast(From &F)