Skip to content

Commit 7fc2592

Browse files
committed
[DebugInfo][RemoveDIs] "Final" cleanup for non-instr debug-info (#79121)
Here's a raft of minor fixes for the RemoveDIs project that's replacing dbg.value intrinsics with DPValue objects, all IMO trivial: * When inserting functions or blocks and calling setIsNewDbgInfoFormat, do that after setting the Parent pointer, just in case conversion from (or to) dbg.value mode is triggered. * When transferring DPValues from an empty range in a splice call, don't transfer if there are no DPValues attached to the source block at all. * stripNonLineTableDebugInfo should drop DPValues. * In insertBefore, don't try to transfer DPValues if there aren't any.
1 parent 750e90e commit 7fc2592

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

llvm/include/llvm/IR/Function.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,9 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
722722
/// Insert \p BB in the basic block list at \p Position. \Returns an iterator
723723
/// to the newly inserted BB.
724724
Function::iterator insert(Function::iterator Position, BasicBlock *BB) {
725+
Function::iterator FIt = BasicBlocks.insert(Position, BB);
725726
BB->setIsNewDbgInfoFormat(IsNewDbgInfoFormat);
726-
return BasicBlocks.insert(Position, BB);
727+
return FIt;
727728
}
728729

729730
/// Transfer all blocks from \p FromF to this function at \p ToIt.

llvm/lib/IR/BasicBlock.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ void BasicBlock::insertInto(Function *NewParent, BasicBlock *InsertBefore) {
237237
assert(NewParent && "Expected a parent");
238238
assert(!Parent && "Already has a parent");
239239

240-
setIsNewDbgInfoFormat(NewParent->IsNewDbgInfoFormat);
241-
242240
if (InsertBefore)
243241
NewParent->insert(InsertBefore->getIterator(), this);
244242
else
245243
NewParent->insert(NewParent->end(), this);
244+
245+
setIsNewDbgInfoFormat(NewParent->IsNewDbgInfoFormat);
246246
}
247247

248248
BasicBlock::~BasicBlock() {
@@ -821,9 +821,15 @@ void BasicBlock::spliceDebugInfoEmptyBlock(BasicBlock::iterator Dest,
821821

822822
// There are instructions in this block; if the First iterator was
823823
// with begin() / getFirstInsertionPt() then the caller intended debug-info
824-
// at the start of the block to be transferred.
825-
if (!Src->empty() && First == Src->begin() && ReadFromHead)
826-
Dest->DbgMarker->absorbDebugValues(*First->DbgMarker, InsertAtHead);
824+
// at the start of the block to be transferred. Return otherwise.
825+
if (Src->empty() || First != Src->begin() || !ReadFromHead)
826+
return;
827+
828+
// Is there actually anything to transfer?
829+
if (!First->hasDbgValues())
830+
return;
831+
832+
createMarker(Dest)->absorbDebugValues(*First->DbgMarker, InsertAtHead);
827833

828834
return;
829835
}

llvm/lib/IR/DebugInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,9 @@ bool llvm::stripNonLineTableDebugInfo(Module &M) {
892892
// Strip heapallocsite attachments, they point into the DIType system.
893893
if (I.hasMetadataOtherThanDebugLoc())
894894
I.setMetadata("heapallocsite", nullptr);
895+
896+
// Strip any DPValues attached.
897+
I.dropDbgValues();
895898
}
896899
}
897900
}

llvm/lib/IR/Instruction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ void Instruction::insertBefore(BasicBlock &BB,
146146
bool InsertAtHead = InsertPos.getHeadBit();
147147
if (!InsertAtHead) {
148148
DPMarker *SrcMarker = BB.getMarker(InsertPos);
149-
if (!SrcMarker)
150-
SrcMarker = BB.createMarker(InsertPos);
151-
DbgMarker->absorbDebugValues(*SrcMarker, false);
149+
// If there's no source marker, InsertPos is very likely end().
150+
if (SrcMarker)
151+
DbgMarker->absorbDebugValues(*SrcMarker, false);
152152
}
153153

154154
// If we're inserting a terminator, check if we need to flush out

llvm/test/DebugInfo/salvage-limit-expr-size.ll

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

34
;; Tests that a DIExpression will only be salvaged up to a certain length, and
45
;; will produce an undef value if an expression would need to exceed that length.

llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-localvars.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: opt -S -passes=strip-nonlinetable-debuginfo %s -o - | FileCheck %s
2+
; RUN: opt -S -passes=strip-nonlinetable-debuginfo %s -o - --try-experimental-debuginfo-iterators | FileCheck %s
23
; CHECK: define void @f() !dbg ![[F:[0-9]+]]
34
define void @f() !dbg !4 {
45
entry:

0 commit comments

Comments
 (0)