Skip to content

Commit 0bb5db5

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 3339a77 commit 0bb5db5

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
@@ -209,9 +209,18 @@ const char *SYCLInstallationDetector::findLibspirvPath(
209209
void SYCLInstallationDetector::addLibspirvLinkArgs(
210210
const llvm::Triple &DeviceTriple, const llvm::opt::ArgList &DriverArgs,
211211
const llvm::Triple &HostTriple, llvm::opt::ArgStringList &CC1Args) const {
212-
if (DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||
213-
D.offloadDeviceOnly())
212+
DriverArgs.claimAllArgs(options::OPT_fno_sycl_libspirv);
213+
214+
if (D.offloadDeviceOnly())
215+
return;
216+
217+
if (DriverArgs.hasArg(options::OPT_fno_sycl_libspirv)) {
218+
// -fno-sycl-libspirv flag is reserved for very unusual cases where the
219+
// libspirv library is not linked when required by the device: so output appropriate
220+
// warnings.
221+
D.Diag(diag::warn_flag_no_sycl_libspirv) << DeviceTriple.str();
214222
return;
223+
}
215224

216225
if (const char *LibSpirvFile =
217226
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
@@ -24,9 +24,9 @@
2424
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"
2525
// CHECK-DEVICE-ONLY-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
2626
//
27-
// Only link libspirv in SYCL language mode, but `-fno-sycl-libspirv` does not result in a warning
27+
// Only link libspirv in SYCL language mode, `-fno-sycl-libspirv` should result in a warning
2828
// RUN: %clang -### -x cu -fno-sycl-libspirv -nocudainc -nocudalib %s 2>&1 | FileCheck %s --check-prefixes=CHECK-CUDA
29-
// CHECK-CUDA-NOT: warning: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]
29+
// CHECK-CUDA: warning: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]
3030
// CHECK-CUDA: "-cc1"{{.*}} "-fcuda-is-device"
3131
// CHECK-CUDA-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
3232
//

0 commit comments

Comments
 (0)