16#include "llvm/MC/TargetRegistry.h"
17#include "llvm/Support/FileSystem.h"
18#include "llvm/Support/Path.h"
28 const llvm::opt::ArgList &Args) {
29 StringRef Path = Args.getLastArgValue(options::OPT_hipspv_pass_plugin_EQ);
31 if (llvm::sys::fs::exists(Path))
33 D.
Diag(diag::err_drv_no_such_file) << Path;
36 StringRef hipPath = Args.getLastArgValue(options::OPT_hip_path_EQ);
37 if (!hipPath.empty()) {
39 llvm::sys::path::append(PluginPath,
"lib",
"libLLVMHipSpvPasses.so");
40 if (llvm::sys::fs::exists(PluginPath))
41 return PluginPath.str().str();
42 PluginPath.assign(hipPath);
43 llvm::sys::path::append(PluginPath,
"lib",
"llvm",
44 "libLLVMHipSpvPasses.so");
45 if (llvm::sys::fs::exists(PluginPath))
46 return PluginPath.str().str();
54 std::string IgnoredError;
55 return llvm::TargetRegistry::lookupTarget(
T, IgnoredError);
64 const llvm::opt::ArgList &Args,
65 StringRef Name,
const char *TempFile) {
67 if (PassPluginPath.empty())
69 const char *PassPathCStr =
C.getArgs().MakeArgString(PassPluginPath);
71 ArgStringList OptArgs{TempFile,
"-load-pass-plugin",
72 PassPathCStr,
"-passes=hip-post-link-passes",
75 C.addCommand(std::make_unique<Command>(
80void HIPSPV::Linker::constructLinkAndEmitSpirvCommand(
82 const InputInfo &Output,
const llvm::opt::ArgList &Args)
const {
84 assert(!Inputs.empty() &&
"Must have at least one input.");
85 std::string Name = std::string(llvm::sys::path::stem(Output.
getFilename()));
89 ArgStringList LinkArgs{};
91 for (
auto Input : Inputs)
92 if (Input.isFilename())
93 LinkArgs.push_back(Input.getFilename());
100 if (
T.getOS() == llvm::Triple::ChipStar) {
108 Args, Name, TempFile);
114 llvm::opt::ArgStringList TrArgs;
115 if (
T.getSubArch() == llvm::Triple::NoSubArch)
116 TrArgs.push_back(
"--spirv-max-version=1.2");
119 TrArgs.push_back(
"--spirv-ext=-all"
120 ",+SPV_INTEL_function_pointers"
121 ",+SPV_INTEL_subgroups"
122 ",+SPV_KHR_bit_instructions"
123 ",+SPV_EXT_shader_atomic_float_add");
135 TrArgs.push_back(
"--spirv-ext=+SPV_KHR_non_semantic_info"
136 ",+SPV_INTEL_optnone");
137 TrArgs.push_back(
"--spirv-debug-info-version=nonsemantic-shader-200");
139 InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile,
"");
153 ArgStringList Cc1Args;
154 Cc1Args.push_back(
"-cc1");
155 Cc1Args.push_back(
"-triple");
156 Cc1Args.push_back(
C.getArgs().MakeArgString(
T.getTriple()));
157 Cc1Args.push_back(
"-emit-obj");
164 Cc1Args.push_back(
"-mllvm");
165 Cc1Args.push_back(
"-spirv-ext=+SPV_INTEL_function_pointers"
166 ",+SPV_INTEL_subgroups"
167 ",+SPV_KHR_bit_instructions"
168 ",+SPV_EXT_shader_atomic_float_add"
169 ",+SPV_KHR_non_semantic_info"
170 ",+SPV_INTEL_optnone");
172 Cc1Args.push_back(TempFile);
173 Cc1Args.push_back(
"-o");
176 const Driver &Drv =
C.getDriver();
178 C.addCommand(std::make_unique<Command>(
189 llvm::opt::ArgStringList TrArgs;
190 if (
T.getSubArch() == llvm::Triple::NoSubArch)
191 TrArgs.push_back(
"--spirv-max-version=1.1");
192 TrArgs.push_back(
"--spirv-ext=+all");
212 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group);
213 A && !A->getOption().matches(options::OPT_g0)) {
214 TrArgs.push_back(
"--spirv-ext=+SPV_KHR_non_semantic_info"
215 ",+SPV_INTEL_optnone");
216 TrArgs.push_back(
"--spirv-debug-info-version=nonsemantic-shader-200");
219 InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile,
"");
227 const char *LinkingOutput)
const {
228 if (JA.
getType() == types::TY_HIP_FATBIN)
232 constructLinkAndEmitSpirvCommand(
C, JA, Inputs, Output, Args);
236 const ToolChain &HostTC,
const ArgList &Args)
237 :
ToolChain(D, Triple, Args), HostTC(&HostTC) {
240 getProgramPaths().push_back(getDriver().Dir);
249 getProgramPaths().push_back(getDriver().Dir);
258 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
263 "Need host toolchain for offloading!");
267 HostTC->addClangTargetOptions(DriverArgs, CC1Args, BA, DeviceOffloadingKind);
270 "Only HIP offloading kinds are supported for GPUs.");
277 "-mllvm",
"-vectorize-loops=false",
"-mllvm",
"-vectorize-slp=false"});
281 if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
282 options::OPT_fvisibility_ms_compat))
284 {
"-fvisibility=hidden",
"-fapply-global-visibility-to-externs"});
289 {
"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
299 HostTC->addClangWarningOptions(CC1Args);
306 return HostTC->GetCXXStdlibType(Args);
311 ArgStringList &CC1Args)
const {
313 HostTC->AddClangSystemIncludeArgs(DriverArgs, CC1Args);
318 const ArgList &Args, ArgStringList &CC1Args)
const {
320 HostTC->AddClangCXXStdlibIncludeArgs(Args, CC1Args);
325 ArgStringList &CC1Args)
const {
327 HostTC->AddIAMCUIncludeArgs(Args, CC1Args);
332 ArgStringList &CC1Args)
const {
333 if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
337 StringRef hipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
338 if (hipPath.empty()) {
339 getDriver().Diag(diag::err_drv_hipspv_no_hip_path);
343 llvm::sys::path::append(P,
"include");
344 CC1Args.append({
"-isystem", DriverArgs.MakeArgString(P)});
349 const llvm::opt::ArgList &DriverArgs,
BoundArch BA,
352 if (!DriverArgs.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
356 ArgStringList LibraryPaths;
358 auto HipDeviceLibPathArgs = DriverArgs.getAllArgValues(
360 options::OPT_rocm_device_lib_path_EQ);
361 for (
auto Path : HipDeviceLibPathArgs)
362 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
364 StringRef HipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
365 if (!HipPath.empty()) {
367 llvm::sys::path::append(Path,
"lib",
"hip-device-lib");
368 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
374 auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
375 if (!BCLibArgs.empty()) {
377 for (StringRef BCName : BCLibArgs) {
379 for (std::string LibraryPath : LibraryPaths) {
381 llvm::sys::path::append(Path, BCName);
383 if (llvm::sys::fs::exists(FullName)) {
384 BCLibs.emplace_back(FullName.str());
390 getDriver().Diag(diag::err_drv_no_such_file) << BCName;
395 std::string BCName =
"hipspv-" + TT +
".bc";
396 for (
auto *LibPath : LibraryPaths) {
398 llvm::sys::path::append(Path, BCName);
399 if (llvm::sys::fs::exists(Path)) {
400 BCLibs.emplace_back(Path.str().str());
404 getDriver().Diag(diag::err_drv_no_hipspv_device_lib)
405 << 1 << (
"'" + TT +
"' target");
426 return HostTC->getSupportedSanitizers(BA, DeviceOffloadKind);
431 const ArgList &Args)
const {
433 return HostTC->computeMSVCVersion(D, Args);
438 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
439 const llvm::opt::ArgList &Args)
const {
static std::string findPassPlugin(const Driver &D, const llvm::opt::ArgList &Args)
static const char * runHipSpvPasses(Compilation &C, const JobAction &JA, const Tool &Creator, const ToolChain &TC, const InputInfoList &Inputs, const InputInfo &Output, const llvm::opt::ArgList &Args, StringRef Name, const char *TempFile)
static bool isSPIRVBackendAvailable(const llvm::Triple &T)
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...
const char * getPrependArg() const
DiagnosticBuilder Diag(unsigned DiagID) const
const char * getDriverProgramPath() const
Get the path to the main driver executable.
SmallVector< InputInfo, 4 > InputInfoList
Top level wrappers for InstallAPI frontend operations.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
const FunctionProtoType * T
bool(*)(llvm::ArrayRef< const char * >, llvm::raw_ostream &, llvm::raw_ostream &, bool, bool) Driver
Represents a bound architecture for offload / multiple architecture compilation.
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.