@@ -6197,6 +6197,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
6197
6197
F->addFnAttr (" target-features" , " +mmx,+sse" );
6198
6198
IRBuilder<> Builder (BB);
6199
6199
auto *Int32Ty = Builder.getInt32Ty ();
6200
+ Builder.SetCurrentDebugLocation (DL);
6200
6201
6201
6202
AllocaInst *APtr = Builder.CreateAlloca (Int32Ty, nullptr , " a_ptr" );
6202
6203
AllocaInst *BPtr = Builder.CreateAlloca (Int32Ty, nullptr , " b_ptr" );
@@ -6206,6 +6207,8 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
6206
6207
Builder.CreateStore (Builder.getInt32 (20 ), BPtr);
6207
6208
auto BodyGenCB = [&](InsertPointTy AllocaIP,
6208
6209
InsertPointTy CodeGenIP) -> InsertPointTy {
6210
+ IRBuilderBase::InsertPointGuard guard (Builder);
6211
+ Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
6209
6212
Builder.restoreIP (CodeGenIP);
6210
6213
LoadInst *AVal = Builder.CreateLoad (Int32Ty, APtr);
6211
6214
LoadInst *BVal = Builder.CreateLoad (Int32Ty, BPtr);
@@ -6223,6 +6226,8 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
6223
6226
[&](llvm::Argument &Arg, llvm::Value *Input, llvm::Value *&RetVal,
6224
6227
llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
6225
6228
llvm::OpenMPIRBuilder::InsertPointTy CodeGenIP) {
6229
+ IRBuilderBase::InsertPointGuard guard (Builder);
6230
+ Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
6226
6231
if (!OMPBuilder.Config .isTargetDevice ()) {
6227
6232
RetVal = cast<llvm::Value>(&Arg);
6228
6233
return CodeGenIP;
@@ -6269,6 +6274,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
6269
6274
Builder.saveIP (), EntryInfo, DefaultAttrs,
6270
6275
RuntimeAttrs, /* IfCond=*/ nullptr , Inputs,
6271
6276
GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB));
6277
+ EXPECT_EQ (DL, Builder.getCurrentDebugLocation ());
6272
6278
Builder.restoreIP (AfterIP);
6273
6279
6274
6280
OMPBuilder.finalize ();
@@ -6368,6 +6374,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
6368
6374
F->addFnAttr (" target-features" , " +gfx9-insts,+wavefrontsize64" );
6369
6375
IRBuilder<> Builder (BB);
6370
6376
OpenMPIRBuilder::LocationDescription Loc ({Builder.saveIP (), DL});
6377
+ Builder.SetCurrentDebugLocation (DL);
6371
6378
6372
6379
LoadInst *Value = nullptr ;
6373
6380
StoreInst *TargetStore = nullptr ;
@@ -6379,6 +6386,8 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
6379
6386
[&](llvm::Argument &Arg, llvm::Value *Input, llvm::Value *&RetVal,
6380
6387
llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
6381
6388
llvm::OpenMPIRBuilder::InsertPointTy CodeGenIP) {
6389
+ IRBuilderBase::InsertPointGuard guard (Builder);
6390
+ Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
6382
6391
if (!OMPBuilder.Config .isTargetDevice ()) {
6383
6392
RetVal = cast<llvm::Value>(&Arg);
6384
6393
return CodeGenIP;
@@ -6412,6 +6421,8 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
6412
6421
auto BodyGenCB = [&](OpenMPIRBuilder::InsertPointTy AllocaIP,
6413
6422
OpenMPIRBuilder::InsertPointTy CodeGenIP)
6414
6423
-> OpenMPIRBuilder::InsertPointTy {
6424
+ IRBuilderBase::InsertPointGuard guard (Builder);
6425
+ Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
6415
6426
Builder.restoreIP (CodeGenIP);
6416
6427
Value = Builder.CreateLoad (Type::getInt32Ty (Ctx), CapturedArgs[0 ]);
6417
6428
TargetStore = Builder.CreateStore (Value, CapturedArgs[1 ]);
@@ -6433,6 +6444,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
6433
6444
EntryInfo, DefaultAttrs, RuntimeAttrs,
6434
6445
/* IfCond=*/ nullptr , CapturedArgs, GenMapInfoCB,
6435
6446
BodyGenCB, SimpleArgAccessorCB));
6447
+ EXPECT_EQ (DL, Builder.getCurrentDebugLocation ());
6436
6448
Builder.restoreIP (AfterIP);
6437
6449
6438
6450
Builder.CreateRetVoid ();
@@ -6742,6 +6754,7 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
6742
6754
F->setName (" func" );
6743
6755
IRBuilder<> Builder (BB);
6744
6756
OpenMPIRBuilder::LocationDescription Loc ({Builder.saveIP (), DL});
6757
+ Builder.SetCurrentDebugLocation (DL);
6745
6758
6746
6759
LoadInst *Value = nullptr ;
6747
6760
StoreInst *TargetStore = nullptr ;
@@ -6752,6 +6765,8 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
6752
6765
[&](llvm::Argument &Arg, llvm::Value *Input, llvm::Value *&RetVal,
6753
6766
llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
6754
6767
llvm::OpenMPIRBuilder::InsertPointTy CodeGenIP) {
6768
+ IRBuilderBase::InsertPointGuard guard (Builder);
6769
+ Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
6755
6770
if (!OMPBuilder.Config .isTargetDevice ()) {
6756
6771
RetVal = cast<llvm::Value>(&Arg);
6757
6772
return CodeGenIP;
@@ -6787,6 +6802,8 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
6787
6802
auto BodyGenCB = [&](OpenMPIRBuilder::InsertPointTy AllocaIP,
6788
6803
OpenMPIRBuilder::InsertPointTy CodeGenIP)
6789
6804
-> OpenMPIRBuilder::InsertPointTy {
6805
+ IRBuilderBase::InsertPointGuard guard (Builder);
6806
+ Builder.SetCurrentDebugLocation (llvm::DebugLoc ());
6790
6807
Builder.restoreIP (CodeGenIP);
6791
6808
RaiseAlloca = Builder.CreateAlloca (Builder.getInt32Ty ());
6792
6809
Value = Builder.CreateLoad (Type::getInt32Ty (Ctx), CapturedArgs[0 ]);
@@ -6809,6 +6826,7 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
6809
6826
EntryInfo, DefaultAttrs, RuntimeAttrs,
6810
6827
/* IfCond=*/ nullptr , CapturedArgs, GenMapInfoCB,
6811
6828
BodyGenCB, SimpleArgAccessorCB));
6829
+ EXPECT_EQ (DL, Builder.getCurrentDebugLocation ());
6812
6830
Builder.restoreIP (AfterIP);
6813
6831
6814
6832
Builder.CreateRetVoid ();
@@ -7662,4 +7680,20 @@ TEST_F(OpenMPIRBuilderTest, createGPUOffloadEntry) {
7662
7680
EXPECT_TRUE (Fn->hasFnAttribute (Attribute::MustProgress));
7663
7681
}
7664
7682
7683
+ TEST_F (OpenMPIRBuilderTest, splitBB) {
7684
+ OpenMPIRBuilder OMPBuilder (*M);
7685
+ OMPBuilder.Config .IsTargetDevice = false ;
7686
+ OMPBuilder.initialize ();
7687
+ F->setName (" func" );
7688
+ IRBuilder<> Builder (BB);
7689
+
7690
+ Builder.SetCurrentDebugLocation (DL);
7691
+ AllocaInst *alloc = Builder.CreateAlloca (Builder.getInt32Ty ());
7692
+ EXPECT_TRUE (DL == alloc->getStableDebugLoc ());
7693
+ BasicBlock *AllocaBB = Builder.GetInsertBlock ();
7694
+ splitBB (Builder, /* CreateBranch=*/ true , " test" );
7695
+ if (AllocaBB->getTerminator ())
7696
+ EXPECT_TRUE (DL == AllocaBB->getTerminator ()->getStableDebugLoc ());
7697
+ }
7698
+
7665
7699
} // namespace
0 commit comments