[PATCH] D133576: [Assignment Tracking][5.1/*] Add deleteAssignmentMarkers function
Orlando Cazalet-Hyams via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 9 07:44:04 PDT 2022
Orlando updated this revision to Diff 459062.
Orlando retitled this revision from "[Assignment Tracing][5.1/*] Add deleteAssignmentMarkers function" to "[Assignment Tracking][5.1/*] Add deleteAssignmentMarkers function".
Orlando added a comment.
+ Add unittest
+ Fix review title
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133576/new/
https://reviews.llvm.org/D133576
Files:
llvm/include/llvm/IR/DebugInfo.h
llvm/lib/IR/DebugInfo.cpp
llvm/unittests/IR/DebugInfoTest.cpp
Index: llvm/unittests/IR/DebugInfoTest.cpp
===================================================================
--- llvm/unittests/IR/DebugInfoTest.cpp
+++ llvm/unittests/IR/DebugInfoTest.cpp
@@ -359,6 +359,13 @@
ret void, !dbg !19
}
+ define dso_local void @fun3() !dbg !21 {
+ entry:
+ %local = alloca i32, align 4, !DIAssignID !24
+ call void @llvm.dbg.assign(metadata i32 undef, metadata !22, metadata !DIExpression(), metadata !24, metadata i32* undef, metadata !DIExpression()), !dbg !23
+ ret void
+ }
+
declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
!llvm.dbg.cu = !{!0}
@@ -386,6 +393,10 @@
!18 = !DILocalVariable(name: "local2", scope: !17, file: !1, line: 2, type: !11)
!19 = !DILocation(line: 4, column: 1, scope: !17)
!20 = distinct !DIAssignID()
+ !21 = distinct !DISubprogram(name: "fun3", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+ !22 = !DILocalVariable(name: "local4", scope: !21, file: !1, line: 2, type: !11)
+ !23 = !DILocation(line: 4, column: 1, scope: !21)
+ !24 = distinct !DIAssignID()
)");
// Check the test IR isn't malformed.
@@ -444,7 +455,16 @@
ASSERT_TRUE(std::distance(Fun2Insts.begin(), Fun2Insts.end()) == 1);
EXPECT_EQ(*Fun2Insts.begin(), &Fun2Alloca);
- // 3. Check that deleting works and applies only to the target function.
+ // 3. Check that deleting dbg.assigns from a specific instruction works.
+ Instruction &Fun3Alloca =
+ *M->getFunction("fun3")->getEntryBlock().getFirstNonPHIOrDbg();
+ auto Fun3Markers = at::getAssignmentMarkers(&Fun3Alloca);
+ ASSERT_TRUE(std::distance(Fun3Markers.begin(), Fun3Markers.end()) == 1);
+ at::deleteAssignmentMarkers(&Fun3Alloca);
+ Fun3Markers = at::getAssignmentMarkers(&Fun3Alloca);
+ EXPECT_EQ(Fun3Markers.empty(), true);
+
+ // 4. Check that deleting works and applies only to the target function.
at::deleteAll(&Fun1);
// There should now only be the alloca and ret in fun1.
EXPECT_EQ(Fun1.begin()->size(), 2);
Index: llvm/lib/IR/DebugInfo.cpp
===================================================================
--- llvm/lib/IR/DebugInfo.cpp
+++ llvm/lib/IR/DebugInfo.cpp
@@ -1696,6 +1696,15 @@
return make_range(IDAsValue->user_begin(), IDAsValue->user_end());
}
+void at::deleteAssignmentMarkers(const Instruction *Inst) {
+ auto Range = getAssignmentMarkers(Inst);
+ if (Range.empty())
+ return;
+ SmallVector<DbgAssignIntrinsic *> ToDelete(Range.begin(), Range.end());
+ for (auto *DAI : ToDelete)
+ DAI->eraseFromParent();
+}
+
void at::RAUW(DIAssignID *Old, DIAssignID *New) {
// Replace MetadataAsValue uses.
if (auto *OldIDAsValue =
Index: llvm/include/llvm/IR/DebugInfo.h
===================================================================
--- llvm/include/llvm/IR/DebugInfo.h
+++ llvm/include/llvm/IR/DebugInfo.h
@@ -219,6 +219,9 @@
return make_range(Value::user_iterator(), Value::user_iterator());
}
+/// Delete the llvm.dbg.assgin intrinsics linked to \p Inst.
+void deleteAssignmentMarkers(const Instruction *Inst);
+
/// Replace all uses (and attachments) of \p Old with \p New.
void RAUW(DIAssignID *Old, DIAssignID *New);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133576.459062.patch
Type: text/x-patch
Size: 3292 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220909/963ecbde/attachment.bin>
More information about the llvm-commits
mailing list