Skip to content
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

[Driver][SYCL] Diagnose SYCL options in non-sycl mode. #10502

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -367,6 +367,8 @@ def err_drv_fsycl_with_pch : Error<
"Precompiled header generation is not supported with '-fsycl'">;
def err_drv_fsycl_unsupported_with_opt
: Error<"'%0' is not supported with '-fsycl'">;
def warn_drv_fsycl_host_compiler_options
: Warning<"'%0' should be used only in conjunction with '-fsycl-host-compiler'">, InGroup<InvalidCommandLineArgument>;
srividya-sundaram marked this conversation as resolved.
Show resolved Hide resolved
def err_drv_sycl_missing_amdgpu_arch : Error<
"missing AMDGPU architecture for SYCL offloading; specify it with '-Xsycl-target-backend --offload-arch'">;
def warn_drv_sycl_offload_target_duplicate : Warning<
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5332,10 +5332,10 @@ def : Flag<["-"], "fno-sycl-explicit-simd">,
defm sycl_early_optimizations : OptOutCC1FFlag<"sycl-early-optimizations", "Enable", "Disable", " standard optimization pipeline for SYCL device compiler", [CoreOption]>,
MarshallingInfoFlag<CodeGenOpts<"DisableSYCLEarlyOpts">>;
def fsycl_dead_args_optimization : Flag<["-"], "fsycl-dead-args-optimization">,
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Enables "
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Enables "
srividya-sundaram marked this conversation as resolved.
Show resolved Hide resolved
"elimination of DPC++ dead kernel arguments">;
def fno_sycl_dead_args_optimization : Flag<["-"], "fno-sycl-dead-args-optimization">,
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Disables "
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Disables "
"elimination of DPC++ dead kernel arguments">;
def fsycl_device_lib_EQ : CommaJoined<["-"], "fsycl-device-lib=">, Group<sycl_Group>, Flags<[NoXarchOption, CoreOption]>,
Values<"libc, libm-fp32, libm-fp64, libimf-fp32, libimf-fp64, libimf-bf16, all">, HelpText<"Control inclusion of "
Expand All @@ -5346,10 +5346,10 @@ def fno_sycl_device_lib_EQ : CommaJoined<["-"], "fno-sycl-device-lib=">, Group<s
"device libraries from device binary linkage. Valid arguments "
"are libc, libm-fp32, libm-fp64, all">;
def fsycl_device_lib_jit_link : Flag<["-"], "fsycl-device-lib-jit-link">,
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Enables "
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Enables "
"sycl device library jit link (experimental)">;
def fno_sycl_device_lib_jit_link : Flag<["-"], "fno-sycl-device-lib-jit-link">,
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Disables "
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Disables "
"sycl device library jit link (experimental)">;
def fsycl_fp32_prec_sqrt : Flag<["-"], "fsycl-fp32-prec-sqrt">, Group<sycl_Group>, Flags<[CC1Option]>,
HelpText<"SYCL only. Specify that single precision floating-point sqrt is correctly rounded.">,
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,11 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
getArgRequiringSYCLRuntime(options::OPT_fsycl_add_targets_EQ);
Arg *SYCLLink = getArgRequiringSYCLRuntime(options::OPT_fsycl_link_EQ);
Arg *SYCLfpga = getArgRequiringSYCLRuntime(options::OPT_fintelfpga);
// Check if -fsycl-host-compiler is used in conjunction with -fsycl.
Arg *SYCLHostCompiler =
getArgRequiringSYCLRuntime(options::OPT_fsycl_host_compiler_EQ);
Arg *SYCLHostCompilerOptions =
getArgRequiringSYCLRuntime(options::OPT_fsycl_host_compiler_options_EQ);

// -fsycl-targets cannot be used with -fsycl-link-targets
if (SYCLTargets && SYCLLinkTargets)
Expand All @@ -1123,6 +1128,10 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
if (SYCLTargets && SYCLfpga)
Diag(clang::diag::err_drv_option_conflict)
<< SYCLTargets->getSpelling() << SYCLfpga->getSpelling();
// -fsycl-host-compiler-options cannot be used without -fsycl-host-compiler
if (SYCLHostCompilerOptions && !SYCLHostCompiler)
Diag(clang::diag::warn_drv_fsycl_host_compiler_options)
<< SYCLHostCompilerOptions->getSpelling().split('=').first;

