Skip to content

[clang][bytecode] Save Immediate bit in Function #139671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions clang/lib/AST/ByteCode/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ 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();
if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {
Virtual = CD->isVirtual();
Kind = FunctionKind::Ctor;
Expand All @@ -40,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;
}
}

Expand Down
27 changes: 19 additions & 8 deletions clang/lib/AST/ByteCode/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -276,22 +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;
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().
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down