Skip to content

Commit 4c47642

Browse files
authored
[SYCL] Don't print the header and footer in the preprocessed output. (#15634)
This is needed to support compilation with `ccache`. When compiling with `ccache`, the integration header and footer shouldn't be printed in the pre-processed output to not confuse `ccache`. In order to do that we added a new option called `include-internal-footer` to include the integration footer. For consistency the `include` option, that was including the integration header was renamed `-include-internal-header`.
1 parent 2c39d67 commit 4c47642

20 files changed

+81
-73
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4658,10 +4658,14 @@ def image__base : Separate<["-"], "image_base">;
46584658
def include_ : JoinedOrSeparate<["-", "--"], "include">, Group<clang_i_Group>, EnumName<"include">,
46594659
MetaVarName<"<file>">, HelpText<"Include file before parsing">,
46604660
Visibility<[ClangOption, CC1Option]>;
4661-
def include_footer : Separate<["-"], "include-footer">, Group<clang_i_Group>,
4661+
def include_internal_footer : Separate<["-"], "include-internal-footer">, Group<clang_i_Group>,
46624662
Visibility<[CC1Option]>,
46634663
HelpText<"Name of the footer integration file">, MetaVarName<"<file>">,
46644664
MarshallingInfoString<PreprocessorOpts<"IncludeFooter">>;
4665+
def include_internal_header : Separate<["-"], "include-internal-header">, Group<clang_i_Group>,
4666+
Visibility<[CC1Option]>,
4667+
HelpText<"Name of the header integration file">, MetaVarName<"<file>">,
4668+
MarshallingInfoString<PreprocessorOpts<"IncludeHeader">>;
46654669
def include_pch : Separate<["-"], "include-pch">, Group<clang_i_Group>,
46664670
Visibility<[ClangOption, CC1Option]>,
46674671
HelpText<"Include precompiled header file">, MetaVarName<"<file>">,

