Skip to content

Commit ad7c0b5

Browse files
committed
[KeyInstr] Don't propagate source atoms to new uncond br in splitBasicBlock (llvm#139070)
splitBasicBlock inserts an unconditional branch in the "before" block to the "after" block. It copies the DebugLoc from the split point. Prevent it copying the source location atom. Add unittest. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668
1 parent 0e8fec4 commit ad7c0b5

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

llvm/lib/IR/BasicBlock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName,
609609
this->getNextNode());
610610

611611
// Save DebugLoc of split point before invalidating iterator.
612-
DebugLoc Loc = I->getStableDebugLoc();
612+
DebugLoc Loc = I->getStableDebugLoc()->getWithoutAtom();
613613
// Move all of the specified instructions from the original basic block into
614614
// the new basic block.
615615
New->splice(New->end(), this, I, end());
@@ -638,7 +638,7 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
638638

639639
BasicBlock *New = BasicBlock::Create(getContext(), BBName, getParent(), this);
640640
// Save DebugLoc of split point before invalidating iterator.
641-
DebugLoc Loc = I->getDebugLoc();
641+
DebugLoc Loc = I->getDebugLoc()->getWithoutAtom();
642642
// Move all of the specified instructions from the original basic block into
643643
// the new basic block.
644644
New->splice(New->end(), this, begin(), I);

llvm/unittests/IR/BasicBlockDbgInfoTest.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,75 @@ TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
149149
ASSERT_TRUE(I2->hasDbgRecords());
150150
}
151151

152+
TEST(BasicBlockDbgInfoTest, DropSourceAtomOnSplit) {
153+
LLVMContext C;
154+
std::unique_ptr<Module> M = parseIR(C, R"---(
155+
define dso_local void @func() !dbg !10 {
156+
%1 = alloca i32, align 4
157+
ret void, !dbg !DILocation(line: 3, column: 2, scope: !10, atomGroup: 1, atomRank: 1)
158+
}
159+
160+
!llvm.dbg.cu = !{!0}
161+
!llvm.module.flags = !{!2, !3}
162+
163+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "dummy", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
164+
!1 = !DIFile(filename: "dummy", directory: "dummy")
165+
!2 = !{i32 7, !"Dwarf Version", i32 5}
166+
!3 = !{i32 2, !"Debug Info Version", i32 3}
167+
!10 = distinct !DISubprogram(name: "func", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13)
168+
!11 = !DISubroutineType(types: !12)
169+
!12 = !{null}
170+
!13 = !{}
171+
!14 = !DILocalVariable(name: "a", scope: !10, file: !1, line: 2, type: !15)
172+
!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
173+
)---");
174+
ASSERT_TRUE(M);
175+
176+
Function *F = M->getFunction("func");
177+
178+
// Test splitBasicBlockBefore.
179+
{
180+
BasicBlock &BB = F->back();
181+
// Split at `ret void`.
182+
BasicBlock *Before =
183+
BB.splitBasicBlockBefore(std::prev(BB.end(), 1), "before");
184+
const DebugLoc &BrToAfterDL = Before->getTerminator()->getDebugLoc();
185+
ASSERT_TRUE(BrToAfterDL);
186+
EXPECT_EQ(BrToAfterDL->getAtomGroup(), 0u);
187+
188+
BasicBlock *After = Before->getSingleSuccessor();
189+
ASSERT_TRUE(After);
190+
const DebugLoc &OrigTerminatorDL = After->getTerminator()->getDebugLoc();
191+
ASSERT_TRUE(OrigTerminatorDL);
192+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
193+
EXPECT_EQ(OrigTerminatorDL->getAtomGroup(), 1u);
194+
#else
195+
EXPECT_EQ(OrigTerminatorDL->getAtomGroup(), 0u);
196+
#endif
197+
}
198+
199+
// Test splitBasicBlock.
200+
{
201+
BasicBlock &BB = F->back();
202+
// Split at `ret void`.
203+
BasicBlock *After = BB.splitBasicBlock(std::prev(BB.end(), 1), "before");
204+
205+
const DebugLoc &OrigTerminatorDL = After->getTerminator()->getDebugLoc();
206+
ASSERT_TRUE(OrigTerminatorDL);
207+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
208+
EXPECT_EQ(OrigTerminatorDL->getAtomGroup(), 1u);
209+
#else
210+
EXPECT_EQ(OrigTerminatorDL->getAtomGroup(), 0u);
211+
#endif
212+
213+
BasicBlock *Before = After->getSinglePredecessor();
214+
ASSERT_TRUE(Before);
215+
const DebugLoc &BrToAfterDL = Before->getTerminator()->getDebugLoc();
216+
ASSERT_TRUE(BrToAfterDL);
217+
EXPECT_EQ(BrToAfterDL->getAtomGroup(), 0u);
218+
}
219+
}
220+
152221
TEST(BasicBlockDbgInfoTest, MarkerOperations) {
153222
LLVMContext C;
154223
std::unique_ptr<Module> M = parseIR(C, R"(

0 commit comments

Comments
 (0)