[PATCH] D128090: [Clang][OpenMP] Process multi-arch compilation options given via -march

Saiyedul Islam via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 17 12:16:02 PDT 2022


saiislam updated this revision to Diff 438004.
saiislam added a comment.

clang-formatted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128090

Files:
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -722,6 +722,38 @@
   return RT;
 }
 
+bool Driver::GetTargetInfoFromMArch(
+    Compilation &C, llvm::StringMap<llvm::DenseSet<StringRef>> &DerivedArchs) {
+  StringRef OpenMPTargetArch;
+  for (Arg *A : C.getInputArgs()) {
+    if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
+      StringRef OpenMPTargetTriple = StringRef(A->getValue(0));
+      llvm::Triple TargetTriple(OpenMPTargetTriple);
+
+      for (auto *V : A->getValues()) {
+        StringRef VStr = StringRef(V);
+        if (VStr.startswith("-march=") || VStr.startswith("--march=")) {
+          OpenMPTargetArch = VStr.split('=').second;
+          CudaArch Arch = StringToCudaArch(StringRef(OpenMPTargetArch));
+          if (Arch == CudaArch::UNKNOWN) {
+            C.getDriver().Diag(clang::diag::err_drv_cuda_bad_gpu_arch)
+                << OpenMPTargetArch;
+            C.setContainsError();
+            return false;
+          }
+
+          if (!OpenMPTargetTriple.empty() && !OpenMPTargetArch.empty()) {
+            DerivedArchs[OpenMPTargetTriple].insert(OpenMPTargetArch);
+          }
+        }
+        A->claim();
+      }
+    }
+  }
+
+  return true;
+}
+
 void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
                                               InputList &Inputs) {
 
@@ -812,6 +844,10 @@
             << OpenMPTargets->getAsString(C.getInputArgs());
         return;
       }
+      // Process legacy option -fopenmp-targets -Xopenmp-target and -march
+      auto status = GetTargetInfoFromMArch(C, DerivedArchs);
+      if (!status)
+        return;
       llvm::copy(OpenMPTargets->getValues(), std::back_inserter(OpenMPTriples));
     } else if (C.getInputArgs().hasArg(options::OPT_offload_arch_EQ) &&
                !IsHIP && !IsCuda) {
Index: clang/include/clang/Driver/Driver.h
===================================================================
--- clang/include/clang/Driver/Driver.h
+++ clang/include/clang/Driver/Driver.h
@@ -412,6 +412,11 @@
   /// current compilation. Also, update the host tool chain kind accordingly.
   void CreateOffloadingDeviceToolChains(Compilation &C, InputList &Inputs);
 
+  /// GetTargetInfoFromMArch - extract sub-architecture from -march flag used
+  /// with -fopenmp-targets and -Xopenmp-target options.
+  bool GetTargetInfoFromMArch(
+      Compilation &C, llvm::StringMap<llvm::DenseSet<StringRef>> &DerivedArchs);
+
   /// BuildCompilation - Construct a compilation object for a command
   /// line argument vector.
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128090.438004.patch
Type: text/x-patch
Size: 2670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220617/35c0d6e8/attachment.bin>


More information about the cfe-commits mailing list