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());
72 LinkArgs.append({
"-o", TempFile});
73 const char *LlvmLink =
74 Args.MakeArgString(
getToolChain().GetProgramPath(
"llvm-link"));
76 LlvmLink, LinkArgs, Inputs, Output));
83 if (!PassPluginPath.empty()) {
84 const char *PassPathCStr =
C.getArgs().MakeArgString(PassPluginPath);
86 ArgStringList OptArgs{TempFile,
"-load-pass-plugin",
87 PassPathCStr,
"-passes=hip-post-link-passes",
89 const char *Opt = Args.MakeArgString(
getToolChain().GetProgramPath(
"opt"));
90 C.addCommand(std::make_unique<Command>(
97 llvm::opt::ArgStringList TrArgs{
"--spirv-max-version=1.1",
99 InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile,
"");
107 const char *LinkingOutput)
const {
108 if (Inputs.size() > 0 && Inputs[0].getType() == types::TY_Image &&
109 JA.
getType() == types::TY_Object)
113 if (JA.
getType() == types::TY_HIP_FATBIN)
117 constructLinkAndEmitSpirvCommand(
C, JA, Inputs, Output, Args);
129 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
131 HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
134 "Only HIP offloading kinds are supported for GPUs.");
137 {
"-fcuda-is-device",
"-fcuda-allow-variadic-functions",
141 "-mllvm",
"-vectorize-loops=false",
"-mllvm",
"-vectorize-slp=false"});
145 if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
146 options::OPT_fvisibility_ms_compat))
148 {
"-fvisibility=hidden",
"-fapply-global-visibility-to-externs"});
153 {
"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
162 HostTC.addClangWarningOptions(CC1Args);
167 return HostTC.GetCXXStdlibType(Args);
171 ArgStringList &CC1Args)
const {
172 HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
176 const ArgList &Args, ArgStringList &CC1Args)
const {
177 HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
181 ArgStringList &CC1Args)
const {
182 HostTC.AddIAMCUIncludeArgs(Args, CC1Args);
186 ArgStringList &CC1Args)
const {
187 if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
191 StringRef hipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
192 if (hipPath.empty()) {
197 llvm::sys::path::append(P,
"include");
198 CC1Args.append({
"-isystem", DriverArgs.MakeArgString(P)});
203 const llvm::opt::ArgList &DriverArgs,
206 if (!DriverArgs.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
210 ArgStringList LibraryPaths;
212 auto HipDeviceLibPathArgs = DriverArgs.getAllArgValues(
214 clang::driver::options::OPT_rocm_device_lib_path_EQ);
215 for (
auto Path : HipDeviceLibPathArgs)
216 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
218 StringRef HipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
219 if (!HipPath.empty()) {
221 llvm::sys::path::append(Path,
"lib",
"hip-device-lib");
222 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
228 auto BCLibArgs = DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ);
229 if (!BCLibArgs.empty()) {
231 for (StringRef BCName : BCLibArgs) {
233 for (std::string LibraryPath : LibraryPaths) {
235 llvm::sys::path::append(Path, BCName);
237 if (llvm::sys::fs::exists(FullName)) {
238 BCLibs.emplace_back(FullName.str());
249 std::string BCName =
"hipspv-" + TT +
".bc";
250 for (
auto *LibPath : LibraryPaths) {
252 llvm::sys::path::append(Path, BCName);
253 if (llvm::sys::fs::exists(Path)) {
254 BCLibs.emplace_back(Path.str().str());
259 << 1 << (
"'" + TT +
"' target");
276 return HostTC.getSupportedSanitizers();
280 const ArgList &Args)
const {
281 return HostTC.computeMSVCVersion(D, Args);
285 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
286 const llvm::opt::ArgList &Args)
const {
290 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.