aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/GlobalModuleIndex.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2024-11-18 11:45:41 -0800
committerGitHub <noreply@github.com>2024-11-18 11:45:41 -0800
commitb769e3544a763a90abefd0dbe9254d83c765e1dc (patch)
tree0122de1508dd0d7a27c135ee008e8997b74ded57 /clang/lib/Serialization/GlobalModuleIndex.cpp
parentf14e1a8597f83fa5bbc78befcb7059144d58ff5c (diff)
downloadllvm-b769e3544a763a90abefd0dbe9254d83c765e1dc.zip
llvm-b769e3544a763a90abefd0dbe9254d83c765e1dc.tar.gz
llvm-b769e3544a763a90abefd0dbe9254d83c765e1dc.tar.bz2
[clang][serialization] Blobify IMPORTS strings and signatures (#116095)
This PR changes a part of the PCM format to store string-like things in the blob attached to a record instead of VBR6-encoding them into the record itself. Applied to the `IMPORTS` section (which is very hot), this speeds up dependency scanning by 2.8%.
Diffstat (limited to 'clang/lib/Serialization/GlobalModuleIndex.cpp')
-rw-r--r--clang/lib/Serialization/GlobalModuleIndex.cpp108
1 files changed, 52 insertions, 56 deletions
diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp
index 9c48712..4b920fc 100644
--- a/clang/lib/Serialization/GlobalModuleIndex.cpp
+++ b/clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -614,62 +614,58 @@ llvm::Error GlobalModuleIndexBuilder::loadModuleFile(FileEntryRef File) {
unsigned Code = MaybeCode.get();
// Handle module dependencies.
- if (State == ControlBlock && Code == IMPORTS) {
- // Load each of the imported PCH files.
- unsigned Idx = 0, N = Record.size();
- while (Idx < N) {
- // Read information about the AST file.
-
- // Skip the imported kind
- ++Idx;
-
- // Skip if it is standard C++ module
- ++Idx;
-
- // Skip the import location
- ++Idx;
-
- // Load stored size/modification time.
- off_t StoredSize = (off_t)Record[Idx++];
- time_t StoredModTime = (time_t)Record[Idx++];
-
- // Skip the stored signature.
- // FIXME: we could read the signature out of the import and validate it.
- auto FirstSignatureByte = Record.begin() + Idx;
- ASTFileSignature StoredSignature = ASTFileSignature::create(
- FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
- Idx += ASTFileSignature::size;
-
- // Skip the module name (currently this is only used for prebuilt
- // modules while here we are only dealing with cached).
- Idx += Record[Idx] + 1;
-
- // Retrieve the imported file name.
- unsigned Length = Record[Idx++];
- SmallString<128> ImportedFile(Record.begin() + Idx,
- Record.begin() + Idx + Length);
- Idx += Length;
-
- // Find the imported module file.
- auto DependsOnFile =
- FileMgr.getOptionalFileRef(ImportedFile, /*OpenFile=*/false,
- /*CacheFailure=*/false);
-
- if (!DependsOnFile)
- return llvm::createStringError(std::errc::bad_file_descriptor,
- "imported file \"%s\" not found",
- ImportedFile.c_str());
-
- // Save the information in ImportedModuleFileInfo so we can verify after
- // loading all pcms.
- ImportedModuleFiles.insert(std::make_pair(
- *DependsOnFile, ImportedModuleFileInfo(StoredSize, StoredModTime,
- StoredSignature)));
-
- // Record the dependency.
- unsigned DependsOnID = getModuleFileInfo(*DependsOnFile).ID;
- getModuleFileInfo(File).Dependencies.push_back(DependsOnID);
- }
+ if (State == ControlBlock && Code == IMPORT) {
+ unsigned Idx = 0;
+ // Read information about the AST file.
+
+ // Skip the imported kind
+ ++Idx;
+
+ // Skip the import location
+ ++Idx;
+
+ // Skip the module name (currently this is only used for prebuilt
+ // modules while here we are only dealing with cached).
+ Blob = Blob.substr(Record[Idx++]);
+
+ // Skip if it is standard C++ module
+ ++Idx;
+
+ // Load stored size/modification time.
+ off_t StoredSize = (off_t)Record[Idx++];
+ time_t StoredModTime = (time_t)Record[Idx++];
+
+ // Skip the stored signature.
+ // FIXME: we could read the signature out of the import and validate it.
+ StringRef SignatureBytes = Blob.substr(0, ASTFileSignature::size);
+ auto StoredSignature = ASTFileSignature::create(SignatureBytes.begin(),
+ SignatureBytes.end());
+ Blob = Blob.substr(ASTFileSignature::size);
+
+ // Retrieve the imported file name.
+ unsigned Length = Record[Idx++];
+ StringRef ImportedFile = Blob.substr(0, Length);
+ Blob = Blob.substr(Length);
+
+ // Find the imported module file.
+ auto DependsOnFile =
+ FileMgr.getOptionalFileRef(ImportedFile, /*OpenFile=*/false,
+ /*CacheFailure=*/false);
+
+ if (!DependsOnFile)
+ return llvm::createStringError(std::errc::bad_file_descriptor,
+ "imported file \"%s\" not found",
+ std::string(ImportedFile).c_str());
+
+ // Save the information in ImportedModuleFileInfo so we can verify after
+ // loading all pcms.
+ ImportedModuleFiles.insert(std::make_pair(
+ *DependsOnFile, ImportedModuleFileInfo(StoredSize, StoredModTime,
+ StoredSignature)));
+
+ // Record the dependency.
+ unsigned DependsOnID = getModuleFileInfo(*DependsOnFile).ID;
+ getModuleFileInfo(File).Dependencies.push_back(DependsOnID);
continue;
}