Skip to content

Commit 73a7a3d

Browse files
authored
[KeyInstr] Inline atom info (#133481)
Source atom groups are identified by an atom group number and inlined-at pair, so we simply can copy the atom numbers into the caller when inlining. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668
1 parent e79dc76 commit 73a7a3d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

llvm/lib/IR/DebugLoc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ DebugLoc DebugLoc::appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt,
135135
// Starting from the top, rebuild the nodes to point to the new inlined-at
136136
// location (then rebuilding the rest of the chain behind it) and update the
137137
// map of already-constructed inlined-at nodes.
138+
// Key Instructions: InlinedAt fields don't need atom info.
138139
for (const DILocation *MD : reverse(InlinedAtLocations))
139140
Cache[MD] = Last = DILocation::getDistinct(
140141
Ctx, MD->getLine(), MD->getColumn(), MD->getScope(), Last);

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,8 @@ static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
18191819
DenseMap<const MDNode *, MDNode *> &IANodes) {
18201820
auto IA = DebugLoc::appendInlinedAt(OrigDL, InlinedAt, Ctx, IANodes);
18211821
return DILocation::get(Ctx, OrigDL.getLine(), OrigDL.getCol(),
1822-
OrigDL.getScope(), IA);
1822+
OrigDL.getScope(), IA, OrigDL.isImplicitCode(),
1823+
OrigDL->getAtomGroup(), OrigDL->getAtomRank());
18231824
}
18241825

18251826
/// Update inlined instructions' line numbers to
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; RUN: opt %s -passes=inline -S -o - | FileCheck %s
2+
3+
;; Inline `f` into `g`. The inlined assignment store and add should retain
4+
;; their atom info.
5+
6+
; CHECK: _Z1gi
7+
; CHECK-NOT: _Z1fi
8+
; CHECK: %add.i = add nsw i32 %mul.i, 1, !dbg [[G1R2:!.*]]
9+
; CHECK-NEXT: store i32 %add.i, ptr %x.i, align 4, !dbg [[G1R1:!.*]]
10+
11+
; CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
12+
; CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
13+
14+
define hidden void @_Z1fi(i32 noundef %a) !dbg !11 {
15+
entry:
16+
%a.addr = alloca i32, align 4
17+
%x = alloca i32, align 4
18+
store i32 %a, ptr %a.addr, align 4
19+
%0 = load i32, ptr %a.addr, align 4
20+
%mul = mul nsw i32 %0, 2
21+
%add = add nsw i32 %mul, 1, !dbg !19
22+
store i32 %add, ptr %x, align 4, !dbg !20
23+
ret void
24+
}
25+
26+
define hidden void @_Z1gi(i32 noundef %b) !dbg !23 {
27+
entry:
28+
%b.addr = alloca i32, align 4
29+
store i32 %b, ptr %b.addr, align 4
30+
%0 = load i32, ptr %b.addr, align 4
31+
call void @_Z1fi(i32 noundef %0), !dbg !24
32+
ret void
33+
}
34+
35+
!llvm.dbg.cu = !{!0}
36+
!llvm.module.flags = !{!2, !3}
37+
!llvm.ident = !{!10}
38+
39+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_17, file: !1, producer: "clang version 19.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
40+
!1 = !DIFile(filename: "test.cpp", directory: "/")
41+
!2 = !{i32 7, !"Dwarf Version", i32 5}
42+
!3 = !{i32 2, !"Debug Info Version", i32 3}
43+
!10 = !{!"clang version 19.0.0"}
44+
!11 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !12, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
45+
!12 = !DISubroutineType(types: !13)
46+
!13 = !{}
47+
!19 = !DILocation(line: 2, scope: !11, atomGroup: 1, atomRank: 2)
48+
!20 = !DILocation(line: 2, scope: !11, atomGroup: 1, atomRank: 1)
49+
!23 = distinct !DISubprogram(name: "g", scope: !1, file: !1, line: 4, type: !12, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
50+
!24 = !DILocation(line: 5, scope: !23)
51+

0 commit comments

Comments
 (0)