diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 4c946b9a98fcf..6ecc1aaf1a75e 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -7057,6 +7057,8 @@ def fsycl_help_EQ : Joined<["-"], "fsycl-help=">, Flags<[NoXarchOption]>, def fsycl_help : Flag<["-"], "fsycl-help">, Alias, Flags<[NoXarchOption]>, AliasArgs<["all"]>, HelpText<"Emit help information from all of the offline compilation tools">; +def fsycl_libdevice_path_EQ : Joined<["-"], "fsycl-libdevice-path=">, + Visibility<[ClangOption]>, HelpText<"Path to libdevice library">; def fsycl_libspirv_path_EQ : Joined<["-"], "fsycl-libspirv-path=">, HelpText<"Path to libspirv library">; def fno_sycl_libspirv : Flag<["-"], "fno-sycl-libspirv">, diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index b0d75b1923224..9bbaa1c499295 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5745,7 +5745,7 @@ class OffloadingActionBuilder final { SYCLDeviceLibLinked = addSYCLDeviceLibs( TC, SYCLDeviceLibs, UseAOTLink, C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(), - IsSYCLNativeCPU, NativeCPULib, BoundArch); + IsSYCLNativeCPU, NativeCPULib, BoundArch, Args); } JobAction *LinkSYCLLibs = C.MakeAction(SYCLDeviceLibs, types::TY_LLVM_BC); @@ -6030,9 +6030,18 @@ class OffloadingActionBuilder final { bool addSYCLDeviceLibs(const ToolChain *TC, ActionList &DeviceLinkObjects, bool isSpirvAOT, bool isMSVCEnv, bool isNativeCPU, - Action *&NativeCPULib, const char *BoundArch) { + Action *&NativeCPULib, const char *BoundArch, + DerivedArgList &Args) { int NumOfDeviceLibLinked = 0; SmallVector, 4> LibLocCandidates; + if (Args.hasArg(options::OPT_fsycl_libdevice_path_EQ)) { + auto ProvidedPath = + Args.getLastArgValue(options::OPT_fsycl_libdevice_path_EQ).str(); + if (llvm::sys::fs::exists(ProvidedPath)) { + SmallString<128> ProvidedPathSS(ProvidedPath); + LibLocCandidates.push_back(ProvidedPathSS); + } + } SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates); SmallVector DeviceLibraries; diff --git a/clang/test/Driver/Inputs/SYCL/libsycl-nativecpu_utils.bc b/clang/test/Driver/Inputs/SYCL/libsycl-nativecpu_utils.bc new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/sycl-native-cpu-fsycl.cpp b/clang/test/Driver/sycl-native-cpu-fsycl.cpp index d4dafdf89b610..73cc09ea72b46 100644 --- a/clang/test/Driver/sycl-native-cpu-fsycl.cpp +++ b/clang/test/Driver/sycl-native-cpu-fsycl.cpp @@ -65,3 +65,10 @@ //CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "SYCL post link", inputs: ["[[LINK2]].bc"], output: "[[POSTL:.*]].table" //CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "offload wrapper", inputs: ["[[POSTL]].table"], output: "[[WRAP:.*]].o" //CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "{{.*}}::Linker", inputs: ["[[FILE1HOST]].o", "[[FILE2HOST]].o", "[[KERNELO]].o", "[[WRAP]].o"], output: "{{.*}}" + +// check that -fsycl-libdevice-path is used correctly +// RUN: %clangxx -ccc-print-phases -std=c++11 -fsycl -fsycl-targets=native_cpu \ +// RUN: -fno-sycl-device-lib=all -fsycl-libdevice-path=%S/Inputs/SYCL %s 2>&1 | FileCheck %s + +// CHECK: [[LIBNATIVECPU:[0-9]*]]: input, "{{.*}}Inputs/SYCL/libsycl-nativecpu_utils.bc", ir, (device-sycl) +// CHECK-NEXT: linker, {{{.*}}, [[LIBNATIVECPU]]}, ir, (device-sycl)