X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FPointerIntPair.h;h=ccdcd1a8d1b949c5f1698d4a74b0288f28420e84;hb=1cacae0f297b7330c4cd2b4f0a1f95ab2615bd65;hp=51a0c77fdcabebaee88511e43ac16638e7c5cc8c;hpb=f341a47d10501bc69b5d4d2217992bb6e08668d8;p=oota-llvm.git diff --git a/include/llvm/ADT/PointerIntPair.h b/include/llvm/ADT/PointerIntPair.h index 51a0c77fdca..ccdcd1a8d1b 100644 --- a/include/llvm/ADT/PointerIntPair.h +++ b/include/llvm/ADT/PointerIntPair.h @@ -30,10 +30,10 @@ struct DenseMapInfo; /// type. /// /// Note that PointerIntPair always puts the Int part in the highest bits -/// possible. For example, PointerIntPair will put the bit for +/// possible. For example, PointerIntPair will put the bit for /// the bool into bit #2, not bit #0, which allows the low two bits to be used /// for something else. For example, this allows: -/// PointerIntPair, 1, bool> +/// PointerIntPair, 1, bool> /// ... and the two bools will land in different bits. /// template (Value & PointerBitMask); + return PtrTraits::getFromVoidPointer( + reinterpret_cast(Value & PointerBitMask)); } IntType getInt() const { @@ -71,7 +74,8 @@ public: } void setPointer(PointerTy Ptr) { - intptr_t PtrVal = reinterpret_cast(Ptr); + intptr_t PtrVal + = reinterpret_cast(PtrTraits::getAsVoidPointer(Ptr)); assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 && "Pointer is not sufficiently aligned"); // Preserve all low bits, just update the pointer. @@ -87,6 +91,17 @@ public: Value |= IntVal << IntShift; // Set new integer. } + PointerTy const *getAddrOfPointer() const { + return const_cast(this)->getAddrOfPointer(); + } + + PointerTy *getAddrOfPointer() { + assert(Value == reinterpret_cast(getPointer()) && + "Can only return the address if IntBits is cleared and " + "PtrTraits doesn't change the pointer"); + return reinterpret_cast(&Value); + } + void *getOpaqueValue() const { return reinterpret_cast(Value); } void setFromOpaqueValue(void *Val) { Value = reinterpret_cast(Val);} @@ -102,6 +117,12 @@ public: bool operator>=(const PointerIntPair &RHS) const {return Value >= RHS.Value;} }; +template struct isPodLike; +template +struct isPodLike > { + static const bool value = true; +}; + // Provide specialization of DenseMapInfo for PointerIntPair. template struct DenseMapInfo > { @@ -121,12 +142,13 @@ struct DenseMapInfo > { return unsigned(IV) ^ unsigned(IV >> 9); } static bool isEqual(const Ty &LHS, const Ty &RHS) { return LHS == RHS; } - static bool isPod() { return true; } }; // Teach SmallPtrSet that PointerIntPair is "basically a pointer". -template -class PointerLikeTypeTraits > { +template +class PointerLikeTypeTraits > { public: static inline void * getAsVoidPointer(const PointerIntPair &P) { @@ -137,8 +159,7 @@ public: return PointerIntPair::getFromOpaqueValue(P); } enum { - NumLowBitsAvailable = - PointerLikeTypeTraits::NumLowBitsAvailable - IntBits + NumLowBitsAvailable = PtrTraits::NumLowBitsAvailable - IntBits }; };