clang 8.0.0

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"
13 #include "clang/Driver/Compilation.h"
14 #include "clang/Driver/DriverDiagnostic.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
23 void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
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
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();
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
52 handleTargetFeaturesGroup(
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
63 Tool *AMDGPUToolChain::buildLinker() const {
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 }
101
102 void AMDGPUToolChain::addClangTargetOptions(
103 const llvm::opt::ArgList &DriverArgs,
104 llvm::opt::ArgStringList &CC1Args,
105 Action::OffloadKind DeviceOffloadingKind) const {
106 // Default to "hidden" visibility, as object level linking will not be
107 // supported for the foreseeable future.
108 if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
109 options::OPT_fvisibility_ms_compat)) {
110 CC1Args.push_back("-fvisibility");
111 CC1Args.push_back("hidden");
112 }
113 }
clang::driver::tools::handleTargetFeaturesGroup
void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier Group)
clang::driver::Driver::Diag
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:109
clang::driver::toolchains::AMDGPUToolChain::buildLinker
Tool * buildLinker() const override
Definition: AMDGPU.cpp:63
clang::driver::tools::amdgpu::Linker
Definition: AMDGPU.h:24
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:84
CommonArgs.h
clang::driver::JobAction
Definition: Action.h:374
AMDGPU.h
clang::driver::tools
Definition: AMDGPU.h:21
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:23
clang::driver::toolchains::AMDGPUToolChain::TranslateArgs
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
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:58
clang::driver::tools::amdgpu::getAMDGPUTargetFeatures
void getAMDGPUTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features)
Definition: AMDGPU.cpp:39
clang::driver::toolchains::AMDGPUToolChain::addClangTargetOptions
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:102
Compilation.h
clang::driver::toolchains::Generic_ELF
Definition: Gnu.h:340
llvm::opt
Definition: Action.h:24
clang::driver::Compilation::addCommand
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:206
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:186
llvm::SmallVector
Definition: LLVM.h:36
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:83
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::driver::tools::amdgpu::Linker::ConstructJob
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
clang::driver::tools::AddLinkerInputs
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
clang::driver::toolchains::AMDGPUToolChain::getOptionDefault
const StringRef getOptionDefault(options::ID OptID) const
Definition: AMDGPU.h:50
InputInfo.h
clang::driver::toolchains::Generic_GCC::TranslateArgs
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:2589
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:46
clang::driver::ToolChain::getTriple
const llvm::Triple & getTriple() const
Definition: ToolChain.h:188
clang::driver
Definition: Action.h:32
DriverDiagnostic.h
clang::driver::toolchains
Definition: AMDGPU.h:41
clang::driver::Driver::getOpts
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:293