-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
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
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-llvm-binary-utilities Author: Daniel Sanders (dsandersllvm) ChangesUnfortunately 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 Full diff: https://github.com/llvm/llvm-project/pull/117215.diff 4 Files Affected:
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index f7d81636f4dd4e..07f87d44088e7e 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -138,6 +138,7 @@ typedef enum {
LLVMDWARFSourceLanguageRuby,
LLVMDWARFSourceLanguageMove,
LLVMDWARFSourceLanguageHylo,
+ LLVMDWARFSourceLanguageMetal,
// Vendor extensions:
LLVMDWARFSourceLanguageMips_Assembler,
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.def b/llvm/include/llvm/BinaryFormat/Dwarf.def
index 4aa6defdc3a41f..d0020e32456243 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.def
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.def
@@ -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, APPLE)
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)
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 4657ad30eb1be4..efdf3f252085e6 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -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 {};
}
@@ -481,6 +483,8 @@ toDW_LNAME(SourceLanguage language) {
return {{DW_LNAME_Hylo, 0}};
case DW_LANG_BORLAND_Delphi:
case DW_LANG_CPP_for_OpenCL:
+ case DW_LANG_Metal:
+ return {{DW_LNAME_Metal, 0}};
case DW_LANG_lo_user:
case DW_LANG_hi_user:
return {};
@@ -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.");
diff --git a/llvm/test/tools/llvm-dwarfdump/AArch64/dwarf-lang-metal.ll b/llvm/test/tools/llvm-dwarfdump/AArch64/dwarf-lang-metal.ll
new file mode 100644
index 00000000000000..b5606ffc71dd37
--- /dev/null
+++ b/llvm/test/tools/llvm-dwarfdump/AArch64/dwarf-lang-metal.ll
@@ -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)
|
This had been missed by previous language id additions too
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