[llvm] [DirectX][NFC] Move DICompileUnit conversion into DXILDebugInfo (PR #196451)

Harald van Dijk via llvm-commits llvm-commits at lists.llvm.org
Fri May 8 18:38:32 PDT 2026


https://github.com/hvdijk updated https://github.com/llvm/llvm-project/pull/196451

>From 42b3fff85b42f95cb8b767012052505641aa9867 Mon Sep 17 00:00:00 2001
From: Harald van Dijk <hdijk at accesssoftek.com>
Date: Fri, 8 May 2026 01:11:48 +0100
Subject: [PATCH] [DirectX][NFC] Move DICompileUnit conversion into
 DXILDebugInfo

In #192574, I added logic for changing versioned language names to
unversioned language names, but did so directly in DXILBitcodeWriter.
This is better done in DXILDebugInfo instead.
---
 .../DirectX/DXILWriter/DXILBitcodeWriter.cpp  |  8 +-------
 .../DirectX/DirectXIRPasses/DXILDebugInfo.cpp | 20 +++++++++++++++++++
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
index 15eb886574e6e..984ddf8f334b7 100644
--- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
+++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
@@ -1528,13 +1528,7 @@ void DXILBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
                                            SmallVectorImpl<uint64_t> &Record,
                                            unsigned Abbrev) {
   Record.push_back(N->isDistinct());
-  DISourceLanguageName Lang = N->getSourceLanguage();
-  if (Lang.hasVersionedName()) {
-    auto LangName = static_cast<dwarf::SourceLanguageName>(Lang.getName());
-    Lang = dwarf::toDW_LANG(LangName, Lang.getVersion())
-               .value_or(dwarf::SourceLanguage{});
-  }
-  Record.push_back(Lang.getUnversionedName());
+  Record.push_back(N->getSourceLanguage().getUnversionedName());
   Record.push_back(VE.getMetadataOrNullID(N->getFile()));
   Record.push_back(VE.getMetadataOrNullID(N->getRawProducer()));
   Record.push_back(N->isOptimized());
diff --git a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
index 650338949d19a..1e638d0195327 100644
--- a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
+++ b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "DXILDebugInfo.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/Module.h"
 
@@ -20,5 +21,24 @@ DXILDebugInfoMap DXILDebugInfoPass::run(Module &M) {
   DebugInfoFinder DIF;
   DIF.processModule(M);
 
+  for (DICompileUnit *CU : DIF.compile_units()) {
+    DISourceLanguageName Lang = CU->getSourceLanguage();
+    if (Lang.hasVersionedName()) {
+      auto LangName = static_cast<dwarf::SourceLanguageName>(Lang.getName());
+      Lang = dwarf::toDW_LANG(LangName, Lang.getVersion())
+                 .value_or(dwarf::SourceLanguage{});
+      auto *NewCU = DICompileUnit::getDistinct(
+          M.getContext(), Lang, CU->getFile(), CU->getProducer(),
+          CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(),
+          CU->getSplitDebugFilename(), CU->getEmissionKind(),
+          CU->getEnumTypes(), CU->getRetainedTypes(), CU->getGlobalVariables(),
+          CU->getImportedEntities(), CU->getMacros(), CU->getDWOId(),
+          CU->getSplitDebugInlining(), CU->getDebugInfoForProfiling(),
+          CU->getNameTableKind(), CU->getRangesBaseAddress(), CU->getSysRoot(),
+          CU->getSDK());
+      Res.MDReplace.insert({CU, NewCU});
+    }
+  }
+
   return Res;
 }



More information about the llvm-commits mailing list