clang/include/clang/Lex/PreprocessorOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class PreprocessorOptions {
6868
std::vector<std::pair<std::string, bool/*isUndef*/>> Macros;
6969
std::vector<std::string> Includes;
7070
std::string IncludeFooter;
71+
std::string IncludeHeader;
7172
std::vector<std::string> MacroIncludes;
7273

7374
/// Perform extra checks when loading PCM files for mutable file systems.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5741,7 +5741,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57415741
// action to determine this.
57425742
if (types::getPreprocessedType(Input.getType()) != types::TY_INVALID &&
57435743
!Header.empty()) {
5744-
CmdArgs.push_back("-include");
5744+
// Add the -include-internal-header option to add the integration header
5745+
CmdArgs.push_back("-include-internal-header");
57455746
CmdArgs.push_back(Args.MakeArgString(Header));
57465747
// When creating dependency information, filter out the generated
57475748
// header file.
@@ -5753,11 +5754,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57535754
CmdArgs.push_back("-fsycl-enable-int-header-diags");
57545755
}
57555756

5756-
// Add the -include-footer option to add the integration footer
57575757
StringRef Footer = D.getIntegrationFooter(Input.getBaseInput());
57585758
if (types::getPreprocessedType(Input.getType()) != types::TY_INVALID &&
57595759
!Args.hasArg(options::OPT_fno_sycl_use_footer) && !Footer.empty()) {
5760-
CmdArgs.push_back("-include-footer");
5760+
// Add the -include-internal-footer option to add the integration footer
5761+
CmdArgs.push_back("-include-internal-footer");
57615762
CmdArgs.push_back(Args.MakeArgString(Footer));
57625763
// When creating dependency information, filter out the generated
57635764
// integration footer file.

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,13 @@ void clang::InitializePreprocessor(Preprocessor &PP,
16631663
AddImplicitInclude(Builder, Path);
16641664
}
16651665

1666+
// Process -include-internal-header directive.
1667+
if (!LangOpts.SYCLIsDevice) {
1668+
if (!InitOpts.IncludeHeader.empty()) {
1669+
AddImplicitInclude(Builder, InitOpts.IncludeHeader);
1670+
}
1671+
}
1672+
16661673
// Instruct the preprocessor to skip the preamble.
16671674
PP.setSkipMainFilePreamble(InitOpts.PrecompiledPreambleBytes.first,
16681675
InitOpts.PrecompiledPreambleBytes.second);

clang/lib/Frontend/PrintPreprocessedOutput.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,24 @@ void PrintPPOutputPPCallbacks::WriteFooterContent(StringRef CodeFooter) {
265265
*OS << '\n';
266266
}
267267

268+
static bool is_separator(char value) { return value == '\\'; }
269+
268270
void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
269271
const char *Extra,
270272
unsigned ExtraLen) {
271273
startNewLineIfNeeded();
272274

275+
if (PP.getLangOpts().isSYCL()) {
276+
StringRef CurFilenameWithNoLeadingDotSlash =
277+
llvm::sys::path::remove_leading_dotbackslash_only(CurFilename.str());
278+
if ((CurFilenameWithNoLeadingDotSlash ==
279+
PP.getPreprocessorOpts().IncludeFooter) ||
280+
CurFilenameWithNoLeadingDotSlash ==
281+
PP.getPreprocessorOpts().IncludeHeader) {
282+
CurFilename = "<uninit>";
283+
}
284+
}
285+
273286
// Emit #line directives or GNU line markers depending on what mode we're in.
274287
if (UseLineDirectives) {
275288
*OS << "#line" << ' ' << LineNo << ' ' << '"';
@@ -288,6 +301,7 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
288301
else if (FileType == SrcMgr::C_ExternCSystem)
289302
OS->write(" 3 4", 4);
290303
}
304+
291305
*OS << '\n';
292306
}
293307

@@ -913,8 +927,6 @@ static void PrintIncludeFooter(Preprocessor &PP, SourceLocation Loc,
913927
return;
914928
FileID FooterFileID = SourceMgr.ComputeValidFooterFileID(Footer);
915929
StringRef FooterContentBuffer = SourceMgr.getBufferData(FooterFileID);
916-
// print out the name of the integration footer.
917-
Callbacks->WriteFooterInfo(Footer);
918930
SmallVector<StringRef, 8> FooterContentArr;
919931
FooterContentBuffer.split(FooterContentArr, '\r');
920932
// print out the content of the integration footer.
@@ -1185,15 +1197,6 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
11851197
PrintPreprocessedTokens(PP, Tok, Callbacks);
11861198
*OS << '\n';
11871199

1188-
if (!PP.getPreprocessorOpts().IncludeFooter.empty() &&
1189-
!PP.IncludeFooterProcessed) {
1190-
assert(PP.getLangOpts().SYCLIsHost &&
1191-
"The 'include-footer' is expected in host compilation only");
1192-
SourceLocation Loc = Tok.getLocation();
1193-
PrintIncludeFooter(PP, Loc, PP.getPreprocessorOpts().IncludeFooter,
1194-
Callbacks);
1195-
}
1196-
11971200
// Remove the handlers we just added to leave the preprocessor in a sane state
11981201
// so that it can be reused (for example by a clang::Parser instance).
11991202
PP.RemovePragmaHandler(MicrosoftExtHandler.get());

clang/test/CodeGenSYCL/debug-info-file-checksum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// COMP1-SAME: checksumkind: CSK_MD5, checksum: "259269f735d83ec32c46a11352458493")
1717

1818
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsycl-is-host \
19-
// RUN: -include %t.header.h -dependency-filter %t.header.h \
20-
// RUN: -include-footer %t.footer.h -dependency-filter %t.footer.h \
19+
// RUN: -include-internal-header %t.header.h -dependency-filter %t.header.h \
20+
// RUN: -include-internal-footer %t.footer.h -dependency-filter %t.footer.h \
2121
// RUN: -main-file-name %S/Inputs/checksum.cpp \
2222
// RUN: -gcodeview -debug-info-kind=limited -emit-llvm -O0 -o - \
2323
// RUN: "%S/Inputs/checksum.cpp" \

clang/test/Driver/sycl-int-footer-old-model.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
// RUN: %clangxx -fsycl --no-offload-new-driver -I cmdline/dir -include dummy.h %/s -### 2>&1 \
33
// RUN: | FileCheck -check-prefix FOOTER %s -DSRCDIR=%/S -DCMDDIR=cmdline/dir
44
// FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}"{{.*}} "-include" "dummy.h"
5-
// FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"
5+
// FOOTER: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"
66
// FOOTER-SAME: "-dependency-filter" "[[INTHEADER]]"
7-
// FOOTER-SAME: "-include-footer" "[[INTFOOTER]]"
8-
// FOOTER-SAME: "-dependency-filter" "[[INTFOOTER]]"
97
// FOOTER-SAME: "-fsycl-is-host"{{.*}} "-main-file-name" "[[SRCFILE:.+\cpp]]" {{.*}} "-include" "dummy.h"{{.*}} "-I" "cmdline/dir"
108

119
/// Preprocessed file creation with integration footer
1210
// RUN: %clangxx -fsycl --no-offload-new-driver -E %/s -### 2>&1 \
1311
// RUN: | FileCheck -check-prefix FOOTER_PREPROC_GEN %s
1412
// FOOTER_PREPROC_GEN: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}" "-o" "[[PREPROC_DEVICE:.+\.ii]]"
15-
// FOOTER_PREPROC_GEN: clang{{.*}} "-include" "[[INTHEADER]]"
16-
// FOOTER_PREPROC_GEN: "-dependency-filter" "[[INTHEADER]]"
17-
// FOOTER_PREPROC_GEN-SAME: "-include-footer" "[[INTFOOTER]]"
13+
// FOOTER_PREPROC_GEN: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"
14+
// FOOTER_PREPROC_GEN-SAME: "-dependency-filter" "[[INTHEADER]]"
15+
// FOOTER_PREPROC_GEN-SAME: "-include-internal-footer" "[[INTFOOTER]]"
1816
// FOOTER_PREPROC_GEN-SAME: "-dependency-filter" "[[INTFOOTER]]"
1917
// FOOTER_PREPROC_GEN-SAME: "-fsycl-is-host"{{.*}} "-E"{{.*}} "-o" "[[PREPROC_HOST:.+\.ii]]"
2018

@@ -31,7 +29,7 @@
3129
// RUN: | FileCheck -check-prefix NO-FOOTER --implicit-check-not "-fsycl-int-footer" %s
3230
// NO-FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-sycl-std={{.*}}"
3331
// NO-FOOTER-NOT: append-file
34-
// NO-FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"
32+
// NO-FOOTER: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"
3533

3634
/// Check phases without integration footer
3735
// RUN: %clangxx -fsycl --no-offload-new-driver -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -fno-sycl-use-footer -target x86_64-unknown-linux-gnu %s -ccc-print-phases 2>&1 \
@@ -69,7 +67,7 @@
6967
// RUN: | FileCheck -check-prefix FOOTER_PATH %s
7068
// FOOTER_PATH: clang{{.*}} "-fsycl-is-device"
7169
// FOOTER_PATH-SAME: "-fsycl-int-footer=dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h"
72-
// FOOTER_PATH: clang{{.*}} "-include-footer" "dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h"
70+
// FOOTER_PATH: clang{{.*}} "-include-internal-footer" "dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h"
7371

7472

7573
/// Check behaviors for dependency generation

clang/test/Driver/sycl-int-footer.cpp renamed to clang/test/Driver/sycl-int-header-footer.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/// Check compilation tool steps when using the integration footer
22
// RUN: %clangxx -fsycl --offload-new-driver -I cmdline/dir -include dummy.h %/s -### 2>&1 \
33
// RUN: | FileCheck -check-prefix FOOTER %s -DSRCDIR=%/S -DCMDDIR=cmdline/dir
4+
45
// FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}"{{.*}} "-include" "dummy.h"
5-
// FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"
6+
// FOOTER: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"
67
// FOOTER-SAME: "-fsycl-is-host"{{.*}} "-include" "dummy.h"{{.*}} "-I" "cmdline/dir"
7-
// FOOTER-NOT: "-include" "[[INTHEADER]]"
8+
// FOOTER-NOT: "-include-internal-header" "[[INTHEADER]]"
89

910
/// Preprocessed file creation with integration footer
1011
// RUN: %clangxx -fsycl --offload-new-driver -E %/s -### 2>&1 \
1112
// RUN: | FileCheck -check-prefix FOOTER_PREPROC_GEN %s
1213
// FOOTER_PREPROC_GEN: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}" "-o" "[[PREPROC_DEVICE:.+\.ii]]"
13-
// FOOTER_PREPROC_GEN: clang{{.*}} "-include" "[[INTHEADER]]"
14-
// FOOTER_PREPROC_GEN-SAME: "-include-footer" "[[INTFOOTER]]"
14+
// FOOTER_PREPROC_GEN: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"
15+
// FOOTER_PREPROC_GEN-SAME: "-dependency-filter" "[[INTHEADER]]"
16+
// FOOTER_PREPROC_GEN-SAME: "-include-internal-footer" "[[INTFOOTER]]"
17+
// FOOTER_PREPROC_GEN-SAME: "-dependency-filter" "[[INTFOOTER]]"
1518
// FOOTER_PREPROC_GEN-SAME: "-fsycl-is-host"{{.*}} "-E"{{.*}} "-o" "-"
1619

1720
/// Preprocessed file use with integration footer
@@ -24,7 +27,7 @@
2427
// RUN: %clangxx -fsycl --offload-new-driver -fno-sycl-use-footer %s -### 2>&1 \
2528
// RUN: | FileCheck -check-prefix NO-FOOTER --implicit-check-not "-fsycl-int-footer" %s
2629
// NO-FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-sycl-std={{.*}}"
27-
// NO-FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o"
30+
// NO-FOOTER: clang{{.*}} "-include-internal-header" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o"
2831

2932
/// Check phases without integration footer
3033
// RUN: %clangxx -fsycl --offload-new-driver -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -fno-sycl-use-footer -target x86_64-unknown-linux-gnu %s -ccc-print-phases 2>&1 \
@@ -58,7 +61,7 @@
5861
// RUN: | FileCheck -check-prefix FOOTER_PATH %s
5962
// FOOTER_PATH: clang{{.*}} "-fsycl-is-device"
6063
// FOOTER_PATH-SAME: "-fsycl-int-footer=dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h"
61-
// FOOTER_PATH: clang{{.*}} "-include-footer" "dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h"
64+
// FOOTER_PATH: clang{{.*}} "-include-internal-footer" "dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h"
6265

6366
/// Check behaviors for dependency generation
6467
// RUN: %clangxx -fsycl --offload-new-driver -MD -c %s -### 2>&1 \

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
// CHK-TOOLS-GEN: clang{{.*}} "-triple" "spir64_gen-unknown-unknown"
139139
// CHK-TOOLS-CPU: clang{{.*}} "-triple" "spir64_x86_64-unknown-unknown"
140140
// CHK-TOOLS-AOT: "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INPUT1:.+\-header.+\.h]]" "-fsycl-int-footer={{.*}}"{{.*}} "-o" "[[OUTPUT1:.+\.bc]]"
141-
// CHK-TOOLS-AOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include" "[[INPUT1]]" {{.*}} "-o" "[[OUTPUT7:.+\.o]]
141+
// CHK-TOOLS-AOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include-internal-header" "[[INPUT1]]" {{.*}} "-o" "[[OUTPUT7:.+\.o]]
142142
// CHK-TOOLS-AOT: llvm-link{{.*}} "[[OUTPUT1]]" "-o" "[[OUTPUT2:.+\.bc]]"
143143
// CHK-TOOLS-FPGA: sycl-post-link{{.*}} "-o" "[[OUTPUT2_T:.+\.table]]" "[[OUTPUT2]]"
144144
// CHK-TOOLS-GEN: sycl-post-link{{.*}} "-o" "[[OUTPUT2_T:.+\.table]]" "[[OUTPUT2]]"

clang/test/Driver/sycl-offload-header-check.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
// RUN: FileCheck --check-prefix=CHECK-HEADER %s
1212
// CHECK-HEADER: clang{{.*}} "-fsycl-int-header=[[HEADER:.+\.h]]"
1313
// CHECK-HEADER: {{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl{{[/\\]+}}stl_wrappers"
14-
// CHECK-HEADER-NOT: clang{{.*}} "-include" "[[HEADER]]"
15-
// CHECK-HEADER: clang{{.*}} "-include" "{{.*}}_dirname{{.+}}.h"
14+
// CHECK-HEADER-NOT: clang{{.*}} "-include-internal-header" "[[HEADER]]"
15+
// CHECK-HEADER: clang{{.*}} "-include-internal-header" "{{.*}}_dirname{{.+}}.h"

0 commit comments

Comments
 (0)