Skip to content

Commit e11fecf

Browse files
authored
[SYCL][Driver][thinLTO] Error for -foffload-lto and -fsycl-device-code-split=off (#14171)
This is really complicated to support so we decided to disallow it. I also fixed the condition to be more of what we want. --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent bd97f28 commit e11fecf

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ def warn_drv_opt_requires_opt
395395
: Warning<"'%0' should be used only in conjunction with '%1'">, InGroup<UnusedCommandLineArgument>;
396396
def err_drv_sycl_missing_amdgpu_arch : Error<
397397
"missing AMDGPU architecture for SYCL offloading; specify it with '-Xsycl-target-backend%select{|=%1}0 --offload-arch=<arch-name>'">;
398+
def err_drv_sycl_thinlto_split_off: Error<
399+
"'%0' is not supported when '%1' is set with '-fsycl'">;
398400
def warn_drv_sycl_offload_target_duplicate : Warning<
399401
"SYCL offloading target '%0' is similar to target '%1' already specified; "
400402
"will be ignored">, InGroup<SyclTarget>;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5846,12 +5846,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
58465846
bool IsUsingOffloadNewDriver =
58475847
Args.hasFlag(options::OPT_offload_new_driver,
58485848
options::OPT_no_offload_new_driver, false);
5849-
bool IsSYCLLTOSupported = JA.isDeviceOffloading(Action::OFK_SYCL) &&
5850-
Triple.isSPIROrSPIRV() &&
5851-
IsUsingOffloadNewDriver;
5852-
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
5853-
!IsUsingOffloadNewDriver && !Triple.isAMDGPU() &&
5854-
!IsSYCLLTOSupported) {
5849+
Arg *SYCLSplitMode =
5850+
Args.getLastArg(options::OPT_fsycl_device_code_split_EQ);
5851+
bool IsDeviceCodeSplitDisabled =
5852+
SYCLSplitMode && StringRef(SYCLSplitMode->getValue()) == "off";
5853+
bool IsSYCLLTOSupported =
5854+
JA.isDeviceOffloading(Action::OFK_SYCL) && IsUsingOffloadNewDriver;
5855+
if ((IsDeviceOffloadAction &&
5856+
!JA.isDeviceOffloading(Action::OFK_OpenMP) && !Triple.isAMDGPU() &&
5857+
!IsUsingOffloadNewDriver) ||
5858+
(JA.isDeviceOffloading(Action::OFK_SYCL) && !IsSYCLLTOSupported)) {
58555859
D.Diag(diag::err_drv_unsupported_opt_for_target)
58565860
<< Args.getLastArg(options::OPT_foffload_lto,
58575861
options::OPT_foffload_lto_EQ)
@@ -5864,6 +5868,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
58645868
options::OPT_foffload_lto_EQ)
58655869
->getAsString(Args)
58665870
<< "-fno-gpu-rdc";
5871+
} else if (JA.isDeviceOffloading(Action::OFK_SYCL) &&
5872+
IsDeviceCodeSplitDisabled && LTOMode == LTOK_Thin) {
5873+
D.Diag(diag::err_drv_sycl_thinlto_split_off)
5874+
<< SYCLSplitMode->getAsString(Args)
5875+
<< Args.getLastArg(options::OPT_foffload_lto,
5876+
options::OPT_foffload_lto_EQ)
5877+
->getAsString(Args);
58675878
} else {
58685879
assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin);
58695880
CmdArgs.push_back(Args.MakeArgString(

clang/test/Driver/sycl-lto.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
// RUN: not %clangxx -fsycl -foffload-lto=thin %s -### 2>&1 | FileCheck -check-prefix=CHECK_ERROR %s
55
// CHECK_ERROR: unsupported option '-foffload-lto=thin' for target 'spir64-unknown-unknown'
66

7+
// Verify we error when using the new offload driver but with device code split set to off.
8+
// 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
9+
// CHECK_SPLIT_ERROR: '-fsycl-device-code-split=off' is not supported when '-foffload-lto=thin' is set with '-fsycl'
10+
711
// Verify there's no error and we see the expected cc1 flags with the new offload driver.
812
// RUN: %clangxx -fsycl --offload-new-driver -foffload-lto=thin %s -### 2>&1 | FileCheck -check-prefix=CHECK_SUPPORTED %s
913
// CHECK_SUPPORTED: clang{{.*}} "-cc1" "-triple" "spir64-unknown-unknown" {{.*}} "-flto=thin" "-flto-unit"

0 commit comments

Comments
 (0)