-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DebugInfo] Update DIBuilder insertion to take InsertPosition #126059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-debuginfo Author: Harald van Dijk (hvdijk) ChangesAfter #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. Patch is 35.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/126059.diff 11 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index db595796c067e98..c80bc866e31edf8 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4897,7 +4897,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
llvm::DILocation::get(CGM.getLLVMContext(), Line,
Column, Scope,
CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
}
}
}
@@ -4965,7 +4965,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
llvm::DILocation::get(CGM.getLLVMContext(), Line,
Column, Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
return D;
}
@@ -5071,7 +5071,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
llvm::DILocation::get(CGM.getLLVMContext(), Line,
Column, Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
return D;
}
@@ -5118,7 +5118,7 @@ void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {
DBuilder.insertLabel(L,
llvm::DILocation::get(CGM.getLLVMContext(), Line, Column,
Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
}
llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
@@ -5196,9 +5196,10 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
LexicalBlockStack.back(), CurInlinedAt);
auto *Expr = DBuilder.createExpression(addr);
if (InsertPoint)
- DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);
+ DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint->getIterator());
else
- DBuilder.insertDeclare(Storage, D, Expr, DL, Builder.GetInsertBlock());
+ DBuilder.insertDeclare(Storage, D, Expr, DL,
+ Builder.GetInsertBlock()->end());
}
llvm::DILocalVariable *
@@ -5381,7 +5382,7 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
llvm::DILocation::get(CGM.getLLVMContext(), line,
column, scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
}
llvm::DIDerivedType *
@@ -5861,7 +5862,7 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder,
if (auto InsertPoint = Value->getInsertionPointAfterDef()) {
DBuilder.insertDbgValueIntrinsic(Value, D, DBuilder.createExpression(), DIL,
- &**InsertPoint);
+ *InsertPoint);
}
}
diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h
index 6c479415b9ed274..71455a9337b1fa9 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -92,33 +92,15 @@ namespace llvm {
/// Create an \a temporary node and track it in \a UnresolvedNodes.
void trackIfUnresolved(MDNode *N);
- /// Internal helper for insertDeclare.
- DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore);
-
- /// Internal helper for insertLabel.
- DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore);
-
/// Internal helper. Track metadata if untracked and insert \p DVR.
- void insertDbgVariableRecord(DbgVariableRecord *DVR, BasicBlock *InsertBB,
- Instruction *InsertBefore,
- bool InsertAtHead = false);
+ void insertDbgVariableRecord(DbgVariableRecord *DVR,
+ InsertPosition InsertPt);
/// Internal helper with common code used by insertDbg{Value,Addr}Intrinsic.
Instruction *insertDbgIntrinsic(llvm::Function *Intrinsic, llvm::Value *Val,
DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore);
-
- /// Internal helper for insertDbgValueIntrinsic.
- DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val,
- DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore);
+ InsertPosition InsertPt);
public:
/// Construct a builder for a module.
@@ -959,16 +941,6 @@ namespace llvm {
StringRef Name = "",
DINodeArray Elements = nullptr);
- /// Insert a new llvm.dbg.declare intrinsic call.
- /// \param Storage llvm::Value of the variable
- /// \param VarInfo Variable's debug info descriptor.
- /// \param Expr A complex location expression.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd);
-
/// Insert a new llvm.dbg.assign intrinsic call.
/// \param LinkedInstr Instruction with a DIAssignID to link with the new
/// intrinsic. The intrinsic will be inserted after
@@ -993,46 +965,28 @@ namespace llvm {
/// \param VarInfo Variable's debug info descriptor.
/// \param Expr A complex location expression.
/// \param DL Debug info location.
- /// \param InsertBefore Location for the new intrinsic.
+ /// \param InsertPt Location for the new intrinsic.
DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore);
+ InsertPosition InsertPt);
/// Insert a new llvm.dbg.label intrinsic call.
/// \param LabelInfo Label's debug info descriptor.
/// \param DL Debug info location.
/// \param InsertBefore Location for the new intrinsic.
DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
- Instruction *InsertBefore);
-
- /// Insert a new llvm.dbg.label intrinsic call.
- /// \param LabelInfo Label's debug info descriptor.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertAtEnd);
-
- /// Insert a new llvm.dbg.value intrinsic call.
- /// \param Val llvm::Value of the variable
- /// \param VarInfo Variable's debug info descriptor.
- /// \param Expr A complex location expression.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val,
- DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertPt);
/// Insert a new llvm.dbg.value intrinsic call.
/// \param Val llvm::Value of the variable
/// \param VarInfo Variable's debug info descriptor.
/// \param Expr A complex location expression.
/// \param DL Debug info location.
- /// \param InsertBefore Location for the new intrinsic.
+ /// \param InsertPt Location for the new intrinsic.
DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val,
DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore);
+ InsertPosition InsertPt);
/// Replace the vtable holder in the given type.
///
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 8f9462ab46d8852..0ccf43a29ca01d6 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -959,22 +959,6 @@ DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
File, Line, Col);
}
-DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore) {
- return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(),
- InsertBefore);
-}
-
-DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- // If this block already has a terminator then insert this intrinsic before
- // the terminator. Otherwise, put it at the end of the block.
- Instruction *InsertBefore = InsertAtEnd->getTerminator();
- return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
-}
-
DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
DILocalVariable *SrcVar,
DIExpression *ValExpr, Value *Addr,
@@ -987,11 +971,10 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
if (M.IsNewDbgInfoFormat) {
DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign(
Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
- BasicBlock *InsertBB = LinkedInstr->getParent();
// Insert after LinkedInstr.
BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
- Instruction *InsertBefore = NextIt == InsertBB->end() ? nullptr : &*NextIt;
- insertDbgVariableRecord(DVR, InsertBB, InsertBefore, true);
+ NextIt.setHeadBit(true);
+ insertDbgVariableRecord(DVR, NextIt);
return DVR;
}
@@ -1017,47 +1000,11 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
return DVI;
}
-DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
- Instruction *InsertBefore) {
- return insertLabel(LabelInfo, DL,
- InsertBefore ? InsertBefore->getParent() : nullptr,
- InsertBefore);
-}
-
-DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- return insertLabel(LabelInfo, DL, InsertAtEnd, nullptr);
-}
-
-DbgInstPtr DIBuilder::insertDbgValueIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- Instruction *InsertBefore) {
- DbgInstPtr DVI = insertDbgValueIntrinsic(
- V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
- InsertBefore);
- if (auto *Inst = dyn_cast<Instruction *>(DVI))
- cast<CallInst>(Inst)->setTailCall();
- return DVI;
-}
-
-DbgInstPtr DIBuilder::insertDbgValueIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
-}
-
/// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
/// This abstracts over the various ways to specify an insert position.
static void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore) {
- if (InsertBefore)
- Builder.SetInsertPoint(InsertBefore);
- else if (InsertBB)
- Builder.SetInsertPoint(InsertBB);
+ InsertPosition InsertPt) {
+ Builder.SetInsertPoint(InsertPt.getBasicBlock(), InsertPt);
Builder.SetCurrentDebugLocation(DL);
}
@@ -1070,26 +1017,28 @@ static Function *getDeclareIntrin(Module &M) {
return Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_declare);
}
-DbgInstPtr DIBuilder::insertDbgValueIntrinsic(
- llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr,
- const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
+DbgInstPtr DIBuilder::insertDbgValueIntrinsic(llvm::Value *Val,
+ DILocalVariable *VarInfo,
+ DIExpression *Expr,
+ const DILocation *DL,
+ InsertPosition InsertPt) {
if (M.IsNewDbgInfoFormat) {
DbgVariableRecord *DVR =
DbgVariableRecord::createDbgVariableRecord(Val, VarInfo, Expr, DL);
- insertDbgVariableRecord(DVR, InsertBB, InsertBefore);
+ insertDbgVariableRecord(DVR, InsertPt);
return DVR;
}
if (!ValueFn)
ValueFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_value);
- return insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertBB,
- InsertBefore);
+ auto *DVI = insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertPt);
+ cast<CallInst>(DVI)->setTailCall();
+ return DVI;
}
DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
+ InsertPosition InsertPt) {
assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
@@ -1099,7 +1048,7 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
if (M.IsNewDbgInfoFormat) {
DbgVariableRecord *DVR =
DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
- insertDbgVariableRecord(DVR, InsertBB, InsertBefore);
+ insertDbgVariableRecord(DVR, InsertPt);
return DVR;
}
@@ -1113,35 +1062,27 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
MetadataAsValue::get(VMContext, Expr)};
IRBuilder<> B(DL->getContext());
- initIRBuilder(B, DL, InsertBB, InsertBefore);
+ initIRBuilder(B, DL, InsertPt);
return B.CreateCall(DeclareFn, Args);
}
void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
- BasicBlock *InsertBB,
- Instruction *InsertBefore,
- bool InsertAtHead) {
- assert(InsertBefore || InsertBB);
+ InsertPosition InsertPt) {
+ assert(InsertPt.isValid());
trackIfUnresolved(DVR->getVariable());
trackIfUnresolved(DVR->getExpression());
if (DVR->isDbgAssign())
trackIfUnresolved(DVR->getAddressExpression());
- BasicBlock::iterator InsertPt;
- if (InsertBB && InsertBefore)
- InsertPt = InsertBefore->getIterator();
- else if (InsertBB)
- InsertPt = InsertBB->end();
- InsertPt.setHeadBit(InsertAtHead);
- InsertBB->insertDbgRecordBefore(DVR, InsertPt);
+ auto *BB = InsertPt.getBasicBlock();
+ BB->insertDbgRecordBefore(DVR, InsertPt);
}
Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
Value *V, DILocalVariable *VarInfo,
DIExpression *Expr,
const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
+ InsertPosition InsertPt) {
assert(IntrinsicFn && "must pass a non-null intrinsic function");
assert(V && "must pass a value to a dbg intrinsic");
assert(VarInfo &&
@@ -1158,13 +1099,12 @@ Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
MetadataAsValue::get(VMContext, Expr)};
IRBuilder<> B(DL->getContext());
- initIRBuilder(B, DL, InsertBB, InsertBefore);
+ initIRBuilder(B, DL, InsertPt);
return B.CreateCall(IntrinsicFn, Args);
}
DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
+ InsertPosition InsertPt) {
assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
@@ -1174,10 +1114,10 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
trackIfUnresolved(LabelInfo);
if (M.IsNewDbgInfoFormat) {
DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
- if (InsertBB && InsertBefore)
- InsertBB->insertDbgRecordBefore(DLR, InsertBefore->getIterator());
- else if (InsertBB)
- InsertBB->insertDbgRecordBefore(DLR, InsertBB->end());
+ if (InsertPt.isValid()) {
+ auto *BB = InsertPt.getBasicBlock();
+ BB->insertDbgRecordBefore(DLR, InsertPt);
+ }
return DLR;
}
@@ -1187,7 +1127,7 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};
IRBuilder<> B(DL->getContext());
- initIRBuilder(B, DL, InsertBB, InsertBefore);
+ initIRBuilder(B, DL, InsertPt);
return B.CreateCall(LabelFn, Args);
}
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 4ce518009bd3ea6..5b825d6df5e08e1 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1686,7 +1686,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.
@@ -1702,7 +1703,8 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordAtEnd(
LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block) {
DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
- unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), unwrap(Block));
+ unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
+ Block ? InsertPositi...
[truncated]
|
@llvm/pr-subscribers-llvm-ir Author: Harald van Dijk (hvdijk) ChangesAfter #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. Patch is 35.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/126059.diff 11 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index db595796c067e98..c80bc866e31edf8 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4897,7 +4897,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
llvm::DILocation::get(CGM.getLLVMContext(), Line,
Column, Scope,
CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
}
}
}
@@ -4965,7 +4965,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
llvm::DILocation::get(CGM.getLLVMContext(), Line,
Column, Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
return D;
}
@@ -5071,7 +5071,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
llvm::DILocation::get(CGM.getLLVMContext(), Line,
Column, Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
return D;
}
@@ -5118,7 +5118,7 @@ void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {
DBuilder.insertLabel(L,
llvm::DILocation::get(CGM.getLLVMContext(), Line, Column,
Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
}
llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
@@ -5196,9 +5196,10 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
LexicalBlockStack.back(), CurInlinedAt);
auto *Expr = DBuilder.createExpression(addr);
if (InsertPoint)
- DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);
+ DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint->getIterator());
else
- DBuilder.insertDeclare(Storage, D, Expr, DL, Builder.GetInsertBlock());
+ DBuilder.insertDeclare(Storage, D, Expr, DL,
+ Builder.GetInsertBlock()->end());
}
llvm::DILocalVariable *
@@ -5381,7 +5382,7 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
llvm::DILocation::get(CGM.getLLVMContext(), line,
column, scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
}
llvm::DIDerivedType *
@@ -5861,7 +5862,7 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder,
if (auto InsertPoint = Value->getInsertionPointAfterDef()) {
DBuilder.insertDbgValueIntrinsic(Value, D, DBuilder.createExpression(), DIL,
- &**InsertPoint);
+ *InsertPoint);
}
}
diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h
index 6c479415b9ed274..71455a9337b1fa9 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -92,33 +92,15 @@ namespace llvm {
/// Create an \a temporary node and track it in \a UnresolvedNodes.
void trackIfUnresolved(MDNode *N);
- /// Internal helper for insertDeclare.
- DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore);
-
- /// Internal helper for insertLabel.
- DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore);
-
/// Internal helper. Track metadata if untracked and insert \p DVR.
- void insertDbgVariableRecord(DbgVariableRecord *DVR, BasicBlock *InsertBB,
- Instruction *InsertBefore,
- bool InsertAtHead = false);
+ void insertDbgVariableRecord(DbgVariableRecord *DVR,
+ InsertPosition InsertPt);
/// Internal helper with common code used by insertDbg{Value,Addr}Intrinsic.
Instruction *insertDbgIntrinsic(llvm::Function *Intrinsic, llvm::Value *Val,
DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore);
-
- /// Internal helper for insertDbgValueIntrinsic.
- DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val,
- DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore);
+ InsertPosition InsertPt);
public:
/// Construct a builder for a module.
@@ -959,16 +941,6 @@ namespace llvm {
StringRef Name = "",
DINodeArray Elements = nullptr);
- /// Insert a new llvm.dbg.declare intrinsic call.
- /// \param Storage llvm::Value of the variable
- /// \param VarInfo Variable's debug info descriptor.
- /// \param Expr A complex location expression.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd);
-
/// Insert a new llvm.dbg.assign intrinsic call.
/// \param LinkedInstr Instruction with a DIAssignID to link with the new
/// intrinsic. The intrinsic will be inserted after
@@ -993,46 +965,28 @@ namespace llvm {
/// \param VarInfo Variable's debug info descriptor.
/// \param Expr A complex location expression.
/// \param DL Debug info location.
- /// \param InsertBefore Location for the new intrinsic.
+ /// \param InsertPt Location for the new intrinsic.
DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore);
+ InsertPosition InsertPt);
/// Insert a new llvm.dbg.label intrinsic call.
/// \param LabelInfo Label's debug info descriptor.
/// \param DL Debug info location.
/// \param InsertBefore Location for the new intrinsic.
DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
- Instruction *InsertBefore);
-
- /// Insert a new llvm.dbg.label intrinsic call.
- /// \param LabelInfo Label's debug info descriptor.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertAtEnd);
-
- /// Insert a new llvm.dbg.value intrinsic call.
- /// \param Val llvm::Value of the variable
- /// \param VarInfo Variable's debug info descriptor.
- /// \param Expr A complex location expression.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val,
- DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertPt);
/// Insert a new llvm.dbg.value intrinsic call.
/// \param Val llvm::Value of the variable
/// \param VarInfo Variable's debug info descriptor.
/// \param Expr A complex location expression.
/// \param DL Debug info location.
- /// \param InsertBefore Location for the new intrinsic.
+ /// \param InsertPt Location for the new intrinsic.
DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val,
DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore);
+ InsertPosition InsertPt);
/// Replace the vtable holder in the given type.
///
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 8f9462ab46d8852..0ccf43a29ca01d6 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -959,22 +959,6 @@ DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
File, Line, Col);
}
-DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore) {
- return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(),
- InsertBefore);
-}
-
-DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- // If this block already has a terminator then insert this intrinsic before
- // the terminator. Otherwise, put it at the end of the block.
- Instruction *InsertBefore = InsertAtEnd->getTerminator();
- return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
-}
-
DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
DILocalVariable *SrcVar,
DIExpression *ValExpr, Value *Addr,
@@ -987,11 +971,10 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
if (M.IsNewDbgInfoFormat) {
DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign(
Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
- BasicBlock *InsertBB = LinkedInstr->getParent();
// Insert after LinkedInstr.
BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
- Instruction *InsertBefore = NextIt == InsertBB->end() ? nullptr : &*NextIt;
- insertDbgVariableRecord(DVR, InsertBB, InsertBefore, true);
+ NextIt.setHeadBit(true);
+ insertDbgVariableRecord(DVR, NextIt);
return DVR;
}
@@ -1017,47 +1000,11 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
return DVI;
}
-DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
- Instruction *InsertBefore) {
- return insertLabel(LabelInfo, DL,
- InsertBefore ? InsertBefore->getParent() : nullptr,
- InsertBefore);
-}
-
-DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- return insertLabel(LabelInfo, DL, InsertAtEnd, nullptr);
-}
-
-DbgInstPtr DIBuilder::insertDbgValueIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- Instruction *InsertBefore) {
- DbgInstPtr DVI = insertDbgValueIntrinsic(
- V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
- InsertBefore);
- if (auto *Inst = dyn_cast<Instruction *>(DVI))
- cast<CallInst>(Inst)->setTailCall();
- return DVI;
-}
-
-DbgInstPtr DIBuilder::insertDbgValueIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
-}
-
/// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
/// This abstracts over the various ways to specify an insert position.
static void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore) {
- if (InsertBefore)
- Builder.SetInsertPoint(InsertBefore);
- else if (InsertBB)
- Builder.SetInsertPoint(InsertBB);
+ InsertPosition InsertPt) {
+ Builder.SetInsertPoint(InsertPt.getBasicBlock(), InsertPt);
Builder.SetCurrentDebugLocation(DL);
}
@@ -1070,26 +1017,28 @@ static Function *getDeclareIntrin(Module &M) {
return Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_declare);
}
-DbgInstPtr DIBuilder::insertDbgValueIntrinsic(
- llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr,
- const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
+DbgInstPtr DIBuilder::insertDbgValueIntrinsic(llvm::Value *Val,
+ DILocalVariable *VarInfo,
+ DIExpression *Expr,
+ const DILocation *DL,
+ InsertPosition InsertPt) {
if (M.IsNewDbgInfoFormat) {
DbgVariableRecord *DVR =
DbgVariableRecord::createDbgVariableRecord(Val, VarInfo, Expr, DL);
- insertDbgVariableRecord(DVR, InsertBB, InsertBefore);
+ insertDbgVariableRecord(DVR, InsertPt);
return DVR;
}
if (!ValueFn)
ValueFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_value);
- return insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertBB,
- InsertBefore);
+ auto *DVI = insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertPt);
+ cast<CallInst>(DVI)->setTailCall();
+ return DVI;
}
DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
+ InsertPosition InsertPt) {
assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
@@ -1099,7 +1048,7 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
if (M.IsNewDbgInfoFormat) {
DbgVariableRecord *DVR =
DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
- insertDbgVariableRecord(DVR, InsertBB, InsertBefore);
+ insertDbgVariableRecord(DVR, InsertPt);
return DVR;
}
@@ -1113,35 +1062,27 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
MetadataAsValue::get(VMContext, Expr)};
IRBuilder<> B(DL->getContext());
- initIRBuilder(B, DL, InsertBB, InsertBefore);
+ initIRBuilder(B, DL, InsertPt);
return B.CreateCall(DeclareFn, Args);
}
void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
- BasicBlock *InsertBB,
- Instruction *InsertBefore,
- bool InsertAtHead) {
- assert(InsertBefore || InsertBB);
+ InsertPosition InsertPt) {
+ assert(InsertPt.isValid());
trackIfUnresolved(DVR->getVariable());
trackIfUnresolved(DVR->getExpression());
if (DVR->isDbgAssign())
trackIfUnresolved(DVR->getAddressExpression());
- BasicBlock::iterator InsertPt;
- if (InsertBB && InsertBefore)
- InsertPt = InsertBefore->getIterator();
- else if (InsertBB)
- InsertPt = InsertBB->end();
- InsertPt.setHeadBit(InsertAtHead);
- InsertBB->insertDbgRecordBefore(DVR, InsertPt);
+ auto *BB = InsertPt.getBasicBlock();
+ BB->insertDbgRecordBefore(DVR, InsertPt);
}
Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
Value *V, DILocalVariable *VarInfo,
DIExpression *Expr,
const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
+ InsertPosition InsertPt) {
assert(IntrinsicFn && "must pass a non-null intrinsic function");
assert(V && "must pass a value to a dbg intrinsic");
assert(VarInfo &&
@@ -1158,13 +1099,12 @@ Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
MetadataAsValue::get(VMContext, Expr)};
IRBuilder<> B(DL->getContext());
- initIRBuilder(B, DL, InsertBB, InsertBefore);
+ initIRBuilder(B, DL, InsertPt);
return B.CreateCall(IntrinsicFn, Args);
}
DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
+ InsertPosition InsertPt) {
assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
@@ -1174,10 +1114,10 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
trackIfUnresolved(LabelInfo);
if (M.IsNewDbgInfoFormat) {
DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
- if (InsertBB && InsertBefore)
- InsertBB->insertDbgRecordBefore(DLR, InsertBefore->getIterator());
- else if (InsertBB)
- InsertBB->insertDbgRecordBefore(DLR, InsertBB->end());
+ if (InsertPt.isValid()) {
+ auto *BB = InsertPt.getBasicBlock();
+ BB->insertDbgRecordBefore(DLR, InsertPt);
+ }
return DLR;
}
@@ -1187,7 +1127,7 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};
IRBuilder<> B(DL->getContext());
- initIRBuilder(B, DL, InsertBB, InsertBefore);
+ initIRBuilder(B, DL, InsertPt);
return B.CreateCall(LabelFn, Args);
}
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 4ce518009bd3ea6..5b825d6df5e08e1 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1686,7 +1686,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.
@@ -1702,7 +1703,8 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordAtEnd(
LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block) {
DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
- unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), unwrap(Block));
+ unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
+ Block ? InsertPositi...
[truncated]
|
@llvm/pr-subscribers-clang-codegen Author: Harald van Dijk (hvdijk) ChangesAfter #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. Patch is 35.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/126059.diff 11 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index db595796c067e98..c80bc866e31edf8 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4897,7 +4897,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
llvm::DILocation::get(CGM.getLLVMContext(), Line,
Column, Scope,
CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
}
}
}
@@ -4965,7 +4965,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
llvm::DILocation::get(CGM.getLLVMContext(), Line,
Column, Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
return D;
}
@@ -5071,7 +5071,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
llvm::DILocation::get(CGM.getLLVMContext(), Line,
Column, Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
return D;
}
@@ -5118,7 +5118,7 @@ void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {
DBuilder.insertLabel(L,
llvm::DILocation::get(CGM.getLLVMContext(), Line, Column,
Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
}
llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
@@ -5196,9 +5196,10 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
LexicalBlockStack.back(), CurInlinedAt);
auto *Expr = DBuilder.createExpression(addr);
if (InsertPoint)
- DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);
+ DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint->getIterator());
else
- DBuilder.insertDeclare(Storage, D, Expr, DL, Builder.GetInsertBlock());
+ DBuilder.insertDeclare(Storage, D, Expr, DL,
+ Builder.GetInsertBlock()->end());
}
llvm::DILocalVariable *
@@ -5381,7 +5382,7 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
llvm::DILocation::get(CGM.getLLVMContext(), line,
column, scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ Builder.GetInsertBlock()->end());
}
llvm::DIDerivedType *
@@ -5861,7 +5862,7 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder,
if (auto InsertPoint = Value->getInsertionPointAfterDef()) {
DBuilder.insertDbgValueIntrinsic(Value, D, DBuilder.createExpression(), DIL,
- &**InsertPoint);
+ *InsertPoint);
}
}
diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h
index 6c479415b9ed274..71455a9337b1fa9 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -92,33 +92,15 @@ namespace llvm {
/// Create an \a temporary node and track it in \a UnresolvedNodes.
void trackIfUnresolved(MDNode *N);
- /// Internal helper for insertDeclare.
- DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore);
-
- /// Internal helper for insertLabel.
- DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore);
-
/// Internal helper. Track metadata if untracked and insert \p DVR.
- void insertDbgVariableRecord(DbgVariableRecord *DVR, BasicBlock *InsertBB,
- Instruction *InsertBefore,
- bool InsertAtHead = false);
+ void insertDbgVariableRecord(DbgVariableRecord *DVR,
+ InsertPosition InsertPt);
/// Internal helper with common code used by insertDbg{Value,Addr}Intrinsic.
Instruction *insertDbgIntrinsic(llvm::Function *Intrinsic, llvm::Value *Val,
DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore);
-
- /// Internal helper for insertDbgValueIntrinsic.
- DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val,
- DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore);
+ InsertPosition InsertPt);
public:
/// Construct a builder for a module.
@@ -959,16 +941,6 @@ namespace llvm {
StringRef Name = "",
DINodeArray Elements = nullptr);
- /// Insert a new llvm.dbg.declare intrinsic call.
- /// \param Storage llvm::Value of the variable
- /// \param VarInfo Variable's debug info descriptor.
- /// \param Expr A complex location expression.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd);
-
/// Insert a new llvm.dbg.assign intrinsic call.
/// \param LinkedInstr Instruction with a DIAssignID to link with the new
/// intrinsic. The intrinsic will be inserted after
@@ -993,46 +965,28 @@ namespace llvm {
/// \param VarInfo Variable's debug info descriptor.
/// \param Expr A complex location expression.
/// \param DL Debug info location.
- /// \param InsertBefore Location for the new intrinsic.
+ /// \param InsertPt Location for the new intrinsic.
DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore);
+ InsertPosition InsertPt);
/// Insert a new llvm.dbg.label intrinsic call.
/// \param LabelInfo Label's debug info descriptor.
/// \param DL Debug info location.
/// \param InsertBefore Location for the new intrinsic.
DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
- Instruction *InsertBefore);
-
- /// Insert a new llvm.dbg.label intrinsic call.
- /// \param LabelInfo Label's debug info descriptor.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertAtEnd);
-
- /// Insert a new llvm.dbg.value intrinsic call.
- /// \param Val llvm::Value of the variable
- /// \param VarInfo Variable's debug info descriptor.
- /// \param Expr A complex location expression.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val,
- DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertPt);
/// Insert a new llvm.dbg.value intrinsic call.
/// \param Val llvm::Value of the variable
/// \param VarInfo Variable's debug info descriptor.
/// \param Expr A complex location expression.
/// \param DL Debug info location.
- /// \param InsertBefore Location for the new intrinsic.
+ /// \param InsertPt Location for the new intrinsic.
DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val,
DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore);
+ InsertPosition InsertPt);
/// Replace the vtable holder in the given type.
///
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 8f9462ab46d8852..0ccf43a29ca01d6 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -959,22 +959,6 @@ DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
File, Line, Col);
}
-DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore) {
- return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(),
- InsertBefore);
-}
-
-DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- // If this block already has a terminator then insert this intrinsic before
- // the terminator. Otherwise, put it at the end of the block.
- Instruction *InsertBefore = InsertAtEnd->getTerminator();
- return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
-}
-
DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
DILocalVariable *SrcVar,
DIExpression *ValExpr, Value *Addr,
@@ -987,11 +971,10 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
if (M.IsNewDbgInfoFormat) {
DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign(
Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
- BasicBlock *InsertBB = LinkedInstr->getParent();
// Insert after LinkedInstr.
BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
- Instruction *InsertBefore = NextIt == InsertBB->end() ? nullptr : &*NextIt;
- insertDbgVariableRecord(DVR, InsertBB, InsertBefore, true);
+ NextIt.setHeadBit(true);
+ insertDbgVariableRecord(DVR, NextIt);
return DVR;
}
@@ -1017,47 +1000,11 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
return DVI;
}
-DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
- Instruction *InsertBefore) {
- return insertLabel(LabelInfo, DL,
- InsertBefore ? InsertBefore->getParent() : nullptr,
- InsertBefore);
-}
-
-DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- return insertLabel(LabelInfo, DL, InsertAtEnd, nullptr);
-}
-
-DbgInstPtr DIBuilder::insertDbgValueIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- Instruction *InsertBefore) {
- DbgInstPtr DVI = insertDbgValueIntrinsic(
- V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
- InsertBefore);
- if (auto *Inst = dyn_cast<Instruction *>(DVI))
- cast<CallInst>(Inst)->setTailCall();
- return DVI;
-}
-
-DbgInstPtr DIBuilder::insertDbgValueIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
-}
-
/// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
/// This abstracts over the various ways to specify an insert position.
static void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore) {
- if (InsertBefore)
- Builder.SetInsertPoint(InsertBefore);
- else if (InsertBB)
- Builder.SetInsertPoint(InsertBB);
+ InsertPosition InsertPt) {
+ Builder.SetInsertPoint(InsertPt.getBasicBlock(), InsertPt);
Builder.SetCurrentDebugLocation(DL);
}
@@ -1070,26 +1017,28 @@ static Function *getDeclareIntrin(Module &M) {
return Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_declare);
}
-DbgInstPtr DIBuilder::insertDbgValueIntrinsic(
- llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr,
- const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
+DbgInstPtr DIBuilder::insertDbgValueIntrinsic(llvm::Value *Val,
+ DILocalVariable *VarInfo,
+ DIExpression *Expr,
+ const DILocation *DL,
+ InsertPosition InsertPt) {
if (M.IsNewDbgInfoFormat) {
DbgVariableRecord *DVR =
DbgVariableRecord::createDbgVariableRecord(Val, VarInfo, Expr, DL);
- insertDbgVariableRecord(DVR, InsertBB, InsertBefore);
+ insertDbgVariableRecord(DVR, InsertPt);
return DVR;
}
if (!ValueFn)
ValueFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_value);
- return insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertBB,
- InsertBefore);
+ auto *DVI = insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertPt);
+ cast<CallInst>(DVI)->setTailCall();
+ return DVI;
}
DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
+ InsertPosition InsertPt) {
assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
@@ -1099,7 +1048,7 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
if (M.IsNewDbgInfoFormat) {
DbgVariableRecord *DVR =
DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
- insertDbgVariableRecord(DVR, InsertBB, InsertBefore);
+ insertDbgVariableRecord(DVR, InsertPt);
return DVR;
}
@@ -1113,35 +1062,27 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
MetadataAsValue::get(VMContext, Expr)};
IRBuilder<> B(DL->getContext());
- initIRBuilder(B, DL, InsertBB, InsertBefore);
+ initIRBuilder(B, DL, InsertPt);
return B.CreateCall(DeclareFn, Args);
}
void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
- BasicBlock *InsertBB,
- Instruction *InsertBefore,
- bool InsertAtHead) {
- assert(InsertBefore || InsertBB);
+ InsertPosition InsertPt) {
+ assert(InsertPt.isValid());
trackIfUnresolved(DVR->getVariable());
trackIfUnresolved(DVR->getExpression());
if (DVR->isDbgAssign())
trackIfUnresolved(DVR->getAddressExpression());
- BasicBlock::iterator InsertPt;
- if (InsertBB && InsertBefore)
- InsertPt = InsertBefore->getIterator();
- else if (InsertBB)
- InsertPt = InsertBB->end();
- InsertPt.setHeadBit(InsertAtHead);
- InsertBB->insertDbgRecordBefore(DVR, InsertPt);
+ auto *BB = InsertPt.getBasicBlock();
+ BB->insertDbgRecordBefore(DVR, InsertPt);
}
Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
Value *V, DILocalVariable *VarInfo,
DIExpression *Expr,
const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
+ InsertPosition InsertPt) {
assert(IntrinsicFn && "must pass a non-null intrinsic function");
assert(V && "must pass a value to a dbg intrinsic");
assert(VarInfo &&
@@ -1158,13 +1099,12 @@ Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
MetadataAsValue::get(VMContext, Expr)};
IRBuilder<> B(DL->getContext());
- initIRBuilder(B, DL, InsertBB, InsertBefore);
+ initIRBuilder(B, DL, InsertPt);
return B.CreateCall(IntrinsicFn, Args);
}
DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
+ InsertPosition InsertPt) {
assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
@@ -1174,10 +1114,10 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
trackIfUnresolved(LabelInfo);
if (M.IsNewDbgInfoFormat) {
DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
- if (InsertBB && InsertBefore)
- InsertBB->insertDbgRecordBefore(DLR, InsertBefore->getIterator());
- else if (InsertBB)
- InsertBB->insertDbgRecordBefore(DLR, InsertBB->end());
+ if (InsertPt.isValid()) {
+ auto *BB = InsertPt.getBasicBlock();
+ BB->insertDbgRecordBefore(DLR, InsertPt);
+ }
return DLR;
}
@@ -1187,7 +1127,7 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};
IRBuilder<> B(DL->getContext());
- initIRBuilder(B, DL, InsertBB, InsertBefore);
+ initIRBuilder(B, DL, InsertPt);
return B.CreateCall(LabelFn, Args);
}
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 4ce518009bd3ea6..5b825d6df5e08e1 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1686,7 +1686,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.
@@ -1702,7 +1703,8 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordAtEnd(
LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block) {
DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
- unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), unwrap(Block));
+ unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
+ Block ? InsertPositi...
[truncated]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks for putting this all together, one nit inline,
Is this intended to be cherry-picked into the release branch or not? Seeing how the original motivation was to ease downstream compatibilities, I'd assumed there'd be the need for something to be cherry-picked, and this might be too invasive at this stage to be moved across. I don't have a full understanding of the use case though.
@OCHyams I believe you did the C API changes, are there any additional concerns in this area?
Yes, I was hoping that we were still early enough to be able to cherry-pick it without issues, especially as the aim is to restore a certain level of compatibility with previous LLVM releases. If that is not the case though, then at least it will be helpful to know that only LLVM 20 will require workarounds. |
After llvm#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.
a815481
to
6929e0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OCHyams I believe you did the C API changes, are there any additional concerns in this area?
SGTM, just one inline question
Instr ? InsertPosition(unwrap<Instruction>(Instr)->getIterator()) | ||
: nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this trip an assertion in the nullptr
InsertPosition case (assert(InsertPt.isValid());
in insertDbgVariableRecord
called by insertDeclare
). Or am I reading this wrong? (Same question applies to the other calls below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Previously, a call with !Instr
would result in a call to insertDeclare(..., /*InsertBefore=*/nullptr)
which results in insertDeclare(..., /*InsertBB=*/nullptr->getParent(), /*InsertBefore=*/nullptr)
, so it would (on typical systems) result in a crash already.
At the same time, previously, insertLabel(..., /*InsertBefore=*/nullptr)
would result in insertLabel(..., /*InsertBB=*/nullptr, /*InsertBefore=*/nullptr)
which specifically does not insert anything.
And insertDbgValueIntrinsic(..., /*InsertBefore=*/nullptr)
is special-cased to call insertDbgValueIntrinsic(..., /*InsertBB=*/nullptr, /*InsertBefore=*/nullptr)
the same way, but the latter calls insertDbgVariableRecord
unconditionally and hits the existing assert(InsertBefore || InsertBB);
assert.
This is a messy situation and in this PR I tried to just keep that exactly the same. What previously worked should still work. What previously didn't work should still not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for unpicking that.
This is a messy situation and in this PR I tried to just keep that exactly the same. What previously worked should still work. What previously didn't work should still not work.
SGTM. I feel as though these functions should probably have asserts in them saying as such but that could reasonably be argued to be out of scope of the patch.
Patch LGTM to me too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think for consistency, it would be nice to update these functions so that they all treat nullptr
consistently, as a request to create whatever the function says to create but not insert it anywhere. When I have some extra time I'll see if that's easy to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM too; thanks for running with this!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/116/builds/10165 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/177/builds/12901 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/14702 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/17955 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/175/builds/13112 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/185/builds/13063 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/138/builds/10230 Here is the relevant piece of the build log for the reference
|
The buildbot failures look like something conflicted with changes that have since gone into LLVM. I have reverted the change for now and will check what is going on and update. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/2/builds/16997 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/14543 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/11762 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/13269 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/12905 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/12902 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/33/builds/11262 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/22689 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/19454 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/56/builds/18511 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/13685 Here is the relevant piece of the build log for the reference
|
…26059) After llvm#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.
…llvm#126059)" This reverts commit 3ec9f74.
…26059) After llvm#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.
…llvm#126059)" This reverts commit 3ec9f74.
…26059) After llvm#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.
…llvm#126059)" This reverts commit 3ec9f74.
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.