Skip to content

Commit 5d9aabb

Browse files
authored
[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
1 parent 182f9aa commit 5d9aabb

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

llvm/include/llvm-c/DebugInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ typedef enum {
138138
LLVMDWARFSourceLanguageRuby,
139139
LLVMDWARFSourceLanguageMove,
140140
LLVMDWARFSourceLanguageHylo,
141+
LLVMDWARFSourceLanguageMetal,
141142

142143
// Vendor extensions:
143144
LLVMDWARFSourceLanguageMips_Assembler,

llvm/include/llvm/BinaryFormat/Dwarf.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ HANDLE_DW_LANG(0x0036, HLSL, 0, 0, DWARF)
967967
HANDLE_DW_LANG(0x0037, OpenCL_CPP, 0, 0, DWARF)
968968
HANDLE_DW_LANG(0x0038, CPP_for_OpenCL, 0, 0, DWARF)
969969
HANDLE_DW_LANG(0x0039, SYCL, 0, 0, DWARF)
970+
HANDLE_DW_LANG(0x003d, Metal, 0, 0, DWARF)
970971
HANDLE_DW_LANG(0x0040, Ruby, 0, 0, DWARF)
971972
HANDLE_DW_LANG(0x0041, Move, 0, 0, DWARF)
972973
HANDLE_DW_LANG(0x0042, Hylo, 0, 0, DWARF)
@@ -1032,6 +1033,7 @@ HANDLE_DW_LNAME(0x0025, SYCL, "SYCL", 0) // YYYYRR
10321033
HANDLE_DW_LNAME(0x0026, Ruby, "Ruby", 0) // VVMMPP
10331034
HANDLE_DW_LNAME(0x0027, Move, "Move", 0) // YYYYMM
10341035
HANDLE_DW_LNAME(0x0028, Hylo, "Hylo", 0)
1036+
HANDLE_DW_LNAME(0x002c, Metal, "Metal", 0) // VVMMPP
10351037

10361038
// DWARF attribute type encodings.
10371039
HANDLE_DW_ATE(0x01, address, 2, DWARF)

llvm/include/llvm/BinaryFormat/Dwarf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ inline std::optional<SourceLanguage> toDW_LANG(SourceLanguageName name,
353353
return DW_LANG_Move;
354354
case DW_LNAME_Hylo:
355355
return DW_LANG_Hylo;
356+
case DW_LNAME_Metal:
357+
return DW_LANG_Metal;
356358
}
357359
return {};
358360
}
@@ -479,6 +481,8 @@ toDW_LNAME(SourceLanguage language) {
479481
return {{DW_LNAME_Move, 0}};
480482
case DW_LANG_Hylo:
481483
return {{DW_LNAME_Hylo, 0}};
484+
case DW_LANG_Metal:
485+
return {{DW_LNAME_Metal, 0}};
482486
case DW_LANG_BORLAND_Delphi:
483487
case DW_LANG_CPP_for_OpenCL:
484488
case DW_LANG_lo_user:
@@ -562,6 +566,7 @@ inline bool isCPlusPlus(SourceLanguage S) {
562566
case DW_LANG_Ruby:
563567
case DW_LANG_Move:
564568
case DW_LANG_Hylo:
569+
case DW_LANG_Metal:
565570
result = false;
566571
break;
567572
}
@@ -641,6 +646,7 @@ inline bool isFortran(SourceLanguage S) {
641646
case DW_LANG_Ruby:
642647
case DW_LANG_Move:
643648
case DW_LANG_Hylo:
649+
case DW_LANG_Metal:
644650
result = false;
645651
break;
646652
}
@@ -718,6 +724,7 @@ inline bool isC(SourceLanguage S) {
718724
case DW_LANG_Ruby:
719725
case DW_LANG_Move:
720726
case DW_LANG_Hylo:
727+
case DW_LANG_Metal:
721728
return false;
722729
}
723730
llvm_unreachable("Unknown language kind.");

llvm/lib/IR/DIBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ DICompileUnit *DIBuilder::createCompileUnit(
139139
DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress,
140140
StringRef SysRoot, StringRef SDK) {
141141

142-
assert(((Lang <= dwarf::DW_LANG_Mojo && Lang >= dwarf::DW_LANG_C89) ||
142+
assert(((Lang <= dwarf::DW_LANG_Metal && Lang >= dwarf::DW_LANG_C89) ||
143143
(Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
144144
"Invalid Language tag");
145145

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; RUN: llc -O0 %s -filetype=obj -o %t.o
2+
; RUN: llvm-dwarfdump -arch arm64 %t.o | FileCheck %s
3+
; AArch64 does not support Metal. However in the absence of a suitable target
4+
; it can still be used to test that DW_LANG_Metal/DW_LNAME_Metal can be
5+
; encoded/decoded correctly.
6+
; CHECK: DW_AT_language (DW_LANG_Metal)
7+
source_filename = "test.cpp"
8+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
9+
target triple = "arm64-apple-macosx15.0.0"
10+
11+
; Function Attrs: mustprogress noinline norecurse nounwind optnone ssp uwtable(sync)
12+
define noundef i32 @main() #0 !dbg !11 {
13+
entry:
14+
ret i32 0, !dbg !14
15+
}
16+
17+
attributes #0 = { mustprogress norecurse nounwind }
18+
19+
!llvm.module.flags = !{!3, !4, !5, !6, !7, !8, !9}
20+
!llvm.dbg.cu = !{!0}
21+
!llvm.linker.options = !{}
22+
!llvm.ident = !{!10}
23+
24+
!0 = distinct !DICompileUnit(language: DW_LANG_Metal, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
25+
!1 = !DIFile(filename: "test.cpp", directory: "/tmp")
26+
!2 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
27+
!3 = !{i32 2, !"SDK Version", [2 x i32] [i32 15, i32 0]}
28+
!4 = !{i32 7, !"Dwarf Version", i32 5}
29+
!5 = !{i32 2, !"Debug Info Version", i32 3}
30+
!6 = !{i32 1, !"wchar_size", i32 4}
31+
!7 = !{i32 8, !"PIC Level", i32 2}
32+
!8 = !{i32 7, !"uwtable", i32 1}
33+
!9 = !{i32 7, !"frame-pointer", i32 1}
34+
!10 = !{!"clang"}
35+
!11 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 8, type: !12, scopeLine: 8, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
36+
!12 = !DISubroutineType(types: !13)
37+
!13 = !{!2}
38+
!14 = !DILocation(line: 11, column: 1, scope: !11)

0 commit comments

Comments
 (0)