diff options
author | Jeremy Morse <jeremy.morse@sony.com> | 2024-01-23 10:43:37 +0000 |
---|---|---|
committer | Jeremy Morse <jeremy.morse@sony.com> | 2024-01-23 22:52:47 +0000 |
commit | 7fc25928233c133a4af1dadf0e060fb5d42ebd4e (patch) | |
tree | 4b4a38f06ea91e5149ef7883b2c673963800d997 | |
parent | 750e90e4403df23d6b271afb90e6b4d463739965 (diff) |
[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.
-rw-r--r-- | llvm/include/llvm/IR/Function.h | 3 | ||||
-rw-r--r-- | llvm/lib/IR/BasicBlock.cpp | 16 | ||||
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/IR/Instruction.cpp | 6 | ||||
-rw-r--r-- | llvm/test/DebugInfo/salvage-limit-expr-size.ll | 1 | ||||
-rw-r--r-- | llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-localvars.ll | 1 |
6 files changed, 21 insertions, 9 deletions
diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index 6ac768b51395..cb87a4498032 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -722,8 +722,9 @@ public: /// 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. diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp index 15b7e50fe6ec..dca528328384 100644 --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -237,12 +237,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() { @@ -821,9 +821,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; } diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 53cbf0191896..d8c1b0d534f6 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -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(); } } } diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index 717e33f1857b..d7bf1447921f 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -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 diff --git a/llvm/test/DebugInfo/salvage-limit-expr-size.ll b/llvm/test/DebugInfo/salvage-limit-expr-size.ll index 39bf14b062e1..94e451327b21 100644 --- a/llvm/test/DebugInfo/salvage-limit-expr-size.ll +++ b/llvm/test/DebugInfo/salvage-limit-expr-size.ll @@ -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. diff --git a/llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-localvars.ll b/llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-localvars.ll index 83887397459d..19558a227b9f 100644 --- a/llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-localvars.ll +++ b/llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-localvars.ll @@ -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: |