[clang] 2787fb1 - [clang][modules] Always keep submodule index up-to-date (#194039)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 29 13:56:51 PDT 2026
Author: Jan Svoboda
Date: 2026-04-29T13:56:46-07:00
New Revision: 2787fb1237c9b13ef108ce42d19eb00b53e9c373
URL: https://github.com/llvm/llvm-project/commit/2787fb1237c9b13ef108ce42d19eb00b53e9c373
DIFF: https://github.com/llvm/llvm-project/commit/2787fb1237c9b13ef108ce42d19eb00b53e9c373.diff
LOG: [clang][modules] Always keep submodule index up-to-date (#194039)
This partially reverts #113391, always keeping the submodule index
up-to-date. This is important for a follow-up PR that will make
deserialization of submodules lazier. Without this change, updating the
index would deserialize submodules too eagerly. The original PR only
showed 0.5% improvement in scan times, while the upcoming PR promises an
order of magnitude larger improvement.
Added:
Modified:
clang/include/clang/Basic/Module.h
clang/lib/Basic/Module.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index 03a5d460e4718..f83319db082d7 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -352,7 +352,7 @@ class alignas(8) Module {
/// A mapping from the submodule name to the index into the
/// \c SubModules vector at which that submodule resides.
- mutable llvm::StringMap<unsigned> SubModuleIndex;
+ llvm::StringMap<unsigned> SubModuleIndex;
/// The AST file name and key if this is a top-level module which has a
/// corresponding serialized AST file, or null otherwise.
@@ -738,6 +738,7 @@ class alignas(8) Module {
void setParent(Module *M) {
assert(!Parent);
Parent = M;
+ Parent->SubModuleIndex[M->Name] = Parent->SubModules.size();
Parent->SubModules.push_back(this);
}
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 7b34f45276db2..66629baa6240b 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -53,6 +53,7 @@ Module::Module(ModuleConstructorTag, StringRef Name,
NoUndeclaredIncludes = Parent->NoUndeclaredIncludes;
ModuleMapIsPrivate = Parent->ModuleMapIsPrivate;
+ Parent->SubModuleIndex[Name] = Parent->SubModules.size();
Parent->SubModules.push_back(this);
}
}
@@ -348,10 +349,6 @@ void Module::markUnavailable(bool Unimportable) {
}
Module *Module::findSubmodule(StringRef Name) const {
- // Add new submodules into the index.
- for (unsigned I = SubModuleIndex.size(), E = SubModules.size(); I != E; ++I)
- SubModuleIndex[SubModules[I]->Name] = I;
-
if (auto It = SubModuleIndex.find(Name); It != SubModuleIndex.end())
return SubModules[It->second];
More information about the cfe-commits
mailing list