Skip to content

Commit 2623abe

Browse files
authored
[Driver][SYCL] Fix processing when using -fsycl-link (#1765)
When using -fsycl-link, the expectation is for the generated object file to be able to be linked in by a non-SYCL enabled compiler/linker. The generated object did not contain the proper device binary. Fix this up to go through all of the proper steps to create the wrapped .spv. Signed-off-by: Michael D Toguchi <michael.d.toguchi@intel.com>
1 parent 9e9faf9 commit 2623abe

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,12 +3549,21 @@ class OffloadingActionBuilder final {
35493549
for (auto SDA : SYCLDeviceActions)
35503550
SYCLLinkBinaryList.push_back(SDA);
35513551
if (WrapDeviceOnlyBinary) {
3552-
auto *DeviceLinkAction =
3553-
C.MakeAction<LinkJobAction>(SYCLLinkBinaryList, types::TY_Image);
3554-
// Wrap the binary when -fsycl-link is given
3555-
SYCLLinkBinary =
3556-
C.MakeAction<OffloadWrapperJobAction>(DeviceLinkAction,
3557-
types::TY_Object);
3552+
// -fsycl-link behavior does the following to the unbundled device
3553+
// binaries:
3554+
// 1) Link them together using llvm-link
3555+
// 2) Pass the linked binary through sycl-post-link
3556+
// 3) Translate final .bc file to .spv
3557+
// 4) Wrap the binary with the offload wrapper which can be used
3558+
// by any compilation link step.
3559+
auto *DeviceLinkAction = C.MakeAction<LinkJobAction>(
3560+
SYCLLinkBinaryList, types::TY_Image);
3561+
auto *PostLinkAction = C.MakeAction<SYCLPostLinkJobAction>(
3562+
DeviceLinkAction, types::TY_LLVM_BC);
3563+
auto *TranslateAction = C.MakeAction<SPIRVTranslatorJobAction>(
3564+
PostLinkAction, types::TY_Image);
3565+
SYCLLinkBinary = C.MakeAction<OffloadWrapperJobAction>(
3566+
TranslateAction, types::TY_Object);
35583567
} else {
35593568
auto *Link = C.MakeAction<LinkJobAction>(SYCLLinkBinaryList,
35603569
types::TY_Image);

clang/test/Driver/sycl-offload.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,10 @@
423423
// CHK-LINK-UB: 0: input, "[[INPUT:.+\.o]]", object
424424
// CHK-LINK-UB: 1: clang-offload-unbundler, {0}, object
425425
// CHK-LINK-UB: 2: linker, {1}, image, (device-sycl)
426-
// CHK-LINK-UB: 3: clang-offload-wrapper, {2}, object, (device-sycl)
427-
// CHK-LINK-UB: 4: offload, "device-sycl (spir64-unknown-unknown-sycldevice{{.*}})" {3}, object
426+
// CHK-LINK-UB: 3: sycl-post-link, {2}, ir, (device-sycl)
427+
// CHK-LINK-UB: 4: llvm-spirv, {3}, image, (device-sycl)
428+
// CHK-LINK-UB: 5: clang-offload-wrapper, {4}, object, (device-sycl)
429+
// CHK-LINK-UB: 6: offload, "device-sycl (spir64-unknown-unknown-sycldevice)" {5}, object
428430

429431
/// ###########################################################################
430432

@@ -437,8 +439,10 @@
437439
// CHK-LINK: 1: preprocessor, {0}, cpp-output, (device-sycl)
438440
// CHK-LINK: 2: compiler, {1}, ir, (device-sycl)
439441
// CHK-LINK: 3: linker, {2}, image, (device-sycl)
440-
// CHK-LINK: 4: clang-offload-wrapper, {3}, object, (device-sycl)
441-
// CHK-LINK: 5: offload, "device-sycl (spir64-unknown-unknown-sycldevice{{.*}})" {4}, object
442+
// CHK-LINK: 4: sycl-post-link, {3}, ir, (device-sycl)
443+
// CHK-LINK: 5: llvm-spirv, {4}, image, (device-sycl)
444+
// CHK-LINK: 6: clang-offload-wrapper, {5}, object, (device-sycl)
445+
// CHK-LINK: 7: offload, "device-sycl (spir64-unknown-unknown-sycldevice)" {6}, object
442446

443447
/// ###########################################################################
444448

0 commit comments

Comments
 (0)