From bc3a43e2ca21e68446aba9a24691be6147a858a7 Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Mon, 16 Sep 2024 17:13:04 +0100 Subject: [PATCH] =?UTF-8?q?Partially=20revert=20"[Driver][SYCL]=20Use=20ex?= =?UTF-8?q?isting=20option=20for=20device-only=20=E2=80=A6=20(#15328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …and some cleanup (#15274)" This partially reverts commit fd4b40988d3ef77e73848ee46c48ef409babd066, undoing the change to alias -fsycl-device-only and --offload-device-only but keeping the other cleanups, and adds a test showing why the alias does not work. Fixes #15319 --- clang/include/clang/Driver/Options.td | 2 +- clang/lib/Driver/Driver.cpp | 26 +++++++------------------- clang/test/Driver/sycl-device.cpp | 4 +++- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 672fe88fa85b..d08af9e0a58a 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6813,7 +6813,7 @@ def fintelfpga : Flag<["-"], "fintelfpga">, MarshallingInfoFlag>, HelpText<"Perform ahead-of-time compilation for FPGA">; def fsycl_device_only : Flag<["-"], "fsycl-device-only">, - Alias, HelpText<"Compile SYCL kernels for device">; + HelpText<"Compile SYCL kernels for device">; def fsycl_embed_ir : Flag<["-"], "fsycl-embed-ir">, HelpText<"Embed LLVM IR for runtime kernel fusion">; defm sycl_esimd_force_stateless_mem : BoolFOption<"sycl-esimd-force-stateless-mem", diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 2b4c1b71f6f8..502b80ecef5d 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -854,19 +854,6 @@ static bool addSYCLDefaultTriple(Compilation &C, return true; } -// Special function that checks if -fsycl-device-only was passed on the -// command line. -fsycl-device-only is an alias of --offload-device-only. -static bool hasSYCLDeviceOnly(const ArgList &Args) { - if (const Arg *SYCLDeviceOnlyArg = - Args.getLastArg(options::OPT_offload_device_only)) { - while (SYCLDeviceOnlyArg->getAlias()) - SYCLDeviceOnlyArg = SYCLDeviceOnlyArg->getAlias(); - if (SYCLDeviceOnlyArg->getSpelling().contains("sycl-device-only")) - return true; - } - return false; -} - void Driver::CreateOffloadingDeviceToolChains(Compilation &C, InputList &Inputs) { @@ -1089,7 +1076,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C, bool HasValidSYCLRuntime = C.getInputArgs().hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) || - hasSYCLDeviceOnly(C.getInputArgs()); + C.getInputArgs().hasArg(options::OPT_fsycl_device_only); Arg *SYCLfpga = C.getInputArgs().getLastArg(options::OPT_fintelfpga); @@ -1758,12 +1745,13 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { if (Args.getLastArg(options::OPT_fsycl_dump_device_code_EQ)) DumpDeviceCode = true; - if (const Arg *A = Args.getLastArg(options::OPT_offload_host_only, - options::OPT_offload_device_only, - options::OPT_offload_host_device)) { + if (const Arg *A = Args.getLastArg( + options::OPT_offload_host_only, options::OPT_offload_device_only, + options::OPT_fsycl_device_only, options::OPT_offload_host_device)) { if (A->getOption().matches(options::OPT_offload_host_only)) Offload = OffloadHost; - else if (A->getOption().matches(options::OPT_offload_device_only)) + else if (A->getOption().matches(options::OPT_offload_device_only) || + A->getOption().matches(options::OPT_fsycl_device_only)) Offload = OffloadDevice; else Offload = OffloadHostDevice; @@ -3138,7 +3126,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, Arg *InputTypeArg = nullptr; bool IsSYCL = Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) || - hasSYCLDeviceOnly(Args); + Args.hasArg(options::OPT_fsycl_device_only); // The last /TC or /TP option sets the input type to C or C++ globally. if (Arg *TCTP = Args.getLastArgNoClaim(options::OPT__SLASH_TC, diff --git a/clang/test/Driver/sycl-device.cpp b/clang/test/Driver/sycl-device.cpp index 025da694d363..734e432007bb 100644 --- a/clang/test/Driver/sycl-device.cpp +++ b/clang/test/Driver/sycl-device.cpp @@ -3,9 +3,11 @@ // RUN: | FileCheck -check-prefix=CHECK-DEFAULT %s // CHECK-DEFAULT-NOT: "-fsycl-is-device" -/// Check "-fsycl-is-device" is passed when compiling for device: +/// Check "-fsycl-is-device" is passed when compiling for device, including when --config is used: // RUN: %clang -### -fsycl-device-only %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-SYCL-DEV %s +// RUN: %clang -### --config=%S/Inputs/empty.cfg -fsycl-device-only %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-SYCL-DEV %s // CHECK-SYCL-DEV: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include" /// Check that "-Wno-sycl-strict" is set on compiler invocation with "-fsycl"