Skip to content

[KeyInstr][debugify] Add --debugify-atoms to add key instructions metadata #133483

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions llvm/lib/Transforms/Utils/Debugify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ using namespace llvm;

namespace {

cl::opt<bool> ApplyAtomGroups("debugify-atoms", cl::init(false));

cl::opt<bool> Quiet("debugify-quiet",
cl::desc("Suppress verbose debugify output"));

Expand Down Expand Up @@ -142,8 +144,13 @@ bool llvm::applyDebugifyMetadata(

for (BasicBlock &BB : F) {
// Attach debug locations.
for (Instruction &I : BB)
I.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
for (Instruction &I : BB) {
uint64_t AtomGroup = ApplyAtomGroups ? NextLine : 0;
uint8_t AtomRank = ApplyAtomGroups ? 1 : 0;
uint64_t Line = NextLine++;
I.setDebugLoc(DILocation::get(Ctx, Line, 1, SP, nullptr, false,
AtomGroup, AtomRank));
}

if (DebugifyLevel < Level::LocationsAndVariables)
continue;
Expand Down
46 changes: 46 additions & 0 deletions llvm/test/DebugInfo/KeyInstructions/debugify.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
; RUN: opt -passes=debugify --debugify-atoms -S -o - < %s \
; RUN: | FileCheck %s

;; Mirrors llvm/test/DebugInfo/debugify.ll. Split out here because the
;; test is only supported if LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS is enabled
;; (which is a condition for running this test directory). Once the conditional
;; compilation of the feature is removed this can be merged into the original.

; CHECK-LABEL: define void @foo
define void @foo() {
; CHECK: ret void, !dbg ![[RET1:.*]]
ret void
}

; CHECK-LABEL: define i32 @bar
define i32 @bar() {
; CHECK: call void @foo(), !dbg ![[CALL1:.*]]
call void @foo()

; CHECK: add i32 0, 1, !dbg ![[ADD1:.*]]
%sum = add i32 0, 1

; CHECK: ret i32 0, !dbg ![[RET2:.*]]
ret i32 0
}

; CHECK-LABEL: define weak_odr zeroext i1 @baz
define weak_odr zeroext i1 @baz() {
; CHECK-NOT: !dbg
ret i1 false
}

; CHECK-LABEL: define i32 @boom
define i32 @boom() {
; CHECK: [[result:%.*]] = musttail call i32 @bar(), !dbg ![[musttail:.*]]
%retval = musttail call i32 @bar()
; CHECK-NEXT: ret i32 [[result]], !dbg ![[musttailRes:.*]]
ret i32 %retval
}

; CHECK-DAG: ![[RET1]] = !DILocation(line: 1, {{.*}}, atomGroup: 1, atomRank: 1
; CHECK-DAG: ![[CALL1]] = !DILocation(line: 2, {{.*}}, atomGroup: 2, atomRank: 1
; CHECK-DAG: ![[ADD1]] = !DILocation(line: 3, {{.*}}, atomGroup: 3, atomRank: 1
; CHECK-DAG: ![[RET2]] = !DILocation(line: 4, {{.*}}, atomGroup: 4, atomRank: 1
; CHECK-DAG: ![[musttail]] = !DILocation(line: 5, {{.*}}, atomGroup: 5, atomRank: 1
; CHECK-DAG: ![[musttailRes]] = !DILocation(line: 6, {{.*}}, atomGroup: 6, atomRank: 1
Loading