https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/225761
And move the fast path to the header file, so it can be more easily inlined. >From da5ad68c62414b9f5e60e3021a25e7bd02270187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Wed, 23 Sep 2026 14:52:27 +0200 Subject: [PATCH] shink()/peekData easier inlinable --- clang/lib/AST/ByteCode/InterpStack.cpp | 20 ++++---------------- clang/lib/AST/ByteCode/InterpStack.h | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/clang/lib/AST/ByteCode/InterpStack.cpp b/clang/lib/AST/ByteCode/InterpStack.cpp index 839540a7912f87..78b74a6a60763b 100644 --- a/clang/lib/AST/ByteCode/InterpStack.cpp +++ b/clang/lib/AST/ByteCode/InterpStack.cpp @@ -54,12 +54,8 @@ void InterpStack::clearTo(size_t NewSize) { assert(size() == NewSize); } -void *InterpStack::peekData(size_t Size) const { - assert(Chunk && "Stack is empty!"); - - if (LLVM_LIKELY(Size <= Chunk->size())) - return reinterpret_cast<void *>(Chunk->start() + Chunk->Size - Size); - +// The "slow" part of peekData(). +void *InterpStack::peekDataSlow(size_t Size) const { StackChunk *Ptr = Chunk; while (Size > Ptr->size()) { Size -= Ptr->size(); @@ -70,16 +66,8 @@ void *InterpStack::peekData(size_t Size) const { return reinterpret_cast<void *>(Ptr->start() + Ptr->Size - Size); } -void InterpStack::shrink(size_t Size) { - assert(Chunk && "Chunk is empty!"); - - // Likely case is that we simply remove something from the current chunk. - if (LLVM_LIKELY(Size <= Chunk->size())) { - Chunk->Size -= Size; - StackSize -= Size; - return; - } - +// The "slow" part of shrink(). +void InterpStack::shrinkSlow(size_t Size) { while (Size > Chunk->size()) { Size -= Chunk->size(); if (Chunk->Next) { diff --git a/clang/lib/AST/ByteCode/InterpStack.h b/clang/lib/AST/ByteCode/InterpStack.h index 2c02979ee6eec8..ce2ed787307176 100644 --- a/clang/lib/AST/ByteCode/InterpStack.h +++ b/clang/lib/AST/ByteCode/InterpStack.h @@ -125,10 +125,30 @@ class InterpStack final { return Object; } + void *peekDataSlow(size_t Size) const; /// Returns a pointer from the top of the stack. - void *peekData(size_t Size) const; + void *peekData(size_t Size) const { + assert(Chunk && "Stack is empty!"); + if (LLVM_LIKELY(Size <= Chunk->size())) + return reinterpret_cast<void *>(Chunk->start() + Chunk->Size - Size); + + return peekDataSlow(Size); + } + + void shrinkSlow(size_t Size); /// Shrinks the stack. - void shrink(size_t Size); + void shrink(size_t Size) { + assert(Chunk && "Chunk is empty!"); + + // Likely case is that we simply remove something from the current chunk. + if (LLVM_LIKELY(Size <= Chunk->size())) { + Chunk->Size -= Size; + StackSize -= Size; + return; + } + + shrinkSlow(Size); + } /// Allocate stack space in 1Mb chunks. static constexpr size_t ChunkSize = 1024 * 1024; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
