Skip to content

Commit a363cca

Browse files
authored
[KeyInstr][debugify] Add --debugify-atoms to add key instructions metadata (#133483)
RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668
1 parent 0eeabd4 commit a363cca

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

llvm/lib/Transforms/Utils/Debugify.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ using namespace llvm;
3535

3636
namespace {
3737

38+
cl::opt<bool> ApplyAtomGroups("debugify-atoms", cl::init(false));
39+
3840
cl::opt<bool> Quiet("debugify-quiet",
3941
cl::desc("Suppress verbose debugify output"));
4042

@@ -142,8 +144,13 @@ bool llvm::applyDebugifyMetadata(
142144

143145
for (BasicBlock &BB : F) {
144146
// Attach debug locations.
145-
for (Instruction &I : BB)
146-
I.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
147+
for (Instruction &I : BB) {
148+
uint64_t AtomGroup = ApplyAtomGroups ? NextLine : 0;
149+
uint8_t AtomRank = ApplyAtomGroups ? 1 : 0;
150+
uint64_t Line = NextLine++;
151+
I.setDebugLoc(DILocation::get(Ctx, Line, 1, SP, nullptr, false,
152+
AtomGroup, AtomRank));
153+
}
147154

148155
if (DebugifyLevel < Level::LocationsAndVariables)
149156
continue;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; RUN: opt -passes=debugify --debugify-atoms -S -o - < %s \
2+
; RUN: | FileCheck %s
3+
4+
;; Mirrors llvm/test/DebugInfo/debugify.ll. Split out here because the
5+
;; test is only supported if LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS is enabled
6+
;; (which is a condition for running this test directory). Once the conditional
7+
;; compilation of the feature is removed this can be merged into the original.
8+
9+
; CHECK-LABEL: define void @foo
10+
define void @foo() {
11+
; CHECK: ret void, !dbg ![[RET1:.*]]
12+
ret void
13+
}
14+
15+
; CHECK-LABEL: define i32 @bar
16+
define i32 @bar() {
17+
; CHECK: call void @foo(), !dbg ![[CALL1:.*]]
18+
call void @foo()
19+
20+
; CHECK: add i32 0, 1, !dbg ![[ADD1:.*]]
21+
%sum = add i32 0, 1
22+
23+
; CHECK: ret i32 0, !dbg ![[RET2:.*]]
24+
ret i32 0
25+
}
26+
27+
; CHECK-LABEL: define weak_odr zeroext i1 @baz
28+
define weak_odr zeroext i1 @baz() {
29+
; CHECK-NOT: !dbg
30+
ret i1 false
31+
}
32+
33+
; CHECK-LABEL: define i32 @boom
34+
define i32 @boom() {
35+
; CHECK: [[result:%.*]] = musttail call i32 @bar(), !dbg ![[musttail:.*]]
36+
%retval = musttail call i32 @bar()
37+
; CHECK-NEXT: ret i32 [[result]], !dbg ![[musttailRes:.*]]
38+
ret i32 %retval
39+
}
40+
41+
; CHECK-DAG: ![[RET1]] = !DILocation(line: 1, {{.*}}, atomGroup: 1, atomRank: 1
42+
; CHECK-DAG: ![[CALL1]] = !DILocation(line: 2, {{.*}}, atomGroup: 2, atomRank: 1
43+
; CHECK-DAG: ![[ADD1]] = !DILocation(line: 3, {{.*}}, atomGroup: 3, atomRank: 1
44+
; CHECK-DAG: ![[RET2]] = !DILocation(line: 4, {{.*}}, atomGroup: 4, atomRank: 1
45+
; CHECK-DAG: ![[musttail]] = !DILocation(line: 5, {{.*}}, atomGroup: 5, atomRank: 1
46+
; CHECK-DAG: ![[musttailRes]] = !DILocation(line: 6, {{.*}}, atomGroup: 6, atomRank: 1

0 commit comments

Comments
 (0)