diff options
Diffstat (limited to 'clang/lib/CodeGen/CGClass.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGClass.cpp | 99 |
1 files changed, 14 insertions, 85 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index 40fb9bb..4bc8001 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -2929,16 +2929,14 @@ llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad( } void CodeGenFunction::EmitForwardingCallToLambda( - const CXXMethodDecl *callOperator, CallArgList &callArgs, - const CGFunctionInfo *calleeFnInfo, llvm::Constant *calleePtr) { + const CXXMethodDecl *callOperator, + CallArgList &callArgs) { // Get the address of the call operator. - if (!calleeFnInfo) - calleeFnInfo = &CGM.getTypes().arrangeCXXMethodDeclaration(callOperator); - - if (!calleePtr) - calleePtr = - CGM.GetAddrOfFunction(GlobalDecl(callOperator), - CGM.getTypes().GetFunctionType(*calleeFnInfo)); + const CGFunctionInfo &calleeFnInfo = + CGM.getTypes().arrangeCXXMethodDeclaration(callOperator); + llvm::Constant *calleePtr = + CGM.GetAddrOfFunction(GlobalDecl(callOperator), + CGM.getTypes().GetFunctionType(calleeFnInfo)); // Prepare the return slot. const FunctionProtoType *FPT = @@ -2946,8 +2944,8 @@ void CodeGenFunction::EmitForwardingCallToLambda( QualType resultType = FPT->getReturnType(); ReturnValueSlot returnSlot; if (!resultType->isVoidType() && - calleeFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect && - !hasScalarEvaluationKind(calleeFnInfo->getReturnType())) + calleeFnInfo.getReturnInfo().getKind() == ABIArgInfo::Indirect && + !hasScalarEvaluationKind(calleeFnInfo.getReturnType())) returnSlot = ReturnValueSlot(ReturnValue, resultType.isVolatileQualified(), /*IsUnused=*/false, /*IsExternallyDestructed=*/true); @@ -2958,7 +2956,7 @@ void CodeGenFunction::EmitForwardingCallToLambda( // Now emit our call. auto callee = CGCallee::forDirect(calleePtr, GlobalDecl(callOperator)); - RValue RV = EmitCall(*calleeFnInfo, callee, returnSlot, callArgs); + RValue RV = EmitCall(calleeFnInfo, callee, returnSlot, callArgs); // If necessary, copy the returned value into the slot. if (!resultType->isVoidType() && returnSlot.isNull()) { @@ -3000,15 +2998,7 @@ void CodeGenFunction::EmitLambdaBlockInvokeBody() { EmitForwardingCallToLambda(CallOp, CallArgs); } -void CodeGenFunction::EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD) { - if (MD->isVariadic()) { - // FIXME: Making this work correctly is nasty because it requires either - // cloning the body of the call operator or making the call operator - // forward. - CGM.ErrorUnsupported(MD, "lambda conversion to variadic function"); - return; - } - +void CodeGenFunction::EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD) { const CXXRecordDecl *Lambda = MD->getParent(); // Start building arguments for forwarding call @@ -3019,16 +3009,10 @@ void CodeGenFunction::EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD) { Address ThisPtr = CreateMemTemp(LambdaType, "unused.capture"); CallArgs.add(RValue::get(ThisPtr.getPointer()), ThisType); - EmitLambdaDelegatingInvokeBody(MD, CallArgs); -} - -void CodeGenFunction::EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD, - CallArgList &CallArgs) { - // Add the rest of the forwarded parameters. + // Add the rest of the parameters. for (auto *Param : MD->parameters()) EmitDelegateCallArg(CallArgs, Param, Param->getBeginLoc()); - const CXXRecordDecl *Lambda = MD->getParent(); const CXXMethodDecl *CallOp = Lambda->getLambdaCallOperator(); // For a generic lambda, find the corresponding call operator specialization // to which the call to the static-invoker shall be forwarded. @@ -3042,21 +3026,10 @@ void CodeGenFunction::EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD, assert(CorrespondingCallOpSpecialization); CallOp = cast<CXXMethodDecl>(CorrespondingCallOpSpecialization); } - - // Special lambda forwarding when there are inalloca parameters. - if (hasInAllocaArg(MD)) { - const CGFunctionInfo *ImplFnInfo = nullptr; - llvm::Function *ImplFn = nullptr; - EmitLambdaInAllocaImplFn(CallOp, &ImplFnInfo, &ImplFn); - - EmitForwardingCallToLambda(CallOp, CallArgs, ImplFnInfo, ImplFn); - return; - } - EmitForwardingCallToLambda(CallOp, CallArgs); } -void CodeGenFunction::EmitLambdaInAllocaCallOpBody(const CXXMethodDecl *MD) { +void CodeGenFunction::EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD) { if (MD->isVariadic()) { // FIXME: Making this work correctly is nasty because it requires either // cloning the body of the call operator or making the call operator forward. @@ -3064,49 +3037,5 @@ void CodeGenFunction::EmitLambdaInAllocaCallOpBody(const CXXMethodDecl *MD) { return; } - // Forward %this argument. - CallArgList CallArgs; - QualType LambdaType = getContext().getRecordType(MD->getParent()); - QualType ThisType = getContext().getPointerType(LambdaType); - llvm::Value *ThisArg = CurFn->getArg(0); - CallArgs.add(RValue::get(ThisArg), ThisType); - - EmitLambdaDelegatingInvokeBody(MD, CallArgs); -} - -void CodeGenFunction::EmitLambdaInAllocaImplFn( - const CXXMethodDecl *CallOp, const CGFunctionInfo **ImplFnInfo, - llvm::Function **ImplFn) { - const CGFunctionInfo &FnInfo = - CGM.getTypes().arrangeCXXMethodDeclaration(CallOp); - llvm::Function *CallOpFn = - cast<llvm::Function>(CGM.GetAddrOfFunction(GlobalDecl(CallOp))); - - // Emit function containing the original call op body. __invoke will delegate - // to this function. - SmallVector<CanQualType, 4> ArgTypes; - for (auto I = FnInfo.arg_begin(); I != FnInfo.arg_end(); ++I) - ArgTypes.push_back(I->type); - *ImplFnInfo = &CGM.getTypes().arrangeLLVMFunctionInfo( - FnInfo.getReturnType(), FnInfoOpts::IsDelegateCall, ArgTypes, - FnInfo.getExtInfo(), {}, FnInfo.getRequiredArgs()); - - // Create mangled name as if this was a method named __impl. - StringRef CallOpName = CallOpFn->getName(); - std::string ImplName = - ("?__impl@" + CallOpName.drop_front(CallOpName.find_first_of("<"))).str(); - - llvm::Function *Fn = CallOpFn->getParent()->getFunction(ImplName); - if (!Fn) { - Fn = llvm::Function::Create(CGM.getTypes().GetFunctionType(**ImplFnInfo), - llvm::GlobalValue::InternalLinkage, ImplName, - CGM.getModule()); - CGM.SetInternalFunctionAttributes(CallOp, Fn, **ImplFnInfo); - - const GlobalDecl &GD = GlobalDecl(CallOp); - const auto *D = cast<FunctionDecl>(GD.getDecl()); - CodeGenFunction(CGM).GenerateCode(GD, Fn, **ImplFnInfo); - CGM.SetLLVMFunctionAttributesForDefinition(D, Fn); - } - *ImplFn = Fn; + EmitLambdaDelegatingInvokeBody(MD); } |