14 #ifndef LLVM_ADT_POINTERINTPAIR_H
15 #define LLVM_ADT_POINTERINTPAIR_H
42 typename PtrTraits = PointerLikeTypeTraits<PointerTy> >
45 static_assert(PtrTraits::NumLowBitsAvailable <
46 std::numeric_limits<uintptr_t>::digits,
47 "cannot use a pointer type that has all bits free");
48 static_assert(IntBits <= PtrTraits::NumLowBitsAvailable,
49 "PointerIntPair with integer size too large for pointer");
53 ~(uintptr_t)(((
intptr_t)1 << PtrTraits::NumLowBitsAvailable)-1),
57 IntShift = (uintptr_t)PtrTraits::NumLowBitsAvailable-IntBits,
60 IntMask = (uintptr_t)(((
intptr_t)1 << IntBits)-1),
63 ShiftedIntMask = (uintptr_t)(IntMask << IntShift)
75 return PtrTraits::getFromVoidPointer(
76 reinterpret_cast<void*>(
Value & PointerBitMask));
80 return (IntType)((
Value >> IntShift) & IntMask);
85 =
reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(PtrVal));
86 assert((PtrWord & ~PointerBitMask) == 0 &&
87 "Pointer is not sufficiently aligned");
94 assert((IntWord & ~IntMask) == 0 &&
"Integer too large for field");
97 Value &= ~ShiftedIntMask;
98 Value |= IntWord << IntShift;
103 =
reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(PtrVal));
104 assert((PtrWord & ~PointerBitMask) == 0 &&
105 "Pointer is not sufficiently aligned");
111 =
reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(PtrVal));
112 assert((PtrWord & ~PointerBitMask) == 0 &&
113 "Pointer is not sufficiently aligned");
115 assert((IntWord & ~IntMask) == 0 &&
"Integer too large for field");
117 Value = PtrWord | (IntWord << IntShift);
126 "Can only return the address if IntBits is cleared and "
127 "PtrTraits doesn't change the pointer");
141 (void)PtrTraits::getFromVoidPointer(V);
153 template <
typename T>
struct isPodLike;
154 template<
typename Po
interTy,
unsigned IntBits,
typename IntType>
160 template<
typename Po
interTy,
unsigned IntBits,
typename IntType>
164 uintptr_t Val =
static_cast<uintptr_t
>(-1);
165 Val <<= PointerLikeTypeTraits<Ty>::NumLowBitsAvailable;
166 return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val));
169 uintptr_t Val =
static_cast<uintptr_t
>(-2);
170 Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable;
171 return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val));
177 static bool isEqual(
const Ty &LHS,
const Ty &RHS) {
return LHS == RHS; }
181 template<
typename PointerTy,
unsigned IntBits,
typename IntType,
199 NumLowBitsAvailable = PtrTraits::NumLowBitsAvailable - IntBits
bool operator<=(const PointerIntPair &RHS) const
PointerIntPair(PointerTy PtrVal, IntType IntVal)
void setFromOpaqueValue(void *Val)
static Ty getTombstoneKey()
bool operator==(const PointerIntPair &RHS) const
PointerLikeTypeTraits - This is a traits object that is used to handle pointer types and things that ...
static unsigned getHashValue(Ty V)
void setPointer(PointerTy PtrVal)
void setPointerAndInt(PointerTy PtrVal, IntType IntVal)
PointerTy * getAddrOfPointer()
void initWithPointer(PointerTy PtrVal)
void setInt(IntType IntVal)
bool operator>(const PointerIntPair &RHS) const
PointerIntPair - This class implements a pair of a pointer and small integer.
bool operator>=(const PointerIntPair &RHS) const
bool operator!=(const PointerIntPair &RHS) const
static PointerIntPair getFromOpaqueValue(void *V)
PointerTy getPointer() const
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
void * getOpaqueValue() const
bool operator<(const PointerIntPair &RHS) const
PointerIntPair(PointerTy PtrVal)
static PointerIntPair< PointerTy, IntBits, IntType > getFromVoidPointer(void *P)
static PointerIntPair getFromOpaqueValue(const void *V)
static bool isEqual(const Ty &LHS, const Ty &RHS)
PointerIntPair< PointerTy, IntBits, IntType > Ty
LLVM Value Representation.
static void * getAsVoidPointer(const PointerIntPair< PointerTy, IntBits, IntType > &P)
PointerTy const * getAddrOfPointer() const
static PointerIntPair< PointerTy, IntBits, IntType > getFromVoidPointer(const void *P)