Skip to content

Commit ca74702

Browse files
committed
Add driver option for libdevice path
1 parent e9143ca commit ca74702

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7057,6 +7057,8 @@ def fsycl_help_EQ : Joined<["-"], "fsycl-help=">, Flags<[NoXarchOption]>,
70577057
def fsycl_help : Flag<["-"], "fsycl-help">, Alias<fsycl_help_EQ>,
70587058
Flags<[NoXarchOption]>, AliasArgs<["all"]>,
70597059
HelpText<"Emit help information from all of the offline compilation tools">;
7060+
def fsycl_libdevice_path_EQ : Joined<["-"], "fsycl-libdevice-path=">,
7061+
Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>, HelpText<"Path to libdevice library">;
70607062
def fsycl_libspirv_path_EQ : Joined<["-"], "fsycl-libspirv-path=">,
70617063
HelpText<"Path to libspirv library">;
70627064
def fno_sycl_libspirv : Flag<["-"], "fno-sycl-libspirv">,

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5745,7 +5745,7 @@ class OffloadingActionBuilder final {
57455745
SYCLDeviceLibLinked = addSYCLDeviceLibs(
57465746
TC, SYCLDeviceLibs, UseAOTLink,
57475747
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(),
5748-
IsSYCLNativeCPU, NativeCPULib, BoundArch);
5748+
IsSYCLNativeCPU, NativeCPULib, BoundArch, Args);
57495749
}
57505750
JobAction *LinkSYCLLibs =
57515751
C.MakeAction<LinkJobAction>(SYCLDeviceLibs, types::TY_LLVM_BC);
@@ -6030,9 +6030,17 @@ class OffloadingActionBuilder final {
60306030

60316031
bool addSYCLDeviceLibs(const ToolChain *TC, ActionList &DeviceLinkObjects,
60326032
bool isSpirvAOT, bool isMSVCEnv, bool isNativeCPU,
6033-
Action *&NativeCPULib, const char *BoundArch) {
6033+
Action *&NativeCPULib, const char *BoundArch, DerivedArgList &Args) {
60346034
int NumOfDeviceLibLinked = 0;
60356035
SmallVector<SmallString<128>, 4> LibLocCandidates;
6036+
if(Args.hasArg(options::OPT_fsycl_libdevice_path_EQ)) {
6037+
auto ProvidedPath =
6038+
Args.getLastArgValue(options::OPT_fsycl_libdevice_path_EQ).str();
6039+
if (llvm::sys::fs::exists(ProvidedPath)) {
6040+
SmallString<128> ProvidedPathSS(ProvidedPath);
6041+
LibLocCandidates.push_back(ProvidedPathSS);
6042+
}
6043+
}
60366044
SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates);
60376045

60386046
SmallVector<std::string, 8> DeviceLibraries;

clang/test/Driver/Inputs/SYCL/libsycl-nativecpu_utils.bc

Whitespace-only changes.

clang/test/Driver/sycl-native-cpu-fsycl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,10 @@
6565
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "SYCL post link", inputs: ["[[LINK2]].bc"], output: "[[POSTL:.*]].table"
6666
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "offload wrapper", inputs: ["[[POSTL]].table"], output: "[[WRAP:.*]].o"
6767
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "{{.*}}::Linker", inputs: ["[[FILE1HOST]].o", "[[FILE2HOST]].o", "[[KERNELO]].o", "[[WRAP]].o"], output: "{{.*}}"
68+
69+
// check that -fsycl-libdevice-path is used correctly
70+
// RUN: %clangxx -ccc-print-phases -std=c++11 -fsycl -fsycl-targets=native_cpu \
71+
// RUN: -fno-sycl-device-lib=all -fsycl-libdevice-path=%S/Inputs/SYCL %s 2>&1 | FileCheck %s
72+
73+
// CHECK: [[LIBNATIVECPU:[0-9]*]]: input, "{{.*}}Inputs/SYCL/libsycl-nativecpu_utils.bc", ir, (device-sycl)
74+
// CHECK-NEXT: linker, {{{.*}}, [[LIBNATIVECPU]]}, ir, (device-sycl)

0 commit comments

Comments
 (0)