Skip to content

Commit 05bd7d2

Browse files
authored
[MLIR] Fix triple mismatch warning for embedded libdevice (#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.
1 parent 14ba3f9 commit 05bd7d2

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

llvm/lib/Linker/IRMover.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,10 +1562,6 @@ Error IRLinker::run() {
15621562
bool EnableDLWarning = true;
15631563
bool EnableTripleWarning = true;
15641564
if (SrcTriple.isNVPTX() && DstTriple.isNVPTX()) {
1565-
std::string ModuleId = SrcM->getModuleIdentifier();
1566-
StringRef FileName = llvm::sys::path::filename(ModuleId);
1567-
bool SrcIsLibDevice =
1568-
FileName.starts_with("libdevice") && FileName.ends_with(".10.bc");
15691565
bool SrcHasLibDeviceDL =
15701566
(SrcM->getDataLayoutStr().empty() ||
15711567
SrcM->getDataLayoutStr() == "e-i64:64-v16:16-v32:32-n16:32:64");
@@ -1576,8 +1572,8 @@ Error IRLinker::run() {
15761572
SrcTriple.getOSName() == "gpulibs") ||
15771573
(SrcTriple.getVendorName() == "unknown" &&
15781574
SrcTriple.getOSName() == "unknown");
1579-
EnableTripleWarning = !(SrcIsLibDevice && SrcHasLibDeviceTriple);
1580-
EnableDLWarning = !(SrcIsLibDevice && SrcHasLibDeviceDL);
1575+
EnableTripleWarning = !SrcHasLibDeviceTriple;
1576+
EnableDLWarning = !(SrcHasLibDeviceTriple && SrcHasLibDeviceDL);
15811577
}
15821578

15831579
if (EnableDLWarning && (SrcM->getDataLayout() != DstM.getDataLayout())) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target triple = "nvptx64-nvidia-gpulibs"
2+
target datalayout = "e-i64:64-i128:128-v32:32-n16:32:64"

llvm/test/Linker/cuda-libdevice.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
; RUN: llvm-as %p/Inputs/libdevice-cuda-9.ll -o %t/libdevice.compute_35.10.bc
55
; RUN: llvm-as %p/Inputs/libdevice-cuda-10.ll -o %t/libdevice.10.bc
66
; RUN: llvm-as %p/Inputs/libdevice-cuda-11.ll -o %t/libdevice.11.10.bc
7-
; RUN: llvm-as %p/Inputs/libdevice-cuda-9.ll -o %t/correct-libdevice-wrong-filename.bc
87
; RUN: llvm-as %p/Inputs/not-a-libdevice.ll -o %t/libdevice-with-wrong-info.bc
8+
; RUN: llvm-as %p/Inputs/libdevice-with-wrong-dl.ll -o %t/libdevice-with-wrong-dl.bc
99

1010
; No warnings expected when we link with libdevice variants
1111
; RUN: llvm-link %t/main.bc %t/libdevice.compute_35.10.bc -S 2>&1 \
@@ -15,12 +15,12 @@
1515
; RUN: llvm-link %t/main.bc %t/libdevice.11.10.bc -S 2>&1 \
1616
; RUN: | FileCheck --check-prefixes COMMON,NOWARN %s
1717

18-
; But make sure we still issue warnings if we see unexpected filename, or
19-
; unexpected triple or datalayout within a libdevice filename.
20-
; RUN: llvm-link %t/main.bc %t/correct-libdevice-wrong-filename.bc -S 2>&1 \
21-
; RUN: | FileCheck --check-prefixes COMMON,WARN-TRIPLE %s
18+
; But make sure we still issue warnings if we see unexpected triple or
19+
; datalayout within a libdevice module.
2220
; RUN: llvm-link %t/main.bc %t/libdevice-with-wrong-info.bc -S 2>&1 \
2321
; RUN: | FileCheck --check-prefixes COMMON,WARN-TRIPLE,WARN-DL %s
22+
; RUN: llvm-link %t/main.bc %t/libdevice-with-wrong-dl.bc -S 2>&1 \
23+
; RUN: | FileCheck --check-prefixes COMMON,NOWARN,WARN-DL %s
2424

2525

2626
target triple = "nvptx64-nvidia-cuda"

0 commit comments

Comments
 (0)