clang  9.0.0svn
AMDGPU.cpp
Go to the documentation of this file.
1 //===--- AMDGPU.cpp - AMDGPU ToolChain Implementations ----------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "AMDGPU.h"
10 #include "CommonArgs.h"
11 #include "InputInfo.h"
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 
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());
34  C.addCommand(llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker),
35  CmdArgs, Inputs));
36 }
37 
39  const llvm::opt::ArgList &Args,
40  std::vector<StringRef> &Features) {
41  if (const Arg *dAbi = Args.getLastArg(options::OPT_mamdgpu_debugger_abi))
42  D.Diag(diag::err_drv_clang_unsupported) << dAbi->getAsString(Args);
43 
45  Args, Features, options::OPT_m_amdgpu_Features_Group);
46 }
47 
48 /// AMDGPU Toolchain
49 AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
50  const ArgList &Args)
51  : Generic_ELF(D, Triple, Args),
52  OptionsDefault({{options::OPT_O, "3"},
53  {options::OPT_cl_std_EQ, "CL1.2"}}) {}
54 
56  return new tools::amdgpu::Linker(*this);
57 }
58 
59 DerivedArgList *
60 AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
61  Action::OffloadKind DeviceOffloadKind) const {
62 
63  DerivedArgList *DAL =
64  Generic_ELF::TranslateArgs(Args, BoundArch, DeviceOffloadKind);
65 
66  // Do nothing if not OpenCL (-x cl)
67  if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
68  return DAL;
69 
70  if (!DAL)
71  DAL = new DerivedArgList(Args.getBaseArgs());
72  for (auto *A : Args)
73  DAL->append(A);
74 
75  const OptTable &Opts = getDriver().getOpts();
76 
77  // Phase 1 (.cl -> .bc)
78  if (Args.hasArg(options::OPT_c) && Args.hasArg(options::OPT_emit_llvm)) {
79  DAL->AddFlagArg(nullptr, Opts.getOption(getTriple().isArch64Bit()
80  ? options::OPT_m64
81  : options::OPT_m32));
82 
83  // Have to check OPT_O4, OPT_O0 & OPT_Ofast separately
84  // as they defined that way in Options.td
85  if (!Args.hasArg(options::OPT_O, options::OPT_O0, options::OPT_O4,
86  options::OPT_Ofast))
87  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_O),
88  getOptionDefault(options::OPT_O));
89  }
90 
91  return DAL;
92 }
93 
95  const llvm::opt::ArgList &DriverArgs,
96  llvm::opt::ArgStringList &CC1Args,
97  Action::OffloadKind DeviceOffloadingKind) const {
98  // Default to "hidden" visibility, as object level linking will not be
99  // supported for the foreseeable future.
100  if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
101  options::OPT_fvisibility_ms_compat)) {
102  CC1Args.push_back("-fvisibility");
103  CC1Args.push_back("hidden");
104  CC1Args.push_back("-fapply-global-visibility-to-externs");
105  }
106 }
void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier Group)
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:108
Tool * buildLinker() const override
Definition: AMDGPU.cpp:55
const char * getFilename() const
Definition: InputInfo.h:83
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
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:60
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:57
void getAMDGPUTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features)
Definition: AMDGPU.cpp:38
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: AMDGPU.cpp:94
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:205
const Driver & getDriver() const
Definition: ToolChain.h:193
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:22
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:33
const StringRef getOptionDefault(options::ID OptID) const
Definition: AMDGPU.h:49
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:2667
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
const llvm::Triple & getTriple() const
Definition: ToolChain.h:195
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:298