diff options
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r-- | llvm/lib/IR/DIBuilder.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index 76d7ade..989b554 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -30,7 +30,7 @@ static cl::opt<bool> DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU) : M(m), VMContext(M.getContext()), CUNode(CU), DeclareFn(nullptr), - ValueFn(nullptr), LabelFn(nullptr), AddrFn(nullptr), + ValueFn(nullptr), LabelFn(nullptr), AddrFn(nullptr), AssignFn(nullptr), AllowUnresolvedNodes(AllowUnresolvedNodes) { if (CUNode) { if (const auto &ETs = CUNode->getEnumTypes()) @@ -960,6 +960,36 @@ Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore); } +DbgAssignIntrinsic * +DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val, + DILocalVariable *SrcVar, DIExpression *ValExpr, + Value *Addr, DIExpression *AddrExpr, + const DILocation *DL) { + LLVMContext &Ctx = LinkedInstr->getContext(); + Module *M = LinkedInstr->getModule(); + if (!AssignFn) + AssignFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_assign); + + auto *Link = LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID); + assert(Link && "Linked instruction must have DIAssign metadata attached"); + + 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); + return DVI; +} + Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, Instruction *InsertBefore) { return insertLabel(LabelInfo, DL, |