]> granicus.if.org Git - clang/commitdiff
Cleaning up more of the ID situation in the AST reader. This patch relaxes and gener...
authorJonathan D. Turner <jonathan.d.turner@gmail.com>
Thu, 21 Jul 2011 21:15:19 +0000 (21:15 +0000)
committerJonathan D. Turner <jonathan.d.turner@gmail.com>
Thu, 21 Jul 2011 21:15:19 +0000 (21:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135705 91177308-0d34-0410-b5e6-96231b3b80d8

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

index d7b574a7749e544dc577d1c55bbc451293ea61a7..24fc070ec120fcd37375de71cd7be994b0f1e76f 100644 (file)
@@ -244,6 +244,9 @@ private:
     /// \brief The size of this file, in bits.
     uint64_t SizeInBits;
 
+    /// \brief The global bit offset (or base) of this module
+    uint64_t GlobalBitOffset;
+
     /// \brief The bitstream reader from which we'll read the AST file.
     llvm::BitstreamReader StreamFile;
 
@@ -613,6 +616,15 @@ private:
   /// added to the global preprocessing entitiy ID to produce a local ID.
   GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
   
+  typedef ContinuousRangeMap<serialization::CXXBaseSpecifiersID,
+                             std::pair<PerFileData *, int32_t>, 4>
+    GlobalCXXBaseSpecifiersMapType;
+
+  /// \brief Mapping from global CXX base specifier IDs to the module in which the
+  /// CXX base specifier resides along with the offset that should be added to the
+  /// global CXX base specifer ID to produce a local ID.
+  GlobalCXXBaseSpecifiersMapType GlobalCXXBaseSpecifiersMap;
+
   /// \name CodeGen-relevant special data
   /// \brief Fields containing data that is relevant to CodeGen.
   //@{
@@ -793,9 +805,15 @@ private:
   /// Number of visible decl contexts read/total.
   unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
   
+  /// Total size of modules, in bits, currently loaded
+  uint64_t TotalModulesSizeInBits;
+
   /// \brief Number of Decl/types that are currently deserializing.
   unsigned NumCurrentElementsDeserializing;
 
+  /// Number of CXX base specifiers currently loaded
+  unsigned NumCXXBaseSpecifiersLoaded;
+
   /// \brief An IdentifierInfo that has been loaded but whose top-level
   /// declarations of the same name have not (yet) been loaded.
   struct PendingIdentifierInfo {
@@ -1067,7 +1085,9 @@ public:
   }
       
   /// \brief Returns the number of C++ base specifiers found in the chain.
-  unsigned getTotalNumCXXBaseSpecifiers() const;
+  unsigned getTotalNumCXXBaseSpecifiers() const {
+    return NumCXXBaseSpecifiersLoaded;
+  }
       
   /// \brief Reads a TemplateArgumentLocInfo appropriate for the
   /// given TemplateArgument kind.
index be2b79d4038a3b2c71143387dbd7d8d0ed8a668f..c8f5db214c0a00adb9b4079e6ed60197733feb03 100644 (file)
@@ -2427,6 +2427,17 @@ ASTReader::ReadASTBlock(PerFileData &F) {
       
       F.LocalNumCXXBaseSpecifiers = Record[0];
       F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart;
+
+      GlobalCXXBaseSpecifiersMap.insert(std::make_pair(
+                                        getTotalNumCXXBaseSpecifiers() + 1,
+                                        std::make_pair(&F,
+                                            -getTotalNumCXXBaseSpecifiers())));
+
+      NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers;
+
+      F.GlobalBitOffset = TotalModulesSizeInBits;
+      TotalModulesSizeInBits += F.SizeInBits;
+
       break;
     }
 
@@ -3920,14 +3931,6 @@ TypeIdx ASTReader::GetTypeIdx(QualType T) const {
   return I->second;
 }
 
-unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const {
-  unsigned Result = 0;
-  for (unsigned I = 0, N = Chain.size(); I != N; ++I)
-    Result += Chain[I]->LocalNumCXXBaseSpecifiers;
-  
-  return Result;
-}
-
 TemplateArgumentLocInfo
 ASTReader::GetTemplateArgumentLocInfo(PerFileData &F,
                                       TemplateArgument::ArgKind Kind,
@@ -3984,21 +3987,17 @@ uint64_t
 ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) {
   if (ID == 0)
     return 0;
-  
-  --ID;
-  uint64_t Offset = 0;
-  for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
-    PerFileData &F = *Chain[N - I - 1];
 
-    if (ID < F.LocalNumCXXBaseSpecifiers)
-      return Offset + F.CXXBaseSpecifiersOffsets[ID];
-    
-    ID -= F.LocalNumCXXBaseSpecifiers;
-    Offset += F.SizeInBits;
-  }
+  GlobalCXXBaseSpecifiersMapType::iterator I =
+      GlobalCXXBaseSpecifiersMap.find(ID);
+
+  assert (I != GlobalCXXBaseSpecifiersMap.end() &&
+                                    "Corrupted global CXX base specifiers map");
   
-  assert(false && "CXXBaseSpecifiers not found");
-  return 0;
+  return I->second.first->CXXBaseSpecifiersOffsets[ID - 1 +
+                                               I->second.second] +
+                                               I->second.first->GlobalBitOffset;
+
 }
 
 CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
@@ -5309,8 +5308,9 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context,
     TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), 
     NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), 
     NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), 
-    NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), 
-    NumCurrentElementsDeserializing(0) 
+    NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0),
+    TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0),
+    NumCXXBaseSpecifiersLoaded(0)
 {
   SourceMgr.setExternalSLocEntrySource(this);
 }
@@ -5328,7 +5328,8 @@ ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
     NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0),
     TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0),
     TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0),
-    TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) 
+    TotalVisibleDeclContexts(0), TotalModulesSizeInBits(0),
+    NumCurrentElementsDeserializing(0), NumCXXBaseSpecifiersLoaded(0)
 {
   SourceMgr.setExternalSLocEntrySource(this);
 }