|
LLVM 23.0.0git
|
A discriminated union of two or more pointer types, with the discriminator in the low bits of the pointer. More...
#include "llvm/ADT/PointerUnion.h"
Public Member Functions | |
| PointerUnion ()=default | |
| PointerUnion (std::nullptr_t) | |
| const PointerUnion & | operator= (std::nullptr_t) |
| Assignment from nullptr clears the union, resetting to the first type. | |
| 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. | |
| void * | getOpaqueValue () const |
Static Public Member Functions | |
| static PointerUnion | getFromOpaqueValue (void *VP) |
Friends | |
| template<typename, int, typename...> | |
| class | pointer_union_detail::PointerUnionMembers |
| template<typename To, typename From, typename Enable> | |
| struct | CastInfo |
| template<typename> | |
| struct | PointerLikeTypeTraits |
| bool | operator== (PointerUnion lhs, PointerUnion rhs) |
| bool | operator!= (PointerUnion lhs, PointerUnion rhs) |
| bool | operator< (PointerUnion lhs, PointerUnion rhs) |
A discriminated union of two or more pointer types, with the discriminator in the low bits 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.
When all types have enough alignment for a fixed-width tag, the tag is placed in the high end of the available low bits, leaving spare low bits for nesting in PointerIntPair or SmallPtrSet. When types have heterogeneous alignment, a variable-length escape-encoded tag is used; in that case, types must be listed in non-decreasing NumLowBitsAvailable order.
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 190 of file PointerUnion.h.
|
default |
|
inline |
Definition at line 274 of file PointerUnion.h.
|
inline |
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
Definition at line 316 of file PointerUnion.h.
Returns the value of the specified pointer type.
If the specified pointer type is incorrect, assert.
Definition at line 309 of file PointerUnion.h.
|
inline |
If the union is set to the first pointer type get an address pointing to it.
Definition at line 328 of file PointerUnion.h.
|
inline |
If the union is set to the first pointer type get an address pointing to it.
Definition at line 322 of file PointerUnion.h.
Referenced by llvm::PointerUnion< TrivialCallback *, NonTrivialCallbacks * >::getAddrOfPtr1().
|
inlinestatic |
Definition at line 345 of file PointerUnion.h.
|
inline |
Definition at line 341 of file PointerUnion.h.
Referenced by llvm::DenseMapInfo< PointerUnion< PTs... > >::getHashValue(), llvm::PointerUnion< TrivialCallback *, NonTrivialCallbacks * >::operator!=, std::hash< VarLocInsertPt >::operator()(), llvm::PointerUnion< TrivialCallback *, NonTrivialCallbacks * >::operator<, and llvm::PointerUnion< TrivialCallback *, NonTrivialCallbacks * >::operator==.
Test if the Union currently holds the type matching T.
Definition at line 302 of file PointerUnion.h.
|
inline |
Test if the pointer held in the union is null, regardless of which type it is.
Definition at line 286 of file PointerUnion.h.
Referenced by llvm::SelectionDAG::getLoad(), llvm::SelectionDAG::getLoadVP(), llvm::MachineFunction::getMachineMemOperand(), llvm::SelectionDAG::getStore(), llvm::SelectionDAG::getTruncStore(), llvm::SelectionDAG::getTruncStoreVP(), and llvm::PointerUnion< TrivialCallback *, NonTrivialCallbacks * >::operator bool().
|
inlineexplicit |
Definition at line 296 of file PointerUnion.h.
|
inline |
Assignment from nullptr clears the union, resetting to the first type.
Definition at line 279 of file PointerUnion.h.
|
friend |
Definition at line 202 of file PointerUnion.h.
|
friend |
Definition at line 355 of file PointerUnion.h.
|
friend |
Definition at line 359 of file PointerUnion.h.
|
friend |
Definition at line 351 of file PointerUnion.h.
|
friend |
Definition at line 201 of file PointerUnion.h.
Definition at line 203 of file PointerUnion.h.