Skip to content

Commit 7f1c801

Browse files
teresajohnsonadrian-prantl
authored andcommitted
Enable stripping of multiple DILocation on !llvm.loop metadata
Summary: I found that stripDebugInfo was still leaving significant amounts of debug info due to !llvm.loop that contained DILocation after stripping. The support for stripping debug info on !llvm.loop added in r293377 only removes a single DILocation. Enhance that to remove all DILocation from !llvm.loop. Reviewers: hfinkel, aprantl, dsanders Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31117 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298213 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit ad346a2)
1 parent 021099d commit 7f1c801

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

lib/IR/DebugInfo.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,26 +243,29 @@ bool DebugInfoFinder::addScope(DIScope *Scope) {
243243

244244
static llvm::MDNode *stripDebugLocFromLoopID(llvm::MDNode *N) {
245245
assert(N->op_begin() != N->op_end() && "Missing self reference?");
246-
auto DebugLocOp =
247-
std::find_if(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
248-
return isa<DILocation>(Op.get());
249-
});
250246

251-
// No debug location, we do not have to rewrite this MDNode.
252-
if (DebugLocOp == N->op_end())
247+
// if there is no debug location, we do not have to rewrite this MDNode.
248+
if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
249+
return isa<DILocation>(Op.get());
250+
}))
253251
return N;
254252

255-
// There is only the debug location without any actual loop metadata, hence we
253+
// If there is only the debug location without any actual loop metadata, we
256254
// can remove the metadata.
257-
if (N->getNumOperands() == 2)
255+
if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
256+
return !isa<DILocation>(Op.get());
257+
}))
258258
return nullptr;
259259

260260
SmallVector<Metadata *, 4> Args;
261261
// Reserve operand 0 for loop id self reference.
262262
auto TempNode = MDNode::getTemporary(N->getContext(), None);
263263
Args.push_back(TempNode.get());
264-
Args.append(N->op_begin() + 1, DebugLocOp);
265-
Args.append(DebugLocOp + 1, N->op_end());
264+
// Add all non-debug location operands back.
265+
for (auto Op = N->op_begin() + 1; Op != N->op_end(); Op++) {
266+
if (!isa<DILocation>(*Op))
267+
Args.push_back(*Op);
268+
}
266269

267270
// Set the first operand to itself.
268271
MDNode *LoopID = MDNode::get(N->getContext(), Args);

test/DebugInfo/strip-loop-metadata.ll

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ return:
3333
ret void, !dbg !21
3434
}
3535

36+
; CHECK-LABEL: _Z5test3v
37+
; CHECK: br {{.*}} !llvm.loop [[LOOP2:![0-9]+]]
38+
define void @_Z5test3v() !dbg !22 {
39+
entry:
40+
br label %while.body, !dbg !23
41+
42+
while.body:
43+
call void @_Z3barv(), !dbg !24
44+
br label %while.body, !dbg !25, !llvm.loop !26
45+
46+
return:
47+
ret void, !dbg !28
48+
}
49+
50+
; CHECK-LABEL: _Z5test4v
51+
; CHECK-NOT: br {{.*}} !llvm.loop
52+
define void @_Z5test4v() !dbg !30 {
53+
entry:
54+
br label %while.body, !dbg !31
55+
56+
while.body:
57+
call void @_Z3barv(), !dbg !32
58+
br label %while.body, !dbg !33, !llvm.loop !34
59+
60+
return:
61+
ret void, !dbg !36
62+
}
63+
3664
!llvm.dbg.cu = !{!0}
3765
!llvm.module.flags = !{!3, !4, !5}
3866
!llvm.ident = !{!6}
@@ -59,6 +87,21 @@ return:
5987
!19 = distinct !{!19, !16, !20}
6088
!20 = !{!"llvm.loop.unroll.enable"}
6189
!21 = !DILocation(line: 12, column: 1, scope: !15)
90+
!22 = distinct !DISubprogram(name: "test3", scope: !1, file: !1, line: 8, type: !8, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
91+
!23 = !DILocation(line: 8, column: 14, scope: !22)
92+
!24 = !DILocation(line: 11, column: 5, scope: !22)
93+
!25 = !DILocation(line: 10, column: 3, scope: !22)
94+
!26 = distinct !{!26, !23, !29, !27}
95+
!27 = !{!"llvm.loop.unroll.enable"}
96+
!28 = !DILocation(line: 12, column: 1, scope: !22)
97+
!29 = !DILocation(line: 12, column: 1, scope: !22)
98+
!30 = distinct !DISubprogram(name: "test4", scope: !1, file: !1, line: 8, type: !8, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
99+
!31 = !DILocation(line: 8, column: 14, scope: !30)
100+
!32 = !DILocation(line: 11, column: 5, scope: !30)
101+
!33 = !DILocation(line: 10, column: 3, scope: !30)
102+
!34 = distinct !{!34, !31, !35}
103+
!35 = !DILocation(line: 12, column: 1, scope: !30)
104+
!36 = !DILocation(line: 12, column: 1, scope: !30)
62105

63106
; CHECK-NOT: !DICompileUnit
64107
; CHECK-NOT: !DIFile
@@ -68,4 +111,5 @@ return:
68111
; CHECK-NOT: !DILexicalBlockFile
69112
; CHECK: [[LOOP]] = distinct !{[[LOOP]], [[LOOP_UNROLL:![0-9]+]]}
70113
; CHECK-NEXT: [[LOOP_UNROLL]] = !{!"llvm.loop.unroll.enable"}
114+
; CHECK: [[LOOP2]] = distinct !{[[LOOP2]], [[LOOP_UNROLL]]}
71115
; CHECK-NOT: !DILocation

0 commit comments

Comments
 (0)