Skip to content
21 changes: 2 additions & 19 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -6056,10 +6056,10 @@ def : Flag<["-"], "nocudainc">, Alias<no_offload_inc>;
def no_offloadlib
: Flag<["--"], "no-offloadlib">,
MarshallingInfoFlag<LangOpts<"NoGPULib">>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
Visibility<[ClangOption, CLOption, CC1Option, FlangOption, FC1Option]>,
HelpText<"Do not link device library for CUDA/HIP/SYCL device compilation">;
def offloadlib : Flag<["--"], "offloadlib">,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
Visibility<[ClangOption, CLOption, CC1Option, FlangOption, FC1Option]>,
HelpText<"Link device libraries for GPU device compilation">;
def : Flag<["-"], "nogpulib">,
Alias<no_offloadlib>,
Expand Down Expand Up @@ -7268,23 +7268,6 @@ def fsycl_dead_args_optimization : Flag<["-"], "fsycl-dead-args-optimization">,
HelpText<"Enables elimination of DPC++ dead kernel arguments">;
def fno_sycl_dead_args_optimization : Flag<["-"], "fno-sycl-dead-args-optimization">,
HelpText<"Disables elimination of DPC++ dead kernel arguments">;
def fsycl_device_lib_EQ : CommaJoined<["-"], "fsycl-device-lib=">,
Flags<[Deprecated]>,
Values<"libc,libm-fp32,libm-fp64,libimf-fp32,libimf-fp64,libimf-bf16,all">,
HelpText<"Control inclusion of device libraries into device binary linkage. "
"Valid arguments are libc, libm-fp32, libm-fp64, libimf-fp32, "
"libimf-fp64, libimf-bf16, all. (deprecated)">;
def fno_sycl_device_lib_EQ : CommaJoined<["-"], "fno-sycl-device-lib=">,
Flags<[Deprecated]>,
Values<"libc, libm-fp32, libm-fp64, all">,
HelpText<"Control exclusion of device libraries from device binary linkage. "
"Valid arguments are libc, libm-fp32, libm-fp64, all. (deprecated)">;
def fsycl_device_lib_jit_link : Flag<["-"], "fsycl-device-lib-jit-link">,
Flags<[Deprecated]>,
HelpText<"Enables sycl device library jit link. (deprecated)">;
def fno_sycl_device_lib_jit_link : Flag<["-"], "fno-sycl-device-lib-jit-link">,
Flags<[Deprecated]>,
HelpText<"Disables sycl device library jit link. (deprecated)">;
def fsycl_fp32_prec_sqrt : Flag<["-"], "fsycl-fp32-prec-sqrt">,
Alias<foffload_fp32_prec_sqrt>, Flags<[Deprecated]>,
Visibility<[ClangOption, CC1Option]>, HelpText<"SYCL only. Specify that "
Expand Down
7 changes: 1 addition & 6 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5496,13 +5496,8 @@ class OffloadingActionBuilder final {
bool SYCLDeviceLibLinked = false;
Action *NativeCPULib = nullptr;
if (IsSPIR || IsNVPTX || IsAMDGCN || IsNativeCPU) {
bool UseJitLink =
IsSPIR &&
Args.hasFlag(options::OPT_fsycl_device_lib_jit_link,
options::OPT_fno_sycl_device_lib_jit_link, false);
bool UseAOTLink = IsSPIR && (IsSpirvAOT || !UseJitLink);
SYCLDeviceLibLinked = addSYCLDeviceLibs(
TC, SYCLDeviceLibs, UseAOTLink,
TC, SYCLDeviceLibs, IsSpirvAOT,
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(),
IsNativeCPU, NativeCPULib, BoundArch);
}
Expand Down
10 changes: 2 additions & 8 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11281,15 +11281,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
// Note: For AMD targets, we do not pass any SYCL device libraries.
if (TC->getTriple().isSPIROrSPIRV() || TC->getTriple().isNVPTX()) {
TargetTriple = TC->getTriple();
SmallVector<std::string, 8> SYCLDeviceLibs;
bool IsSPIR = TargetTriple.isSPIROrSPIRV();
bool IsSpirvAOT = TargetTriple.isSPIRAOT();
bool UseJitLink =
IsSPIR &&
Args.hasFlag(options::OPT_fsycl_device_lib_jit_link,
options::OPT_fno_sycl_device_lib_jit_link, false);
bool UseAOTLink = IsSPIR && (IsSpirvAOT || !UseJitLink);
SYCLDeviceLibs = SYCL::getDeviceLibraries(C, TargetTriple, UseAOTLink);
SmallVector<std::string, 8> SYCLDeviceLibs =
SYCL::getDeviceLibraries(C, TargetTriple, IsSpirvAOT);
for (const auto &AddLib : SYCLDeviceLibs) {
if (LibList.size() > 0)
LibList += ",";
Expand Down
190 changes: 0 additions & 190 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,202 +561,12 @@ addSYCLDeviceSanitizerLibs(const Compilation &C, bool IsSpirvAOT,
}
#endif

// Get the list of SYCL device libraries to link with user's device image if
// some deprecated options are used including: -f[no-]sycl-device-lib=xxx,
// -f[no-]sycl-device-lib-jit-link.
// TODO: remove getDeviceLibrariesLegacy when we remove deprecated options
// related to sycl device library link.
static SmallVector<std::string, 8>
getDeviceLibrariesLegacy(const Compilation &C, const llvm::Triple &TargetTriple,
bool IsSpirvAOT) {
SmallVector<std::string, 8> LibraryList;
const llvm::opt::ArgList &Args = C.getArgs();

// For NVPTX and AMDGCN we only use one single bitcode library and ignore
// manually specified SYCL device libraries.
// For NativeCPU, only native_utils devicelib is used.
bool UseSingleLib = TargetTriple.isNVPTX() || TargetTriple.isAMDGCN() ||
TargetTriple.isNativeCPU();
bool IgnoreSingleLib = false;

struct DeviceLibOptInfo {
StringRef DeviceLibName;
StringRef DeviceLibOption;
};

enum { JIT = 0, AOT_CPU, AOT_DG2, AOT_PVC };

// Currently, all SYCL device libraries will be linked by default.
llvm::StringMap<bool> DeviceLibLinkInfo = {
{"libc", true}, {"libm-fp32", true}, {"libm-fp64", true},
{"libimf-fp32", true}, {"libimf-fp64", true}, {"libimf-bf16", true},
{"libm-bfloat16", true}, {"internal", true}};

// If -fno-sycl-device-lib is specified, its values will be used to exclude
// linkage of libraries specified by DeviceLibLinkInfo. Linkage of "internal"
// libraries cannot be affected via -fno-sycl-device-lib.
bool ExcludeDeviceLibs = false;

if (Arg *A = Args.getLastArg(options::OPT_fsycl_device_lib_EQ,
options::OPT_fno_sycl_device_lib_EQ)) {
if (A->getValues().size() == 0)
C.getDriver().Diag(diag::warn_drv_empty_joined_argument)
<< A->getAsString(Args);
else {
if (A->getOption().matches(options::OPT_fno_sycl_device_lib_EQ))
ExcludeDeviceLibs = true;

// When single libraries are ignored and a subset of library names
// not containing the value "all" is specified by -fno-sycl-device-lib,
// print an unused argument warning.
bool PrintUnusedExcludeWarning = false;

for (StringRef Val : A->getValues()) {
if (Val == "all") {
PrintUnusedExcludeWarning = false;

// Make sure that internal libraries are still linked against
// when -fno-sycl-device-lib contains "all" and single libraries
// should be ignored. For NativeCPU, the native_cpu utils library
// is always linked without '-only-needed' flag.
IgnoreSingleLib =
UseSingleLib && ExcludeDeviceLibs && !TargetTriple.isNativeCPU();

for (const auto &K : DeviceLibLinkInfo.keys())
DeviceLibLinkInfo[K] = (K == "internal") || !ExcludeDeviceLibs;
break;
}
auto LinkInfoIter = DeviceLibLinkInfo.find(Val);
if (LinkInfoIter == DeviceLibLinkInfo.end() || Val == "internal") {
// TODO: Move the diagnostic to the SYCL section of
// Driver::CreateOffloadingDeviceToolChains() to minimize code
// duplication.
C.getDriver().Diag(diag::err_drv_unsupported_option_argument)
<< A->getSpelling() << Val;
}
DeviceLibLinkInfo[Val] = !ExcludeDeviceLibs;
PrintUnusedExcludeWarning = UseSingleLib && ExcludeDeviceLibs;
}
if (PrintUnusedExcludeWarning)
C.getDriver().Diag(diag::warn_drv_unused_argument) << A->getSpelling();
}
}

if (TargetTriple.isNVPTX() && !IgnoreSingleLib)
LibraryList.push_back(
Args.MakeArgString("devicelib-nvptx64-nvidia-cuda.bc"));

if (TargetTriple.isAMDGCN() && !IgnoreSingleLib)
LibraryList.push_back(Args.MakeArgString("devicelib-amdgcn-amd-amdhsa.bc"));

if (TargetTriple.isNativeCPU() && !IgnoreSingleLib)
LibraryList.push_back(Args.MakeArgString("libsycl-nativecpu_utils.bc"));

if (UseSingleLib)
return LibraryList;

using SYCLDeviceLibsList = SmallVector<DeviceLibOptInfo, 5>;

const SYCLDeviceLibsList SYCLDeviceWrapperLibs = {
{"libsycl-crt", "libc"},
{"libsycl-complex", "libm-fp32"},
{"libsycl-complex-fp64", "libm-fp64"},
{"libsycl-cmath", "libm-fp32"},
{"libsycl-cmath-fp64", "libm-fp64"},
#if defined(_WIN32)
{"libsycl-msvc-math", "libm-fp32"},
#endif
{"libsycl-imf", "libimf-fp32"},
{"libsycl-imf-fp64", "libimf-fp64"},
{"libsycl-imf-bf16", "libimf-bf16"}};
// For AOT compilation, we need to link sycl_device_fallback_libs as
// default too.
const SYCLDeviceLibsList SYCLDeviceFallbackLibs = {
{"libsycl-fallback-cassert", "libc"},
{"libsycl-fallback-cstring", "libc"},
{"libsycl-fallback-complex", "libm-fp32"},
{"libsycl-fallback-complex-fp64", "libm-fp64"},
{"libsycl-fallback-cmath", "libm-fp32"},
{"libsycl-fallback-cmath-fp64", "libm-fp64"},
{"libsycl-fallback-imf", "libimf-fp32"},
{"libsycl-fallback-imf-fp64", "libimf-fp64"},
{"libsycl-fallback-imf-bf16", "libimf-bf16"}};
const SYCLDeviceLibsList SYCLDeviceBfloat16FallbackLib = {
{"libsycl-fallback-bfloat16", "libm-bfloat16"}};
const SYCLDeviceLibsList SYCLDeviceBfloat16NativeLib = {
{"libsycl-native-bfloat16", "libm-bfloat16"}};
// ITT annotation libraries are linked in separately whenever the device
// code instrumentation is enabled.
const SYCLDeviceLibsList SYCLDeviceAnnotationLibs = {
{"libsycl-itt-user-wrappers", "internal"},
{"libsycl-itt-compiler-wrappers", "internal"},
{"libsycl-itt-stubs", "internal"}};
const SYCLDeviceLibsList SYCLNativeCpuDeviceLibs = {
{"libsycl-nativecpu_utils", "internal"}};

bool IsWindowsMSVCEnv =
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
bool IsNewOffload = C.getDriver().getUseNewOffloadingDriver();
StringRef LibSuffix = ".bc";
if (IsNewOffload)
// For new offload model, we use packaged .bc files.
LibSuffix = IsWindowsMSVCEnv ? ".new.obj" : ".new.o";
auto addLibraries = [&](const SYCLDeviceLibsList &LibsList) {
for (const DeviceLibOptInfo &Lib : LibsList) {
if (!DeviceLibLinkInfo[Lib.DeviceLibOption])
continue;
SmallString<128> LibName(Lib.DeviceLibName);
llvm::sys::path::replace_extension(LibName, LibSuffix);
LibraryList.push_back(Args.MakeArgString(LibName));
}
};

addLibraries(SYCLDeviceWrapperLibs);
if (IsSpirvAOT)
addLibraries(SYCLDeviceFallbackLibs);

bool NativeBfloatLibs;
bool NeedBfloatLibs = selectBfloatLibs(TargetTriple, C, NativeBfloatLibs);
if (NeedBfloatLibs) {
// Add native or fallback bfloat16 library.
if (NativeBfloatLibs)
addLibraries(SYCLDeviceBfloat16NativeLib);
else
addLibraries(SYCLDeviceBfloat16FallbackLib);
}

// Link in ITT annotations library unless fsycl-no-instrument-device-code
// is specified. This ensures that we are ABI-compatible with the
// instrumented device code, which was the default not so long ago.
if (Args.hasFlag(options::OPT_fsycl_instrument_device_code,
options::OPT_fno_sycl_instrument_device_code, true))
addLibraries(SYCLDeviceAnnotationLibs);

// Currently, device sanitizer support is required by some developers on
// Linux platform only, so compiler only provides device sanitizer libraries
// on Linux platform.
#if !defined(_WIN32)
addSYCLDeviceSanitizerLibs(C, IsSpirvAOT, LibSuffix, LibraryList);
#endif

if (TargetTriple.isNativeCPU())
addLibraries(SYCLNativeCpuDeviceLibs);

return LibraryList;
}

// Get the list of SYCL device libraries to link with user's device image.
SmallVector<std::string, 8>
SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
bool IsSpirvAOT) {
SmallVector<std::string, 8> LibraryList;
const llvm::opt::ArgList &Args = C.getArgs();
if (Args.getLastArg(options::OPT_fsycl_device_lib_EQ,
options::OPT_fno_sycl_device_lib_EQ) ||
Args.getLastArg(options::OPT_fsycl_device_lib_jit_link,
options::OPT_fno_sycl_device_lib_jit_link))
return getDeviceLibrariesLegacy(C, TargetTriple, IsSpirvAOT);

bool NoOffloadLib =
!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true);
if (TargetTriple.isNVPTX()) {
Expand Down
8 changes: 0 additions & 8 deletions clang/test/Driver/sycl-deprecated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,3 @@
// RUN: %clangxx -fsycl -fsycl-fp32-prec-sqrt %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_REPLACE -DOPTION=-fsycl-fp32-prec-sqrt -DOPTION_REPLACE=-foffload-fp32-prec-sqrt
// RUN: %clangxx -fsycl -fsycl-dump-device-code=/path/to/spv/ %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_REPLACE -DOPTION=-fsycl-dump-device-code=/path/to/spv/ -DOPTION_REPLACE=-save-offload-code=/path/to/spv/
// CHECK_REPLACE: option '[[OPTION]]' is deprecated and will be removed in a future release, use '[[OPTION_REPLACE]]' instead

// RUN: %clangxx -fsycl -fsycl-device-lib-jit-link %s -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK -DOPTION=-fsycl-device-lib-jit-link
// RUN: %clangxx -fsycl -fsycl-device-lib=libc %s -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK -DOPTION=-fsycl-device-lib=libc
// RUN: %clangxx -fsycl -fno-sycl-device-lib=libc %s -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK -DOPTION=-fno-sycl-device-lib=libc

23 changes: 0 additions & 23 deletions clang/test/Driver/sycl-device-lib-amdgcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@

// UNSUPPORTED: system-windows

// Check that the -fsycl-device-lib flag has no effect when "all" is specified.
// RUN: %clangxx -ccc-print-phases -std=c++11 -fsycl -fsycl-device-lib=all --sysroot=%S/Inputs/SYCL \
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx906 %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-ALL %s

// Check that the -fsycl-device-lib flag has no effect when subsets of libs
// are specified.
// RUN: %clangxx -ccc-print-phases -std=c++11 --sysroot=%S/Inputs/SYCL \
// RUN: -fsycl -fsycl-device-lib=libc,libm-fp32,libm-fp64,libimf-fp32,libimf-fp64,libimf-bf16,libm-bfloat16 \
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx906 %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-ALL %s

// Check that -fno-sycl-device-lib is ignored when it does not contain "all".
// A warning should be printed that the flag got ignored.
// RUN: %clangxx -ccc-print-phases -std=c++11 -fsycl --sysroot=%S/Inputs/SYCL \
// RUN: -fno-sycl-device-lib=libc,libm-fp32,libm-fp64,libimf-fp32,libimf-fp64,libimf-bf16,libm-bfloat16 \
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx906 %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHK-UNUSED-WARN,CHK-ALL %s

// CHK-UNUSED-WARN: warning: argument unused during compilation: '-fno-sycl-device-lib='
// CHK-ALL: [[DEVLIB:[0-9]+]]: input, "{{.*}}devicelib-amdgcn-amd-amdhsa.bc", ir, (device-sycl, gfx906)
// CHK-ALL: {{[0-9]+}}: linker, {{{.*}}[[DEVLIB]]{{.*}}}, ir, (device-sycl, gfx906)

// Check that llvm-link uses the "-only-needed" flag.
// Not using the flag breaks kernel bundles.
// RUN: %clangxx -### -fsycl -fsycl-targets=amdgcn-amd-amdhsa -fno-sycl-libspirv --sysroot=%S/Inputs/SYCL \
Expand Down
23 changes: 0 additions & 23 deletions clang/test/Driver/sycl-device-lib-nvptx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@

// UNSUPPORTED: system-windows

// Check that the -fsycl-device-lib flag has no effect when "all" is specified.
// RUN: %clangxx -ccc-print-phases -std=c++11 -fsycl -fsycl-device-lib=all --sysroot=%S/Inputs/SYCL \
// RUN: -fsycl-targets=nvptx64-nvidia-cuda %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-ALL %s

// Check that the -fsycl-device-lib flag has no effect when subsets of libs
// are specified.
// RUN: %clangxx -ccc-print-phases -std=c++11 --sysroot=%S/Inputs/SYCL \
// RUN: -fsycl -fsycl-device-lib=libc,libm-fp32,libm-fp64,libimf-fp32,libimf-fp64,libimf-bf16,libm-bfloat16 \
// RUN: -fsycl-targets=nvptx64-nvidia-cuda %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-ALL %s

// Check that -fno-sycl-device-lib is ignored when it does not contain "all".
// A warning should be printed that the flag got ignored.
// RUN: %clangxx -ccc-print-phases -std=c++11 -fsycl --sysroot=%S/Inputs/SYCL \
// RUN: -fno-sycl-device-lib=libc,libm-fp32,libm-fp64,libimf-fp32,libimf-fp64,libimf-bf16,libm-bfloat16 \
// RUN: -fsycl-targets=nvptx64-nvidia-cuda %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHK-UNUSED-WARN,CHK-ALL %s

// CHK-UNUSED-WARN: warning: argument unused during compilation: '-fno-sycl-device-lib='
// CHK-ALL: [[DEVLIB:[0-9]+]]: input, "{{.*}}devicelib-nvptx64-nvidia-cuda.bc", ir, (device-sycl, sm_50)
// CHK-ALL: {{[0-9]+}}: linker, {{{.*}}[[DEVLIB]]{{.*}}}, ir, (device-sycl, sm_50)

// Check that llvm-link uses the "-only-needed" flag.
// Not using the flag breaks kernel bundles.
// RUN: %clangxx -### --cuda-path=%S/Inputs/CUDA/usr/local/cuda -fno-sycl-libspirv --sysroot=%S/Inputs/SYCL \
Expand Down
Loading
Loading