diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-20 16:04:35 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-20 16:04:35 +0000 |
commit | 074dcc8ef8c5df7a155c85648e8eae786bee6cab (patch) | |
tree | 5c863db01bce5193d1e028a91032e95f2b30e9fa /lib/AST/DeclBase.cpp | |
parent | 5d26768e2661faa7ce0b55ffff4be8b3969fbbf5 (diff) |
Use the AST on-disk hash table for name lookup inside a DeclContext.
*Huge* improvement over the amount of deserializing that we do for C++ lookup.
e.g, if he have the Carbon header precompiled and include it on a file containing this:
int x;
these are the before/after stats:
BEFORE:
*** AST File Statistics:
578 stat cache hits
4 stat cache misses
548/30654 source location entries read (1.787695%)
15907/16501 types read (96.400223%)
53525/59955 declarations read (89.275291%)
33993/43525 identifiers read (78.099945%)
41516/51891 statements read (80.006165%)
77/5317 macros read (1.448185%)
0/6335 lexical declcontexts read (0.000000%)
1/5424 visible declcontexts read (0.018437%)
AFTER using the on-disk table:
*** AST File Statistics:
578 stat cache hits
4 stat cache misses
548/30654 source location entries read (1.787695%)
10/16501 types read (0.060602%)
9/59955 declarations read (0.015011%)
161/43525 identifiers read (0.369902%)
20/51891 statements read (0.038542%)
6/5317 macros read (0.112846%)
0/6335 lexical declcontexts read (0.000000%)
2/5424 visible declcontexts read (0.036873%)
There's only one issue affecting mostly the precompiled preambles which I will address soon.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111636 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r-- | lib/AST/DeclBase.cpp | 104 |
1 files changed, 13 insertions, 91 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 74cc1c29b9..30d540a00a 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -648,19 +648,6 @@ ExternalASTSource::SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclContext::lookup_result ExternalASTSource::SetExternalVisibleDeclsForName(const DeclContext *DC, - const VisibleDeclaration &VD) { - ASTContext &Context = DC->getParentASTContext(); - StoredDeclsMap *Map; - if (!(Map = DC->LookupPtr)) - Map = DC->CreateStoredDeclsMap(Context); - - StoredDeclsList &List = (*Map)[VD.Name]; - List.setFromDeclIDs(VD.Declarations); - return List.getLookupResult(Context); -} - -DeclContext::lookup_result -ExternalASTSource::SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, llvm::SmallVectorImpl<NamedDecl*> &Decls) { ASTContext &Context = DC->getParentASTContext();; @@ -677,35 +664,7 @@ ExternalASTSource::SetExternalVisibleDeclsForName(const DeclContext *DC, List.AddSubsequentDecl(Decls[I]); } - return List.getLookupResult(Context); -} - -void ExternalASTSource::SetExternalVisibleDecls(const DeclContext *DC, - const llvm::SmallVectorImpl<VisibleDeclaration> &Decls) { - // There is no longer any visible storage in this context. - DC->ExternalVisibleStorage = false; - - assert(!DC->LookupPtr && "Have a lookup map before de-serialization?"); - StoredDeclsMap *Map = DC->CreateStoredDeclsMap(DC->getParentASTContext()); - for (unsigned I = 0, N = Decls.size(); I != N; ++I) { - (*Map)[Decls[I].Name].setFromDeclIDs(Decls[I].Declarations); - } -} - -void ExternalASTSource::SetExternalVisibleDecls(const DeclContext *DC, - const llvm::SmallVectorImpl<NamedDecl*> &Decls) { - // There is no longer any visible storage in this context. - DC->ExternalVisibleStorage = false; - - assert(!DC->LookupPtr && "Have a lookup map before de-serialization?"); - StoredDeclsMap &Map = *DC->CreateStoredDeclsMap(DC->getParentASTContext()); - for (unsigned I = 0, N = Decls.size(); I != N; ++I) { - StoredDeclsList &List = Map[Decls[I]->getDeclName()]; - if (List.isNull()) - List.setOnlyValue(Decls[I]); - else - List.AddSubsequentDecl(Decls[I]); - } + return List.getLookupResult(); } DeclContext::decl_iterator DeclContext::noload_decls_begin() const { @@ -841,7 +800,7 @@ DeclContext::lookup(DeclarationName Name) { if (LookupPtr) { StoredDeclsMap::iterator I = LookupPtr->find(Name); if (I != LookupPtr->end()) - return I->second.getLookupResult(getParentASTContext()); + return I->second.getLookupResult(); } ExternalASTSource *Source = getParentASTContext().getExternalSource(); @@ -861,7 +820,7 @@ DeclContext::lookup(DeclarationName Name) { StoredDeclsMap::iterator Pos = LookupPtr->find(Name); if (Pos == LookupPtr->end()) return lookup_result(lookup_iterator(0), lookup_iterator(0)); - return Pos->second.getLookupResult(getParentASTContext()); + return Pos->second.getLookupResult(); } DeclContext::lookup_const_result @@ -925,18 +884,21 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) { if (isa<ClassTemplateSpecializationDecl>(D)) return; - // If there is an external AST source, load any declarations it knows about - // with this declaration's name. - if (ExternalASTSource *Source = getParentASTContext().getExternalSource()) - if (hasExternalVisibleStorage()) - Source->FindExternalVisibleDeclsByName(this, D->getDeclName()); - ASTContext *C = 0; if (!LookupPtr) { C = &getParentASTContext(); CreateStoredDeclsMap(*C); } + // If there is an external AST source, load any declarations it knows about + // with this declaration's name. + // If the lookup table contains an entry about this name it means that we + // have already checked the external source. + if (ExternalASTSource *Source = getParentASTContext().getExternalSource()) + if (hasExternalVisibleStorage() && + LookupPtr->find(D->getDeclName()) == LookupPtr->end()) + Source->FindExternalVisibleDeclsByName(this, D->getDeclName()); + // Insert this declaration into the map. StoredDeclsList &DeclNameEntries = (*LookupPtr)[D->getDeclName()]; if (DeclNameEntries.isNull()) { @@ -947,10 +909,7 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) { // If it is possible that this is a redeclaration, check to see if there is // already a decl for which declarationReplaces returns true. If there is // one, just replace it and return. - if (!C) - C = &getParentASTContext(); - - if (DeclNameEntries.HandleRedeclaration(*C, D)) + if (DeclNameEntries.HandleRedeclaration(D)) return; // Put this declaration into the appropriate slot. @@ -966,43 +925,6 @@ DeclContext::getUsingDirectives() const { reinterpret_cast<udir_iterator>(Result.second)); } -void StoredDeclsList::materializeDecls(ASTContext &Context) { - if (isNull()) - return; - - switch ((DataKind)(Data & 0x03)) { - case DK_Decl: - case DK_Decl_Vector: - break; - - case DK_DeclID: { - // Resolve this declaration ID to an actual declaration by - // querying the external AST source. - unsigned DeclID = Data >> 2; - - ExternalASTSource *Source = Context.getExternalSource(); - assert(Source && "No external AST source available!"); - - Data = reinterpret_cast<uintptr_t>(Source->GetExternalDecl(DeclID)); - break; - } - - case DK_ID_Vector: { - // We have a vector of declaration IDs. Resolve all of them to - // actual declarations. - VectorTy &Vector = *getAsVector(); - ExternalASTSource *Source = Context.getExternalSource(); - assert(Source && "No external AST source available!"); - - for (unsigned I = 0, N = Vector.size(); I != N; ++I) - Vector[I] = reinterpret_cast<uintptr_t>(Source->GetExternalDecl(Vector[I])); - - Data = (Data & ~0x03) | DK_Decl_Vector; - break; - } - } -} - //===----------------------------------------------------------------------===// // Creation and Destruction of StoredDeclsMaps. // //===----------------------------------------------------------------------===// |