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 if (Input.isFilename())
64 LinkArgs.push_back(Input.getFilename());
81 if (!PassPluginPath.empty()) {
82 const char *PassPathCStr =
C.getArgs().MakeArgString(PassPluginPath);
84 ArgStringList OptArgs{TempFile,
"-load-pass-plugin",
85 PassPathCStr,
"-passes=hip-post-link-passes",
87 const char *Opt = Args.MakeArgString(
getToolChain().GetProgramPath(
"opt"));
88 C.addCommand(std::make_unique<Command>(
94 llvm::opt::ArgStringList TrArgs;
96 bool HasNoSubArch = T.getSubArch() == llvm::Triple::NoSubArch;
97 if (T.getOS() == llvm::Triple::ChipStar) {
103 TrArgs.push_back(
"--spirv-max-version=1.2");
104 TrArgs.push_back(
"--spirv-ext=-all"
106 ",+SPV_INTEL_function_pointers"
108 ",+SPV_INTEL_subgroups");
111 TrArgs.push_back(
"--spirv-max-version=1.1");
112 TrArgs.push_back(
"--spirv-ext=+all");
115 InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile,
"");
123 const char *LinkingOutput)
const {
124 if (Inputs.size() > 0 && Inputs[0].getType() == types::TY_Image &&
125 JA.
getType() == types::TY_Object)
129 if (JA.
getType() == types::TY_HIP_FATBIN)
133 constructLinkAndEmitSpirvCommand(
C, JA, Inputs, Output, Args);
137 const ToolChain &HostTC,
const ArgList &Args)
138 :
ToolChain(D, Triple, Args), HostTC(&HostTC) {
141 getProgramPaths().push_back(getDriver().Dir);
150 getProgramPaths().push_back(getDriver().Dir);
154 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
159 "Need host toolchain for offloading!");
163 HostTC->addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
166 "Only HIP offloading kinds are supported for GPUs.");
173 "-mllvm",
"-vectorize-loops=false",
"-mllvm",
"-vectorize-slp=false"});
177 if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
178 options::OPT_fvisibility_ms_compat))
180 {
"-fvisibility=hidden",
"-fapply-global-visibility-to-externs"});
185 {
"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
195 HostTC->addClangWarningOptions(CC1Args);
202 return HostTC->GetCXXStdlibType(Args);
207 ArgStringList &CC1Args)
const {
209 HostTC->AddClangSystemIncludeArgs(DriverArgs, CC1Args);
214 const ArgList &Args, ArgStringList &CC1Args)
const {
216 HostTC->AddClangCXXStdlibIncludeArgs(Args, CC1Args);
221 ArgStringList &CC1Args)
const {
223 HostTC->AddIAMCUIncludeArgs(Args, CC1Args);
228 ArgStringList &CC1Args)
const {
229 if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
233 StringRef hipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
234 if (hipPath.empty()) {
235 getDriver().Diag(diag::err_drv_hipspv_no_hip_path);
239 llvm::sys::path::append(P,
"include");
240 CC1Args.append({
"-isystem", DriverArgs.MakeArgString(P)});
245 const llvm::opt::ArgList &DriverArgs,
248 if (!DriverArgs.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
252 ArgStringList LibraryPaths;
254 auto HipDeviceLibPathArgs = DriverArgs.getAllArgValues(
256 options::OPT_rocm_device_lib_path_EQ);
257 for (
auto Path : HipDeviceLibPathArgs)
258 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
260 StringRef HipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
261 if (!HipPath.empty()) {
263 llvm::sys::path::append(Path,
"lib",
"hip-device-lib");
264 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
270 auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
271 if (!BCLibArgs.empty()) {
273 for (StringRef BCName : BCLibArgs) {
275 for (std::string LibraryPath : LibraryPaths) {
277 llvm::sys::path::append(Path, BCName);
279 if (llvm::sys::fs::exists(FullName)) {
280 BCLibs.emplace_back(FullName.str());
286 getDriver().Diag(diag::err_drv_no_such_file) << BCName;
291 std::string BCName =
"hipspv-" + TT +
".bc";
292 for (
auto *LibPath : LibraryPaths) {
294 llvm::sys::path::append(Path, BCName);
295 if (llvm::sys::fs::exists(Path)) {
296 BCLibs.emplace_back(Path.str().str());
300 getDriver().Diag(diag::err_drv_no_hipspv_device_lib)
301 << 1 << (
"'" + TT +
"' target");
319 return HostTC->getSupportedSanitizers();
324 const ArgList &Args)
const {
326 return HostTC->computeMSVCVersion(D, Args);
331 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
332 const llvm::opt::ArgList &Args)
const {
336 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
static std::string findPassPlugin(const Driver &D, const llvm::opt::ArgList &Args)
static StringRef getTriple(const Command &Job)
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.