From 4a943f25698d581c582627503cc7186bfa37b955 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Mon, 24 Mar 2025 15:53:27 +0000 Subject: [PATCH 1/2] [KeyInstr][debugify] Add --debugify-atoms to add key instructions metadata --- llvm/lib/Transforms/Utils/Debugify.cpp | 11 +++++++++-- llvm/test/DebugInfo/debugify.ll | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp index d67a563f531f6..3e323ccffcd99 100644 --- a/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -35,6 +35,8 @@ using namespace llvm; namespace { +cl::opt ApplyAtomGroups("debugify-atoms", cl::init(false)); + cl::opt Quiet("debugify-quiet", cl::desc("Suppress verbose debugify output")); @@ -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; diff --git a/llvm/test/DebugInfo/debugify.ll b/llvm/test/DebugInfo/debugify.ll index 191015f825933..269a301ce830c 100644 --- a/llvm/test/DebugInfo/debugify.ll +++ b/llvm/test/DebugInfo/debugify.ll @@ -1,6 +1,9 @@ ; RUN: opt -passes=debugify -S -o - < %s | FileCheck %s ; RUN: opt -passes=debugify -S -o - < %s | FileCheck %s +; RUN: opt -passes=debugify --debugify-atoms -S -o - < %s \ +; RUN: | FileCheck %s -check-prefixes=CHECK-ATOMS + ; RUN: opt -passes=debugify,debugify -S -o - < %s 2>&1 | \ ; RUN: FileCheck %s -check-prefix=CHECK-REPEAT ; RUN: opt -passes=debugify,debugify -S -o - < %s 2>&1 | \ @@ -101,6 +104,13 @@ define i32 @boom() { ; CHECK-DAG: ![[musttail]] = !DILocation(line: 5, column: 1 ; CHECK-DAG: ![[musttailRes]] = !DILocation(line: 6, column: 1 +; CHECK-ATOMS-DAG: !DILocation(line: 1{{.*}}, atomGroup: 1, atomRank: 1 +; CHECK-ATOMS-DAG: !DILocation(line: 2{{.*}}, atomGroup: 2, atomRank: 1 +; CHECK-ATOMS-DAG: !DILocation(line: 3{{.*}}, atomGroup: 3, atomRank: 1 +; CHECK-ATOMS-DAG: !DILocation(line: 4{{.*}}, atomGroup: 4, atomRank: 1 +; CHECK-ATOMS-DAG: !DILocation(line: 5{{.*}}, atomGroup: 5, atomRank: 1 +; CHECK-ATOMS-DAG: !DILocation(line: 6{{.*}}, atomGroup: 6, atomRank: 1 + ; --- DILocalVariables ; CHECK-DAG: ![[TY32:.*]] = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned) ; CHECK-DAG: !DILocalVariable(name: "1", scope: {{.*}}, file: {{.*}}, line: 1, type: ![[TY32]]) From 35ca36842c135678bdb8304b331265473d518766 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Tue, 6 May 2025 16:13:48 +0100 Subject: [PATCH 2/2] split into separate test to avoid failure in normal builds --- .../DebugInfo/KeyInstructions/debugify.ll | 46 +++++++++++++++++++ llvm/test/DebugInfo/debugify.ll | 10 ---- 2 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 llvm/test/DebugInfo/KeyInstructions/debugify.ll diff --git a/llvm/test/DebugInfo/KeyInstructions/debugify.ll b/llvm/test/DebugInfo/KeyInstructions/debugify.ll new file mode 100644 index 0000000000000..881375873f324 --- /dev/null +++ b/llvm/test/DebugInfo/KeyInstructions/debugify.ll @@ -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 diff --git a/llvm/test/DebugInfo/debugify.ll b/llvm/test/DebugInfo/debugify.ll index 269a301ce830c..191015f825933 100644 --- a/llvm/test/DebugInfo/debugify.ll +++ b/llvm/test/DebugInfo/debugify.ll @@ -1,9 +1,6 @@ ; RUN: opt -passes=debugify -S -o - < %s | FileCheck %s ; RUN: opt -passes=debugify -S -o - < %s | FileCheck %s -; RUN: opt -passes=debugify --debugify-atoms -S -o - < %s \ -; RUN: | FileCheck %s -check-prefixes=CHECK-ATOMS - ; RUN: opt -passes=debugify,debugify -S -o - < %s 2>&1 | \ ; RUN: FileCheck %s -check-prefix=CHECK-REPEAT ; RUN: opt -passes=debugify,debugify -S -o - < %s 2>&1 | \ @@ -104,13 +101,6 @@ define i32 @boom() { ; CHECK-DAG: ![[musttail]] = !DILocation(line: 5, column: 1 ; CHECK-DAG: ![[musttailRes]] = !DILocation(line: 6, column: 1 -; CHECK-ATOMS-DAG: !DILocation(line: 1{{.*}}, atomGroup: 1, atomRank: 1 -; CHECK-ATOMS-DAG: !DILocation(line: 2{{.*}}, atomGroup: 2, atomRank: 1 -; CHECK-ATOMS-DAG: !DILocation(line: 3{{.*}}, atomGroup: 3, atomRank: 1 -; CHECK-ATOMS-DAG: !DILocation(line: 4{{.*}}, atomGroup: 4, atomRank: 1 -; CHECK-ATOMS-DAG: !DILocation(line: 5{{.*}}, atomGroup: 5, atomRank: 1 -; CHECK-ATOMS-DAG: !DILocation(line: 6{{.*}}, atomGroup: 6, atomRank: 1 - ; --- DILocalVariables ; CHECK-DAG: ![[TY32:.*]] = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned) ; CHECK-DAG: !DILocalVariable(name: "1", scope: {{.*}}, file: {{.*}}, line: 1, type: ![[TY32]])