[PATCH] D117634: [OpenMP] Add triple warning exceptions for OpenMP bitcode library

Joseph Huber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 18 19:27:22 PST 2022


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield, ye-luo.
Herald added subscribers: guansong, hiraditya, yaxunl, mgorny.
jhuber6 requested review of this revision.
Herald added subscribers: llvm-commits, openmp-commits, sstefan1.
Herald added projects: OpenMP, LLVM.

This patch extends the existing checks to avoid unhelpful warnings for
linking different targets of different triples when using device bitcode
libraries. This suppresses warnings when linking in the libomptarget
device bitcode library for cases where the base architecture matches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117634

Files:
  llvm/lib/Linker/IRMover.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt


Index: openmp/libomptarget/DeviceRTL/CMakeLists.txt
===================================================================
--- openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ 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})
Index: llvm/lib/Linker/IRMover.cpp
===================================================================
--- llvm/lib/Linker/IRMover.cpp
+++ 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())) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117634.401076.patch
Type: text/x-patch
Size: 3140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220119/6a21bf48/attachment.bin>


More information about the llvm-commits mailing list