14#include "llvm/Support/Path.h"
21#if defined(_WIN32) || defined(_WIN64)
22#define NULL_FILE "nul"
24#define NULL_FILE "/dev/null"
28const unsigned HIPCodeObjectAlign = 4096;
34 llvm::StringRef OutputFileName,
36 const llvm::opt::ArgList &Args,
40 ArgStringList BundlerArgs;
41 BundlerArgs.push_back(Args.MakeArgString(
"-type=o"));
42 BundlerArgs.push_back(
43 Args.MakeArgString(
"-bundle-align=" + Twine(HIPCodeObjectAlign)));
47 std::string BundlerTargetArg =
"-targets=host-x86_64-unknown-linux-gnu";
52 std::string OffloadKind =
"hip";
53 if (
T.getToolChain().getTriple().isAMDGCN() &&
55 OffloadKind = OffloadKind +
"v4";
56 for (
const auto &II : Inputs) {
57 const auto *A = II.getAction();
58 const llvm::Triple &InputTriple = A->getOffloadingToolChain()->getTriple();
61 BundlerTargetArg +=
',' + OffloadKind +
'-';
63 BundlerTargetArg +=
"spirv64-amd-amdhsa-";
67 BundlerTargetArg +=
'-' + BA.
ArchName.str();
69 BundlerArgs.push_back(Args.MakeArgString(BundlerTargetArg));
72 std::string BundlerInputArg =
"-input=" NULL_FILE;
73 BundlerArgs.push_back(Args.MakeArgString(BundlerInputArg));
74 for (
const auto &II : Inputs) {
75 BundlerInputArg = std::string(
"-input=") + II.getFilename();
76 BundlerArgs.push_back(Args.MakeArgString(BundlerInputArg));
79 std::string Output = std::string(OutputFileName);
80 auto *BundlerOutputArg =
81 Args.MakeArgString(std::string(
"-output=").append(Output));
82 BundlerArgs.push_back(BundlerOutputArg);
86 const char *Bundler = Args.MakeArgString(
87 T.getToolChain().GetProgramPath(
"clang-offload-bundler"));
88 C.addCommand(std::make_unique<Command>(
90 InputInfo(&JA, Args.MakeArgString(Output))));
96 StringRef Extension) {
97 if (
C.getDriver().isSaveTempsEnabled()) {
98 return C.getArgs().MakeArgString(Prefix +
"." + Extension);
100 auto TmpFile =
C.getDriver().GetTemporaryPath(Prefix, Extension);
101 return C.addTempFile(
C.getArgs().MakeArgString(TmpFile));
Compilation - A set of tasks to perform for a single driver invocation.
SmallVector< InputInfo, 4 > InputInfoList
Top level wrappers for InstallAPI frontend operations.
std::string normalizeForBundler(const llvm::Triple &T, llvm::StringRef BoundArch)
Constructs the normalized triple string used inside an offload bundle entry ID for device triple T.
const FunctionProtoType * T
Represents a bound architecture for offload / multiple architecture compilation.
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.