Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10366,12 +10366,14 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
const toolchains::SYCLToolChain &SYCLTC =
static_cast<const toolchains::SYCLToolChain &>(*TC);


SYCLTC.AddImpliedTargetArgs(TC->getTriple(), Args, BuildArgs, JA, *HostTC,
Arch);
SYCLTC.TranslateBackendTargetArgs(TC->getTriple(), Args, BuildArgs);
SYCLTC.TranslateBackendTargetArgs(TC->getTriple(), Args, BuildArgs, OffloadAction->getOffloadingArch());
createArgString("compile-opts=");
BuildArgs.clear();
SYCLTC.TranslateLinkerTargetArgs(TC->getTriple(), Args, BuildArgs);
SYCLTC.TranslateLinkerTargetArgs(TC->getTriple(), Args, BuildArgs, OffloadAction->getOffloadingArch());
createArgString("link-opts=");
}

Expand Down Expand Up @@ -11530,27 +11532,38 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
if (!TC->getTriple().isSPIROrSPIRV())
continue;
ArgStringList BuildArgs;
SmallString<128> BackendOptString;
SmallVector<SmallString<128>, 4> BackendOptStrings;
SmallString<128> LinkOptString;
SYCLTC.TranslateBackendTargetArgs(TC->getTriple(), Args, BuildArgs);
for (const auto &A : BuildArgs)
appendOption(BackendOptString, A);

BuildArgs.clear();
// Process each -Xsycl-target-backend individually
for (const Arg *A : Args.filtered(options::OPT_Xsycl_backend_EQ)) {
StringRef Device = SYCL::gen::resolveGenDevice(A->getValue(0));
SmallString<128> BackendString;

SYCLTC.TranslateBackendTargetArgs(TC->getTriple(), Args, BuildArgs, Device);
for (const auto &BA : BuildArgs) {
appendOption(BackendString, BA);
}

BuildArgs.clear();
BackendOptStrings.push_back(std::move(BackendString));
}

SYCLTC.TranslateLinkerTargetArgs(TC->getTriple(), Args, BuildArgs);
for (const auto &A : BuildArgs) {
if (TC->getTriple().getSubArch() == llvm::Triple::NoSubArch)
appendOption(LinkOptString, A);
else
// For AOT, combine the Backend and Linker strings into one.
appendOption(BackendOptString, A);
// For AOT, append linker args to every backend string
for (auto &BOS : BackendOptStrings)
appendOption(BOS, A);
}

if (!BackendOptString.empty()) {
CmdArgs.push_back(Args.MakeArgString(
for (auto &BOS : BackendOptStrings) {
CmdArgs.push_back(Args.MakeArgString(
"--device-compiler=" +
Action::GetOffloadKindName(Action::OFK_SYCL) + ":" +
TC->getTripleString() + "=" + BackendOptString));
TC->getTripleString() + "=" + BOS));
}
if (!LinkOptString.empty()) {
CmdArgs.push_back(Args.MakeArgString(
Expand Down
21 changes: 15 additions & 6 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,16 +1558,25 @@ void SYCLToolChain::TranslateTargetOpt(const llvm::Triple &Triple,
StringRef GenDevice = SYCL::gen::resolveGenDevice(A->getValue());
bool IsGenTriple = Triple.isSPIR() &&
Triple.getSubArch() == llvm::Triple::SPIRSubArch_gen;
// llvm::errs() << "[DEBUG] Args: " << A->getAsString(Args)
// << " OptTargetTriple: " << OptTargetTriple.str()
// << ", Triple: " << Triple.str() << ", Device: " << Device
// << ", GenDevice: " << GenDevice << "\n";
if (IsGenTriple) {
if (Device != GenDevice && !Device.empty())
continue;
if (Device != GenDevice) {
if(!GenDevice.empty()) {
continue;
}
SmallString<64> DeviceOpt("-device ");
DeviceOpt += Device;
if (A->getAsString(Args).find(DeviceOpt.str()) == std::string::npos)
continue;
}
// if (Device != GenDevice && !Device.empty())
if (OptTargetTriple != Triple && GenDevice.empty())
// Triples do not match, but only skip when we know we are not
// comparing against intel_gpu_*
continue;
if (OptTargetTriple == Triple && !Device.empty())
// Triples match, but we are expecting a specific device to be set.
continue;
} else if (OptTargetTriple != Triple)
continue;
} else if (!OptNoTriple)
Expand Down Expand Up @@ -1678,7 +1687,7 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
}
// Check for any -device settings.
std::string DevArg;
if (IsJIT || Device == "pvc" || hasPVCDevice(TargArgs, DevArg)) {
if (IsJIT || Device == "pvc") {
// The -device option passed in by the user may not be 'pvc'. Use the
// value provided by the user if it was specified.
StringRef DeviceName = "pvc";
Expand Down
Loading