]> granicus.if.org Git - clang/commitdiff
Promote DeclOffsets and TypeOffsets to per-file data.
authorSebastian Redl <sebastian.redl@getdesigned.at>
Mon, 19 Jul 2010 22:06:55 +0000 (22:06 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Mon, 19 Jul 2010 22:06:55 +0000 (22:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108760 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PCHReader.h
lib/Frontend/PCHReader.cpp

index 9ec7ea40d5ab05f9ae633eb9bdb3c64f05987b51..81acd51a86a8a1075c1036f710d853e06d5b5fc4 100644 (file)
@@ -231,9 +231,17 @@ private:
     /// \brief The number of types in this PCH file.
     unsigned LocalNumTypes;
 
+    /// \brief Offset of each type within the bitstream, indexed by the
+    /// type ID, or the representation of a Type*.
+    const uint32_t *TypeOffsets;
+
     /// \brief The number of declarations in this PCH file.
     unsigned LocalNumDecls;
 
+  /// \brief Offset of each declaration within the bitstream, indexed
+  /// by the declaration ID (-1).
+  const uint32_t *DeclOffsets;
+
     /// \brief Actual data for the on-disk hash table.
     ///
     // This pointer points into a memory buffer, where the on-disk hash
@@ -257,22 +265,12 @@ private:
   /// \brief The number of source location entries in all PCH files.
   unsigned TotalNumSLocEntries;
 
-  /// \brief Offset of each type within the bitstream, indexed by the
-  /// type ID, or the representation of a Type*. The offset is local to the
-  /// containing file; the file is chosen using the ID.
-  const uint32_t *TypeOffsets;
-
   /// \brief Types that have already been loaded from the PCH file.
   ///
   /// When the pointer at index I is non-NULL, the type with
   /// ID = (I + 1) << FastQual::Width has already been loaded from the PCH chain
   std::vector<QualType> TypesLoaded;
 
-  /// \brief Offset of each declaration within the bitstream, indexed
-  /// by the declaration ID (-1). The offset is local to the containing file;
-  /// the file is chosen using the ID.
-  const uint32_t *DeclOffsets;
-
   /// \brief Declarations that have already been loaded from the PCH file.
   ///
   /// When the pointer at index I is non-NULL, the declaration with ID
index aa92701abd6d817b2f6329358d2e59325764b619..9a9a1fc29bd449c609e932fe08d20609e471d6a2 100644 (file)
@@ -454,7 +454,9 @@ PCHReader::~PCHReader() {
 }
 
 PCHReader::PerFileData::PerFileData()
-  : StatCache(0), IdentifierTableData(0), IdentifierLookupTable(0)
+  : StatCache(0), LocalNumSLocEntries(0), LocalNumTypes(0), TypeOffsets(0),
+    LocalNumDecls(0), DeclOffsets(0), IdentifierTableData(0),
+    IdentifierLookupTable(0)
 {}
 
 
@@ -1489,21 +1491,21 @@ PCHReader::ReadPCHBlock(PerFileData &F) {
     }
 
     case pch::TYPE_OFFSET:
-      if (!TypesLoaded.empty()) {
+      if (F.LocalNumTypes != 0) {
         Error("duplicate TYPE_OFFSET record in PCH file");
         return Failure;
       }
-      TypeOffsets = (const uint32_t *)BlobStart;
-      TypesLoaded.resize(Record[0]);
+      F.TypeOffsets = (const uint32_t *)BlobStart;
+      F.LocalNumTypes = Record[0];
       break;
 
     case pch::DECL_OFFSET:
-      if (!DeclsLoaded.empty()) {
+      if (F.LocalNumDecls != 0) {
         Error("duplicate DECL_OFFSET record in PCH file");
         return Failure;
       }
-      DeclOffsets = (const uint32_t *)BlobStart;
-      DeclsLoaded.resize(Record[0]);
+      F.DeclOffsets = (const uint32_t *)BlobStart;
+      F.LocalNumDecls = Record[0];
       break;
 
     case pch::LANGUAGE_OPTIONS:
@@ -1692,6 +1694,15 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
 
   // Here comes stuff that we only do once the entire chain is loaded.
 
+  // Allocate space for loaded decls and types.
+  unsigned TotalNumTypes = 0, TotalNumDecls = 0;
+  for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
+    TotalNumTypes += Chain[I]->LocalNumTypes;
+    TotalNumDecls += Chain[I]->LocalNumDecls;
+  }
+  TypesLoaded.resize(TotalNumTypes);
+  DeclsLoaded.resize(TotalNumDecls);
+
   // Check the predefines buffers.
   if (CheckPredefinesBuffers())
     return IgnorePCH;
@@ -2690,7 +2701,7 @@ QualType PCHReader::GetType(pch::TypeID ID) {
   Index -= pch::NUM_PREDEF_TYPE_IDS;
   //assert(Index < TypesLoaded.size() && "Type index out-of-range");
   if (TypesLoaded[Index].isNull()) {
-    TypesLoaded[Index] = ReadTypeRecord(TypeOffsets[Index]);
+    TypesLoaded[Index] = ReadTypeRecord(Chain[0]->TypeOffsets[Index]);
     TypesLoaded[Index]->setFromPCH();
     if (DeserializationListener)
       DeserializationListener->TypeRead(ID >> Qualifiers::FastWidth,
@@ -2742,7 +2753,7 @@ Decl *PCHReader::GetExternalDecl(uint32_t ID) {
 
 TranslationUnitDecl *PCHReader::GetTranslationUnitDecl() {
   if (!DeclsLoaded[0]) {
-    ReadDeclRecord(DeclOffsets[0], 0);
+    ReadDeclRecord(Chain[0]->DeclOffsets[0], 0);
     if (DeserializationListener)
       DeserializationListener->DeclRead(1, DeclsLoaded[0]);
   }
@@ -2761,7 +2772,7 @@ Decl *PCHReader::GetDecl(pch::DeclID ID) {
 
   unsigned Index = ID - 1;
   if (!DeclsLoaded[Index]) {
-    ReadDeclRecord(DeclOffsets[Index], Index);
+    ReadDeclRecord(Chain[0]->DeclOffsets[Index], Index);
     if (DeserializationListener)
       DeserializationListener->DeclRead(ID, DeclsLoaded[Index]);
   }