Skip to content

[clang][bytecode] Remove InterpFrame::ThisPointerOffset#202322

Merged
tbaederr merged 3 commits into
llvm:mainfrom
tbaederr:funcflags
Jun 9, 2026
Merged

[clang][bytecode] Remove InterpFrame::ThisPointerOffset#202322
tbaederr merged 3 commits into
llvm:mainfrom
tbaederr:funcflags

Conversation

@tbaederr

@tbaederr tbaederr commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

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.

@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Jun 8, 2026
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/202322.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+4-6)
  • (modified) clang/lib/AST/ByteCode/InterpFrame.h (+9-4)
diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 9c9318fe0e55a..98bd897445cad 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -35,6 +35,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);
@@ -61,12 +65,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 7dbf58c23fd5c..64bbb87d7a6fe 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.h
+++ b/clang/lib/AST/ByteCode/InterpFrame.h
@@ -127,13 +127,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.
@@ -169,6 +169,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);
@@ -215,8 +218,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.
@@ -228,6 +229,10 @@ class InterpFrame final : public Frame {
 
 public:
   unsigned MSVCConstexprAllowed = 0;
+
+private:
+  /// Relevant flags about the function.
+  uint8_t FuncFlags = 0;
 };
 
 } // namespace interp

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 118185 tests passed
  • 4820 tests skipped

✅ The build succeeded and all tests passed.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 55686 tests passed
  • 2641 tests skipped

✅ The build succeeded and all tests passed.

@tbaederr
tbaederr merged commit 96a2636 into llvm:main Jun 9, 2026
10 checks passed
carlobertolli pushed a commit to carlobertolli/llvm-project that referenced this pull request Jun 11, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant