[PATCH] D118495: [OpenMP] Accept shortened triples for -Xopenmp-target=

Joseph Huber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 28 10:30:44 PST 2022


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

This patch builds on the change in D117634 <https://reviews.llvm.org/D117634> that expanded the short
triples when passed in by the user. This patch adds the same
functionality for the `-Xopenmp-target=` flag. Previously it was
unintuitive that passing `-fopenmp-targets=nvptx64
-Xopenmp-target=nvptx64 <arg>` would not forward the arg because the
triples did not match on account of `nvptx64` being expanded to
`nvptx64-nvidia-cuda`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118495

Files:
  clang/lib/Driver/ToolChain.cpp


Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -1129,8 +1129,20 @@
         A->getOption().matches(options::OPT_Xopenmp_target);
 
     if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
+      llvm::Triple TT(A->getValue(0));
+      // We want to expand the shortened versions of the triples passed in to
+      // the values used for the bitcode libraries for convenience.
+      if (TT.getVendor() == llvm::Triple::UnknownVendor ||
+          TT.getOS() == llvm::Triple::UnknownOS) {
+        if (TT.getArch() == llvm::Triple::nvptx)
+          TT = llvm::Triple("nvptx-nvidia-cuda");
+        else if (TT.getArch() == llvm::Triple::nvptx64)
+          TT = llvm::Triple("nvptx64-nvidia-cuda");
+        else if (TT.getArch() == llvm::Triple::amdgcn)
+          TT = llvm::Triple("amdgcn-amd-amdhsa");
+      }
       // Passing device args: -Xopenmp-target=<triple> -opt=val.
-      if (A->getValue(0) == getTripleString())
+      if (TT.getTriple() == getTripleString())
         Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
       else
         continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118495.404087.patch
Type: text/x-patch
Size: 1213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220128/7b75499e/attachment-0001.bin>


More information about the cfe-commits mailing list