[llvm] [DebugInfo][RemoveDIs] Support maintaining DPValues in CodeGenPrepare (PR #73660)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 29 03:32:58 PST 2023
================
@@ -8421,6 +8479,65 @@ bool CodeGenPrepare::placeDbgValues(Function &F) {
}
}
}
+
+ return MadeChange;
+}
+
+bool CodeGenPrepare::placeDPValues(Instruction &I, DominatorTree &DT) {
+ bool MadeChange = false;
+
+ for (DPValue &DPV : llvm::make_early_inc_range(I.getDbgValueRange())) {
+ if (DPV.Type != DPValue::LocationType::Value)
+ continue;
+
+ SmallVector<Instruction *, 4> VIs;
+ for (Value *V : DPV.location_ops())
+ if (Instruction *VI = dyn_cast_or_null<Instruction>(V))
+ VIs.push_back(VI);
+
+ // This DPV may depend on multiple instructions, complicating any
+ // potential sink. This block takes the defensive approach, opting to
+ // "undef" the DVI if it has more than one instruction and any of them do
+ // not dominate DVI.
+ for (Instruction *VI : VIs) {
+ if (VI->isTerminator())
+ continue;
+
+ // If VI is a phi in a block with an EHPad terminator, we can't insert
+ // after it.
+ if (isa<PHINode>(VI) && VI->getParent()->getTerminator()->isEHPad())
+ continue;
+
+ // If the defining instruction dominates the position, we do not need
+ // to move the dbg.value.
+ if (DT.dominates(VI, &I))
+ continue;
+
+ // If we depend on multiple instructions and any of them doesn't
+ // dominate this DPV, we probably can't salvage it: moving it to
+ // after any of the instructions could cause us to lose the others.
+ if (VIs.size() > 1) {
+ LLVM_DEBUG(
+ dbgs()
+ << "Unable to find valid location for Debug Value, undefing:\n"
+ << DPV);
+ DPV.setKillLocation();
+ break;
+ }
+
+ LLVM_DEBUG(dbgs() << "Moving Debug Value before :\n"
+ << DPV << ' ' << *VI);
+ DPV.removeFromParent();
+ BasicBlock *VIBB = VI->getParent();
+ if (isa<PHINode>(VI)) {
+ VIBB->insertDPValueBefore(&DPV, VIBB->getFirstInsertionPt());
+ } else {
+ VIBB->insertDPValueAfter(&DPV, VI);
+ }
+ MadeChange = true;
+ ++NumDbgValueMoved;
+ }
+ }
----------------
OCHyams wrote:
Can this be folded back into the `placeDbgValues` function using the "turn the loop into a lambda and then call for_each(DbgValues, Lambda), for_each(DPValues, Lambda)" idiom (workshopping the name still).
https://github.com/llvm/llvm-project/pull/73660
More information about the llvm-commits
mailing list