[llvm] [DebugInfo][RemoveDIs] Handle DPValues in LCSSA (PR #72996)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 21 06:37:52 PST 2023
https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/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.
>From f557773d4ef7f51237c512f88cb08b5daab8f57a Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Tue, 21 Nov 2023 12:23:34 +0000
Subject: [PATCH] [DebugInfo][RemoveDIs] Handle DPValues in LCSSA
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 communciating
debug-info in the future.
---
llvm/lib/Transforms/Utils/LCSSA.cpp | 21 +++++++++++++++++--
.../LCSSA/rewrite-existing-dbg-values.ll | 1 +
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Utils/LCSSA.cpp b/llvm/lib/Transforms/Utils/LCSSA.cpp
index c36b0533580b97c..5e0c312fe149e73 100644
--- a/llvm/lib/Transforms/Utils/LCSSA.cpp
+++ b/llvm/lib/Transforms/Utils/LCSSA.cpp
@@ -160,7 +160,8 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
if (SSAUpdate.HasValueForBlock(ExitBB))
continue;
PHINode *PN = PHINode::Create(I->getType(), PredCache.size(ExitBB),
- I->getName() + ".lcssa", &ExitBB->front());
+ I->getName() + ".lcssa");
+ PN->insertBefore(ExitBB->begin());
if (InsertedPHIs)
InsertedPHIs->push_back(PN);
// Get the debug location from the original instruction.
@@ -241,7 +242,8 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
}
SmallVector<DbgValueInst *, 4> DbgValues;
- llvm::findDbgValues(DbgValues, I);
+ SmallVector<DPValue *, 4> DPValues;
+ llvm::findDbgValues(DbgValues, I, &DPValues);
// Update pre-existing debug value uses that reside outside the loop.
for (auto *DVI : DbgValues) {
@@ -257,6 +259,21 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
DVI->replaceVariableLocationOp(I, V);
}
+ // RemoveDIs: copy-paste of block above, using non-instruction debug-info
+ // records.
+ for (DPValue *DPV : DPValues) {
+ BasicBlock *UserBB = DPV->getMarker()->getParent();
+ if (InstBB == UserBB || L->contains(UserBB))
+ continue;
+ // We currently only handle debug values residing in blocks that were
+ // traversed while rewriting the uses. If we inserted just a single PHI,
+ // we will handle all relevant debug values.
+ Value *V = AddedPHIs.size() == 1 ? AddedPHIs[0]
+ : SSAUpdate.FindValueForBlock(UserBB);
+ if (V)
+ DPV->replaceVariableLocationOp(I, V);
+ }
+
// SSAUpdater might have inserted phi-nodes inside other loops. We'll need
// to post-process them to keep LCSSA form.
for (PHINode *InsertedPN : LocalInsertedPHIs) {
diff --git a/llvm/test/Transforms/LCSSA/rewrite-existing-dbg-values.ll b/llvm/test/Transforms/LCSSA/rewrite-existing-dbg-values.ll
index afd19ec0780f09d..f4b8fff5a0d738b 100644
--- a/llvm/test/Transforms/LCSSA/rewrite-existing-dbg-values.ll
+++ b/llvm/test/Transforms/LCSSA/rewrite-existing-dbg-values.ll
@@ -1,4 +1,5 @@
; RUN: opt -S -passes=lcssa < %s | FileCheck %s
+; RUN: opt -S -passes=lcssa < %s --try-experimental-debuginfo-iterators | FileCheck %s
; Reproducer for PR39019.
;
More information about the llvm-commits
mailing list