Skip to content

[MC] output inlined-at debug info #106230

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 1 commit into from
Mar 7, 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
4 changes: 2 additions & 2 deletions llvm/include/llvm/MC/MCObjectStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class MCObjectStreamer : public MCStreamer {
SMLoc Loc) override;
void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column,
unsigned Flags, unsigned Isa,
unsigned Discriminator,
StringRef FileName) override;
unsigned Discriminator, StringRef FileName,
StringRef Comment = {}) override;
void emitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel,
const MCSymbol *Label,
unsigned PointerSize) override;
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,8 @@ class MCStreamer {
virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa, unsigned Discriminator,
StringRef FileName);
StringRef FileName,
StringRef Comment = {});

/// This implements the '.loc_label Name' directive.
virtual void emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name);
Expand Down
23 changes: 15 additions & 8 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,14 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
}
}

auto RecordSourceLine = [&](auto &DL, auto Flags) {
SmallString<128> LocationString;
raw_svector_ostream OS(LocationString);
DL.print(OS);

const MDNode *Scope = DL.getScope();
recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags, LocationString);
};
// When we emit a line-0 record, we don't update PrevInstLoc; so look at
// the last line number actually emitted, to see if it was line 0.
unsigned LastAsmLine =
Expand Down Expand Up @@ -2084,8 +2092,7 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
// But we might be coming back to it after a line 0 record.
if ((LastAsmLine == 0 && DL.getLine() != 0) || Flags) {
// Reinstate the source location but not marked as a statement.
const MDNode *Scope = DL.getScope();
recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
RecordSourceLine(DL, Flags);
}
return;
}
Expand Down Expand Up @@ -2136,8 +2143,7 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
if (DL.getLine() && (DL.getLine() != OldLine || ForceIsStmt))
Flags |= DWARF2_FLAG_IS_STMT;

const MDNode *Scope = DL.getScope();
recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
RecordSourceLine(DL, Flags);

// If we're not at line 0, remember this location.
if (DL.getLine())
Expand Down Expand Up @@ -2272,7 +2278,8 @@ findPrologueEndLoc(const MachineFunction *MF) {
static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
const MDNode *S, unsigned Flags, unsigned CUID,
uint16_t DwarfVersion,
ArrayRef<std::unique_ptr<DwarfCompileUnit>> DCUs) {
ArrayRef<std::unique_ptr<DwarfCompileUnit>> DCUs,
StringRef Comment = {}) {
StringRef Fn;
unsigned FileNo = 1;
unsigned Discriminator = 0;
Expand All @@ -2286,7 +2293,7 @@ static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
.getOrCreateSourceID(Scope->getFile());
}
Asm.OutStreamer->emitDwarfLocDirective(FileNo, Line, Col, Flags, 0,
Discriminator, Fn);
Discriminator, Fn, Comment);
}

const MachineInstr *
Expand Down Expand Up @@ -2617,10 +2624,10 @@ void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {
// Register a source line with debug info. Returns the unique label that was
// emitted and which provides correspondence to the source line list.
void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
unsigned Flags) {
unsigned Flags, StringRef Location) {
::recordSourceLine(*Asm, Line, Col, S, Flags,
Asm->OutStreamer->getContext().getDwarfCompileUnitID(),
getDwarfVersion(), getUnits());
getDwarfVersion(), getUnits(), Location);
}

//===----------------------------------------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ class DwarfDebug : public DebugHandlerBase {
/// label that was emitted and which provides correspondence to the
/// source line list.
void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
unsigned Flags);
unsigned Flags, StringRef Location = {});

/// Populate LexicalScope entries with variables' info.
void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
Expand Down
18 changes: 11 additions & 7 deletions llvm/lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ class MCAsmStreamer final : public MCStreamer {
unsigned CUID = 0) override;
void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column,
unsigned Flags, unsigned Isa,
unsigned Discriminator,
StringRef FileName) override;
unsigned Discriminator, StringRef FileName,
StringRef Location = {}) override;
virtual void emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name) override;

MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override;
Expand Down Expand Up @@ -1739,15 +1739,16 @@ void MCAsmStreamer::emitDwarfFile0Directive(
void MCAsmStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa, unsigned Discriminator,
StringRef FileName) {
StringRef FileName,
StringRef Comment) {
// If target doesn't support .loc/.file directive, we need to record the lines
// same way like we do in object mode.
if (MAI->isAIX()) {
// In case we see two .loc directives in a row, make sure the
// first one gets a line entry.
MCDwarfLineEntry::make(this, getCurrentSectionOnly());
this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa,
Discriminator, FileName);
Discriminator, FileName, Comment);
return;
}

Expand Down Expand Up @@ -1778,12 +1779,15 @@ void MCAsmStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,

if (IsVerboseAsm) {
OS.PadToColumn(MAI->getCommentColumn());
OS << MAI->getCommentString() << ' ' << FileName << ':'
<< Line << ':' << Column;
OS << MAI->getCommentString() << ' ';
if (Comment.empty())
OS << FileName << ':' << Line << ':' << Column;
else
OS << Comment;
}
EmitEOL();
this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa,
Discriminator, FileName);
Discriminator, FileName, Comment);
}

void MCAsmStreamer::emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name) {
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/MC/MCObjectStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,14 @@ void MCObjectStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa,
unsigned Discriminator,
StringRef FileName) {
StringRef FileName,
StringRef Comment) {
// In case we see two .loc directives in a row, make sure the
// first one gets a line entry.
MCDwarfLineEntry::make(this, getCurrentSectionOnly());

this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa,
Discriminator, FileName);
Discriminator, FileName, Comment);
}

