LLVM 20.0.0git
|
A discriminated union of two or more pointer types, with the discriminator in the low bit of the pointer. More...
#include "llvm/ADT/PointerUnion.h"
Public Member Functions | |
PointerUnion ()=default | |
PointerUnion (std::nullptr_t) | |
bool | isNull () const |
Test if the pointer held in the union is null, regardless of which type it is. | |
operator bool () const | |
template<typename T > | |
bool | is () const |
Test if the Union currently holds the type matching T. | |
template<typename T > | |
T | get () const |
Returns the value of the specified pointer type. | |
template<typename T > | |
T | dyn_cast () const |
Returns the current pointer if it is of the specified pointer type, otherwise returns null. | |
First const * | getAddrOfPtr1 () const |
If the union is set to the first pointer type get an address pointing to it. | |
First * | getAddrOfPtr1 () |
If the union is set to the first pointer type get an address pointing to it. | |
const PointerUnion & | operator= (std::nullptr_t) |
Assignment from nullptr which just clears the union. | |
void * | getOpaqueValue () const |
Static Public Member Functions | |
static PointerUnion | getFromOpaqueValue (void *VP) |
Friends | |
struct | CastInfoPointerUnionImpl< PTs... > |
This is needed to give the CastInfo implementation below access to protected members. | |
A discriminated union of two or more pointer types, with the discriminator in the low bit of the pointer.
This implementation is extremely efficient in space due to leveraging the low bits of the pointer, while exposing a natural and type-safe API.
Common use patterns would be something like this: PointerUnion<int*, float*> P; P = (int*)0; printf("%d %d", P.is<int*>(), P.is<float*>()); // prints "1 0" X = P.get<int*>(); // ok. Y = P.get<float*>(); // runtime assertion failure. Z = P.get<double*>(); // compile time failure. P = (float*)0; Y = P.get<float*>(); // ok. X = P.get<int*>(); // runtime assertion failure. PointerUnion<int*, int*> Q; // compile time failure.
Definition at line 112 of file PointerUnion.h.
|
default |
|
inline |
Definition at line 137 of file PointerUnion.h.
|
inline |
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
Definition at line 162 of file PointerUnion.h.
Referenced by llvm::SIRegisterInfo::getConstrainedRegClassForOperand(), llvm::sandboxir::EraseFromParent::revert(), and selectDebugInstr().
Returns the value of the specified pointer type.
If the specified pointer type is incorrect, assert.
Definition at line 155 of file PointerUnion.h.
References assert().
Referenced by llvm::DIBuilder::insertDbgValueIntrinsic(), insertDbgValueOrDbgVariableRecord(), insertDbgValueOrDbgVariableRecordAfter(), insertNewDbgInst(), llvm::ReplaceableMetadataImpl::replaceAllUsesWith(), llvm::sandboxir::EraseFromParent::revert(), and selectDebugInstr().
|
inline |
If the union is set to the first pointer type get an address pointing to it.
Definition at line 174 of file PointerUnion.h.
References assert().
|
inline |
If the union is set to the first pointer type get an address pointing to it.
Definition at line 168 of file PointerUnion.h.
References llvm::PointerUnion< PTs >::getAddrOfPtr1().
Referenced by llvm::TinyPtrVector< EltTy >::begin(), llvm::PointerUnion< PTs >::getAddrOfPtr1(), llvm::MachineSDNode::memoperands(), llvm::TinyPtrVector< EltTy >::operator ArrayRef< EltTy >(), and llvm::TinyPtrVector< EltTy >::operator MutableArrayRef< EltTy >().
|
inlinestatic |
Definition at line 194 of file PointerUnion.h.
References llvm::PointerUnion< PTs >::getFromOpaqueValue().
Referenced by llvm::PointerUnion< PTs >::getFromOpaqueValue(), and llvm::PointerLikeTypeTraits< PointerUnion< PTs... > >::getFromVoidPointer().
|
inline |
Definition at line 193 of file PointerUnion.h.
Referenced by llvm::DenseMapInfo< PointerUnion< PTs... > >::getHashValue(), llvm::DwarfStringPoolEntryRef::operator!=(), llvm::operator!=(), std::hash< VarLocInsertPt >::operator()(), llvm::operator<(), llvm::DwarfStringPoolEntryRef::operator==(), and llvm::operator==().
Test if the Union currently holds the type matching T.
Definition at line 150 of file PointerUnion.h.
Referenced by llvm::ReplaceableMetadataImpl::getAllDbgVariableRecordUsers(), llvm::DIBuilder::insertDbgValueIntrinsic(), and llvm::ReplaceableMetadataImpl::replaceAllUsesWith().
|
inline |
Test if the pointer held in the union is null, regardless of which type it is.
Definition at line 142 of file PointerUnion.h.
Referenced by llvm::TinyPtrVector< EltTy >::empty(), llvm::TinyPtrVector< EltTy >::end(), llvm::ReplaceableMetadataImpl::getAllArgListUsers(), llvm::ReplaceableMetadataImpl::getAllDbgVariableRecordUsers(), llvm::SelectionDAG::getLoad(), llvm::SelectionDAG::getLoadVP(), llvm::MachineFunction::getMachineMemOperand(), llvm::SelectionDAG::getStore(), llvm::SelectionDAG::getTruncStore(), llvm::SelectionDAG::getTruncStoreVP(), llvm::MachinePointerInfo::getWithOffset(), llvm::TinyPtrVector< EltTy >::insert(), llvm::MachineMemOperand::MachineMemOperand(), llvm::TinyPtrVector< EltTy >::operator ArrayRef< EltTy >(), llvm::PointerUnion< PTs >::operator bool(), llvm::DwarfStringPoolEntryRef::operator bool(), llvm::TinyPtrVector< EltTy >::operator MutableArrayRef< EltTy >(), llvm::TinyPtrVector< EltTy >::operator[](), and llvm::TinyPtrVector< EltTy >::push_back().
|
inlineexplicit |
Definition at line 144 of file PointerUnion.h.
References llvm::PointerUnion< PTs >::isNull().
|
inline |
Assignment from nullptr which just clears the union.
Definition at line 185 of file PointerUnion.h.
|
friend |
This is needed to give the CastInfo implementation below access to protected members.
Refer to its definition for further details.
Definition at line 119 of file PointerUnion.h.