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());
107 if (
T.getOS() == llvm::Triple::ChipStar) {
115 Args, Name, TempFile);
121 llvm::opt::ArgStringList TrArgs;
122 if (
T.getSubArch() == llvm::Triple::NoSubArch)
123 TrArgs.push_back(
"--spirv-max-version=1.2");
126 TrArgs.push_back(
"--spirv-ext=-all"
127 ",+SPV_INTEL_function_pointers"
128 ",+SPV_INTEL_subgroups"
129 ",+SPV_KHR_bit_instructions"
130 ",+SPV_EXT_shader_atomic_float_add");
142 TrArgs.push_back(
"--spirv-ext=+SPV_KHR_non_semantic_info"
143 ",+SPV_INTEL_optnone");
144 TrArgs.push_back(
"--spirv-debug-info-version=nonsemantic-shader-200");
146 InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile,
"");
160 ArgStringList Cc1Args;
161 Cc1Args.push_back(
"-cc1");
162 Cc1Args.push_back(
"-triple");
163 Cc1Args.push_back(
C.getArgs().MakeArgString(
T.getTriple()));
164 Cc1Args.push_back(
"-emit-obj");
171 Cc1Args.push_back(
"-mllvm");
172 Cc1Args.push_back(
"-spirv-ext=+SPV_INTEL_function_pointers"
173 ",+SPV_INTEL_subgroups"
174 ",+SPV_KHR_bit_instructions"
175 ",+SPV_EXT_shader_atomic_float_add"
176 ",+SPV_KHR_non_semantic_info"
177 ",+SPV_INTEL_optnone");
179 Cc1Args.push_back(TempFile);
180 Cc1Args.push_back(
"-o");
183 const Driver &Drv =
C.getDriver();
185 C.addCommand(std::make_unique<Command>(
196 llvm::opt::ArgStringList TrArgs;
197 if (
T.getSubArch() == llvm::Triple::NoSubArch)
198 TrArgs.push_back(
"--spirv-max-version=1.1");
199 TrArgs.push_back(
"--spirv-ext=+all");
219 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group);
220 A && !A->getOption().matches(options::OPT_g0)) {
221 TrArgs.push_back(
"--spirv-ext=+SPV_KHR_non_semantic_info"
222 ",+SPV_INTEL_optnone");
223 TrArgs.push_back(
"--spirv-debug-info-version=nonsemantic-shader-200");
226 InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile,
"");
234 const char *LinkingOutput)
const {
235 if (Inputs.size() > 0 && Inputs[0].getType() == types::TY_Image &&
236 JA.
getType() == types::TY_Object)
240 if (JA.
getType() == types::TY_HIP_FATBIN)
244 constructLinkAndEmitSpirvCommand(
C, JA, Inputs, Output, Args);
248 const ToolChain &HostTC,
const ArgList &Args)
249 :
ToolChain(D, Triple, Args), HostTC(&HostTC) {
252 getProgramPaths().push_back(getDriver().Dir);
261 getProgramPaths().push_back(getDriver().Dir);
270 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
275 "Need host toolchain for offloading!");
279 HostTC->addClangTargetOptions(DriverArgs, CC1Args, BA, DeviceOffloadingKind);
282 "Only HIP offloading kinds are supported for GPUs.");
289 "-mllvm",
"-vectorize-loops=false",
"-mllvm",
"-vectorize-slp=false"});
293 if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
294 options::OPT_fvisibility_ms_compat))
296 {
"-fvisibility=hidden",
"-fapply-global-visibility-to-externs"});
301 {
"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
311 HostTC->addClangWarningOptions(CC1Args);
318 return HostTC->GetCXXStdlibType(Args);
323 ArgStringList &CC1Args)
const {
325 HostTC->AddClangSystemIncludeArgs(DriverArgs, CC1Args);
330 const ArgList &Args, ArgStringList &CC1Args)
const {
332 HostTC->AddClangCXXStdlibIncludeArgs(Args, CC1Args);
337 ArgStringList &CC1Args)
const {
339 HostTC->AddIAMCUIncludeArgs(Args, CC1Args);
344 ArgStringList &CC1Args)
const {
345 if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
349 StringRef hipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
350 if (hipPath.empty()) {
351 getDriver().Diag(diag::err_drv_hipspv_no_hip_path);
355 llvm::sys::path::append(P,
"include");
356 CC1Args.append({
"-isystem", DriverArgs.MakeArgString(P)});
361 const llvm::opt::ArgList &DriverArgs,
BoundArch BA,
364 if (!DriverArgs.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
368 ArgStringList LibraryPaths;
370 auto HipDeviceLibPathArgs = DriverArgs.getAllArgValues(
372 options::OPT_rocm_device_lib_path_EQ);
373 for (
auto Path : HipDeviceLibPathArgs)
374 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
376 StringRef HipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
377 if (!HipPath.empty()) {
379 llvm::sys::path::append(Path,
"lib",
"hip-device-lib");
380 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
386 auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
387 if (!BCLibArgs.empty()) {
389 for (StringRef BCName : BCLibArgs) {
391 for (std::string LibraryPath : LibraryPaths) {
393 llvm::sys::path::append(Path, BCName);
395 if (llvm::sys::fs::exists(FullName)) {
396 BCLibs.emplace_back(FullName.str());
402 getDriver().Diag(diag::err_drv_no_such_file) << BCName;
407 std::string BCName =
"hipspv-" + TT +
".bc";
408 for (
auto *LibPath : LibraryPaths) {
410 llvm::sys::path::append(Path, BCName);
411 if (llvm::sys::fs::exists(Path)) {
412 BCLibs.emplace_back(Path.str().str());
416 getDriver().Diag(diag::err_drv_no_hipspv_device_lib)
417 << 1 << (
"'" + TT +
"' target");
438 return HostTC->getSupportedSanitizers(BA, DeviceOffloadKind);
443 const ArgList &Args)
const {
445 return HostTC->computeMSVCVersion(D, Args);
450 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
451 const llvm::opt::ArgList &Args)
const {
468 if (!Args.hasFlag(options::OPT_offload_new_driver,
469 options::OPT_no_offload_new_driver,
true))
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.
LTOKind
Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
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',...
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.