From: Richard Smith Date: Mon, 24 Aug 2015 03:33:22 +0000 (+0000) Subject: [modules] Stop updating all identifiers when writing a module. This is X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7c37157bba61841444bd6ccf19ab06e4496f8f6;p=clang [modules] Stop updating all identifiers when writing a module. This is unnecessary in C++ modules (where we don't need the identifiers for their Decls) and expensive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245821 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 9899eaf698..8e19c708f7 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -755,6 +755,12 @@ static bool readBit(unsigned &Bits) { return Value; } +IdentID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) { + using namespace llvm::support; + unsigned RawID = endian::readNext(d); + return Reader.getGlobalIdentifierID(F, RawID >> 1); +} + IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, const unsigned char* d, unsigned DataLen) { @@ -3455,7 +3461,20 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, ASTIdentifierLookupTrait Trait(*this, F); auto KeyDataLen = Trait.ReadKeyDataLength(Data); auto Key = Trait.ReadKey(Data, KeyDataLen.first); - PP.getIdentifierTable().getOwn(Key).setOutOfDate(true); + auto &II = PP.getIdentifierTable().getOwn(Key); + II.setOutOfDate(true); + + // Mark this identifier as being from an AST file so that we can track + // whether we need to serialize it. + if (!II.isFromAST()) { + II.setIsFromAST(); + if (isInterestingIdentifier(*this, II, F.isModule())) + II.setChangedSinceDeserialization(); + } + + // Associate the ID with the identifier so that the writer can reuse it. + auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first); + SetIdentifierInfo(ID, &II); } } diff --git a/lib/Serialization/ASTReaderInternals.h b/lib/Serialization/ASTReaderInternals.h index 701cf7300f..47640f6c47 100644 --- a/lib/Serialization/ASTReaderInternals.h +++ b/lib/Serialization/ASTReaderInternals.h @@ -137,6 +137,8 @@ public: const unsigned char* d, unsigned DataLen); + IdentID ReadIdentifierID(const unsigned char *d); + ASTReader &getReader() const { return Reader; } }; diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index d7803d166e..678258eb44 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -4273,22 +4273,24 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, } // Make sure all decls associated with an identifier are registered for - // serialization. - llvm::SmallVector IIs; - for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), - IDEnd = PP.getIdentifierTable().end(); - ID != IDEnd; ++ID) { - const IdentifierInfo *II = ID->second; - if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) - IIs.push_back(II); - } - // Sort the identifiers to visit based on their name. - std::sort(IIs.begin(), IIs.end(), llvm::less_ptr()); - for (const IdentifierInfo *II : IIs) { - for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), - DEnd = SemaRef.IdResolver.end(); - D != DEnd; ++D) { - GetDeclRef(*D); + // serialization, if we're storing decls with identifiers. + if (!WritingModule || !getLangOpts().CPlusPlus) { + llvm::SmallVector IIs; + for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), + IDEnd = PP.getIdentifierTable().end(); + ID != IDEnd; ++ID) { + const IdentifierInfo *II = ID->second; + if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) + IIs.push_back(II); + } + // Sort the identifiers to visit based on their name. + std::sort(IIs.begin(), IIs.end(), llvm::less_ptr()); + for (const IdentifierInfo *II : IIs) { + for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), + DEnd = SemaRef.IdResolver.end(); + D != DEnd; ++D) { + GetDeclRef(*D); + } } } diff --git a/test/Modules/macros.c b/test/Modules/macros.c index 6995bcba5b..4b08e6c5d3 100644 --- a/test/Modules/macros.c +++ b/test/Modules/macros.c @@ -2,8 +2,14 @@ // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s -DALT // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s -detailed-preprocessing-record -// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -DLOCAL_VISIBILITY -fmodules-local-submodule-visibility -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s // RUN: not %clang_cc1 -E -fmodules -fimplicit-module-maps -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix CHECK-PREPROCESSED %s +// +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s -DALT +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s -detailed-preprocessing-record +// RUN: not %clang_cc1 -E -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix CHECK-PREPROCESSED %s +// +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -DLOCAL_VISIBILITY -fmodules-local-submodule-visibility -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s // FIXME: When we have a syntax for modules in C, use that. // These notes come from headers in modules, and are bogus.