Skip to content

Commit 459ebb5

Browse files
committed
[clang][modules] Only serialize info for locally-included headers (llvm#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()`. (cherry picked from commit 590b1e3)
1 parent 4d006ca commit 459ebb5

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
@@ -1515,7 +1515,7 @@ class Preprocessor {
15151515
/// Mark the file as included.
15161516
/// Returns true if this is the first time the file was included.
15171517
bool markIncluded(FileEntryRef File) {
1518-
HeaderInfo.getFileInfo(File);
1518+
HeaderInfo.getFileInfo(File).IsLocallyIncluded = true;
15191519
return IncludedFiles.insert(File).second;
15201520
}
15211521

clang/lib/Lex/HeaderSearch.cpp

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

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

clang/lib/Serialization/ASTWriter.cpp

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

21992199
// Massage the file path into an appropriate form.
22002200
StringRef Filename = File->getName();
@@ -2206,7 +2206,7 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
22062206
SavedStrings.push_back(Filename.data());
22072207
}
22082208

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

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

0 commit comments

Comments
 (0)