Author: Timm Baeder Date: 2025-04-28T14:08:42+02:00 New Revision: 959905a5adca4dc697160f8cbab302fefe610034
URL: https://github.com/llvm/llvm-project/commit/959905a5adca4dc697160f8cbab302fefe610034 DIFF: https://github.com/llvm/llvm-project/commit/959905a5adca4dc697160f8cbab302fefe610034.diff LOG: [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. Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/lib/AST/ByteCode/Function.cpp clang/lib/AST/ByteCode/Function.h clang/lib/AST/ByteCode/Interp.cpp clang/lib/AST/ByteCode/Interp.h clang/lib/AST/ByteCode/InterpBuiltin.cpp clang/lib/AST/ByteCode/InterpFrame.cpp clang/lib/AST/ByteCode/Opcodes.td Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index a1b2d13a15fc6..9a1e61b54b8be 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4798,10 +4798,6 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E, return true; } - const Function *Func = getFunction(E->getDirectCallee()); - if (!Func) - return false; - // For these, we're expected to ultimately return an APValue pointing // to the CallExpr. This is needed to get the correct codegen. if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString || @@ -4833,7 +4829,7 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E, } } - if (!this->emitCallBI(Func, E, BuiltinID, E)) + if (!this->emitCallBI(E, BuiltinID, E)) return false; if (DiscardResult && !ReturnType->isVoidType()) { diff --git a/clang/lib/AST/ByteCode/Function.cpp b/clang/lib/AST/ByteCode/Function.cpp index 17f2caa55f503..8a4e089d9ecd0 100644 --- a/clang/lib/AST/ByteCode/Function.cpp +++ b/clang/lib/AST/ByteCode/Function.cpp @@ -26,7 +26,6 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize, HasRVO(HasRVO) { if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) { Variadic = F->isVariadic(); - BuiltinID = F->getBuiltinID(); 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 ea3baf6fca4d6..436574dd3a4c7 100644 --- a/clang/lib/AST/ByteCode/Function.h +++ b/clang/lib/AST/ByteCode/Function.h @@ -198,10 +198,6 @@ class Function final { bool isVariadic() const { return Variadic; } - unsigned getBuiltinID() const { return BuiltinID; } - - bool isBuiltin() const { return getBuiltinID() != 0; } - unsigned getNumParams() const { return ParamTypes.size(); } /// Returns the number of parameter this function takes when it's called, @@ -296,7 +292,6 @@ class Function final { bool Defined = false; bool Variadic = false; bool Virtual = false; - unsigned BuiltinID = 0; 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 af9b3bf92ce55..4d89f23401db5 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1607,15 +1607,15 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func, return true; } -bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func, - const CallExpr *CE, uint32_t BuiltinID) { +bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE, + uint32_t BuiltinID) { // A little arbitrary, but the current interpreter allows evaluation // of builtin functions in this mode, with some exceptions. if (BuiltinID == Builtin::BI__builtin_operator_new && S.checkingPotentialConstantExpression()) return false; - return InterpretBuiltin(S, OpPC, Func, CE, BuiltinID); + return InterpretBuiltin(S, OpPC, CE, BuiltinID); } bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize, diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 27e73bb72fecb..6cd995279029a 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -153,8 +153,8 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize); bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize); -bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func, - const CallExpr *CE, uint32_t BuiltinID); +bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE, + uint32_t BuiltinID); bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize, const CallExpr *CE); bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T); @@ -302,8 +302,8 @@ bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR); bool Interpret(InterpState &S); /// Interpret a builtin function. -bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, - const CallExpr *Call, uint32_t BuiltinID); +bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, + uint32_t BuiltinID); /// Interpret an offsetof operation. bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E, diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 8779adf0d9c6b..34baae1986c35 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -2184,8 +2184,8 @@ static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC, return true; } -bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, - const CallExpr *Call, uint32_t BuiltinID) { +bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, + uint32_t BuiltinID) { if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID)) return Invalid(S, OpPC); diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index c383b2bc7f95c..1a6e271c78d6f 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -111,8 +111,6 @@ static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, } static bool shouldSkipInBacktrace(const Function *F) { - if (F->isBuiltin()) - return true; if (F->isLambdaStaticInvoker()) return true; diff --git a/clang/lib/AST/ByteCode/Opcodes.td b/clang/lib/AST/ByteCode/Opcodes.td index 7a1cc4e8c408a..e71790211293a 100644 --- a/clang/lib/AST/ByteCode/Opcodes.td +++ b/clang/lib/AST/ByteCode/Opcodes.td @@ -213,9 +213,7 @@ def CallVirt : Opcode { let Args = [ArgFunction, ArgUint32]; } -def CallBI : Opcode { - let Args = [ArgFunction, ArgCallExpr, ArgUint32]; -} +def CallBI : Opcode { let Args = [ArgCallExpr, ArgUint32]; } def CallPtr : Opcode { let Args = [ArgUint32, ArgCallExpr]; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits