diff options
author | Jeremy Morse <jeremy.morse@sony.com> | 2025-01-24 09:06:01 +0000 |
---|---|---|
committer | Jeremy Morse <jeremy.morse@sony.com> | 2025-01-28 14:02:24 +0000 |
commit | 79499f010d2bfe809187a9a5f042d4e4ee1f1bcc (patch) | |
tree | 8d15eaeaa3e3d7e959964593eaa30dab709efdae /llvm/lib/IR/BasicBlock.cpp | |
parent | a1ab5b4c87256ce7e99d6fd4bd0c62641e6ce853 (diff) | |
download | llvm-79499f010d2bfe809187a9a5f042d4e4ee1f1bcc.zip llvm-79499f010d2bfe809187a9a5f042d4e4ee1f1bcc.tar.gz llvm-79499f010d2bfe809187a9a5f042d4e4ee1f1bcc.tar.bz2 |
[NFC][DebugInfo] Deprecate iterator-taking moveBefore and getFirstNonPHI (#124290)
The RemoveDIs project [0] makes debug intrinsics obsolete and to support
this instruction iterators carry an extra bit of debug information. To
maintain debug information accuracy insertion needs to be performed with a
BasicBlock::iterator rather than with Instruction pointers, otherwise the
extra bit of debug information is lost.
To that end, we're deprecating getFirstNonPHI and moveBefore for
instruction pointers. They're replaced by getFirstNonPHIIt and an
iterator-taking moveBefore: switching to the replacement is
straightforwards, and 99% of call-sites need only to unwrap the iterator
with &* or call getIterator() on an Instruction pointer.
The exception is when inserting instructions at the start of a block: if
you call getFirstNonPHI() (or begin() or getFirstInsertionPt()) and then
insert something at that position, you must pass the BasicBlock::iterator
returned into the insertion method. Unwrapping with &* and then calling
getIterator strips the debug-info bit we wish to preserve. Please do
contact us about any use case that's confusing or unclear [1].
[0] https://llvm.org/docs/RemoveDIsDebugInfo.html
[1] https://discourse.llvm.org/t/psa-ir-output-changing-from-debug-intrinsics-to-debug-records/79578
Diffstat (limited to 'llvm/lib/IR/BasicBlock.cpp')
-rw-r--r-- | llvm/lib/IR/BasicBlock.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp index 0fbe023..8eaa6e5 100644 --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -372,15 +372,19 @@ const Instruction* BasicBlock::getFirstNonPHI() const { } BasicBlock::const_iterator BasicBlock::getFirstNonPHIIt() const { - const Instruction *I = getFirstNonPHI(); - if (!I) - return end(); - BasicBlock::const_iterator It = I->getIterator(); - // Set the head-inclusive bit to indicate that this iterator includes - // any debug-info at the start of the block. This is a no-op unless the - // appropriate CMake flag is set. - It.setHeadBit(true); - return It; + for (const Instruction &I : *this) { + if (isa<PHINode>(I)) + continue; + + BasicBlock::const_iterator It = I.getIterator(); + // Set the head-inclusive bit to indicate that this iterator includes + // any debug-info at the start of the block. This is a no-op unless the + // appropriate CMake flag is set. + It.setHeadBit(true); + return It; + } + + return end(); } BasicBlock::const_iterator @@ -424,11 +428,10 @@ BasicBlock::getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp) const { } BasicBlock::const_iterator BasicBlock::getFirstInsertionPt() const { - const Instruction *FirstNonPHI = getFirstNonPHI(); - if (!FirstNonPHI) + const_iterator InsertPt = getFirstNonPHIIt(); + if (InsertPt == end()) return end(); - const_iterator InsertPt = FirstNonPHI->getIterator(); if (InsertPt->isEHPad()) ++InsertPt; // Set the head-inclusive bit to indicate that this iterator includes // any debug-info at the start of the block. This is a no-op unless the |