Skip to content

Commit 68fa250

Browse files
committed
Fix tests and move user specified options towards the end of the sycl-post-link command line
Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent ce71e8c commit 68fa250

File tree

5 files changed

+43
-56
lines changed

5 files changed

+43
-56
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10738,14 +10738,6 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA,
1073810738
ArgStringList CmdArgs;
1073910739

1074010740
llvm::Triple T = getToolChain().getTriple();
10741-
const toolchains::SYCLToolChain &TC =
10742-
static_cast<const toolchains::SYCLToolChain &>(getToolChain());
10743-
10744-
// Handle -Xdevice-post-link
10745-
TC.TranslateTargetOpt(T, TCArgs, CmdArgs, options::OPT_Xdevice_post_link,
10746-
options::OPT_Xdevice_post_link_EQ,
10747-
JA.getOffloadingArch());
10748-
1074910741
getNonTripleBasedSYCLPostLinkOpts(getToolChain(), JA, TCArgs, CmdArgs);
1075010742
getTripleBasedSYCLPostLinkOpts(getToolChain(), TCArgs, CmdArgs, T,
1075110743
SYCLPostLink->getRTSetsSpecConstants(),
@@ -10758,6 +10750,14 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA,
1075810750
if (T.getSubArch() == llvm::Triple::SPIRSubArch_gen && Device.data())
1075910751
OutputArg = ("intel_gpu_" + Device + "," + OutputArg).str();
1076010752

10753+
const toolchains::SYCLToolChain &TC =
10754+
static_cast<const toolchains::SYCLToolChain &>(getToolChain());
10755+
10756+
// Handle -Xdevice-post-link
10757+
TC.TranslateTargetOpt(T, TCArgs, CmdArgs, options::OPT_Xdevice_post_link,
10758+
options::OPT_Xdevice_post_link_EQ,
10759+
JA.getOffloadingArch());
10760+
1076110761
addArgs(CmdArgs, TCArgs, {"-o", OutputArg});
1076210762

1076310763
// Add input file
@@ -11112,14 +11112,14 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1111211112
// --sycl-post-link-options="options" provides a string of options to be
1111311113
// passed along to the sycl-post-link tool during device link.
1111411114
SmallString<128> PostLinkOptString;
11115-
if (Args.hasArg(options::OPT_Xdevice_post_link)) {
11116-
for (const auto &A : Args.getAllArgValues(options::OPT_Xdevice_post_link))
11117-
appendOption(PostLinkOptString, A);
11118-
}
1111911115
ArgStringList PostLinkArgs;
1112011116
getNonTripleBasedSYCLPostLinkOpts(getToolChain(), JA, Args, PostLinkArgs);
1112111117
for (const auto &A : PostLinkArgs)
1112211118
appendOption(PostLinkOptString, A);
11119+
if (Args.hasArg(options::OPT_Xdevice_post_link)) {
11120+
for (const auto &A : Args.getAllArgValues(options::OPT_Xdevice_post_link))
11121+
appendOption(PostLinkOptString, A);
11122+
}
1112311123
if (!PostLinkOptString.empty())
1112411124
CmdArgs.push_back(
1112511125
Args.MakeArgString("--sycl-post-link-options=" + PostLinkOptString));

clang/test/Driver/linker-wrapper-sycl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// CHK-CMDS: "{{.*}}spirv-to-ir-wrapper" {{.*}} -o [[FIRSTLLVMLINKIN:.*]].bc --llvm-spirv-opts=--spirv-preserve-auxdata --llvm-spirv-opts=--spirv-target-env=SPV-IR --llvm-spirv-opts=--spirv-builtin-format=global
66
// CHK-CMDS-NEXT: "{{.*}}llvm-link" [[FIRSTLLVMLINKIN:.*]].bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
77
// CHK-CMDS-NEXT: "{{.*}}llvm-link" -only-needed [[FIRSTLLVMLINKOUT]].bc {{.*}}.bc {{.*}}.bc -o [[SECONDLLVMLINKOUT:.*]].bc --suppress-warnings
8-
// CHK-CMDS-NEXT: "{{.*}}sycl-post-link" SYCL_POST_LINK_OPTIONS {{.*}} -o [[SYCLPOSTLINKOUT:.*]].table [[SECONDLLVMLINKOUT]].bc
8+
// CHK-CMDS-NEXT: "{{.*}}sycl-post-link"{{.*}} SYCL_POST_LINK_OPTIONS -o [[SYCLPOSTLINKOUT:.*]].table [[SECONDLLVMLINKOUT]].bc
99
// LLVM-SPIRV is not called in dry-run
1010
// CHK-CMDS-NEXT: offload-wrapper: input: [[LLVMSPIRVOUT:.*]].table, output: [[WRAPPEROUT:.*]].bc
1111
// CHK-CMDS-NEXT: "{{.*}}llc" -filetype=obj -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
// REQUIRES: system-windows
22
/// Verify same set of sycl-post-link options generated for old and new offloading model
3-
// Test for JIT compilation
4-
// RUN: %clangxx --target=x86_64-pc-windows-msvc -fsycl --offload-new-driver \
5-
// RUN: -Xdevice-post-link -O0 -v %s 2>&1 \
6-
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT %s
7-
// RUN: %clangxx --target=x86_64-pc-windows-msvc -fsycl --no-offload-new-driver \
8-
// RUN: -Xdevice-post-link -O0 -v %s 2>&1 \
9-
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT %s
10-
// OPTIONS_POSTLINK_JIT: sycl-post-link{{.*}} -O0 -O2 -device-globals -spec-const=native -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -split-esimd -lower-esimd
3+
// RUN: %clangxx -### --target=x86_64-pc-windows-msvc -fsycl \
4+
// RUN: -Xdevice-post-link -O0 %s 2>&1 \
5+
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT_OLD %s
6+
// OPTIONS_POSTLINK_JIT_OLD: sycl-post-link{{.*}} "-O2" "-device-globals" "-spec-const=native" "-split=auto" "-emit-only-kernels-as-entry-points" "-emit-param-info" "-symbols" "-emit-exported-symbols" "-split-esimd" "-lower-esimd" "-O0"
117

12-
#include <sycl/sycl.hpp>
13-
using namespace sycl;
14-
15-
int main(void) {
16-
sycl::queue queue;
17-
sycl::event event = queue.submit([&](sycl::handler &cgh) {
18-
cgh.parallel_for<class set_range>(sycl::range<1>{16},
19-
[=](sycl::id<1> idx) {});
20-
});
21-
return 0;
22-
}
8+
// RUN: %clang -cc1 %s -triple x86_64-pc-windows-msvc -emit-obj -o %t.elf.o
9+
// RUN: clang-offload-packager -o %t.out --image=file=%t.elf.o,kind=sycl,triple=spir64
10+
// RUN: %clang -cc1 %s -triple x86_64-pc-windows-msvc -emit-obj -o %t.o \
11+
// RUN: -fembed-offload-object=%t.out
12+
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-pc-windows-msvc \
13+
// RUN: -sycl-device-library-location=%S/Inputs -sycl-device-libraries=libsycl-crt.new.obj \
14+
// RUN: --sycl-post-link-options="-O2 -device-globals -O0" \
15+
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_POSTLINK_JIT_NEW %s
16+
// OPTIONS_POSTLINK_JIT_NEW: sycl-post-link{{.*}} -spec-const=native -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -split-esimd -lower-esimd -O2 -device-globals -O0
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
// REQUIRES: system-linux
22
/// Verify same set of sycl-post-link options generated for old and new offloading model
3-
// Test for JIT compilation
4-
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
5-
// RUN: -Xdevice-post-link -O0 -v %s 2>&1 \
6-
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT %s
7-
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --no-offload-new-driver \
8-
// RUN: -Xdevice-post-link -O0 -v %s 2>&1 \
9-
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT %s
10-
// OPTIONS_POSTLINK_JIT: sycl-post-link{{.*}} -O0 -O2 -device-globals -spec-const=native -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -split-esimd -lower-esimd
3+
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl -### \
4+
// RUN: -Xdevice-post-link -O0 %s 2>&1 \
5+
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT_OLD %s
6+
// OPTIONS_POSTLINK_JIT_OLD: sycl-post-link{{.*}} "-O2" "-device-globals" "-spec-const=native" "-split=auto" "-emit-only-kernels-as-entry-points" "-emit-param-info" "-symbols" "-emit-exported-symbols" "-split-esimd" "-lower-esimd" "-O0"
117

12-
#include <sycl/sycl.hpp>
13-
using namespace sycl;
14-
15-
int main(void) {
16-
sycl::queue queue;
17-
sycl::event event = queue.submit([&](sycl::handler &cgh) {
18-
cgh.parallel_for<class set_range>(sycl::range<1>{16},
19-
[=](sycl::id<1> idx) {});
20-
});
21-
return 0;
22-
}
8+
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.elf.o
9+
// RUN: clang-offload-packager -o %t.out --image=file=%t.elf.o,kind=sycl,triple=spir64
10+
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o \
11+
// RUN: -fembed-offload-object=%t.out
12+
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
13+
// RUN: -sycl-device-library-location=%S/Inputs -sycl-device-libraries=libsycl-crt.new.o \
14+
// RUN: --sycl-post-link-options="-O2 -device-globals -O0" \
15+
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_POSTLINK_JIT_NEW %s
16+
// OPTIONS_POSTLINK_JIT_NEW: sycl-post-link{{.*}} -spec-const=native -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -split-esimd -lower-esimd -O2 -device-globals -O0

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,15 @@ static Expected<StringRef> runSYCLPostLink(ArrayRef<StringRef> InputFiles,
604604
if (!TempFileOrErr)
605605
return TempFileOrErr.takeError();
606606

607+
SmallVector<StringRef, 8> CmdArgs;
608+
CmdArgs.push_back(*SYCLPostLinkPath);
609+
const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ));
610+
getTripleBasedSYCLPostLinkOpts(Args, CmdArgs, Triple);
607611
StringRef SYCLPostLinkOptions;
608612
if (Arg *A = Args.getLastArg(OPT_sycl_post_link_options_EQ))
609613
SYCLPostLinkOptions = A->getValue();
610-
611-
SmallVector<StringRef, 8> CmdArgs;
612-
CmdArgs.push_back(*SYCLPostLinkPath);
613614
SYCLPostLinkOptions.split(CmdArgs, " ", /* MaxSplit = */ -1,
614615
/* KeepEmpty = */ false);
615-
const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ));
616-
getTripleBasedSYCLPostLinkOpts(Args, CmdArgs, Triple);
617616
CmdArgs.push_back("-o");
618617
CmdArgs.push_back(*TempFileOrErr);
619618
for (auto &File : InputFiles)

0 commit comments

Comments
 (0)