-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][modules] Only serialize info for locally-included headers #113718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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()`.
@llvm/pr-subscribers-clang Author: Jan Svoboda (jansvoboda11) ChangesI noticed that some PCM files contain 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 Full diff: https://github.com/llvm/llvm-project/pull/113718.diff 3 Files Affected:
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index f3f4de044fc41a..38a527d2324ffe 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -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;
}
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 8826ab449df493..052be1395161d4 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1582,7 +1582,6 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,
}
}
- FileInfo.IsLocallyIncluded = true;
IsFirstIncludeOfFile = PP.markIncluded(File);
return true;
}
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 494890284d2f2c..612fdf499fa750 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -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();
@@ -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)
|
@llvm/pr-subscribers-clang-modules Author: Jan Svoboda (jansvoboda11) ChangesI noticed that some PCM files contain 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 Full diff: https://github.com/llvm/llvm-project/pull/113718.diff 3 Files Affected:
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index f3f4de044fc41a..38a527d2324ffe 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -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;
}
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 8826ab449df493..052be1395161d4 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1582,7 +1582,6 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,
}
}
- FileInfo.IsLocallyIncluded = true;
IsFirstIncludeOfFile = PP.markIncluded(File);
return true;
}
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 494890284d2f2c..612fdf499fa750 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -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();
@@ -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)
|
…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()`.
…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()`.
…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()`. (cherry picked from commit 590b1e3)
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 byPreprocessor::alreadyIncluded()
.