diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -370,8 +370,7 @@ /*RefersToEnclosingVariableOrCapture=*/false, VD->getType().getNonReferenceType(), VK_LValue, C.getLocation()); - PrivScope.addPrivate( - VD, [&CGF, &DRE]() { return CGF.EmitLValue(&DRE).getAddress(CGF); }); + PrivScope.addPrivate(VD, CGF.EmitLValue(&DRE).getAddress(CGF)); } (void)PrivScope.Privatize(); } @@ -634,10 +633,8 @@ const auto *RHSDRE = cast(cast(RHS)->getSubExpr()); CodeGenFunction::OMPPrivateScope PrivateScope(CGF); - PrivateScope.addPrivate(cast(LHSDRE->getDecl()), - [=]() { return Private; }); - PrivateScope.addPrivate(cast(RHSDRE->getDecl()), - [=]() { return Original; }); + PrivateScope.addPrivate(cast(LHSDRE->getDecl()), Private); + PrivateScope.addPrivate(cast(RHSDRE->getDecl()), Original); (void)PrivateScope.Privatize(); RValue Func = RValue::get(Reduction.second); CodeGenFunction::OpaqueValueMapping Map(CGF, OVE, Func); @@ -1141,15 +1138,13 @@ Out->getLocation()); CodeGenFunction::OMPPrivateScope Scope(CGF); Address AddrIn = CGF.GetAddrOfLocalVar(&OmpInParm); - Scope.addPrivate(In, [&CGF, AddrIn, PtrTy]() { - return CGF.EmitLoadOfPointerLValue(AddrIn, PtrTy->castAs()) - .getAddress(CGF); - }); + Scope.addPrivate( + In, CGF.EmitLoadOfPointerLValue(AddrIn, PtrTy->castAs()) + .getAddress(CGF)); Address AddrOut = CGF.GetAddrOfLocalVar(&OmpOutParm); - Scope.addPrivate(Out, [&CGF, AddrOut, PtrTy]() { - return CGF.EmitLoadOfPointerLValue(AddrOut, PtrTy->castAs()) - .getAddress(CGF); - }); + Scope.addPrivate( + Out, CGF.EmitLoadOfPointerLValue(AddrOut, PtrTy->castAs()) + .getAddress(CGF)); (void)Scope.Privatize(); if (!IsCombiner && Out->hasInit() && !CGF.isTrivialInitializer(Out->getInit())) { @@ -3938,8 +3933,7 @@ Address SrcElement) { // Clean up any temporaries needed by the initialization. CodeGenFunction::OMPPrivateScope InitScope(CGF); - InitScope.addPrivate( - Elem, [SrcElement]() -> Address { return SrcElement; }); + InitScope.addPrivate(Elem, SrcElement); (void)InitScope.Privatize(); // Emit initialization for single element. CodeGenFunction::CGCapturedStmtRAII CapInfoRAII( @@ -3951,9 +3945,7 @@ } } else { CodeGenFunction::OMPPrivateScope InitScope(CGF); - InitScope.addPrivate(Elem, [SharedRefLValue, &CGF]() -> Address { - return SharedRefLValue.getAddress(CGF); - }); + InitScope.addPrivate(Elem, SharedRefLValue.getAddress(CGF)); (void)InitScope.Privatize(); CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CapturesInfo); CGF.EmitExprAsInit(Init, VD, PrivateLValue, @@ -4099,14 +4091,11 @@ for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) { Uppers.push_back(CGF.EmitScalarExpr(E->getHelper(I).Upper)); const auto *VD = cast(E->getIteratorDecl(I)); - addPrivate(VD, [&CGF, VD]() { - return CGF.CreateMemTemp(VD->getType(), VD->getName()); - }); + addPrivate(VD, CGF.CreateMemTemp(VD->getType(), VD->getName())); const OMPIteratorHelperData &HelperData = E->getHelper(I); - addPrivate(HelperData.CounterVD, [&CGF, &HelperData]() { - return CGF.CreateMemTemp(HelperData.CounterVD->getType(), - "counter.addr"); - }); + addPrivate( + HelperData.CounterVD, + CGF.CreateMemTemp(HelperData.CounterVD->getType(), "counter.addr")); } Privatize(); @@ -5397,8 +5386,8 @@ // Emit copy. CodeGenFunction::OMPPrivateScope Scope(CGF); - Scope.addPrivate(LHSVar, [=]() { return LHSElementCurrent; }); - Scope.addPrivate(RHSVar, [=]() { return RHSElementCurrent; }); + Scope.addPrivate(LHSVar, LHSElementCurrent); + Scope.addPrivate(RHSVar, RHSElementCurrent); Scope.Privatize(); RedOpGen(CGF, XExpr, EExpr, UpExpr); Scope.ForceCleanup(); @@ -5487,14 +5476,10 @@ for (unsigned I = 0, E = ReductionOps.size(); I < E; ++I, ++IPriv, ++Idx) { const auto *RHSVar = cast(cast(RHSExprs[I])->getDecl()); - Scope.addPrivate(RHSVar, [&CGF, RHS, Idx, RHSVar]() { - return emitAddrOfVarFromArray(CGF, RHS, Idx, RHSVar); - }); + Scope.addPrivate(RHSVar, emitAddrOfVarFromArray(CGF, RHS, Idx, RHSVar)); const auto *LHSVar = cast(cast(LHSExprs[I])->getDecl()); - Scope.addPrivate(LHSVar, [&CGF, LHS, Idx, LHSVar]() { - return emitAddrOfVarFromArray(CGF, LHS, Idx, LHSVar); - }); + Scope.addPrivate(LHSVar, emitAddrOfVarFromArray(CGF, LHS, Idx, LHSVar)); QualType PrivTy = (*IPriv)->getType(); if (PrivTy->isVariablyModifiedType()) { // Get array size and emit VLA type. @@ -5789,14 +5774,11 @@ llvm::AtomicOrdering::Monotonic, Loc, [&CGF, UpExpr, VD, Loc](RValue XRValue) { CodeGenFunction::OMPPrivateScope PrivateScope(CGF); - PrivateScope.addPrivate( - VD, [&CGF, VD, XRValue, Loc]() { - Address LHSTemp = CGF.CreateMemTemp(VD->getType()); - CGF.emitOMPSimpleStore( - CGF.MakeAddrLValue(LHSTemp, VD->getType()), XRValue, - VD->getType().getNonReferenceType(), Loc); - return LHSTemp; - }); + Address LHSTemp = CGF.CreateMemTemp(VD->getType()); + CGF.emitOMPSimpleStore( + CGF.MakeAddrLValue(LHSTemp, VD->getType()), XRValue, + VD->getType().getNonReferenceType(), Loc); + PrivateScope.addPrivate(VD, LHSTemp); (void)PrivateScope.Privatize(); return CGF.EmitAnyExpr(UpExpr); }); @@ -5996,22 +5978,22 @@ // %lhs = bitcast void* %arg0 to * // %rhs = bitcast void* %arg1 to * CodeGenFunction::OMPPrivateScope PrivateScope(CGF); - PrivateScope.addPrivate(LHSVD, [&C, &CGF, &ParamInOut, LHSVD]() { - // Pull out the pointer to the variable. - Address PtrAddr = CGF.EmitLoadOfPointer( - CGF.GetAddrOfLocalVar(&ParamInOut), - C.getPointerType(C.VoidPtrTy).castAs()); - return CGF.Builder.CreateElementBitCast( - PtrAddr, CGF.ConvertTypeForMem(LHSVD->getType())); - }); - PrivateScope.addPrivate(RHSVD, [&C, &CGF, &ParamIn, RHSVD]() { - // Pull out the pointer to the variable. - Address PtrAddr = CGF.EmitLoadOfPointer( - CGF.GetAddrOfLocalVar(&ParamIn), - C.getPointerType(C.VoidPtrTy).castAs()); - return CGF.Builder.CreateElementBitCast( - PtrAddr, CGF.ConvertTypeForMem(RHSVD->getType())); - }); + PrivateScope.addPrivate( + LHSVD, + // Pull out the pointer to the variable. + CGF.Builder.CreateElementBitCast( + CGF.EmitLoadOfPointer( + CGF.GetAddrOfLocalVar(&ParamInOut), + C.getPointerType(C.VoidPtrTy).castAs()), + CGF.ConvertTypeForMem(LHSVD->getType()))); + PrivateScope.addPrivate( + RHSVD, + // Pull out the pointer to the variable. + CGF.Builder.CreateElementBitCast( + CGF.EmitLoadOfPointer( + CGF.GetAddrOfLocalVar(&ParamIn), + C.getPointerType(C.VoidPtrTy).castAs()), + CGF.ConvertTypeForMem(RHSVD->getType()))); PrivateScope.Privatize(); // Emit the combiner body: // %2 = ( *%lhs, *%rhs) @@ -10101,7 +10083,7 @@ .alignmentOfArrayElement(ElementSize)); // Privatize the declared variable of mapper to be the current array element. CodeGenFunction::OMPPrivateScope Scope(MapperCGF); - Scope.addPrivate(MapperVarDecl, [PtrCurrent]() { return PtrCurrent; }); + Scope.addPrivate(MapperVarDecl, PtrCurrent); (void)Scope.Privatize(); // Get map clause information. Fill up the arrays with all mapped variables. diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -95,9 +95,7 @@ isCapturedVar(CGF, VD) || (CGF.CapturedStmtInfo && InlinedShareds.isGlobalVarCaptured(VD)), VD->getType().getNonReferenceType(), VK_LValue, C.getLocation()); - InlinedShareds.addPrivate(VD, [&CGF, &DRE]() -> Address { - return CGF.EmitLValue(&DRE).getAddress(CGF); - }); + InlinedShareds.addPrivate(VD, CGF.EmitLValue(&DRE).getAddress(CGF)); } } (void)InlinedShareds.Privatize(); @@ -273,9 +271,7 @@ InlinedShareds.isGlobalVarCaptured(VD)), VD->getType().getNonReferenceType(), VK_LValue, C.getLocation()); - InlinedShareds.addPrivate(VD, [&CGF, &DRE]() -> Address { - return CGF.EmitLValue(&DRE).getAddress(CGF); - }); + InlinedShareds.addPrivate(VD, CGF.EmitLValue(&DRE).getAddress(CGF)); } } CS = dyn_cast(CS->getCapturedStmt()); @@ -630,9 +626,8 @@ CodeGenFunction::OMPPrivateScope LocalScope(*this); for (const auto &LocalAddrPair : LocalAddrs) { if (LocalAddrPair.second.first) { - LocalScope.addPrivate(LocalAddrPair.second.first, [&LocalAddrPair]() { - return LocalAddrPair.second.second; - }); + LocalScope.addPrivate(LocalAddrPair.second.first, + LocalAddrPair.second.second); } } (void)LocalScope.Privatize(); @@ -779,8 +774,8 @@ // destination and source variables to corresponding array // elements. CodeGenFunction::OMPPrivateScope Remap(*this); - Remap.addPrivate(DestVD, [DestElement]() { return DestElement; }); - Remap.addPrivate(SrcVD, [SrcElement]() { return SrcElement; }); + Remap.addPrivate(DestVD, DestElement); + Remap.addPrivate(SrcVD, SrcElement); (void)Remap.Privatize(); EmitIgnoredExpr(Copy); }); @@ -788,8 +783,8 @@ } else { // Remap pseudo source variable to private copy. CodeGenFunction::OMPPrivateScope Remap(*this); - Remap.addPrivate(SrcVD, [SrcAddr]() { return SrcAddr; }); - Remap.addPrivate(DestVD, [DestAddr]() { return DestAddr; }); + Remap.addPrivate(SrcVD, SrcAddr); + Remap.addPrivate(DestVD, DestAddr); (void)Remap.Privatize(); // Emit copying of the whole variable. EmitIgnoredExpr(Copy); @@ -878,68 +873,56 @@ // Emit VarDecl with copy init for arrays. // Get the address of the original variable captured in current // captured region. - IsRegistered = PrivateScope.addPrivate( - OrigVD, [this, VD, Type, OriginalLVal, VDInit]() { - AutoVarEmission Emission = EmitAutoVarAlloca(*VD); - const Expr *Init = VD->getInit(); - if (!isa(Init) || - isTrivialInitializer(Init)) { - // Perform simple memcpy. - LValue Dest = - MakeAddrLValue(Emission.getAllocatedAddress(), Type); - EmitAggregateAssign(Dest, OriginalLVal, Type); - } else { - EmitOMPAggregateAssign( - Emission.getAllocatedAddress(), - OriginalLVal.getAddress(*this), Type, - [this, VDInit, Init](Address DestElement, - Address SrcElement) { - // Clean up any temporaries needed by the - // initialization. - RunCleanupsScope InitScope(*this); - // Emit initialization for single element. - setAddrOfLocalVar(VDInit, SrcElement); - EmitAnyExprToMem(Init, DestElement, - Init->getType().getQualifiers(), - /*IsInitializer*/ false); - LocalDeclMap.erase(VDInit); - }); - } - EmitAutoVarCleanups(Emission); - return Emission.getAllocatedAddress(); - }); + AutoVarEmission Emission = EmitAutoVarAlloca(*VD); + const Expr *Init = VD->getInit(); + if (!isa(Init) || isTrivialInitializer(Init)) { + // Perform simple memcpy. + LValue Dest = MakeAddrLValue(Emission.getAllocatedAddress(), Type); + EmitAggregateAssign(Dest, OriginalLVal, Type); + } else { + EmitOMPAggregateAssign( + Emission.getAllocatedAddress(), OriginalLVal.getAddress(*this), + Type, + [this, VDInit, Init](Address DestElement, Address SrcElement) { + // Clean up any temporaries needed by the + // initialization. + RunCleanupsScope InitScope(*this); + // Emit initialization for single element. + setAddrOfLocalVar(VDInit, SrcElement); + EmitAnyExprToMem(Init, DestElement, + Init->getType().getQualifiers(), + /*IsInitializer*/ false); + LocalDeclMap.erase(VDInit); + }); + } + EmitAutoVarCleanups(Emission); + IsRegistered = + PrivateScope.addPrivate(OrigVD, Emission.getAllocatedAddress()); } else { Address OriginalAddr = OriginalLVal.getAddress(*this); - IsRegistered = - PrivateScope.addPrivate(OrigVD, [this, VDInit, OriginalAddr, VD, - ThisFirstprivateIsLastprivate, - OrigVD, &Lastprivates, IRef]() { - // Emit private VarDecl with copy init. - // Remap temp VDInit variable to the address of the original - // variable (for proper handling of captured global variables). - setAddrOfLocalVar(VDInit, OriginalAddr); - EmitDecl(*VD); - LocalDeclMap.erase(VDInit); - if (ThisFirstprivateIsLastprivate && - Lastprivates[OrigVD->getCanonicalDecl()] == - OMPC_LASTPRIVATE_conditional) { - // Create/init special variable for lastprivate conditionals. - Address VDAddr = - CGM.getOpenMPRuntime().emitLastprivateConditionalInit( - *this, OrigVD); - llvm::Value *V = EmitLoadOfScalar( - MakeAddrLValue(GetAddrOfLocalVar(VD), (*IRef)->getType(), - AlignmentSource::Decl), - (*IRef)->getExprLoc()); - EmitStoreOfScalar(V, - MakeAddrLValue(VDAddr, (*IRef)->getType(), - AlignmentSource::Decl)); - LocalDeclMap.erase(VD); - setAddrOfLocalVar(VD, VDAddr); - return VDAddr; - } - return GetAddrOfLocalVar(VD); - }); + // Emit private VarDecl with copy init. + // Remap temp VDInit variable to the address of the original + // variable (for proper handling of captured global variables). + setAddrOfLocalVar(VDInit, OriginalAddr); + EmitDecl(*VD); + LocalDeclMap.erase(VDInit); + Address VDAddr = GetAddrOfLocalVar(VD); + if (ThisFirstprivateIsLastprivate && + Lastprivates[OrigVD->getCanonicalDecl()] == + OMPC_LASTPRIVATE_conditional) { + // Create/init special variable for lastprivate conditionals. + llvm::Value *V = + EmitLoadOfScalar(MakeAddrLValue(VDAddr, (*IRef)->getType(), + AlignmentSource::Decl), + (*IRef)->getExprLoc()); + VDAddr = CGM.getOpenMPRuntime().emitLastprivateConditionalInit( + *this, OrigVD); + EmitStoreOfScalar(V, MakeAddrLValue(VDAddr, (*IRef)->getType(), + AlignmentSource::Decl)); + LocalDeclMap.erase(VD); + setAddrOfLocalVar(VD, VDAddr); + } + IsRegistered = PrivateScope.addPrivate(OrigVD, VDAddr); } assert(IsRegistered && "firstprivate var already registered as private"); @@ -965,11 +948,10 @@ const auto *OrigVD = cast(cast(*IRef)->getDecl()); if (EmittedAsPrivate.insert(OrigVD->getCanonicalDecl()).second) { const auto *VD = cast(cast(IInit)->getDecl()); - bool IsRegistered = PrivateScope.addPrivate(OrigVD, [this, VD]() { - // Emit private VarDecl with copy init. - EmitDecl(*VD); - return GetAddrOfLocalVar(VD); - }); + EmitDecl(*VD); + // Emit private VarDecl with copy init. + bool IsRegistered = + PrivateScope.addPrivate(OrigVD, GetAddrOfLocalVar(VD)); assert(IsRegistered && "private var already registered as private"); // Silence the warning about unused variable. (void)IsRegistered; @@ -1080,31 +1062,27 @@ if (AlreadyEmittedVars.insert(OrigVD->getCanonicalDecl()).second) { const auto *DestVD = cast(cast(*IDestRef)->getDecl()); - PrivateScope.addPrivate(DestVD, [this, OrigVD, IRef]() { - DeclRefExpr DRE(getContext(), const_cast(OrigVD), - /*RefersToEnclosingVariableOrCapture=*/ - CapturedStmtInfo->lookup(OrigVD) != nullptr, - (*IRef)->getType(), VK_LValue, (*IRef)->getExprLoc()); - return EmitLValue(&DRE).getAddress(*this); - }); + DeclRefExpr DRE(getContext(), const_cast(OrigVD), + /*RefersToEnclosingVariableOrCapture=*/ + CapturedStmtInfo->lookup(OrigVD) != nullptr, + (*IRef)->getType(), VK_LValue, (*IRef)->getExprLoc()); + PrivateScope.addPrivate(DestVD, EmitLValue(&DRE).getAddress(*this)); // Check if the variable is also a firstprivate: in this case IInit is // not generated. Initialization of this variable will happen in codegen // for 'firstprivate' clause. if (IInit && !SIMDLCVs.count(OrigVD->getCanonicalDecl())) { const auto *VD = cast(cast(IInit)->getDecl()); - bool IsRegistered = - PrivateScope.addPrivate(OrigVD, [this, VD, C, OrigVD]() { - if (C->getKind() == OMPC_LASTPRIVATE_conditional) { - Address VDAddr = - CGM.getOpenMPRuntime().emitLastprivateConditionalInit( - *this, OrigVD); - setAddrOfLocalVar(VD, VDAddr); - return VDAddr; - } - // Emit private VarDecl with copy init. - EmitDecl(*VD); - return GetAddrOfLocalVar(VD); - }); + Address VDAddr = Address::invalid(); + if (C->getKind() == OMPC_LASTPRIVATE_conditional) { + VDAddr = CGM.getOpenMPRuntime().emitLastprivateConditionalInit( + *this, OrigVD); + setAddrOfLocalVar(VD, VDAddr); + } else { + // Emit private VarDecl with copy init. + EmitDecl(*VD); + VDAddr = GetAddrOfLocalVar(VD); + } + bool IsRegistered = PrivateScope.addPrivate(OrigVD, VDAddr); assert(IsRegistered && "lastprivate var already registered as private"); (void)IsRegistered; @@ -1258,8 +1236,8 @@ EmitAutoVarCleanups(Emission); Address BaseAddr = RedCG.adjustPrivateAddress( *this, Count, Emission.getAllocatedAddress()); - bool IsRegistered = PrivateScope.addPrivate( - RedCG.getBaseDecl(Count), [BaseAddr]() { return BaseAddr; }); + bool IsRegistered = + PrivateScope.addPrivate(RedCG.getBaseDecl(Count), BaseAddr); assert(IsRegistered && "private var already registered as private"); // Silence the warning about unused variable. (void)IsRegistered; @@ -1271,23 +1249,19 @@ if (isaOMPArraySectionExpr && Type->isVariablyModifiedType()) { // Store the address of the original variable associated with the LHS // implicit variable. - PrivateScope.addPrivate(LHSVD, [&RedCG, Count, this]() { - return RedCG.getSharedLValue(Count).getAddress(*this); - }); - PrivateScope.addPrivate( - RHSVD, [this, PrivateVD]() { return GetAddrOfLocalVar(PrivateVD); }); + PrivateScope.addPrivate(LHSVD, + RedCG.getSharedLValue(Count).getAddress(*this)); + PrivateScope.addPrivate(RHSVD, GetAddrOfLocalVar(PrivateVD)); } else if ((isaOMPArraySectionExpr && Type->isScalarType()) || isa(IRef)) { // Store the address of the original variable associated with the LHS // implicit variable. - PrivateScope.addPrivate(LHSVD, [&RedCG, Count, this]() { - return RedCG.getSharedLValue(Count).getAddress(*this); - }); - PrivateScope.addPrivate(RHSVD, [this, PrivateVD, RHSVD]() { - return Builder.CreateElementBitCast(GetAddrOfLocalVar(PrivateVD), - ConvertTypeForMem(RHSVD->getType()), - "rhs.begin"); - }); + PrivateScope.addPrivate(LHSVD, + RedCG.getSharedLValue(Count).getAddress(*this)); + PrivateScope.addPrivate(RHSVD, Builder.CreateElementBitCast( + GetAddrOfLocalVar(PrivateVD), + ConvertTypeForMem(RHSVD->getType()), + "rhs.begin")); } else { QualType Type = PrivateVD->getType(); bool IsArray = getContext().getAsArrayType(Type) != nullptr; @@ -1298,13 +1272,12 @@ OriginalAddr = Builder.CreateElementBitCast( OriginalAddr, ConvertTypeForMem(LHSVD->getType()), "lhs.begin"); } - PrivateScope.addPrivate(LHSVD, [OriginalAddr]() { return OriginalAddr; }); - PrivateScope.addPrivate(RHSVD, [this, PrivateVD, RHSVD, IsArray]() { - return IsArray ? Builder.CreateElementBitCast( - GetAddrOfLocalVar(PrivateVD), - ConvertTypeForMem(RHSVD->getType()), "rhs.begin") - : GetAddrOfLocalVar(PrivateVD); - }); + PrivateScope.addPrivate(LHSVD, OriginalAddr); + PrivateScope.addPrivate( + RHSVD, IsArray ? Builder.CreateElementBitCast( + GetAddrOfLocalVar(PrivateVD), + ConvertTypeForMem(RHSVD->getType()), "rhs.begin") + : GetAddrOfLocalVar(PrivateVD)); } ++ILHS; ++IRHS; @@ -2183,7 +2156,7 @@ (*IC)->getType(), VK_LValue, (*IC)->getExprLoc()); Address OrigAddr = EmitLValue(&DRE).getAddress(*this); CodeGenFunction::OMPPrivateScope VarScope(*this); - VarScope.addPrivate(OrigVD, [OrigAddr]() { return OrigAddr; }); + VarScope.addPrivate(OrigVD, OrigAddr); (void)VarScope.Privatize(); EmitIgnoredExpr(F); ++IC; @@ -2242,20 +2215,15 @@ AutoVarEmission VarEmission = EmitAutoVarAlloca(*PrivateVD); EmitAutoVarCleanups(VarEmission); LocalDeclMap.erase(PrivateVD); - (void)LoopScope.addPrivate( - VD, [&VarEmission]() { return VarEmission.getAllocatedAddress(); }); + (void)LoopScope.addPrivate(VD, VarEmission.getAllocatedAddress()); if (LocalDeclMap.count(VD) || CapturedStmtInfo->lookup(VD) || VD->hasGlobalStorage()) { - (void)LoopScope.addPrivate(PrivateVD, [this, VD, E]() { - DeclRefExpr DRE(getContext(), const_cast(VD), - LocalDeclMap.count(VD) || CapturedStmtInfo->lookup(VD), - E->getType(), VK_LValue, E->getExprLoc()); - return EmitLValue(&DRE).getAddress(*this); - }); + DeclRefExpr DRE(getContext(), const_cast(VD), + LocalDeclMap.count(VD) || CapturedStmtInfo->lookup(VD), + E->getType(), VK_LValue, E->getExprLoc()); + (void)LoopScope.addPrivate(PrivateVD, EmitLValue(&DRE).getAddress(*this)); } else { - (void)LoopScope.addPrivate(PrivateVD, [&VarEmission]() { - return VarEmission.getAllocatedAddress(); - }); + (void)LoopScope.addPrivate(PrivateVD, VarEmission.getAllocatedAddress()); } ++I; } @@ -2270,9 +2238,8 @@ // Override only those variables that can be captured to avoid re-emission // of the variables declared within the loops. if (DRE->refersToEnclosingVariableOrCapture()) { - (void)LoopScope.addPrivate(VD, [this, DRE, VD]() { - return CreateMemTemp(DRE->getType(), VD->getName()); - }); + (void)LoopScope.addPrivate( + VD, CreateMemTemp(DRE->getType(), VD->getName())); } } } @@ -2335,11 +2302,10 @@ const auto *PrivateVD = cast(cast(*CurPrivate)->getDecl()); if (!SIMDLCVs.count(VD->getCanonicalDecl())) { - bool IsRegistered = PrivateScope.addPrivate(VD, [this, PrivateVD]() { - // Emit private VarDecl with copy init. - EmitVarDecl(*PrivateVD); - return GetAddrOfLocalVar(PrivateVD); - }); + // Emit private VarDecl with copy init. + EmitVarDecl(*PrivateVD); + bool IsRegistered = + PrivateScope.addPrivate(VD, GetAddrOfLocalVar(PrivateVD)); assert(IsRegistered && "linear var already registered as private"); // Silence the warning about unused variable. (void)IsRegistered; @@ -2430,7 +2396,7 @@ OrigAddr = EmitLValue(&DRE).getAddress(*this); } OMPPrivateScope VarScope(*this); - VarScope.addPrivate(OrigVD, [OrigAddr]() { return OrigAddr; }); + VarScope.addPrivate(OrigVD, OrigAddr); (void)VarScope.Privatize(); EmitIgnoredExpr(F); } @@ -3619,7 +3585,7 @@ RValue::get(IVal)); LHSAddr = CGF.EmitLValue(CopyArrayElem).getAddress(CGF); } - PrivScope.addPrivate(LHSVD, [LHSAddr]() { return LHSAddr; }); + PrivScope.addPrivate(LHSVD, LHSAddr); Address RHSAddr = Address::invalid(); { llvm::Value *OffsetIVal = CGF.Builder.CreateNUWSub(IVal, Pow2K); @@ -3630,7 +3596,7 @@ RValue::get(OffsetIVal)); RHSAddr = CGF.EmitLValue(CopyArrayElem).getAddress(CGF); } - PrivScope.addPrivate(RHSVD, [RHSAddr]() { return RHSAddr; }); + PrivScope.addPrivate(RHSVD, RHSAddr); ++ILHS; ++IRHS; } @@ -4665,15 +4631,13 @@ CGF.CapturedStmtInfo->lookup(OrigVD) != nullptr, Pair.second->getType(), VK_LValue, Pair.second->getExprLoc()); - Scope.addPrivate(Pair.first, [&CGF, &DRE]() { - return CGF.EmitLValue(&DRE).getAddress(CGF); - }); + Scope.addPrivate(Pair.first, CGF.EmitLValue(&DRE).getAddress(CGF)); } for (const auto &Pair : PrivatePtrs) { Address Replacement = Address::deprecated(CGF.Builder.CreateLoad(Pair.second), CGF.getContext().getDeclAlign(Pair.first)); - Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; }); + Scope.addPrivate(Pair.first, Replacement); if (auto *DI = CGF.getDebugInfo()) if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo()) (void)DI->EmitDeclareOfAutoVariable( @@ -4705,8 +4669,7 @@ Address Replacement = Address::deprecated(CGF.Builder.CreateLoad(Pair.second), CGF.getContext().getDeclAlign(Pair.first)); - FirstprivateScope.addPrivate(Pair.first, - [Replacement]() { return Replacement; }); + FirstprivateScope.addPrivate(Pair.first, Replacement); } (void)FirstprivateScope.Privatize(); OMPLexicalScope LexScope(CGF, S, CapturedRegion); @@ -4732,8 +4695,7 @@ Data.ReductionCopies[Cnt]->getExprLoc()), Replacement.getAlignment()); Replacement = RedCG.adjustPrivateAddress(CGF, Cnt, Replacement); - Scope.addPrivate(RedCG.getBaseDecl(Cnt), - [Replacement]() { return Replacement; }); + Scope.addPrivate(RedCG.getBaseDecl(Cnt), Replacement); } } // Privatize all private variables except for in_reduction items. @@ -4787,8 +4749,7 @@ InRedPrivs[Cnt]->getExprLoc()), Replacement.getAlignment()); Replacement = RedCG.adjustPrivateAddress(CGF, Cnt, Replacement); - InRedScope.addPrivate(RedCG.getBaseDecl(Cnt), - [Replacement]() { return Replacement; }); + InRedScope.addPrivate(RedCG.getBaseDecl(Cnt), Replacement); } } (void)InRedScope.Privatize(); @@ -4884,20 +4845,16 @@ /*IndexTypeQuals=*/0); SVD = createImplicitFirstprivateForType(getContext(), Data, SizesType, CD, S.getBeginLoc()); - TargetScope.addPrivate( - BPVD, [&InputInfo]() { return InputInfo.BasePointersArray; }); - TargetScope.addPrivate(PVD, - [&InputInfo]() { return InputInfo.PointersArray; }); - TargetScope.addPrivate(SVD, - [&InputInfo]() { return InputInfo.SizesArray; }); + TargetScope.addPrivate(BPVD, InputInfo.BasePointersArray); + TargetScope.addPrivate(PVD, InputInfo.PointersArray); + TargetScope.addPrivate(SVD, InputInfo.SizesArray); // If there is no user-defined mapper, the mapper array will be nullptr. In // this case, we don't need to privatize it. if (!isa_and_nonnull( InputInfo.MappersArray.getPointer())) { MVD = createImplicitFirstprivateForType( getContext(), Data, BaseAndPointerAndMapperType, CD, S.getBeginLoc()); - TargetScope.addPrivate(MVD, - [&InputInfo]() { return InputInfo.MappersArray; }); + TargetScope.addPrivate(MVD, InputInfo.MappersArray); } } (void)TargetScope.Privatize(); @@ -4942,7 +4899,7 @@ Address Replacement = Address::deprecated(CGF.Builder.CreateLoad(Pair.second), CGF.getContext().getDeclAlign(Pair.first)); - Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; }); + Scope.addPrivate(Pair.first, Replacement); } } // Privatize all private variables except for in_reduction items. @@ -6923,30 +6880,26 @@ if (InitAddrIt == CaptureDeviceAddrMap.end()) continue; - bool IsRegistered = PrivateScope.addPrivate( - OrigVD, [this, OrigVD, InitAddrIt, InitVD, PvtVD]() { - // Initialize the temporary initialization variable with the address - // we get from the runtime library. We have to cast the source address - // because it is always a void *. References are materialized in the - // privatization scope, so the initialization here disregards the fact - // the original variable is a reference. - llvm::Type *Ty = - ConvertTypeForMem(OrigVD->getType().getNonReferenceType()); - Address InitAddr = - Builder.CreateElementBitCast(InitAddrIt->second, Ty); - setAddrOfLocalVar(InitVD, InitAddr); - - // Emit private declaration, it will be initialized by the value we - // declaration we just added to the local declarations map. - EmitDecl(*PvtVD); - - // The initialization variables reached its purpose in the emission - // of the previous declaration, so we don't need it anymore. - LocalDeclMap.erase(InitVD); - - // Return the address of the private variable. - return GetAddrOfLocalVar(PvtVD); - }); + // Initialize the temporary initialization variable with the address + // we get from the runtime library. We have to cast the source address + // because it is always a void *. References are materialized in the + // privatization scope, so the initialization here disregards the fact + // the original variable is a reference. + llvm::Type *Ty = ConvertTypeForMem(OrigVD->getType().getNonReferenceType()); + Address InitAddr = Builder.CreateElementBitCast(InitAddrIt->second, Ty); + setAddrOfLocalVar(InitVD, InitAddr); + + // Emit private declaration, it will be initialized by the value we + // declaration we just added to the local declarations map. + EmitDecl(*PvtVD); + + // The initialization variables reached its purpose in the emission + // of the previous declaration, so we don't need it anymore. + LocalDeclMap.erase(InitVD); + + // Return the address of the private variable. + bool IsRegistered = + PrivateScope.addPrivate(OrigVD, GetAddrOfLocalVar(PvtVD)); assert(IsRegistered && "firstprivate var already registered as private"); // Silence the warning about unused variable. (void)IsRegistered; @@ -7007,7 +6960,7 @@ PrivAddr = Builder.CreatePointerBitCastOrAddrSpaceCast(PrivAddr, RealTy, RealElTy); - (void)PrivateScope.addPrivate(OrigVD, [PrivAddr]() { return PrivAddr; }); + (void)PrivateScope.addPrivate(OrigVD, PrivAddr); } } @@ -7279,8 +7232,7 @@ const ImplicitParamDecl *PVD, CodeGenFunction::OMPPrivateScope &Privates) { const auto *VDecl = cast(Helper->getDecl()); - Privates.addPrivate(VDecl, - [&CGF, PVD]() { return CGF.GetAddrOfLocalVar(PVD); }); + Privates.addPrivate(VDecl, CGF.GetAddrOfLocalVar(PVD)); } void CodeGenFunction::EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S) { @@ -7572,8 +7524,7 @@ continue; if (!CGF.LocalDeclMap.count(VD)) { LValue GlobLVal = CGF.EmitLValue(Ref); - GlobalsScope.addPrivate( - VD, [&GlobLVal, &CGF]() { return GlobLVal.getAddress(CGF); }); + GlobalsScope.addPrivate(VD, GlobLVal.getAddress(CGF)); } } } @@ -7588,8 +7539,7 @@ const auto *VD = cast(cast(E)->getDecl()); if (!VD->hasLocalStorage() && !CGF.LocalDeclMap.count(VD)) { LValue GlobLVal = CGF.EmitLValue(E); - GlobalsScope.addPrivate( - VD, [&GlobLVal, &CGF]() { return GlobLVal.getAddress(CGF); }); + GlobalsScope.addPrivate(VD, GlobLVal.getAddress(CGF)); } if (isa(VD)) { // Emit only those that were not explicitly referenced in clauses. diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1068,15 +1068,14 @@ /// Enter a new OpenMP private scope. explicit OMPPrivateScope(CodeGenFunction &CGF) : RunCleanupsScope(CGF) {} - /// Registers \p LocalVD variable as a private and apply \p PrivateGen - /// function for it to generate corresponding private variable. \p - /// PrivateGen returns an address of the generated private variable. + /// Registers \p LocalVD variable as a private with \p Addr as the address + /// of the corresponding private variable. \p + /// PrivateGen is the address of the generated private variable. /// \return true if the variable is registered as private, false if it has /// been privatized already. - bool addPrivate(const VarDecl *LocalVD, - const llvm::function_ref PrivateGen) { + bool addPrivate(const VarDecl *LocalVD, Address Addr) { assert(PerformCleanup && "adding private to dead scope"); - return MappedVars.setVarAddr(CGF, LocalVD, PrivateGen()); + return MappedVars.setVarAddr(CGF, LocalVD, Addr); } /// Privatizes local variables previously registered as private.