aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Debugify.cpp
diff options
context:
space:
mode:
authorHarald van Dijk <harald.vandijk@codeplay.com>2025-02-12 17:38:59 +0000
committerGitHub <noreply@github.com>2025-02-12 17:38:59 +0000
commit3ec9f7494b31f2fe51d5ed0e07adcf4b7199def6 (patch)
tree89381a101050af46d7df249b16cd0d2c41885810 /llvm/lib/Transforms/Utils/Debugify.cpp
parentf8c7457c79eece1bd1b7f15e7679517c7c63ad89 (diff)
downloadllvm-3ec9f7494b31f2fe51d5ed0e07adcf4b7199def6.zip
llvm-3ec9f7494b31f2fe51d5ed0e07adcf4b7199def6.tar.gz
llvm-3ec9f7494b31f2fe51d5ed0e07adcf4b7199def6.tar.bz2
[DebugInfo] Update DIBuilder insertion to take InsertPosition (#126059)
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.
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);