@@ -644,27 +644,42 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S,
644
644
// Build the argument list.
645
645
bool NeedWrapperFunction =
646
646
getDebugInfo () && CGM.getCodeGenOpts ().hasReducedDebugInfo ();
647
- FunctionArgList Args;
648
- llvm::MapVector<const Decl *, std::pair<const VarDecl *, Address>> LocalAddrs;
649
- llvm::DenseMap<const Decl *, std::pair<const Expr *, llvm::Value *>> VLASizes;
647
+ FunctionArgList Args, WrapperArgs;
648
+ llvm::MapVector<const Decl *, std::pair<const VarDecl *, Address>> LocalAddrs,
649
+ WrapperLocalAddrs;
650
+ llvm::DenseMap<const Decl *, std::pair<const Expr *, llvm::Value *>> VLASizes,
651
+ WrapperVLASizes;
650
652
SmallString<256 > Buffer;
651
653
llvm::raw_svector_ostream Out (Buffer);
652
654
Out << CapturedStmtInfo->getHelperName ();
653
- if (NeedWrapperFunction)
655
+
656
+ CodeGenFunction WrapperCGF (CGM, /* suppressNewContext=*/ true );
657
+ llvm::Function *WrapperF = nullptr ;
658
+ if (NeedWrapperFunction) {
659
+ // Emit the final kernel early to allow attributes to be added by the
660
+ // OpenMPI-IR-Builder.
661
+ FunctionOptions WrapperFO (&S, /* UIntPtrCastRequired=*/ true ,
662
+ /* RegisterCastedArgsOnly=*/ true ,
663
+ CapturedStmtInfo->getHelperName (), Loc);
664
+ WrapperCGF.CapturedStmtInfo = CapturedStmtInfo;
665
+ WrapperF =
666
+ emitOutlinedFunctionPrologue (WrapperCGF, Args, LocalAddrs, VLASizes,
667
+ WrapperCGF.CXXThisValue , WrapperFO);
654
668
Out << " _debug__" ;
669
+ }
655
670
FunctionOptions FO (&S, !NeedWrapperFunction, /* RegisterCastedArgsOnly=*/ false ,
656
671
Out.str (), Loc);
657
- llvm::Function *F = emitOutlinedFunctionPrologue (* this , Args, LocalAddrs,
658
- VLASizes , CXXThisValue, FO);
672
+ llvm::Function *F = emitOutlinedFunctionPrologue (
673
+ * this , WrapperArgs, WrapperLocalAddrs, WrapperVLASizes , CXXThisValue, FO);
659
674
CodeGenFunction::OMPPrivateScope LocalScope (*this );
660
- for (const auto &LocalAddrPair : LocalAddrs ) {
675
+ for (const auto &LocalAddrPair : WrapperLocalAddrs ) {
661
676
if (LocalAddrPair.second .first ) {
662
677
LocalScope.addPrivate (LocalAddrPair.second .first ,
663
678
LocalAddrPair.second .second );
664
679
}
665
680
}
666
681
(void )LocalScope.Privatize ();
667
- for (const auto &VLASizePair : VLASizes )
682
+ for (const auto &VLASizePair : WrapperVLASizes )
668
683
VLASizeMap[VLASizePair.second .first ] = VLASizePair.second .second ;
669
684
PGO.assignRegionCounters (GlobalDecl (CD), F);
670
685
CapturedStmtInfo->EmitBody (*this , CD->getBody ());
@@ -673,17 +688,10 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S,
673
688
if (!NeedWrapperFunction)
674
689
return F;
675
690
676
- FunctionOptions WrapperFO (&S, /* UIntPtrCastRequired=*/ true ,
677
- /* RegisterCastedArgsOnly=*/ true ,
678
- CapturedStmtInfo->getHelperName (), Loc);
679
- CodeGenFunction WrapperCGF (CGM, /* suppressNewContext=*/ true );
680
- WrapperCGF.CapturedStmtInfo = CapturedStmtInfo;
681
- Args.clear ();
682
- LocalAddrs.clear ();
683
- VLASizes.clear ();
684
- llvm::Function *WrapperF =
685
- emitOutlinedFunctionPrologue (WrapperCGF, Args, LocalAddrs, VLASizes,
686
- WrapperCGF.CXXThisValue , WrapperFO);
691
+ // Reverse the order.
692
+ WrapperF->removeFromParent ();
693
+ F->getParent ()->getFunctionList ().insertAfter (F->getIterator (), WrapperF);
694
+
687
695
llvm::SmallVector<llvm::Value *, 4 > CallArgs;
688
696
auto *PI = F->arg_begin ();
689
697
for (const auto *Arg : Args) {
0 commit comments