@@ -2617,7 +2617,7 @@ void OpenMPIRBuilder::emitReductionListCopy(
26172617Expected<Function *> OpenMPIRBuilder::emitInterWarpCopyFunction (
26182618    const  LocationDescription &Loc, ArrayRef<ReductionInfo> ReductionInfos,
26192619    AttributeList FuncAttrs) {
2620-   InsertPointTy SavedIP = Builder. saveIP ( );
2620+   IRBuilder<>::InsertPointGuard  IPG (Builder );
26212621  LLVMContext &Ctx = M.getContext ();
26222622  FunctionType *FuncTy = FunctionType::get (
26232623      Builder.getVoidTy (), {Builder.getPtrTy (), Builder.getInt32Ty ()},
@@ -2630,6 +2630,7 @@ Expected<Function *> OpenMPIRBuilder::emitInterWarpCopyFunction(
26302630  WcFunc->addParamAttr (1 , Attribute::NoUndef);
26312631  BasicBlock *EntryBB = BasicBlock::Create (M.getContext (), " entry"  , WcFunc);
26322632  Builder.SetInsertPoint (EntryBB);
2633+   Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
26332634
26342635  //  ReduceList: thread local Reduce list.
26352636  //  At the stage of the computation when this function is called, partially
@@ -2844,7 +2845,6 @@ Expected<Function *> OpenMPIRBuilder::emitInterWarpCopyFunction(
28442845  }
28452846
28462847  Builder.CreateRetVoid ();
2847-   Builder.restoreIP (SavedIP);
28482848
28492849  return  WcFunc;
28502850}
@@ -2853,6 +2853,7 @@ Function *OpenMPIRBuilder::emitShuffleAndReduceFunction(
28532853    ArrayRef<ReductionInfo> ReductionInfos, Function *ReduceFn,
28542854    AttributeList FuncAttrs) {
28552855  LLVMContext &Ctx = M.getContext ();
2856+   IRBuilder<>::InsertPointGuard IPG (Builder);
28562857  FunctionType *FuncTy =
28572858      FunctionType::get (Builder.getVoidTy (),
28582859                        {Builder.getPtrTy (), Builder.getInt16Ty (),
@@ -2871,6 +2872,7 @@ Function *OpenMPIRBuilder::emitShuffleAndReduceFunction(
28712872  SarFunc->addParamAttr (3 , Attribute::SExt);
28722873  BasicBlock *EntryBB = BasicBlock::Create (M.getContext (), " entry"  , SarFunc);
28732874  Builder.SetInsertPoint (EntryBB);
2875+   Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
28742876
28752877  //  Thread local Reduce list used to host the values of data to be reduced.
28762878  Argument *ReduceListArg = SarFunc->getArg (0 );
@@ -3017,7 +3019,7 @@ Function *OpenMPIRBuilder::emitShuffleAndReduceFunction(
30173019Function *OpenMPIRBuilder::emitListToGlobalCopyFunction (
30183020    ArrayRef<ReductionInfo> ReductionInfos, Type *ReductionsBufferTy,
30193021    AttributeList FuncAttrs) {
3020-   OpenMPIRBuilder::InsertPointTy OldIP = Builder. saveIP ( );
3022+   IRBuilder<>::InsertPointGuard  IPG (Builder );
30213023  LLVMContext &Ctx = M.getContext ();
30223024  FunctionType *FuncTy = FunctionType::get (
30233025      Builder.getVoidTy (),
@@ -3033,6 +3035,7 @@ Function *OpenMPIRBuilder::emitListToGlobalCopyFunction(
30333035
30343036  BasicBlock *EntryBlock = BasicBlock::Create (Ctx, " entry"  , LtGCFunc);
30353037  Builder.SetInsertPoint (EntryBlock);
3038+   Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
30363039
30373040  //  Buffer: global reduction buffer.
30383041  Argument *BufferArg = LtGCFunc->getArg (0 );
@@ -3120,14 +3123,13 @@ Function *OpenMPIRBuilder::emitListToGlobalCopyFunction(
31203123  }
31213124
31223125  Builder.CreateRetVoid ();
3123-   Builder.restoreIP (OldIP);
31243126  return  LtGCFunc;
31253127}
31263128
31273129Function *OpenMPIRBuilder::emitListToGlobalReduceFunction (
31283130    ArrayRef<ReductionInfo> ReductionInfos, Function *ReduceFn,
31293131    Type *ReductionsBufferTy, AttributeList FuncAttrs) {
3130-   OpenMPIRBuilder::InsertPointTy OldIP = Builder. saveIP ( );
3132+   IRBuilder<>::InsertPointGuard  IPG (Builder );
31313133  LLVMContext &Ctx = M.getContext ();
31323134  FunctionType *FuncTy = FunctionType::get (
31333135      Builder.getVoidTy (),
@@ -3143,6 +3145,7 @@ Function *OpenMPIRBuilder::emitListToGlobalReduceFunction(
31433145
31443146  BasicBlock *EntryBlock = BasicBlock::Create (Ctx, " entry"  , LtGRFunc);
31453147  Builder.SetInsertPoint (EntryBlock);
3148+   Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
31463149
31473150  //  Buffer: global reduction buffer.
31483151  Argument *BufferArg = LtGRFunc->getArg (0 );
@@ -3203,14 +3206,13 @@ Function *OpenMPIRBuilder::emitListToGlobalReduceFunction(
32033206  Builder.CreateCall (ReduceFn, {LocalReduceListAddrCast, ReduceList})
32043207      ->addFnAttr (Attribute::NoUnwind);
32053208  Builder.CreateRetVoid ();
3206-   Builder.restoreIP (OldIP);
32073209  return  LtGRFunc;
32083210}
32093211
32103212Function *OpenMPIRBuilder::emitGlobalToListCopyFunction (
32113213    ArrayRef<ReductionInfo> ReductionInfos, Type *ReductionsBufferTy,
32123214    AttributeList FuncAttrs) {
3213-   OpenMPIRBuilder::InsertPointTy OldIP = Builder. saveIP ( );
3215+   IRBuilder<>::InsertPointGuard  IPG (Builder );
32143216  LLVMContext &Ctx = M.getContext ();
32153217  FunctionType *FuncTy = FunctionType::get (
32163218      Builder.getVoidTy (),
@@ -3226,6 +3228,7 @@ Function *OpenMPIRBuilder::emitGlobalToListCopyFunction(
32263228
32273229  BasicBlock *EntryBlock = BasicBlock::Create (Ctx, " entry"  , LtGCFunc);
32283230  Builder.SetInsertPoint (EntryBlock);
3231+   Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
32293232
32303233  //  Buffer: global reduction buffer.
32313234  Argument *BufferArg = LtGCFunc->getArg (0 );
@@ -3311,14 +3314,13 @@ Function *OpenMPIRBuilder::emitGlobalToListCopyFunction(
33113314  }
33123315
33133316  Builder.CreateRetVoid ();
3314-   Builder.restoreIP (OldIP);
33153317  return  LtGCFunc;
33163318}
33173319
33183320Function *OpenMPIRBuilder::emitGlobalToListReduceFunction (
33193321    ArrayRef<ReductionInfo> ReductionInfos, Function *ReduceFn,
33203322    Type *ReductionsBufferTy, AttributeList FuncAttrs) {
3321-   OpenMPIRBuilder::InsertPointTy OldIP = Builder. saveIP ( );
3323+   IRBuilder<>::InsertPointGuard  IPG (Builder );
33223324  LLVMContext &Ctx = M.getContext ();
33233325  auto  *FuncTy = FunctionType::get (
33243326      Builder.getVoidTy (),
@@ -3334,6 +3336,7 @@ Function *OpenMPIRBuilder::emitGlobalToListReduceFunction(
33343336
33353337  BasicBlock *EntryBlock = BasicBlock::Create (Ctx, " entry"  , LtGRFunc);
33363338  Builder.SetInsertPoint (EntryBlock);
3339+   Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
33373340
33383341  //  Buffer: global reduction buffer.
33393342  Argument *BufferArg = LtGRFunc->getArg (0 );
@@ -3394,7 +3397,6 @@ Function *OpenMPIRBuilder::emitGlobalToListReduceFunction(
33943397  Builder.CreateCall (ReduceFn, {ReduceList, ReductionList})
33953398      ->addFnAttr (Attribute::NoUnwind);
33963399  Builder.CreateRetVoid ();
3397-   Builder.restoreIP (OldIP);
33983400  return  LtGRFunc;
33993401}
34003402
@@ -3407,6 +3409,7 @@ std::string OpenMPIRBuilder::getReductionFuncName(StringRef Name) const {
34073409Expected<Function *> OpenMPIRBuilder::createReductionFunction (
34083410    StringRef ReducerName, ArrayRef<ReductionInfo> ReductionInfos,
34093411    ReductionGenCBKind ReductionGenCBKind, AttributeList FuncAttrs) {
3412+   IRBuilder<>::InsertPointGuard IPG (Builder);
34103413  auto  *FuncTy = FunctionType::get (Builder.getVoidTy (),
34113414                                   {Builder.getPtrTy (), Builder.getPtrTy ()},
34123415                                   /*  IsVarArg */   false );
@@ -3419,6 +3422,7 @@ Expected<Function *> OpenMPIRBuilder::createReductionFunction(
34193422  BasicBlock *EntryBB =
34203423      BasicBlock::Create (M.getContext (), " entry"  , ReductionFunc);
34213424  Builder.SetInsertPoint (EntryBB);
3425+   Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
34223426
34233427  //  Need to alloca memory here and deal with the pointers before getting
34243428  //  LHS/RHS pointers out
@@ -3746,10 +3750,12 @@ static Error populateReductionFunction(
37463750    Function *ReductionFunc,
37473751    ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos,
37483752    IRBuilder<> &Builder, ArrayRef<bool > IsByRef, bool  IsGPU) {
3753+   IRBuilder<>::InsertPointGuard IPG (Builder);
37493754  Module *Module = ReductionFunc->getParent ();
37503755  BasicBlock *ReductionFuncBlock =
37513756      BasicBlock::Create (Module->getContext (), " "  , ReductionFunc);
37523757  Builder.SetInsertPoint (ReductionFuncBlock);
3758+   Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
37533759  Value *LHSArrayPtr = nullptr ;
37543760  Value *RHSArrayPtr = nullptr ;
37553761  if  (IsGPU) {
0 commit comments