diff options
author | Samuel Antao <sfantao@us.ibm.com> | 2016-10-27 16:38:05 +0000 |
---|---|---|
committer | Samuel Antao <sfantao@us.ibm.com> | 2016-10-27 16:38:05 +0000 |
commit | 39f9da2a8752ae6d42c16b3a09538e83d3dedd6d (patch) | |
tree | ac5147eb48844ac8f6cf66a36e34a234a7669a5e /clang/lib/Driver/Tools.cpp | |
parent | 44f6f2ee423325e6157846593a74e5ed01ab3062 (diff) | |
download | bcm5719-llvm-39f9da2a8752ae6d42c16b3a09538e83d3dedd6d.tar.gz bcm5719-llvm-39f9da2a8752ae6d42c16b3a09538e83d3dedd6d.zip |
[Driver][OpenMP] Create tool chains for OpenMP offloading kind.
Summary: This patch adds new logic to create the necessary tool chains to support offloading for OpenMP. The OpenMP related options are checked and the tool chains created accordingly. Diagnostics are emitted in case the options are illegal or express unknown targets.
Reviewers: echristo, tra, jlebar, rsmith, ABataev, hfinkel
Subscribers: whchung, mkuron, mehdi_amini, cfe-commits, Hahnfeld, arpith-jacob, carlo.bertolli, caomhin
Differential Revision: https://reviews.llvm.org/D21843
llvm-svn: 285311
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 85 |
1 files changed, 18 insertions, 67 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 36b4c950ae4..848ea5bf1e8 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3009,72 +3009,23 @@ static void addClangRT(const ToolChain &TC, const ArgList &Args, CmdArgs.push_back(TC.getCompilerRTArgString(Args, "builtins")); } -namespace { -enum OpenMPRuntimeKind { - /// An unknown OpenMP runtime. We can't generate effective OpenMP code - /// without knowing what runtime to target. - OMPRT_Unknown, - - /// The LLVM OpenMP runtime. When completed and integrated, this will become - /// the default for Clang. - OMPRT_OMP, - - /// The GNU OpenMP runtime. Clang doesn't support generating OpenMP code for - /// this runtime but can swallow the pragmas, and find and link against the - /// runtime library itself. - OMPRT_GOMP, - - /// The legacy name for the LLVM OpenMP runtime from when it was the Intel - /// OpenMP runtime. We support this mode for users with existing dependencies - /// on this runtime library name. - OMPRT_IOMP5 -}; -} - -/// Compute the desired OpenMP runtime from the flag provided. -static OpenMPRuntimeKind getOpenMPRuntime(const ToolChain &TC, - const ArgList &Args) { - StringRef RuntimeName(CLANG_DEFAULT_OPENMP_RUNTIME); - - const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ); - if (A) - RuntimeName = A->getValue(); - - auto RT = llvm::StringSwitch<OpenMPRuntimeKind>(RuntimeName) - .Case("libomp", OMPRT_OMP) - .Case("libgomp", OMPRT_GOMP) - .Case("libiomp5", OMPRT_IOMP5) - .Default(OMPRT_Unknown); - - if (RT == OMPRT_Unknown) { - if (A) - TC.getDriver().Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << A->getValue(); - else - // FIXME: We could use a nicer diagnostic here. - TC.getDriver().Diag(diag::err_drv_unsupported_opt) << "-fopenmp"; - } - - return RT; -} - static void addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC, const ArgList &Args) { if (!Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, options::OPT_fno_openmp, false)) return; - switch (getOpenMPRuntime(TC, Args)) { - case OMPRT_OMP: + switch (TC.getDriver().getOpenMPRuntime(Args)) { + case Driver::OMPRT_OMP: CmdArgs.push_back("-lomp"); break; - case OMPRT_GOMP: + case Driver::OMPRT_GOMP: CmdArgs.push_back("-lgomp"); break; - case OMPRT_IOMP5: + case Driver::OMPRT_IOMP5: CmdArgs.push_back("-liomp5"); break; - case OMPRT_Unknown: + case Driver::OMPRT_Unknown: // Already diagnosed. break; } @@ -5188,9 +5139,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, options::OPT_fno_openmp, false) && JA.isDeviceOffloading(Action::OFK_None)) { - switch (getOpenMPRuntime(getToolChain(), Args)) { - case OMPRT_OMP: - case OMPRT_IOMP5: + switch (getToolChain().getDriver().getOpenMPRuntime(Args)) { + case Driver::OMPRT_OMP: + case Driver::OMPRT_IOMP5: // Clang can generate useful OpenMP code for these two runtime libraries. CmdArgs.push_back("-fopenmp"); @@ -9854,21 +9805,21 @@ void gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, WantPthread = true; // Also link the particular OpenMP runtimes. - switch (getOpenMPRuntime(ToolChain, Args)) { - case OMPRT_OMP: + switch (ToolChain.getDriver().getOpenMPRuntime(Args)) { + case Driver::OMPRT_OMP: CmdArgs.push_back("-lomp"); break; - case OMPRT_GOMP: + case Driver::OMPRT_GOMP: CmdArgs.push_back("-lgomp"); // FIXME: Exclude this for platforms with libgomp that don't require // librt. Most modern Linux platforms require it, but some may not. CmdArgs.push_back("-lrt"); break; - case OMPRT_IOMP5: + case Driver::OMPRT_IOMP5: CmdArgs.push_back("-liomp5"); break; - case OMPRT_Unknown: + case Driver::OMPRT_Unknown: // Already diagnosed. break; } @@ -10546,16 +10497,16 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-nodefaultlib:vcompd.lib"); CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + TC.getDriver().Dir + "/../lib")); - switch (getOpenMPRuntime(getToolChain(), Args)) { - case OMPRT_OMP: + switch (TC.getDriver().getOpenMPRuntime(Args)) { + case Driver::OMPRT_OMP: CmdArgs.push_back("-defaultlib:libomp.lib"); break; - case OMPRT_IOMP5: + case Driver::OMPRT_IOMP5: CmdArgs.push_back("-defaultlib:libiomp5md.lib"); break; - case OMPRT_GOMP: + case Driver::OMPRT_GOMP: break; - case OMPRT_Unknown: + case Driver::OMPRT_Unknown: // Already diagnosed. break; } |