Skip to content

Tweak BumpPtrAllocator to benefit the hot path #90571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2024
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
11 changes: 8 additions & 3 deletions llvm/include/llvm/Support/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ class BumpPtrAllocatorImpl
#endif

// Check if we have enough space.
if (Adjustment + SizeToAllocate <= size_t(End - CurPtr)
// We can't return nullptr even for a zero-sized allocation!
&& CurPtr != nullptr) {
if (LLVM_LIKELY(Adjustment + SizeToAllocate <= size_t(End - CurPtr)
// We can't return nullptr even for a zero-sized allocation!
&& CurPtr != nullptr)) {
char *AlignedPtr = CurPtr + Adjustment;
CurPtr = AlignedPtr + SizeToAllocate;
// Update the allocation point of this memory block in MemorySanitizer.
Expand All @@ -173,6 +173,11 @@ class BumpPtrAllocatorImpl
return AlignedPtr;
}

return AllocateSlow(Size, SizeToAllocate, Alignment);
}

LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_NOINLINE void *
AllocateSlow(size_t Size, size_t SizeToAllocate, Align Alignment) {
// If Size is really big, allocate a separate slab for it.
size_t PaddedSize = SizeToAllocate + Alignment.value() - 1;
if (PaddedSize > SizeThreshold) {
Expand Down