Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1733,12 +1733,13 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
if (Args.getLastArg(options::OPT_fsycl_dump_device_code_EQ))
DumpDeviceCode = true;

if (const Arg *A = Args.getLastArg(options::OPT_offload_host_only,
options::OPT_offload_device_only,
options::OPT_offload_host_device)) {
if (const Arg *A = Args.getLastArg(
options::OPT_offload_host_only, options::OPT_offload_device_only,
options::OPT_offload_host_device, options::OPT_fsycl_device_only)) {
if (A->getOption().matches(options::OPT_offload_host_only))
Offload = OffloadHost;
else if (A->getOption().matches(options::OPT_offload_device_only))
else if (A->getOption().matches(options::OPT_offload_device_only) ||
A->getOption().matches(options::OPT_fsycl_device_only))
Offload = OffloadDevice;
else
Offload = OffloadHostDevice;
Expand Down Expand Up @@ -4947,7 +4948,7 @@ class OffloadingActionBuilder final {
getDeviceDependences(OffloadAction::DeviceDependences &DA,
phases::ID CurPhase, phases::ID FinalPhase,
PhasesTy &Phases) override {
bool SYCLDeviceOnly = Args.hasArg(options::OPT_fsycl_device_only);
bool SYCLDeviceOnly = C.getDriver().offloadDeviceOnly();
if (CurPhase == phases::Preprocess) {
// Do not perform the host compilation when doing preprocessing only
// with -fsycl-device-only.
Expand Down Expand Up @@ -7881,9 +7882,9 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
break;
}

// Backend/Assemble actions are not used for the SYCL device side
if (Kind == Action::OFK_SYCL &&
(Phase == phases::Backend || Phase == phases::Assemble))
// Assemble actions are not used for the SYCL device side. Both compile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to deviate from the old-offloading-model flow where we do not seem to be calling Backend? If yes, is that agreeable? Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is agreeable. The functionality is the same, we just introduce the additional phase to better match with the new model expectations.

// and backend actions are used to generate IR and textual IR if needed.
if (Kind == Action::OFK_SYCL && Phase == phases::Assemble)
continue;

auto TCAndArch = TCAndArchs.begin();
Expand Down Expand Up @@ -8138,12 +8139,14 @@ Action *Driver::ConstructPhaseAction(
return C.MakeAction<BackendJobAction>(Input, Output);
}
if (Args.hasArg(options::OPT_emit_llvm) ||
(((Input->getOffloadingToolChain() &&
Input->getOffloadingToolChain()->getTriple().isAMDGPU()) ||
TargetDeviceOffloadKind == Action::OFK_HIP) &&
(Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
false) ||
TargetDeviceOffloadKind == Action::OFK_OpenMP))) {
((TargetDeviceOffloadKind == Action::OFK_SYCL &&
C.getDriver().getUseNewOffloadingDriver()) ||
(((Input->getOffloadingToolChain() &&
Input->getOffloadingToolChain()->getTriple().isAMDGPU()) ||
TargetDeviceOffloadKind == Action::OFK_HIP) &&
(Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
false) ||
TargetDeviceOffloadKind == Action::OFK_OpenMP)))) {
types::ID Output =
Args.hasArg(options::OPT_S) &&
(TargetDeviceOffloadKind == Action::OFK_None ||
Expand Down Expand Up @@ -9400,7 +9403,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
return C.addResultFile(FinalOutput->getValue(), &JA);
// Output to destination for -fsycl-device-only and Windows -o
if (C.getArgs().hasArg(options::OPT_fsycl_device_only))
if (offloadDeviceOnly() && JA.getOffloadingDeviceKind() == Action::OFK_SYCL)
if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT__SLASH_o))
return C.addResultFile(FinalOutput->getValue(), &JA);
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10359,7 +10359,7 @@ static void getOtherSPIRVTransOpts(Compilation &C,
C.getDriver().getFinalPhase(C.getArgs()) != phases::Link &&
TCArgs.getLastArgValue(options::OPT_fsycl_device_obj_EQ)
.equals_insensitive("spirv") &&
!TCArgs.hasArg(options::OPT_fsycl_device_only);
!C.getDriver().offloadDeviceOnly();
bool ShouldPreserveMetadataInFinalImage =
TCArgs.hasArg(options::OPT_fsycl_preserve_device_nonsemantic_metadata);
bool ShouldPreserveMetadata =
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,8 @@ void CudaToolChain::addClangTargetOptions(
}
}

auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv,
options::OPT_fsycl_device_only);
auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||
getDriver().offloadDeviceOnly();
if (DeviceOffloadingKind == Action::OFK_SYCL && !NoLibSpirv) {
std::string LibSpirvFile;

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/HIPAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ void HIPAMDToolChain::addClangTargetOptions(
CC1Args);
}

auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv,
options::OPT_fsycl_device_only);
auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||
getDriver().offloadDeviceOnly();
if (DeviceOffloadingKind == Action::OFK_SYCL && !NoLibSpirv) {
std::string LibSpirvFile;

Expand Down
35 changes: 25 additions & 10 deletions clang/test/Driver/sycl-offload-new-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
// OFFLOAD-NEW-DRIVER: 4: input, "[[INPUT]]", c++, (device-sycl)
// OFFLOAD-NEW-DRIVER: 5: preprocessor, {4}, c++-cpp-output, (device-sycl)
// OFFLOAD-NEW-DRIVER: 6: compiler, {5}, ir, (device-sycl)
// OFFLOAD-NEW-DRIVER: 7: offload, "device-sycl (nvptx64-nvidia-cuda)" {6}, ir
// OFFLOAD-NEW-DRIVER: 8: input, "[[INPUT]]", c++, (device-sycl)
// OFFLOAD-NEW-DRIVER: 9: preprocessor, {8}, c++-cpp-output, (device-sycl)
// OFFLOAD-NEW-DRIVER: 10: compiler, {9}, ir, (device-sycl)
// OFFLOAD-NEW-DRIVER: 11: offload, "device-sycl (spir64-unknown-unknown)" {10}, ir
// OFFLOAD-NEW-DRIVER: 12: clang-offload-packager, {7, 11}, image, (device-sycl)
// OFFLOAD-NEW-DRIVER: 13: offload, "host-sycl (x86_64-unknown-linux-gnu)" {3}, "device-sycl (x86_64-unknown-linux-gnu)" {12}, ir
// OFFLOAD-NEW-DRIVER: 14: backend, {13}, assembler, (host-sycl)
// OFFLOAD-NEW-DRIVER: 15: assembler, {14}, object, (host-sycl)
// OFFLOAD-NEW-DRIVER: 16: clang-linker-wrapper, {15}, image, (host-sycl)
// OFFLOAD-NEW-DRIVER: 7: backend, {6}, ir, (device-sycl)
// OFFLOAD-NEW-DRIVER: 8: offload, "device-sycl (nvptx64-nvidia-cuda)" {7}, ir
// OFFLOAD-NEW-DRIVER: 9: input, "[[INPUT]]", c++, (device-sycl)
// OFFLOAD-NEW-DRIVER: 10: preprocessor, {9}, c++-cpp-output, (device-sycl)
// OFFLOAD-NEW-DRIVER: 11: compiler, {10}, ir, (device-sycl)
// OFFLOAD-NEW-DRIVER: 12: backend, {11}, ir, (device-sycl)
// OFFLOAD-NEW-DRIVER: 13: offload, "device-sycl (spir64-unknown-unknown)" {12}, ir
// OFFLOAD-NEW-DRIVER: 14: clang-offload-packager, {8, 13}, image, (device-sycl)
// OFFLOAD-NEW-DRIVER: 15: offload, "host-sycl (x86_64-unknown-linux-gnu)" {3}, "device-sycl (x86_64-unknown-linux-gnu)" {14}, ir
// OFFLOAD-NEW-DRIVER: 16: backend, {15}, assembler, (host-sycl)
// OFFLOAD-NEW-DRIVER: 17: assembler, {16}, object, (host-sycl)
// OFFLOAD-NEW-DRIVER: 18: clang-linker-wrapper, {17}, image, (host-sycl)

/// Check the toolflow for SYCL compilation using new offload model
// RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64 --offload-new-driver %s 2>&1 | FileCheck -check-prefix=CHK-FLOW %s
Expand Down Expand Up @@ -47,3 +49,16 @@
// RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_POSTLINK %s
// WRAPPER_OPTIONS_POSTLINK: clang-linker-wrapper{{.*}} "--triple=spir64"
// WRAPPER_OPTIONS_POSTLINK-SAME: "--sycl-post-link-options=-post-link-opt -O2 -spec-const=native -device-globals -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -split-esimd -lower-esimd"

// -fsycl-device-only behavior
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
// RUN: -fsycl-device-only -ccc-print-phases %s 2>&1 \
// RUN | FileCheck -check-prefix DEVICE_ONLY %s
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
// RUN: --offload-device-only -ccc-print-phases %s 2>&1 \
// RUN: | FileCheck -check-prefix DEVICE_ONLY %s
// DEVICE_ONLY: 0: input, "{{.*}}", c++, (device-sycl)
// DEVICE_ONLY: 1: preprocessor, {0}, c++-cpp-output, (device-sycl)
// DEVICE_ONLY: 2: compiler, {1}, ir, (device-sycl)
// DEVICE_ONLY: 3: backend, {2}, ir, (device-sycl)
// DEVICE_ONLY: 4: offload, "device-sycl (spir64-unknown-unknown)" {3}, none