1 //===--- AMDGPU.cpp - AMDGPU ToolChain Implementations ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "CommonArgs.h"
12 #include "InputInfo.h"
13 #include "clang/Driver/Compilation.h"
14 #include "clang/Driver/DriverDiagnostic.h"
15 #include "llvm/Option/ArgList.h"
17 using namespace clang::driver;
18 using namespace clang::driver::tools;
19 using namespace clang::driver::toolchains;
20 using namespace clang;
21 using namespace llvm::opt;
23 void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
24 const InputInfo &Output,
25 const InputInfoList &Inputs,
27 const char *LinkingOutput) const {
29 std::string Linker = getToolChain().GetProgramPath(getShortName());
30 ArgStringList CmdArgs;
31 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
32 CmdArgs.push_back("-shared");
33 CmdArgs.push_back("-o");
34 CmdArgs.push_back(Output.getFilename());
35 C.addCommand(llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker),
39 void amdgpu::getAMDGPUTargetFeatures(const Driver &D,
40 const llvm::opt::ArgList &Args,
41 std::vector<StringRef> &Features) {
42 if (const Arg *dAbi = Args.getLastArg(options::OPT_mamdgpu_debugger_abi)) {
43 StringRef value = dAbi->getValue();
45 Features.push_back("+amdgpu-debugger-insert-nops");
46 Features.push_back("+amdgpu-debugger-reserve-regs");
47 Features.push_back("+amdgpu-debugger-emit-prologue");
49 D.Diag(diag::err_drv_clang_unsupported) << dAbi->getAsString(Args);
53 handleTargetFeaturesGroup(
54 Args, Features, options::OPT_m_amdgpu_Features_Group);
58 AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
60 : Generic_ELF(D, Triple, Args),
61 OptionsDefault({{options::OPT_O, "3"},
62 {options::OPT_cl_std_EQ, "CL1.2"}}) {}
64 Tool *AMDGPUToolChain::buildLinker() const {
65 return new tools::amdgpu::Linker(*this);
69 AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
70 Action::OffloadKind DeviceOffloadKind) const {
73 Generic_ELF::TranslateArgs(Args, BoundArch, DeviceOffloadKind);
75 // Do nothing if not OpenCL (-x cl)
76 if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
80 DAL = new DerivedArgList(Args.getBaseArgs());
84 const OptTable &Opts = getDriver().getOpts();
86 // Phase 1 (.cl -> .bc)
87 if (Args.hasArg(options::OPT_c) && Args.hasArg(options::OPT_emit_llvm)) {
88 DAL->AddFlagArg(nullptr, Opts.getOption(getTriple().isArch64Bit()
92 // Have to check OPT_O4, OPT_O0 & OPT_Ofast separately
93 // as they defined that way in Options.td
94 if (!Args.hasArg(options::OPT_O, options::OPT_O0, options::OPT_O4,
96 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_O),
97 getOptionDefault(options::OPT_O));