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

Sebastian Redl sebastian.redl at getdesigned.at
Wed Jul 21 13:07:32 PDT 2010


Author: cornedbee
Date: Wed Jul 21 15:07:32 2010
New Revision: 109030

URL: http://llvm.org/viewvc/llvm-project?rev=109030&view=rev
Log:
Promote some macro-related stuff to per-file data. Fix a cache-inefficient nested loop by inverting the nesting. Store the size of each file in the chain; will need this later for statement offsets.

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=109030&r1=109029&r2=109030&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Wed Jul 21 15:07:32 2010
@@ -208,6 +208,9 @@
     llvm::BitstreamReader StreamFile;
     llvm::BitstreamCursor Stream;
 
+    /// \brief The size of this file, in bits.
+    uint64_t SizeInBits;
+
     /// \brief The cursor to the start of the preprocessor block, which stores
     /// all of the macro definitions.
     llvm::BitstreamCursor MacroCursor;
@@ -267,6 +270,17 @@
     /// \brief A pointer to an on-disk hash table of opaque type
     /// IdentifierHashTable.
     void *IdentifierLookupTable;
+
+    /// \brief The number of macro definitions in this file.
+    unsigned LocalNumMacroDefinitions;
+
+    /// \brief Offsets of all of the macro definitions in the preprocessing
+    /// record in the PCH file.
+    const uint32_t *MacroDefinitionOffsets;
+      
+    /// \brief The number of preallocated preprocessing entities in the
+    /// preprocessing record.
+    unsigned NumPreallocatedPreprocessingEntities;
   };
 
   /// \brief The chain of PCH files. The first entry is the one named by the
@@ -330,18 +344,10 @@
   /// entries indicate that the particular selector ID has not yet
   /// been loaded.
   llvm::SmallVector<Selector, 16> SelectorsLoaded;
-
-  /// \brief Offsets of all of the macro definitions in the preprocessing
-  /// record in the PCH file.
-  const uint32_t *MacroDefinitionOffsets;
       
   /// \brief The macro definitions we have already loaded.
   llvm::SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded;
       
-  /// \brief The number of preallocated preprocessing entities in the
-  /// preprocessing record.
-  unsigned NumPreallocatedPreprocessingEntities;
-      
   /// \brief The set of external definitions stored in the the PCH
   /// file.
   llvm::SmallVector<uint64_t, 16> ExternalDefinitions;

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=109030&r1=109029&r2=109030&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Jul 21 15:07:32 2010
@@ -420,9 +420,7 @@
     Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context),
     Consumer(0), MethodPoolLookupTable(0), MethodPoolLookupTableData(0),
     TotalSelectorsInMethodPool(0), SelectorOffsets(0),
-    TotalNumSelectors(0), MacroDefinitionOffsets(0), 
-    NumPreallocatedPreprocessingEntities(0),  
-    isysroot(isysroot), NumStatHits(0), NumStatMisses(0),
+    TotalNumSelectors(0),  isysroot(isysroot), NumStatHits(0), NumStatMisses(0),
     NumSLocEntriesRead(0), TotalNumSLocEntries(0), NumStatementsRead(0),
     TotalNumStatements(0), NumMacrosRead(0), NumMethodPoolSelectorsRead(0),
     NumMethodPoolMisses(0), TotalNumMacros(0), NumLexicalDeclContextsRead(0),
@@ -437,9 +435,7 @@
     Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0),
     MethodPoolLookupTable(0), MethodPoolLookupTableData(0),
     TotalSelectorsInMethodPool(0), SelectorOffsets(0),
-    TotalNumSelectors(0), MacroDefinitionOffsets(0), 
-    NumPreallocatedPreprocessingEntities(0),  
-    isysroot(isysroot), NumStatHits(0), NumStatMisses(0),
+    TotalNumSelectors(0), isysroot(isysroot), NumStatHits(0), NumStatMisses(0),
     NumSLocEntriesRead(0), TotalNumSLocEntries(0), NumStatementsRead(0),
     TotalNumStatements(0), NumMacrosRead(0), NumMethodPoolSelectorsRead(0),
     NumMethodPoolMisses(0), TotalNumMacros(0), NumLexicalDeclContextsRead(0),
@@ -456,7 +452,9 @@
 PCHReader::PerFileData::PerFileData()
   : StatCache(0), LocalNumSLocEntries(0), LocalNumTypes(0), TypeOffsets(0),
     LocalNumDecls(0), DeclOffsets(0), LocalNumIdentifiers(0),
-    IdentifierOffsets(0), IdentifierTableData(0), IdentifierLookupTable(0)
+    IdentifierOffsets(0), IdentifierTableData(0), IdentifierLookupTable(0),
+    LocalNumMacroDefinitions(0), MacroDefinitionOffsets(0),
+    NumPreallocatedPreprocessingEntities(0)
 {}
 
 
@@ -1357,7 +1355,7 @@
     return 0;
   
   if (!MacroDefinitionsLoaded[ID])
-    ReadMacroRecord(MacroDefinitionOffsets[ID]);
+    ReadMacroRecord(Chain[0]->MacroDefinitionOffsets[ID]);
     
   return MacroDefinitionsLoaded[ID];
 }
