aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DIBuilder.cpp
diff options
context:
space:
mode:
authorJeremy Morse <jeremy.morse@sony.com>2025-06-11 14:51:13 +0100
committerJeremy Morse <jeremy.morse@sony.com>2025-06-11 14:52:17 +0100
commit76197ea6f91f802467f2614e1217e99eb4037200 (patch)
tree7398905a7079d66ec996598a4a9ec4043c1d05ec /llvm/lib/IR/DIBuilder.cpp
parent46d9abbba2ad63c0280d4248cc2349de78439294 (diff)
downloadllvm-76197ea6f91f802467f2614e1217e99eb4037200.zip
llvm-76197ea6f91f802467f2614e1217e99eb4037200.tar.gz
llvm-76197ea6f91f802467f2614e1217e99eb4037200.tar.bz2
Revert "[DebugInfo][RemoveDIs] Remove some debug intrinsic-only codepaths (#143451)"
This reverts commit c71a2e688828ab3ede4fb54168a674ff68396f61. /me squints -- this is hitting an assertion I thought had been deleted, will revert and investigate for a bit.
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r--llvm/lib/IR/DIBuilder.cpp97
1 files changed, 77 insertions, 20 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 1484c54..5e5ff22 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -1047,13 +1047,36 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID));
assert(Link && "Linked instruction must have DIAssign metadata attached");
- DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign(
- Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
- // Insert after LinkedInstr.
- BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
- NextIt.setHeadBit(true);
- insertDbgVariableRecord(DVR, NextIt);
- return DVR;
+ if (M.IsNewDbgInfoFormat) {
+ DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign(
+ Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
+ // Insert after LinkedInstr.
+ BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
+ NextIt.setHeadBit(true);
+ insertDbgVariableRecord(DVR, NextIt);
+ return DVR;
+ }
+
+ LLVMContext &Ctx = LinkedInstr->getContext();
+ Module *M = LinkedInstr->getModule();
+ if (!AssignFn)
+ AssignFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_assign);
+
+ std::array<Value *, 6> Args = {
+ MetadataAsValue::get(Ctx, ValueAsMetadata::get(Val)),
+ MetadataAsValue::get(Ctx, SrcVar),
+ MetadataAsValue::get(Ctx, ValExpr),
+ MetadataAsValue::get(Ctx, Link),
+ MetadataAsValue::get(Ctx, ValueAsMetadata::get(Addr)),
+ MetadataAsValue::get(Ctx, AddrExpr),
+ };
+
+ IRBuilder<> B(Ctx);
+ B.SetCurrentDebugLocation(DL);
+
+ auto *DVI = cast<DbgAssignIntrinsic>(B.CreateCall(AssignFn, Args));
+ DVI->insertAfter(LinkedInstr->getIterator());
+ return DVI;
}
/// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
@@ -1078,10 +1101,18 @@ DbgInstPtr DIBuilder::insertDbgValueIntrinsic(llvm::Value *Val,
DIExpression *Expr,
const DILocation *DL,
InsertPosition InsertPt) {
- DbgVariableRecord *DVR =
- DbgVariableRecord::createDbgVariableRecord(Val, VarInfo, Expr, DL);
- insertDbgVariableRecord(DVR, InsertPt);
- return DVR;
+ if (M.IsNewDbgInfoFormat) {
+ DbgVariableRecord *DVR =
+ DbgVariableRecord::createDbgVariableRecord(Val, VarInfo, Expr, DL);
+ insertDbgVariableRecord(DVR, InsertPt);
+ return DVR;
+ }
+
+ if (!ValueFn)
+ ValueFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_value);
+ auto *DVI = insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertPt);
+ cast<CallInst>(DVI)->setTailCall();
+ return DVI;
}
DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
@@ -1093,10 +1124,25 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
VarInfo->getScope()->getSubprogram() &&
"Expected matching subprograms");
- DbgVariableRecord *DVR =
- DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
- insertDbgVariableRecord(DVR, InsertPt);
- return DVR;
+ if (M.IsNewDbgInfoFormat) {
+ DbgVariableRecord *DVR =
+ DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
+ insertDbgVariableRecord(DVR, InsertPt);
+ return DVR;
+ }
+
+ if (!DeclareFn)
+ DeclareFn = getDeclareIntrin(M);
+
+ trackIfUnresolved(VarInfo);
+ trackIfUnresolved(Expr);
+ Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
+ MetadataAsValue::get(VMContext, VarInfo),
+ MetadataAsValue::get(VMContext, Expr)};
+
+ IRBuilder<> B(DL->getContext());
+ initIRBuilder(B, DL, InsertPt);
+ return B.CreateCall(DeclareFn, Args);
}
void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
@@ -1145,12 +1191,23 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
"Expected matching subprograms");
trackIfUnresolved(LabelInfo);
- DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
- if (InsertPt.isValid()) {
- auto *BB = InsertPt.getBasicBlock();
- BB->insertDbgRecordBefore(DLR, InsertPt);
+ if (M.IsNewDbgInfoFormat) {
+ DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
+ if (InsertPt.isValid()) {
+ auto *BB = InsertPt.getBasicBlock();
+ BB->insertDbgRecordBefore(DLR, InsertPt);
+ }
+ return DLR;
}
- return DLR;
+
+ if (!LabelFn)
+ LabelFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_label);
+
+ Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};
+
+ IRBuilder<> B(DL->getContext());
+ initIRBuilder(B, DL, InsertPt);
+ return B.CreateCall(LabelFn, Args);
}
void DIBuilder::replaceVTableHolder(DICompositeType *&T, DIType *VTableHolder) {