r314902 - [OpenMP] Fix passing of -m arguments correctly
Jonas Hahnfeld via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 4 06:32:59 PDT 2017
Author: hahnfeld
Date: Wed Oct 4 06:32:59 2017
New Revision: 314902
URL: http://llvm.org/viewvc/llvm-project?rev=314902&view=rev
Log:
[OpenMP] Fix passing of -m arguments correctly
The recent fix in D38258 was wrong: getAuxTriple() only returns
non-null values for the CUDA toolchain. That is why the now added
test for PPC and X86 failed.
Differential Revision: https://reviews.llvm.org/D38372
Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/Compilation.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/test/Driver/openmp-offload.c
Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=314902&r1=314901&r2=314902&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Wed Oct 4 06:32:59 2017
@@ -245,14 +245,9 @@ public:
/// TranslateOpenMPTargetArgs - Create a new derived argument list for
/// that contains the OpenMP target specific flags passed via
/// -Xopenmp-target -opt=val OR -Xopenmp-target=<triple> -opt=val
- /// Translation occurs only when the \p DeviceOffloadKind is specified.
- ///
- /// \param DeviceOffloadKind - The device offload kind used for the
- /// translation.
virtual llvm::opt::DerivedArgList *TranslateOpenMPTargetArgs(
- const llvm::opt::DerivedArgList &Args,
- Action::OffloadKind DeviceOffloadKind,
- SmallVector<llvm::opt::Arg *, 4> &AllocatedArgs) const;
+ const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost,
+ SmallVectorImpl<llvm::opt::Arg *> &AllocatedArgs) const;
/// Choose a tool to use to handle the action \p JA.
///
Modified: cfe/trunk/lib/Driver/Compilation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Compilation.cpp?rev=314902&r1=314901&r2=314902&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Compilation.cpp (original)
+++ cfe/trunk/lib/Driver/Compilation.cpp Wed Oct 4 06:32:59 2017
@@ -52,9 +52,15 @@ Compilation::getArgsForToolChain(const T
DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
if (!Entry) {
SmallVector<Arg *, 4> AllocatedArgs;
+ DerivedArgList *OpenMPArgs = nullptr;
// Translate OpenMP toolchain arguments provided via the -Xopenmp-target flags.
- DerivedArgList *OpenMPArgs = TC->TranslateOpenMPTargetArgs(
- *TranslatedArgs, DeviceOffloadKind, AllocatedArgs);
+ if (DeviceOffloadKind == Action::OFK_OpenMP) {
+ const ToolChain *HostTC = getSingleOffloadToolChain<Action::OFK_Host>();
+ bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple());
+ OpenMPArgs = TC->TranslateOpenMPTargetArgs(
+ *TranslatedArgs, SameTripleAsHost, AllocatedArgs);
+ }
+
if (!OpenMPArgs) {
Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind);
if (!Entry)
Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=314902&r1=314901&r2=314902&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Wed Oct 4 06:32:59 2017
@@ -801,74 +801,68 @@ ToolChain::computeMSVCVersion(const Driv
}
llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs(
- const llvm::opt::DerivedArgList &Args,
- Action::OffloadKind DeviceOffloadKind,
- SmallVector<llvm::opt::Arg *, 4> &AllocatedArgs) const {
- if (DeviceOffloadKind == Action::OFK_OpenMP) {
- DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
- const OptTable &Opts = getDriver().getOpts();
- bool Modified = false;
-
- // 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 it is not present
- // at all, target and host share a toolchain.
- if (A->getOption().matches(options::OPT_m_Group)) {
- if (!getAuxTriple() || getAuxTriple()->str() == getTriple().str())
- DAL->append(A);
- else
- Modified = true;
- 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 {
+ const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost,
+ SmallVectorImpl<llvm::opt::Arg *> &AllocatedArgs) const {
+ DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
+ const OptTable &Opts = getDriver().getOpts();
+ bool Modified = false;
+
+ // 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 it is not present
+ // at all, target and host share a toolchain.
+ if (A->getOption().matches(options::OPT_m_Group)) {
+ if (SameTripleAsHost)
DAL->append(A);
- continue;
- }
+ else
+ Modified = true;
+ 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);
+ 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;
- }
- XOpenMPTargetArg->setBaseArg(A);
- A = XOpenMPTargetArg.release();
- AllocatedArgs.push_back(A);
+ } else if (XOpenMPTargetNoTriple) {
+ // Passing device args: -Xopenmp-target -opt=val.
+ Index = Args.getBaseArgs().MakeIndex(A->getValue(0));
+ } else {
DAL->append(A);
- Modified = true;
+ continue;
}
- if (Modified) {
- return DAL;
- } else {
- delete DAL;
+ // 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();
+ AllocatedArgs.push_back(A);
+ DAL->append(A);
+ Modified = true;
}
+ if (Modified)
+ return DAL;
+
+ delete DAL;
return nullptr;
}
Modified: cfe/trunk/test/Driver/openmp-offload.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openmp-offload.c?rev=314902&r1=314901&r2=314902&view=diff
==============================================================================
--- cfe/trunk/test/Driver/openmp-offload.c (original)
+++ cfe/trunk/test/Driver/openmp-offload.c Wed Oct 4 06:32:59 2017
@@ -71,6 +71,14 @@
/// ###########################################################################
+/// Check -march=pwr7 is NOT passed to x86_64-unknown-linux-gnu.
+// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=x86_64-unknown-linux-gnu -march=pwr7 %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHK-FOPENMP-MARCH-TO-X86 %s
+
+// CHK-FOPENMP-MARCH-TO-X86-NOT: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
+
+/// ###########################################################################
+
/// Check -Xopenmp-target triggers error when multiple triples are used.
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu,powerpc64le-unknown-linux-gnu -Xopenmp-target -mcpu=pwr8 %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-FOPENMP-TARGET-AMBIGUOUS-ERROR %s
More information about the cfe-commits
mailing list