@@ -561,202 +561,12 @@ addSYCLDeviceSanitizerLibs(const Compilation &C, bool IsSpirvAOT,
561561}
562562#endif
563563
564- // Get the list of SYCL device libraries to link with user's device image if
565- // some deprecated options are used including: -f[no-]sycl-device-lib=xxx,
566- // -f[no-]sycl-device-lib-jit-link.
567- // TODO: remove getDeviceLibrariesLegacy when we remove deprecated options
568- // related to sycl device library link.
569- static SmallVector<std::string, 8 >
570- getDeviceLibrariesLegacy (const Compilation &C, const llvm::Triple &TargetTriple,
571- bool IsSpirvAOT) {
572- SmallVector<std::string, 8 > LibraryList;
573- const llvm::opt::ArgList &Args = C.getArgs ();
574-
575- // For NVPTX and AMDGCN we only use one single bitcode library and ignore
576- // manually specified SYCL device libraries.
577- // For NativeCPU, only native_utils devicelib is used.
578- bool UseSingleLib = TargetTriple.isNVPTX () || TargetTriple.isAMDGCN () ||
579- TargetTriple.isNativeCPU ();
580- bool IgnoreSingleLib = false ;
581-
582- struct DeviceLibOptInfo {
583- StringRef DeviceLibName;
584- StringRef DeviceLibOption;
585- };
586-
587- enum { JIT = 0 , AOT_CPU, AOT_DG2, AOT_PVC };
588-
589- // Currently, all SYCL device libraries will be linked by default.
590- llvm::StringMap<bool > DeviceLibLinkInfo = {
591- {" libc" , true }, {" libm-fp32" , true }, {" libm-fp64" , true },
592- {" libimf-fp32" , true }, {" libimf-fp64" , true }, {" libimf-bf16" , true },
593- {" libm-bfloat16" , true }, {" internal" , true }};
594-
595- // If -fno-sycl-device-lib is specified, its values will be used to exclude
596- // linkage of libraries specified by DeviceLibLinkInfo. Linkage of "internal"
597- // libraries cannot be affected via -fno-sycl-device-lib.
598- bool ExcludeDeviceLibs = false ;
599-
600- if (Arg *A = Args.getLastArg (options::OPT_fsycl_device_lib_EQ,
601- options::OPT_fno_sycl_device_lib_EQ)) {
602- if (A->getValues ().size () == 0 )
603- C.getDriver ().Diag (diag::warn_drv_empty_joined_argument)
604- << A->getAsString (Args);
605- else {
606- if (A->getOption ().matches (options::OPT_fno_sycl_device_lib_EQ))
607- ExcludeDeviceLibs = true ;
608-
609- // When single libraries are ignored and a subset of library names
610- // not containing the value "all" is specified by -fno-sycl-device-lib,
611- // print an unused argument warning.
612- bool PrintUnusedExcludeWarning = false ;
613-
614- for (StringRef Val : A->getValues ()) {
615- if (Val == " all" ) {
616- PrintUnusedExcludeWarning = false ;
617-
618- // Make sure that internal libraries are still linked against
619- // when -fno-sycl-device-lib contains "all" and single libraries
620- // should be ignored. For NativeCPU, the native_cpu utils library
621- // is always linked without '-only-needed' flag.
622- IgnoreSingleLib =
623- UseSingleLib && ExcludeDeviceLibs && !TargetTriple.isNativeCPU ();
624-
625- for (const auto &K : DeviceLibLinkInfo.keys ())
626- DeviceLibLinkInfo[K] = (K == " internal" ) || !ExcludeDeviceLibs;
627- break ;
628- }
629- auto LinkInfoIter = DeviceLibLinkInfo.find (Val);
630- if (LinkInfoIter == DeviceLibLinkInfo.end () || Val == " internal" ) {
631- // TODO: Move the diagnostic to the SYCL section of
632- // Driver::CreateOffloadingDeviceToolChains() to minimize code
633- // duplication.
634- C.getDriver ().Diag (diag::err_drv_unsupported_option_argument)
635- << A->getSpelling () << Val;
636- }
637- DeviceLibLinkInfo[Val] = !ExcludeDeviceLibs;
638- PrintUnusedExcludeWarning = UseSingleLib && ExcludeDeviceLibs;
639- }
640- if (PrintUnusedExcludeWarning)
641- C.getDriver ().Diag (diag::warn_drv_unused_argument) << A->getSpelling ();
642- }
643- }
644-
645- if (TargetTriple.isNVPTX () && !IgnoreSingleLib)
646- LibraryList.push_back (
647- Args.MakeArgString (" devicelib-nvptx64-nvidia-cuda.bc" ));
648-
649- if (TargetTriple.isAMDGCN () && !IgnoreSingleLib)
650- LibraryList.push_back (Args.MakeArgString (" devicelib-amdgcn-amd-amdhsa.bc" ));
651-
652- if (TargetTriple.isNativeCPU () && !IgnoreSingleLib)
653- LibraryList.push_back (Args.MakeArgString (" libsycl-nativecpu_utils.bc" ));
654-
655- if (UseSingleLib)
656- return LibraryList;
657-
658- using SYCLDeviceLibsList = SmallVector<DeviceLibOptInfo, 5 >;
659-
660- const SYCLDeviceLibsList SYCLDeviceWrapperLibs = {
661- {" libsycl-crt" , " libc" },
662- {" libsycl-complex" , " libm-fp32" },
663- {" libsycl-complex-fp64" , " libm-fp64" },
664- {" libsycl-cmath" , " libm-fp32" },
665- {" libsycl-cmath-fp64" , " libm-fp64" },
666- #if defined(_WIN32)
667- {" libsycl-msvc-math" , " libm-fp32" },
668- #endif
669- {" libsycl-imf" , " libimf-fp32" },
670- {" libsycl-imf-fp64" , " libimf-fp64" },
671- {" libsycl-imf-bf16" , " libimf-bf16" }};
672- // For AOT compilation, we need to link sycl_device_fallback_libs as
673- // default too.
674- const SYCLDeviceLibsList SYCLDeviceFallbackLibs = {
675- {" libsycl-fallback-cassert" , " libc" },
676- {" libsycl-fallback-cstring" , " libc" },
677- {" libsycl-fallback-complex" , " libm-fp32" },
678- {" libsycl-fallback-complex-fp64" , " libm-fp64" },
679- {" libsycl-fallback-cmath" , " libm-fp32" },
680- {" libsycl-fallback-cmath-fp64" , " libm-fp64" },
681- {" libsycl-fallback-imf" , " libimf-fp32" },
682- {" libsycl-fallback-imf-fp64" , " libimf-fp64" },
683- {" libsycl-fallback-imf-bf16" , " libimf-bf16" }};
684- const SYCLDeviceLibsList SYCLDeviceBfloat16FallbackLib = {
685- {" libsycl-fallback-bfloat16" , " libm-bfloat16" }};
686- const SYCLDeviceLibsList SYCLDeviceBfloat16NativeLib = {
687- {" libsycl-native-bfloat16" , " libm-bfloat16" }};
688- // ITT annotation libraries are linked in separately whenever the device
689- // code instrumentation is enabled.
690- const SYCLDeviceLibsList SYCLDeviceAnnotationLibs = {
691- {" libsycl-itt-user-wrappers" , " internal" },
692- {" libsycl-itt-compiler-wrappers" , " internal" },
693- {" libsycl-itt-stubs" , " internal" }};
694- const SYCLDeviceLibsList SYCLNativeCpuDeviceLibs = {
695- {" libsycl-nativecpu_utils" , " internal" }};
696-
697- bool IsWindowsMSVCEnv =
698- C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment ();
699- bool IsNewOffload = C.getDriver ().getUseNewOffloadingDriver ();
700- StringRef LibSuffix = " .bc" ;
701- if (IsNewOffload)
702- // For new offload model, we use packaged .bc files.
703- LibSuffix = IsWindowsMSVCEnv ? " .new.obj" : " .new.o" ;
704- auto addLibraries = [&](const SYCLDeviceLibsList &LibsList) {
705- for (const DeviceLibOptInfo &Lib : LibsList) {
706- if (!DeviceLibLinkInfo[Lib.DeviceLibOption ])
707- continue ;
708- SmallString<128 > LibName (Lib.DeviceLibName );
709- llvm::sys::path::replace_extension (LibName, LibSuffix);
710- LibraryList.push_back (Args.MakeArgString (LibName));
711- }
712- };
713-
714- addLibraries (SYCLDeviceWrapperLibs);
715- if (IsSpirvAOT)
716- addLibraries (SYCLDeviceFallbackLibs);
717-
718- bool NativeBfloatLibs;
719- bool NeedBfloatLibs = selectBfloatLibs (TargetTriple, C, NativeBfloatLibs);
720- if (NeedBfloatLibs) {
721- // Add native or fallback bfloat16 library.
722- if (NativeBfloatLibs)
723- addLibraries (SYCLDeviceBfloat16NativeLib);
724- else
725- addLibraries (SYCLDeviceBfloat16FallbackLib);
726- }
727-
728- // Link in ITT annotations library unless fsycl-no-instrument-device-code
729- // is specified. This ensures that we are ABI-compatible with the
730- // instrumented device code, which was the default not so long ago.
731- if (Args.hasFlag (options::OPT_fsycl_instrument_device_code,
732- options::OPT_fno_sycl_instrument_device_code, true ))
733- addLibraries (SYCLDeviceAnnotationLibs);
734-
735- // Currently, device sanitizer support is required by some developers on
736- // Linux platform only, so compiler only provides device sanitizer libraries
737- // on Linux platform.
738- #if !defined(_WIN32)
739- addSYCLDeviceSanitizerLibs (C, IsSpirvAOT, LibSuffix, LibraryList);
740- #endif
741-
742- if (TargetTriple.isNativeCPU ())
743- addLibraries (SYCLNativeCpuDeviceLibs);
744-
745- return LibraryList;
746- }
747-
748564// Get the list of SYCL device libraries to link with user's device image.
749565SmallVector<std::string, 8 >
750566SYCL::getDeviceLibraries (const Compilation &C, const llvm::Triple &TargetTriple,
751567 bool IsSpirvAOT) {
752568 SmallVector<std::string, 8 > LibraryList;
753569 const llvm::opt::ArgList &Args = C.getArgs ();
754- if (Args.getLastArg (options::OPT_fsycl_device_lib_EQ,
755- options::OPT_fno_sycl_device_lib_EQ) ||
756- Args.getLastArg (options::OPT_fsycl_device_lib_jit_link,
757- options::OPT_fno_sycl_device_lib_jit_link))
758- return getDeviceLibrariesLegacy (C, TargetTriple, IsSpirvAOT);
759-
760570 bool NoOffloadLib =
761571 !Args.hasFlag (options::OPT_offloadlib, options::OPT_no_offloadlib, true );
762572 if (TargetTriple.isNVPTX ()) {
0 commit comments