From 188bdcd1aaf5e9f457cec6851707d7dc3e7bbb15 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 25 Jan 2013 23:32:03 +0000 Subject: 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 --- lib/Serialization/GlobalModuleIndex.cpp | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) (limited to 'lib/Serialization/GlobalModuleIndex.cpp') diff --git a/lib/Serialization/GlobalModuleIndex.cpp b/lib/Serialization/GlobalModuleIndex.cpp index b192398280..b778a72ba2 100644 --- a/lib/Serialization/GlobalModuleIndex.cpp +++ b/lib/Serialization/GlobalModuleIndex.cpp @@ -127,7 +127,8 @@ struct LoadedModuleInfo { GlobalModuleIndex::GlobalModuleIndex(FileManager &FileMgr, llvm::MemoryBuffer *Buffer, llvm::BitstreamCursor Cursor) - : Buffer(Buffer), IdentifierIndex() + : Buffer(Buffer), IdentifierIndex(), + NumIdentifierLookups(), NumIdentifierLookupHits() { typedef llvm::DenseMap LoadedModulesMap; LoadedModulesMap LoadedModules; @@ -368,10 +369,8 @@ void GlobalModuleIndex::getModuleDependencies( Dependencies = Modules[Known->second].Dependencies; } -bool GlobalModuleIndex::lookupIdentifier( - StringRef Name, - SmallVectorImpl &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 @@ bool GlobalModuleIndex::lookupIdentifier( 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 &ModuleFiles) { - llvm::SmallPtrSet 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 @@ void GlobalModuleIndex::printStats() { 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"); } -- cgit v1.2.3