Index: cfe/trunk/include/clang/Driver/ToolChain.h =================================================================== --- cfe/trunk/include/clang/Driver/ToolChain.h +++ cfe/trunk/include/clang/Driver/ToolChain.h @@ -245,14 +245,9 @@ /// TranslateOpenMPTargetArgs - Create a new derived argument list for /// that contains the OpenMP target specific flags passed via /// -Xopenmp-target -opt=val OR -Xopenmp-target= -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 &AllocatedArgs) const; + const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost, + SmallVectorImpl &AllocatedArgs) const; /// Choose a tool to use to handle the action \p JA. /// Index: cfe/trunk/lib/Driver/Compilation.cpp =================================================================== --- cfe/trunk/lib/Driver/Compilation.cpp +++ cfe/trunk/lib/Driver/Compilation.cpp @@ -52,9 +52,15 @@ DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}]; if (!Entry) { SmallVector 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(); + bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple()); + OpenMPArgs = TC->TranslateOpenMPTargetArgs( + *TranslatedArgs, SameTripleAsHost, AllocatedArgs); + } + if (!OpenMPArgs) { Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind); if (!Entry) Index: cfe/trunk/lib/Driver/ToolChain.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChain.cpp +++ cfe/trunk/lib/Driver/ToolChain.cpp @@ -801,74 +801,68 @@ } llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs( - const llvm::opt::DerivedArgList &Args, - Action::OffloadKind DeviceOffloadKind, - SmallVector &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= -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 &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 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= -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 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; } Index: cfe/trunk/test/Driver/openmp-offload.c =================================================================== --- cfe/trunk/test/Driver/openmp-offload.c +++ cfe/trunk/test/Driver/openmp-offload.c @@ -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