@@ -11222,43 +11222,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1122211222 if (Args.hasArg (options::OPT_fsycl_link_EQ))
1122311223 CmdArgs.push_back (Args.MakeArgString (" --sycl-device-link" ));
1122411224
11225- // -sycl-device-libraries=<comma separated list> contains all of the SYCL
11226- // device specific libraries that are needed. This generic list will be
11227- // populated with device binaries for all target triples in the current
11228- // compilation flow.
11229-
11230- // Create a comma separated list to pass along to the linker wrapper.
11231- SmallString<256 > LibList;
11232- llvm::Triple TargetTriple;
11233- auto ToolChainRange = C.getOffloadToolChains <Action::OFK_SYCL>();
11234- for (auto &I :
11235- llvm::make_range (ToolChainRange.first , ToolChainRange.second )) {
11236- const ToolChain *TC = I.second ;
11237- // Note: For AMD targets, we do not pass any SYCL device libraries.
11238- if (TC->getTriple ().isSPIROrSPIRV () || TC->getTriple ().isNVPTX ()) {
11239- TargetTriple = TC->getTriple ();
11240- SmallVector<std::string, 8 > SYCLDeviceLibs;
11241- bool IsSPIR = TargetTriple.isSPIROrSPIRV ();
11242- bool IsSpirvAOT = TargetTriple.isSPIRAOT ();
11243- bool UseJitLink =
11244- IsSPIR &&
11245- Args.hasFlag (options::OPT_fsycl_device_lib_jit_link,
11246- options::OPT_fno_sycl_device_lib_jit_link, false );
11247- bool UseAOTLink = IsSPIR && (IsSpirvAOT || !UseJitLink);
11248- SYCLDeviceLibs = SYCL::getDeviceLibraries (C, TargetTriple, UseAOTLink);
11249- for (const auto &AddLib : SYCLDeviceLibs) {
11250- if (LibList.size () > 0 )
11251- LibList += " ," ;
11252- LibList += AddLib;
11253- }
11254- }
11255- }
11256- // -sycl-device-libraries=<libs> provides a comma separate list of
11257- // libraries to add to the device linking step.
11258- if (LibList.size ())
11259- CmdArgs.push_back (
11260- Args.MakeArgString (Twine (" -sycl-device-libraries=" ) + LibList));
11261-
1126211225 // -sycl-device-library-location=<dir> provides the location in which the
1126311226 // SYCL device libraries can be found.
1126411227 SmallString<128 > DeviceLibDir (D.Dir );
@@ -11283,6 +11246,68 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1128311246 break ;
1128411247 }
1128511248 }
11249+
11250+ // -sycl-device-libraries=<comma separated list> contains a list of
11251+ // file names for fat object files that contain SYCL device library bitcode
11252+ // necessary for SYCL offloading that will be linked to the user's device
11253+ // code. clang-linker-wrapper uses the value provided to
11254+ // -sycl-device-library-location=<dir> to construct the full paths of the
11255+ // device libraries.
11256+
11257+ // On the other hand, --bitcode-library=<triple>=<path to bc file> specifies
11258+ // one bitcode library to link in for a specific triple. Additionally, the
11259+ // path is *not* relative to the -sycl-device-library-location - the full
11260+ // path must be provided.
11261+ SmallString<256 > LibList;
11262+ SmallVector<std::string, 4 > BCLibList;
11263+
11264+ auto appendToList = [](SmallString<256 > &List, const Twine &Arg) {
11265+ if (List.size () > 0 )
11266+ List += " ," ;
11267+ List += Arg.str ();
11268+ };
11269+
11270+ auto ToolChainRange = C.getOffloadToolChains <Action::OFK_SYCL>();
11271+ for (const auto &[Kind, TC] :
11272+ llvm::make_range (ToolChainRange.first , ToolChainRange.second )) {
11273+ llvm::Triple TargetTriple = TC->getTriple ();
11274+ bool IsSPIR = TargetTriple.isSPIROrSPIRV ();
11275+ bool IsSpirAOT = TargetTriple.isSPIRAOT ();
11276+ bool UseJitLink =
11277+ IsSPIR &&
11278+ Args.hasFlag (options::OPT_fsycl_device_lib_jit_link,
11279+ options::OPT_fno_sycl_device_lib_jit_link, false );
11280+ bool UseAOTLink = IsSPIR && (IsSpirAOT || !UseJitLink);
11281+ SmallVector<std::string, 8 > SYCLDeviceLibs =
11282+ SYCL::getDeviceLibraries (C, TargetTriple, UseAOTLink);
11283+ for (const auto &AddLib : SYCLDeviceLibs) {
11284+ if (llvm::sys::path::extension (AddLib) == " .bc" ) {
11285+ SmallString<256 > LibPath (DeviceLibDir);
11286+ llvm::sys::path::append (LibPath, AddLib);
11287+ BCLibList.push_back (
11288+ (Twine (TC->getTriple ().str ()) + " =" + LibPath).str ());
11289+ continue ;
11290+ }
11291+
11292+ appendToList (LibList, AddLib);
11293+ }
11294+
11295+ if (TC->getTriple ().isNVPTX ())
11296+ if (const char *LibSpirvFile = SYCLInstallation.findLibspirvPath (
11297+ TC->getTriple (), Args, *TC->getAuxTriple ()))
11298+ BCLibList.push_back (
11299+ (Twine (TC->getTriple ().str ()) + " =" + LibSpirvFile).str ());
11300+ }
11301+
11302+ if (LibList.size ())
11303+ CmdArgs.push_back (
11304+ Args.MakeArgString (Twine (" -sycl-device-libraries=" ) + LibList));
11305+
11306+ if (BCLibList.size ())
11307+ for (const std::string &Lib : BCLibList)
11308+ CmdArgs.push_back (
11309+ Args.MakeArgString (Twine (" --bitcode-library=" ) + Lib));
11310+
1128611311 CmdArgs.push_back (Args.MakeArgString (
1128711312 Twine (" -sycl-device-library-location=" ) + DeviceLibDir));
1128811313
0 commit comments