16#include "llvm/Support/FileSystem.h"
17#include "llvm/Support/Path.h"
27 const llvm::opt::ArgList &Args) {
28 StringRef Path = Args.getLastArgValue(options::OPT_hipspv_pass_plugin_EQ);
30 if (llvm::sys::fs::exists(Path))
32 D.
Diag(diag::err_drv_no_such_file) << Path;
35 StringRef hipPath = Args.getLastArgValue(options::OPT_hip_path_EQ);
36 if (!hipPath.empty()) {
38 llvm::sys::path::append(PluginPath,
"lib",
"libLLVMHipSpvPasses.so");
39 if (llvm::sys::fs::exists(PluginPath))
40 return PluginPath.str().str();
41 PluginPath.assign(hipPath);
42 llvm::sys::path::append(PluginPath,
"lib",
"llvm",
43 "libLLVMHipSpvPasses.so");
44 if (llvm::sys::fs::exists(PluginPath))
45 return PluginPath.str().str();
51void HIPSPV::Linker::constructLinkAndEmitSpirvCommand(
53 const InputInfo &Output,
const llvm::opt::ArgList &Args)
const {
55 assert(!Inputs.empty() &&
"Must have at least one input.");
56 std::string Name = std::string(llvm::sys::path::stem(Output.
getFilename()));
60 ArgStringList LinkArgs{};
62 for (
auto Input : Inputs)
63 LinkArgs.push_back(Input.getFilename());
80 if (!PassPluginPath.empty()) {
81 const char *PassPathCStr =
C.getArgs().MakeArgString(PassPluginPath);
83 ArgStringList OptArgs{TempFile,
"-load-pass-plugin",
84 PassPathCStr,
"-passes=hip-post-link-passes",
86 const char *Opt = Args.MakeArgString(
getToolChain().GetProgramPath(
"opt"));
87 C.addCommand(std::make_unique<Command>(
94 llvm::opt::ArgStringList TrArgs{
"--spirv-max-version=1.1",
96 InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile,
"");
104 const char *LinkingOutput)
const {
105 if (Inputs.size() > 0 && Inputs[0].getType() == types::TY_Image &&
106 JA.
getType() == types::TY_Object)
110 if (JA.
getType() == types::TY_HIP_FATBIN)
114 constructLinkAndEmitSpirvCommand(
C, JA, Inputs, Output, Args);
126 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
128 HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
131 "Only HIP offloading kinds are supported for GPUs.");
134 {
"-fcuda-is-device",
"-fcuda-allow-variadic-functions",
138 "-mllvm",
"-vectorize-loops=false",
"-mllvm",
"-vectorize-slp=false"});
142 if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
143 options::OPT_fvisibility_ms_compat))
145 {
"-fvisibility=hidden",
"-fapply-global-visibility-to-externs"});
150 {
"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
159 HostTC.addClangWarningOptions(CC1Args);
164 return HostTC.GetCXXStdlibType(Args);
168 ArgStringList &CC1Args)
const {
169 HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
173 const ArgList &Args, ArgStringList &CC1Args)
const {
174 HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
178 ArgStringList &CC1Args)
const {
179 HostTC.AddIAMCUIncludeArgs(Args, CC1Args);
183 ArgStringList &CC1Args)
const {
184 if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
188 StringRef hipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
189 if (hipPath.empty()) {
194 llvm::sys::path::append(P,
"include");
195 CC1Args.append({
"-isystem", DriverArgs.MakeArgString(P)});
200 const llvm::opt::ArgList &DriverArgs,
203 if (!DriverArgs.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
207 ArgStringList LibraryPaths;
209 auto HipDeviceLibPathArgs = DriverArgs.getAllArgValues(
211 options::OPT_rocm_device_lib_path_EQ);
212 for (
auto Path : HipDeviceLibPathArgs)
213 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
215 StringRef HipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
216 if (!HipPath.empty()) {
218 llvm::sys::path::append(Path,
"lib",
"hip-device-lib");
219 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
225 auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
226 if (!BCLibArgs.empty()) {
228 for (StringRef BCName : BCLibArgs) {
230 for (std::string LibraryPath : LibraryPaths) {
232 llvm::sys::path::append(Path, BCName);
234 if (llvm::sys::fs::exists(FullName)) {
235 BCLibs.emplace_back(FullName.str());
246 std::string BCName =
"hipspv-" + TT +
".bc";
247 for (
auto *LibPath : LibraryPaths) {
249 llvm::sys::path::append(Path, BCName);
250 if (llvm::sys::fs::exists(Path)) {
251 BCLibs.emplace_back(Path.str().str());
256 << 1 << (
"'" + TT +
"' target");
273 return HostTC.getSupportedSanitizers();
277 const ArgList &Args)
const {
278 return HostTC.computeMSVCVersion(D, Args);
282 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
283 const llvm::opt::ArgList &Args)
const {
287 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
static std::string findPassPlugin(const Driver &D, const llvm::opt::ArgList &Args)
types::ID getType() const
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
DiagnosticBuilder Diag(unsigned DiagID) const
SmallVector< InputInfo, 4 > InputInfoList
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.