Skip to content

Commit c1146f3

Browse files
authored
[DebugInfo][RemoveDIs] Handle DPValues in LCSSA (#72996)
LCSSA needs to manually update dbg.value intrinsic users of Values that are having LCSSA PHIs inserted -- instrument it to do the same for DPValues, the replacement for dbg.values. This patch also contains an opportunistic fix replacing instruction-insertion with iterator-insertion, necessary for communicating debug-info in the future.
1 parent 64c0e86 commit c1146f3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

llvm/lib/Transforms/Utils/LCSSA.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
160160
if (SSAUpdate.HasValueForBlock(ExitBB))
161161
continue;
162162
PHINode *PN = PHINode::Create(I->getType(), PredCache.size(ExitBB),
163-
I->getName() + ".lcssa", &ExitBB->front());
163+
I->getName() + ".lcssa");
164+
PN->insertBefore(ExitBB->begin());
164165
if (InsertedPHIs)
165166
InsertedPHIs->push_back(PN);
166167
// Get the debug location from the original instruction.
@@ -241,7 +242,8 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
241242
}
242243

243244
SmallVector<DbgValueInst *, 4> DbgValues;
244-
llvm::findDbgValues(DbgValues, I);
245+
SmallVector<DPValue *, 4> DPValues;
246+
llvm::findDbgValues(DbgValues, I, &DPValues);
245247

246248
// Update pre-existing debug value uses that reside outside the loop.
247249
for (auto *DVI : DbgValues) {
@@ -257,6 +259,21 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
257259
DVI->replaceVariableLocationOp(I, V);
258260
}
259261

262+
// RemoveDIs: copy-paste of block above, using non-instruction debug-info
263+
// records.
264+
for (DPValue *DPV : DPValues) {
265+
BasicBlock *UserBB = DPV->getMarker()->getParent();
266+
if (InstBB == UserBB || L->contains(UserBB))
267+
continue;
268+
// We currently only handle debug values residing in blocks that were
269+
// traversed while rewriting the uses. If we inserted just a single PHI,
270+
// we will handle all relevant debug values.
271+
Value *V = AddedPHIs.size() == 1 ? AddedPHIs[0]
272+
: SSAUpdate.FindValueForBlock(UserBB);
273+
if (V)
274+
DPV->replaceVariableLocationOp(I, V);
275+
}
276+
260277
// SSAUpdater might have inserted phi-nodes inside other loops. We'll need
261278
// to post-process them to keep LCSSA form.
262279
for (PHINode *InsertedPN : LocalInsertedPHIs) {

llvm/test/Transforms/LCSSA/rewrite-existing-dbg-values.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: opt -S -passes=lcssa < %s | FileCheck %s
2+
; RUN: opt -S -passes=lcssa < %s --try-experimental-debuginfo-iterators | FileCheck %s
23

34
; Reproducer for PR39019.
45
;

0 commit comments

Comments
 (0)