Skip to content

Commit

Permalink
[clang][modules] Only serialize info for locally-included headers (ll…
Browse files Browse the repository at this point in the history
…vm#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()`.
  • Loading branch information
jansvoboda11 authored Oct 25, 2024
1 parent a93c952 commit 590b1e3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Lex/Preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ class Preprocessor {
/// Mark the file as included.
/// Returns true if this is the first time the file was included.
bool markIncluded(FileEntryRef File) {
HeaderInfo.getFileInfo(File);
HeaderInfo.getFileInfo(File).IsLocallyIncluded = true;
return IncludedFiles.insert(File).second;
}

Expand Down
1 change: 0 additions & 1 deletion clang/lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,6 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,
}
}

FileInfo.IsLocallyIncluded = true;
IsFirstIncludeOfFile = PP.markIncluded(File);
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2163,8 +2163,8 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
continue; // We have no information on this being a header file.
if (!HFI->isCompilingModuleHeader && HFI->isModuleHeader)
continue; // Header file info is tracked by the owning module file.
if (!HFI->isCompilingModuleHeader && !PP->alreadyIncluded(*File))
continue; // Non-modular header not included is not needed.
if (!HFI->isCompilingModuleHeader && !HFI->IsLocallyIncluded)
continue; // Header file info is tracked by the including module file.

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

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

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

0 comments on commit 590b1e3

Please sign in to comment.