[llvm] 5d9aabb - [dwarf] Add language id for Metal Shading Language (#117215)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 22 13:49:46 PST 2024


Author: Daniel Sanders
Date: 2024-11-22T13:49:42-08:00
New Revision: 5d9aabbab3bcb83c84d29432f374db5119a4b578

URL: https://github.com/llvm/llvm-project/commit/5d9aabbab3bcb83c84d29432f374db5119a4b578
DIFF: https://github.com/llvm/llvm-project/commit/5d9aabbab3bcb83c84d29432f374db5119a4b578.diff

LOG: [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

Added: 
    llvm/test/tools/llvm-dwarfdump/AArch64/dwarf-lang-metal.ll

Modified: 
    llvm/include/llvm-c/DebugInfo.h
    llvm/include/llvm/BinaryFormat/Dwarf.def
    llvm/include/llvm/BinaryFormat/Dwarf.h
    llvm/lib/IR/DIBuilder.cpp

Removed: 
    


################################################################################
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..2bb84fbc864d8e 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, 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)

diff  --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 4657ad30eb1be4..3be819c0a76eeb 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 {};
 }
@@ -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.");

diff  --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 3af397bfc9ad19..b240a2a39de362 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -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");
 

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)


        


More information about the llvm-commits mailing list