Skip to content

[DebugInfo][RemoveDIs] "Final" cleanup for non-instr debug-info #79121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/include/llvm/IR/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,9 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
/// Insert \p BB in the basic block list at \p Position. \Returns an iterator
/// to the newly inserted BB.
Function::iterator insert(Function::iterator Position, BasicBlock *BB) {
Function::iterator FIt = BasicBlocks.insert(Position, BB);
BB->setIsNewDbgInfoFormat(IsNewDbgInfoFormat);
return BasicBlocks.insert(Position, BB);
return FIt;
}

/// Transfer all blocks from \p FromF to this function at \p ToIt.
Expand Down
16 changes: 11 additions & 5 deletions llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ void BasicBlock::insertInto(Function *NewParent, BasicBlock *InsertBefore) {
assert(NewParent && "Expected a parent");
assert(!Parent && "Already has a parent");

setIsNewDbgInfoFormat(NewParent->IsNewDbgInfoFormat);

if (InsertBefore)
NewParent->insert(InsertBefore->getIterator(), this);
else
NewParent->insert(NewParent->end(), this);

setIsNewDbgInfoFormat(NewParent->IsNewDbgInfoFormat);
}

BasicBlock::~BasicBlock() {
Expand Down Expand Up @@ -824,9 +824,15 @@ void BasicBlock::spliceDebugInfoEmptyBlock(BasicBlock::iterator Dest,

// There are instructions in this block; if the First iterator was
// with begin() / getFirstInsertionPt() then the caller intended debug-info
// at the start of the block to be transferred.
if (!Src->empty() && First == Src->begin() && ReadFromHead)
Dest->DbgMarker->absorbDebugValues(*First->DbgMarker, InsertAtHead);
// at the start of the block to be transferred. Return otherwise.
if (Src->empty() || First != Src->begin() || !ReadFromHead)
return;

// Is there actually anything to transfer?
if (!First->hasDbgValues())
return;

createMarker(Dest)->absorbDebugValues(*First->DbgMarker, InsertAtHead);

return;
}
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/IR/DebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,9 @@ bool llvm::stripNonLineTableDebugInfo(Module &M) {
// Strip heapallocsite attachments, they point into the DIType system.
if (I.hasMetadataOtherThanDebugLoc())
I.setMetadata("heapallocsite", nullptr);

// Strip any DPValues attached.
I.dropDbgValues();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ void Instruction::insertBefore(BasicBlock &BB,
bool InsertAtHead = InsertPos.getHeadBit();
if (!InsertAtHead) {
DPMarker *SrcMarker = BB.getMarker(InsertPos);
if (!SrcMarker)
SrcMarker = BB.createMarker(InsertPos);
DbgMarker->absorbDebugValues(*SrcMarker, false);
// If there's no source marker, InsertPos is very likely end().
if (SrcMarker)
DbgMarker->absorbDebugValues(*SrcMarker, false);
}

// If we're inserting a terminator, check if we need to flush out
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2340,7 +2340,7 @@ void llvm::salvageDebugInfoForDbgValues(
// currently only valid for stack value expressions.
// Also do not salvage if the resulting DIArgList would contain an
// unreasonably large number of values.
Value *Undef = UndefValue::get(I.getOperand(0)->getType());
Value *Undef = PoisonValue::get(I.getOperand(0)->getType());
DPV->replaceVariableLocationOp(I.getOperand(0), Undef);
}
LLVM_DEBUG(dbgs() << "SALVAGE: " << DPV << '\n');
Expand Down
1 change: 1 addition & 0 deletions llvm/test/DebugInfo/salvage-limit-expr-size.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: opt %s -passes=dce -S | FileCheck %s
; RUN: opt %s -passes=dce -S --try-experimental-debuginfo-iterators | FileCheck %s

;; Tests that a DIExpression will only be salvaged up to a certain length, and
;; will produce an undef value if an expression would need to exceed that length.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: opt -S -passes=strip-nonlinetable-debuginfo %s -o - | FileCheck %s
; RUN: opt -S -passes=strip-nonlinetable-debuginfo %s -o - --try-experimental-debuginfo-iterators | FileCheck %s
; CHECK: define void @f() !dbg ![[F:[0-9]+]]
define void @f() !dbg !4 {
entry:
Expand Down