[cfe-commits] r70320 - in /cfe/trunk/lib/Frontend: PCHReader.cpp PCHWriter.cpp

Douglas Gregor dgregor at apple.com
Tue Apr 28 13:01:51 PDT 2009


Author: dgregor
Date: Tue Apr 28 15:01:51 2009
New Revision: 70320

URL: http://llvm.org/viewvc/llvm-project?rev=70320&view=rev
Log:
Revert r70075 and r70078, which reorganized the PCH on-disk hash table
for identifiers to separate "interesting" from "uninteresting"
identifiers. However, to cope with compiler invocations where the
predefines buffers mismatch, we need to be able to search the complete
identifier table. Cocoa.h.pch is now about 500k larger that it used to
be :(

Modified:
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=70320&r1=70319&r2=70320&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Tue Apr 28 15:01:51 2009
@@ -1943,47 +1943,14 @@
     uint32_t Offset = IdentifierOffsets[ID - 1];
     const char *Str = IdentifierTableData + Offset;
 
-    // If there is an identifier lookup table, but the offset of this
-    // string is after the identifier table itself, then we know that
-    // this string is not in the on-disk hash table. Therefore,
-    // disable lookup into the hash table when looking for this
-    // identifier.
-    PCHIdentifierLookupTable *IdTable 
-      = (PCHIdentifierLookupTable *)IdentifierLookupTable;
-    if (!IdTable ||
-        Offset >= uint32_t(IdTable->getBuckets() - IdTable->getBase())) {
-      // Turn off lookup into the on-disk hash table. We know that
-      // this identifier is not there.
-      if (IdTable)
-        PP.getIdentifierTable().setExternalIdentifierLookup(0);
-
-      // All of the strings in the PCH file are preceded by a 16-bit
-      // length. Extract that 16-bit length to avoid having to execute
-      // strlen().
-      const char *StrLenPtr = Str - 2;
-      unsigned StrLen = (((unsigned) StrLenPtr[0])
-                         | (((unsigned) StrLenPtr[1]) << 8)) - 1;
-      IdentifiersLoaded[ID - 1]=&PP.getIdentifierTable().get(Str, Str + StrLen);
-
-      // Turn on lookup into the on-disk hash table, if we have an
-      // on-disk hash table.
-      if (IdTable)
-        PP.getIdentifierTable().setExternalIdentifierLookup(this);
-    } else {
-      // The identifier is a key in our on-disk hash table. Since we
-      // know where the hash table entry starts, just read in this
-      // (key, value) pair.
-      PCHIdentifierLookupTrait Trait(const_cast<PCHReader &>(*this));
-      const unsigned char *Pos = (const unsigned char *)Str - 4;
-      std::pair<unsigned, unsigned> KeyDataLengths
-        = Trait.ReadKeyDataLength(Pos);
-
-      PCHIdentifierLookupTrait::internal_key_type InternalKey
-        = Trait.ReadKey(Pos, KeyDataLengths.first);
-      Pos = (const unsigned char *)Str + KeyDataLengths.first;
-      IdentifiersLoaded[ID - 1] = Trait.ReadData(InternalKey, Pos,
-                                                 KeyDataLengths.second);
-    }
+    // All of the strings in the PCH file are preceded by a 16-bit
+    // length. Extract that 16-bit length to avoid having to execute
+    // strlen().
+    const char *StrLenPtr = Str - 2;
+    unsigned StrLen = (((unsigned) StrLenPtr[0])
+                       | (((unsigned) StrLenPtr[1]) << 8)) - 1;
+    IdentifiersLoaded[ID - 1] 
+      = &PP.getIdentifierTable().get(Str, Str + StrLen);
   }
   
   return IdentifiersLoaded[ID - 1];

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=70320&r1=70319&r2=70320&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Tue Apr 28 15:01:51 2009
@@ -1318,12 +1318,10 @@
                                    DEnd = IdentifierResolver::end();
          D != DEnd; ++D)
       DataLen += sizeof(pch::DeclID);
-    // We emit the key length after the data length so that the
-    // "uninteresting" identifiers following the identifier hash table
-    // structure will have the same (key length, key characters)
-    // layout as the keys in the hash table. This also matches the
-    // format for identifiers in pretokenized headers.
     clang::io::Emit16(Out, DataLen);
+    // We emit the key length after the data length so that every
+    // string is preceded by a 16-bit length. This matches the PTH
+    // format for storing identifiers.
     clang::io::Emit16(Out, KeyLen);
     return std::make_pair(KeyLen, DataLen);
   }
@@ -1384,33 +1382,12 @@
   {
     OnDiskChainedHashTableGenerator<PCHIdentifierTableTrait> Generator;
     
-    llvm::SmallVector<const IdentifierInfo *, 32> UninterestingIdentifiers;
-
     // Create the on-disk hash table representation.
     for (llvm::DenseMap<const IdentifierInfo *, pch::IdentID>::iterator
            ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end();
          ID != IDEnd; ++ID) {
       assert(ID->first && "NULL identifier in identifier table");
-
-      // Classify each identifier as either "interesting" or "not
-      // interesting". Interesting identifiers are those that have
-      // additional information that needs to be read from the PCH
-      // file, e.g., a built-in ID, declaration chain, or macro
-      // definition. These identifiers are placed into the hash table
-      // so that they can be found when looked up in the user program.
-      // All other identifiers are "uninteresting", which means that
-      // the IdentifierInfo built by default has all of the
-      // information we care about. Such identifiers are placed after
-      // the hash table.
-      const IdentifierInfo *II = ID->first;
-      if (II->isPoisoned() ||
-          II->isExtensionToken() ||
-          II->hasMacroDefinition() ||
-          II->getObjCOrBuiltinID() ||
-          II->getFETokenInfo<void>())
-        Generator.insert(ID->first, ID->second);
-      else
-        UninterestingIdentifiers.push_back(II);
+      Generator.insert(ID->first, ID->second);
     }
 
     // Create the on-disk hash table in a buffer.
@@ -1422,14 +1399,6 @@
       // Make sure that no bucket is at offset 0
       clang::io::Emit32(Out, 0);
       BucketOffset = Generator.Emit(Out, Trait);
-      
-      for (unsigned I = 0, N = UninterestingIdentifiers.size(); I != N; ++I) {
-        const IdentifierInfo *II = UninterestingIdentifiers[I];
-        unsigned N = II->getLength() + 1;
-        clang::io::Emit16(Out, N);
-        SetIdentifierOffset(II, Out.tell());
-        Out.write(II->getName(), N);
-      }
     }
 
     // Create a blob abbreviation





More information about the cfe-commits mailing list