Skip to content

Conversation

@arthurqiu
Copy link
Contributor

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. This patch uses source filename for that purpose instead.

Note that source_filename is recorded as below in libdevice.10.bc:

; ModuleID = 'libdevice.10.bc'
source_filename = "libdevice.10.bc"
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
target triple = "nvptx64-nvidia-gpulibs"

@llvmbot llvmbot added the LTO Link time optimization (regular/full LTO or ThinLTO) label Dec 20, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 20, 2024

@llvm/pr-subscribers-lto

Author: None (arthurqiu)

Changes

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. This patch uses source filename for that purpose instead.

Note that source_filename is recorded as below in libdevice.10.bc:

; ModuleID = 'libdevice.10.bc'
source_filename = "libdevice.10.bc"
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
target triple = "nvptx64-nvidia-gpulibs"

Full diff: https://github.com/llvm/llvm-project/pull/120669.diff

1 Files Affected:

  • (modified) llvm/lib/Linker/IRMover.cpp (+1-2)
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index a0c3f2c5b0baf6..23f889eff17020 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1562,8 +1562,7 @@ 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);
+    StringRef FileName = SrcM->getSourceFileName();
     bool SrcIsLibDevice =
         FileName.starts_with("libdevice") && FileName.ends_with(".10.bc");
     bool SrcHasLibDeviceDL =

@arthurqiu arthurqiu marked this pull request as draft December 20, 2024 03:30
if (SrcTriple.isNVPTX() && DstTriple.isNVPTX()) {
std::string ModuleId = SrcM->getModuleIdentifier();
StringRef FileName = llvm::sys::path::filename(ModuleId);
StringRef FileName = SrcM->getSourceFileName();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
StringRef FileName = SrcM->getSourceFileName();
StringRef FileName = llvm::sys::path::filename(SrcM->getSourceFileName());

@arthurqiu arthurqiu closed this Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LTO Link time optimization (regular/full LTO or ThinLTO)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants