10 #ifndef LLVM_ADT_POINTERSUMTYPE_H 11 #define LLVM_ADT_POINTERSUMTYPE_H 17 #include <type_traits> 25 template <uintptr_t
N,
typename PointerArgT,
26 typename TraitsArgT = PointerLikeTypeTraits<PointerArgT>>
74 create(
typename HelperT::template Lookup<N>::PointerT Pointer) {
76 void *V = HelperT::template Lookup<N>::TraitsT::getAsVoidPointer(Pointer);
77 assert((reinterpret_cast<uintptr_t>(V) & HelperT::TagMask) == 0 &&
78 "Pointer is insufficiently aligned to store the discriminant!");
79 Result.Value =
reinterpret_cast<uintptr_t
>(V) | N;
83 TagT
getTag()
const {
return static_cast<TagT
>(Value & HelperT::TagMask); }
85 template <TagT N>
bool is()
const {
return N ==
getTag(); }
87 template <TagT N>
typename HelperT::template Lookup<N>::PointerT
get()
const {
88 void *
P = is<N>() ?
getImpl() :
nullptr;
89 return HelperT::template Lookup<N>::TraitsT::getFromVoidPointer(P);
93 typename HelperT::template Lookup<N>::PointerT
cast()
const {
94 assert(is<N>() &&
"This instance has a different active member.");
95 return HelperT::template Lookup<N>::TraitsT::getFromVoidPointer(
getImpl());
98 explicit operator bool()
const {
return Value & HelperT::PointerMask; }
110 return reinterpret_cast<void *
>(Value & HelperT::PointerMask);
119 template <
typename TagT,
typename...
MemberTs>
120 struct PointerSumTypeHelper :
MemberTs... {
126 template <TagT N,
typename Po
interT,
typename TraitsT>
129 template <TagT N>
static void LookupOverload(...);
133 LookupOverload<N>(static_cast<PointerSumTypeHelper *>(
nullptr)));
145 template <uintptr_t V, uintptr_t... Vs>
146 struct Min : std::integral_constant<
147 uintptr_t, (V < Min<Vs...>::value ? V : Min<Vs...>::value)> {
149 template <uintptr_t V>
150 struct Min<V> : std::integral_constant<uintptr_t, V> {};
151 enum { NumTagBits = Min<MemberTs::TraitsT::NumLowBitsAvailable...>::value };
155 MinTag = Min<MemberTs::Tag...>::value,
156 PointerMask = static_cast<uint64_t>(-1) << NumTagBits,
157 TagMask = ~PointerMask
162 template <typename MemberT, typename... InnerMemberTs>
163 struct Checker : Checker<InnerMemberTs...> {
164 static_assert(MemberT::Tag < (1 << NumTagBits),
165 "This discriminant value requires too many bits!");
167 template <typename MemberT> struct Checker<MemberT> : std::true_type {
168 static_assert(MemberT::Tag < (1 << NumTagBits),
169 "This discriminant value requires too many bits!");
171 static_assert(Checker<MemberTs...>::value,
172 "Each member must pass the checker.");
178 template <typename TagT, typename... MemberTs>
179 struct DenseMapInfo<PointerSumType<TagT, MemberTs...>> {
180 using SumType = PointerSumType<TagT, MemberTs...>;
181 using HelperT = detail::PointerSumTypeHelper<TagT, MemberTs...>;
182 enum { SomeTag = HelperT::MinTag };
184 typename HelperT::template Lookup<HelperT::MinTag>::PointerT;
185 using SomePointerInfo = DenseMapInfo<SomePointerT>;
187 static inline SumType getEmptyKey() {
188 return SumType::create<SomeTag>(SomePointerInfo::getEmptyKey());
191 static inline SumType getTombstoneKey() {
192 return SumType::create<SomeTag>(SomePointerInfo::getTombstoneKey());
195 static unsigned getHashValue(const SumType &Arg) {
196 uintptr_t OpaqueValue = Arg.getOpaqueValue();
197 return DenseMapInfo<uintptr_t>::getHashValue(OpaqueValue);
200 static bool isEqual(const SumType &LHS, const SumType &RHS) {
bool operator==(const PointerSumType &R) const
Compute iterated dominance frontiers using a linear time algorithm.
A compile time pair of an integer tag and the pointer-like type which it indexes within a sum type...
bool operator>(const PointerSumType &R) const
typename MemberT::TraitsT TraitsT
The Nth member's traits type.
uintptr_t getOpaqueValue() const
decltype(LookupOverload< N >(static_cast< PointerSumTypeHelper * >(nullptr))) MemberT
static PointerSumType create(typename HelperT::template Lookup< N >::PointerT Pointer)
A typed constructor for a specific tagged member of the sum type.
bool operator>=(const PointerSumType &R) const
bool operator<=(const PointerSumType &R) const
HelperT::template Lookup< N >::PointerT cast() const
bool operator!=(const PointerSumType &R) const
static Optional< unsigned > getTag(const TargetRegisterInfo *TRI, const MachineInstr &MI, const LoadInfo &LI)
A sum type over pointer-like types.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
A helper template for implementing PointerSumType.
bool operator<(const PointerSumType &R) const
typename MemberT::PointerT PointerT
The Nth member's pointer type.