aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Debugify.cpp
diff options
context:
space:
mode:
authorHarald van Dijk <harald.vandijk@codeplay.com>2025-02-13 10:46:42 +0000
committerGitHub <noreply@github.com>2025-02-13 10:46:42 +0000
commit1083ec647f16314bcc9af8c4d6b11f50d288bca6 (patch)
treefbcfcb9558123fc7915bd90b412af1c8aec2e455 /llvm/lib/Transforms/Utils/Debugify.cpp
parent9c89faa62bbf71b1e634a993983cef5507aab249 (diff)
downloadllvm-1083ec647f16314bcc9af8c4d6b11f50d288bca6.zip
llvm-1083ec647f16314bcc9af8c4d6b11f50d288bca6.tar.gz
llvm-1083ec647f16314bcc9af8c4d6b11f50d288bca6.tar.bz2
[reland][DebugInfo] Update DIBuilder insertion to take InsertPosition (#126967)
After #124287 updated several functions to return iterators rather than Instruction *, it was no longer straightforward to pass their result to DIBuilder. This commit updates DIBuilder methods to accept an InsertPosition instead, so that they can be called with an iterator (preferred), or with a deprecation warning an Instruction *, or a BasicBlock *. This commit also updates the existing calls to the DIBuilder methods to pass in iterators. As a special exception, DIBuilder::insertDeclare() keeps a separate overload accepting a BasicBlock *InsertAtEnd. This is because despite the name, this method does not insert at the end of the block, therefore this cannot be handled implicitly by using InsertPosition.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Debugify.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Debugify.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp
index e5e2aa6..e47a6ce 100644
--- a/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -127,7 +127,7 @@ bool llvm::applyDebugifyMetadata(
// Helper that inserts a dbg.value before \p InsertBefore, copying the
// location (and possibly the type, if it's non-void) from \p TemplateInst.
auto insertDbgVal = [&](Instruction &TemplateInst,
- Instruction *InsertBefore) {
+ BasicBlock::iterator InsertPt) {
std::string Name = utostr(NextVar++);
Value *V = &TemplateInst;
if (TemplateInst.getType()->isVoidTy())
@@ -137,7 +137,7 @@ bool llvm::applyDebugifyMetadata(
getCachedDIType(V->getType()),
/*AlwaysPreserve=*/true);
DIB.insertDbgValueIntrinsic(V, LocalVar, DIB.createExpression(), Loc,
- InsertBefore);
+ InsertPt);
};
for (BasicBlock &BB : F) {
@@ -161,7 +161,9 @@ bool llvm::applyDebugifyMetadata(
// are made.
BasicBlock::iterator InsertPt = BB.getFirstInsertionPt();
assert(InsertPt != BB.end() && "Expected to find an insertion point");
- Instruction *InsertBefore = &*InsertPt;
+
+ // Insert after existing debug values to preserve order.
+ InsertPt.setHeadBit(false);
// Attach debug values.
for (Instruction *I = &*BB.begin(); I != LastInst; I = I->getNextNode()) {
@@ -172,9 +174,9 @@ bool llvm::applyDebugifyMetadata(
// Phis and EH pads must be grouped at the beginning of the block.
// Only advance the insertion point when we finish visiting these.
if (!isa<PHINode>(I) && !I->isEHPad())
- InsertBefore = I->getNextNode();
+ InsertPt = std::next(I->getIterator());
- insertDbgVal(*I, InsertBefore);
+ insertDbgVal(*I, InsertPt);
InsertedDbgVal = true;
}
}
@@ -185,7 +187,7 @@ bool llvm::applyDebugifyMetadata(
// those tests, and this helps with that.)
if (DebugifyLevel == Level::LocationsAndVariables && !InsertedDbgVal) {
auto *Term = findTerminatingInstruction(F.getEntryBlock());
- insertDbgVal(*Term, Term);
+ insertDbgVal(*Term, Term->getIterator());
}
if (ApplyToMF)
ApplyToMF(DIB, F);