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

Douglas Gregor dgregor at apple.com
Tue Jul 19 18:29:15 PDT 2011


Author: dgregor
Date: Tue Jul 19 20:29:15 2011
New Revision: 135556

URL: http://llvm.org/viewvc/llvm-project?rev=135556&view=rev
Log:
Use a ContinuousRangeMap to map from the global macro definition ID in
the AST reader down to the AST file + local ID, rather than walking
the PCH chain. More cleanup/generalization, although there is more
work to do for preprocessed entities. In particular, the
"preallocation" scheme for preprocessed entities is not going to work
well with late loading of PCH files, and it's likely we'll have to do
something akin to the SourceManager's negative/positive loading.



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

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=135556&r1=135555&r2=135556&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Jul 19 20:29:15 2011
@@ -582,6 +582,15 @@
   /// \brief The macro definitions we have already loaded.
   llvm::SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded;
 
+  typedef ContinuousRangeMap<serialization::MacroID, 
+                             std::pair<PerFileData *, int32_t>, 4> 
+    GlobalMacroDefinitionMapType;
+  
+  /// \brief Mapping from global macro definition IDs to the module in which the
+  /// selector resides along with the offset that should be added to the
+  /// global selector ID to produce a local ID.
+  GlobalMacroDefinitionMapType GlobalMacroDefinitionMap;
+
   /// \brief Mapping from identifiers that represent macros whose definitions
   /// have not yet been deserialized to the global offset where the macro
   /// record resides.

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=135556&r1=135555&r2=135556&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Jul 19 20:29:15 2011
@@ -1833,18 +1833,14 @@
     return 0;
 
   if (!MacroDefinitionsLoaded[ID - 1]) {
-    unsigned Index = ID - 1;
-    for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
-      PerFileData &F = *Chain[N - I - 1];
-      if (Index < F.LocalNumMacroDefinitions) {
-        SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor);  
-        F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]);
-        LoadPreprocessedEntity(F);
-        break;
-      }
-      Index -= F.LocalNumMacroDefinitions;
-    }
-    assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain");
+    GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID);
+    assert(I != GlobalMacroDefinitionMap.end() && 
+           "Corrupted global macro definition map");
+    PerFileData &F = *I->second.first;
+    unsigned Index = ID - 1 + I->second.second;
+    SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor);  
+    F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]);
+    LoadPreprocessedEntity(F);
   }
 
   return MacroDefinitionsLoaded[ID - 1];
@@ -2357,6 +2353,16 @@
       F.MacroDefinitionOffsets = (const uint32_t *)BlobStart;
       F.NumPreallocatedPreprocessingEntities = Record[0];
       F.LocalNumMacroDefinitions = Record[1];
+        
+      // Introduce the global -> local mapping for identifiers within this AST
+      // file
+      GlobalMacroDefinitionMap.insert(
+               std::make_pair(getTotalNumMacroDefinitions() + 1, 
+                              std::make_pair(&F, 
+                                             -getTotalNumMacroDefinitions())));
+      MacroDefinitionsLoaded.resize(
+                    MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions);
+
       break;
 
     case DECL_UPDATE_OFFSETS: {
@@ -2545,17 +2551,14 @@
   }
 
   // Allocate space for loaded slocentries, identifiers, decls and types.
-  unsigned TotalNumTypes = 0, 
-           TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0;
+  unsigned TotalNumTypes = 0, TotalNumPreallocatedPreprocessingEntities = 0;
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
     TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries;
     TotalNumTypes += Chain[I]->LocalNumTypes;
     TotalNumPreallocatedPreprocessingEntities +=
         Chain[I]->NumPreallocatedPreprocessingEntities;
-    TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions;
   }
   TypesLoaded.resize(TotalNumTypes);
-  MacroDefinitionsLoaded.resize(TotalNumMacroDefs);
   if (PP) {
     PP->getHeaderSearchInfo().SetExternalLookup(this);
     if (TotalNumPreallocatedPreprocessingEntities > 0) {





More information about the cfe-commits mailing list