clang  7.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-emit-prologue");
47  } else {
48  D.Diag(diag::err_drv_clang_unsupported) << dAbi->getAsString(Args);
49  }
50  }
51 
53  Args, Features, options::OPT_m_amdgpu_Features_Group);
54 }
55 
56 /// AMDGPU Toolchain
57 AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
58  const ArgList &Args)
59  : Generic_ELF(D, Triple, Args),
60  OptionsDefault({{options::OPT_O, "3"},
61  {options::OPT_cl_std_EQ, "CL1.2"}}) {}
62 
64  return new tools::amdgpu::Linker(*this);
65 }
66 
67 DerivedArgList *
68 AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
69  Action::OffloadKind DeviceOffloadKind) const {
70 
71  DerivedArgList *DAL =
72  Generic_ELF::TranslateArgs(Args, BoundArch, DeviceOffloadKind);
73 
74  // Do nothing if not OpenCL (-x cl)
75  if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
76  return DAL;
77 
78  if (!DAL)
79  DAL = new DerivedArgList(Args.getBaseArgs());
80  for (auto *A : Args)
81  DAL->append(A);
82 
83  const OptTable &Opts = getDriver().getOpts();
84 
85  // Phase 1 (.cl -> .bc)
86  if (Args.hasArg(options::OPT_c) && Args.hasArg(options::OPT_emit_llvm)) {
87  DAL->AddFlagArg(nullptr, Opts.getOption(getTriple().isArch64Bit()
88  ? options::OPT_m64
89  : options::OPT_m32));
90 
91  // Have to check OPT_O4, OPT_O0 & OPT_Ofast separately
92  // as they defined that way in Options.td
93  if (!Args.hasArg(options::OPT_O, options::OPT_O0, options::OPT_O4,
94  options::OPT_Ofast))
95  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_O),
96  getOptionDefault(options::OPT_O));
97  }
98 
99  return DAL;
100 }
void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier Group)
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:110
Tool * buildLinker() const override
Definition: AMDGPU.cpp:63
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:68
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
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:206
const Driver & getDriver() const
Definition: ToolChain.h:181
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:2499
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:46
const llvm::Triple & getTriple() const
Definition: ToolChain.h:183
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:297