Skip to content

[KeyInstr] Inline atom info #133481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2025
Merged

[KeyInstr] Inline atom info #133481

merged 2 commits into from
May 6, 2025

Conversation

OCHyams
Copy link
Contributor

@OCHyams OCHyams commented Mar 28, 2025

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.

Copy link
Contributor Author

OCHyams commented Mar 28, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented Mar 28, 2025

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-debuginfo

Author: Orlando Cazalet-Hyams (OCHyams)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/133481.diff

3 Files Affected:

  • (modified) llvm/lib/IR/DebugLoc.cpp (+1)
  • (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+2-1)
  • (added) llvm/test/DebugInfo/KeyInstructions/Generic/inline.ll (+53)
diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp
index bdea52180f74a..61f5bd8e9b0a2 100644
--- a/llvm/lib/IR/DebugLoc.cpp
+++ b/llvm/lib/IR/DebugLoc.cpp
@@ -129,6 +129,7 @@ DebugLoc DebugLoc::appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt,
   // Starting from the top, rebuild the nodes to point to the new inlined-at
   // location (then rebuilding the rest of the chain behind it) and update the
   // map of already-constructed inlined-at nodes.
+  // Key Instructions: InlinedAt fields don't need atom info.
   for (const DILocation *MD : reverse(InlinedAtLocations))
     Cache[MD] = Last = DILocation::getDistinct(
         Ctx, MD->getLine(), MD->getColumn(), MD->getScope(), Last);
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 1404867fda6bc..9202451f5726d 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1813,7 +1813,8 @@ static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
                                DenseMap<const MDNode *, MDNode *> &IANodes) {
   auto IA = DebugLoc::appendInlinedAt(OrigDL, InlinedAt, Ctx, IANodes);
   return DILocation::get(Ctx, OrigDL.getLine(), OrigDL.getCol(),
-                         OrigDL.getScope(), IA);
+                         OrigDL.getScope(), IA, OrigDL.isImplicitCode(),
+                         OrigDL->getAtomGroup(), OrigDL->getAtomRank());
 }
 
 /// Update inlined instructions' line numbers to
diff --git a/llvm/test/DebugInfo/KeyInstructions/Generic/inline.ll b/llvm/test/DebugInfo/KeyInstructions/Generic/inline.ll
new file mode 100644
index 0000000000000..c2663ee51a77d
--- /dev/null
+++ b/llvm/test/DebugInfo/KeyInstructions/Generic/inline.ll
@@ -0,0 +1,53 @@
+; RUN: opt %s -passes=inline -S -o - | FileCheck %s
+
+;; Inline `f` into `g`. The inlined assignment store and add should retain
+;; their atom info.
+
+; CHECK: _Z1gi
+; CHECK-NOT: _Z1fi
+; CHECK: %add.i = add nsw i32 %mul.i, 1, !dbg [[G1R2:!.*]]
+; CHECK-NEXT: store i32 %add.i, ptr %x.i, align 4, !dbg [[G1R1:!.*]]
+
+; CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+; CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+
+define hidden void @_Z1fi(i32 noundef %a) !dbg !11 {
+entry:
+  %a.addr = alloca i32, align 4
+  %x = alloca i32, align 4
+  store i32 %a, ptr %a.addr, align 4
+  %0 = load i32, ptr %a.addr, align 4, !dbg !18
+  %mul = mul nsw i32 %0, 2, !dbg !18
+  %add = add nsw i32 %mul, 1, !dbg !19
+  store i32 %add, ptr %x, align 4, !dbg !20
+  ret void, !dbg !22
+}
+
+define hidden void @_Z1gi(i32 noundef %b) !dbg !23 {
+entry:
+  %b.addr = alloca i32, align 4
+  store i32 %b, ptr %b.addr, align 4
+  %0 = load i32, ptr %b.addr, align 4, !dbg !24
+  call void @_Z1fi(i32 noundef %0), !dbg !24
+  ret void, !dbg !25
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+!llvm.ident = !{!10}
+
+!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)
+!1 = !DIFile(filename: "test.cpp", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!10 = !{!"clang version 19.0.0"}
+!11 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !12, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!12 = !DISubroutineType(types: !13)
+!13 = !{}
+!18 = !DILocation(line: 2, scope: !11)
+!19 = !DILocation(line: 2, scope: !11, atomGroup: 1, atomRank: 2)
+!20 = !DILocation(line: 2, scope: !11, atomGroup: 1, atomRank: 1)
+!22 = !DILocation(line: 3, scope: !11, atomGroup: 2, atomRank: 1)
+!23 = distinct !DISubprogram(name: "g", scope: !1, file: !1, line: 4, type: !12, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!24 = !DILocation(line: 5, scope: !23)
+!25 = !DILocation(line: 6, scope: !23, atomGroup: 1, atomRank: 1)

Copy link
Contributor

@SLTozer SLTozer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, besides a couple inline comments.

@@ -1813,7 +1813,8 @@ static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
DenseMap<const MDNode *, MDNode *> &IANodes) {
auto IA = DebugLoc::appendInlinedAt(OrigDL, InlinedAt, Ctx, IANodes);
return DILocation::get(Ctx, OrigDL.getLine(), OrigDL.getCol(),
OrigDL.getScope(), IA);
OrigDL.getScope(), IA, OrigDL.isImplicitCode(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my comment on a different review, propagating OrigDL's IsImplicitCode field is a change in behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(note to others: this was discussed offline as fine to ignore)

Comment on lines 19 to 32
%0 = load i32, ptr %a.addr, align 4, !dbg !18
%mul = mul nsw i32 %0, 2, !dbg !18
%add = add nsw i32 %mul, 1, !dbg !19
store i32 %add, ptr %x, align 4, !dbg !20
ret void, !dbg !22
}

define hidden void @_Z1gi(i32 noundef %b) !dbg !23 {
entry:
%b.addr = alloca i32, align 4
store i32 %b, ptr %b.addr, align 4
%0 = load i32, ptr %b.addr, align 4, !dbg !24
call void @_Z1fi(i32 noundef %0), !dbg !24
ret void, !dbg !25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, could remove DILocations from the instructions that aren't relevant to the test.

Copy link
Member

@jmorse jmorse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@OCHyams OCHyams force-pushed the users/OCHyams/ki-llvm-merge branch from 0335154 to 2c538d7 Compare May 1, 2025 13:48
@OCHyams OCHyams force-pushed the users/OCHyams/ki-llvm-inline branch from a6f7a92 to fde8c9e Compare May 1, 2025 15:09
@OCHyams OCHyams force-pushed the users/OCHyams/ki-llvm-merge branch from 1353653 to 6c4caf3 Compare May 6, 2025 12:09
Base automatically changed from users/OCHyams/ki-llvm-merge to main May 6, 2025 12:48
OCHyams added 2 commits May 6, 2025 13:53
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.
@OCHyams OCHyams force-pushed the users/OCHyams/ki-llvm-inline branch from c89fa2b to 06aae56 Compare May 6, 2025 12:54
@OCHyams OCHyams merged commit 73a7a3d into main May 6, 2025
4 of 6 checks passed
@OCHyams OCHyams deleted the users/OCHyams/ki-llvm-inline branch May 6, 2025 13:38
OCHyams added a commit to OCHyams/llvm-project that referenced this pull request May 6, 2025
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
OCHyams added a commit to OCHyams/llvm-project that referenced this pull request May 6, 2025
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
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants