Author: Timm Bäder Date: 2022-10-22T10:32:05+02:00 New Revision: 0e754cfadc9487282d9b6119c41962c5c6c3660f
URL: https://github.com/llvm/llvm-project/commit/0e754cfadc9487282d9b6119c41962c5c6c3660f DIFF: https://github.com/llvm/llvm-project/commit/0e754cfadc9487282d9b6119c41962c5c6c3660f.diff LOG: [clang][Interp][NFC] Unify Call() implementations The type parameter we used to pass to call() was unused. Use the same implementation for void and value-returning function calls. Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/EvalEmitter.cpp clang/lib/AST/Interp/Interp.cpp clang/lib/AST/Interp/Interp.h clang/lib/AST/Interp/Opcodes.td Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index c785d3cafdad..a5969bb9f318 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -786,7 +786,7 @@ bool ByteCodeExprGen<Emitter>::visitRecordInitializer(const Expr *Initializer) { return false; } - return this->emitCallVoid(Func, Initializer); + return this->emitCall(Func, Initializer); } else if (const auto *InitList = dyn_cast<InitListExpr>(Initializer)) { const Record *R = getRecord(InitList->getType()); @@ -982,18 +982,10 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) { return false; } - // Primitive return value, just call it. - if (T) - return this->emitCall(*T, Func, E); - - // Void Return value, easy. - if (ReturnType->isVoidType()) - return this->emitCallVoid(Func, E); - - // Non-primitive return value with Return Value Optimization, - // we already have a pointer on the stack to write the result into. - if (Func->hasRVO()) - return this->emitCallVoid(Func, E); + // In any case call the function. The return value will end up on the stack and + // if the function has RVO, we already have the pointer on the stack to write + // the result into. + return this->emitCall(Func, E); } else { assert(false && "We don't support non-FunctionDecl callees right now."); } diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index dc0e15c82fc0..22e8695b9211 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -102,17 +102,6 @@ template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) { return ReturnValue<T>(S.Stk.pop<T>(), Result); } -bool EvalEmitter::emitCallVoid(const Function *Func, const SourceInfo &Info) { - APValue VoidResult; - InterpFrame *before = S.Current; - (void)before; - S.Current = new InterpFrame(S, Func, {}); - bool Success = Interpret(S, VoidResult); - assert(VoidResult.isAbsent()); - assert(S.Current == before); - return Success; -} - bool EvalEmitter::emitRetVoid(const SourceInfo &Info) { return true; } bool EvalEmitter::emitRetValue(const SourceInfo &Info) { diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp index ad94f2ac6ccd..e9bda12a9d0b 100644 --- a/clang/lib/AST/Interp/Interp.cpp +++ b/clang/lib/AST/Interp/Interp.cpp @@ -53,15 +53,6 @@ static bool Ret(InterpState &S, CodePtr &PC, APValue &Result) { return true; } -static bool CallVoid(InterpState &S, CodePtr &PC, const Function *Func) { - APValue VoidResult; - S.Current = new InterpFrame(S, const_cast<Function *>(Func), PC); - bool Success = Interpret(S, VoidResult); - assert(VoidResult.isAbsent()); - - return Success; -} - static bool RetVoid(InterpState &S, CodePtr &PC, APValue &Result) { S.CallStackDepth--; diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 42dff23cd6a6..73b1bc9bb406 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -1106,8 +1106,7 @@ inline bool ExpandPtr(InterpState &S, CodePtr OpPC) { return true; } -template <PrimType Name, class T = typename PrimConv<Name>::T> -static bool Call(InterpState &S, CodePtr &PC, const Function *Func) { +inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) { auto NewFrame = std::make_unique<InterpFrame>(S, Func, PC); if (Func->hasThisPointer()) { if (!CheckInvoke(S, PC, NewFrame->getThis())) { diff --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td index 52591da8a6b5..f9d2a5997625 100644 --- a/clang/lib/AST/Interp/Opcodes.td +++ b/clang/lib/AST/Interp/Opcodes.td @@ -159,17 +159,9 @@ def NoRet : Opcode {} def Call : Opcode { - let Args = [ArgFunction]; - let Types = [AllTypeClass]; - let ChangesPC = 1; - let HasGroup = 1; -} - -def CallVoid : Opcode { let Args = [ArgFunction]; let Types = []; let ChangesPC = 1; - let HasCustomEval = 1; } //===----------------------------------------------------------------------===// _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits