13#include "llvm/Support/Path.h"
20#if defined(_WIN32) || defined(_WIN64)
21#define NULL_FILE "nul"
23#define NULL_FILE "/dev/null"
27const unsigned HIPCodeObjectAlign = 4096;
33 llvm::Triple
T(OrigT);
39 if (HasTargetID &&
T.isAMDGCN()) {
40 return (
"amdgcn-" +
T.getVendorName() +
"-" +
T.getOSName() +
"-" +
41 T.getEnvironmentName())
45 return HasTargetID ? (
T.getArchName() +
"-" +
T.getVendorName() +
"-" +
46 T.getOSName() +
"-" +
T.getEnvironmentName())
48 :
T.normalize(llvm::Triple::CanonicalForm::FOUR_IDENT);
54 llvm::StringRef OutputFileName,
56 const llvm::opt::ArgList &Args,
60 ArgStringList BundlerArgs;
61 BundlerArgs.push_back(Args.MakeArgString(
"-type=o"));
62 BundlerArgs.push_back(
63 Args.MakeArgString(
"-bundle-align=" + Twine(HIPCodeObjectAlign)));
67 std::string BundlerTargetArg =
"-targets=host-x86_64-unknown-linux-gnu";
72 std::string OffloadKind =
"hip";
73 if (
T.getToolChain().getTriple().isAMDGCN() &&
75 OffloadKind = OffloadKind +
"v4";
76 for (
const auto &II : Inputs) {
77 const auto *A = II.getAction();
78 const llvm::Triple &InputTriple = A->getOffloadingToolChain()->getTriple();
81 BundlerTargetArg +=
',' + OffloadKind +
'-';
83 BundlerTargetArg +=
"spirv64-amd-amdhsa-";
87 BundlerTargetArg +=
'-' + BA.
ArchName.str();
89 BundlerArgs.push_back(Args.MakeArgString(BundlerTargetArg));
92 std::string BundlerInputArg =
"-input=" NULL_FILE;
93 BundlerArgs.push_back(Args.MakeArgString(BundlerInputArg));
94 for (
const auto &II : Inputs) {
95 BundlerInputArg = std::string(
"-input=") + II.getFilename();
96 BundlerArgs.push_back(Args.MakeArgString(BundlerInputArg));
99 std::string Output = std::string(OutputFileName);
100 auto *BundlerOutputArg =
101 Args.MakeArgString(std::string(
"-output=").append(Output));
102 BundlerArgs.push_back(BundlerOutputArg);
106 const char *Bundler = Args.MakeArgString(
107 T.getToolChain().GetProgramPath(
"clang-offload-bundler"));
108 C.addCommand(std::make_unique<Command>(
110 InputInfo(&JA, Args.MakeArgString(Output))));
116 StringRef Extension) {
117 if (
C.getDriver().isSaveTempsEnabled()) {
118 return C.getArgs().MakeArgString(Prefix +
"." + Extension);
120 auto TmpFile =
C.getDriver().GetTemporaryPath(Prefix, Extension);
121 return C.addTempFile(
C.getArgs().MakeArgString(TmpFile));
static std::string normalizeForBundler(const llvm::Triple &OrigT, StringRef BoundArch)
Compilation - A set of tasks to perform for a single driver invocation.
SmallVector< InputInfo, 4 > InputInfoList
Top level wrappers for InstallAPI frontend operations.
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.