class BumpPtrAllocatorImpl

Declaration

template <typename AllocatorT = llvm::MallocAllocator,
          size_t SlabSize = 4096,
          size_t SizeThreshold = SlabSize,
          size_t GrowthDelay = 128>
class BumpPtrAllocatorImpl { /* full declaration omitted */ };

Description

Allocate memory in an ever growing pool, as if by bump-pointer. This isn't strictly a bump-pointer allocator as it uses backing slabs of memory rather than relying on a boundless contiguous heap. However, it has bump-pointer semantics in that it is a monotonically growing pool of memory where every allocation is found by merely allocating the next N bytes in the slab, or the next N bytes in the next slab. Note that this also has a threshold for forcing allocations above a certain size into their own slab. The BumpPtrAllocatorImpl template defaults to using a MallocAllocator object, which wraps malloc, to allocate memory, but it can be changed to use a custom allocator. The GrowthDelay specifies after how many allocated slabs the allocator increases the size of the slabs.

Declared at: llvm/include/llvm/Support/Allocator.h:63

Templates

AllocatorT = llvm::MallocAllocator
size_t SlabSize = 4096
size_t SizeThreshold = SlabSize
size_t GrowthDelay = 128

Member Variables

private char* CurPtr = nullptr
This points to the next free byte in the slab.
private char* End = nullptr
The end of the current slab.
private SmallVector<void*, 4> Slabs
The slabs allocated so far.
private SmallVector<std::pair<void*, size_t>, 0> CustomSizedSlabs
Custom-sized slabs allocated for too-large allocation requests.
private size_t BytesAllocated = 0
Used so that we can compute how much space was wasted.
private size_t RedZoneSize = 1
The number of bytes to put between allocations when running under a sanitizer.

Method Overview

Methods

void* Allocate(size_t Size, llvm::Align Alignment)

Description

Allocate space at the specified alignment.

Declared at: llvm/include/llvm/Support/Allocator.h:148

Parameters

size_t Size
llvm::Align Alignment

inline void* Allocate(size_t Size,
                      size_t Alignment)

Declared at: llvm/include/llvm/Support/Allocator.h:207

Parameters

size_t Size
size_t Alignment

BumpPtrAllocatorImpl<AllocatorT,
                     SlabSize,
                     SizeThreshold,
                     GrowthDelay>(
    BumpPtrAllocatorImpl<AllocatorT,
                         SlabSize,
                         SizeThreshold,
                         GrowthDelay>&& Old)

Declared at: llvm/include/llvm/Support/Allocator.h:86

Parameters

BumpPtrAllocatorImpl<AllocatorT, SlabSize, SizeThreshold, GrowthDelay>&& Old

template <typename T>
BumpPtrAllocatorImpl<AllocatorT,
                     SlabSize,
                     SizeThreshold,
                     GrowthDelay>(T&& Allocator)

Declared at: llvm/include/llvm/Support/Allocator.h:81

Templates

T

Parameters

T&& Allocator

BumpPtrAllocatorImpl<AllocatorT,
                     SlabSize,
                     SizeThreshold,
                     GrowthDelay>()

Declared at: llvm/include/llvm/Support/Allocator.h:78

void Deallocate(const void* Ptr,
                size_t Size,
                size_t)

Declared at: llvm/include/llvm/Support/Allocator.h:218

Parameters

const void* Ptr
size_t Size
size_t

void DeallocateCustomSizedSlabs()

Description

Deallocate all memory for custom sized slabs.

Declared at: llvm/include/llvm/Support/Allocator.h:362

void DeallocateSlabs(
    SmallVectorImpl<void*>::iterator I,
    SmallVectorImpl<void*>::iterator E)

Description

Deallocate a sequence of slabs.

Declared at: llvm/include/llvm/Support/Allocator.h:351

Parameters

SmallVectorImpl<void*>::iterator I
SmallVectorImpl<void*>::iterator E

size_t GetNumSlabs() const

Declared at: llvm/include/llvm/Support/Allocator.h:225

void PrintStats() const

Declared at: llvm/include/llvm/Support/Allocator.h:296

void Reset()

Description

Deallocate all but the current slab and reset the current pointer to the beginning of it, freeing all memory allocated so far.

Declared at: llvm/include/llvm/Support/Allocator.h:123

void StartNewSlab()

Description

Allocate a new slab and move the bump pointers over into the new slab, modifying CurPtr and End.

Declared at: llvm/include/llvm/Support/Allocator.h:336

static size_t computeSlabSize(
    unsigned int SlabIdx)

Declared at: llvm/include/llvm/Support/Allocator.h:325

Parameters

unsigned int SlabIdx

size_t getBytesAllocated() const

Declared at: llvm/include/llvm/Support/Allocator.h:290

size_t getTotalMemory() const

Declared at: llvm/include/llvm/Support/Allocator.h:281

template <typename T>
int64_t identifyKnownAlignedObject(
    const void* Ptr)

Description

A wrapper around identifyKnownObject. Accepts type information about the object and produces a smaller identifier by relying on the alignment information. Note that sub-classes may have different alignment, so the most base class should be passed as template parameter in order to obtain correct results. For that reason automatic template parameter deduction is disabled.

Declared at: llvm/include/llvm/Support/Allocator.h:275

Templates

T

Parameters

const void* Ptr

Returns

An index uniquely and reproducibly identifying an input pointer \p Ptr in the given allocator. This identifier is different from the ones produced by identifyObject and identifyAlignedObject.

int64_t identifyKnownObject(const void* Ptr)

Description

A wrapper around identifyObject that additionally asserts that the object is indeed within the allocator.

Declared at: llvm/include/llvm/Support/Allocator.h:258

Parameters

const void* Ptr

Returns

An index uniquely and reproducibly identifying an input pointer \p Ptr in the given allocator.

llvm::Optional<int64_t> identifyObject(
    const void* Ptr)

Declared at: llvm/include/llvm/Support/Allocator.h:232

Parameters

const void* Ptr

Returns

An index uniquely and reproducibly identifying an input pointer \p Ptr in the given allocator. The returned value is negative iff the object is inside a custom-size slab. Returns an empty optional if the pointer is not found in the allocator.

void setRedZoneSize(size_t NewSize)

Declared at: llvm/include/llvm/Support/Allocator.h:292

Parameters

size_t NewSize

~BumpPtrAllocatorImpl<AllocatorT,
                      SlabSize,
                      SizeThreshold,
                      GrowthDelay>()

Declared at: llvm/include/llvm/Support/Allocator.h:97