aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/GeneratePCH.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2024-11-11 13:07:08 -0800
committerGitHub <noreply@github.com>2024-11-11 13:07:08 -0800
commit25d1ac11d537debb217c65c2bcdd087a60cff58e (patch)
tree0feb3f8500c9ac158e5ce0881f1b24e69e735bca /clang/lib/Serialization/GeneratePCH.cpp
parent9eefa922f8ef60a8032db28a33f13ed6d5249d0a (diff)
downloadllvm-25d1ac11d537debb217c65c2bcdd087a60cff58e.zip
llvm-25d1ac11d537debb217c65c2bcdd087a60cff58e.tar.gz
llvm-25d1ac11d537debb217c65c2bcdd087a60cff58e.tar.bz2
[clang][deps] Only write preprocessor info into PCMs (#115239)
This patch builds on top of https://github.com/llvm/llvm-project/pull/115237 and https://github.com/llvm/llvm-project/pull/115235, only passing the `Preprocessor` object to `ASTWriter`. This reduces the size of scanning PCM files by 1/3 and speeds up scans by 16%.
Diffstat (limited to 'clang/lib/Serialization/GeneratePCH.cpp')
-rw-r--r--clang/lib/Serialization/GeneratePCH.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp
index fdd240b..7a8a951 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -29,8 +29,8 @@ PCHGenerator::PCHGenerator(
bool AllowASTWithErrors, bool IncludeTimestamps,
bool BuildingImplicitModule, bool ShouldCacheASTInMemory,
bool GeneratingReducedBMI)
- : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()),
- SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
+ : PP(PP), Subject(&PP), OutputFile(OutputFile), isysroot(isysroot.str()),
+ Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
Writer(Stream, this->Buffer->Data, ModuleCache, Extensions,
IncludeTimestamps, BuildingImplicitModule, GeneratingReducedBMI),
AllowASTWithErrors(AllowASTWithErrors),
@@ -56,6 +56,17 @@ Module *PCHGenerator::getEmittingModule(ASTContext &) {
return M;
}
+DiagnosticsEngine &PCHGenerator::getDiagnostics() const {
+ return PP.getDiagnostics();
+}
+
+void PCHGenerator::InitializeSema(Sema &S) {
+ if (!PP.getHeaderSearchInfo()
+ .getHeaderSearchOpts()
+ .ModulesSerializeOnlyPreprocessor)
+ Subject = &S;
+}
+
void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
// Don't create a PCH if there were fatal failures during module loading.
if (PP.getModuleLoader().HadFatalFailure)
@@ -72,9 +83,7 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
if (AllowASTWithErrors)
PP.getDiagnostics().getClient()->clear();
- // Emit the PCH file to the Buffer.
- assert(SemaPtr && "No Sema?");
- Buffer->Signature = Writer.WriteAST(SemaPtr, OutputFile, Module, isysroot,
+ Buffer->Signature = Writer.WriteAST(Subject, OutputFile, Module, isysroot,
ShouldCacheASTInMemory);
Buffer->IsComplete = true;