llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> And move the fast path to the header file, so it can be more easily inlined. --- Full diff: https://github.com/llvm/llvm-project/pull/225761.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/InterpStack.cpp (+4-16) - (modified) clang/lib/AST/ByteCode/InterpStack.h (+22-2) ``````````diff diff --git a/clang/lib/AST/ByteCode/InterpStack.cpp b/clang/lib/AST/ByteCode/InterpStack.cpp index 839540a7912f8..78b74a6a60763 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 2c02979ee6eec..ce2ed78730717 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; `````````` </details> https://github.com/llvm/llvm-project/pull/225761 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
