Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions llvm/include/llvm/Support/Recycler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include <cassert>
#include <type_traits>

namespace llvm {

Expand Down Expand Up @@ -72,19 +73,19 @@ class Recycler {
/// deleted; calling clear is one way to ensure this.
template<class AllocatorType>
void clear(AllocatorType &Allocator) {
while (FreeList) {
T *t = reinterpret_cast<T *>(pop_val());
Allocator.Deallocate(t, Size, Align);
if constexpr (std::is_same_v<std::decay_t<AllocatorType>,
BumpPtrAllocator>) {
// For BumpPtrAllocator, Deallocate is a no-op, so just drop the free
// list.
FreeList = nullptr;
} else {
while (FreeList) {
T *t = reinterpret_cast<T *>(pop_val());
Allocator.Deallocate(t, Size, Align);
}
}
}

/// Special case for BumpPtrAllocator which has an empty Deallocate()
/// function.
///
/// There is no need to traverse the free list, pulling all the objects into
/// cache.
void clear(BumpPtrAllocator &) { FreeList = nullptr; }

template<class SubClass, class AllocatorType>
SubClass *Allocate(AllocatorType &Allocator) {
static_assert(alignof(SubClass) <= Align,
Expand Down