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>(
93 llvm::opt::ArgStringList TrArgs;
95 bool HasNoSubArch = T.getSubArch() == llvm::Triple::NoSubArch;
96 if (T.getOS() == llvm::Triple::ChipStar) {
102 TrArgs.push_back(
"--spirv-max-version=1.2");
103 TrArgs.push_back(
"--spirv-ext=-all"
105 ",+SPV_INTEL_function_pointers"
107 ",+SPV_INTEL_subgroups");
110 TrArgs.push_back(
"--spirv-max-version=1.1");
111 TrArgs.push_back(
"--spirv-ext=+all");
114 InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile,
"");
122 const char *LinkingOutput)
const {
123 if (Inputs.size() > 0 && Inputs[0].getType() == types::TY_Image &&
124 JA.
getType() == types::TY_Object)
128 if (JA.
getType() == types::TY_HIP_FATBIN)
132 constructLinkAndEmitSpirvCommand(
C, JA, Inputs, Output, Args);
136 const ToolChain &HostTC,
const ArgList &Args)
137 :
ToolChain(D, Triple, Args), HostTC(&HostTC) {
140 getProgramPaths().push_back(getDriver().Dir);
149 getProgramPaths().push_back(getDriver().Dir);
153 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
158 "Need host toolchain for offloading!");
162 HostTC->addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
165 "Only HIP offloading kinds are supported for GPUs.");
172 "-mllvm",
"-vectorize-loops=false",
"-mllvm",
"-vectorize-slp=false"});
176 if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
177 options::OPT_fvisibility_ms_compat))
179 {
"-fvisibility=hidden",
"-fapply-global-visibility-to-externs"});
184 {
"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
194 HostTC->addClangWarningOptions(CC1Args);
201 return HostTC->GetCXXStdlibType(Args);
206 ArgStringList &CC1Args)
const {
208 HostTC->AddClangSystemIncludeArgs(DriverArgs, CC1Args);
213 const ArgList &Args, ArgStringList &CC1Args)
const {
215 HostTC->AddClangCXXStdlibIncludeArgs(Args, CC1Args);
220 ArgStringList &CC1Args)
const {
222 HostTC->AddIAMCUIncludeArgs(Args, CC1Args);
227 ArgStringList &CC1Args)
const {
228 if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
232 StringRef hipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
233 if (hipPath.empty()) {
234 getDriver().Diag(diag::err_drv_hipspv_no_hip_path);
238 llvm::sys::path::append(P,
"include");
239 CC1Args.append({
"-isystem", DriverArgs.MakeArgString(P)});
244 const llvm::opt::ArgList &DriverArgs,
247 if (!DriverArgs.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
251 ArgStringList LibraryPaths;
253 auto HipDeviceLibPathArgs = DriverArgs.getAllArgValues(
255 options::OPT_rocm_device_lib_path_EQ);
256 for (
auto Path : HipDeviceLibPathArgs)
257 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
259 StringRef HipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
260 if (!HipPath.empty()) {
262 llvm::sys::path::append(Path,
"lib",
"hip-device-lib");
263 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
269 auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
270 if (!BCLibArgs.empty()) {
272 for (StringRef BCName : BCLibArgs) {
274 for (std::string LibraryPath : LibraryPaths) {
276 llvm::sys::path::append(Path, BCName);
278 if (llvm::sys::fs::exists(FullName)) {
279 BCLibs.emplace_back(FullName.str());
285 getDriver().Diag(diag::err_drv_no_such_file) << BCName;
290 std::string BCName =
"hipspv-" + TT +
".bc";
291 for (
auto *LibPath : LibraryPaths) {
293 llvm::sys::path::append(Path, BCName);
294 if (llvm::sys::fs::exists(Path)) {
295 BCLibs.emplace_back(Path.str().str());
299 getDriver().Diag(diag::err_drv_no_hipspv_device_lib)
300 << 1 << (
"'" + TT +
"' target");
318 return HostTC->getSupportedSanitizers();
323 const ArgList &Args)
const {
325 return HostTC->computeMSVCVersion(D, Args);
330 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
331 const llvm::opt::ArgList &Args)
const {
335 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.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.