auto argSYCLIncompatible = [&](OptSpecifier OptId) {
if (!HasValidSYCLRuntime)
Expand Down
151 changes: 151 additions & 0 deletions clang/test/Driver/sycl-specific-args-diagnostics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// This test emits an error or a warning if -fsycl-* options are not used in
// conjunction with -fsycl.

// Error should be emitted when using -fsycl-host-compiler without -fsycl

// RUN: %clang -### -fsycl-host-compiler=g++ %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-NO-FSYCL %s
// RUN: %clang_cl -### -fsycl-host-compiler=g++ %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-NO-FSYCL %s
// CHK-NO-FSYCL: error: '-fsycl-host-compiler' must be used in conjunction with '-fsycl' to enable offloading

// Warning should be emitted when using -fsycl-host-compiler-options without -fsycl-host-compiler
// RUN: %clang -### -fsycl -fsycl-host-compiler-options="-g" %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-FSYCL-WARNING %s
// RUN: %clang_cl -### -fsycl -fsycl-host-compiler-options="-g" %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-FSYCL-WARNING %s
// CHK-FSYCL-WARNING: warning: '-fsycl-host-compiler-options' should be used only in conjunction with '-fsycl-host-compiler'

// Warning should be emitted when using -fsycl-dead-args-optimization without -fsycl
// RUN: %clang -### -fsycl-dead-args-optimization %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEAD-ARGS -DOPT=-fsycl-dead-args-optimization %s
// RUN: %clang_cl -### -fsycl-dead-args-optimization %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEAD-ARGS -DOPT=-fsycl-dead-args-optimization %s
// WARNING-DEAD-ARGS: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-device-lib-jit-link without -fsycl
// RUN: %clang -### -fsycl-device-lib-jit-link %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-JIT-LINK -DOPT=-fsycl-device-lib-jit-link %s
// RUN: %clang_cl -### -fsycl-device-lib-jit-link %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-JIT-LINK -DOPT=-fsycl-device-lib-jit-link %s
// WARNING-JIT-LINK: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-default-sub-group-size= without -fsycl
// RUN: %clang -### -fsycl-default-sub-group-size=10 %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DSS %s
// WARNING-DSS: warning: argument unused during compilation: '-fsycl-default-sub-group-size=10' [-Wunused-command-line-argument]
// RUN: %clang_cl -### -fsycl-default-sub-group-size=10 %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DSS-CL %s
// WARNING-DSS-CL: unknown argument ignored in clang-cl: '-fsycl-default-sub-group-size=10' [-Wunknown-argument]

// Warning should be emitted when using -fsycl-device-code-split-esimd without -fsycl
// RUN: %clang -### -fsycl-device-code-split-esimd %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DCSE -DOPT=-fsycl-device-code-split-esimd %s
// WARNING-DCSE: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-device-lib=libc without -fsycl
// RUN: %clang -### -fsycl-device-lib=libc %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-LIB %s
// RUN: %clang_cl -### -fsycl-device-lib=libc %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-LIB %s
// WARNING-DEVICE-LIB: warning: argument unused during compilation: '-fsycl-device-lib=libc' [-Wunused-command-line-argument]
srividya-sundaram marked this conversation as resolved.
Show resolved Hide resolved

// Warning should be emitted when using -fsycl-device-obj=spirv without -fsycl
// RUN: %clang -### -fsycl-device-obj=spirv %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-OBJ %s
// RUN: %clang_cl -### -fsycl-device-obj=spirv %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-OBJ %s
// WARNING-DEVICE-OBJ: warning: argument unused during compilation: '-fsycl-device-obj=spirv' [-Wunused-command-line-argument]
srividya-sundaram marked this conversation as resolved.
Show resolved Hide resolved

// Warning should be emitted when using -fsycl-device-only without -fsycl
// RUN: %clang -### -fsycl-device-only %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-ONLY -DOPT=-fsycl-device-only %s
// WARNING-DEVICE-ONLY-NOT: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]
// RUN: %clang_cl -### -fsycl-device-only %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-ONLY -DOPT=-fsycl-device-only %s
// WARNING-DEVICE-ONLY-NOT: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-early-optimizations without -fsycl
// RUN: %clang -### -fsycl-early-optimizations %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-EARLY-OPT -DOPT=-fsycl-early-optimizations %s
// RUN: %clang_cl -### -fsycl-early-optimizations %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-EARLY-OPT -DOPT=-fsycl-early-optimizations %s
// WARNING-EARLY-OPT: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-embed-ir without -fsycl
// RUN: %clang -### -fsycl-embed-ir %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-EMBED-IR -DOPT=-fsycl-embed-ir %s
// RUN: %clang_cl -### -fsycl-embed-ir %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-EMBED-IR -DOPT=-fsycl-embed-ir %s
// WARNING-EMBED-IR: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-esimd-force-stateless-mem without -fsycl
// RUN: %clang -### -fsycl-esimd-force-stateless-mem %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-FSM -DOPT=-fsycl-esimd-force-stateless-mem %s
// RUN: %clang_cl -### -fsycl-esimd-force-stateless-mem %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-FSM -DOPT=-fsycl-esimd-force-stateless-mem %s
// WARNING-FSM: warning: argument unused during compilation: '-fsycl-esimd-force-stateless-mem' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-force-inline-kernel-lambda without -fsycl
// RUN: %clang -### -fsycl-force-inline-kernel-lambda %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-FORCE-INLINE -DOPT=-fsycl-force-inline-kernel-lambda %s
// RUN: %clang_cl -### -fsycl-force-inline-kernel-lambda %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-FORCE-INLINE -DOPT=-fsycl-force-inline-kernel-lambda %s
// WARNING-FORCE-INLINE: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-fp32-prec-sqrt without -fsycl
// RUN: %clang -### -fsycl-fp32-prec-sqrt %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-FP32 -DOPT=-fsycl-fp32-prec-sqrt %s
// WARNING-FP32: warning: argument unused during compilation: '-fsycl-fp32-prec-sqrt' [-Wunused-command-line-argument]
// RUN: %clang_cl -### -fsycl-fp32-prec-sqrt %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-FP32-CL -DOPT=-fsycl-fp32-prec-sqrt %s
// WARNING-FP32-CL: warning: unknown argument ignored in clang-cl: '[[OPT]]' [-Wunknown-argument]

// Warning should be emitted when using -fsycl-id-queries-fit-in-int without -fsycl
// RUN: %clang -### -fsycl-id-queries-fit-in-int %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-ID -DOPT=-fsycl-id-queries-fit-in-int %s
// RUN: %clang_cl -### -fsycl-id-queries-fit-in-int %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-ID -DOPT=-fsycl-id-queries-fit-in-int %s
// WARNING-ID: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-instrument-device-code without -fsycl
// RUN: %clang -### -fsycl-instrument-device-code %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-INS-DEV -DOPT=-fsycl-instrument-device-code %s
// RUN: %clang_cl -### -fsycl-instrument-device-code %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-INS-DEV -DOPT=-fsycl-instrument-device-code %s
// WARNING-INS-DEV: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-libspirv-path without -fsycl
// RUN: %clang -### -fsycl-libspirv-path=libspirv.bc %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-LIBSPRIV %s
// RUN: %clang_cl -### -fsycl-libspirv-path=libspirv.bc %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-LIBSPRIV %s
// WARNING-LIBSPRIV: warning: argument unused during compilation: '-fsycl-libspirv-path=libspirv.bc' [-Wunused-command-line-argument]
srividya-sundaram marked this conversation as resolved.
Show resolved Hide resolved

// Warning should be emitted when using -fsycl-max-parallel-link-jobs without -fyscl
// RUN: %clang -### -fsycl-max-parallel-link-jobs=4 %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-PARALLEL %s
// RUN: %clang_cl -### -fsycl-max-parallel-link-jobs=4 %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-PARALLEL %s
// WARNING-PARALLEL: warning: argument unused during compilation: '-fsycl-max-parallel-link-jobs=4' [-Wunused-command-line-argument]
srividya-sundaram marked this conversation as resolved.
Show resolved Hide resolved

// Warning should be emitted when using -fsycl-optimize-non-user-code without -fsycl
// RUN: %clang -### -fsycl-optimize-non-user-code %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-OPTIMIZE -DOPT=-fsycl-optimize-non-user-code %s
// RUN: %clang_cl -### -fsycl-optimize-non-user-code %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-OPTIMIZE -DOPT=-fsycl-optimize-non-user-code %s
// WARNING-OPTIMIZE: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-unnamed-lambda without -fsycl
// RUN: %clang -### -fsycl-unnamed-lambda %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNNAMED-LAMBDA -DOPT=-fsycl-unnamed-lambda %s
// RUN: %clang_cl -### -fsycl-unnamed-lambda %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNNAMED-LAMBDA -DOPT=-fsycl-unnamed-lambda %s
// WARNING-UNNAMED-LAMBDA: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-use-bitcode without -fsycl
// RUN: %clang -### -fsycl-use-bitcode %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-USE-BITCODE -DOPT=-fsycl-use-bitcode %s
// RUN: %clang_cl -### -fsycl-use-bitcode %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-USE-BITCODE -DOPT=-fsycl-use-bitcode %s
// WARNING-USE-BITCODE: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]
srividya-sundaram marked this conversation as resolved.
Show resolved Hide resolved
Loading