Skip to content

Commit

Permalink
Partially revert "[Driver][SYCL] Use existing option for device-only … (
Browse files Browse the repository at this point in the history
#15328)

…and some cleanup (#15274)"

This partially reverts commit fd4b409,
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
  • Loading branch information
hvdijk authored Sep 16, 2024
1 parent fb94e86 commit bc3a43e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -6813,7 +6813,7 @@ def fintelfpga : Flag<["-"], "fintelfpga">,
MarshallingInfoFlag<LangOpts<"IntelFPGA">>,
HelpText<"Perform ahead-of-time compilation for FPGA">;
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
Alias<offload_device_only>, 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",
Expand Down
26 changes: 7 additions & 19 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1758,12 +1745,13 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> 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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion clang/test/Driver/sycl-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit bc3a43e

Please sign in to comment.