Skip to content

Commit 959905a

Browse files
authored
[clang][bytecode] Don't create Function instances for builtins (#137618)
Now that we don't use them anymore in InterpBuiltin.cpp and we don't create frames for them anymore anyway, just don't create Function instances.
1 parent e086d7b commit 959905a

File tree

8 files changed

+11
-25
lines changed

8 files changed

+11
-25
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4798,10 +4798,6 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E,
47984798
return true;
47994799
}
48004800

4801-
const Function *Func = getFunction(E->getDirectCallee());
4802-
if (!Func)
4803-
return false;
4804-
48054801
// For these, we're expected to ultimately return an APValue pointing
48064802
// to the CallExpr. This is needed to get the correct codegen.
48074803
if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
@@ -4833,7 +4829,7 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E,
48334829
}
48344830
}
48354831

4836-
if (!this->emitCallBI(Func, E, BuiltinID, E))
4832+
if (!this->emitCallBI(E, BuiltinID, E))
48374833
return false;
48384834

48394835
if (DiscardResult && !ReturnType->isVoidType()) {

clang/lib/AST/ByteCode/Function.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
2626
HasRVO(HasRVO) {
2727
if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) {
2828
Variadic = F->isVariadic();
29-
BuiltinID = F->getBuiltinID();
3029
if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {
3130
Virtual = CD->isVirtual();
3231
Kind = FunctionKind::Ctor;

clang/lib/AST/ByteCode/Function.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ class Function final {
198198

199199
bool isVariadic() const { return Variadic; }
200200

201-
unsigned getBuiltinID() const { return BuiltinID; }
202-
203-
bool isBuiltin() const { return getBuiltinID() != 0; }
204-
205201
unsigned getNumParams() const { return ParamTypes.size(); }
206202

207203
/// Returns the number of parameter this function takes when it's called,
@@ -296,7 +292,6 @@ class Function final {
296292
bool Defined = false;
297293
bool Variadic = false;
298294
bool Virtual = false;
299-
unsigned BuiltinID = 0;
300295

301296
public:
302297
/// Dumps the disassembled bytecode to \c llvm::errs().

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,15 +1607,15 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
16071607
return true;
16081608
}
16091609

1610-
bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
1611-
const CallExpr *CE, uint32_t BuiltinID) {
1610+
bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE,
1611+
uint32_t BuiltinID) {
16121612
// A little arbitrary, but the current interpreter allows evaluation
16131613
// of builtin functions in this mode, with some exceptions.
16141614
if (BuiltinID == Builtin::BI__builtin_operator_new &&
16151615
S.checkingPotentialConstantExpression())
16161616
return false;
16171617

1618-
return InterpretBuiltin(S, OpPC, Func, CE, BuiltinID);
1618+
return InterpretBuiltin(S, OpPC, CE, BuiltinID);
16191619
}
16201620

16211621
bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,

clang/lib/AST/ByteCode/Interp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
153153
uint32_t VarArgSize);
154154
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
155155
uint32_t VarArgSize);
156-
bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
157-
const CallExpr *CE, uint32_t BuiltinID);
156+
bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE,
157+
uint32_t BuiltinID);
158158
bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
159159
const CallExpr *CE);
160160
bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T);
@@ -302,8 +302,8 @@ bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR);
302302
bool Interpret(InterpState &S);
303303

304304
/// Interpret a builtin function.
305-
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
306-
const CallExpr *Call, uint32_t BuiltinID);
305+
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
306+
uint32_t BuiltinID);
307307

308308
/// Interpret an offsetof operation.
309309
bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E,

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,8 +2184,8 @@ static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
21842184
return true;
21852185
}
21862186

2187-
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
2188-
const CallExpr *Call, uint32_t BuiltinID) {
2187+
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
2188+
uint32_t BuiltinID) {
21892189
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
21902190
return Invalid(S, OpPC);
21912191

clang/lib/AST/ByteCode/InterpFrame.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx,
111111
}
112112

113113
static bool shouldSkipInBacktrace(const Function *F) {
114-
if (F->isBuiltin())
115-
return true;
116114
if (F->isLambdaStaticInvoker())
117115
return true;
118116

clang/lib/AST/ByteCode/Opcodes.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ def CallVirt : Opcode {
213213
let Args = [ArgFunction, ArgUint32];
214214
}
215215

216-
def CallBI : Opcode {
217-
let Args = [ArgFunction, ArgCallExpr, ArgUint32];
218-
}
216+
def CallBI : Opcode { let Args = [ArgCallExpr, ArgUint32]; }
219217

220218
def CallPtr : Opcode {
221219
let Args = [ArgUint32, ArgCallExpr];

0 commit comments

Comments
 (0)