From 1083ec647f16314bcc9af8c4d6b11f50d288bca6 Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Thu, 13 Feb 2025 10:46:42 +0000 Subject: [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. --- llvm/lib/IR/DebugInfo.cpp | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'llvm/lib/IR/DebugInfo.cpp') 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(VarInfo), unwrap(Expr), unwrap(DL), - unwrap(Instr)); + Instr ? InsertPosition(unwrap(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(VarInfo), unwrap(Expr), - unwrap(DebugLoc), unwrap(Instr)); + unwrap(DebugLoc), + Instr ? InsertPosition(unwrap(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(VarInfo), unwrap(Expr), - unwrap(DebugLoc), unwrap(Block)); + unwrap(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(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(Context), StringRef(Name, NameLen), - unwrapDI(File), LineNo, AlwaysPreserve)); + unwrapDI(Context), StringRef(Name, NameLen), + unwrapDI(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(LabelInfo), unwrapDI(Location), - unwrap(InsertBefore)); + unwrapDI(LabelInfo), unwrapDI(Location), + InsertBefore + ? InsertPosition(unwrap(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(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(LabelInfo), unwrapDI(Location), - unwrap(InsertAtEnd)); + unwrapDI(LabelInfo), unwrapDI(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. -- cgit v1.1