[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 12:34:03 PST 2022
jhuber6 updated this revision to Diff 404136.
jhuber6 added a comment.
Adding test and shared function.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118495/new/
https://reviews.llvm.org/D118495
Files:
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChain.cpp
clang/test/Driver/openmp-offload-gpu.c
Index: clang/test/Driver/openmp-offload-gpu.c
===================================================================
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -343,3 +343,10 @@
// RUN: | FileCheck -check-prefix=SAVE_TEMPS_NAMES %s
// SAVE_TEMPS_NAMES-NOT: "GNU::Linker"{{.*}}["[[SAVE_TEMPS_INPUT1:.*\.o]]", "[[SAVE_TEMPS_INPUT1]]"]
+
+// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64 -Xopenmp-target=nvptx64 -march=sm_35 \
+// RUN: -save-temps -no-canonical-prefixes %s -o openmp-offload-gpu 2>&1 \
+// RUN: | FileCheck -check-prefix=TRIPLE %s
+
+// TRIPLE: "-triple" "nvptx64-nvidia-cuda"
+// TRIPLE: "-target-cpu" "sm_35"
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -1129,8 +1129,10 @@
A->getOption().matches(options::OPT_Xopenmp_target);
if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
+ llvm::Triple TT(getOpenMPTriple(A->getValue(0)));
+
// 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;
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -773,21 +773,9 @@
if (HasValidOpenMPRuntime) {
llvm::StringMap<const char *> FoundNormalizedTriples;
for (const char *Val : OpenMPTargets->getValues()) {
- llvm::Triple TT(Val);
+ llvm::Triple TT(ToolChain::getOpenMPTriple(Val));
std::string NormalizedName = TT.normalize();
- // 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");
- }
-
// Make sure we don't have a duplicate triple.
auto Duplicate = FoundNormalizedTriples.find(NormalizedName);
if (Duplicate != FoundNormalizedTriples.end()) {
Index: clang/include/clang/Driver/ToolChain.h
===================================================================
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -711,6 +711,22 @@
const llvm::fltSemantics *FPType = nullptr) const {
return llvm::DenormalMode::getIEEE();
}
+
+ // We want to expand the shortened versions of the triples passed in to
+ // the values used for the bitcode libraries.
+ static llvm::Triple getOpenMPTriple(StringRef TripleStr) {
+ llvm::Triple TT(TripleStr);
+ if (TT.getVendor() == llvm::Triple::UnknownVendor ||
+ TT.getOS() == llvm::Triple::UnknownOS) {
+ if (TT.getArch() == llvm::Triple::nvptx)
+ return llvm::Triple("nvptx-nvidia-cuda");
+ if (TT.getArch() == llvm::Triple::nvptx64)
+ return llvm::Triple("nvptx64-nvidia-cuda");
+ if (TT.getArch() == llvm::Triple::amdgcn)
+ return llvm::Triple("amdgcn-amd-amdhsa");
+ }
+ return TT;
+ }
};
/// Set a ToolChain's effective triple. Reset it when the registration object
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118495.404136.patch
Type: text/x-patch
Size: 3741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220128/e60a3de8/attachment-0001.bin>
More information about the cfe-commits
mailing list