aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/GlobalModuleIndex.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2023-08-22 14:24:20 -0700
committerJan Svoboda <jan_svoboda@apple.com>2023-08-24 09:16:04 -0700
commit7d1565727dad3acb54fe76a908630843835d7bc8 (patch)
tree03008b8423c858064abe888fb914ee24a52d53f2 /clang/lib/Serialization/GlobalModuleIndex.cpp
parentb9d78bdc730b2fcfe029a7579c24020536c3fa25 (diff)
downloadllvm-7d1565727dad3acb54fe76a908630843835d7bc8.zip
llvm-7d1565727dad3acb54fe76a908630843835d7bc8.tar.gz
llvm-7d1565727dad3acb54fe76a908630843835d7bc8.tar.bz2
[clang][modules] Move `UNHASHED_CONTROL_BLOCK` up in the AST file
When loading (transitively) imported AST file, `ModuleManager::addModule()` first checks it has the expected signature via `readASTFileSignature()`. The signature is part of `UNHASHED_CONTROL_BLOCK`, which is placed at the end of the AST file. This means that just to verify signature of an AST file, we need to skip over all top-level blocks, paging in the whole AST file from disk. This is pretty slow. This patch moves `UNHASHED_CONTROL_BLOCK` to the start of the AST file, so that it can be read more efficiently. To achieve this, we use dummy signature when first emitting the unhashed control block, and then backpatch the real signature at the end of the serialization process. This speeds up dependency scanning by over 9% and significantly reduces run-to-run variability of my benchmarks. Depends on D158572. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D158573
Diffstat (limited to 'clang/lib/Serialization/GlobalModuleIndex.cpp')
-rw-r--r--clang/lib/Serialization/GlobalModuleIndex.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp
index d57f4ce..92417c7 100644
--- a/clang/lib/Serialization/GlobalModuleIndex.cpp
+++ b/clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -697,9 +697,12 @@ llvm::Error GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
}
// Get Signature.
- if (State == DiagnosticOptionsBlock && Code == SIGNATURE)
- getModuleFileInfo(File).Signature = ASTFileSignature::create(
- Record.begin(), Record.begin() + ASTFileSignature::size);
+ if (State == DiagnosticOptionsBlock && Code == SIGNATURE) {
+ auto Signature = ASTFileSignature::create(Blob.begin(), Blob.end());
+ assert(Signature != ASTFileSignature::createDummy() &&
+ "Dummy AST file signature not backpatched in ASTWriter.");
+ getModuleFileInfo(File).Signature = Signature;
+ }
// We don't care about this record.
}