Skip to content

Commit cd46c2c

Browse files
authored
Tweak BumpPtrAllocator to benefit the hot path (llvm#90571)
This takes the form of three consecutive but related changes: - Mark the fast path of BumpPtrAllocator as likely-taken. - Move the slow path of BumpPtrAllocator to a separate function. - Mark the slow path of BumpPtrAllocator as noinline. Overall, this saves geomean 0.4% userspace instructions on CTMark -O3, and 0.98% on CTMark -O0 -g. http://llvm-compile-time-tracker.com/compare.php?from=e1622e189e8c0ef457bfac528f90a7a930d9aad2&to=9eb53a4ed3af4a55e769ae1dd22d034b63d046e3&stat=instructions%3Au
1 parent d392520 commit cd46c2c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

llvm/include/llvm/Support/Allocator.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ class BumpPtrAllocatorImpl
159159
#endif
160160

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

176+
return AllocateSlow(Size, SizeToAllocate, Alignment);
177+
}
178+
179+
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_NOINLINE void *
180+
AllocateSlow(size_t Size, size_t SizeToAllocate, Align Alignment) {
176181
// If Size is really big, allocate a separate slab for it.
177182
size_t PaddedSize = SizeToAllocate + Alignment.value() - 1;
178183
if (PaddedSize > SizeThreshold) {

0 commit comments

Comments
 (0)