@@ -5564,7 +5564,7 @@ class OffloadingActionBuilder final {
55645564 SYCLDeviceLibLinked = addSYCLDeviceLibs (
55655565 TC, SYCLDeviceLibs, UseAOTLink,
55665566 C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment (),
5567- IsSYCLNativeCPU, NativeCPULib);
5567+ IsSYCLNativeCPU, NativeCPULib, BoundArch );
55685568 }
55695569 JobAction *LinkSYCLLibs =
55705570 C.MakeAction <LinkJobAction>(SYCLDeviceLibs, types::TY_LLVM_BC);
@@ -5842,7 +5842,7 @@ class OffloadingActionBuilder final {
58425842
58435843 bool addSYCLDeviceLibs (const ToolChain *TC, ActionList &DeviceLinkObjects,
58445844 bool isSpirvAOT, bool isMSVCEnv, bool isNativeCPU,
5845- Action *&NativeCPULib) {
5845+ Action *&NativeCPULib, const char *BoundArch ) {
58465846 int NumOfDeviceLibLinked = 0 ;
58475847 SmallVector<SmallString<128 >, 4 > LibLocCandidates;
58485848 SYCLInstallation.getSYCLDeviceLibPath (LibLocCandidates);
@@ -5852,14 +5852,10 @@ class OffloadingActionBuilder final {
58525852 tools::SYCL::getDeviceLibraries (C, TC->getTriple (), isSpirvAOT);
58535853
58545854 for (const auto &DeviceLib : DeviceLibraries) {
5855- bool LibLocSelected = false ;
58565855 for (const auto &LLCandidate : LibLocCandidates) {
5857- if (LibLocSelected)
5858- break ;
58595856 SmallString<128 > LibName (LLCandidate);
58605857 llvm::sys::path::append (LibName, DeviceLib);
58615858 if (llvm::sys::fs::exists (LibName)) {
5862-
58635859 // NativeCPU currently only needs libsycl-nativecpu_utils and
58645860 // libclc, so temporarily skip other device libs in invocation.
58655861 // Todo: remove once NativeCPU tests the other libraries.
@@ -5897,8 +5893,6 @@ class OffloadingActionBuilder final {
58975893 C.MakeAction <InputAction>(*InputArg, types::TY_LLVM_BC);
58985894 DeviceLinkObjects.push_back (SYCLDeviceLibsInputAction);
58995895 }
5900- if (!LibLocSelected)
5901- LibLocSelected = !LibLocSelected;
59025896
59035897 // The device link stage may remove symbols not referenced in the
59045898 // source code. Since libsycl-nativecpu_utils contains such symbols
@@ -5909,22 +5903,26 @@ class OffloadingActionBuilder final {
59095903 NativeCPULib = DeviceLinkObjects.back ();
59105904 DeviceLinkObjects.pop_back ();
59115905 }
5906+
5907+ break ;
59125908 }
59135909 }
59145910 }
59155911
5916- // For NVPTX backend we need to also link libclc and CUDA libdevice
5917- // at the same stage that we link all of the unbundled SYCL libdevice
5918- // objects together.
5919- if ((TC->getTriple ().isNVPTX () || isNativeCPU) && NumOfDeviceLibLinked) {
5912+ if (!NumOfDeviceLibLinked)
5913+ return false ;
5914+
5915+ // For NVPTX and NativeCPU we need to also link libclc at the same stage
5916+ // that we link all of the unbundled SYCL libdevice objects together.
5917+ if (TC->getTriple ().isNVPTX () || isNativeCPU) {
59205918 std::string LibSpirvFile;
59215919 if (Args.hasArg (options::OPT_fsycl_libspirv_path_EQ)) {
59225920 auto ProvidedPath =
59235921 Args.getLastArgValue (options::OPT_fsycl_libspirv_path_EQ).str ();
59245922 if (llvm::sys::fs::exists (ProvidedPath))
59255923 LibSpirvFile = ProvidedPath;
59265924 } else {
5927- SmallVector<StringRef, 8 > LibraryPaths;
5925+ SmallVector<StringRef, 2 > LibraryPaths;
59285926
59295927 // Expected path w/out install.
59305928 SmallString<256 > WithoutInstallPath (C.getDriver ().ResourceDir );
@@ -5936,22 +5934,17 @@ class OffloadingActionBuilder final {
59365934 llvm::sys::path::append (WithInstallPath, Twine (" ../../../share/clc" ));
59375935 LibraryPaths.emplace_back (WithInstallPath.c_str ());
59385936
5939- // TODO: check if the isNVPTX() path can also use
5940- // TC->getTripleString() so that the conditional could be removed
5941- const std::string TrStr =
5942- isNativeCPU ? TC->getTripleString () : " nvptx64-nvidia-cuda" ;
5943-
59445937 // Select remangled libclc variant
59455938 StringRef LibSpirvTargetNamePref =
59465939 TC->getAuxTriple ()->isOSWindows ()
59475940 ? " remangled-l32-signed_char.libspirv-"
59485941 : " remangled-l64-signed_char.libspirv-" ;
5949- llvm::Twine LibSpirvTargetNameTemp = LibSpirvTargetNamePref + TrStr;
5950- llvm::Twine LibSpirvTargetName = LibSpirvTargetNameTemp + " .bc" ;
59515942
59525943 for (StringRef LibraryPath : LibraryPaths) {
59535944 SmallString<128 > LibSpirvTargetFile (LibraryPath);
5954- llvm::sys::path::append (LibSpirvTargetFile, LibSpirvTargetName);
5945+ llvm::sys::path::append (LibSpirvTargetFile,
5946+ LibSpirvTargetNamePref +
5947+ TC->getTripleString () + " .bc" );
59555948 if (llvm::sys::fs::exists (LibSpirvTargetFile) ||
59565949 Args.hasArg (options::OPT__HASH_HASH_HASH)) {
59575950 LibSpirvFile = std::string (LibSpirvTargetFile.str ());
@@ -5966,30 +5959,24 @@ class OffloadingActionBuilder final {
59665959 C.MakeAction <InputAction>(*LibClcInputArg, types::TY_LLVM_BC);
59675960 DeviceLinkObjects.push_back (SYCLLibClcInputAction);
59685961 }
5962+ }
59695963
5970- if (isNativeCPU) {
5971- // return here to not generate cuda actions
5972- return NumOfDeviceLibLinked != 0 ;
5973- }
5974-
5964+ // For NVPTX we also need to link with the CUDA libdevice
5965+ if (TC->getTriple ().isNVPTX () && !Args.hasArg (options::OPT_nogpulib)) {
59755966 const toolchains::CudaToolChain *CudaTC =
59765967 static_cast <const toolchains::CudaToolChain *>(TC);
5977- for (const auto &LinkInputEnum : enumerate(DeviceLinkerInputs)) {
5978- const char *BoundArch =
5979- SYCLTargetInfoList[LinkInputEnum.index ()].BoundArch ;
5980- std::string LibDeviceFile =
5981- CudaTC->CudaInstallation .getLibDeviceFile (BoundArch);
5982- if (!LibDeviceFile.empty ()) {
5983- Arg *CudaDeviceLibInputArg =
5984- MakeInputArg (Args, C.getDriver ().getOpts (),
5985- Args.MakeArgString (LibDeviceFile));
5986- auto *SYCLDeviceLibInputAction = C.MakeAction <InputAction>(
5987- *CudaDeviceLibInputArg, types::TY_LLVM_BC);
5988- DeviceLinkObjects.push_back (SYCLDeviceLibInputAction);
5989- }
5968+ std::string LibDeviceFile =
5969+ CudaTC->CudaInstallation .getLibDeviceFile (BoundArch);
5970+ if (!LibDeviceFile.empty ()) {
5971+ Arg *CudaDeviceLibInputArg = MakeInputArg (
5972+ Args, C.getDriver ().getOpts (), Args.MakeArgString (LibDeviceFile));
5973+ auto *SYCLDeviceLibInputAction = C.MakeAction <InputAction>(
5974+ *CudaDeviceLibInputArg, types::TY_LLVM_BC);
5975+ DeviceLinkObjects.push_back (SYCLDeviceLibInputAction);
59905976 }
59915977 }
5992- return NumOfDeviceLibLinked != 0 ;
5978+
5979+ return true ;
59935980 }
59945981
59955982 void appendLinkDependences (OffloadAction::DeviceDependences &DA) override {
0 commit comments