Skip to content

Commit 53ae4bf

Browse files
authored
[Driver][SYCL] Pass as system headers for external SYCL host compilation (#18449)
The use of `-fsycl-host-compiler=arg` allows a user to specify a 3rd party compiler to perform host compilation when using `-fsycl`. The compilation will also include the SYCL specific headers. Pass in these headers as system headers with `-isystem` so they are treated as system headers as opposed to user headers. --------- Signed-off-by: Michael D Toguchi <michael.d.toguchi@intel.com>
1 parent 15b3ece commit 53ae4bf

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5282,6 +5282,12 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
52825282
HostCompileArgs.push_back(TCArgs.MakeArgString(*CWD));
52835283
}
52845284

5285+
// Add /external:W0 for MSVC based compilation. We are using /external:I
5286+
// which requires /external:Wn upon usage. Use of /external:W0 disables
5287+
// warnings from headers that are included with /external:I.
5288+
if (IsMSVCHostCompiler)
5289+
HostCompileArgs.push_back("/external:W0");
5290+
52855291
// Add default header search directories.
52865292
SmallString<128> BaseDir(C.getDriver().Dir);
52875293
llvm::sys::path::append(BaseDir, "..", "include");
@@ -5292,11 +5298,13 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
52925298
// STL headers in their programs (e.g., <complex>).
52935299
SmallString<128> STLWrappersDir(SYCLDir);
52945300
llvm::sys::path::append(STLWrappersDir, "stl_wrappers");
5295-
HostCompileArgs.push_back("-I");
5301+
// Add the SYCL specific header directories as system directories for non
5302+
// MSVC compilers.
5303+
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/external:I" : "-isystem");
52965304
HostCompileArgs.push_back(TCArgs.MakeArgString(SYCLDir));
5297-
HostCompileArgs.push_back("-I");
5305+
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/external:I" : "-isystem");
52985306
HostCompileArgs.push_back(TCArgs.MakeArgString(STLWrappersDir));
5299-
HostCompileArgs.push_back("-I");
5307+
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/external:I" : "-isystem");
53005308
HostCompileArgs.push_back(TCArgs.MakeArgString(BaseDir));
53015309

53025310
if (!OutputAdded) {

clang/test/Driver/sycl-host-compiler-old-model.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@
44
// RUN: %clangxx -fsycl --no-offload-new-driver -fsycl-host-compiler=/some/dir/g++ %s -### 2>&1 \
55
// RUN: | FileCheck -check-prefix=HOST_COMPILER %s
66
// HOST_COMPILER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer={{.*}}"
7-
// HOST_COMPILER: g++{{.*}} "-c" "-include" "[[INTHEADER]]" "-iquote" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-o" "[[HOSTOBJ:.+\.o]]"{{.*}}
7+
// HOST_COMPILER: g++{{.*}} "-c" "-include" "[[INTHEADER]]"
8+
// HOST_COMPILER-SAME: "-iquote"
9+
// HOST_COMPILER-SAME: "-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"
10+
// HOST_COMPILER-SAME: "-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl{{[/\\]+}}stl_wrappers"
11+
// HOST_COMPILER-SAME: "-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"
12+
// HOST_COMPILER-SAME: "-o" "[[HOSTOBJ:.+\.o]]"
813
// HOST_COMPILER: ld{{.*}} "[[HOSTOBJ]]"
914

1015
// RUN: %clang_cl -fsycl --no-offload-new-driver -fsycl-host-compiler=/some/dir/cl %s -### 2>&1 \
1116
// RUN: | FileCheck -check-prefix=HOST_COMPILER_CL %s
1217
// HOST_COMPILER_CL: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer={{.*}}"
13-
// HOST_COMPILER_CL: cl{{.*}} "-c" "-Fo[[HOSTOBJ:.+\.obj]]" "-FI" "[[INTHEADER]]"{{.*}} "-I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}}
18+
// HOST_COMPILER_CL: cl{{.*}} "-c" "-Fo[[HOSTOBJ:.+\.obj]]" "-FI" "[[INTHEADER]]"
19+
// HOST_COMPILER_CL-SAME: "/external:W0"
20+
// HOST_COMPILER_CL-SAME: "/external:I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"
21+
// HOST_COMPILER_CL-SAME: "/external:I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl{{[/\\]+}}stl_wrappers"
22+
// HOST_COMPILER_CL-SAME: "/external:I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"
1423
// HOST_COMPILER_CL: link{{.*}} "[[HOSTOBJ]]"
1524

1625
/// check for additional host options

0 commit comments

Comments
 (0)