Skip to content

Commit 590b1e3

Browse files
authored
[clang][modules] Only serialize info for locally-included headers (#113718)
I noticed that some PCM files contain `HeaderFileInfo` for headers only included in a dependent PCM file, which is wasteful. This patch changes the logic to only write headers that are included locally. This makes the PCM files smaller and saves some superfluous deserialization of `HeaderFileInfo` triggered by `Preprocessor::alreadyIncluded()`.
1 parent a93c952 commit 590b1e3

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

clang/include/clang/Lex/Preprocessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ class Preprocessor {
14901490
/// Mark the file as included.
14911491
/// Returns true if this is the first time the file was included.
14921492
bool markIncluded(FileEntryRef File) {
1493-
HeaderInfo.getFileInfo(File);
1493+
HeaderInfo.getFileInfo(File).IsLocallyIncluded = true;
14941494
return IncludedFiles.insert(File).second;
14951495
}
14961496

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,6 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,
15821582
}
15831583
}
15841584

1585-
FileInfo.IsLocallyIncluded = true;
15861585
IsFirstIncludeOfFile = PP.markIncluded(File);
15871586
return true;
15881587
}

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,8 +2163,8 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
21632163
continue; // We have no information on this being a header file.
21642164
if (!HFI->isCompilingModuleHeader && HFI->isModuleHeader)
21652165
continue; // Header file info is tracked by the owning module file.
2166-
if (!HFI->isCompilingModuleHeader && !PP->alreadyIncluded(*File))
2167-
continue; // Non-modular header not included is not needed.
2166+
if (!HFI->isCompilingModuleHeader && !HFI->IsLocallyIncluded)
2167+
continue; // Header file info is tracked by the including module file.
21682168

21692169
// Massage the file path into an appropriate form.
21702170
StringRef Filename = File->getName();
@@ -2176,7 +2176,7 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
21762176
SavedStrings.push_back(Filename.data());
21772177
}
21782178

2179-
bool Included = PP->alreadyIncluded(*File);
2179+
bool Included = HFI->IsLocallyIncluded || PP->alreadyIncluded(*File);
21802180

21812181
HeaderFileInfoTrait::key_type Key = {
21822182
Filename, File->getSize(), getTimestampForOutput(*File)

0 commit comments

Comments
 (0)