10 #ifndef LLVM_ADT_POINTERSUMTYPE_H
11 #define LLVM_ADT_POINTERSUMTYPE_H
23 template <uintptr_t
N,
typename PointerArgT,
24 typename TraitsArgT = PointerLikeTypeTraits<PointerArgT>>
33 template <
typename TagT,
typename...
MemberTs>
73 create(
typename HelperT::template Lookup<N>::PointerT Pointer) {
75 void *V = HelperT::template Lookup<N>::TraitsT::getAsVoidPointer(Pointer);
77 "Pointer is insufficiently aligned to store the discriminant!");
78 Result.Value =
reinterpret_cast<uintptr_t
>(V) |
N;
84 template <TagT N>
bool is()
const {
return N ==
getTag(); }
86 template <TagT N>
typename HelperT::template Lookup<N>::PointerT
get()
const {
87 void *
P = is<N>() ?
getImpl() :
nullptr;
88 return HelperT::template Lookup<N>::TraitsT::getFromVoidPointer(P);
92 typename HelperT::template Lookup<N>::PointerT
cast()
const {
93 assert(is<N>() &&
"This instance has a different active member.");
94 return HelperT::template Lookup<N>::TraitsT::getFromVoidPointer(
getImpl());
118 template <
typename TagT,
typename...
MemberTs>
119 struct PointerSumTypeHelper :
MemberTs... {
125 template <TagT N,
typename Po
interT,
typename TraitsT>
126 static PointerSumTypeMember<N, PointerT, TraitsT>
131 typedef decltype(LookupOverload<N>(
132 static_cast<PointerSumTypeHelper *>(
nullptr)))
MemberT;
144 template <uintptr_t V, uintptr_t... Vs>
145 struct
Min : std::integral_constant<
146 uintptr_t, (V <
Min<Vs...>::value ? V :
Min<Vs...>::value)> {
148 template <u
intptr_t V>
149 struct Min<V> : std::integral_constant<uintptr_t, V> {};
150 enum {
NumTagBits =
Min<MemberTs::TraitsT::NumLowBitsAvailable...>::value };
161 template <
typename MemberT,
typename... InnerMemberTs>
164 "This discriminant value requires too many bits!");
168 "This discriminant value requires too many bits!");
171 "Each member must pass the checker.");
177 template <
typename TagT,
typename...
MemberTs>
182 enum { SomeTag = HelperT::MinTag };
183 typedef typename HelperT::template Lookup<HelperT::MinTag>::PointerT
188 return SumType::create<SomeTag>(SomePointerInfo::getEmptyKey());
191 return SumType::create<SomeTag>(
192 SomePointerInfo::getTombstoneKey());
bool operator==(const PointerSumType &R) const
HelperT::template Lookup< HelperT::MinTag >::PointerT SomePointerT
bool operator!=(const PointerSumType &R) const
A compile time pair of an integer tag and the pointer-like type which it indexes within a sum type...
static PointerSumTypeMember< N, PointerT, TraitsT > LookupOverload(PointerSumTypeMember< N, PointerT, TraitsT > *)
detail::PointerSumTypeHelper< TagT, MemberTs...> HelperT
bool operator>(const PointerSumType &R) const
decltype(LookupOverload< N >(static_cast< PointerSumTypeHelper * >(nullptr))) typede MemberT)
MemberT::PointerT PointerT
The Nth member's pointer type.
bool operator<=(const PointerSumType &R) const
static PointerSumType create(typename HelperT::template Lookup< N >::PointerT Pointer)
A typed constructor for a specific tagged member of the sum type.
static SumType getTombstoneKey()
bool operator>=(const PointerSumType &R) const
PointerSumType< TagT, MemberTs...> SumType
MemberT::TraitsT TraitsT
The Nth member's traits type.
DenseMapInfo< SomePointerT > SomePointerInfo
uintptr_t getOpaqueValue() const
static SumType getEmptyKey()
bool operator<(const PointerSumType &R) const
A sum type over pointer-like types.
static unsigned getHashValue(const SumType &Arg)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
static bool isEqual(const SumType &LHS, const SumType &RHS)
HelperT::template Lookup< N >::PointerT cast() const
A helper template for implementing PointerSumType.