Skip to content

Commit 1bee8f1

Browse files
committed
[SYCL] Forward some triple dependent options to clang-linker-wrapper
1 parent c0f8a08 commit 1bee8f1

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11341,6 +11341,23 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1134111341
CmdArgs.push_back(
1134211342
Args.MakeArgString("--sycl-post-link-options=" + PostLinkOptString));
1134311343

11344+
if (Args.hasArg(options::OPT_fsycl_remove_unused_external_funcs))
11345+
CmdArgs.push_back(
11346+
Args.MakeArgString("-sycl-remove-unused-external-funcs"));
11347+
if (Args.hasArg(options::OPT_fno_sycl_remove_unused_external_funcs))
11348+
CmdArgs.push_back(
11349+
Args.MakeArgString("-no-sycl-remove-unused-external-funcs"));
11350+
if (Args.hasArg(options::OPT_fsycl_device_code_split_esimd))
11351+
CmdArgs.push_back(Args.MakeArgString("-sycl-device-code-split-esimd"));
11352+
if (Args.hasArg(options::OPT_fno_sycl_device_code_split_esimd))
11353+
CmdArgs.push_back(Args.MakeArgString("-no-sycl-device-code-split-esimd"));
11354+
if (Args.hasArg(options::OPT_fsycl_add_default_spec_consts_image))
11355+
CmdArgs.push_back(
11356+
Args.MakeArgString("-sycl-add-default-spec-consts-image"));
11357+
if (Args.hasArg(options::OPT_fno_sycl_add_default_spec_consts_image))
11358+
CmdArgs.push_back(
11359+
Args.MakeArgString("-no-sycl-add-default-spec-consts-image"));
11360+
1134411361
// --llvm-spirv-options="options" provides a string of options to be passed
1134511362
// along to the llvm-spirv (translation) step during device link.
1134611363
SmallString<128> OptString;

clang/test/Driver/sycl-post-link-options.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,52 @@
2929
// RUN: --sycl-post-link-options="-O2 -device-globals -O0" \
3030
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_POSTLINK_JIT_NEW_SYCLBIN %s
3131
// OPTIONS_POSTLINK_JIT_NEW_SYCLBIN: sycl-post-link{{.*}} -spec-const=native -properties -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-kernel-names -emit-exported-symbols -emit-imported-symbols -split-esimd -lower-esimd -O2 -device-globals -O0
32+
//
33+
// Ensure driver forwards these triple based options to clang-linker-wrapper.
34+
//
35+
// RUN: %clangxx %s -### -fsycl --offload-new-driver \
36+
// RUN: -fsycl-remove-unused-external-funcs \
37+
// RUN: -fsycl-device-code-split-esimd \
38+
// RUN: -fsycl-add-default-spec-consts-image \
39+
// RUN: 2>&1 | FileCheck --check-prefix=OPTIONS_FORWARD %s
40+
// OPTIONS_FORWARD: clang-linker-wrapper{{.*}} "-sycl-remove-unused-external-funcs" "-sycl-device-code-split-esimd" "-sycl-add-default-spec-consts-image"
41+
//
42+
// RUN: %clangxx %s -### -fsycl --offload-new-driver \
43+
// RUN: -fno-sycl-remove-unused-external-funcs \
44+
// RUN: -fno-sycl-device-code-split-esimd \
45+
// RUN: -fno-sycl-add-default-spec-consts-image \
46+
// RUN: 2>&1 | FileCheck --check-prefix=OPTIONS_FORWARD_NO %s
47+
// OPTIONS_FORWARD_NO: clang-linker-wrapper{{.*}} "-no-sycl-remove-unused-external-funcs" "-no-sycl-device-code-split-esimd" "-no-sycl-add-default-spec-consts-image"
48+
//
49+
// Check -no-sycl-remove-unused-external-funcs option disables emitting
50+
// -emit-only-kernels-as-entry-points in sycl-post-link.
51+
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
52+
// RUN: -sycl-device-libraries=%t.devicelib.o \
53+
// RUN: -no-sycl-remove-unused-external-funcs \
54+
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_NO_EMIT_ONLY_KERNELS %s
55+
// OPTIONS_NO_EMIT_ONLY_KERNELS: sycl-post-link{{.*}} -spec-const=native -properties -split=auto -emit-param-info -symbols -emit-exported-symbols -emit-imported-symbols -split-esimd -lower-esimd
56+
//
57+
// Check -no-sycl-device-code-split-esimd option disables emitting
58+
// -split-esimd in sycl-post-link.
59+
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
60+
// RUN: -sycl-device-libraries=%t.devicelib.o \
61+
// RUN: -no-sycl-device-code-split-esimd \
62+
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_NO_SPLIT_ESIMD %s
63+
// OPTIONS_NO_SPLIT_ESIMD: sycl-post-link{{.*}} -spec-const=native -properties -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -emit-imported-symbols -lower-esimd
64+
//
65+
// Generate AOT .o file as linker wrapper input.
66+
//
67+
// RUN: %clang %s -fsycl -fsycl-targets=spir64_gen-unknown-unknown -c --offload-new-driver -o %t_aot.o
68+
//
69+
// Generate AOT .o file as SYCL device library file.
70+
//
71+
// RUN: touch %t.devicelib.cpp
72+
// RUN: %clang %t.devicelib.cpp -fsycl -fsycl-targets=spir64_gen-unknown-unknown -c --offload-new-driver -o %t.devicelib_aot.o
73+
//
74+
// Check -sycl-add-default-spec-consts-image option enables emitting
75+
// -generate-device-image-default-spec-consts in sycl-post-link.
76+
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
77+
// RUN: -sycl-device-libraries=%t.devicelib_aot.o \
78+
// RUN: -sycl-add-default-spec-consts-image \
79+
// RUN: --linker-path=/usr/bin/ld %t_aot.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_DEFAULT_SPEC_CONSTS %s
80+
// OPTIONS_DEFAULT_SPEC_CONSTS: sycl-post-link{{.*}} -spec-const=emulation -properties -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -emit-imported-symbols -split-esimd -lower-esimd -generate-device-image-default-spec-consts

0 commit comments

Comments
 (0)