@@ -1691,18 +1689,11 @@
       }
       break;
     }
-        
+
     case pch::MACRO_DEFINITION_OFFSETS:
-      MacroDefinitionOffsets = (const uint32_t *)BlobStart;
-      if (PP) {
-        if (!PP->getPreprocessingRecord())
-          PP->createPreprocessingRecord();
-        PP->getPreprocessingRecord()->SetExternalSource(*this, Record[0]);
-      } else {
-        NumPreallocatedPreprocessingEntities = Record[0];
-      }
-       
-      MacroDefinitionsLoaded.resize(Record[1]);
+      F.MacroDefinitionOffsets = (const uint32_t *)BlobStart;
+      F.NumPreallocatedPreprocessingEntities = Record[0];
+      F.LocalNumMacroDefinitions = Record[1];
       break;
     }
     First = false;
@@ -1721,17 +1712,30 @@
   // Here comes stuff that we only do once the entire chain is loaded.
 
   // Allocate space for loaded identifiers, decls and types.
-  unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0;
+  unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0,
+           TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0;
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
     TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers;
     TotalNumTypes += Chain[I]->LocalNumTypes;
     TotalNumDecls += Chain[I]->LocalNumDecls;
+    TotalNumPreallocatedPreprocessingEntities +=
+        Chain[I]->NumPreallocatedPreprocessingEntities;
+    TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions;
   }
   IdentifiersLoaded.resize(TotalNumIdentifiers);
   TypesLoaded.resize(TotalNumTypes);
   DeclsLoaded.resize(TotalNumDecls);
-  if (PP && TotalNumIdentifiers > 0)
-    PP->getHeaderSearchInfo().SetExternalLookup(this);
+  MacroDefinitionsLoaded.resize(TotalNumMacroDefs);
+  if (PP) {
+    if (TotalNumIdentifiers > 0)
+      PP->getHeaderSearchInfo().SetExternalLookup(this);
+    if (TotalNumPreallocatedPreprocessingEntities > 0) {
+      if (!PP->getPreprocessingRecord())
+        PP->createPreprocessingRecord();
+      PP->getPreprocessingRecord()->SetExternalSource(*this,
+                                     TotalNumPreallocatedPreprocessingEntities);
+    }
+  }
 
   // Check the predefines buffers.
   if (CheckPredefinesBuffers())
@@ -1755,19 +1759,17 @@
                                 IdEnd = PP->getIdentifierTable().end();
          Id != IdEnd; ++Id)
       Identifiers.push_back(Id->second);
-    // FIXME: The loop order here is very cache-inefficient. Loop over files
-    // should probably be the outer loop.
-    for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) {
-      IdentifierInfo *II = Identifiers[I];
-      // Look in the on-disk hash tables for an entry for this identifier
-      PCHIdentifierLookupTrait Info(*this, II);
-      std::pair<const char*, unsigned> Key(II->getNameStart(), II->getLength());
-      // We need to search the tables in all files.
-      // FIXME: What happens if this stuff changes between files, e.g. the
-      // dependent PCH undefs a macro from the core file?
-      for (unsigned J = 0, M = Chain.size(); J != M; ++J) {
-        PCHIdentifierLookupTable *IdTable
-          = (PCHIdentifierLookupTable *)Chain[J]->IdentifierLookupTable;
+    // We need to search the tables in all files.
+    // FIXME: What happens if this stuff changes between files, e.g. the
+    // dependent PCH undefs a macro from the core file?
+    for (unsigned J = 0, M = Chain.size(); J != M; ++J) {
+      PCHIdentifierLookupTable *IdTable
+        = (PCHIdentifierLookupTable *)Chain[J]->IdentifierLookupTable;
+      for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) {
+        IdentifierInfo *II = Identifiers[I];
+        // Look in the on-disk hash tables for an entry for this identifier
+        PCHIdentifierLookupTrait Info(*this, II);
+        std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength());
         PCHIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info);
         if (Pos == IdTable->end())
           continue;
@@ -1807,6 +1809,7 @@
                     (const unsigned char *)F.Buffer->getBufferEnd());
   llvm::BitstreamCursor &Stream = F.Stream;
   Stream.init(F.StreamFile);
+  F.SizeInBits = F.Buffer->getBufferSize() * 8;
 
   // Sniff for the signature.
   if (Stream.Read(8) != 'C' ||
@@ -1873,13 +1876,14 @@
 
 void PCHReader::setPreprocessor(Preprocessor &pp) {
   PP = &pp;
-  
-  if (NumPreallocatedPreprocessingEntities) {
+
+  unsigned TotalNum = 0;
+  for (unsigned I = 0, N = Chain.size(); I != N; ++I)
+    TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities;
+  if (TotalNum) {
     if (!PP->getPreprocessingRecord())
       PP->createPreprocessingRecord();
-    PP->getPreprocessingRecord()->SetExternalSource(*this, 
-                                          NumPreallocatedPreprocessingEntities);
-    NumPreallocatedPreprocessingEntities = 0;
+    PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum);
   }
 }
 





More information about the cfe-commits mailing list