Skip to content

[dwarf] Add language id for Metal Shading Language #117215

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 4 commits into from
Nov 22, 2024
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
1 change: 1 addition & 0 deletions llvm/include/llvm-c/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ typedef enum {
LLVMDWARFSourceLanguageRuby,
LLVMDWARFSourceLanguageMove,
LLVMDWARFSourceLanguageHylo,
LLVMDWARFSourceLanguageMetal,

// Vendor extensions:
LLVMDWARFSourceLanguageMips_Assembler,
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/BinaryFormat/Dwarf.def
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ HANDLE_DW_LANG(0x0036, HLSL, 0, 0, DWARF)
HANDLE_DW_LANG(0x0037, OpenCL_CPP, 0, 0, DWARF)
HANDLE_DW_LANG(0x0038, CPP_for_OpenCL, 0, 0, DWARF)
HANDLE_DW_LANG(0x0039, SYCL, 0, 0, DWARF)
HANDLE_DW_LANG(0x003d, Metal, 0, 0, DWARF)
HANDLE_DW_LANG(0x0040, Ruby, 0, 0, DWARF)
HANDLE_DW_LANG(0x0041, Move, 0, 0, DWARF)
HANDLE_DW_LANG(0x0042, Hylo, 0, 0, DWARF)
Expand Down Expand Up @@ -1032,6 +1033,7 @@ HANDLE_DW_LNAME(0x0025, SYCL, "SYCL", 0) // YYYYRR
HANDLE_DW_LNAME(0x0026, Ruby, "Ruby", 0) // VVMMPP
HANDLE_DW_LNAME(0x0027, Move, "Move", 0) // YYYYMM
HANDLE_DW_LNAME(0x0028, Hylo, "Hylo", 0)
HANDLE_DW_LNAME(0x002c, Metal, "Metal", 0) // VVMMPP

// DWARF attribute type encodings.
HANDLE_DW_ATE(0x01, address, 2, DWARF)
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/BinaryFormat/Dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ inline std::optional<SourceLanguage> toDW_LANG(SourceLanguageName name,
return DW_LANG_Move;
case DW_LNAME_Hylo:
return DW_LANG_Hylo;
case DW_LNAME_Metal:
return DW_LANG_Metal;
}
return {};
}
Expand Down Expand Up @@ -479,6 +481,8 @@ toDW_LNAME(SourceLanguage language) {
return {{DW_LNAME_Move, 0}};
case DW_LANG_Hylo:
return {{DW_LNAME_Hylo, 0}};
case DW_LANG_Metal:
return {{DW_LNAME_Metal, 0}};
case DW_LANG_BORLAND_Delphi:
case DW_LANG_CPP_for_OpenCL:
case DW_LANG_lo_user:
Expand Down Expand Up @@ -562,6 +566,7 @@ inline bool isCPlusPlus(SourceLanguage S) {
case DW_LANG_Ruby:
case DW_LANG_Move:
case DW_LANG_Hylo:
case DW_LANG_Metal:
result = false;
break;
}
Expand Down Expand Up @@ -641,6 +646,7 @@ inline bool isFortran(SourceLanguage S) {
case DW_LANG_Ruby:
case DW_LANG_Move:
case DW_LANG_Hylo:
case DW_LANG_Metal:
result = false;
break;
}
Expand Down Expand Up @@ -718,6 +724,7 @@ inline bool isC(SourceLanguage S) {
case DW_LANG_Ruby:
case DW_LANG_Move:
case DW_LANG_Hylo:
case DW_LANG_Metal:
return false;
}
llvm_unreachable("Unknown language kind.");
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/DIBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ DICompileUnit *DIBuilder::createCompileUnit(
DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress,
StringRef SysRoot, StringRef SDK) {

assert(((Lang <= dwarf::DW_LANG_Mojo && Lang >= dwarf::DW_LANG_C89) ||
assert(((Lang <= dwarf::DW_LANG_Metal && Lang >= dwarf::DW_LANG_C89) ||
(Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
"Invalid Language tag");

Expand Down
38 changes: 38 additions & 0 deletions llvm/test/tools/llvm-dwarfdump/AArch64/dwarf-lang-metal.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
; RUN: llc -O0 %s -filetype=obj -o %t.o
; RUN: llvm-dwarfdump -arch arm64 %t.o | FileCheck %s
; AArch64 does not support Metal. However in the absence of a suitable target
; it can still be used to test that DW_LANG_Metal/DW_LNAME_Metal can be
; encoded/decoded correctly.
; CHECK: DW_AT_language (DW_LANG_Metal)
source_filename = "test.cpp"
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "arm64-apple-macosx15.0.0"

; Function Attrs: mustprogress noinline norecurse nounwind optnone ssp uwtable(sync)
define noundef i32 @main() #0 !dbg !11 {
entry:
ret i32 0, !dbg !14
}

attributes #0 = { mustprogress norecurse nounwind }

!llvm.module.flags = !{!3, !4, !5, !6, !7, !8, !9}
!llvm.dbg.cu = !{!0}
!llvm.linker.options = !{}
!llvm.ident = !{!10}

!0 = distinct !DICompileUnit(language: DW_LANG_Metal, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
!1 = !DIFile(filename: "test.cpp", directory: "/tmp")
!2 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!3 = !{i32 2, !"SDK Version", [2 x i32] [i32 15, i32 0]}
!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 = !{i32 7, !"uwtable", i32 1}
!9 = !{i32 7, !"frame-pointer", i32 1}
!10 = !{!"clang"}
!11 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 8, type: !12, scopeLine: 8, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
!12 = !DISubroutineType(types: !13)
!13 = !{!2}
!14 = !DILocation(line: 11, column: 1, scope: !11)
Loading