diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2024-10-28 11:47:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-28 11:47:59 -0700 |
commit | 6c6351ee350589c8e6bcd69c3255374a714d87d0 (patch) | |
tree | 9dd0de912bd30419c35e4dcc52198c951dfa694b /clang/lib/Basic/Module.cpp | |
parent | e0a02fdb459f3126fbc40cf376f4a3871652ae49 (diff) | |
download | llvm-6c6351ee350589c8e6bcd69c3255374a714d87d0.zip llvm-6c6351ee350589c8e6bcd69c3255374a714d87d0.tar.gz llvm-6c6351ee350589c8e6bcd69c3255374a714d87d0.tar.bz2 |
[clang][modules] Optimize construction and usage of the submodule index (#113391)
This patch avoids eagerly populating the submodule index on `Module`
construction. The `StringMap` allocation shows up in my profiles of
`clang-scan-deps`, while the index is not necessary most of the time. We
still construct it on-demand.
Moreover, this patch avoids performing qualified submodule lookup in
`ASTReader` whenever we're serializing a module graph whose top-level
module is unknown. This is pointless, since that's guaranteed to never
find any existing submodules anyway.
This speeds up `clang-scan-deps` by ~0.5% on my workload.
Diffstat (limited to 'clang/lib/Basic/Module.cpp')
-rw-r--r-- | clang/lib/Basic/Module.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index a7a3f6b..330108d 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -54,7 +54,6 @@ Module::Module(ModuleConstructorTag, StringRef Name, NoUndeclaredIncludes = Parent->NoUndeclaredIncludes; ModuleMapIsPrivate = Parent->ModuleMapIsPrivate; - Parent->SubModuleIndex[Name] = Parent->SubModules.size(); Parent->SubModules.push_back(this); } } @@ -351,11 +350,14 @@ void Module::markUnavailable(bool Unimportable) { } Module *Module::findSubmodule(StringRef Name) const { - llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name); - if (Pos == SubModuleIndex.end()) - return nullptr; + // Add new submodules into the index. + for (unsigned I = SubModuleIndex.size(), E = SubModules.size(); I != E; ++I) + SubModuleIndex[SubModules[I]->Name] = I; - return SubModules[Pos->getValue()]; + if (auto It = SubModuleIndex.find(Name); It != SubModuleIndex.end()) + return SubModules[It->second]; + + return nullptr; } Module *Module::getGlobalModuleFragment() const { |