Skip to content

Commit de159ae

Browse files
authored
[NVPTX][DebugInfo] avoid emitting extra .loc directives (#84584)
This change removes an extra, unneeded debug directive emitted in the PTX at the beginning on non-empty functions: ```nvptx .visible .func (.param .b32 func_retval0) foo( .param .b32 foo_param_0, .param .b32 foo_param_1 ) { .reg .b32 %r<4>; .loc 1 26 0 <---- unneeded (removed by the PR) $L__func_begin0: .loc 1 26 0 ```
1 parent 09db84c commit de159ae

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,11 @@ void NVPTXAsmPrinter::emitFunctionEntryLabel() {
489489
OutStreamer->emitRawText(StringRef("{\n"));
490490
setAndEmitFunctionVirtualRegisters(*MF);
491491
// Emit initial .loc debug directive for correct relocation symbol data.
492-
if (MMI && MMI->hasDebugInfo())
493-
emitInitialRawDwarfLocDirective(*MF);
492+
if (const DISubprogram *SP = MF->getFunction().getSubprogram()) {
493+
assert(SP->getUnit());
494+
if (!SP->getUnit()->isDebugDirectivesOnly() && MMI && MMI->hasDebugInfo())
495+
emitInitialRawDwarfLocDirective(*MF);
496+
}
494497
}
495498

496499
bool NVPTXAsmPrinter::runOnMachineFunction(MachineFunction &F) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda | FileCheck %s
2+
; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64-nvidia-cuda | %ptxas-verify %}
3+
4+
5+
define i32 @foo(i32 %a, i32 %b) !dbg !3 {
6+
7+
; CHECK: .loc [[FILE:[0-9]+]] 26 0 // extra-lineinfo.cu:26:0
8+
; CHECK-NOT: .loc [[FILE]] 26 0 // extra-lineinfo.cu:26:0
9+
; CHECK: .file [[FILE]] "/test/directory/extra-lineinfo.cu"
10+
11+
%add = add i32 %b, %a, !dbg !6
12+
ret i32 %add, !dbg !6
13+
}
14+
15+
!llvm.dbg.cu = !{!0}
16+
!nvvm.annotations = !{}
17+
!llvm.module.flags = !{!2}
18+
19+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: DebugDirectivesOnly)
20+
!1 = !DIFile(filename: "extra-lineinfo.cu", directory: "/test/directory/")
21+
!2 = !{i32 1, !"Debug Info Version", i32 3}
22+
!3 = distinct !DISubprogram(name: "kernel", linkageName: "foo", scope: !1, file: !1, line: 123, type: !4, scopeLine: 26, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
23+
!4 = !DISubroutineType(types: !5)
24+
!5 = !{}
25+
!6 = !DILocation(line: 40, column: 22, scope: !31)
26+
!31 = distinct !DILexicalBlock(scope: !3, file: !1, line: 3, column: 17)

0 commit comments

Comments
 (0)