LLVM 20.0.0git
|
Allocate memory in an ever growing pool, as if by bump-pointer. More...
#include "llvm/Support/Allocator.h"
Public Member Functions | |
BumpPtrAllocatorImpl ()=default | |
template<typename T > | |
BumpPtrAllocatorImpl (T &&Allocator) | |
BumpPtrAllocatorImpl (BumpPtrAllocatorImpl &&Old) | |
~BumpPtrAllocatorImpl () | |
BumpPtrAllocatorImpl & | operator= (BumpPtrAllocatorImpl &&RHS) |
void | Reset () |
Deallocate all but the current slab and reset the current pointer to the beginning of it, freeing all memory allocated so far. | |
LLVM_ATTRIBUTE_RETURNS_NONNULL void * | Allocate (size_t Size, Align Alignment) |
Allocate space at the specified alignment. | |
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_NOINLINE void * | AllocateSlow (size_t Size, size_t SizeToAllocate, Align Alignment) |
LLVM_ATTRIBUTE_RETURNS_NONNULL void * | Allocate (size_t Size, size_t Alignment) |
void | Deallocate (const void *Ptr, size_t Size, size_t) |
size_t | GetNumSlabs () const |
std::optional< int64_t > | identifyObject (const void *Ptr) |
int64_t | identifyKnownObject (const void *Ptr) |
A wrapper around identifyObject that additionally asserts that the object is indeed within the allocator. | |
template<typename T > | |
int64_t | identifyKnownAlignedObject (const void *Ptr) |
A wrapper around identifyKnownObject. | |
size_t | getTotalMemory () const |
size_t | getBytesAllocated () const |
void | setRedZoneSize (size_t NewSize) |
void | PrintStats () const |
Public Member Functions inherited from llvm::AllocatorBase< DerivedT > | |
void * | Allocate (size_t Size, size_t Alignment) |
Allocate Size bytes of Alignment aligned memory. | |
void | Deallocate (const void *Ptr, size_t Size, size_t Alignment) |
Deallocate Ptr to Size bytes of memory allocated by this allocator. | |
template<typename T > | |
T * | Allocate (size_t Num=1) |
Allocate space for a sequence of objects without constructing them. | |
template<typename T > | |
std::enable_if_t<!std::is_same_v< std::remove_cv_t< T >, void >, void > | Deallocate (T *Ptr, size_t Num=1) |
Deallocate space for a sequence of objects without constructing them. | |
Friends | |
template<typename T > | |
class | SpecificBumpPtrAllocator |
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.
Definition at line 63 of file Allocator.h.
|
default |
|
inline |
Definition at line 81 of file Allocator.h.
|
inline |
Definition at line 86 of file Allocator.h.
|
inline |
Definition at line 97 of file Allocator.h.
References llvm::SmallVectorTemplateCommon< T, typename >::begin(), and llvm::SmallVectorTemplateCommon< T, typename >::end().
|
inline |
Allocate space at the specified alignment.
Definition at line 148 of file Allocator.h.
References __asan_unpoison_memory_region, __msan_allocated_memory, llvm::alignAddr(), llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::AllocateSlow(), assert(), LLVM_LIKELY, and Size.
Referenced by llvm::codeview::DebugChecksumsSubsection::addChecksum(), llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::Allocate(), llvm::LoopInfoBase< BlockT, LoopT >::AllocateLoop(), llvm::MachineFunction::allocateRegMask(), llvm::MachineFunction::allocateShuffleMask(), llvm::MCContext::allocFragment(), llvm::MachO::RecordsSlice::copyString(), llvm::MachineFunction::createExternalSymbolName(), llvm::pdb::TpiStreamBuilder::finalizeMsfLayout(), llvm::msf::MSFBuilder::generateLayout(), llvm::CondOpInit::get(), llvm::ListInit::get(), llvm::DagInit::get(), llvm::Attribute::get(), llvm::VarDefInit::get(), llvm::BitsInit::get(), llvm::RecordRecTy::get(), llvm::ScalarEvolution::getMinMaxExpr(), llvm::ScalarEvolution::getSequentialMinMaxExpr(), llvm::SelectionDAG::getVectorShuffle(), llvm::SelectionDAG::getVTList(), llvm::codeview::GlobalTypeTableBuilder::insertRecordAs(), llvm::msf::MappedBlockStream::readBytes(), llvm::StringSaver::save(), stabilize(), llvm::CodeViewYAML::toDebugH(), and llvm::codeview::SymbolSerializer::visitSymbolEnd().
|
inline |
Definition at line 214 of file Allocator.h.
References llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::Allocate(), assert(), and Size.
|
inline |
Definition at line 182 of file Allocator.h.
References __asan_poison_memory_region, __asan_unpoison_memory_region, __msan_allocated_memory, llvm::alignAddr(), assert(), llvm::detail::AllocatorHolder< Alloc >::getAllocator(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), Size, and llvm::Align::value().
Referenced by llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::Allocate().
|
inline |
Definition at line 225 of file Allocator.h.
References __asan_poison_memory_region, Ptr, and Size.
Referenced by llvm::LoopInfoBase< BlockT, LoopT >::destroy().
|
inline |
Definition at line 297 of file Allocator.h.
|
inline |
Definition at line 232 of file Allocator.h.
References llvm::SmallVectorBase< Size_T >::size().
|
inline |
Definition at line 288 of file Allocator.h.
References llvm::SmallVectorTemplateCommon< T, typename >::begin(), E, llvm::SmallVectorTemplateCommon< T, typename >::end(), and I.
Referenced by llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::PrintStats().
|
inline |
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.
Ptr
in the given allocator. This identifier is different from the ones produced by identifyObject and identifyAlignedObject. Definition at line 282 of file Allocator.h.
References assert(), llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::identifyKnownObject(), Ptr, and T.
|
inline |
A wrapper around identifyObject that additionally asserts that the object is indeed within the allocator.
Ptr
in the given allocator. Definition at line 265 of file Allocator.h.
References assert(), llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::identifyObject(), and Ptr.
Referenced by llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::identifyKnownAlignedObject().
|
inline |
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. Definition at line 239 of file Allocator.h.
References E, Idx, P, Ptr, llvm::SmallVectorBase< Size_T >::size(), and Size.
Referenced by llvm::MachO::RecordsSlice::copyString(), and llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::identifyKnownObject().
|
inline |
Definition at line 102 of file Allocator.h.
References llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::SmallVectorTemplateCommon< T, typename >::end(), and RHS.
|
inline |
Definition at line 303 of file Allocator.h.
References llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold, GrowthDelay >::getTotalMemory(), llvm::detail::printBumpPtrAllocatorStats(), and llvm::SmallVectorBase< Size_T >::size().
|
inline |
Deallocate all but the current slab and reset the current pointer to the beginning of it, freeing all memory allocated so far.
Definition at line 123 of file Allocator.h.
References __asan_poison_memory_region, llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::SmallVectorImpl< T >::clear(), llvm::SmallVectorBase< Size_T >::empty(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::SmallVectorImpl< T >::erase(), and llvm::SmallVectorTemplateCommon< T, typename >::front().
Referenced by llvm::rdf::NodeAllocator::clear(), llvm::SelectionDAG::clear(), llvm::GISelCSEInfo::releaseMemory(), llvm::LoopInfoBase< BlockT, LoopT >::releaseMemory(), llvm::LiveStacks::releaseMemory(), and llvm::MCContext::reset().
|
inline |
Definition at line 299 of file Allocator.h.
|
friend |
Definition at line 377 of file Allocator.h.