static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void MCStreamer::emitCFIMTETaggedFrame() {
void MCStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa, unsigned Discriminator,
StringRef FileName) {
StringRef FileName, StringRef Comment) {
getContext().setCurrentDwarfLoc(FileNo, Line, Column, Flags, Isa,
Discriminator);
}
Expand Down
66 changes: 66 additions & 0 deletions llvm/test/CodeGen/AMDGPU/dbg-info-inline-at.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 < %s | FileCheck %s

define amdgpu_kernel void @_Z3fooPiiii(ptr addrspace(1) nocapture noundef writeonly %c.coerce, i32 noundef %a, i32 noundef %b, i32 noundef %d) !dbg !9 {
; CHECK-LABEL: _Z3fooPiiii:
; CHECK: .Lfunc_begin0:
; CHECK-NEXT: .file 0 "test" "a.hip" md5 0x004a28df8cfd98cdd2c71d5d814d9c6b
; CHECK-NEXT: .cfi_sections .debug_frame
; CHECK-NEXT: .cfi_startproc
; CHECK-NEXT: ; %bb.0: ; %entry
; CHECK-NEXT: .file 1 "." "a.h"
; CHECK-NEXT: .loc 1 5 12 prologue_end ; ./a.h:5:12 @[ a.hip:12:8 ]
; CHECK-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x8
; CHECK-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
; CHECK-NEXT: v_mov_b32_e32 v0, 0
; CHECK-NEXT: s_waitcnt lgkmcnt(0)
; CHECK-NEXT: s_add_i32 s1, s1, s0
; CHECK-NEXT: .Ltmp0:
; CHECK-NEXT: .loc 1 5 12 is_stmt 0 ; ./a.h:5:12 @[ a.hip:13:9 ]
; CHECK-NEXT: s_add_i32 s0, s2, s0
; CHECK-NEXT: .Ltmp1:
; CHECK-NEXT: .file 2 "a.hip"
; CHECK-NEXT: .loc 2 13 6 is_stmt 1 ; a.hip:13:6
; CHECK-NEXT: s_mul_i32 s0, s0, s1
; CHECK-NEXT: v_mov_b32_e32 v1, s0
; CHECK-NEXT: global_store_dword v0, v1, s[4:5]
; CHECK-NEXT: .loc 2 14 1 ; a.hip:14:1
; CHECK-NEXT: s_endpgm
; CHECK-NEXT: .Ltmp2:
entry:
%add.i = add nsw i32 %b, %a, !dbg !13
%add.i3 = add nsw i32 %d, %a, !dbg !17
%mul = mul nsw i32 %add.i3, %add.i, !dbg !19
store i32 %mul, ptr addrspace(1) %c.coerce, align 4, !dbg !19, !tbaa !20
ret void, !dbg !24
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
!llvm.ident = !{!8}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "a.hip", directory: "test", checksumkind: CSK_MD5, checksum: "004a28df8cfd98cdd2c71d5d814d9c6b")
!2 = !{i32 1, !"amdhsa_code_object_version", i32 500}
!3 = !{i32 1, !"amdgpu_printf_kind", !"hostcall"}
!4 = !{i32 7, !"Dwarf Version", i32 5}
!5 = !{i32 2, !"Debug Info Version", i32 3}
!6 = !{i32 1, !"wchar_size", i32 4}
!7 = !{i32 8, !"PIC Level", i32 2}
!8 = !{!"clang version 20.0.0"}
!9 = distinct !DISubprogram(name: "foo", scope: !10, file: !10, line: 11, type: !11, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
!10 = !DIFile(filename: "a.hip", directory: "test")
!11 = !DISubroutineType(types: !12)
!12 = !{}
!13 = !DILocation(line: 5, column: 12, scope: !14, inlinedAt: !16)
!14 = distinct !DISubprogram(name: "bar", scope: !15, file: !15, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
!15 = !DIFile(filename: "./a.h", directory: "test")
!16 = distinct !DILocation(line: 12, column: 8, scope: !9)
!17 = !DILocation(line: 5, column: 12, scope: !14, inlinedAt: !18)
!18 = distinct !DILocation(line: 13, column: 9, scope: !9)
!19 = !DILocation(line: 13, column: 6, scope: !9)
!20 = !{!21, !21, i64 0}
!21 = !{!"int", !22, i64 0}
!22 = !{!"omnipotent char", !23, i64 0}
!23 = !{!"Simple C++ TBAA"}
!24 = !DILocation(line: 14, column: 1, scope: !9)
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/XCore/dwarf_debug.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
; CHECK-LABEL: f
; CHECK: entsp [[S:[0-9]+]]
; ...the prologue...
; CHECK: .loc 1 2 0 prologue_end # test.c:2:0
; CHECK: .loc 1 2 0 prologue_end # test.c:2
; CHECK: add r0, r0, 1
; CHECK: retsp [[S]]
define i32 @f(i32 %a) !dbg !4 {
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/DebugInfo/X86/inline-seldag-test.ll
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
; Make sure the condition test is attributed to the inline function, not the
; location of the test's operands within the caller.

; ASM: # inline-seldag-test.c:2:0
; ASM-NOT: .loc
; ASM: # inline-seldag-test.c:4:0
; ASM: .loc 1 2 0 # inline-seldag-test.c:2 @[ inline-seldag-test.c:6:7 ]
; ASM: testl

; Function Attrs: nounwind uwtable
Expand Down