]> granicus.if.org Git - clang/commitdiff
Introduce a generation number for selector lookups in the global
authorDouglas Gregor <dgregor@apple.com>
Wed, 25 Jan 2012 01:14:32 +0000 (01:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 25 Jan 2012 01:14:32 +0000 (01:14 +0000)
method pool, so that we don't perform the same lookups into the same
PCH/module file repeatedly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148895 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp

index 2f4a5eba7d307b684f43a23258b8ee38895dbf6e..91f872bc1b1ae5018db7adec7c8940f6eb7b490c 100644 (file)
@@ -424,6 +424,10 @@ private:
   /// global selector ID to produce a local ID.
   GlobalSelectorMapType GlobalSelectorMap;
 
+  /// \brief The generation number of the last time we loaded data from the
+  /// global method pool for this selector.
+  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
+
   /// \brief Mapping from identifiers that represent macros whose definitions
   /// have not yet been deserialized to the global offset where the macro
   /// record resides.
@@ -656,7 +660,8 @@ private:
   /// loaded once the recursive loading has completed.
   std::deque<PendingIdentifierInfo> PendingIdentifierInfos;
 
-  /// \brief The generation number of 
+  /// \brief The generation number of each identifier, which keeps track of
+  /// the last time we loaded information about this identifier.
   llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
   
   /// \brief Contains declarations and definitions that will be
index 6fa680a74f81a4d1668de6bcb1b7b899748600c3..d336eb154725511fc0ffee2bba1e1e57da885dc3 100644 (file)
@@ -5212,13 +5212,15 @@ IdentifierIterator *ASTReader::getIdentifiers() const {
 namespace clang { namespace serialization {
   class ReadMethodPoolVisitor {
     ASTReader &Reader;
-    Selector Sel;    
+    Selector Sel;
+    unsigned PriorGeneration;
     llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods;
     llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods;
 
   public:
-    ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel)
-      : Reader(Reader), Sel(Sel) { }
+    ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, 
+                          unsigned PriorGeneration)
+      : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) { }
     
     static bool visit(ModuleFile &M, void *UserData) {
       ReadMethodPoolVisitor *This
@@ -5227,6 +5229,10 @@ namespace clang { namespace serialization {
       if (!M.SelectorLookupTable)
         return false;
       
+      // If we've already searched this module file, skip it now.
+      if (M.Generation <= This->PriorGeneration)
+        return true;
+
       ASTSelectorLookupTable *PoolTable
         = (ASTSelectorLookupTable*)M.SelectorLookupTable;
       ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel);
@@ -5269,7 +5275,13 @@ static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods,
 }
                              
 void ASTReader::ReadMethodPool(Selector Sel) {
-  ReadMethodPoolVisitor Visitor(*this, Sel);
+  // Get the selector generation and update it to the current generation.
+  unsigned &Generation = SelectorGeneration[Sel];
+  unsigned PriorGeneration = Generation;
+  Generation = CurrentGeneration;
+  
+  // Search for methods defined with this selector.
+  ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration);
   ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor);
   
   if (Visitor.getInstanceMethods().empty() &&