Improve coordination between the module manager and the global module
index, optimizing the operation that skips lookup in modules where we
know the identifier will not be found. This makes the global module
index optimization actually useful, providing an 8.5% speedup over
modules without the global module index for -fsyntax-only.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173529 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/GlobalModuleIndex.cpp b/lib/Serialization/GlobalModuleIndex.cpp
index b192398..b778a72 100644
--- a/lib/Serialization/GlobalModuleIndex.cpp
+++ b/lib/Serialization/GlobalModuleIndex.cpp
@@ -127,7 +127,8 @@
GlobalModuleIndex::GlobalModuleIndex(FileManager &FileMgr,
llvm::MemoryBuffer *Buffer,
llvm::BitstreamCursor Cursor)
- : Buffer(Buffer), IdentifierIndex()
+ : Buffer(Buffer), IdentifierIndex(),
+ NumIdentifierLookups(), NumIdentifierLookupHits()
{
typedef llvm::DenseMap<unsigned, LoadedModuleInfo> LoadedModulesMap;
LoadedModulesMap LoadedModules;
@@ -368,10 +369,8 @@
Dependencies = Modules[Known->second].Dependencies;
}
-bool GlobalModuleIndex::lookupIdentifier(
- StringRef Name,
- SmallVectorImpl<const FileEntry *> &ModuleFiles) {
- ModuleFiles.clear();
+bool GlobalModuleIndex::lookupIdentifier(StringRef Name, HitSet &Hits) {
+ Hits.clear();
// If there's no identifier index, there is nothing we can do.
if (!IdentifierIndex)
@@ -392,29 +391,13 @@
if (ID >= Modules.size() || !Modules[ID].File)
continue;
- ModuleFiles.push_back(Modules[ID].File);
+ Hits.insert(Modules[ID].File);
}
++NumIdentifierLookupHits;
return true;
}
-GlobalModuleIndex::SkipSet
-GlobalModuleIndex::computeSkipSet(
- const SmallVectorImpl<const FileEntry *> &ModuleFiles) {
- llvm::SmallPtrSet<const FileEntry *, 8> Found(ModuleFiles.begin(),
- ModuleFiles.end());
-
- SkipSet Result;
- for (unsigned I = 0, N = Modules.size(); I != N; ++I) {
- if (Modules[I].File && !Found.count(Modules[I].File))
- Result.insert(Modules[I].File);
- }
-
- NumIdentifierModulesSkipped += Result.size();
- return Result;
-}
-
void GlobalModuleIndex::printStats() {
std::fprintf(stderr, "*** Global Module Index Statistics:\n");
if (NumIdentifierLookups) {
@@ -422,10 +405,6 @@
NumIdentifierLookupHits, NumIdentifierLookups,
(double)NumIdentifierLookupHits*100.0/NumIdentifierLookups);
}
- if (NumIdentifierLookups && NumIdentifierModulesSkipped) {
- fprintf(stderr, " %f modules skipped per lookup (on average)\n",
- (double)NumIdentifierModulesSkipped/NumIdentifierLookups);
- }
std::fprintf(stderr, "\n");
}