aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DIBuilder.cpp
diff options
context:
space:
mode:
authorOCHyams <orlando.hyams@sony.com>2022-11-07 17:39:40 +0000
committerOCHyams <orlando.hyams@sony.com>2022-11-08 16:52:11 +0000
commit913b561c0a1d5817be7e2bc811a42bd4b9b6ff1e (patch)
tree86ab5e3c78078089379a34e9497b6bc2126e80ea /llvm/lib/IR/DIBuilder.cpp
parent322cf744b926a31986f78d74c79713e412cf811d (diff)
downloadllvm-913b561c0a1d5817be7e2bc811a42bd4b9b6ff1e.zip
llvm-913b561c0a1d5817be7e2bc811a42bd4b9b6ff1e.tar.gz
llvm-913b561c0a1d5817be7e2bc811a42bd4b9b6ff1e.tar.bz2
[Assignment Tracking][6/*] Add trackAssignments function
The Assignment Tracking debug-info feature is outlined in this RFC: https://discourse.llvm.org/t/ rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir Add trackAssignments which adds assignment tracking metadata to a function for a specified set of variables. The intended callers are the inliner and the front end - those calls will be added in separate patches. I've added a pass called declare-to-assign (AssignmentTrackingPass) that converts dbg.declare intrinsics to dbg.assigns using trackAssignments so that the function can be easily tested (see llvm/test/DebugInfo/Generic/track-assignments.ll). The pass could also be used by front ends to easily test out enabling assignment tracking. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D132225
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r--llvm/lib/IR/DIBuilder.cpp32
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,