clang  6.0.0svn
AMDGPU.cpp
Go to the documentation of this file.
1 //===--- AMDGPU.cpp - AMDGPU ToolChain Implementations ----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "AMDGPU.h"
11 #include "CommonArgs.h"
12 #include "InputInfo.h"
15 #include "llvm/Option/ArgList.h"
16 
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;
22 
24  const InputInfo &Output,
25  const InputInfoList &Inputs,
26  const ArgList &Args,
27  const char *LinkingOutput) const {
28 
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),
36  CmdArgs, Inputs));
37 }
38 
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();
44  if (value == "1.0") {
45  Features.push_back("+amdgpu-debugger-insert-nops");
46  Features.push_back("+amdgpu-debugger-reserve-regs");
47  Features.push_back("+amdgpu-debugger-emit-prologue");
48  } else {
49  D.Diag(diag::err_drv_clang_unsupported) << dAbi->getAsString(Args);
50  }
51  }
52 
54  Args, Features, options::OPT_m_amdgpu_Features_Group);
55 }
56 
57 /// AMDGPU Toolchain
58 AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
59  const ArgList &Args)
60  : Generic_ELF(D, Triple, Args),
61  OptionsDefault({{options::OPT_O, "3"},
62  {options::OPT_cl_std_EQ, "CL1.2"}}) {}
63 
65  return new tools::amdgpu::Linker(*this);
66 }
67 
68 DerivedArgList *
69 AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
70  Action::OffloadKind DeviceOffloadKind) const {
71 
72  DerivedArgList *DAL =
73  Generic_ELF::TranslateArgs(Args, BoundArch, DeviceOffloadKind);
74 
75  // Do nothing if not OpenCL (-x cl)
76  if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
77  return DAL;
78 
79  if (!DAL)
80  DAL = new DerivedArgList(Args.getBaseArgs());
81  for (auto *A : Args)
82  DAL->append(A);
83 
84  const OptTable &Opts = getDriver().getOpts();
85 
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()
89  ? options::OPT_m64
90  : options::OPT_m32));
91 
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,
95  options::OPT_Ofast))
96  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_O),
97  getOptionDefault(options::OPT_O));
98  }
99 
100  return DAL;
101 }
void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier Group)
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:116
Tool * buildLinker() const override
Definition: AMDGPU.cpp:64
const char * getFilename() const
Definition: InputInfo.h:84
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:23
llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: AMDGPU.cpp:69
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:65
void getAMDGPUTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features)
Definition: AMDGPU.cpp:39
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:189
const Driver & getDriver() const
Definition: ToolChain.h:167
Dataflow Directional Tag Classes.
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: AMDGPU.cpp:23
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
const StringRef getOptionDefault(options::ID OptID) const
Definition: AMDGPU.h:50
llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: Gnu.cpp:2327
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:34
const llvm::Triple & getTriple() const
Definition: ToolChain.h:169
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:280