r245821 - [modules] Stop updating all identifiers when writing a module. This is
Sean Silva via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 24 22:53:51 PDT 2015
On Sun, Aug 23, 2015 at 8:33 PM, Richard Smith via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> Author: rsmith
> Date: Sun Aug 23 22:33:22 2015
> New Revision: 245821
>
> URL: http://llvm.org/viewvc/llvm-project?rev=245821&view=rev
> Log:
> [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.
>
Why specifically C++ modules?
-- Sean Silva
>
> Modified:
> cfe/trunk/lib/Serialization/ASTReader.cpp
> cfe/trunk/lib/Serialization/ASTReaderInternals.h
> cfe/trunk/lib/Serialization/ASTWriter.cpp
> cfe/trunk/test/Modules/macros.c
>
> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=245821&r1=245820&r2=245821&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Sun Aug 23 22:33:22 2015
> @@ -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<uint32_t, little, unaligned>(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::Read
> 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);
> }
> }
>
>
> Modified: cfe/trunk/lib/Serialization/ASTReaderInternals.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderInternals.h?rev=245821&r1=245820&r2=245821&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTReaderInternals.h (original)
> +++ cfe/trunk/lib/Serialization/ASTReaderInternals.h Sun Aug 23 22:33:22
> 2015
> @@ -137,6 +137,8 @@ public:
> const unsigned char* d,
> unsigned DataLen);
>
> + IdentID ReadIdentifierID(const unsigned char *d);
> +
> ASTReader &getReader() const { return Reader; }
> };
>
>
> Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=245821&r1=245820&r2=245821&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sun Aug 23 22:33:22 2015
> @@ -4273,22 +4273,24 @@ void ASTWriter::WriteASTCore(Sema &SemaR
> }
>
> // Make sure all decls associated with an identifier are registered for
> - // serialization.
> - llvm::SmallVector<const IdentifierInfo*, 256> 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<IdentifierInfo>());
> - 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<const IdentifierInfo*, 256> 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<IdentifierInfo>());
> + for (const IdentifierInfo *II : IIs) {
> + for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II),
> + DEnd = SemaRef.IdResolver.end();
> + D != DEnd; ++D) {
> + GetDeclRef(*D);
> + }
> }
> }
>
>
> Modified: cfe/trunk/test/Modules/macros.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macros.c?rev=245821&r1=245820&r2=245821&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Modules/macros.c (original)
> +++ cfe/trunk/test/Modules/macros.c Sun Aug 23 22:33:22 2015
> @@ -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.
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150824/491c60ab/attachment.html>
More information about the cfe-commits
mailing list