[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:11:16 PDT 2022


saiislam created this revision.
saiislam added reviewers: jdoerfert, JonChesterfield, jhuber6, yaxunl.
Herald added a subscriber: guansong.
Herald added a project: All.
saiislam requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, MaskRay.
Herald added a project: clang.

Subarchitectures for multi-file compilation specified using -fopenmp-targets,
-Xopenmp-target, and -march were not getting added to the
<Triple, Set(Archs)> map `KnownArchs`.


Repository:
  rG LLVM Github Monorepo

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,37 @@
   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 +843,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,10 @@
   /// 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.438002.patch
Type: text/x-patch
Size: 2656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220617/7de224ce/attachment.bin>


More information about the cfe-commits mailing list