Skip to content

Commit db2c9d8

Browse files
committed
[SYCL][Driver] Emit unused argument warning for -fno-libspirv
Previously the `-fno-libspirv` option was not warned about when there was no SYCL compilation. Remove the explicit target check for the targets that support `-fno-libspirv` and instead rely on each target to emit appropriate warnings when its used. This commit slightly degrades diagnostic quality, from "ignoring '-fno-sycl-libspirv' option as it is not currently supported for target" to "argument unused during compilation: '-fno-sycl-libspirv'" , but I believe this is acceptable as it allows to remove the list of targets that support the option from the driver. Additionally, now if the user mixes targets that support and do not support `-fno-libspirv` in the same compilation, they will not get warnings that are not actionable.
1 parent 491016c commit db2c9d8

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,19 +1567,6 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
15671567
}
15681568
}
15691569

1570-
// -fno-sycl-libspirv flag is reserved for very unusual cases where the
1571-
// libspirv library is not linked when using CUDA/HIP: so output appropriate
1572-
// warnings.
1573-
if (C.getInputArgs().hasArg(options::OPT_fno_sycl_libspirv)) {
1574-
for (auto &TT : UniqueSYCLTriplesVec) {
1575-
if (TT.isNVPTX() || TT.isAMDGCN()) {
1576-
Diag(diag::warn_flag_no_sycl_libspirv) << TT.getTriple();
1577-
continue;
1578-
}
1579-
Diag(diag::warn_drv_unsupported_option_for_target)
1580-
<< "-fno-sycl-libspirv" << TT.getTriple() << 0;
1581-
}
1582-
}
15831570
// -fsycl-fp64-conv-emu is valid only for AOT compilation with an Intel GPU
15841571
// target. For other scenarios, we emit a warning message.
15851572
if (C.getInputArgs().hasArg(options::OPT_fsycl_fp64_conv_emu)) {

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,18 @@ const char *SYCLInstallationDetector::findLibspirvPath(
204204
void SYCLInstallationDetector::addLibspirvLinkArgs(
205205
const llvm::Triple &DeviceTriple, const llvm::opt::ArgList &DriverArgs,
206206
const llvm::Triple &HostTriple, llvm::opt::ArgStringList &CC1Args) const {
207-
if (DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||
208-
D.offloadDeviceOnly())
207+
DriverArgs.claimAllArgs(options::OPT_fno_sycl_libspirv);
208+
209+
if (D.offloadDeviceOnly())
210+
return;
211+
212+
if (DriverArgs.hasArg(options::OPT_fno_sycl_libspirv)) {
213+
// -fno-sycl-libspirv flag is reserved for very unusual cases where the
214+
// libspirv library is not linked when required by the device: so output appropriate
215+
// warnings.
216+
D.Diag(diag::warn_flag_no_sycl_libspirv) << DeviceTriple.str();
209217
return;
218+
}
210219

211220
if (const char *LibSpirvFile =
212221
findLibspirvPath(DeviceTriple, DriverArgs, HostTriple)) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Test that appropriate warnings are output when -fno-sycl-libspirv is used.
22

3-
// RUN: not %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda,amdgcn-amd-amdhsa -fno-sycl-libspirv %s -### 2>&1 | FileCheck %s
3+
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda,amdgcn-amd-amdhsa -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=gfx908 -nogpulib -fno-sycl-libspirv %s -### 2>&1 | FileCheck %s
44
// CHECK-DAG: warning: '-fno-sycl-libspirv' should not be used with target 'nvptx64-nvidia-cuda'; libspirv is required for correct behavior [-Wunsafe-libspirv-not-linked]
55
// CHECK-DAG: warning: '-fno-sycl-libspirv' should not be used with target 'amdgcn-amd-amdhsa'; libspirv is required for correct behavior [-Wunsafe-libspirv-not-linked]
66
// RUN: %clangxx -fsycl -fsycl-targets=spir64-unknown-unknown -fno-sycl-libspirv %s -### 2>&1 | FileCheck --check-prefix=CHECK-SPIR64 %s
7-
// CHECK-SPIR64: ignoring '-fno-sycl-libspirv' option as it is not currently supported for target 'spir64-unknown-unknown' [-Woption-ignored]
7+
// CHECK-SPIR64: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]

clang/test/Driver/sycl-libspirv-toolchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"
2121
// CHECK-DEVICE-ONLY-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
2222
//
23-
// Only link libspirv in SYCL language mode, but `-fno-sycl-libspirv` does not result in a warning
23+
// Only link libspirv in SYCL language mode, `-fno-sycl-libspirv` should result in a warning
2424
// RUN: %clang -### -x cu -fno-sycl-libspirv -nocudainc -nocudalib %s 2>&1 | FileCheck %s --check-prefixes=CHECK-CUDA
25-
// CHECK-CUDA-NOT: warning: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]
25+
// CHECK-CUDA: warning: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]
2626
// CHECK-CUDA: "-cc1"{{.*}} "-fcuda-is-device"
2727
// CHECK-CUDA-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
2828
//

0 commit comments

Comments
 (0)