Skip to content

[SYCL][Driver][thinLTO] Error for -foffload-lto and -fsycl-device-code-split=off #14171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2024
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
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ def warn_drv_opt_requires_opt
: Warning<"'%0' should be used only in conjunction with '%1'">, InGroup<UnusedCommandLineArgument>;
def err_drv_sycl_missing_amdgpu_arch : Error<
"missing AMDGPU architecture for SYCL offloading; specify it with '-Xsycl-target-backend%select{|=%1}0 --offload-arch=<arch-name>'">;
def err_drv_sycl_thinlto_split_off: Error<
"'%0' is not supported when '%1' is set with '-fsycl'">;
def warn_drv_sycl_offload_target_duplicate : Warning<
"SYCL offloading target '%0' is similar to target '%1' already specified; "
"will be ignored">, InGroup<SyclTarget>;
Expand Down
23 changes: 17 additions & 6 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5846,12 +5846,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
bool IsUsingOffloadNewDriver =
Args.hasFlag(options::OPT_offload_new_driver,
options::OPT_no_offload_new_driver, false);
bool IsSYCLLTOSupported = JA.isDeviceOffloading(Action::OFK_SYCL) &&
Triple.isSPIROrSPIRV() &&
IsUsingOffloadNewDriver;
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
!IsUsingOffloadNewDriver && !Triple.isAMDGPU() &&
!IsSYCLLTOSupported) {
Arg *SYCLSplitMode =
Args.getLastArg(options::OPT_fsycl_device_code_split_EQ);
bool IsDeviceCodeSplitDisabled =
SYCLSplitMode && StringRef(SYCLSplitMode->getValue()) == "off";
bool IsSYCLLTOSupported =
JA.isDeviceOffloading(Action::OFK_SYCL) && IsUsingOffloadNewDriver;
if ((IsDeviceOffloadAction &&
!JA.isDeviceOffloading(Action::OFK_OpenMP) && !Triple.isAMDGPU() &&
!IsUsingOffloadNewDriver) ||
(JA.isDeviceOffloading(Action::OFK_SYCL) && !IsSYCLLTOSupported)) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< Args.getLastArg(options::OPT_foffload_lto,
options::OPT_foffload_lto_EQ)
Expand All @@ -5864,6 +5868,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_foffload_lto_EQ)
->getAsString(Args)
<< "-fno-gpu-rdc";
} else if (JA.isDeviceOffloading(Action::OFK_SYCL) &&
IsDeviceCodeSplitDisabled && LTOMode == LTOK_Thin) {
D.Diag(diag::err_drv_sycl_thinlto_split_off)
<< SYCLSplitMode->getAsString(Args)
<< Args.getLastArg(options::OPT_foffload_lto,
options::OPT_foffload_lto_EQ)
->getAsString(Args);
} else {
assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin);
CmdArgs.push_back(Args.MakeArgString(
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/sycl-lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
// RUN: not %clangxx -fsycl -foffload-lto=thin %s -### 2>&1 | FileCheck -check-prefix=CHECK_ERROR %s
// CHECK_ERROR: unsupported option '-foffload-lto=thin' for target 'spir64-unknown-unknown'

// Verify we error when using the new offload driver but with device code split set to off.
// RUN: not %clangxx -fsycl --offload-new-driver -foffload-lto=thin -fsycl-device-code-split=off %s -### 2>&1 | FileCheck -check-prefix=CHECK_SPLIT_ERROR %s
// CHECK_SPLIT_ERROR: '-fsycl-device-code-split=off' is not supported when '-foffload-lto=thin' is set with '-fsycl'

// Verify there's no error and we see the expected cc1 flags with the new offload driver.
// RUN: %clangxx -fsycl --offload-new-driver -foffload-lto=thin %s -### 2>&1 | FileCheck -check-prefix=CHECK_SUPPORTED %s
// CHECK_SUPPORTED: clang{{.*}} "-cc1" "-triple" "spir64-unknown-unknown" {{.*}} "-flto=thin" "-flto-unit"
Loading