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

Douglas Gregor dgregor at apple.com
Tue Apr 28 14:18:29 PDT 2009


Author: dgregor
Date: Tue Apr 28 16:18:29 2009
New Revision: 70325

URL: http://llvm.org/viewvc/llvm-project?rev=70325&view=rev
Log:
Implement a minor space optimization for the PCH identifier table,
which eliminates the storage for IdentifierInfo in the "uninteresting
identifier" cases. Sadly, this only brought back 7k of the 500k we
lost :(

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=70325&r1=70324&r2=70325&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Tue Apr 28 16:18:29 2009
@@ -220,6 +220,23 @@
                            const unsigned char* d,
                            unsigned DataLen) {
     using namespace clang::io;
+    pch::IdentID ID = ReadUnalignedLE32(d);
+    bool IsInteresting = ID & 0x01;
+
+    // Wipe out the "is interesting" bit.
+    ID = ID >> 1;
+
+    if (!IsInteresting) {
+      // For unintersting identifiers, just build the IdentifierInfo
+      // and associate it with the persistent ID.
+      IdentifierInfo *II = KnownII;
+      if (!II)
+        II = &Reader.getIdentifierTable().CreateIdentifierInfo(
+                                                 k.first, k.first + k.second);
+      Reader.SetIdentifierInfo(ID, II);
+      return II;
+    }
+
     uint32_t Bits = ReadUnalignedLE32(d);
     bool CPlusPlusOperatorKeyword = Bits & 0x01;
     Bits >>= 1;
@@ -233,8 +250,7 @@
     Bits >>= 10;
     unsigned TokenID = Bits & 0xFF;
     Bits >>= 8;
-
-    pch::IdentID ID = ReadUnalignedLE32(d);
+    
     assert(Bits == 0 && "Extra bits in the identifier?");
     DataLen -= 8;
 

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Tue Apr 28 16:18:29 2009
@@ -1291,6 +1291,17 @@
   PCHWriter &Writer;
   Preprocessor &PP;
 
+  /// \brief Determines whether this is an "interesting" identifier
+  /// that needs a full IdentifierInfo structure written into the hash
+  /// table.
+  static bool isInterestingIdentifier(const IdentifierInfo *II) {
+    return II->isPoisoned() ||
+      II->isExtensionToken() ||
+      II->hasMacroDefinition() ||
+      II->getObjCOrBuiltinID() ||
+      II->getFETokenInfo<void>();
+  }
+
 public:
   typedef const IdentifierInfo* key_type;
   typedef key_type  key_type_ref;
@@ -1309,15 +1320,17 @@
     EmitKeyDataLength(llvm::raw_ostream& Out, const IdentifierInfo* II, 
                       pch::IdentID ID) {
     unsigned KeyLen = strlen(II->getName()) + 1;
-    unsigned DataLen = 4 + 4; // 4 bytes for token ID, builtin, flags
-                              // 4 bytes for the persistent ID
-    if (II->hasMacroDefinition() && 
-        !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro())
-      DataLen += 8;
-    for (IdentifierResolver::iterator D = IdentifierResolver::begin(II),
-                                   DEnd = IdentifierResolver::end();
-         D != DEnd; ++D)
-      DataLen += sizeof(pch::DeclID);
+    unsigned DataLen = 4; // 4 bytes for the persistent ID << 1
+    if (isInterestingIdentifier(II)) {
+      DataLen += 4; // 4 bytes for token ID, builtin, flags
+      if (II->hasMacroDefinition() && 
+          !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro())
+        DataLen += 8;
+      for (IdentifierResolver::iterator D = IdentifierResolver::begin(II),
+                                     DEnd = IdentifierResolver::end();
+           D != DEnd; ++D)
+        DataLen += sizeof(pch::DeclID);
+    }
     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
@@ -1336,6 +1349,11 @@
   
   void EmitData(llvm::raw_ostream& Out, const IdentifierInfo* II, 
                 pch::IdentID ID, unsigned) {
+    if (!isInterestingIdentifier(II)) {
+      clang::io::Emit32(Out, ID << 1);
+      return;
+    }
+    clang::io::Emit32(Out, (ID << 1) | 0x01);
     uint32_t Bits = 0;
     bool hasMacroDefinition = 
       II->hasMacroDefinition() && 
@@ -1347,7 +1365,6 @@
     Bits = (Bits << 1) | II->isPoisoned();
     Bits = (Bits << 1) | II->isCPlusPlusOperatorKeyword();
     clang::io::Emit32(Out, Bits);
-    clang::io::Emit32(Out, ID);
 
     if (hasMacroDefinition)
       clang::io::Emit64(Out, Writer.getMacroOffset(II));





More information about the cfe-commits mailing list