[clang] 8112a42 - clang/Modules: Bring back optimization lost in 31e14f41a21f

Duncan P. N. Exon Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 4 11:40:21 PST 2019


Author: Duncan P. N. Exon Smith
Date: 2019-11-04T11:40:03-08:00
New Revision: 8112a423a8ede9bce64b6553e6451bf10995105c

URL: https://github.com/llvm/llvm-project/commit/8112a423a8ede9bce64b6553e6451bf10995105c
DIFF: https://github.com/llvm/llvm-project/commit/8112a423a8ede9bce64b6553e6451bf10995105c.diff

LOG: clang/Modules: Bring back optimization lost in 31e14f41a21f

31e14f41a21f9016050a20f07d5da03db2e8c13e accidentally dropped caching of
failed module loads.  This brings it back by making
ModuleMap::getCachedModuleLoad return an Optional.

Added: 
    

Modified: 
    clang/include/clang/Lex/ModuleMap.h
    clang/lib/Frontend/CompilerInstance.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index 3110ead86010..1e6b28d4aa3d 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -696,8 +696,11 @@ class ModuleMap {
   }
 
   /// Return a cached module load.
-  Module *getCachedModuleLoad(const IdentifierInfo &II) {
-    return CachedModuleLoads.lookup(&II);
+  llvm::Optional<Module *> getCachedModuleLoad(const IdentifierInfo &II) {
+    auto I = CachedModuleLoads.find(&II);
+    if (I == CachedModuleLoads.end())
+      return None;
+    return I->second;
   }
 };
 

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index cc3d848c1e02..a0663217453a 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1633,10 +1633,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
   }
 
   // If we don't already have information on this module, load the module now.
+  Module *Module = nullptr;
   ModuleMap &MM = getPreprocessor().getHeaderSearchInfo().getModuleMap();
-  clang::Module *Module = MM.getCachedModuleLoad(*Path[0].first);
-  if (Module) {
-    // Nothing to do here, we found it.
+  if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].first)) {
+    // Use the cached result, which may be nullptr.
+    Module = *MaybeModule;
   } else if (ModuleName == getLangOpts().CurrentModule) {
     // This is the module we're building.
     Module = PP->getHeaderSearchInfo().lookupModule(


        


More information about the cfe-commits mailing list