Skip to content

Commit 80d3a4c

Browse files
authored
[DebugInfo][RemoveDIs] Add local-utility plumbing for DPValues (#72276)
This patch re-implements a variety of debug-info maintenence functions to use DPValues instead of DbgValueInst's: supporting the "new" non-intrinsic representation of debug-info. As per [0], we need to have parallel implementations of various utilities for a time, and these are the most fundamental utilities used throughout the compiler. I've added --try-experimental-debuginfo-iterators to a variety of RUN lines: this is a flag that turns on "new debug-info" if it's built into LLVM, and not otherwise. This should ensure that we have the same behaviour for the same IR inputs, but using a different internal representation. For the most part these changes affect SROA/Mem2Reg promotion of dbg.declares into dbg.value intrinsics (now DPValues), we're leaving dbg.declares as instructions until later in the day. There's also some salvaging changes made. I believe the tests that I've added cover almost all the code being updated here. The only thing I'm not confident about is SimplifyCFG, which calls rewriteDebugUsers down a variety of code paths. Those changes can't immediately get full coverage as an additional patch is needed that updates handling of Unreachable instructions, will upload that shortly. [0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939/9
1 parent 6e547ce commit 80d3a4c

24 files changed

+409
-44
lines changed

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,22 @@ CallInst *changeToCall(InvokeInst *II, DomTreeUpdater *DTU = nullptr);
262262
/// that has an associated llvm.dbg.declare intrinsic.
263263
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
264264
StoreInst *SI, DIBuilder &Builder);
265+
void ConvertDebugDeclareToDebugValue(DPValue *DPV, StoreInst *SI,
266+
DIBuilder &Builder);
265267

266268
/// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
267269
/// that has an associated llvm.dbg.declare intrinsic.
268270
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
269271
LoadInst *LI, DIBuilder &Builder);
272+
void ConvertDebugDeclareToDebugValue(DPValue *DPV, LoadInst *LI,
273+
DIBuilder &Builder);
270274

271275
/// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
272276
/// llvm.dbg.declare intrinsic.
273277
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
274278
PHINode *LI, DIBuilder &Builder);
279+
void ConvertDebugDeclareToDebugValue(DPValue *DPV, PHINode *LI,
280+
DIBuilder &Builder);
275281

276282
/// Lowers llvm.dbg.declare intrinsics into appropriate set of
277283
/// llvm.dbg.value intrinsics.
@@ -302,12 +308,12 @@ void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
302308
/// cannot be salvaged changes its debug uses to undef.
303309
void salvageDebugInfo(Instruction &I);
304310

305-
306311
/// Implementation of salvageDebugInfo, applying only to instructions in
307312
/// \p Insns, rather than all debug users from findDbgUsers( \p I).
308313
/// Mark undef if salvaging cannot be completed.
309314
void salvageDebugInfoForDbgValues(Instruction &I,
310-
ArrayRef<DbgVariableIntrinsic *> Insns);
315+
ArrayRef<DbgVariableIntrinsic *> Insns,
316+
ArrayRef<DPValue *> DPInsns);
311317

312318
/// Given an instruction \p I and DIExpression \p DIExpr operating on
313319
/// it, append the effects of \p I to the DIExpression operand list

llvm/lib/IR/BasicBlock.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,9 @@ void BasicBlock::insertDPValueAfter(DPValue *DPV, Instruction *I) {
985985
assert(I->getParent() == this);
986986

987987
iterator NextIt = std::next(I->getIterator());
988-
DPMarker *NextMarker =
989-
(NextIt == end()) ? getTrailingDPValues() : NextIt->DbgMarker;
988+
DPMarker *NextMarker = getMarker(NextIt);
989+
if (!NextMarker)
990+
NextMarker = createMarker(NextIt);
990991
NextMarker->insertDPValue(DPV, true);
991992
}
992993

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3926,6 +3926,7 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I,
39263926
// For all debug values in the destination block, the sunk instruction
39273927
// will still be available, so they do not need to be dropped.
39283928
SmallVector<DbgVariableIntrinsic *, 2> DbgUsersToSalvage;
3929+
SmallVector<DPValue *, 2> DPValuesToSalvage;
39293930
for (auto &DbgUser : DbgUsers)
39303931
if (DbgUser->getParent() != DestBlock)
39313932
DbgUsersToSalvage.push_back(DbgUser);
@@ -3969,7 +3970,10 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I,
39693970

39703971
// Perform salvaging without the clones, then sink the clones.
39713972
if (!DIIClones.empty()) {
3972-
salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage);
3973+
// RemoveDIs: pass in empty vector of DPValues until we get to instrumenting
3974+
// this pass.
3975+
SmallVector<DPValue *, 1> DummyDPValues;
3976+
salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, DummyDPValues);
39733977
// The clones are in reverse order of original appearance, reverse again to
39743978
// maintain the original order.
39753979
for (auto &DIIClone : llvm::reverse(DIIClones)) {

0 commit comments

Comments
 (0)