[llvm] [DebugInfo] Assign best possible debugloc to bundle (PR #164573)
Santanu Das via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 4 00:19:01 PST 2025
https://github.com/quic-santdas updated https://github.com/llvm/llvm-project/pull/164573
>From 796ca060a6760649bcd9d4357e61c1cecfa1de8b Mon Sep 17 00:00:00 2001
From: quic-santdas <quic_santdas at quicinc.com>
Date: Wed, 22 Oct 2025 00:53:48 -0700
Subject: [PATCH 1/6] [DebugInfo] Assign best possible debugloc to bundle
The debug info attached to the BUNDLE is the first instruction
in the BUNDLE, even if a better debug info (line:column) is present
in the later instructions of the bundle. The patch tries to get a
better debug info first. If not, then a worse debug info without
line number is chosen.
---
llvm/lib/CodeGen/MachineInstrBundle.cpp | 15 +++-
llvm/test/DebugInfo/Hexagon/packet-debug.ll | 96 +++++++++++++++++++++
2 files changed, 107 insertions(+), 4 deletions(-)
create mode 100644 llvm/test/DebugInfo/Hexagon/packet-debug.ll
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index da29ffc9d2fed..a749b13846e0c 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -88,10 +88,17 @@ llvm::createUnpackMachineBundles(
/// DILocation is found, then an empty location is returned.
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI,
MachineBasicBlock::instr_iterator LastMI) {
- for (auto MII = FirstMI; MII != LastMI; ++MII)
- if (MII->getDebugLoc())
- return MII->getDebugLoc();
- return DebugLoc();
+ DebugLoc DL;
+ for (auto MII = FirstMI; MII != LastMI; ++MII) {
+ DebugLoc MIIDL = MII->getDebugLoc();
+ if (MIIDL) {
+ if (MIIDL.getLine() == 0)
+ DL = MIIDL.get();
+ else
+ return MII->getDebugLoc();
+ }
+ }
+ return DL;
}
/// Check if target reg is contained in given lists, which are:
diff --git a/llvm/test/DebugInfo/Hexagon/packet-debug.ll b/llvm/test/DebugInfo/Hexagon/packet-debug.ll
new file mode 100644
index 0000000000000..ad1b04bbf400f
--- /dev/null
+++ b/llvm/test/DebugInfo/Hexagon/packet-debug.ll
@@ -0,0 +1,96 @@
+; Passes if line number 9 is generated in the line table
+
+; REQUIRES: hexagon-registered-target
+
+; RUN: llc %s -march=hexagon -filetype=obj -mcpu=hexagonv69 -o - | llvm-dwarfdump --debug-line - | FileCheck %s
+
+; CHECK: 9 9 1 0 0 0 is_stmt prologue_end
+
+ at glob = common dso_local local_unnamed_addr global i32 0, align 4, !dbg !0
+ at .str = private unnamed_addr constant [23 x i8] c"Factorial of %d is %d\0A\00", align 1, !dbg !5
+define dso_local i32 @factorial(i32 %i) local_unnamed_addr !dbg !18 {
+entry:
+ #dbg_value(i32 %i, !22, !DIExpression(), !24)
+ %cmp = icmp eq i32 %i, 1, !dbg !25
+ br i1 %cmp, label %common.ret, label %if.end, !dbg !25
+common.ret: ; preds = %entry, %if.end
+ %common.ret.op = phi i32 [ %mul, %if.end ], [ 1, %entry ]
+ ret i32 %common.ret.op, !dbg !27
+if.end: ; preds = %entry
+ %sub = add nsw i32 %i, -1, !dbg !28
+ %call = tail call i32 @factorial(i32 noundef %sub), !dbg !29
+ %mul = mul nsw i32 %call, %i, !dbg !30
+ #dbg_value(i32 %mul, !23, !DIExpression(), !24)
+ store i32 %mul, ptr @glob, align 4, !dbg !31, !tbaa !32
+ br label %common.ret, !dbg !27
+}
+define dso_local noundef i32 @main(i32 noundef %argc, ptr noundef readnone captures(none) %argv) local_unnamed_addr !dbg !36 {
+entry:
+ #dbg_value(i32 %argc, !42, !DIExpression(), !46)
+ #dbg_value(ptr %argv, !43, !DIExpression(), !46)
+ #dbg_value(i32 10, !44, !DIExpression(), !46)
+ %call = tail call i32 @factorial(i32 noundef 10), !dbg !47
+ %call1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 10, i32 noundef %call), !dbg !48
+ ret i32 0, !dbg !50
+}
+declare !dbg !51 dso_local noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!12, !13, !14, !15, !16}
+!llvm.ident = !{!17}
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "glob", scope: !2, file: !3, line: 4, type: !11, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "QuIC LLVM Hexagon Clang version 21.0 Engineering Release: hexagon-clang-210", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
+!3 = !DIFile(filename: "fact.c", directory: ".")
+!4 = !{!5, !0}
+!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
+!6 = distinct !DIGlobalVariable(scope: null, file: !3, line: 38, type: !7, isLocal: true, isDefinition: true)
+!7 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 184, elements: !9)
+!8 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)
+!9 = !{!10}
+!10 = !DISubrange(count: 23)
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !{i32 7, !"Dwarf Version", i32 4}
+!13 = !{i32 2, !"Debug Info Version", i32 3}
+!14 = !{i32 1, !"wchar_size", i32 4}
+!15 = !{i32 7, !"frame-pointer", i32 2}
+!16 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
+!17 = !{!"QuIC LLVM Hexagon Clang version 21.0 Engineering Release: hexagon-clang-210"}
+!18 = distinct !DISubprogram(name: "factorial", scope: !3, file: !3, line: 6, type: !19, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !21)
+!19 = !DISubroutineType(types: !20)
+!20 = !{!11, !11}
+!21 = !{!22, !23}
+!22 = !DILocalVariable(name: "i", arg: 1, scope: !18, file: !3, line: 6, type: !11)
+!23 = !DILocalVariable(name: "j", scope: !18, file: !3, line: 8, type: !11)
+!24 = !DILocation(line: 0, scope: !18)
+!25 = !DILocation(line: 9, column: 9, scope: !26)
+!26 = distinct !DILexicalBlock(scope: !18, file: !3, line: 9, column: 7)
+!27 = !DILocation(line: 14, column: 1, scope: !18)
+!28 = !DILocation(line: 11, column: 23, scope: !18)
+!29 = !DILocation(line: 11, column: 11, scope: !18)
+!30 = !DILocation(line: 11, column: 9, scope: !18)
+!31 = !DILocation(line: 12, column: 8, scope: !18)
+!32 = !{!33, !33, i64 0}
+!33 = !{!"int", !34, i64 0}
+!34 = !{!"omnipotent char", !35, i64 0}
+!35 = !{!"Simple C/C++ TBAA"}
+!36 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 16, type: !37, scopeLine: 17, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !41)
+!37 = !DISubroutineType(types: !38)
+!38 = !{!11, !11, !39}
+!39 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !40, size: 32)
+!40 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 32)
+!41 = !{!42, !43, !44}
+!42 = !DILocalVariable(name: "argc", arg: 1, scope: !36, file: !3, line: 16, type: !11)
+!43 = !DILocalVariable(name: "argv", arg: 2, scope: !36, file: !3, line: 16, type: !39)
+!44 = !DILocalVariable(name: "base", scope: !36, file: !3, line: 18, type: !45)
+!45 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+!46 = !DILocation(line: 0, scope: !36)
+!47 = !DILocation(line: 38, column: 43, scope: !36)
+!48 = !DILocation(line: 38, column: 3, scope: !49)
+!49 = !DILexicalBlockFile(scope: !36, file: !3, discriminator: 2)
+!50 = !DILocation(line: 39, column: 3, scope: !36)
+!51 = !DISubprogram(name: "printf", scope: !52, file: !52, line: 160, type: !53, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
+!52 = !DIFile(filename: "stdio.h", directory: ".")
+!53 = !DISubroutineType(types: !54)
+!54 = !{!11, !55, null}
+!55 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !56, size: 32)
+!56 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8)
>From acc3986edd4f7e1622c113955498d2a32af404cc Mon Sep 17 00:00:00 2001
From: Santanu Das <quic_santdas at quicinc.com>
Date: Mon, 27 Oct 2025 20:58:37 +0530
Subject: [PATCH 2/6] Update llvm/lib/CodeGen/MachineInstrBundle.cpp
Co-authored-by: Vladislav Dzhidzhoev <dzhidzhoev at gmail.com>
---
llvm/lib/CodeGen/MachineInstrBundle.cpp | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index a749b13846e0c..43110a33c1b80 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -92,10 +92,9 @@ static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI,
for (auto MII = FirstMI; MII != LastMI; ++MII) {
DebugLoc MIIDL = MII->getDebugLoc();
if (MIIDL) {
- if (MIIDL.getLine() == 0)
- DL = MIIDL.get();
- else
- return MII->getDebugLoc();
+ if (MIIDL.getLine() != 0)
+ return MIIDL;
+ DL = MIIDL.get();
}
}
return DL;
>From 7fdfa030fdae6cc21fb3ce9912c8525513535814 Mon Sep 17 00:00:00 2001
From: quic-santdas <quic_santdas at quicinc.com>
Date: Mon, 27 Oct 2025 08:52:17 -0700
Subject: [PATCH 3/6] [DebugInfo] Added lit config for Hexagon
---
llvm/lib/CodeGen/MachineInstrBundle.cpp | 2 +-
llvm/test/DebugInfo/Hexagon/lit.local.cfg | 2 ++
llvm/test/DebugInfo/Hexagon/packet-debug.ll | 4 +---
3 files changed, 4 insertions(+), 4 deletions(-)
create mode 100644 llvm/test/DebugInfo/Hexagon/lit.local.cfg
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index 43110a33c1b80..560a58810d24a 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -94,7 +94,7 @@ static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI,
if (MIIDL) {
if (MIIDL.getLine() != 0)
return MIIDL;
- DL = MIIDL.get();
+ DL = MIIDL.get();
}
}
return DL;
diff --git a/llvm/test/DebugInfo/Hexagon/lit.local.cfg b/llvm/test/DebugInfo/Hexagon/lit.local.cfg
new file mode 100644
index 0000000000000..3bed54b1a88d2
--- /dev/null
+++ b/llvm/test/DebugInfo/Hexagon/lit.local.cfg
@@ -0,0 +1,2 @@
+if not "Hexagon" in config.root.targets:
+ config.unsupported = True
diff --git a/llvm/test/DebugInfo/Hexagon/packet-debug.ll b/llvm/test/DebugInfo/Hexagon/packet-debug.ll
index ad1b04bbf400f..606e0725a3be2 100644
--- a/llvm/test/DebugInfo/Hexagon/packet-debug.ll
+++ b/llvm/test/DebugInfo/Hexagon/packet-debug.ll
@@ -1,8 +1,6 @@
; Passes if line number 9 is generated in the line table
-; REQUIRES: hexagon-registered-target
-
-; RUN: llc %s -march=hexagon -filetype=obj -mcpu=hexagonv69 -o - | llvm-dwarfdump --debug-line - | FileCheck %s
+; RUN: llc %s -mtriple=hexagon-unknown-elf -filetype=obj -mcpu=hexagonv69 -o - | llvm-dwarfdump --debug-line - | FileCheck %s
; CHECK: 9 9 1 0 0 0 is_stmt prologue_end
>From 2161ba6c77a622e3dc8b35eef47d44e4ed48ee7e Mon Sep 17 00:00:00 2001
From: Santanu Das <quic_santdas at quicinc.com>
Date: Fri, 31 Oct 2025 11:15:24 +0530
Subject: [PATCH 4/6] Update llvm/lib/CodeGen/MachineInstrBundle.cpp
Co-authored-by: Orlando Cazalet-Hyams <orlandoch.och at gmail.com>
---
llvm/lib/CodeGen/MachineInstrBundle.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index 560a58810d24a..73c2259fca421 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -90,8 +90,7 @@ static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI,
MachineBasicBlock::instr_iterator LastMI) {
DebugLoc DL;
for (auto MII = FirstMI; MII != LastMI; ++MII) {
- DebugLoc MIIDL = MII->getDebugLoc();
- if (MIIDL) {
+ if (DebugLoc MIIDL = MII->getDebugLoc()) {
if (MIIDL.getLine() != 0)
return MIIDL;
DL = MIIDL.get();
>From 0557d56e30bc04be667eed5c9a3bae69efb30dbd Mon Sep 17 00:00:00 2001
From: quic-santdas <quic_santdas at quicinc.com>
Date: Mon, 3 Nov 2025 22:17:11 -0800
Subject: [PATCH 5/6] Updated testcase and comment
---
llvm/lib/CodeGen/MachineInstrBundle.cpp | 6 +-
llvm/test/DebugInfo/Hexagon/packet-debug.ll | 94 --------------------
llvm/test/DebugInfo/Hexagon/packet-debug.mir | 48 ++++++++++
3 files changed, 51 insertions(+), 97 deletions(-)
delete mode 100644 llvm/test/DebugInfo/Hexagon/packet-debug.ll
create mode 100644 llvm/test/DebugInfo/Hexagon/packet-debug.mir
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index 73c2259fca421..fd03d2febf5cf 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -83,9 +83,9 @@ llvm::createUnpackMachineBundles(
return new UnpackMachineBundles(std::move(Ftor));
}
-/// Return the first found DebugLoc that has a DILocation, given a range of
-/// instructions. The search range is from FirstMI to LastMI (exclusive). If no
-/// DILocation is found, then an empty location is returned.
+/// Return the first good DebugLoc that has line number information, given a
+/// range of instructions. The search range is from FirstMI to LastMI (exclusive).
+/// If no such DebugLoc is found, get the one with DILocation
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI,
MachineBasicBlock::instr_iterator LastMI) {
DebugLoc DL;
diff --git a/llvm/test/DebugInfo/Hexagon/packet-debug.ll b/llvm/test/DebugInfo/Hexagon/packet-debug.ll
deleted file mode 100644
index 606e0725a3be2..0000000000000
--- a/llvm/test/DebugInfo/Hexagon/packet-debug.ll
+++ /dev/null
@@ -1,94 +0,0 @@
-; Passes if line number 9 is generated in the line table
-
-; RUN: llc %s -mtriple=hexagon-unknown-elf -filetype=obj -mcpu=hexagonv69 -o - | llvm-dwarfdump --debug-line - | FileCheck %s
-
-; CHECK: 9 9 1 0 0 0 is_stmt prologue_end
-
- at glob = common dso_local local_unnamed_addr global i32 0, align 4, !dbg !0
- at .str = private unnamed_addr constant [23 x i8] c"Factorial of %d is %d\0A\00", align 1, !dbg !5
-define dso_local i32 @factorial(i32 %i) local_unnamed_addr !dbg !18 {
-entry:
- #dbg_value(i32 %i, !22, !DIExpression(), !24)
- %cmp = icmp eq i32 %i, 1, !dbg !25
- br i1 %cmp, label %common.ret, label %if.end, !dbg !25
-common.ret: ; preds = %entry, %if.end
- %common.ret.op = phi i32 [ %mul, %if.end ], [ 1, %entry ]
- ret i32 %common.ret.op, !dbg !27
-if.end: ; preds = %entry
- %sub = add nsw i32 %i, -1, !dbg !28
- %call = tail call i32 @factorial(i32 noundef %sub), !dbg !29
- %mul = mul nsw i32 %call, %i, !dbg !30
- #dbg_value(i32 %mul, !23, !DIExpression(), !24)
- store i32 %mul, ptr @glob, align 4, !dbg !31, !tbaa !32
- br label %common.ret, !dbg !27
-}
-define dso_local noundef i32 @main(i32 noundef %argc, ptr noundef readnone captures(none) %argv) local_unnamed_addr !dbg !36 {
-entry:
- #dbg_value(i32 %argc, !42, !DIExpression(), !46)
- #dbg_value(ptr %argv, !43, !DIExpression(), !46)
- #dbg_value(i32 10, !44, !DIExpression(), !46)
- %call = tail call i32 @factorial(i32 noundef 10), !dbg !47
- %call1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 10, i32 noundef %call), !dbg !48
- ret i32 0, !dbg !50
-}
-declare !dbg !51 dso_local noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1
-!llvm.dbg.cu = !{!2}
-!llvm.module.flags = !{!12, !13, !14, !15, !16}
-!llvm.ident = !{!17}
-!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
-!1 = distinct !DIGlobalVariable(name: "glob", scope: !2, file: !3, line: 4, type: !11, isLocal: false, isDefinition: true)
-!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "QuIC LLVM Hexagon Clang version 21.0 Engineering Release: hexagon-clang-210", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
-!3 = !DIFile(filename: "fact.c", directory: ".")
-!4 = !{!5, !0}
-!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
-!6 = distinct !DIGlobalVariable(scope: null, file: !3, line: 38, type: !7, isLocal: true, isDefinition: true)
-!7 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 184, elements: !9)
-!8 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)
-!9 = !{!10}
-!10 = !DISubrange(count: 23)
-!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!12 = !{i32 7, !"Dwarf Version", i32 4}
-!13 = !{i32 2, !"Debug Info Version", i32 3}
-!14 = !{i32 1, !"wchar_size", i32 4}
-!15 = !{i32 7, !"frame-pointer", i32 2}
-!16 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
-!17 = !{!"QuIC LLVM Hexagon Clang version 21.0 Engineering Release: hexagon-clang-210"}
-!18 = distinct !DISubprogram(name: "factorial", scope: !3, file: !3, line: 6, type: !19, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !21)
-!19 = !DISubroutineType(types: !20)
-!20 = !{!11, !11}
-!21 = !{!22, !23}
-!22 = !DILocalVariable(name: "i", arg: 1, scope: !18, file: !3, line: 6, type: !11)
-!23 = !DILocalVariable(name: "j", scope: !18, file: !3, line: 8, type: !11)
-!24 = !DILocation(line: 0, scope: !18)
-!25 = !DILocation(line: 9, column: 9, scope: !26)
-!26 = distinct !DILexicalBlock(scope: !18, file: !3, line: 9, column: 7)
-!27 = !DILocation(line: 14, column: 1, scope: !18)
-!28 = !DILocation(line: 11, column: 23, scope: !18)
-!29 = !DILocation(line: 11, column: 11, scope: !18)
-!30 = !DILocation(line: 11, column: 9, scope: !18)
-!31 = !DILocation(line: 12, column: 8, scope: !18)
-!32 = !{!33, !33, i64 0}
-!33 = !{!"int", !34, i64 0}
-!34 = !{!"omnipotent char", !35, i64 0}
-!35 = !{!"Simple C/C++ TBAA"}
-!36 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 16, type: !37, scopeLine: 17, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !41)
-!37 = !DISubroutineType(types: !38)
-!38 = !{!11, !11, !39}
-!39 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !40, size: 32)
-!40 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 32)
-!41 = !{!42, !43, !44}
-!42 = !DILocalVariable(name: "argc", arg: 1, scope: !36, file: !3, line: 16, type: !11)
-!43 = !DILocalVariable(name: "argv", arg: 2, scope: !36, file: !3, line: 16, type: !39)
-!44 = !DILocalVariable(name: "base", scope: !36, file: !3, line: 18, type: !45)
-!45 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
-!46 = !DILocation(line: 0, scope: !36)
-!47 = !DILocation(line: 38, column: 43, scope: !36)
-!48 = !DILocation(line: 38, column: 3, scope: !49)
-!49 = !DILexicalBlockFile(scope: !36, file: !3, discriminator: 2)
-!50 = !DILocation(line: 39, column: 3, scope: !36)
-!51 = !DISubprogram(name: "printf", scope: !52, file: !52, line: 160, type: !53, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
-!52 = !DIFile(filename: "stdio.h", directory: ".")
-!53 = !DISubroutineType(types: !54)
-!54 = !{!11, !55, null}
-!55 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !56, size: 32)
-!56 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8)
diff --git a/llvm/test/DebugInfo/Hexagon/packet-debug.mir b/llvm/test/DebugInfo/Hexagon/packet-debug.mir
new file mode 100644
index 0000000000000..485b543b6e176
--- /dev/null
+++ b/llvm/test/DebugInfo/Hexagon/packet-debug.mir
@@ -0,0 +1,48 @@
+# RUN: llc -mtriple=hexagon -run-pass hexagon-packetizer %s -o - | FileCheck %s
+
+# CHECK-LABEL: name: factorial
+
+# The first bundle in bb.0 should have debug-location !19 (line 9),
+# not !18 (line 0) from the DBG_VALUE instructions.
+# CHECK: bb.0:
+# CHECK: BUNDLE {{.*}}line: 9
+
+--- |
+ define void @factorial() { ret void }
+
+ !llvm.dbg.cu = !{!2}
+ !llvm.module.flags = !{!6, !7}
+
+ !2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "test", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+ !3 = !DIFile(filename: "fact.c", directory: "/test")
+ !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+ !6 = !{i32 2, !"Debug Info Version", i32 3}
+ !7 = !{i32 1, !"wchar_size", i32 4}
+ !12 = distinct !DISubprogram(name: "factorial", scope: !3, file: !3, line: 6, type: !13, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)
+ !13 = !DISubroutineType(types: !14)
+ !14 = !{!5, !5}
+ !16 = !DILocalVariable(name: "i", arg: 1, scope: !12, file: !3, line: 6, type: !5)
+ !18 = !DILocation(line: 0, scope: !12)
+ !19 = !DILocation(line: 9, column: 9, scope: !12)
+ !21 = !DILocation(line: 9, column: 7, scope: !12)
+
+...
+---
+name: factorial
+alignment: 16
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $r0
+
+ DBG_VALUE $r0, $noreg, !16, !DIExpression(), debug-location !18
+ $r2 = A2_tfr $r0
+ DBG_VALUE $r2, $noreg, !16, !DIExpression(), debug-location !18
+ renamable $p0 = C2_cmpeqi killed $r0, 1, debug-location !19
+ renamable $r0 = A2_tfrsi 1
+ J2_jumpt killed $p0, %bb.1, implicit-def $pc, debug-location !21
+
+ bb.1:
+ PS_jmpret $r31, implicit-def dead $pc
+
+...
>From fd55d000ca7329eb6db83e5c6ddc6fbf24ea78ef Mon Sep 17 00:00:00 2001
From: quic-santdas <quic_santdas at quicinc.com>
Date: Tue, 4 Nov 2025 00:18:30 -0800
Subject: [PATCH 6/6] clang format patch
---
llvm/lib/CodeGen/MachineInstrBundle.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index fd03d2febf5cf..2ad5f0fc04860 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -84,8 +84,8 @@ llvm::createUnpackMachineBundles(
}
/// Return the first good DebugLoc that has line number information, given a
-/// range of instructions. The search range is from FirstMI to LastMI (exclusive).
-/// If no such DebugLoc is found, get the one with DILocation
+/// range of instructions. The search range is from FirstMI to LastMI
+/// (exclusive). If no such DebugLoc is found, get the one with DILocation
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI,
MachineBasicBlock::instr_iterator LastMI) {
DebugLoc DL;
More information about the llvm-commits
mailing list