Skip to content

Commit 91b840c

Browse files
authored
[Driver][SYCL][NewOffloadModel] Hook up -fsycl-device-obj support (#13688)
The -fsycl-device-obj option is available to allow the user to specify if they want a different output binary with -fsycl based compilations. Default is to create LLVM-IR based device binaries, but when using -fsycl-device-obj=spirv, we will generate SPIR-V based binaries.
1 parent ccca3b7 commit 91b840c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7918,6 +7918,15 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
79187918
++TCAndArch;
79197919
}
79207920
}
7921+
// Use of -fsycl-device-obj=spirv converts the original LLVM-IR file to
7922+
// SPIR-V for later consumption.
7923+
for (Action *&A : DeviceActions) {
7924+
if (!Args.getLastArgValue(options::OPT_fsycl_device_obj_EQ)
7925+
.equals_insensitive("spirv") ||
7926+
Kind != Action::OFK_SYCL || A->getType() != types::TY_LLVM_BC)
7927+
continue;
7928+
A = C.MakeAction<SPIRVTranslatorJobAction>(A, types::TY_SPIRV);
7929+
}
79217930

79227931
// Compiling HIP in non-RDC mode requires linking each action individually.
79237932
for (Action *&A : DeviceActions) {

clang/test/Driver/sycl-offload-new-driver.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@
3838
// WRAPPER_OPTIONS-SAME: "-sycl-device-libraries=libsycl-crt.new.o,libsycl-complex.new.o,libsycl-complex-fp64.new.o,libsycl-cmath.new.o,libsycl-cmath-fp64.new.o,libsycl-imf.new.o,libsycl-imf-fp64.new.o,libsycl-imf-bf16.new.o,libsycl-itt-user-wrappers.new.o,libsycl-itt-compiler-wrappers.new.o,libsycl-itt-stubs.new.o"
3939
// WRAPPER_OPTIONS-SAME: "-sycl-device-library-location={{.*}}/lib"
4040

41+
/// Verify phases used to generate SPIR-V instead of LLVM-IR
42+
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
43+
// RUN: -fsycl-device-obj=spirv -ccc-print-phases %s 2>&1 \
44+
// RUN: | FileCheck -check-prefix SPIRV_OBJ %s
45+
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
46+
// RUN: -fsycl-device-only -fsycl-device-obj=spirv \
47+
// RUN: -ccc-print-phases %s 2>&1 \
48+
// RUN: | FileCheck -check-prefix SPIRV_OBJ %s
49+
// SPIRV_OBJ: [[#SPVOBJ:]]: input, "{{.*}}", c++, (device-sycl)
50+
// SPIRV_OBJ: [[#SPVOBJ+1]]: preprocessor, {[[#SPVOBJ]]}, c++-cpp-output, (device-sycl)
51+
// SPIRV_OBJ: [[#SPVOBJ+2]]: compiler, {[[#SPVOBJ+1]]}, ir, (device-sycl)
52+
// SPIRV_OBJ: [[#SPVOBJ+3]]: backend, {[[#SPVOBJ+2]]}, ir, (device-sycl)
53+
// SPIRV_OBJ: [[#SPVOBJ+4]]: llvm-spirv, {[[#SPVOBJ+3]]}, spirv, (device-sycl)
54+
// SPIRV_OBJ: [[#SPVOBJ+5]]: offload, "device-sycl (spir64-unknown-unknown)" {[[#SPVOBJ+4]]}, {{.*}}
55+
4156
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
4257
// RUN: -Xspirv-translator -translator-opt -### %s 2>&1 \
4358
// RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_TRANSLATOR %s

0 commit comments

Comments
 (0)