summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-21 22:25:48 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-21 22:25:48 +0000
commita868bbd392594290cff15a3d25e8a69fe43a3857 (patch)
tree045c8d9a805a09312e207cea5c7a0a8aab565ca6 /clang/lib/Sema
parent1f9183c7ca3621dff097392aa5b2390a3ea69df3 (diff)
downloadbcm5719-llvm-a868bbd392594290cff15a3d25e8a69fe43a3857.tar.gz
bcm5719-llvm-a868bbd392594290cff15a3d25e8a69fe43a3857.zip
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header. This patch changes the primary name lookup method for entities within a precompiled header. Previously, we would load all of the names of declarations at translation unit scope into a large DenseMap (inside the TranslationUnitDecl's DeclContext), and then perform a special "last resort" lookup into this DeclContext when we knew there was a PCH file (see Sema::LookupName). Now, when we see an identifier named for the first time, we load all of the declarations with that name that are visible from the translation unit into the IdentifierInfo's chain of declarations. Thus, the explicit "look into the translation unit's DeclContext" code is gone, and Sema effectively uses the same IdentifierInfo-based name lookup mechanism whether we are using a PCH file or not. This approach should help PCH scale with the size of the input program rather than the size of the PCH file. The "Hello, World!" application with Carbon.h as a PCH file now loads 20% of the identifiers in the PCH file rather than 85% of the identifiers. 90% of the 20% of identifiers loaded are actually loaded when we deserialize the preprocessor state. The next step is to make the preprocessor load macros lazily, which should drastically reduce the number of types, declarations, and identifiers loaded for "Hello, World". llvm-svn: 69737
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/IdentifierResolver.cpp22
-rw-r--r--clang/lib/Sema/IdentifierResolver.h8
-rw-r--r--clang/lib/Sema/ParseAST.cpp10
-rw-r--r--clang/lib/Sema/SemaLookup.cpp11
4 files changed, 38 insertions, 13 deletions
diff --git a/clang/lib/Sema/IdentifierResolver.cpp b/clang/lib/Sema/IdentifierResolver.cpp
index c31435b6771..ceab859c90a 100644
--- a/clang/lib/Sema/IdentifierResolver.cpp
+++ b/clang/lib/Sema/IdentifierResolver.cpp
@@ -243,6 +243,28 @@ IdentifierResolver::begin(DeclarationName Name) {
return end();
}
+void IdentifierResolver::AddDeclToIdentifierChain(IdentifierInfo *II,
+ NamedDecl *D) {
+ void *Ptr = II->getFETokenInfo<void>();
+
+ if (!Ptr) {
+ II->setFETokenInfo(D);
+ return;
+ }
+
+ IdDeclInfo *IDI;
+
+ if (isDeclPtr(Ptr)) {
+ II->setFETokenInfo(NULL);
+ IDI = &(*IdDeclInfos)[II];
+ NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
+ IDI->AddDecl(PrevD);
+ } else
+ IDI = toIdDeclInfo(Ptr);
+
+ IDI->AddDecl(D);
+}
+
//===----------------------------------------------------------------------===//
// IdDeclInfoMap Implementation
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Sema/IdentifierResolver.h b/clang/lib/Sema/IdentifierResolver.h
index 1843f4ebca1..0b0e6b388dd 100644
--- a/clang/lib/Sema/IdentifierResolver.h
+++ b/clang/lib/Sema/IdentifierResolver.h
@@ -177,6 +177,14 @@ public:
/// (and, therefore, replaced).
bool ReplaceDecl(NamedDecl *Old, NamedDecl *New);
+ /// \brief Link the declaration into the chain of declarations for
+ /// the given identifier.
+ ///
+ /// This is a lower-level routine used by the PCH reader to link a
+ /// declaration into a specific IdentifierInfo before the
+ /// declaration actually has a name.
+ void AddDeclToIdentifierChain(IdentifierInfo *II, NamedDecl *D);
+
explicit IdentifierResolver(const LangOptions &LangOpt);
~IdentifierResolver();
diff --git a/clang/lib/Sema/ParseAST.cpp b/clang/lib/Sema/ParseAST.cpp
index 448556092f6..e2ee88ac86b 100644
--- a/clang/lib/Sema/ParseAST.cpp
+++ b/clang/lib/Sema/ParseAST.cpp
@@ -14,6 +14,7 @@
#include "clang/Sema/ParseAST.h"
#include "Sema.h"
#include "clang/Sema/SemaConsumer.h"
+#include "clang/Sema/ExternalSemaSource.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ExternalASTSource.h"
#include "clang/AST/Stmt.h"
@@ -50,8 +51,13 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer))
SC->InitializeSema(S);
- if (Ctx.getExternalSource())
- Ctx.getExternalSource()->StartTranslationUnit(Consumer);
+ if (ExternalASTSource *External = Ctx.getExternalSource()) {
+ if (ExternalSemaSource *ExternalSema =
+ dyn_cast<ExternalSemaSource>(External))
+ ExternalSema->InitializeSema(S);
+
+ External->StartTranslationUnit(Consumer);
+ }
Parser::DeclGroupPtrTy ADecl;
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index cd825070054..0b11d9cf68c 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -878,17 +878,6 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind,
// We have a single lookup result.
return LookupResult::CreateLookupResult(Context, *I);
}
-
- /// If the context has an external AST source attached, look at
- /// translation unit scope.
- if (Context.getExternalSource()) {
- DeclContext::lookup_iterator I, E;
- for (llvm::tie(I, E)
- = Context.getTranslationUnitDecl()->lookup(Context, Name);
- I != E; ++I)
- if (isAcceptableLookupResult(*I, NameKind, IDNS))
- return LookupResult::CreateLookupResult(Context, I, E);
- }
} else {
// Perform C++ unqualified name lookup.
std::pair<bool, LookupResult> MaybeResult =
OpenPOWER on IntegriCloud