diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-28 21:18:29 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-28 21:18:29 +0000 |
commit | a92193ebd9840e5ce4de1b09e49f1b024c0f5c2f (patch) | |
tree | 85d51c24d4fdf4ffdf76fed399f5c4fe5b4901b5 | |
parent | 13c8aa7a6c3605dd3c9588977b4809bb5128e6e0 (diff) |
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 :(
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70325 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Frontend/PCHReader.cpp | 20 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 37 |
2 files changed, 45 insertions, 12 deletions
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 8324f8de0b..64929dcb1d 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -220,6 +220,23 @@ public: 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 @@ public: Bits >>= 10; unsigned TokenID = Bits & 0xFF; Bits >>= 8; - - pch::IdentID ID = ReadUnalignedLE32(d); + assert(Bits == 0 && "Extra bits in the identifier?"); DataLen -= 8; diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 11f620279c..4870b4933a 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -1291,6 +1291,17 @@ class VISIBILITY_HIDDEN PCHIdentifierTableTrait { 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 @@ public: 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 @@ public: 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 @@ public: 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)); |