X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FPointerUnion.h;h=f27b81113ec504eb91d321f201285f0a94db3150;hb=1e2c16606dc69989c6358918d57099320d9acb51;hp=dafd0e05109399fd3d23aa4fd3b275325145807b;hpb=9393eb354ff7cc08a8cc0a4ec6ed5c55b100abf5;p=oota-llvm.git diff --git a/include/llvm/ADT/PointerUnion.h b/include/llvm/ADT/PointerUnion.h index dafd0e05109..f27b81113ec 100644 --- a/include/llvm/ADT/PointerUnion.h +++ b/include/llvm/ADT/PointerUnion.h @@ -61,7 +61,7 @@ namespace llvm { NumLowBitsAvailable = PT1BitsAv < PT2BitsAv ? PT1BitsAv : PT2BitsAv }; }; - + /// PointerUnion - This implements a discriminated union of two pointer types, /// and keeps the discriminator bit-mangled into the low bits of the pointer. /// This allows the implementation to be extremely efficient in space, but @@ -80,7 +80,7 @@ namespace llvm { template class PointerUnion { public: - typedef PointerIntPair > ValTy; private: ValTy Val; @@ -96,14 +96,14 @@ namespace llvm { public: PointerUnion() {} - + PointerUnion(PT1 V) : Val( const_cast(PointerLikeTypeTraits::getAsVoidPointer(V))) { } PointerUnion(PT2 V) : Val( const_cast(PointerLikeTypeTraits::getAsVoidPointer(V)), 1) { } - + /// isNull - Return true if the pointer held in the union is null, /// regardless of which type it is. bool isNull() const { @@ -111,7 +111,7 @@ namespace llvm { // we recursively strip off low bits if we have a nested PointerUnion. return !PointerLikeTypeTraits::getFromVoidPointer(Val.getPointer()); } - LLVM_EXPLICIT operator bool() const { return !isNull(); } + explicit operator bool() const { return !isNull(); } /// is() return true if the Union currently holds the type matching T. template @@ -123,7 +123,7 @@ namespace llvm { int TyNo = Ty::Num; return static_cast(Val.getInt()) == TyNo; } - + /// get() - Return the value of the specified pointer type. If the /// specified pointer type is incorrect, assert. template @@ -131,7 +131,7 @@ namespace llvm { assert(is() && "Invalid accessor called"); return PointerLikeTypeTraits::getFromVoidPointer(Val.getPointer()); } - + /// dyn_cast() - If the current value is of the specified pointer type, /// return it, otherwise return null. template @@ -154,7 +154,13 @@ namespace llvm { "Can't get the address because PointerLikeTypeTraits changes the ptr"); return (PT1 *)Val.getAddrOfPointer(); } - + + /// \brief Assignment from nullptr which just clears the union. + const PointerUnion &operator=(std::nullptr_t) { + Val.initWithPointer(nullptr); + return *this; + } + /// Assignment operators - Allow assigning into this union from either /// pointer type, setting the discriminator to remember what it came from. const PointerUnion &operator=(const PT1 &RHS) { @@ -168,7 +174,7 @@ namespace llvm { 1); return *this; } - + void *getOpaqueValue() const { return Val.getOpaqueValue(); } static inline PointerUnion getFromOpaqueValue(void *VP) { PointerUnion V; @@ -189,6 +195,12 @@ namespace llvm { return lhs.getOpaqueValue() != rhs.getOpaqueValue(); } + template + static bool operator<(PointerUnion lhs, + PointerUnion rhs) { + return lhs.getOpaqueValue() < rhs.getOpaqueValue(); + } + // Teach SmallPtrSet that PointerUnion is "basically a pointer", that has // # low bits available = min(PT1bits,PT2bits)-1. template @@ -202,16 +214,16 @@ namespace llvm { getFromVoidPointer(void *P) { return PointerUnion::getFromOpaqueValue(P); } - + // The number of bits available are the min of the two pointer types. enum { - NumLowBitsAvailable = + NumLowBitsAvailable = PointerLikeTypeTraits::ValTy> ::NumLowBitsAvailable }; }; - - + + /// PointerUnion3 - This is a pointer union of three pointer types. See /// documentation for PointerUnion for usage. template @@ -227,7 +239,7 @@ namespace llvm { IsInnerUnion(ValTy val) : Val(val) { } template int is() const { - return Val.template is() && + return Val.template is() && Val.template get().template is(); } template @@ -251,7 +263,7 @@ namespace llvm { public: PointerUnion3() {} - + PointerUnion3(PT1 V) { Val = InnerUnion(V); } @@ -261,12 +273,12 @@ namespace llvm { PointerUnion3(PT3 V) { Val = V; } - + /// isNull - Return true if the pointer held in the union is null, /// regardless of which type it is. bool isNull() const { return Val.isNull(); } - LLVM_EXPLICIT operator bool() const { return !isNull(); } - + explicit operator bool() const { return !isNull(); } + /// is() return true if the Union currently holds the type matching T. template int is() const { @@ -277,7 +289,7 @@ namespace llvm { >::Return Ty; return Ty(Val).template is(); } - + /// get() - Return the value of the specified pointer type. If the /// specified pointer type is incorrect, assert. template @@ -290,7 +302,7 @@ namespace llvm { >::Return Ty; return Ty(Val).template get(); } - + /// dyn_cast() - If the current value is of the specified pointer type, /// return it, otherwise return null. template @@ -298,7 +310,13 @@ namespace llvm { if (is()) return get(); return T(); } - + + /// \brief Assignment from nullptr which just clears the union. + const PointerUnion3 &operator=(std::nullptr_t) { + Val = nullptr; + return *this; + } + /// Assignment operators - Allow assigning into this union from either /// pointer type, setting the discriminator to remember what it came from. const PointerUnion3 &operator=(const PT1 &RHS) { @@ -313,7 +331,7 @@ namespace llvm { Val = RHS; return *this; } - + void *getOpaqueValue() const { return Val.getOpaqueValue(); } static inline PointerUnion3 getFromOpaqueValue(void *VP) { PointerUnion3 V; @@ -321,7 +339,7 @@ namespace llvm { return V; } }; - + // Teach SmallPtrSet that PointerUnion3 is "basically a pointer", that has // # low bits available = min(PT1bits,PT2bits,PT2bits)-2. template @@ -335,10 +353,10 @@ namespace llvm { getFromVoidPointer(void *P) { return PointerUnion3::getFromOpaqueValue(P); } - + // The number of bits available are the min of the two pointer types. enum { - NumLowBitsAvailable = + NumLowBitsAvailable = PointerLikeTypeTraits::ValTy> ::NumLowBitsAvailable }; @@ -356,7 +374,7 @@ namespace llvm { ValTy Val; public: PointerUnion4() {} - + PointerUnion4(PT1 V) { Val = InnerUnion1(V); } @@ -369,12 +387,12 @@ namespace llvm { PointerUnion4(PT4 V) { Val = InnerUnion2(V); } - + /// isNull - Return true if the pointer held in the union is null, /// regardless of which type it is. bool isNull() const { return Val.isNull(); } - LLVM_EXPLICIT operator bool() const { return !isNull(); } - + explicit operator bool() const { return !isNull(); } + /// is() return true if the Union currently holds the type matching T. template int is() const { @@ -383,10 +401,10 @@ namespace llvm { ::llvm::PointerUnionTypeSelector >::Return Ty; - return Val.template is() && + return Val.template is() && Val.template get().template is(); } - + /// get() - Return the value of the specified pointer type. If the /// specified pointer type is incorrect, assert. template @@ -399,7 +417,7 @@ namespace llvm { >::Return Ty; return Val.template get().template get(); } - + /// dyn_cast() - If the current value is of the specified pointer type, /// return it, otherwise return null. template @@ -407,7 +425,13 @@ namespace llvm { if (is()) return get(); return T(); } - + + /// \brief Assignment from nullptr which just clears the union. + const PointerUnion4 &operator=(std::nullptr_t) { + Val = nullptr; + return *this; + } + /// Assignment operators - Allow assigning into this union from either /// pointer type, setting the discriminator to remember what it came from. const PointerUnion4 &operator=(const PT1 &RHS) { @@ -426,7 +450,7 @@ namespace llvm { Val = InnerUnion2(RHS); return *this; } - + void *getOpaqueValue() const { return Val.getOpaqueValue(); } static inline PointerUnion4 getFromOpaqueValue(void *VP) { PointerUnion4 V; @@ -434,7 +458,7 @@ namespace llvm { return V; } }; - + // Teach SmallPtrSet that PointerUnion4 is "basically a pointer", that has // # low bits available = min(PT1bits,PT2bits,PT2bits)-2. template @@ -448,10 +472,10 @@ namespace llvm { getFromVoidPointer(void *P) { return PointerUnion4::getFromOpaqueValue(P); } - + // The number of bits available are the min of the two pointer types. enum { - NumLowBitsAvailable = + NumLowBitsAvailable = PointerLikeTypeTraits::ValTy> ::NumLowBitsAvailable };