summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver/ToolChain.cpp
diff options
context:
space:
mode:
authorGheorghe-Teodor Bercea <gheorghe-teod.bercea@ibm.com>2017-08-07 15:39:11 +0000
committerGheorghe-Teodor Bercea <gheorghe-teod.bercea@ibm.com>2017-08-07 15:39:11 +0000
commit47e0cf378c793b00207998a0537c2fd75bd1ec74 (patch)
tree3f667d95b0f1bf3a9a5009c9c8a568374d48cfb2 /clang/lib/Driver/ToolChain.cpp
parent02d9945e6f11959887e2eefbbb5a635ff5087dbe (diff)
downloadbcm5719-llvm-47e0cf378c793b00207998a0537c2fd75bd1ec74.tar.gz
bcm5719-llvm-47e0cf378c793b00207998a0537c2fd75bd1ec74.zip
[OpenMP] Add flag for specifying the target device architecture for OpenMP device offloading
Summary: OpenMP has the ability to offload target regions to devices which may have different architectures. A new -fopenmp-target-arch flag is introduced to specify the device architecture. In this patch I use the new flag to specify the compute capability of the underlying NVIDIA architecture for the OpenMP offloading CUDA tool chain. Only a host-offloading test is provided since full device offloading capability will only be available when [[ https://reviews.llvm.org/D29654 | D29654 ]] lands. Reviewers: hfinkel, Hahnfeld, carlo.bertolli, caomhin, ABataev Reviewed By: hfinkel Subscribers: guansong, cfe-commits Tags: #openmp Differential Revision: https://reviews.llvm.org/D34784 llvm-svn: 310263
Diffstat (limited to 'clang/lib/Driver/ToolChain.cpp')
-rw-r--r--clang/lib/Driver/ToolChain.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 1e446dc1ebc..94d5e4fc0f2 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -795,3 +795,65 @@ ToolChain::computeMSVCVersion(const Driver *D,
return VersionTuple();
}
+
+llvm::opt::DerivedArgList *
+ToolChain::TranslateOpenMPTargetArgs(const llvm::opt::DerivedArgList &Args,
+ Action::OffloadKind DeviceOffloadKind) const {
+ if (DeviceOffloadKind == Action::OFK_OpenMP) {
+ DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
+ const OptTable &Opts = getDriver().getOpts();
+
+ // Handle -Xopenmp-target flags
+ for (Arg *A : Args) {
+ // Exclude flags which may only apply to the host toolchain.
+ // Do not exclude flags when the host triple (AuxTriple),
+ // matches the current toolchain triple.
+ if (A->getOption().matches(options::OPT_m_Group)) {
+ if (getAuxTriple() && getAuxTriple()->str() == getTriple().str())
+ DAL->append(A);
+ continue;
+ }
+
+ unsigned Index;
+ unsigned Prev;
+ bool XOpenMPTargetNoTriple = A->getOption().matches(
+ options::OPT_Xopenmp_target);
+
+ if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
+ // Passing device args: -Xopenmp-target=<triple> -opt=val.
+ if (A->getValue(0) == getTripleString())
+ Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
+ else
+ continue;
+ } else if (XOpenMPTargetNoTriple) {
+ // Passing device args: -Xopenmp-target -opt=val.
+ Index = Args.getBaseArgs().MakeIndex(A->getValue(0));
+ } else {
+ DAL->append(A);
+ continue;
+ }
+
+ // Parse the argument to -Xopenmp-target.
+ Prev = Index;
+ std::unique_ptr<Arg> XOpenMPTargetArg(Opts.ParseOneArg(Args, Index));
+ if (!XOpenMPTargetArg || Index > Prev + 1) {
+ getDriver().Diag(diag::err_drv_invalid_Xopenmp_target_with_args)
+ << A->getAsString(Args);
+ continue;
+ }
+ if (XOpenMPTargetNoTriple && XOpenMPTargetArg &&
+ Args.getAllArgValues(
+ options::OPT_fopenmp_targets_EQ).size() != 1) {
+ getDriver().Diag(diag::err_drv_Xopenmp_target_missing_triple);
+ continue;
+ }
+ XOpenMPTargetArg->setBaseArg(A);
+ A = XOpenMPTargetArg.release();
+ DAL->append(A);
+ }
+
+ return DAL;
+ }
+
+ return nullptr;
+}
OpenPOWER on IntegriCloud