Skip to content

Commit c63b49d

Browse files
authored
[Driver][SYCL] Address issue with improper bundler call with -fsycl-link (#13002)
The initial change to modify -fsycl-link for AOT introduced a modification to the general toolchain flow that is more aligned with the host link step. This caused a disconnect with the unbundling step from objects where we were unbundling for host and target, but not providing the needed output files. Fix this up to allow for both the host and target output files to be available. There is an additional fix that will be needed to restrict this (i.e. only unbundle the target, and not the host), but functionally what we have in place takes care of the immediate problem at hand.
1 parent 161c25d commit c63b49d

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5048,7 +5048,7 @@ class OffloadingActionBuilder final {
50485048
SYCLDeviceActions.clear();
50495049

50505050
if (WrapDeviceOnlyBinary)
5051-
return ABRT_Success;
5051+
return ABRT_Ignore_Host;
50525052
auto *Link =
50535053
C.MakeAction<LinkJobAction>(SYCLLinkBinaryList, types::TY_Image);
50545054
SYCLLinkBinary =
@@ -6747,9 +6747,8 @@ class OffloadingActionBuilder final {
67476747
return false;
67486748
if (HasFPGATarget && !updateInputForFPGA(A, InputArg, Args))
67496749
return false;
6750-
// FIXME - unbundling action is being split into two different actions
6751-
// when unbundling objects. One action for the host, the other for the
6752-
// device.
6750+
// FIXME - unbundling action with -fsycl-link is unbundling for both host
6751+
// and device, where only the device is needed.
67536752
auto UnbundlingHostAction = C.MakeAction<OffloadUnbundlingJobAction>(
67546753
A, (HasSPIRTarget && HostAction->getType() == types::TY_Archive)
67556754
? types::TY_Tempfilelist
@@ -7323,7 +7322,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
73237322
ExtractAPIJobAction *ExtractAPIAction = nullptr;
73247323
ActionList LinkerInputs;
73257324
ActionList MergerInputs;
7326-
ActionList DeviceAOTLinkerInputs;
73277325
ActionList HostActions;
73287326
llvm::SmallVector<const Arg *, 6> LinkerInputArgs;
73297327
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL;
@@ -7360,17 +7358,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
73607358
if (Phase == phases::Link) {
73617359
assert(Phase == PL.back() && "linking must be final compilation step.");
73627360

7363-
// When performing -fsycl-link the current inputs are not expected to
7364-
// be passed to the final host link step. Instead, take these inputs
7365-
// and redirect them to the associated wrapping step to create the
7366-
// final object.
7367-
if (C.getInputArgs().hasArg(options::OPT_fsycl_link_EQ) &&
7368-
!Args.hasArg(options::OPT_fintelfpga)) {
7369-
DeviceAOTLinkerInputs.push_back(Current);
7370-
Current = nullptr;
7371-
break;
7372-
}
7373-
73747361
// We don't need to generate additional link commands if emitting AMD
73757362
// bitcode or compiling only for the offload device
73767363
if (!(C.getInputArgs().hasArg(options::OPT_hip_link) &&
@@ -7516,11 +7503,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
75167503
if (!UseNewOffloadingDriver &&
75177504
getFinalPhase(Args, &FinalPhaseArg) == phases::Link &&
75187505
!Args.hasArg(options::OPT_fsycl_link_targets_EQ)) {
7519-
if (LinkerInputs.empty() && DeviceAOTLinkerInputs.empty())
7520-
OffloadBuilder->appendDeviceLinkActions(Actions);
7521-
7522-
if (!DeviceAOTLinkerInputs.empty() &&
7523-
Args.hasArg(options::OPT_fsycl_link_EQ) &&
7506+
if (Args.hasArg(options::OPT_fsycl_link_EQ) &&
75247507
!Args.hasArg(options::OPT_fintelfpga)) {
75257508
ActionList LAList;
75267509
OffloadBuilder->makeHostLinkDeviceOnlyAction(LAList);
@@ -7529,7 +7512,8 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
75297512
LA = OffloadBuilder->processHostLinkAction(LA);
75307513
Actions.push_back(LA);
75317514
}
7532-
}
7515+
} else if (LinkerInputs.empty())
7516+
OffloadBuilder->appendDeviceLinkActions(Actions);
75337517
}
75347518

75357519
if (!LinkerInputs.empty()) {
@@ -9017,6 +9001,7 @@ InputInfoList Driver::BuildJobsForActionNoCache(
90179001
InputInfo CurI;
90189002
bool IsFPGAObjLink =
90199003
(JA->getType() == types::TY_Object &&
9004+
EffectiveTriple.getSubArch() == llvm::Triple::SPIRSubArch_fpga &&
90209005
C.getInputArgs().hasArg(options::OPT_fsycl_link_EQ));
90219006
if (C.getDriver().getOffloadStaticLibSeen() &&
90229007
(JA->getType() == types::TY_Archive ||

clang/test/Driver/sycl-offload.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,27 @@
326326
// CHK-LINK-UB: 10: backend, {9}, assembler, (host-sycl)
327327
// CHK-LINK-UB: 11: assembler, {10}, object, (host-sycl)
328328

329+
/// Check -fsycl-link tool calls
330+
// RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl -o %t.out \
331+
// RUN: -fsycl-targets=spir64_gen -fsycl-link \
332+
// RUN: -fno-sycl-device-lib=all %t.o 2>&1 \
333+
// RUN: | FileCheck -check-prefixes=CHK-FSYCL-LINK-UB,CHK-FSYCL-LINK-UB-LIN %s
334+
// RUN: %clang_cl -### --target=x86_64-pc-windows-msvc -fsycl -o %t.out \
335+
// RUN: -fsycl-targets=spir64_gen -fsycl-link \
336+
// RUN: -fno-sycl-device-lib=all %t.o 2>&1 \
337+
// RUN: | FileCheck -check-prefixes=CHK-FSYCL-LINK-UB,CHK-FSYCL-LINK-UB-WIN %s
338+
// CHK-FSYCL-LINK-UB: clang-offload-bundler{{.*}} "-type=o" "-targets=host{{.*}},sycl-spir64_gen-unknown-unknown" "-input=[[INPUT:.+\.o]]" "-output={{.*}}" "-output=[[DEVICE_O:.+]]" "-unbundle"
339+
// CHK-FSYCL-LINK-UB: spirv-to-ir-wrapper{{.*}} "[[DEVICE_O]]" "-o" "[[DEVICE_BC:.+\.bc]]"
340+
// CHK-FSYCL-LINK-UB: llvm-link{{.*}} "[[DEVICE_BC]]"
341+
// CHK-FSYCL-LINK-UB: sycl-post-link{{.*}} "-o" "[[POST_LINK_TABLE:.+\.table]]"
342+
// CHK-FSYCL-LINK-UB: file-table-tform{{.*}} "-o" "[[TFORM_TABLE:.+\.txt]]" "[[POST_LINK_TABLE]]"
343+
// CHK-FSYCL-LINK-UB: llvm-spirv{{.*}} "-o" "[[SPIRV:.+\.txt]]"{{.*}} "[[TFORM_TABLE]]"
344+
// CHK-FSYCL-LINK-UB-LIN: ocloc{{.*}} "-output" "[[OCLOC_OUT:.+\.out]]"
345+
// CHK-FSYCL-LINK-UB-WIN: ocloc{{.*}} "-output" "[[OCLOC_OUT:.+\.exe]]"
346+
// CHK-FSYCL-LINK-UB: file-table-tform{{.*}} "-o" "[[TFORM_TABLE2:.+\.table]]" "[[POST_LINK_TABLE]]" "[[OCLOC_OUT]]"
347+
// CHK-FSYCL-LINK-UB: clang-offload-wrapper{{.*}} "-o" "[[WRAPPER_OUT:.+\.bc]]"{{.*}} "-batch" "[[TFORM_TABLE2]]"
348+
// CHK-FSYCL-LINK-UB: clang{{.*}} "-cc1"{{.*}} "-o" "{{.*}}.out" "-x" "ir" "[[WRAPPER_OUT]]"
349+
329350
/// Check -fsycl-link AOT unbundle
330351
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu \
331352
// RUN: -fsycl -o %t.out -fsycl-link -fno-sycl-instrument-device-code \

0 commit comments

Comments
 (0)