aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.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/Local.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/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp23
1 files changed, 6 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 2c63283..6d7c710 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1693,9 +1693,7 @@ static void insertDbgValueOrDbgVariableRecord(DIBuilder &Builder, Value *DV,
const DebugLoc &NewLoc,
BasicBlock::iterator Instr) {
if (!UseNewDbgInfoFormat) {
- auto DbgVal = Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
- (Instruction *)nullptr);
- cast<Instruction *>(DbgVal)->insertBefore(Instr);
+ Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc, Instr);
} else {
// RemoveDIs: if we're using the new debug-info format, allocate a
// DbgVariableRecord directly instead of a dbg.value intrinsic.
@@ -1708,19 +1706,10 @@ static void insertDbgValueOrDbgVariableRecord(DIBuilder &Builder, Value *DV,
static void insertDbgValueOrDbgVariableRecordAfter(
DIBuilder &Builder, Value *DV, DILocalVariable *DIVar, DIExpression *DIExpr,
- const DebugLoc &NewLoc, BasicBlock::iterator Instr) {
- if (!UseNewDbgInfoFormat) {
- auto DbgVal = Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
- (Instruction *)nullptr);
- cast<Instruction *>(DbgVal)->insertAfter(Instr);
- } else {
- // RemoveDIs: if we're using the new debug-info format, allocate a
- // DbgVariableRecord directly instead of a dbg.value intrinsic.
- ValueAsMetadata *DVAM = ValueAsMetadata::get(DV);
- DbgVariableRecord *DV =
- new DbgVariableRecord(DVAM, DIVar, DIExpr, NewLoc.get());
- Instr->getParent()->insertDbgRecordAfter(DV, &*Instr);
- }
+ const DebugLoc &NewLoc, Instruction *Instr) {
+ BasicBlock::iterator NextIt = std::next(Instr->getIterator());
+ NextIt.setHeadBit(true);
+ insertDbgValueOrDbgVariableRecord(Builder, DV, DIVar, DIExpr, NewLoc, NextIt);
}
/// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
@@ -1812,7 +1801,7 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
// preferable to keep tracking both the loaded value and the original
// address in case the alloca can not be elided.
insertDbgValueOrDbgVariableRecordAfter(Builder, LI, DIVar, DIExpr, NewLoc,
- LI->getIterator());
+ LI);
}
void llvm::ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,