Timm =?utf-8?q?Bäder?= <tbae...@redhat.com>, Timm =?utf-8?q?Bäder?= <tbae...@redhat.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/139...@github.com>
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/139671 >From 17963fa2a3af608c861dee3edf5b45b7b0dd18cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Mon, 12 May 2025 17:59:38 +0200 Subject: [PATCH 1/3] [clang][bytecode] Save Immediate bit in Function Otherwise, we have to look at the FunctionDecl at every function call. --- clang/lib/AST/ByteCode/Function.cpp | 1 + clang/lib/AST/ByteCode/Function.h | 2 ++ clang/lib/AST/ByteCode/Interp.cpp | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Function.cpp b/clang/lib/AST/ByteCode/Function.cpp index 8a4e089d9ecd0..f790d13738953 100644 --- a/clang/lib/AST/ByteCode/Function.cpp +++ b/clang/lib/AST/ByteCode/Function.cpp @@ -26,6 +26,7 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize, HasRVO(HasRVO) { if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) { Variadic = F->isVariadic(); + Immediate = F->isImmediateFunction(); if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) { Virtual = CD->isVirtual(); Kind = FunctionKind::Ctor; diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h index 436574dd3a4c7..c21ac441ad5d5 100644 --- a/clang/lib/AST/ByteCode/Function.h +++ b/clang/lib/AST/ByteCode/Function.h @@ -155,6 +155,7 @@ class Function final { /// Checks if the function is virtual. bool isVirtual() const { return Virtual; }; + bool isImmediate() const { return Immediate; } /// Checks if the function is a constructor. bool isConstructor() const { return Kind == FunctionKind::Ctor; } @@ -292,6 +293,7 @@ class Function final { bool Defined = false; bool Variadic = false; bool Virtual = false; + bool Immediate = false; public: /// Dumps the disassembled bytecode to \c llvm::errs(). diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 43f8d156589b6..a13b56c82cb44 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1502,7 +1502,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func, InterpFrame *FrameBefore = S.Current; S.Current = NewFrame.get(); - InterpStateCCOverride CCOverride(S, Func->getDecl()->isImmediateFunction()); + InterpStateCCOverride CCOverride(S, Func->isImmediate()); // Note that we cannot assert(CallResult.hasValue()) here since // Ret() above only sets the APValue if the curent frame doesn't // have a caller set. >From 9ee011624a9a77c318af950fce1fde333bb346ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Tue, 13 May 2025 09:08:13 +0200 Subject: [PATCH 2/3] Use bitfields Actually shrinks the struct from 528 to 520 bytes. --- clang/lib/AST/ByteCode/Function.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h index c21ac441ad5d5..45a1c1bf9f839 100644 --- a/clang/lib/AST/ByteCode/Function.h +++ b/clang/lib/AST/ByteCode/Function.h @@ -277,23 +277,32 @@ class Function final { /// List of parameter offsets. llvm::SmallVector<unsigned, 8> ParamOffsets; /// Flag to indicate if the function is valid. - bool IsValid = false; + LLVM_PREFERRED_TYPE(bool) + unsigned IsValid : 1; /// Flag to indicate if the function is done being /// compiled to bytecode. - bool IsFullyCompiled = false; + LLVM_PREFERRED_TYPE(bool) + unsigned IsFullyCompiled : 1; /// Flag indicating if this function takes the this pointer /// as the first implicit argument - bool HasThisPointer = false; + LLVM_PREFERRED_TYPE(bool) + unsigned HasThisPointer : 1; /// Whether this function has Return Value Optimization, i.e. /// the return value is constructed in the caller's stack frame. /// This is done for functions that return non-primive values. - bool HasRVO = false; + LLVM_PREFERRED_TYPE(bool) + unsigned HasRVO : 1; /// If we've already compiled the function's body. - bool HasBody = false; - bool Defined = false; - bool Variadic = false; - bool Virtual = false; - bool Immediate = false; + LLVM_PREFERRED_TYPE(bool) + unsigned HasBody : 1; + LLVM_PREFERRED_TYPE(bool) + unsigned Defined : 1; + LLVM_PREFERRED_TYPE(bool) + unsigned Variadic : 1; + LLVM_PREFERRED_TYPE(bool) + unsigned Virtual : 1; + LLVM_PREFERRED_TYPE(bool) + unsigned Immediate : 1; public: /// Dumps the disassembled bytecode to \c llvm::errs(). >From 24ad1be50262835c5399de622f84b7a3a842772d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Tue, 13 May 2025 10:21:36 +0200 Subject: [PATCH 3/3] Fix bitfield initialization --- clang/lib/AST/ByteCode/Function.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ByteCode/Function.cpp b/clang/lib/AST/ByteCode/Function.cpp index f790d13738953..d3e7e1ffc63d5 100644 --- a/clang/lib/AST/ByteCode/Function.cpp +++ b/clang/lib/AST/ByteCode/Function.cpp @@ -22,8 +22,9 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize, bool HasThisPointer, bool HasRVO, bool IsLambdaStaticInvoker) : P(P), Kind(FunctionKind::Normal), Source(Source), ArgSize(ArgSize), ParamTypes(std::move(ParamTypes)), Params(std::move(Params)), - ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer), - HasRVO(HasRVO) { + ParamOffsets(std::move(ParamOffsets)), IsValid(false), + IsFullyCompiled(false), HasThisPointer(HasThisPointer), HasRVO(HasRVO), + Defined(false) { if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) { Variadic = F->isVariadic(); Immediate = F->isImmediateFunction(); @@ -41,7 +42,13 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize, Kind = FunctionKind::LambdaCallOperator; else if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()) Kind = FunctionKind::CopyOrMoveOperator; + } else { + Virtual = false; } + } else { + Variadic = false; + Virtual = false; + Immediate = false; } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits