Skip to content

Commit d99183b

Browse files
authored
[Driver][SYCL] Compile source file for integration header generation (#20818)
When compiler for preprocessing only, the preprocessing step that occurs does not generate the integration header/footer information that is used during the host compilation step. To generate the integration information in this case, the driver inserts an additional compilation step that creates the files to be consumed at the host step. The compilation step to produce the integration information is using the generated preprocessed file. For cases where there are build warnings that are emitted during this step, use of -Werror will cause the compilation to fail. These diagnostics are typically suppressed when not performing preprocess only compilations, but due to the fact that the build step against the preprocessed file does not know to suppress the diagnostics from system headers, compilation behaviors are at a disconnect. To fix this, the behavior when creating a preprocessed file (i.e. when we are using -E and stopping compilation), the driver will now compile the original source file instead of the preprocessed file.
1 parent f746a55 commit d99183b

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5061,14 +5061,19 @@ class OffloadingActionBuilder final {
50615061
llvm::zip(SYCLDeviceActions, SYCLTargetInfoList)) {
50625062
Action *&A = std::get<0>(TargetActionInfo);
50635063
auto &TargetInfo = std::get<1>(TargetActionInfo);
5064-
A = C.getDriver().ConstructPhaseAction(C, Args, CurPhase, A,
5065-
AssociatedOffloadKind);
5066-
if (SYCLDeviceOnly)
5064+
Action *PreprocAction = C.getDriver().ConstructPhaseAction(
5065+
C, Args, CurPhase, A, AssociatedOffloadKind);
5066+
if (SYCLDeviceOnly) {
5067+
A = PreprocAction;
50675068
continue;
5069+
}
50685070
// Add an additional compile action to generate the integration
5069-
// header.
5071+
// header. This action compiles the source file instead of the
5072+
// generated preprocessed file to allow for control of the
5073+
// diagnostics that could come from the system headers.
50705074
Action *CompileAction =
50715075
C.MakeAction<CompileJobAction>(A, types::TY_Nothing);
5076+
A = PreprocAction;
50725077
DA.add(*CompileAction, *TargetInfo.TC, TargetInfo.BoundArch,
50735078
Action::OFK_SYCL);
50745079
}
@@ -8001,8 +8006,15 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
80018006
if (isa<PreprocessJobAction>(A)) {
80028007
PackagerActions.push_back(OA);
80038008
A->setCannotBeCollapsedWithNextDependentAction();
8004-
Action *CompileAction =
8005-
C.MakeAction<CompileJobAction>(A, types::TY_Nothing);
8009+
// The input to the compilation job is the preprocessed job.
8010+
// Take that input action (it should be one input) which is
8011+
// the source file and compile that file to generate the
8012+
// integration header/footer.
8013+
ActionList PreprocInputs = A->getInputs();
8014+
assert(PreprocInputs.size() == 1 &&
8015+
"Single input size to preprocess action expected.");
8016+
Action *CompileAction = C.MakeAction<CompileJobAction>(
8017+
PreprocInputs.front(), types::TY_Nothing);
80068018
DDeps.add(*CompileAction, *TC, BoundArch, Action::OFK_SYCL);
80078019
}
80088020
});

clang/test/Driver/sycl-offload-nvptx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
// RUN: | FileCheck -check-prefix=CHK-PREPROC %s
107107
// CHK-PREPROC: 1: preprocessor, {0}, c++-cpp-output, (device-sycl, sm_[[CUDA_VERSION:[0-9.]+]])
108108
// CHK-PREPROC: 2: offload, "device-sycl (nvptx64-nvidia-cuda:sm_[[CUDA_VERSION]])" {1}, c++-cpp-output
109-
// CHK-PREPROC: 4: compiler, {1}, none, (device-sycl, sm_[[CUDA_VERSION]])
109+
// CHK-PREPROC: 4: compiler, {0}, none, (device-sycl, sm_[[CUDA_VERSION]])
110110
//
111111
// RUN: not %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
112112
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/no/CUDA/path/here \

clang/test/Driver/sycl-preprocess-old-model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// PREPROC_PHASES: 1: preprocessor, {0}, c++-cpp-output, (device-sycl)
2323
// PREPROC_PHASES: 2: offload, "device-sycl (spir64-unknown-unknown)" {1}, c++-cpp-output
2424
// PREPROC_PHASES: 3: input, "[[INPUT]]", c++, (host-sycl)
25-
// PREPROC_PHASES: 4: compiler, {1}, none, (device-sycl)
25+
// PREPROC_PHASES: 4: compiler, {0}, none, (device-sycl)
2626
// PREPROC_PHASES: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {3}, "device-sycl (spir64-unknown-unknown)" {4}, c++
2727
// PREPROC_PHASES: 6: preprocessor, {5}, c++-cpp-output, (host-sycl)
2828
// PREPROC_PHASES: 7: clang-offload-bundler, {2, 6}, c++-cpp-output, (host-sycl)

clang/test/Driver/sycl-preprocess.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// PREPROC_PHASES: 1: preprocessor, {0}, c++-cpp-output, (host-sycl)
2525
// PREPROC_PHASES: 2: input, "[[INPUT]]", c++, (device-sycl)
2626
// PREPROC_PHASES: 3: preprocessor, {2}, c++-cpp-output, (device-sycl)
27-
// PREPROC_PHASES: 4: compiler, {3}, none, (device-sycl)
27+
// PREPROC_PHASES: 4: compiler, {2}, none, (device-sycl)
2828
// PREPROC_PHASES: 5: offload, "device-sycl (spir64-unknown-unknown)" {3}, c++-cpp-output
2929
// PREPROC_PHASES: 6: llvm-offload-binary, {5, 1}, c++-cpp-output
3030
// PREPROC_PHASES: 7: offload, "host-sycl ([[TARGET]])" {1}, "device-sycl (spir64-unknown-unknown)" {3}, "device-sycl (spir64-unknown-unknown)" {4}, " ([[TARGET]])" {6}, c++-cpp-output

0 commit comments

Comments
 (0)