14#ifndef WPIUTIL_WPI_POINTERINTPAIR_H
15#define WPIUTIL_WPI_POINTERINTPAIR_H
26template <
typename T,
typename Enable>
struct DenseMapInfo;
27template <
typename Po
interT,
unsigned IntBits,
typename PtrTraits>
28struct PointerIntPairInfo;
43template <
typename PointerTy,
unsigned IntBits,
typename IntType = unsigned,
44 typename PtrTraits = PointerLikeTypeTraits<PointerTy>,
45 typename Info = PointerIntPairInfo<PointerTy, IntBits, PtrTraits>>
60 PointerTy
getPointer()
const {
return Info::getPointer(Value); }
62 IntType
getInt()
const {
return (IntType)Info::getInt(Value); }
65 Value = Info::updatePointer(Value, PtrVal);
69 Value = Info::updateInt(Value,
static_cast<intptr_t
>(IntVal));
73 Value = Info::updatePointer(0, PtrVal);
77 Value = Info::updateInt(Info::updatePointer(0, PtrVal),
78 static_cast<intptr_t
>(IntVal));
86 assert(Value ==
reinterpret_cast<intptr_t
>(
getPointer()) &&
87 "Can only return the address if IntBits is cleared and "
88 "PtrTraits doesn't change the pointer");
89 return reinterpret_cast<PointerTy *
>(&Value);
95 Value =
reinterpret_cast<intptr_t
>(Val);
107 (void)PtrTraits::getFromVoidPointer(V);
112 return Value == RHS.Value;
116 return Value != RHS.Value;
123 return Value <= RHS.Value;
127 return Value >= RHS.Value;
132template <
typename Po
interT,
unsigned IntBits,
typename PtrTraits>
134 static_assert(PtrTraits::NumLowBitsAvailable <
135 std::numeric_limits<uintptr_t>::digits,
136 "cannot use a pointer type that has all bits free");
137 static_assert(IntBits <= PtrTraits::NumLowBitsAvailable,
138 "PointerIntPair with integer size too large for pointer");
142 ~(
uintptr_t)(((intptr_t)1 << PtrTraits::NumLowBitsAvailable) - 1),
156 return PtrTraits::getFromVoidPointer(
166 reinterpret_cast<intptr_t
>(PtrTraits::getAsVoidPointer(Ptr));
168 "Pointer is not sufficiently aligned");
170 return PtrWord | (OrigValue & ~PointerBitMask);
173 static intptr_t
updateInt(intptr_t OrigValue, intptr_t Int) {
174 intptr_t IntWord =
static_cast<intptr_t
>(Int);
175 assert((IntWord & ~
IntMask) == 0 &&
"Integer too large for field");
183template <
typename Po
interTy,
unsigned IntBits,
typename IntType>
189 Val <<= PointerLikeTypeTraits<Ty>::NumLowBitsAvailable;
190 return Ty::getFromOpaqueValue(
reinterpret_cast<void *
>(Val));
195 Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable;
196 return Ty::getFromOpaqueValue(
reinterpret_cast<void *
>(Val));
201 return unsigned(IV) ^ unsigned(IV >> 9);
204 static bool isEqual(
const Ty &LHS,
const Ty &RHS) {
return LHS == RHS; }
208template <
typename PointerTy,
unsigned IntBits,
typename IntType,
227 static constexpr int NumLowBitsAvailable =
228 PtrTraits::NumLowBitsAvailable - IntBits;
#define LLVM_LVALUE_FUNCTION
Expands to '&' if ref-qualifiers for *this are supported.
Definition: Compiler.h:118
PointerIntPair - This class implements a pair of a pointer and small integer.
Definition: PointerIntPair.h:46
PointerIntPair(PointerTy PtrVal)
Definition: PointerIntPair.h:58
void setPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION
Definition: PointerIntPair.h:64
void setPointerAndInt(PointerTy PtrVal, IntType IntVal) LLVM_LVALUE_FUNCTION
Definition: PointerIntPair.h:76
bool operator>=(const PointerIntPair &RHS) const
Definition: PointerIntPair.h:126
constexpr PointerIntPair()=default
bool operator<(const PointerIntPair &RHS) const
Definition: PointerIntPair.h:119
PointerTy const * getAddrOfPointer() const
Definition: PointerIntPair.h:81
PointerIntPair(PointerTy PtrVal, IntType IntVal)
Definition: PointerIntPair.h:54
static PointerIntPair getFromOpaqueValue(void *V)
Definition: PointerIntPair.h:98
static PointerIntPair getFromOpaqueValue(const void *V)
Definition: PointerIntPair.h:106
bool operator>(const PointerIntPair &RHS) const
Definition: PointerIntPair.h:120
bool operator==(const PointerIntPair &RHS) const
Definition: PointerIntPair.h:111
void * getOpaqueValue() const
Definition: PointerIntPair.h:92
void setFromOpaqueValue(void *Val) LLVM_LVALUE_FUNCTION
Definition: PointerIntPair.h:94
IntType getInt() const
Definition: PointerIntPair.h:62
PointerTy getPointer() const
Definition: PointerIntPair.h:60
void initWithPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION
Definition: PointerIntPair.h:72
bool operator!=(const PointerIntPair &RHS) const
Definition: PointerIntPair.h:115
PointerTy * getAddrOfPointer()
Definition: PointerIntPair.h:85
bool operator<=(const PointerIntPair &RHS) const
Definition: PointerIntPair.h:122
void setInt(IntType IntVal) LLVM_LVALUE_FUNCTION
Definition: PointerIntPair.h:68
uint128_t uintptr_t
Definition: format.h:432
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18
static Ty getTombstoneKey()
Definition: PointerIntPair.h:193
static unsigned getHashValue(Ty V)
Definition: PointerIntPair.h:199
static bool isEqual(const Ty &LHS, const Ty &RHS)
Definition: PointerIntPair.h:204
static Ty getEmptyKey()
Definition: PointerIntPair.h:187
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:49
Definition: PointerIntPair.h:133
static intptr_t getInt(intptr_t Value)
Definition: PointerIntPair.h:160
MaskAndShiftConstants
Definition: PointerIntPair.h:139
@ PointerBitMask
PointerBitMask - The bits that come from the pointer.
Definition: PointerIntPair.h:141
@ IntMask
IntMask - This is the unshifted mask for valid bits of the int type.
Definition: PointerIntPair.h:149
@ IntShift
IntShift - The number of low bits that we reserve for other uses, and keep zero.
Definition: PointerIntPair.h:146
@ ShiftedIntMask
Definition: PointerIntPair.h:152
static PointerT getPointer(intptr_t Value)
Definition: PointerIntPair.h:155
static intptr_t updatePointer(intptr_t OrigValue, PointerT Ptr)
Definition: PointerIntPair.h:164
static intptr_t updateInt(intptr_t OrigValue, intptr_t Int)
Definition: PointerIntPair.h:173
static void * getAsVoidPointer(const PointerIntPair< PointerTy, IntBits, IntType > &P)
Definition: PointerIntPair.h:213
static PointerIntPair< PointerTy, IntBits, IntType > getFromVoidPointer(const void *P)
Definition: PointerIntPair.h:223
static PointerIntPair< PointerTy, IntBits, IntType > getFromVoidPointer(void *P)
Definition: PointerIntPair.h:218
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Definition: PointerLikeTypeTraits.h:25