Skip to content

Commit 21f519d

Browse files
committed
update device linking pt3
1 parent 2da4a26 commit 21f519d

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11299,6 +11299,15 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1129911299
// Create a comma separated list to pass along to the linker wrapper.
1130011300
SmallString<256> LibList;
1130111301
SmallString<256> BCLibList;
11302+
11303+
// Lambda to append items to BCLibList with comma separation
11304+
auto appendToBCLibList = [&BCLibList](const llvm::Triple &Triple,
11305+
const Twine &Path) {
11306+
if (BCLibList.size() > 0)
11307+
BCLibList += ",";
11308+
BCLibList += (Twine(Triple.str()) + "=" + Path).str();
11309+
};
11310+
1130211311
llvm::Triple TargetTriple;
1130311312
auto ToolChainRange = C.getOffloadToolChains<Action::OFK_SYCL>();
1130411313
for (auto &I :
@@ -11316,15 +11325,23 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1131611325
SYCLDeviceLibs = SYCL::getDeviceLibraries(C, TargetTriple, UseAOTLink);
1131711326
for (const auto &AddLib : SYCLDeviceLibs) {
1131811327
if (llvm::sys::path::extension(AddLib) == ".bc") {
11319-
if (BCLibList.size() > 0)
11320-
BCLibList += ",";
11321-
BCLibList += Twine(TC->getTriple().str() + "=" + AddLib).str();
11328+
SmallString<256> LibPath(DeviceLibDir);
11329+
llvm::sys::path::append(LibPath, AddLib);
11330+
appendToBCLibList(TC->getTriple(), LibPath);
1132211331
continue;
1132311332
}
11333+
1132411334
if (LibList.size() > 0)
1132511335
LibList += ",";
1132611336
LibList += AddLib;
1132711337
}
11338+
11339+
if (TC->getTriple().isNVPTX()) {
11340+
if (const char *LibSpirvFile = SYCLInstallation.findLibspirvPath(
11341+
TC->getTriple(), Args, *TC->getAuxTriple())) {
11342+
appendToBCLibList(TC->getTriple(), LibSpirvFile);
11343+
}
11344+
}
1132811345
}
1132911346
// -sycl-device-libraries=<libs> provides a comma separate list of
1133011347
// libraries to add to the device linking step.
@@ -11334,7 +11351,7 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1133411351

1133511352
if (BCLibList.size())
1133611353
CmdArgs.push_back(
11337-
Args.MakeArgString(Twine("--sycl-bc-device-libraries=") + BCLibList));
11354+
Args.MakeArgString(Twine("-sycl-bc-device-libraries=") + BCLibList));
1133811355

1133911356
// -sycl-device-library-location=<dir> provides the location in which the
1134011357
// SYCL device libraries can be found.

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,21 +1418,21 @@ static Expected<StringRef> linkDevice(ArrayRef<StringRef> InputFiles,
14181418
}
14191419

14201420
for (StringRef Library : Args.getAllArgValues(OPT_sycl_bc_device_lib_EQ)) {
1421-
auto [LibraryTriple, LibraryName] = Library.split('=');
1421+
auto [LibraryTriple, LibraryPath] = Library.split('=');
14221422
if (llvm::Triple(LibraryTriple) != Triple)
14231423
continue;
1424-
StringRef DeviceLibraryDir("");
1425-
if (Arg *DeviceLibDirArg =
1426-
Args.getLastArg(OPT_sycl_device_library_location_EQ))
1427-
DeviceLibraryDir = DeviceLibDirArg->getValue();
1428-
SmallString<128> DeviceLibPath(DeviceLibraryDir);
1429-
llvm::sys::path::append(DeviceLibPath, LibraryName);
1430-
if (!llvm::sys::fs::exists(DeviceLibPath)) {
1424+
// StringRef DeviceLibraryDir("");
1425+
// if (Arg *DeviceLibDirArg =
1426+
// Args.getLastArg(OPT_sycl_device_library_location_EQ))
1427+
// DeviceLibraryDir = DeviceLibDirArg->getValue();
1428+
// SmallString<128> DeviceLibPath(DeviceLibraryDir);
1429+
// llvm::sys::path::append(DeviceLibPath, LibraryName);
1430+
if (!llvm::sys::fs::exists(LibraryPath)) {
14311431
return createStringError(inconvertibleErrorCode(),
1432-
"The specified device library " + DeviceLibPath +
1432+
"The specified device library " + LibraryPath +
14331433
" does not exist.");
14341434
}
1435-
ExtractedDeviceLibFiles.emplace_back(DeviceLibPath.str());
1435+
ExtractedDeviceLibFiles.emplace_back(LibraryPath.str());
14361436
}
14371437

14381438
// Make sure that SYCL device library files are available.

0 commit comments

Comments
 (0)