diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-10-14 20:14:34 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-10-14 20:14:34 +0000 |
commit | eb5e9986e577b1e2bff3cca5973a2494fb593fbb (patch) | |
tree | 72f5c7c97cf402e7afdc1df4587ce7a240a3f0f9 /lib/Serialization | |
parent | 336d43a368cee30549dc21a94e25fb03f887a27e (diff) |
Allow deserialization of just the fields of a record, when we want to iterate over them,
instead of deserializing the complete declaration context of the record.
Iterating over the fields of a record is very common (e.g to determine the layout), unfortunately we needlessly deserialize every declaration
that the declaration context of the record contains; this can be bad for large C++ classes that contain a lot of methods.
Fix this by allow deserialization of just the fields when we want to iterate over them.
Progress for rdar://7260160.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116507 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 18 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 13 |
2 files changed, 18 insertions, 13 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 9ee818367b..23f2eaac66 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -903,8 +903,8 @@ bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, return true; } - Info.LexicalDecls = reinterpret_cast<const DeclID*>(Blob); - Info.NumLexicalDecls = BlobLen / sizeof(DeclID); + Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); + Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); } else { Info.LexicalDecls = 0; Info.NumLexicalDecls = 0; @@ -1778,8 +1778,8 @@ ASTReader::ReadASTBlock(PerFileData &F) { case TU_UPDATE_LEXICAL: { DeclContextInfo Info = { /* No visible information */ 0, - reinterpret_cast<const DeclID *>(BlobStart), - BlobLen / sizeof(DeclID) + reinterpret_cast<const KindDeclIDPair *>(BlobStart), + BlobLen / sizeof(KindDeclIDPair) }; DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] .push_back(Info); @@ -3242,6 +3242,7 @@ Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { } bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, + bool (*isKindWeWant)(Decl::Kind), llvm::SmallVectorImpl<Decl*> &Decls) { assert(DC->hasExternalLexicalStorage() && "DeclContext has no lexical decls in storage"); @@ -3258,9 +3259,12 @@ bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, continue; // Load all of the declaration IDs - for (const DeclID *ID = I->LexicalDecls, *IDE = ID + I->NumLexicalDecls; - ID != IDE; ++ID) { - Decl *D = GetDecl(*ID); + for (const KindDeclIDPair *ID = I->LexicalDecls, + *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { + if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) + continue; + + Decl *D = GetDecl(ID->second); assert(D && "Null decl in lexical decls"); Decls.push_back(D); } diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index eae47db44e..8dffe1a950 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1474,14 +1474,15 @@ uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, uint64_t Offset = Stream.GetCurrentBitNo(); RecordData Record; Record.push_back(DECL_CONTEXT_LEXICAL); - llvm::SmallVector<DeclID, 64> Decls; + llvm::SmallVector<KindDeclIDPair, 64> Decls; for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); D != DEnd; ++D) - Decls.push_back(GetDeclRef(*D)); + Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); ++NumLexicalDeclContexts; Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, - reinterpret_cast<char*>(Decls.data()), Decls.size() * sizeof(DeclID)); + reinterpret_cast<char*>(Decls.data()), + Decls.size() * sizeof(KindDeclIDPair)); return Offset; } @@ -2471,12 +2472,12 @@ void ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls, // We don't start with the translation unit, but with its decls that // don't come from the chained PCH. const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); - llvm::SmallVector<DeclID, 64> NewGlobalDecls; + llvm::SmallVector<KindDeclIDPair, 64> NewGlobalDecls; for (DeclContext::decl_iterator I = TU->noload_decls_begin(), E = TU->noload_decls_end(); I != E; ++I) { if ((*I)->getPCHLevel() == 0) - NewGlobalDecls.push_back(GetDeclRef(*I)); + NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); else if ((*I)->isChangedSinceDeserialization()) (void)GetDeclRef(*I); // Make sure it's written, but don't record it. } @@ -2489,7 +2490,7 @@ void ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls, Record.push_back(TU_UPDATE_LEXICAL); Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, reinterpret_cast<const char*>(NewGlobalDecls.data()), - NewGlobalDecls.size() * sizeof(DeclID)); + NewGlobalDecls.size() * sizeof(KindDeclIDPair)); // And in C++, a visible updates block for the TU. if (Context.getLangOptions().CPlusPlus) { Abv = new llvm::BitCodeAbbrev(); |