[llvm] [MLIR] Fix triple mismatch warning for embedded libdevice (PR #121447)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 1 18:29:21 PST 2025


https://github.com/arthurqiu created https://github.com/llvm/llvm-project/pull/121447

IRLinker emits warning when linking two modules of different target triples. The warning is disabled if the source module is libdevice. When using libdevice embedded in LLVM library via MLIR_NVVM_EMBED_LIBDEVICE, IRLinker can no longer tell whether the source module is libdevice via module identifier.

Since `nvptx64-nvidia-gpulibs` is a magic triple that identifies the libdevice module already, the libdevice filename check is redundant. This patch fixes the triple mismatch warning by just removing the filename check.

>From 1087c4f6fa6fe7694813181e68a9d69e03a0ed7a Mon Sep 17 00:00:00 2001
From: Arthurq Qiu <arthurq at nvidia.com>
Date: Wed, 1 Jan 2025 18:23:28 -0800
Subject: [PATCH] Remove libdevice filename check

---
 llvm/lib/Linker/IRMover.cpp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index a0c3f2c5b0baf6..be3535ae94ff4e 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1562,10 +1562,6 @@ Error IRLinker::run() {
   bool EnableDLWarning = true;
   bool EnableTripleWarning = true;
   if (SrcTriple.isNVPTX() && DstTriple.isNVPTX()) {
-    std::string ModuleId = SrcM->getModuleIdentifier();
-    StringRef FileName = llvm::sys::path::filename(ModuleId);
-    bool SrcIsLibDevice =
-        FileName.starts_with("libdevice") && FileName.ends_with(".10.bc");
     bool SrcHasLibDeviceDL =
         (SrcM->getDataLayoutStr().empty() ||
          SrcM->getDataLayoutStr() == "e-i64:64-v16:16-v32:32-n16:32:64");
@@ -1576,8 +1572,8 @@ Error IRLinker::run() {
                                   SrcTriple.getOSName() == "gpulibs") ||
                                  (SrcTriple.getVendorName() == "unknown" &&
                                   SrcTriple.getOSName() == "unknown");
-    EnableTripleWarning = !(SrcIsLibDevice && SrcHasLibDeviceTriple);
-    EnableDLWarning = !(SrcIsLibDevice && SrcHasLibDeviceDL);
+    EnableTripleWarning = !SrcHasLibDeviceTriple;
+    EnableDLWarning = !(SrcHasLibDeviceTriple && SrcHasLibDeviceDL);
   }
 
   if (EnableDLWarning && (SrcM->getDataLayout() != DstM.getDataLayout())) {



More information about the llvm-commits mailing list