[clang] 96a2636 - [clang][bytecode] Remove `InterpFrame::ThisPointerOffset` (#202322)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 9 03:08:02 PDT 2026
Author: Timm Baeder
Date: 2026-06-09T12:07:57+02:00
New Revision: 96a263602fa6a8130cf9f67723bddb27787b7d97
URL: https://github.com/llvm/llvm-project/commit/96a263602fa6a8130cf9f67723bddb27787b7d97
DIFF: https://github.com/llvm/llvm-project/commit/96a263602fa6a8130cf9f67723bddb27787b7d97.diff
LOG: [clang][bytecode] Remove `InterpFrame::ThisPointerOffset` (#202322)
Replace it with a `uint8_t` representing some bool flags about the
function. This reduces the size of a frame from 88 to 80 bytes.
Added:
Modified:
clang/lib/AST/ByteCode/InterpFrame.cpp
clang/lib/AST/ByteCode/InterpFrame.h
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 97d33dad0bd98..5eb8273af17f2 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -37,6 +37,10 @@ InterpFrame::InterpFrame(InterpState &S, const Function *Func,
if (!Func)
return;
+
+ FuncFlags |= Func->hasRVO() * HasRVOFlag;
+ FuncFlags |= Func->hasThisPointer() * HasThisFlag;
+
// Initialize argument blocks.
for (unsigned I = 0, N = Func->getNumWrittenParams(); I != N; ++I)
new (argBlock(I)) Block(S.EvalID, Func->getParamDescriptor(I).Desc);
@@ -63,12 +67,6 @@ InterpFrame::InterpFrame(InterpState &S, const Function *Func, CodePtr RetPC,
// If the fuction has a This pointer, that one is next.
// Then follow the actual arguments (but those are handled
// in getParamPointer()).
- if (Func->hasRVO()) {
- // RVO pointer offset is always 0.
- }
-
- if (Func->hasThisPointer())
- ThisPointerOffset = Func->hasRVO() ? sizeof(Pointer) : 0;
}
InterpFrame::~InterpFrame() {
diff --git a/clang/lib/AST/ByteCode/InterpFrame.h b/clang/lib/AST/ByteCode/InterpFrame.h
index 4d772e1b55f46..731ffddc5a68d 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.h
+++ b/clang/lib/AST/ByteCode/InterpFrame.h
@@ -129,13 +129,13 @@ class InterpFrame final : public Frame {
/// Returns a pointer to an argument - lazily creates a block.
Pointer getParamPointer(unsigned Offset);
- bool hasThisPointer() const { return Func && Func->hasThisPointer(); }
+ bool hasThisPointer() const { return FuncFlags & HasThisFlag; }
/// Returns the 'this' pointer.
const Pointer &getThis() const {
assert(hasThisPointer());
assert(!isBottomFrame());
- return stackRef<Pointer>(ThisPointerOffset);
+ return stackRef<Pointer>((FuncFlags & HasRVOFlag) ? sizeof(Pointer) : 0);
}
/// Returns the RVO pointer, if the Function has one.
@@ -171,6 +171,9 @@ class InterpFrame final : public Frame {
void dump(llvm::raw_ostream &OS, unsigned Indent = 0) const;
private:
+ static constexpr uint8_t HasRVOFlag = 1u << 0u;
+ static constexpr uint8_t HasThisFlag = 1u << 1u;
+
/// Returns an original argument from the stack.
template <typename T> const T &stackRef(unsigned Offset) const {
assert(Args);
@@ -217,8 +220,6 @@ class InterpFrame final : public Frame {
unsigned Depth;
/// Reference to the function being executed.
const Function *Func;
- /// Offset of the instance pointer. Use with stackRef<>().
- unsigned ThisPointerOffset;
/// Return address.
CodePtr RetPC;
/// The size of all the arguments.
@@ -232,6 +233,10 @@ class InterpFrame final : public Frame {
public:
unsigned MSVCConstexprAllowed = 0;
+
+private:
+ /// Relevant flags about the function.
+ uint8_t FuncFlags = 0;
};
} // namespace interp
More information about the cfe-commits
mailing list