From: Douglas Gregor Date: Tue, 24 Jan 2012 15:24:38 +0000 (+0000) Subject: Only mark an IdentifierInfo as having changed since deserialization X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d5051f3e79bf754134ccdf7a1dc7778cd80c73e;p=clang Only mark an IdentifierInfo as having changed since deserialization when it actually has changed (and not, e.g., when we've simply attached a deserialized macro definition). Good for ~1.5% reduction in module file size, mostly in the identifier table. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148808 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index c6190b0470..33efbd960c 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -433,7 +433,8 @@ public: /// setMacroInfo - Specify a macro for this identifier. /// - void setMacroInfo(IdentifierInfo *II, MacroInfo *MI); + void setMacroInfo(IdentifierInfo *II, MacroInfo *MI, + bool LoadedFromAST = false); /// macro_iterator/macro_begin/macro_end - This allows you to walk the current /// state of the macro table. This visits every currently-defined macro. diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 73efb4d576..035272279d 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -47,16 +47,17 @@ MacroInfo *Preprocessor::getInfoForMacro(IdentifierInfo *II) const { /// setMacroInfo - Specify a macro for this identifier. /// -void Preprocessor::setMacroInfo(IdentifierInfo *II, MacroInfo *MI) { +void Preprocessor::setMacroInfo(IdentifierInfo *II, MacroInfo *MI, + bool LoadedFromAST) { if (MI) { Macros[II] = MI; II->setHasMacroDefinition(true); - if (II->isFromAST()) + if (II->isFromAST() && !LoadedFromAST) II->setChangedSinceDeserialization(); } else if (II->hasMacroDefinition()) { Macros.erase(II); II->setHasMacroDefinition(false); - if (II->isFromAST()) + if (II->isFromAST() && !LoadedFromAST) II->setChangedSinceDeserialization(); } } diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp index a80f23f58e..b4691617d0 100644 --- a/lib/Sema/IdentifierResolver.cpp +++ b/lib/Sema/IdentifierResolver.cpp @@ -202,10 +202,6 @@ void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) { return; } - if (IdentifierInfo *II = Name.getAsIdentifierInfo()) - if (II->isFromAST()) - II->setChangedSinceDeserialization(); - // General case: insert the declaration at the appropriate point in the // list, which already has at least two elements. IdDeclInfo *IDI = toIdDeclInfo(Ptr); @@ -323,7 +319,7 @@ static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New) { bool IdentifierResolver::tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name){ if (IdentifierInfo *II = Name.getAsIdentifierInfo()) - updatingIdentifier(*II); + readingIdentifier(*II); void *Ptr = Name.getFETokenInfo(); diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 5842bbb468..683bc379cb 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -510,8 +510,10 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, // For uninteresting identifiers, just build the IdentifierInfo // and associate it with the persistent ID. IdentifierInfo *II = KnownII; - if (!II) + if (!II) { II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); + KnownII = II; + } Reader.SetIdentifierInfo(ID, II); II->setIsFromAST(); Reader.markIdentifierUpToDate(II); @@ -538,8 +540,10 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, // Build the IdentifierInfo itself and link the identifier ID with // the new IdentifierInfo. IdentifierInfo *II = KnownII; - if (!II) + if (!II) { II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); + KnownII = II; + } Reader.markIdentifierUpToDate(II); II->setIsFromAST(); @@ -1362,7 +1366,7 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { } // Finally, install the macro. - PP.setMacroInfo(II, MI); + PP.setMacroInfo(II, MI, /*LoadedFromAST=*/true); // Remember that we saw this macro last so that we add the tokens that // form its body to it. @@ -1541,7 +1545,7 @@ void ASTReader::ReadDefinedMacros() { } void ASTReader::LoadMacroDefinition( - llvm::DenseMap::iterator Pos) { + llvm::DenseMap::iterator Pos) { assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); uint64_t Offset = Pos->second; UnreadMacroRecordOffsets.erase(Pos); @@ -1579,9 +1583,12 @@ namespace { if (!IdTable) return false; + ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), + M, This->Found); + std::pair Key(This->Name.begin(), This->Name.size()); - ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); + ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Trait); if (Pos == IdTable->end()) return false; diff --git a/lib/Serialization/ASTReaderInternals.h b/lib/Serialization/ASTReaderInternals.h index 635f95fe59..3a1dfcf4b7 100644 --- a/lib/Serialization/ASTReaderInternals.h +++ b/lib/Serialization/ASTReaderInternals.h @@ -129,6 +129,9 @@ public: IdentifierInfo *ReadData(const internal_key_type& k, const unsigned char* d, unsigned DataLen); + + ASTReader &getReader() const { return Reader; } + }; /// \brief The on-disk hash table used to contain information about