[cfe-commits] r108760 - in /cfe/trunk: include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Mon Jul 19 15:06:55 PDT 2010


Author: cornedbee
Date: Mon Jul 19 17:06:55 2010
New Revision: 108760

URL: http://llvm.org/viewvc/llvm-project?rev=108760&view=rev
Log:
Promote DeclOffsets and TypeOffsets to per-file data.

Modified:
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/lib/Frontend/PCHReader.cpp

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=108760&r1=108759&r2=108760&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Mon Jul 19 17:06:55 2010
@@ -231,9 +231,17 @@
     /// \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 @@
   /// \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

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=108760&r1=108759&r2=108760&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Mon Jul 19 17:06:55 2010
@@ -454,7 +454,9 @@
 }
 
 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 @@
     }
 
     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 @@
 
   // 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 @@
   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 @@
 
 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 @@
 
   unsigned Index = ID - 1;
   if (!DeclsLoaded[Index]) {
-    ReadDeclRecord(DeclOffsets[Index], Index);
+    ReadDeclRecord(Chain[0]->DeclOffsets[Index], Index);
     if (DeserializationListener)
       DeserializationListener->DeclRead(ID, DeclsLoaded[Index]);
   }





More information about the cfe-commits mailing list