]> granicus.if.org Git - clang/commitdiff
[PCH] Store the offsets of source location file entries and go through them
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 2 Jun 2011 20:01:46 +0000 (20:01 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 2 Jun 2011 20:01:46 +0000 (20:01 +0000)
in ASTReader::validateFileEntries().

This avoids going through all source location entries and fixes the performance regression.
Many thanks to Doug for the hint!
(rdar://9530587)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132481 91177308-0d34-0410-b5e6-96231b3b80d8

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

index ae87b291477eca902b8d3d89336c87a631356129..113f73ad7d435c7068b94ffc9ead2b0cdf3cb26e 100644 (file)
@@ -367,7 +367,12 @@ namespace clang {
       OPENCL_EXTENSIONS = 43,
 
       /// \brief The list of delegating constructor declarations.
-      DELEGATING_CTORS = 44
+      DELEGATING_CTORS = 44,
+
+      /// \brief Record code for the table of offsets into the block
+      /// of file source-location information.
+      FILE_SOURCE_LOCATION_OFFSETS = 45
+
     };
 
     /// \brief Record types used within a source manager block.
index 6d3a0c9bd04d1531849320064e69012bf4ca3523..8923e2ab0d71318ae7e7bc71017028a0de554e5a 100644 (file)
@@ -257,6 +257,13 @@ private:
     /// AST file.
     const uint32_t *SLocOffsets;
 
+    /// \brief The number of source location file entries in this AST file.
+    unsigned LocalNumSLocFileEntries;
+
+    /// \brief Offsets for all of the source location file entries in the
+    /// AST file.
+    const uint32_t *SLocFileOffsets;
+
     /// \brief The entire size of this module's source location offset range.
     unsigned LocalSLocSize;
 
index 8b99fc7dfe6e2b4332fd5f70c4a4c9064602834d..3c3993f412d30b6724d1c884c3ddf2fc690511f7 100644 (file)
@@ -2193,6 +2193,11 @@ ASTReader::ReadASTBlock(PerFileData &F) {
       F.LocalSLocSize = Record[1];
       break;
 
+    case FILE_SOURCE_LOCATION_OFFSETS:
+      F.SLocFileOffsets = (const uint32_t *)BlobStart;
+      F.LocalNumSLocFileEntries = Record[0];
+      break;
+
     case SOURCE_LOCATION_PRELOADS:
       if (PreloadSLocEntries.empty())
         PreloadSLocEntries.swap(Record);
@@ -2372,8 +2377,8 @@ ASTReader::ASTReadResult ASTReader::validateFileEntries() {
     PerFileData *F = Chain[CI];
     llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
 
-    for (unsigned i = 0, e = F->LocalNumSLocEntries; i != e; ++i) {
-      SLocEntryCursor.JumpToBit(F->SLocOffsets[i]);
+    for (unsigned i = 0, e = F->LocalNumSLocFileEntries; i != e; ++i) {
+      SLocEntryCursor.JumpToBit(F->SLocFileOffsets[i]);
       unsigned Code = SLocEntryCursor.ReadCode();
       if (Code == llvm::bitc::END_BLOCK ||
           Code == llvm::bitc::ENTER_SUBBLOCK ||
@@ -2429,10 +2434,6 @@ ASTReader::ASTReadResult ASTReader::validateFileEntries() {
 
         break;
       }
-
-      case SM_SLOC_BUFFER_ENTRY:
-      case SM_SLOC_INSTANTIATION_ENTRY:
-        break;
       }
     }
   }
@@ -5197,7 +5198,8 @@ ASTReader::~ASTReader() {
 }
 
 ASTReader::PerFileData::PerFileData(ASTFileType Ty)
-  : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0),
+  : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0),
+    SLocFileOffsets(0), LocalSLocSize(0),
     LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0),
     IdentifierLookupTable(0), LocalNumMacroDefinitions(0),
     MacroDefinitionOffsets(0), 
index 297115c491c9fbdc339f3b2fceb4f1e3828d5db9..3bb27cff0f121164b9c704208e1136e803085832 100644 (file)
@@ -1449,6 +1449,9 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
   // Write out the source location entry table. We skip the first
   // entry, which is always the same dummy entry.
   std::vector<uint32_t> SLocEntryOffsets;
+  // Write out the offsets of only source location file entries.
+  // We will go through them in ASTReader::validateFileEntries().
+  std::vector<uint32_t> SLocFileEntryOffsets;
   RecordData PreloadSLocs;
   unsigned BaseSLocID = Chain ? Chain->getTotalNumSLocs() : 0;
   SLocEntryOffsets.reserve(SourceMgr.sloc_entry_size() - 1 - BaseSLocID);
@@ -1463,9 +1466,10 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
     // Figure out which record code to use.
     unsigned Code;
     if (SLoc->isFile()) {
-      if (SLoc->getFile().getContentCache()->OrigEntry)
+      if (SLoc->getFile().getContentCache()->OrigEntry) {
         Code = SM_SLOC_FILE_ENTRY;
-      else
+        SLocFileEntryOffsets.push_back(Stream.GetCurrentBitNo());
+      } else
         Code = SM_SLOC_BUFFER_ENTRY;
     } else
       Code = SM_SLOC_INSTANTIATION_ENTRY;
@@ -1565,6 +1569,18 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
   Record.push_back(SourceMgr.getNextOffset() - BaseOffset);
   Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets));
 
+  Abbrev = new BitCodeAbbrev();
+  Abbrev->Add(BitCodeAbbrevOp(FILE_SOURCE_LOCATION_OFFSETS));
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets
+  unsigned SLocFileOffsetsAbbrev = Stream.EmitAbbrev(Abbrev);
+
+  Record.clear();
+  Record.push_back(FILE_SOURCE_LOCATION_OFFSETS);
+  Record.push_back(SLocFileEntryOffsets.size());
+  Stream.EmitRecordWithBlob(SLocFileOffsetsAbbrev, Record,
+                            data(SLocFileEntryOffsets));
+
   // Write the source location entry preloads array, telling the AST
   // reader which source locations entries it should load eagerly.
   Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs);