Skip to content
Merged
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
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def err_drv_hipspv_no_hip_path : Error<
"'--hip-path' must be specified when offloading to SPIR-V unless '-nogpuinc' "
"is given">;

def err_drv_no_sycl_device_lib
: Error<"cannot find expected SYCL device library '%0'. Pass "
"'--no-offloadlib' to "
"build without the SYCL device libraries">;
def err_drv_no_spv_tools : Error<"cannot find SPIR-V Tools binary '%0', which "
"is required for SPIR-V compilation. "
"It can be obtained from your system package "
Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/Driver/SyclInstallationDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace driver {

class SYCLInstallationDetector {
public:
SYCLInstallationDetector(const Driver &D);
SYCLInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
const llvm::opt::ArgList &Args);

Expand Down
25 changes: 14 additions & 11 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5069,7 +5069,8 @@ class OffloadingActionBuilder final {
SYCLActionBuilder(Compilation &C, DerivedArgList &Args,
const InputList &Inputs, OffloadingActionBuilder &OAB)
: DeviceActionBuilder(C, Args, Inputs, Action::OFK_SYCL, OAB),
SYCLInstallation(C.getDriver()) {}
SYCLInstallation(C.getDriver(), C.getDefaultToolChain().getTriple(),
Args) {}

void pushForeignAction(Action *A) override {
// Accept a foreign action from the CudaActionBuilder for compiling CUDA
Expand Down Expand Up @@ -5593,12 +5594,9 @@ class OffloadingActionBuilder final {
// is removed in compiler.
bool SYCLDeviceLibLinked = false;
Action *NativeCPULib = nullptr;
if (IsSPIR || IsNVPTX || IsAMDGCN || IsNativeCPU) {
if (IsSPIR || IsNVPTX || IsAMDGCN || IsNativeCPU)
SYCLDeviceLibLinked = addSYCLDeviceLibs(
TC, SYCLDeviceLibs, IsSpirvAOT,
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(),
IsNativeCPU, NativeCPULib, BoundArch);
}
TC, SYCLDeviceLibs, IsNativeCPU, NativeCPULib, BoundArch);
JobAction *LinkSYCLLibs =
C.MakeAction<LinkJobAction>(SYCLDeviceLibs, types::TY_LLVM_BC);
for (Action *FullLinkObject : FullLinkObjects) {
Expand Down Expand Up @@ -5823,20 +5821,25 @@ class OffloadingActionBuilder final {
}

bool addSYCLDeviceLibs(const ToolChain *TC, ActionList &DeviceLinkObjects,
bool isSpirvAOT, bool isMSVCEnv, bool isNativeCPU,
Action *&NativeCPULib, const char *BoundArch) {
bool isNativeCPU, Action *&NativeCPULib,
const char *BoundArch) {
int NumOfDeviceLibLinked = 0;
SmallVector<SmallString<128>, 4> LibLocCandidates;
SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates);

SmallVector<std::string, 8> DeviceLibraries;
const toolchains::SYCLToolChain &SYCLTC =
static_cast<const toolchains::SYCLToolChain &>(*TC);
SmallVector<ToolChain::BitCodeLibraryInfo, 8> DeviceLibraries;
// TODO: Use the getDeviceLibs for each toolchain instead of using the
// specific libs and doing a separate directory search. Each toolchain
// has their own getDeviceLibs that we can potentially use.
DeviceLibraries =
tools::SYCL::getDeviceLibraries(C, TC->getTriple(), isSpirvAOT);
SYCLTC.getDeviceLibNames(C.getDriver(), Args, TC->getTriple());

for (const auto &DeviceLib : DeviceLibraries) {
for (const auto &LLCandidate : LibLocCandidates) {
SmallString<128> LibName(LLCandidate);
llvm::sys::path::append(LibName, DeviceLib);
llvm::sys::path::append(LibName, DeviceLib.Path);
if (llvm::sys::fs::exists(LibName)) {
++NumOfDeviceLibLinked;
Arg *InputArg = makeInputArg(Args, C.getDriver().getOpts(),
Expand Down
27 changes: 13 additions & 14 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11059,7 +11059,8 @@ static void getNonTripleBasedSYCLPostLinkOpts(const ToolChain &TC,
// For bfloat16 conversions LLVM IR devicelib, we only need to embed it
// when non-AOT compilation is used.
if (TC.getTriple().isSPIROrSPIRV() && !TC.getTriple().isSPIRAOT()) {
SYCLInstallationDetector SYCLInstall(TC.getDriver());
SYCLInstallationDetector SYCLInstall(TC.getDriver(), TC.getTriple(),
TCArgs);
SmallVector<SmallString<128>, 4> DeviceLibLocCandidates;
SmallString<128> NativeBfloat16Name("libsycl-native-bfloat16.bc");
SYCLInstall.getSYCLDeviceLibPath(DeviceLibLocCandidates);
Expand Down Expand Up @@ -11606,7 +11607,8 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
// and use that location. Base the location on relative to driver if this
// is not resolved.
SmallVector<SmallString<128>, 4> LibLocCandidates;
SYCLInstallationDetector SYCLInstallation(D);
SYCLInstallationDetector SYCLInstallation(D, getToolChain().getTriple(),
Args);
SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates);
SmallString<128> LibName("libsycl-crt");
bool IsNewOffload = D.getUseNewOffloadingDriver();
Expand Down Expand Up @@ -11634,7 +11636,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
// one bitcode library to link in for a specific triple. Additionally, the
// path is *not* relative to the -sycl-device-library-location - the full
// path must be provided.
SmallString<256> LibList;
SmallVector<std::string, 4> BCLibList;

auto appendToList = [](SmallString<256> &List, const Twine &Arg) {
Expand All @@ -11647,19 +11648,21 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
for (const auto &[Kind, TC] :
llvm::make_range(ToolChainRange.first, ToolChainRange.second)) {
llvm::Triple TargetTriple = TC->getTriple();
bool IsSpirAOT = TargetTriple.isSPIRAOT();
SmallVector<std::string, 8> SYCLDeviceLibs =
SYCL::getDeviceLibraries(C, TargetTriple, IsSpirAOT);
const toolchains::SYCLToolChain &SYCLTC =
static_cast<const toolchains::SYCLToolChain &>(*TC);
SmallVector<ToolChain::BitCodeLibraryInfo, 8> SYCLDeviceLibs;
// SPIR or SPIR-V device libraries are compiled into the device compile
// step.
if (!TargetTriple.isSPIROrSPIRV())
SYCLDeviceLibs.append(SYCLTC.getDeviceLibNames(D, Args, TargetTriple));
for (const auto &AddLib : SYCLDeviceLibs) {
if (llvm::sys::path::extension(AddLib) == ".bc") {
if (llvm::sys::path::extension(AddLib.Path) == ".bc") {
SmallString<256> LibPath(DeviceLibDir);
llvm::sys::path::append(LibPath, AddLib);
llvm::sys::path::append(LibPath, AddLib.Path);
BCLibList.push_back(
(Twine(TC->getTriple().str()) + "=" + LibPath).str());
continue;
}

appendToList(LibList, AddLib);
}

if (TC->getTriple().isNVPTX())
Expand All @@ -11669,10 +11672,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
(Twine(TC->getTriple().str()) + "=" + LibSpirvFile).str());
}

if (LibList.size())
CmdArgs.push_back(
Args.MakeArgString(Twine("-sycl-device-libraries=") + LibList));

if (BCLibList.size())
for (const std::string &Lib : BCLibList)
CmdArgs.push_back(
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
const ToolChain &HostTC, const ArgList &Args,
const Action::OffloadKind OK)
: NVPTXToolChain(D, Triple, HostTC.getTriple(), Args), HostTC(HostTC),
SYCLInstallation(D), OK(OK) {}
SYCLInstallation(D, HostTC.getTriple(), Args), OK(OK) {}

void CudaToolChain::addClangTargetOptions(
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/HIPAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ void AMDGCN::Linker::ConstructJob(Compilation &C, const JobAction &JA,
HIPAMDToolChain::HIPAMDToolChain(const Driver &D, const llvm::Triple &Triple,
const ToolChain &HostTC, const ArgList &Args,
const Action::OffloadKind OK)
: ROCMToolChain(D, Triple, Args), HostTC(HostTC), SYCLInstallation(D),
OK(OK) {
: ROCMToolChain(D, Triple, Args), HostTC(HostTC),
SYCLInstallation(D, HostTC.getTriple(), Args), OK(OK) {
// Lookup binaries into the driver directory, this is used to
// discover the clang-offload-bundler executable.
getProgramPaths().push_back(getDriver().Dir);
Expand Down
Loading
Loading