LLVM
13.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. More... | |
operator bool () const | |
template<typename T > | |
bool | is () const |
Test if the Union currently holds the type matching T. More... | |
template<typename T > | |
T | get () const |
Returns the value of the specified pointer type. More... | |
template<typename T > | |
T | dyn_cast () const |
Returns the current pointer if it is of the specified pointer type, otherwise returns null. More... | |
const First * | getAddrOfPtr1 () const |
If the union is set to the first pointer type get an address pointing to it. More... | |
First * | getAddrOfPtr1 () |
If the union is set to the first pointer type get an address pointing to it. More... | |
const PointerUnion & | operator= (std::nullptr_t) |
Assignment from nullptr which just clears the union. More... | |
void * | getOpaqueValue () const |
Static Public Member Functions | |
static PointerUnion | getFromOpaqueValue (void *VP) |
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.
Definition at line 149 of file PointerUnion.h.
|
default |
|
inline |
Definition at line 167 of file PointerUnion.h.
|
inline |
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
Definition at line 194 of file PointerUnion.h.
Referenced by llvm::SIRegisterInfo::getConstrainedRegClassForOperand(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::RegisterBankInfo::getRegBank(), llvm::MachineRegisterInfo::getRegBankOrNull(), llvm::MachineRegisterInfo::getRegClassOrNull(), llvm::generic_gep_type_iterator< ItTy >::getStructTypeOrNull(), llvm::inferAlignFromPtrInfo(), isStackPtrRelative(), and llvm::MachinePointerInfo::MachinePointerInfo().
Returns the value of the specified pointer type.
If the specified pointer type is incorrect, assert.
Definition at line 187 of file PointerUnion.h.
Referenced by llvm::DIBuilder::createArrayType(), llvm::ReplaceableMetadataImpl::getAllArgListUsers(), llvm::SIRegisterInfo::getConstrainedRegClassForOperand(), llvm::ContextAndReplaceableUses::getContext(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::ContextAndReplaceableUses::getReplaceableUses(), llvm::generic_gep_type_iterator< ItTy >::getStructType(), llvm::MachinePointerInfo::getWithOffset(), llvm::MachinePointerInfo::isDereferenceable(), llvm::MachineMemOperand::MachineMemOperand(), llvm::MachinePointerInfo::MachinePointerInfo(), llvm::MachineSDNode::memoperands(), llvm::ReplaceableMetadataImpl::replaceAllUsesWith(), and llvm::FunctionLoweringInfo::set().
|
inline |
If the union is set to the first pointer type get an address pointing to it.
Definition at line 208 of file PointerUnion.h.
|
inline |
If the union is set to the first pointer type get an address pointing to it.
Definition at line 202 of file PointerUnion.h.
Referenced by llvm::TinyPtrVector< llvm::VPValue * >::begin(), llvm::PointerUnion< llvm::LLVMContext *, llvm::ReplaceableMetadataImpl * >::getAddrOfPtr1(), llvm::MachineSDNode::memoperands(), llvm::TinyPtrVector< llvm::VPValue * >::operator ArrayRef< llvm::VPValue * >(), and llvm::TinyPtrVector< llvm::VPValue * >::operator MutableArrayRef< llvm::VPValue * >().
|
inlinestatic |
Definition at line 228 of file PointerUnion.h.
Referenced by llvm::PointerUnion< llvm::LLVMContext *, llvm::ReplaceableMetadataImpl * >::getFromOpaqueValue(), and llvm::PointerLikeTypeTraits< PointerUnion< PTs... > >::getFromVoidPointer().
|
inline |
Definition at line 227 of file PointerUnion.h.
Referenced by llvm::DenseMapInfo< PointerUnion< PTs... > >::getHashValue(), llvm::operator!=(), llvm::operator<(), and llvm::operator==().
Test if the Union currently holds the type matching T.
Definition at line 177 of file PointerUnion.h.
Referenced by llvm::DIBuilder::createArrayType(), llvm::ReplaceableMetadataImpl::getAllArgListUsers(), llvm::MachinePointerInfo::getWithOffset(), llvm::ContextAndReplaceableUses::hasReplaceableUses(), llvm::MachinePointerInfo::isDereferenceable(), llvm::generic_gep_type_iterator< ItTy >::isSequential(), llvm::generic_gep_type_iterator< ItTy >::isStruct(), llvm::MachineMemOperand::MachineMemOperand(), and llvm::ReplaceableMetadataImpl::replaceAllUsesWith().
|
inline |
Test if the pointer held in the union is null, regardless of which type it is.
Definition at line 172 of file PointerUnion.h.
Referenced by llvm::TinyPtrVector< llvm::VPValue * >::empty(), llvm::TinyPtrVector< llvm::VPValue * >::end(), llvm::SelectionDAG::getLoad(), llvm::MachineFunction::getMachineMemOperand(), llvm::SelectionDAG::getStore(), llvm::SelectionDAG::getTruncStore(), llvm::MachinePointerInfo::getWithOffset(), llvm::TinyPtrVector< llvm::VPValue * >::insert(), llvm::MachineMemOperand::MachineMemOperand(), llvm::TinyPtrVector< llvm::VPValue * >::operator ArrayRef< llvm::VPValue * >(), llvm::PointerUnion< llvm::LLVMContext *, llvm::ReplaceableMetadataImpl * >::operator bool(), llvm::TinyPtrVector< llvm::VPValue * >::operator MutableArrayRef< llvm::VPValue * >(), llvm::TinyPtrVector< llvm::VPValue * >::operator[](), and llvm::TinyPtrVector< llvm::VPValue * >::push_back().
|
inlineexplicit |
Definition at line 174 of file PointerUnion.h.
|
inline |
Assignment from nullptr which just clears the union.
Definition at line 219 of file PointerUnion.h.