Skip to content

Commit c14acb7

Browse files
authored
[clang][bytecode] Save Immediate bit in Function (llvm#139671)
Otherwise, we have to look at the FunctionDecl at every function call.
1 parent 95c683f commit c14acb7

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

clang/lib/AST/ByteCode/Function.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
2222
bool HasThisPointer, bool HasRVO, bool IsLambdaStaticInvoker)
2323
: P(P), Kind(FunctionKind::Normal), Source(Source), ArgSize(ArgSize),
2424
ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
25-
ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer),
26-
HasRVO(HasRVO) {
25+
ParamOffsets(std::move(ParamOffsets)), IsValid(false),
26+
IsFullyCompiled(false), HasThisPointer(HasThisPointer), HasRVO(HasRVO),
27+
Defined(false) {
2728
if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) {
2829
Variadic = F->isVariadic();
30+
Immediate = F->isImmediateFunction();
2931
if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {
3032
Virtual = CD->isVirtual();
3133
Kind = FunctionKind::Ctor;
@@ -40,7 +42,13 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
4042
Kind = FunctionKind::LambdaCallOperator;
4143
else if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())
4244
Kind = FunctionKind::CopyOrMoveOperator;
45+
} else {
46+
Virtual = false;
4347
}
48+
} else {
49+
Variadic = false;
50+
Virtual = false;
51+
Immediate = false;
4452
}
4553
}
4654

clang/lib/AST/ByteCode/Function.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class Function final {
155155

156156
/// Checks if the function is virtual.
157157
bool isVirtual() const { return Virtual; };
158+
bool isImmediate() const { return Immediate; }
158159

159160
/// Checks if the function is a constructor.
160161
bool isConstructor() const { return Kind == FunctionKind::Ctor; }
@@ -276,22 +277,32 @@ class Function final {
276277
/// List of parameter offsets.
277278
llvm::SmallVector<unsigned, 8> ParamOffsets;
278279
/// Flag to indicate if the function is valid.
279-
bool IsValid = false;
280+
LLVM_PREFERRED_TYPE(bool)
281+
unsigned IsValid : 1;
280282
/// Flag to indicate if the function is done being
281283
/// compiled to bytecode.
282-
bool IsFullyCompiled = false;
284+
LLVM_PREFERRED_TYPE(bool)
285+
unsigned IsFullyCompiled : 1;
283286
/// Flag indicating if this function takes the this pointer
284287
/// as the first implicit argument
285-
bool HasThisPointer = false;
288+
LLVM_PREFERRED_TYPE(bool)
289+
unsigned HasThisPointer : 1;
286290
/// Whether this function has Return Value Optimization, i.e.
287291
/// the return value is constructed in the caller's stack frame.
288292
/// This is done for functions that return non-primive values.
289-
bool HasRVO = false;
293+
LLVM_PREFERRED_TYPE(bool)
294+
unsigned HasRVO : 1;
290295
/// If we've already compiled the function's body.
291-
bool HasBody = false;
292-
bool Defined = false;
293-
bool Variadic = false;
294-
bool Virtual = false;
296+
LLVM_PREFERRED_TYPE(bool)
297+
unsigned HasBody : 1;
298+
LLVM_PREFERRED_TYPE(bool)
299+
unsigned Defined : 1;
300+
LLVM_PREFERRED_TYPE(bool)
301+
unsigned Variadic : 1;
302+
LLVM_PREFERRED_TYPE(bool)
303+
unsigned Virtual : 1;
304+
LLVM_PREFERRED_TYPE(bool)
305+
unsigned Immediate : 1;
295306

296307
public:
297308
/// Dumps the disassembled bytecode to \c llvm::errs().

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
15011501
InterpFrame *FrameBefore = S.Current;
15021502
S.Current = NewFrame.get();
15031503

1504-
InterpStateCCOverride CCOverride(S, Func->getDecl()->isImmediateFunction());
1504+
InterpStateCCOverride CCOverride(S, Func->isImmediate());
15051505
// Note that we cannot assert(CallResult.hasValue()) here since
15061506
// Ret() above only sets the APValue if the curent frame doesn't
15071507
// have a caller set.

0 commit comments

Comments
 (0)