Skip to content

Commit 5297ca0

Browse files
authored
[Driver][SYCL] Fix integration header handling with preprocessed files (#3650)
When generating preprocessed files using -fsycl, The preprocessed files did not contain the integration header causing the host side of the preprocessed file to not contain that information. Compiling from preprocessed files are not expected to do another preprocessing step so the addition of the integration header is lost.
1 parent 2398c20 commit 5297ca0

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,24 +3854,33 @@ class OffloadingActionBuilder final {
38543854
getDeviceDependences(OffloadAction::DeviceDependences &DA,
38553855
phases::ID CurPhase, phases::ID FinalPhase,
38563856
PhasesTy &Phases) override {
3857+
bool SYCLDeviceOnly = Args.hasArg(options::OPT_fsycl_device_only);
38573858
if (CurPhase == phases::Preprocess) {
38583859
// Do not perform the host compilation when doing preprocessing only
38593860
// with -fsycl-device-only.
38603861
bool IsPreprocessOnly =
38613862
Args.getLastArg(options::OPT_E) ||
38623863
Args.getLastArg(options::OPT__SLASH_EP, options::OPT__SLASH_P) ||
38633864
Args.getLastArg(options::OPT_M, options::OPT_MM);
3864-
if (Args.hasArg(options::OPT_fsycl_device_only) && IsPreprocessOnly) {
3865-
for (Action *&A : SYCLDeviceActions)
3865+
if (IsPreprocessOnly) {
3866+
for (Action *&A : SYCLDeviceActions) {
38663867
A = C.getDriver().ConstructPhaseAction(C, Args, CurPhase, A,
38673868
AssociatedOffloadKind);
3868-
return ABRT_Ignore_Host;
3869+
if (SYCLDeviceOnly)
3870+
continue;
3871+
// Add an additional compile action to generate the integration
3872+
// header.
3873+
Action *CompileAction =
3874+
C.MakeAction<CompileJobAction>(A, types::TY_Nothing);
3875+
DA.add(*CompileAction, *ToolChains.front(), nullptr,
3876+
Action::OFK_SYCL);
3877+
}
3878+
return SYCLDeviceOnly ? ABRT_Ignore_Host : ABRT_Success;
38693879
}
38703880
}
38713881

38723882
// Device compilation generates LLVM BC.
38733883
if (CurPhase == phases::Compile) {
3874-
bool SYCLDeviceOnly = Args.hasArg(options::OPT_fsycl_device_only);
38753884
for (Action *&A : SYCLDeviceActions) {
38763885
types::ID OutputType = types::TY_LLVM_BC;
38773886
if (SYCLDeviceOnly) {

clang/test/Driver/sycl-preprocess.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// Test preprocessing capabilities when using -fsycl
2+
/// Creating a preprocessed file is expected to do an integration header
3+
/// creation step.
4+
// RUN: %clangxx -fsycl -E -o %t_output.ii %s -### 2>&1 \
5+
// RUN: | FileCheck -check-prefix PREPROC_ONLY %s
6+
// RUN: %clang_cl -fsycl -P -Fi%t_output.ii %s -### 2>&1 \
7+
// RUN: | FileCheck -check-prefix PREPROC_ONLY %s
8+
// PREPROC_ONLY: clang{{.*}} "-fsycl-is-device"{{.*}} "-E"{{.*}} "-o" "[[DEVICE_OUT:.+\.ii]]"
9+
// PREPROC_ONLY: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]"{{.*}} "-fsyntax-only"
10+
// PREPROC_ONLY: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o" "[[HOST_OUT:.+\.ii]]"
11+
// PREPROC_ONLY: clang-offload-bundler{{.*}} "-type=ii"{{.*}} "-outputs={{.+_output.ii}}" "-inputs=[[DEVICE_OUT]],[[HOST_OUT]]"
12+
13+
/// When compiling from preprocessed file, no integration header is expected
14+
// RUN: touch %t.ii
15+
// RUN: %clangxx -fsycl %t.ii -### 2>&1 | FileCheck -check-prefix PREPROC_IN %s
16+
// PREPROC_IN: clang{{.*}} "-fsycl-is-device"
17+
// PREPROC_IN-NOT: "-fsycl-int-header={{.*}}"
18+
// PREPROC_IN: clang{{.*}} "-fsycl-is-host"
19+
20+
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -E %s -ccc-print-phases 2>&1 \
21+
// RUN: | FileCheck -check-prefix PREPROC_PHASES %s
22+
// PREPROC_PHASES: 0: input, "[[INPUT:.+\.cpp]]", c++, (device-sycl)
23+
// PREPROC_PHASES: 1: preprocessor, {0}, c++-cpp-output, (device-sycl)
24+
// PREPROC_PHASES: 2: offload, "device-sycl (spir64-unknown-unknown-sycldevice)" {1}, c++-cpp-output
25+
// PREPROC_PHASES: 3: input, "[[INPUT]]", c++, (host-sycl)
26+
// PREPROC_PHASES: 4: compiler, {1}, none, (device-sycl)
27+
// PREPROC_PHASES: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {3}, "device-sycl (spir64-unknown-unknown-sycldevice)" {4}, c++
28+
// PREPROC_PHASES: 6: preprocessor, {5}, c++-cpp-output, (host-sycl)
29+
// PREPROC_PHASES: 7: clang-offload-bundler, {2, 6}, c++-cpp-output, (host-sycl)

0 commit comments

Comments
 (0)