David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 1 | //===--- AMDGPU.cpp - AMDGPU ToolChain Implementations ----------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "AMDGPU.h" |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 10 | #include "CommonArgs.h" |
Andrey Kasaurov | 6618c39 | 2017-09-05 10:24:38 +0000 | [diff] [blame] | 11 | #include "InputInfo.h" |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Compilation.h" |
Konstantin Zhuravlyov | 8914a6d | 2017-11-10 19:09:57 +0000 | [diff] [blame] | 13 | #include "clang/Driver/DriverDiagnostic.h" |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 14 | #include "llvm/Option/ArgList.h" |
| 15 | |
| 16 | using namespace clang::driver; |
| 17 | using namespace clang::driver::tools; |
| 18 | using namespace clang::driver::toolchains; |
| 19 | using namespace clang; |
| 20 | using namespace llvm::opt; |
| 21 | |
| 22 | void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA, |
| 23 | const InputInfo &Output, |
| 24 | const InputInfoList &Inputs, |
| 25 | const ArgList &Args, |
| 26 | const char *LinkingOutput) const { |
| 27 | |
| 28 | std::string Linker = getToolChain().GetProgramPath(getShortName()); |
| 29 | ArgStringList CmdArgs; |
| 30 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); |
| 31 | CmdArgs.push_back("-shared"); |
| 32 | CmdArgs.push_back("-o"); |
| 33 | CmdArgs.push_back(Output.getFilename()); |
Jonas Devlieghere | 2b3d49b | 2019-08-14 23:04:18 +0000 | [diff] [blame] | 34 | C.addCommand(std::make_unique<Command>(JA, *this, Args.MakeArgString(Linker), |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 35 | CmdArgs, Inputs)); |
| 36 | } |
| 37 | |
Konstantin Zhuravlyov | 8914a6d | 2017-11-10 19:09:57 +0000 | [diff] [blame] | 38 | void amdgpu::getAMDGPUTargetFeatures(const Driver &D, |
| 39 | const llvm::opt::ArgList &Args, |
| 40 | std::vector<StringRef> &Features) { |
Matt Arsenault | d91bb48 | 2019-02-21 21:31:43 +0000 | [diff] [blame] | 41 | if (const Arg *dAbi = Args.getLastArg(options::OPT_mamdgpu_debugger_abi)) |
| 42 | D.Diag(diag::err_drv_clang_unsupported) << dAbi->getAsString(Args); |
Konstantin Zhuravlyov | 8914a6d | 2017-11-10 19:09:57 +0000 | [diff] [blame] | 43 | |
Stanislav Mekhanoshin | 8a8131a | 2019-06-13 23:47:59 +0000 | [diff] [blame] | 44 | if (Args.getLastArg(options::OPT_mwavefrontsize64)) { |
| 45 | Features.push_back("-wavefrontsize16"); |
| 46 | Features.push_back("-wavefrontsize32"); |
| 47 | Features.push_back("+wavefrontsize64"); |
| 48 | } |
| 49 | if (Args.getLastArg(options::OPT_mno_wavefrontsize64)) { |
| 50 | Features.push_back("-wavefrontsize16"); |
| 51 | Features.push_back("+wavefrontsize32"); |
| 52 | Features.push_back("-wavefrontsize64"); |
| 53 | } |
| 54 | |
Konstantin Zhuravlyov | 8914a6d | 2017-11-10 19:09:57 +0000 | [diff] [blame] | 55 | handleTargetFeaturesGroup( |
| 56 | Args, Features, options::OPT_m_amdgpu_Features_Group); |
| 57 | } |
| 58 | |
Andrey Kasaurov | 099f633 | 2017-07-21 15:24:37 +0000 | [diff] [blame] | 59 | /// AMDGPU Toolchain |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 60 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, |
| 61 | const ArgList &Args) |
Andrey Kasaurov | 6618c39 | 2017-09-05 10:24:38 +0000 | [diff] [blame] | 62 | : Generic_ELF(D, Triple, Args), |
| 63 | OptionsDefault({{options::OPT_O, "3"}, |
| 64 | {options::OPT_cl_std_EQ, "CL1.2"}}) {} |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 65 | |
| 66 | Tool *AMDGPUToolChain::buildLinker() const { |
| 67 | return new tools::amdgpu::Linker(*this); |
| 68 | } |
Andrey Kasaurov | 6618c39 | 2017-09-05 10:24:38 +0000 | [diff] [blame] | 69 | |
| 70 | DerivedArgList * |
| 71 | AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch, |
| 72 | Action::OffloadKind DeviceOffloadKind) const { |
| 73 | |
| 74 | DerivedArgList *DAL = |
| 75 | Generic_ELF::TranslateArgs(Args, BoundArch, DeviceOffloadKind); |
| 76 | |
| 77 | // Do nothing if not OpenCL (-x cl) |
| 78 | if (!Args.getLastArgValue(options::OPT_x).equals("cl")) |
| 79 | return DAL; |
| 80 | |
| 81 | if (!DAL) |
| 82 | DAL = new DerivedArgList(Args.getBaseArgs()); |
| 83 | for (auto *A : Args) |
| 84 | DAL->append(A); |
| 85 | |
| 86 | const OptTable &Opts = getDriver().getOpts(); |
| 87 | |
| 88 | // Phase 1 (.cl -> .bc) |
| 89 | if (Args.hasArg(options::OPT_c) && Args.hasArg(options::OPT_emit_llvm)) { |
| 90 | DAL->AddFlagArg(nullptr, Opts.getOption(getTriple().isArch64Bit() |
| 91 | ? options::OPT_m64 |
| 92 | : options::OPT_m32)); |
| 93 | |
| 94 | // Have to check OPT_O4, OPT_O0 & OPT_Ofast separately |
| 95 | // as they defined that way in Options.td |
| 96 | if (!Args.hasArg(options::OPT_O, options::OPT_O0, options::OPT_O4, |
| 97 | options::OPT_Ofast)) |
| 98 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_O), |
| 99 | getOptionDefault(options::OPT_O)); |
| 100 | } |
| 101 | |
| 102 | return DAL; |
| 103 | } |
Matt Arsenault | cd5bc7b | 2018-08-30 08:18:06 +0000 | [diff] [blame] | 104 | |
| 105 | void AMDGPUToolChain::addClangTargetOptions( |
| 106 | const llvm::opt::ArgList &DriverArgs, |
| 107 | llvm::opt::ArgStringList &CC1Args, |
| 108 | Action::OffloadKind DeviceOffloadingKind) const { |
| 109 | // Default to "hidden" visibility, as object level linking will not be |
Raphael Isemann | b23ccec | 2018-12-10 12:37:46 +0000 | [diff] [blame] | 110 | // supported for the foreseeable future. |
Matt Arsenault | cd5bc7b | 2018-08-30 08:18:06 +0000 | [diff] [blame] | 111 | if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ, |
| 112 | options::OPT_fvisibility_ms_compat)) { |
| 113 | CC1Args.push_back("-fvisibility"); |
| 114 | CC1Args.push_back("hidden"); |
Scott Linder | bef2663 | 2019-01-28 17:12:19 +0000 | [diff] [blame] | 115 | CC1Args.push_back("-fapply-global-visibility-to-externs"); |
Matt Arsenault | cd5bc7b | 2018-08-30 08:18:06 +0000 | [diff] [blame] | 116 | } |
| 117 | } |