Skip to content

Commit d03de03

Browse files
authored
[Driver][SYCL] Fix SYCL option passing for preprocessing (#3149)
When performing SYCL offload, various -fsycl -fsycl-is* options are passed to the host and target compilations respectively. When performing preprocessing, a few of these options were not properly passed causing problems with the generated preprocessed file for the host compilation side.
1 parent 0c7bd24 commit d03de03

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6473,17 +6473,21 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
64736473
}
64746474

64756475
if (IsSYCL) {
6476-
// Host-side SYCL compilation receives the integration header file as
6477-
// Inputs[1]. Include the header with -include
6478-
if (!IsSYCLOffloadDevice && SYCLDeviceInput) {
6479-
const char *IntHeaderPath =
6480-
Args.MakeArgString(SYCLDeviceInput->getFilename());
6481-
CmdArgs.push_back("-include");
6482-
CmdArgs.push_back(IntHeaderPath);
6483-
// When creating dependency information, filter out the generated
6484-
// header file.
6485-
CmdArgs.push_back("-dependency-filter");
6486-
CmdArgs.push_back(IntHeaderPath);
6476+
// Add any options that are needed specific to SYCL offload while
6477+
// performing the host side compilation.
6478+
if (!IsSYCLOffloadDevice) {
6479+
// Host-side SYCL compilation receives the integration header file as
6480+
// Inputs[1]. Include the header with -include
6481+
if (SYCLDeviceInput) {
6482+
const char *IntHeaderPath =
6483+
Args.MakeArgString(SYCLDeviceInput->getFilename());
6484+
CmdArgs.push_back("-include");
6485+
CmdArgs.push_back(IntHeaderPath);
6486+
// When creating dependency information, filter out the generated
6487+
// header file.
6488+
CmdArgs.push_back("-dependency-filter");
6489+
CmdArgs.push_back(IntHeaderPath);
6490+
}
64876491
// Let the FE know we are doing a SYCL offload compilation, but we are
64886492
// doing the host pass.
64896493
CmdArgs.push_back("-fsycl");

clang/test/Driver/sycl-offload.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,13 @@
1414
// OFFLOAD-AVX-NEXT: clang{{.*}} "-cc1" {{.*}}
1515
// OFFLOAD-AVX-NEXT-SAME: "-fsycl-is-host"
1616
// OFFLOAD-AVX-NEXT-SAME: "-target-cpu" "[[HOST_CPU_NAME]]" "-target-feature" "+avx"
17+
18+
/// Check that the needed -fsycl -fsycl-is-device and -fsycl-is-host options
19+
/// are passed to all of the needed compilation steps regardless of final
20+
/// phase.
21+
// RUN: %clang -### -fsycl -c %s 2>&1 | FileCheck -check-prefix=CHECK-OPTS %s
22+
// RUN: %clang -### -fsycl -E %s 2>&1 | FileCheck -check-prefix=CHECK-OPTS %s
23+
// RUN: %clang -### -fsycl -S %s 2>&1 | FileCheck -check-prefix=CHECK-OPTS %s
24+
// RUN: %clang -### -fsycl %s 2>&1 | FileCheck -check-prefix=CHECK-OPTS %s
25+
// CHECK-OPTS: clang{{.*}} "-cc1" {{.*}} "-fsycl" "-fsycl-is-device"
26+
// CHECK-OPTS: clang{{.*}} "-cc1" {{.*}} "-fsycl" "-fsycl-is-host"

0 commit comments

Comments
 (0)