LLVM  8.0.1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
llvm::PointerSumType< TagT, MemberTs > Class Template Reference

A sum type over pointer-like types. More...

#include "llvm/ADT/PointerSumType.h"

Inheritance diagram for llvm::PointerSumType< TagT, MemberTs >:
Inheritance graph
[legend]

Public Member Functions

constexpr PointerSumType ()=default
 
template<TagT N>
void set (typename HelperT::template Lookup< N >::PointerT Pointer)
 A typed setter to a given tagged member of the sum type. More...
 
void clear ()
 Clear the value to null with the min tag type. More...
 
TagT getTag () const
 
template<TagT N>
bool is () const
 
template<TagT N>
HelperT::template Lookup< N >::PointerT get () const
 
template<TagT N>
HelperT::template Lookup< N >::PointerT cast () const
 
HelperT::template Lookup< HelperT::MinTag >::PointerT constgetAddrOfZeroTagPointer () const
 If the tag is zero and the pointer's value isn't changed when being stored, get the address of the stored value type-punned to the zero-tag's pointer type. More...
 
HelperT::template Lookup< HelperT::MinTag >::PointerT * getAddrOfZeroTagPointer ()
 If the tag is zero and the pointer's value isn't changed when being stored, get the address of the stored value type-punned to the zero-tag's pointer type. More...
 
 operator bool () const
 
bool operator== (const PointerSumType &R) const
 
bool operator!= (const PointerSumType &R) const
 
bool operator< (const PointerSumType &R) const
 
bool operator> (const PointerSumType &R) const
 
bool operator<= (const PointerSumType &R) const
 
bool operator>= (const PointerSumType &R) const
 
uintptr_t getOpaqueValue () const
 

Static Public Member Functions

template<TagT N>
static PointerSumType create (typename HelperT::template Lookup< N >::PointerT Pointer)
 A typed constructor for a specific tagged member of the sum type. More...
 

Protected Member Functions

void * getVoidPtr () const
 

Detailed Description

template<typename TagT, typename... MemberTs>
class llvm::PointerSumType< TagT, MemberTs >

A sum type over pointer-like types.

This is a normal tagged union across pointer-like types that uses the low bits of the pointers to store the tag.

Each member of the sum type is specified by passing a PointerSumTypeMember specialization in the variadic member argument list. This allows the user to control the particular tag value associated with a particular type, use the same type for multiple different tags, and customize the pointer-like traits used for a particular member. Note that these must be specializations of PointerSumTypeMember, no other type will suffice, even if it provides a compatible interface.

This type implements all of the comparison operators and even hash table support by comparing the underlying storage of the pointer values. It doesn't support delegating to particular members for comparisons.

It also default constructs to a zero tag with a null pointer, whatever that would be. This means that the zero value for the tag type is significant and may be desirable to set to a state that is particularly desirable to default construct.

Having a supported zero-valued tag also enables getting the address of a pointer stored with that tag provided it is stored in its natural bit representation. This works because in the case of a zero-valued tag, the pointer's value is directly stored into this object and we can expose the address of that internal storage. This is especially useful when building an ArrayRef of a single pointer stored in a sum type.

There is no support for constructing or accessing with a dynamic tag as that would fundamentally violate the type safety provided by the sum type.

Definition at line 71 of file PointerSumType.h.

Constructor & Destructor Documentation

◆ PointerSumType()

template<typename TagT, typename... MemberTs>
constexpr llvm::PointerSumType< TagT, MemberTs >::PointerSumType ( )
default

Member Function Documentation

◆ cast()

template<typename TagT, typename... MemberTs>
template<TagT N>
HelperT::template Lookup<N>::PointerT llvm::PointerSumType< TagT, MemberTs >::cast ( ) const
inline

Definition at line 132 of file PointerSumType.h.

◆ clear()

template<typename TagT, typename... MemberTs>
void llvm::PointerSumType< TagT, MemberTs >::clear ( )
inline

Clear the value to null with the min tag type.

Definition at line 118 of file PointerSumType.h.

◆ create()

template<typename TagT, typename... MemberTs>
template<TagT N>
static PointerSumType llvm::PointerSumType< TagT, MemberTs >::create ( typename HelperT::template Lookup< N >::PointerT  Pointer)
inlinestatic

A typed constructor for a specific tagged member of the sum type.

Definition at line 111 of file PointerSumType.h.

◆ get()

template<typename TagT, typename... MemberTs>
template<TagT N>
HelperT::template Lookup<N>::PointerT llvm::PointerSumType< TagT, MemberTs >::get ( ) const
inline

Definition at line 126 of file PointerSumType.h.

◆ getAddrOfZeroTagPointer() [1/2]

template<typename TagT, typename... MemberTs>
HelperT::template Lookup<HelperT::MinTag>::PointerT const* llvm::PointerSumType< TagT, MemberTs >::getAddrOfZeroTagPointer ( ) const
inline

If the tag is zero and the pointer's value isn't changed when being stored, get the address of the stored value type-punned to the zero-tag's pointer type.

Definition at line 142 of file PointerSumType.h.

◆ getAddrOfZeroTagPointer() [2/2]

