[PATCH] D96877: [libomptarget] Try a fallback devicertl if the preferred one is missing

Jon Chesterfield via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 17 10:03:48 PST 2021


JonChesterfield updated this revision to Diff 324342.
JonChesterfield added a comment.

- drop whitespace from .td


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96877/new/

https://reviews.llvm.org/D96877

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1628,6 +1628,33 @@
   }
 }
 
+namespace {
+bool tryAppendBuiltinBitcode(const llvm::opt::ArgList &DriverArgs,
+                             llvm::opt::ArgStringList &CC1Args, StringRef lib) {
+  if (llvm::sys::fs::exists(lib)) {
+    CC1Args.push_back("-mlink-builtin-bitcode");
+    CC1Args.push_back(DriverArgs.MakeArgString(lib));
+    return true;
+  } else {
+    return false;
+  }
+}
+
+bool tryAppendBuiltinBitcodeGivenPaths(
+    const SmallVector<StringRef, 8> &LibraryPaths,
+    const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
+    llvm::Twine lib) {
+  for (StringRef LibraryPath : LibraryPaths) {
+    SmallString<128> TargetFile(LibraryPath);
+    llvm::sys::path::append(TargetFile, lib);
+    if (tryAppendBuiltinBitcode(DriverArgs, CC1Args, TargetFile)) {
+      return true;
+    }
+  }
+  return false;
+}
+} // namespace
+
 void tools::addOpenMPDeviceRTL(const Driver &D,
                                const llvm::opt::ArgList &DriverArgs,
                                llvm::opt::ArgStringList &CC1Args,
@@ -1658,32 +1685,31 @@
   // First check whether user specifies bc library
   if (const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
     std::string LibOmpTargetName(A->getValue());
-    if (llvm::sys::fs::exists(LibOmpTargetName)) {
-      CC1Args.push_back("-mlink-builtin-bitcode");
-      CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetName));
-    } else {
+    if (!tryAppendBuiltinBitcode(DriverArgs, CC1Args, LibOmpTargetName)) {
       D.Diag(diag::err_drv_omp_offload_target_bcruntime_not_found)
           << LibOmpTargetName;
     }
   } else {
     bool FoundBCLibrary = false;
 
-    std::string LibOmpTargetName =
-        "libomptarget-" + BitcodeSuffix.str() + ".bc";
-
-    for (StringRef LibraryPath : LibraryPaths) {
-      SmallString<128> LibOmpTargetFile(LibraryPath);
-      llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
-      if (llvm::sys::fs::exists(LibOmpTargetFile)) {
-        CC1Args.push_back("-mlink-builtin-bitcode");
-        CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
-        FoundBCLibrary = true;
-        break;
+    llvm::Twine LibOmpTargetName = "libomptarget-" + BitcodeSuffix + ".bc";
+    llvm::Twine FallbackTargetName =
+        "libomptarget-" + ArchPrefix + "-unknown.bc";
+
+    FoundBCLibrary = tryAppendBuiltinBitcodeGivenPaths(
+        LibraryPaths, DriverArgs, CC1Args, LibOmpTargetName);
+
+    if (!FoundBCLibrary) {
+      FoundBCLibrary = tryAppendBuiltinBitcodeGivenPaths(
+          LibraryPaths, DriverArgs, CC1Args, FallbackTargetName);
+      if (FoundBCLibrary) {
+        D.Diag(diag::warn_drv_omp_offload_target_missingbcruntime)
+            << LibOmpTargetName.str() << FallbackTargetName.str() << ArchPrefix;
       }
     }
 
     if (!FoundBCLibrary)
       D.Diag(diag::err_drv_omp_offload_target_missingbcruntime)
-          << LibOmpTargetName << ArchPrefix;
+          << LibOmpTargetName.str() << ArchPrefix;
   }
 }
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -262,6 +262,7 @@
   "The option -fopenmp-targets must be used in conjunction with a -fopenmp option compatible with offloading, please use -fopenmp=libomp or -fopenmp=libiomp5.">;
 def err_drv_omp_offload_target_missingbcruntime : Error<
   "No library '%0' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-%1-bc-path to specify %1 bitcode library.">;
+def warn_drv_omp_offload_target_missingbcruntime : Warning<"No library '%0' found in the default clang lib directory or in LIBRARY_PATH, using '%1' instead. Please use --libomptarget-%2-bc-path to specify %2 bitcode library.">;
 def err_drv_omp_offload_target_bcruntime_not_found : Error<"Bitcode library '%0' does not exist.">;
 def warn_drv_omp_offload_target_duplicate : Warning<
   "The OpenMP offloading target '%0' is similar to target '%1' already specified - will be ignored.">,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96877.324342.patch
Type: text/x-patch
Size: 4340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210217/ba929335/attachment-0001.bin>


More information about the cfe-commits mailing list