Skip to content

Commit 3d2225a

Browse files
authored
[Driver][SYCL] Only preprocess for device when using -fsycl-device-only (#3248)
When performing -fsycl-device-only with preprocessing output, make sure we only output for the device compilation. The compilation was also doing host compiles causing incorrect output for 'device only'
1 parent fdacb75 commit 3d2225a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,6 +3728,20 @@ class OffloadingActionBuilder final {
37283728
getDeviceDependences(OffloadAction::DeviceDependences &DA,
37293729
phases::ID CurPhase, phases::ID FinalPhase,
37303730
PhasesTy &Phases) override {
3731+
if (CurPhase == phases::Preprocess) {
3732+
// Do not perform the host compilation when doing preprocessing only
3733+
// with -fsycl-device-only.
3734+
bool IsPreprocessOnly =
3735+
Args.getLastArg(options::OPT_E) ||
3736+
Args.getLastArg(options::OPT__SLASH_EP, options::OPT__SLASH_P) ||
3737+
Args.getLastArg(options::OPT_M, options::OPT_MM);
3738+
if (Args.hasArg(options::OPT_fsycl_device_only) && IsPreprocessOnly) {
3739+
for (Action *&A : SYCLDeviceActions)
3740+
A = C.getDriver().ConstructPhaseAction(C, Args, CurPhase, A,
3741+
AssociatedOffloadKind);
3742+
return ABRT_Ignore_Host;
3743+
}
3744+
}
37313745

37323746
// FIXME: This adds the integration header generation pass before the
37333747
// Host compilation pass so the Host can use the header generated. This

clang/test/Driver/sycl-device.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,24 @@
3535
// RUN: %clang_cl -### -fsycl -fsycl-device-only -o dummy.out %s 2>&1 \
3636
// RUN: | FileCheck -check-prefix=CHECK-OUTPUT-FILE %s
3737
// CHECK-OUTPUT-FILE: clang{{.*}} "-o" "dummy.out"
38+
39+
/// -fsycl-device-only with preprocessing should only do the device compile
40+
// RUN: %clang -ccc-print-phases -E -fsycl -fsycl-device-only %s 2>&1 \
41+
// RUN: | FileCheck -check-prefix=PHASES-PREPROCESS %s
42+
// RUN: %clang_cl -ccc-print-phases -E -fsycl -fsycl-device-only %s 2>&1 \
43+
// RUN: | FileCheck -check-prefix=PHASES-PREPROCESS %s
44+
// RUN: %clang_cl -ccc-print-phases -P -fsycl -fsycl-device-only %s 2>&1 \
45+
// RUN: | FileCheck -check-prefix=PHASES-PREPROCESS %s
46+
// RUN: %clang_cl -ccc-print-phases -EP -fsycl -fsycl-device-only %s 2>&1 \
47+
// RUN: | FileCheck -check-prefix=PHASES-PREPROCESS %s
48+
// PHASES-PREPROCESS: 0: input, {{.*}}, c++, (device-sycl)
49+
// PHASES-PREPROCESS: 1: preprocessor, {0}, c++-cpp-output, (device-sycl)
50+
// PHASES-PREPROCESS: 2: offload, "device-sycl (spir64-unknown-unknown-sycldevice)" {1}, c++-cpp-output
51+
52+
// RUN: %clang -ccc-print-phases -MM -fsycl -fsycl-device-only %s 2>&1 \
53+
// RUN: | FileCheck -check-prefix=PHASES-PREPROC-DEPS %s
54+
// RUN: %clang -ccc-print-phases -M -fsycl -fsycl-device-only %s 2>&1 \
55+
// RUN: | FileCheck -check-prefix=PHASES-PREPROC-DEPS %s
56+
// PHASES-PREPROC-DEPS: 0: input, {{.*}}, c++, (device-sycl)
57+
// PHASES-PROPROC-DEPS: 1: preprocessor, {0}, dependencies, (device-sycl)
58+
// PHASES-PREPROC-DEPS: 2: offload, "device-sycl (spir64-unknown-unknown-sycldevice)" {1}, dependencies

0 commit comments

Comments
 (0)