template<typename TagT, typename... MemberTs>
HelperT::template Lookup<HelperT::MinTag>::PointerT* llvm::PointerSumType< TagT, MemberTs >::getAddrOfZeroTagPointer ( )
inline

If the tag is zero and the pointer's value isn't changed when being stored, get the address of the stored value type-punned to the zero-tag's pointer type.

Definition at line 150 of file PointerSumType.h.

◆ getOpaqueValue()

template<typename TagT, typename... MemberTs>
uintptr_t llvm::PointerSumType< TagT, MemberTs >::getOpaqueValue ( ) const
inline

Definition at line 189 of file PointerSumType.h.

Referenced by llvm::PointerSumType< ExtraInfoInlineKinds, llvm::PointerSumTypeMember< EIIK_MMO, llvm::MachineMemOperand *>, llvm::PointerSumTypeMember< EIIK_PreInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_PostInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_OutOfLine, ExtraInfo *> >::operator!=(), llvm::PointerSumType< ExtraInfoInlineKinds, llvm::PointerSumTypeMember< EIIK_MMO, llvm::MachineMemOperand *>, llvm::PointerSumTypeMember< EIIK_PreInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_PostInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_OutOfLine, ExtraInfo *> >::operator<(), llvm::PointerSumType< ExtraInfoInlineKinds, llvm::PointerSumTypeMember< EIIK_MMO, llvm::MachineMemOperand *>, llvm::PointerSumTypeMember< EIIK_PreInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_PostInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_OutOfLine, ExtraInfo *> >::operator<=(), llvm::PointerSumType< ExtraInfoInlineKinds, llvm::PointerSumTypeMember< EIIK_MMO, llvm::MachineMemOperand *>, llvm::PointerSumTypeMember< EIIK_PreInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_PostInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_OutOfLine, ExtraInfo *> >::operator==(), llvm::PointerSumType< ExtraInfoInlineKinds, llvm::PointerSumTypeMember< EIIK_MMO, llvm::MachineMemOperand *>, llvm::PointerSumTypeMember< EIIK_PreInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_PostInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_OutOfLine, ExtraInfo *> >::operator>(), and llvm::PointerSumType< ExtraInfoInlineKinds, llvm::PointerSumTypeMember< EIIK_MMO, llvm::MachineMemOperand *>, llvm::PointerSumTypeMember< EIIK_PreInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_PostInstrSymbol, llvm::MCSymbol *>, llvm::PointerSumTypeMember< EIIK_OutOfLine, ExtraInfo *> >::operator>=().

◆ getTag()

template<typename TagT, typename... MemberTs>
TagT llvm::PointerSumType< TagT, MemberTs >::getTag ( ) const
inline

Definition at line 120 of file PointerSumType.h.

◆ getVoidPtr()

template<typename TagT, typename... MemberTs>
void* llvm::PointerSumType< TagT, MemberTs >::getVoidPtr ( ) const
inlineprotected

Definition at line 196 of file PointerSumType.h.

◆ is()

template<typename TagT, typename... MemberTs>
template<TagT N>
bool llvm::PointerSumType< TagT, MemberTs >::is ( ) const
inline

Definition at line 124 of file PointerSumType.h.

◆ operator bool()

template<typename TagT, typename... MemberTs>
llvm::PointerSumType< TagT, MemberTs >::operator bool ( ) const
inlineexplicit

Definition at line 167 of file PointerSumType.h.

◆ operator!=()

template<typename TagT, typename... MemberTs>
bool llvm::PointerSumType< TagT, MemberTs >::operator!= ( const PointerSumType< TagT, MemberTs > &  R) const
inline

Definition at line 173 of file PointerSumType.h.

◆ operator<()

template<typename TagT, typename... MemberTs>
bool llvm::PointerSumType< TagT, MemberTs >::operator< ( const PointerSumType< TagT, MemberTs > &  R) const
inline

Definition at line 176 of file PointerSumType.h.

◆ operator<=()

template<typename TagT, typename... MemberTs>
bool llvm::PointerSumType< TagT, MemberTs >::operator<= ( const PointerSumType< TagT, MemberTs > &  R) const
inline

Definition at line 182 of file PointerSumType.h.

◆ operator==()

template<typename TagT, typename... MemberTs>
bool llvm::PointerSumType< TagT, MemberTs >::operator== ( const PointerSumType< TagT, MemberTs > &  R) const
inline

Definition at line 170 of file PointerSumType.h.

◆ operator>()

template<typename TagT, typename... MemberTs>
bool llvm::PointerSumType< TagT, MemberTs >::operator> ( const PointerSumType< TagT, MemberTs > &  R) const
inline

Definition at line 179 of file PointerSumType.h.

◆ operator>=()

template<typename TagT, typename... MemberTs>
bool llvm::PointerSumType< TagT, MemberTs >::operator>= ( const PointerSumType< TagT, MemberTs > &  R) const
inline

Definition at line 185 of file PointerSumType.h.

◆ set()

template<typename TagT, typename... MemberTs>
template<TagT N>
void llvm::PointerSumType< TagT, MemberTs >::set ( typename HelperT::template Lookup< N >::PointerT  Pointer)
inline

The documentation for this class was generated from the following file: