[cfe-commits] r136441 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTReaderDecl.cpp

Douglas Gregor dgregor at apple.com
Thu Jul 28 17:56:45 PDT 2011


Author: dgregor
Date: Thu Jul 28 19:56:45 2011
New Revision: 136441

URL: http://llvm.org/viewvc/llvm-project?rev=136441&view=rev
Log:
In the ASTReader, replace the continuous range maps whose value types
were (Module*, Offset) with equivalent maps whose value type is just a
Module*. The offsets have moved into corresponding "Base" fields
within the Module itself, where they will also be helpful for
local->global translation (eventually).

Modified:
    cfe/trunk/include/clang/Serialization/ASTReader.h
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=136441&r1=136440&r2=136441&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Jul 28 19:56:45 2011
@@ -252,6 +252,9 @@
   /// stored.
   const uint32_t *IdentifierOffsets;
   
+  /// \brief Base identifier ID for identifiers local to this module.
+  serialization::IdentID BaseIdentifierID;
+
   /// \brief Actual data for the on-disk hash table of identifiers.
   ///
   /// This pointer points into a memory buffer, where the on-disk hash
@@ -280,6 +283,10 @@
   /// \brief The offset of the start of the preprocessor detail cursor.
   uint64_t PreprocessorDetailStartOffset;
   
+  /// \brief Base preprocessed entity ID for preprocessed entities local to 
+  /// this module.
+  serialization::PreprocessedEntityID BasePreprocessedEntityID;
+  
   /// \brief The number of macro definitions in this file.
   unsigned LocalNumMacroDefinitions;
   
@@ -287,6 +294,10 @@
   /// record in the AST file.
   const uint32_t *MacroDefinitionOffsets;
   
+  /// \brief Base macro definition ID for macro definitions local to this 
+  /// module.
+  serialization::MacroID BaseMacroDefinitionID;
+
   // === Header search information ===
   
   /// \brief The number of local HeaderFileInfo structures.
@@ -318,6 +329,9 @@
   /// where each selector resides.
   const uint32_t *SelectorOffsets;
   
+  /// \brief Base selector ID for selectors local to this module.
+  serialization::SelectorID BaseSelectorID;
+
   /// \brief A pointer to the character data that comprises the selector table
   ///
   /// The SelectorOffsets table refers into this memory.
@@ -343,14 +357,20 @@
   /// \brief Offset of each declaration within the bitstream, indexed
   /// by the declaration ID (-1).
   const uint32_t *DeclOffsets;
-    
+  
+  /// \brief Base declaration ID for declarations local to this module.
+  serialization::DeclID BaseDeclID;
+
   /// \brief The number of C++ base specifier sets in this AST file.
   unsigned LocalNumCXXBaseSpecifiers;
   
   /// \brief Offset of each C++ base specifier set within the bitstream,
   /// indexed by the C++ base specifier set ID (-1).
   const uint32_t *CXXBaseSpecifiersOffsets;
-  
+
+  /// \brief Base base specifier ID for base specifiers local to this module.
+  serialization::CXXBaseSpecifiersID BaseCXXBaseSpecifiersID;
+
   // === Types ===
   
   /// \brief The number of types in this AST file.
@@ -565,13 +585,11 @@
   /// = I + 1 has already been loaded.
   std::vector<Decl *> DeclsLoaded;
 
-  typedef ContinuousRangeMap<serialization::DeclID, 
-                             std::pair<Module *, int32_t>, 4> 
+  typedef ContinuousRangeMap<serialization::DeclID, Module *, 4> 
     GlobalDeclMapType;
   
   /// \brief Mapping from global declaration IDs to the module in which the
-  /// declaration resides along with the offset that should be added to the
-  /// global declaration ID to produce a local ID.
+  /// declaration resides.
   GlobalDeclMapType GlobalDeclMap;
   
   typedef std::pair<Module *, uint64_t> FileOffset;
@@ -646,8 +664,7 @@
   /// been loaded.
   std::vector<IdentifierInfo *> IdentifiersLoaded;
 
-  typedef ContinuousRangeMap<serialization::IdentID, 
-                             std::pair<Module *, int32_t>, 4> 
+  typedef ContinuousRangeMap<serialization::IdentID, Module *, 4> 
     GlobalIdentifierMapType;
   
   /// \brief Mapping from global identifer IDs to the module in which the
@@ -662,8 +679,7 @@
   /// been loaded.
   SmallVector<Selector, 16> SelectorsLoaded;
 
-  typedef ContinuousRangeMap<serialization::SelectorID, 
-                             std::pair<Module *, int32_t>, 4> 
+  typedef ContinuousRangeMap<serialization::SelectorID, Module *, 4> 
     GlobalSelectorMapType;
   
   /// \brief Mapping from global selector IDs to the module in which the
@@ -674,8 +690,7 @@
   /// \brief The macro definitions we have already loaded.
   SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded;
 
-  typedef ContinuousRangeMap<serialization::MacroID, 
-                             std::pair<Module *, int32_t>, 4> 
+  typedef ContinuousRangeMap<serialization::MacroID, Module *, 4> 
     GlobalMacroDefinitionMapType;
   
   /// \brief Mapping from global macro definition IDs to the module in which the
@@ -688,7 +703,7 @@
   /// record resides.
   llvm::DenseMap<IdentifierInfo *, uint64_t> UnreadMacroRecordOffsets;
 
-  typedef ContinuousRangeMap<unsigned, std::pair<Module *, int>, 4> 
+  typedef ContinuousRangeMap<unsigned, Module *, 4> 
     GlobalPreprocessedEntityMapType;
   
   /// \brief Mapping from global preprocessing entity IDs to the module in
@@ -696,8 +711,7 @@
   /// added to the global preprocessing entitiy ID to produce a local ID.
   GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
   
-  typedef ContinuousRangeMap<serialization::CXXBaseSpecifiersID,
-                             std::pair<Module *, int32_t>, 4>
+  typedef ContinuousRangeMap<serialization::CXXBaseSpecifiersID, Module *, 4>
     GlobalCXXBaseSpecifiersMapType;
 
   /// \brief Mapping from global CXX base specifier IDs to the module in which

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=136441&r1=136440&r2=136441&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Jul 28 19:56:45 2011
@@ -1851,11 +1851,11 @@
     GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID);
     assert(I != GlobalMacroDefinitionMap.end() && 
            "Corrupted global macro definition map");
-    Module &F = *I->second.first;
-    unsigned Index = ID - 1 + I->second.second;
-    SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor);  
-    F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]);
-    LoadPreprocessedEntity(F);
+    Module &M = *I->second;
+    unsigned Index = ID - 1 - M.BaseMacroDefinitionID;
+    SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor);  
+    M.PreprocessorDetailCursor.JumpToBit(M.MacroDefinitionOffsets[Index]);
+    LoadPreprocessedEntity(M);
   }
 
   return MacroDefinitionsLoaded[ID - 1];
@@ -2069,12 +2069,11 @@
       }
       F.DeclOffsets = (const uint32_t *)BlobStart;
       F.LocalNumDecls = Record[0];
+      F.BaseDeclID = getTotalNumDecls();
         
       // Introduce the global -> local mapping for declarations within this 
       // AST file.
-      GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1, 
-                                          std::make_pair(&F, 
-                                                         -getTotalNumDecls())));
+      GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1, &F));
       DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls);      
       break;
 
@@ -2145,13 +2144,12 @@
       }
       F.IdentifierOffsets = (const uint32_t *)BlobStart;
       F.LocalNumIdentifiers = Record[0];
+      F.BaseIdentifierID = getTotalNumIdentifiers();
         
       // Introduce the global -> local mapping for identifiers within this AST
       // file
-      GlobalIdentifierMap.insert(
-                     std::make_pair(getTotalNumIdentifiers() + 1, 
-                                    std::make_pair(&F, 
-                                                   -getTotalNumIdentifiers())));
+      GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, 
+                                                &F));
       IdentifiersLoaded.resize(IdentifiersLoaded.size() +F.LocalNumIdentifiers);
       break;
 
@@ -2212,13 +2210,11 @@
     case SELECTOR_OFFSETS:
       F.SelectorOffsets = (const uint32_t *)BlobStart;
       F.LocalNumSelectors = Record[0];
+      F.BaseSelectorID = getTotalNumSelectors();
         
       // Introduce the global -> local mapping for identifiers within this AST
       // file
-      GlobalSelectorMap.insert(
-                     std::make_pair(getTotalNumSelectors() + 1, 
-                                    std::make_pair(&F, 
-                                                   -getTotalNumSelectors())));
+      GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors() + 1, &F));
       SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors);        
       break;
 
@@ -2428,16 +2424,14 @@
         StartingID = getTotalNumPreprocessedEntities();
       }
       
-      GlobalPreprocessedEntityMap.insert(
-                        std::make_pair(StartingID,
-                                         std::make_pair(&F, -(int)StartingID)));
+      F.BaseMacroDefinitionID = getTotalNumMacroDefinitions();
+      F.BasePreprocessedEntityID = StartingID;
 
       // Introduce the global -> local mapping for macro definitions within 
       // this AST file.
+      GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F));
       GlobalMacroDefinitionMap.insert(
-               std::make_pair(getTotalNumMacroDefinitions() + 1, 
-                              std::make_pair(&F, 
-                                             -getTotalNumMacroDefinitions())));
+        std::make_pair(getTotalNumMacroDefinitions() + 1, &F));
       MacroDefinitionsLoaded.resize(
                     MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions);
       break;
@@ -2473,11 +2467,9 @@
       
       F.LocalNumCXXBaseSpecifiers = Record[0];
       F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart;
-
-      GlobalCXXBaseSpecifiersMap.insert(std::make_pair(
-                                        getTotalNumCXXBaseSpecifiers() + 1,
-                                        std::make_pair(&F,
-                                            -getTotalNumCXXBaseSpecifiers())));
+      F.BaseCXXBaseSpecifiersID = getTotalNumCXXBaseSpecifiers();
+      GlobalCXXBaseSpecifiersMap.insert(
+        std::make_pair(getTotalNumCXXBaseSpecifiers() + 1, &F));
 
       NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers;
       break;
@@ -4051,10 +4043,9 @@
   assert (I != GlobalCXXBaseSpecifiersMap.end() &&
                                     "Corrupted global CXX base specifiers map");
   
-  return I->second.first->CXXBaseSpecifiersOffsets[ID - 1 +
-                                               I->second.second] +
-                                               I->second.first->GlobalBitOffset;
-
+  Module *M = I->second;
+  return M->CXXBaseSpecifiersOffsets[ID - 1 - M->BaseCXXBaseSpecifiersID] +
+    M->GlobalBitOffset;
 }
 
 CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
@@ -4374,14 +4365,13 @@
   dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap);
   dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap);
   dumpModuleIDMap("Global type map", GlobalTypeMap);
-  dumpModuleIDOffsetMap("Global declaration map", GlobalDeclMap);
-  dumpModuleIDOffsetMap("Global identifier map", GlobalIdentifierMap);
-  dumpModuleIDOffsetMap("Global selector map", GlobalSelectorMap);
-  dumpModuleIDOffsetMap("Global macro definition map", 
-                        GlobalMacroDefinitionMap);
-  dumpModuleIDOffsetMap("Global preprocessed entity map", 
-                        GlobalPreprocessedEntityMap);
-  
+  dumpModuleIDMap("Global declaration map", GlobalDeclMap);
+  dumpModuleIDMap("Global C++ base specifiers map", GlobalCXXBaseSpecifiersMap);
+  dumpModuleIDMap("Global identifier map", GlobalIdentifierMap);
+  dumpModuleIDMap("Global selector map", GlobalSelectorMap);
+  dumpModuleIDMap("Global macro definition map", GlobalMacroDefinitionMap);
+  dumpModuleIDMap("Global preprocessed entity map", 
+                  GlobalPreprocessedEntityMap);
 }
 
 /// Return the amount of memory used by memory buffers, breaking down
@@ -4758,9 +4748,9 @@
   if (!IdentifiersLoaded[ID]) {
     GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1);
     assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map");
-    unsigned Index = ID + I->second.second;
-    const char *Str = I->second.first->IdentifierTableData
-                    + I->second.first->IdentifierOffsets[Index];
+    Module *M = I->second;
+    unsigned Index = ID - M->BaseIdentifierID;
+    const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index];
 
     // All of the strings in the AST file are preceded by a 16-bit length.
     // Extract that 16-bit length to avoid having to execute strlen().
@@ -4809,11 +4799,11 @@
     // Load this selector from the selector table.
     GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID);
     assert(I != GlobalSelectorMap.end() && "Corrupted global selector map");
-    Module &F = *I->second.first;
-    ASTSelectorLookupTrait Trait(*this, F);
-    unsigned Idx = ID - 1 + I->second.second;
+    Module &M = *I->second;
+    ASTSelectorLookupTrait Trait(*this, M);
+    unsigned Idx = ID - 1 - M.BaseSelectorID;
     SelectorsLoaded[ID - 1] =
-      Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0);
+      Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0);
     if (DeserializationListener)
       DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]);
   }

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=136441&r1=136440&r2=136441&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Jul 28 19:56:45 2011
@@ -1406,8 +1406,8 @@
 
   GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
   assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
-  return RecordLocation(I->second.first, 
-                        I->second.first->DeclOffsets[Index + I->second.second]);
+  Module *M = I->second;
+  return RecordLocation(M, M->DeclOffsets[Index - M->BaseDeclID]);
 }
 
 ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {





More information about the cfe-commits mailing list