LLVM 23.0.0git
llvm::pointer_union_detail Namespace Reference

Classes

class  PointerUnionMembers
 CRTP base that generates non-template constructors and assignment operators for each type in the union. More...
class  PointerUnionMembers< Derived, Idx >
class  PointerUnionMembers< Derived, Idx, Type, Types... >
struct  TagEntry
 Tag descriptor for one type in the union. More...

Functions

constexpr int bitsRequired (unsigned NumValues)
 Determine the number of bits required to store values in [0, NumValues).
template<typename... Ts>
constexpr int lowBitsAvailable ()
template<typename... PTs>
constexpr bool useFixedWidthTags ()
 True if all types have enough low bits for a fixed-width tag.
template<typename... PTs>
constexpr bool typesInNonDecreasingBitOrder ()
 True if types are in non-decreasing NumLowBitsAvailable order.
template<typename... PTs>
constexpr std::array< TagEntry, sizeof...(PTs)> computeFixedTags ()
 Compute fixed-width tag table (all types have enough bits for the tag).
template<typename... PTs>
constexpr std::optional< std::array< TagEntry, sizeof...(PTs)> > computeExtendedTags ()
 Compute variable-width tag table, or return std::nullopt if the types don't fit.

Function Documentation

◆ bitsRequired()

int llvm::pointer_union_detail::bitsRequired ( unsigned NumValues)
constexpr

Determine the number of bits required to store values in [0, NumValues).

This is ceil(log2(NumValues)).

Definition at line 36 of file PointerUnion.h.

References llvm::bit_width_constexpr().

Referenced by computeFixedTags(), and useFixedWidthTags().

◆ computeExtendedTags()

template<typename... PTs>
std::optional< std::array< TagEntry, sizeof...(PTs)> > llvm::pointer_union_detail::computeExtendedTags ( )
constexpr

Compute variable-width tag table, or return std::nullopt if the types don't fit.

Types must be in non-decreasing NumLowBitsAvailable order. Groups types by available bits into tiers; each non-final tier reserves its highest code as an escape prefix.

Example with 3 tiers (2-bit, 3-bit, 5-bit types): Tier 0 (2 bits): codes 0b00, 0b01, 0b10; escape = 0b11 Tier 1 (3 bits): codes 0b011, escape = 0b111 Tier 2 (5 bits): codes 0b00111, 0b01111, 0b10111, 0b11111

Definition at line 92 of file PointerUnion.h.

References I, and N.

◆ computeFixedTags()

template<typename... PTs>
std::array< TagEntry, sizeof...(PTs)> llvm::pointer_union_detail::computeFixedTags ( )
constexpr

Compute fixed-width tag table (all types have enough bits for the tag).

For example, with 4 types and 3 available bits, the tag is 2 bits wide (values 0-3) and each entry has the same mask of 0x3.

Definition at line 70 of file PointerUnion.h.

References bitsRequired(), I, and N.

◆ lowBitsAvailable()

template<typename... Ts>
int llvm::pointer_union_detail::lowBitsAvailable ( )
constexpr

Definition at line 40 of file PointerUnion.h.

Referenced by useFixedWidthTags().

◆ typesInNonDecreasingBitOrder()

template<typename... PTs>
bool llvm::pointer_union_detail::typesInNonDecreasingBitOrder ( )
constexpr

True if types are in non-decreasing NumLowBitsAvailable order.

Definition at line 52 of file PointerUnion.h.

References I.

◆ useFixedWidthTags()

template<typename... PTs>
bool llvm::pointer_union_detail::useFixedWidthTags ( )
constexpr

True if all types have enough low bits for a fixed-width tag.

Definition at line 46 of file PointerUnion.h.

References bitsRequired(), and lowBitsAvailable().

Referenced by llvm::PointerUnion< TrivialCallback *, NonTrivialCallbacks * >::PointerLikeTypeTraits.