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

Unfortunately there's no upstream frontend for Metal but since the id's
are now assigned by the DWARF standard I think it makes sense to have
the enums upstream to enable tools like llvm-dwarfdump. This patch
therefore uses an AArch64 test with artificially modified debug info to
verify that the Metal language id can be used.

https://dwarfstd.org/issues/241111.1.html
This commit is contained in:
Daniel Sanders 2024-11-22 13:49:42 -08:00 committed by GitHub
parent 182f9aad8b
commit 5d9aabbab3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 49 additions and 1 deletions

View File

@ -138,6 +138,7 @@ typedef enum {
LLVMDWARFSourceLanguageRuby,
LLVMDWARFSourceLanguageMove,
LLVMDWARFSourceLanguageHylo,
LLVMDWARFSourceLanguageMetal,
// Vendor extensions:
LLVMDWARFSourceLanguageMips_Assembler,

View File

@ -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)
@ -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)

View File

@ -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 {};
}
@ -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:
@ -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;
}
@ -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;
}
@ -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.");

View File

@ -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");

View File

@ -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)