aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DebugInfo.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/IR/DebugInfo.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/IR/DebugInfo.cpp')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index ea1d79d..cc36b71 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1690,7 +1690,8 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordBefore(
DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
- unwrap<Instruction>(Instr));
+ Instr ? InsertPosition(unwrap<Instruction>(Instr)->getIterator())
+ : nullptr);
// This assert will fail if the module is in the old debug info format.
// This function should only be called if the module is in the new
// debug info format.
@@ -1722,7 +1723,9 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueRecordBefore(
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr) {
DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
- unwrap<DILocation>(DebugLoc), unwrap<Instruction>(Instr));
+ unwrap<DILocation>(DebugLoc),
+ Instr ? InsertPosition(unwrap<Instruction>(Instr)->getIterator())
+ : nullptr);
// This assert will fail if the module is in the old debug info format.
// This function should only be called if the module is in the new
// debug info format.
@@ -1738,7 +1741,8 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueRecordAtEnd(
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) {
DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
- unwrap<DILocation>(DebugLoc), unwrap(Block));
+ unwrap<DILocation>(DebugLoc),
+ Block ? InsertPosition(unwrap(Block)->end()) : nullptr);
// This assert will fail if the module is in the old debug info format.
// This function should only be called if the module is in the new
// debug info format.
@@ -1804,21 +1808,25 @@ void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) {
unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
}
-LLVMMetadataRef LLVMDIBuilderCreateLabel(
- LLVMDIBuilderRef Builder,
- LLVMMetadataRef Context, const char *Name, size_t NameLen,
- LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve) {
+LLVMMetadataRef LLVMDIBuilderCreateLabel(LLVMDIBuilderRef Builder,
+ LLVMMetadataRef Context,
+ const char *Name, size_t NameLen,
+ LLVMMetadataRef File, unsigned LineNo,
+ LLVMBool AlwaysPreserve) {
return wrap(unwrap(Builder)->createLabel(
- unwrapDI<DIScope>(Context), StringRef(Name, NameLen),
- unwrapDI<DIFile>(File), LineNo, AlwaysPreserve));
+ unwrapDI<DIScope>(Context), StringRef(Name, NameLen),
+ unwrapDI<DIFile>(File), LineNo, AlwaysPreserve));
}
-LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
- LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
- LLVMMetadataRef Location, LLVMValueRef InsertBefore) {
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(LLVMDIBuilderRef Builder,
+ LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location,
+ LLVMValueRef InsertBefore) {
DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
- unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
- unwrap<Instruction>(InsertBefore));
+ unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
+ InsertBefore
+ ? InsertPosition(unwrap<Instruction>(InsertBefore)->getIterator())
+ : nullptr);
// This assert will fail if the module is in the old debug info format.
// This function should only be called if the module is in the new
// debug info format.
@@ -1829,12 +1837,13 @@ LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
return wrap(cast<DbgRecord *>(DbgInst));
}
-LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(
- LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
- LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd) {
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(LLVMDIBuilderRef Builder,
+ LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location,
+ LLVMBasicBlockRef InsertAtEnd) {
DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
- unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
- unwrap(InsertAtEnd));
+ unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
+ InsertAtEnd ? InsertPosition(unwrap(InsertAtEnd)->end()) : nullptr);
// This assert will fail if the module is in the old debug info format.
// This function should only be called if the module is in the new
// debug info format.