diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -1478,20 +1478,32 @@ if (SrcTriple.isNVPTX() && DstTriple.isNVPTX()) { std::string ModuleId = SrcM->getModuleIdentifier(); StringRef FileName = llvm::sys::path::filename(ModuleId); - bool SrcIsLibDevice = - FileName.startswith("libdevice") && FileName.endswith(".10.bc"); + bool SrcIsDeviceLib = + (FileName.startswith("libdevice") && FileName.endswith(".10.bc")) || + (FileName.startswith("libomptarget") && FileName.endswith(".bc")); bool SrcHasLibDeviceDL = (SrcM->getDataLayoutStr().empty() || SrcM->getDataLayoutStr() == "e-i64:64-v16:16-v32:32-n16:32:64"); // libdevice bitcode uses nvptx64-nvidia-gpulibs or just // 'nvptx-unknown-unknown' triple (before CUDA-10.x) and is compatible with - // all NVPTX variants. + // all NVPTX variants. libomptarget bitcode uses nvptx64-nvidia-cuda. bool SrcHasLibDeviceTriple = (SrcTriple.getVendor() == Triple::NVIDIA && SrcTriple.getOSName() == "gpulibs") || (SrcTriple.getVendorName() == "unknown" && - SrcTriple.getOSName() == "unknown"); - EnableTripleWarning = !(SrcIsLibDevice && SrcHasLibDeviceTriple); - EnableDLWarning = !(SrcIsLibDevice && SrcHasLibDeviceDL); + SrcTriple.getOSName() == "unknown") || + (SrcTriple.getVendor() == Triple::NVIDIA && + SrcTriple.getOS() == Triple::CUDA); + EnableTripleWarning = !(SrcIsDeviceLib && SrcHasLibDeviceTriple); + EnableDLWarning = !(SrcIsDeviceLib && SrcHasLibDeviceDL); + } else if (SrcTriple.isAMDGPU() && DstTriple.isAMDGPU()) { + std::string ModuleId = SrcM->getModuleIdentifier(); + StringRef FileName = llvm::sys::path::filename(ModuleId); + bool SrcIsDeviceLib = + (FileName.startswith("libomptarget") && FileName.endswith(".bc")); + // libomptarget bitcode uses an amdgcn-amd-amdhsa triple. + bool SrcHasLibDeviceTriple = SrcTriple.getVendor() == Triple::AMD && + SrcTriple.getOS() == Triple::AMDHSA; + EnableTripleWarning = !(SrcIsDeviceLib && SrcHasLibDeviceTriple); } if (EnableDLWarning && (SrcM->getDataLayout() != DstM.getDataLayout())) { diff --git a/llvm/test/Linker/Inputs/libomptarget-amdgcn.ll b/llvm/test/Linker/Inputs/libomptarget-amdgcn.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Linker/Inputs/libomptarget-amdgcn.ll @@ -0,0 +1 @@ +target triple = "amdgcn-amd-amdhsa" diff --git a/llvm/test/Linker/Inputs/libomptarget-nvptx.ll b/llvm/test/Linker/Inputs/libomptarget-nvptx.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Linker/Inputs/libomptarget-nvptx.ll @@ -0,0 +1 @@ +target triple = "nvptx64-nvidia-cuda" diff --git a/llvm/test/Linker/libomptarget-amdgcn.ll b/llvm/test/Linker/libomptarget-amdgcn.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Linker/libomptarget-amdgcn.ll @@ -0,0 +1,19 @@ +; Prepare bitcode files. +; RUN: rm -rf %t && mkdir -p %t +; RUN: llvm-as %s -o %t/main.bc +; RUN: llvm-as %p/Inputs/libomptarget-amdgcn.ll -o %t/libomptarget-amdgcn.bc +; RUN: llvm-as %p/Inputs/not-a-libdevice.ll -o %t/libomptarget-wrong-info.bc + +; No warnings expected when we link with libomptarget variants. +; RUN: llvm-link %t/main.bc %t/libomptarget-amdgcn.bc -S 2>&1 \ +; RUN: | FileCheck --check-prefixes COMMON,NOWARN %s + +; But make sure we still issue warnings if we see unexpected filename. +; RUN: llvm-link %t/main.bc %t/libomptarget-wrong-info.bc -S 2>&1 \ +; RUN: | FileCheck --check-prefixes COMMON,WARN %s + +target triple = "amdgcn-unknown-unknown" + +; WARN-DAG: warning: Linking two modules of different target triples: +; NOWARN-NOT: warning: +; COMMON-DAG: target triple = "amdgcn-unknown-unknown" diff --git a/llvm/test/Linker/libomptarget-nvptx.ll b/llvm/test/Linker/libomptarget-nvptx.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Linker/libomptarget-nvptx.ll @@ -0,0 +1,20 @@ +; Prepare bitcode files. +; RUN: rm -rf %t && mkdir -p %t +; RUN: llvm-as %s -o %t/main.bc +; RUN: llvm-as %p/Inputs/libomptarget-nvptx.ll -o %t/libomptarget-nvptx.bc +; RUN: llvm-as %p/Inputs/not-a-libdevice.ll -o %t/libomptarget-wrong-info.bc + +; No warnings expected when we link with libomptarget variants. +; RUN: llvm-link %t/main.bc %t/libomptarget-nvptx.bc -S 2>&1 \ +; RUN: | FileCheck --check-prefixes COMMON,NOWARN %s + +; But make sure we still issue warnings if we see unexpected filename. +; RUN: llvm-link %t/main.bc %t/libomptarget-wrong-info.bc -S 2>&1 \ +; RUN: | FileCheck --check-prefixes COMMON,WARN %s + + +target triple = "nvptx64-unknown-unknown" + +; WARN-DAG: warning: Linking two modules of different target triples: +; NOWARN-NOT: warning: +; COMMON-DAG: target triple = "nvptx64-unknown-unknown" diff --git a/openmp/libomptarget/DeviceRTL/CMakeLists.txt b/openmp/libomptarget/DeviceRTL/CMakeLists.txt --- a/openmp/libomptarget/DeviceRTL/CMakeLists.txt +++ b/openmp/libomptarget/DeviceRTL/CMakeLists.txt @@ -227,7 +227,7 @@ # Generate a Bitcode library for all the compute capabilities the user requested foreach(sm ${nvptx_sm_list}) - compileDeviceRTLLibrary(sm_${sm} nvptx -target nvptx64 -Xclang -target-feature -Xclang +ptx61 "-D__CUDA_ARCH__=${sm}0") + compileDeviceRTLLibrary(sm_${sm} nvptx -target nvptx64-nvidia-cuda -Xclang -target-feature -Xclang +ptx61 "-D__CUDA_ARCH__=${sm}0") endforeach() foreach(mcpu ${amdgpu_mcpus})