aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-07-27 20:58:46 +0000
committerDouglas Gregor <dgregor@apple.com>2011-07-27 20:58:46 +0000
commita862320972e63349524dc9aa744dec1b95f54ba1 (patch)
treea106b64315d2b07c6c6e7078ecf6294cd58118d3 /lib
parentd648d373d6c14dccadd3bef7b560f6a7296f949e (diff)
Introduce a new data structure, LazyVector, which is a vector whose
contents are lazily loaded on demand from an external source (e.g., an ExternalASTSource or ExternalSemaSource). The "loaded" entities are kept separate from the "local" entities, so that the two can grow independently. Switch Sema::TentativeDefinitions from a normal vector that is eagerly populated by the ASTReader into one of these LazyVectors, making the ASTReader a bit more like me (i.e., lazy). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136262 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/Sema.cpp8
-rw-r--r--lib/Serialization/ASTReader.cpp17
-rw-r--r--lib/Serialization/ASTWriter.cpp19
3 files changed, 28 insertions, 16 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index c1d8fe03f1..cb240cc031 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -473,8 +473,12 @@ void Sema::ActOnEndOfTranslationUnit() {
// identifier, with the composite type as of the end of the
// translation unit, with an initializer equal to 0.
llvm::SmallSet<VarDecl *, 32> Seen;
- for (unsigned i = 0, e = TentativeDefinitions.size(); i != e; ++i) {
- VarDecl *VD = TentativeDefinitions[i]->getActingDefinition();
+ for (TentativeDefinitionsType::iterator
+ T = TentativeDefinitions.begin(ExternalSource),
+ TEnd = TentativeDefinitions.end();
+ T != TEnd; ++T)
+ {
+ VarDecl *VD = (*T)->getActingDefinition();
// If the tentative definition was completed, getActingDefinition() returns
// null. If we've already seen this variable before, insert()'s second
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index b377be6267..9f8514f187 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -4328,13 +4328,6 @@ void ASTReader::InitializeSema(Sema &S) {
}
PreloadedDecls.clear();
- // If there were any tentative definitions, deserialize them and add
- // them to Sema's list of tentative definitions.
- for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) {
- VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I]));
- SemaObj->TentativeDefinitions.push_back(Var);
- }
-
// If there were any unused file scoped decls, deserialize them and add to
// Sema's list of unused file scoped decls.
for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) {
@@ -4571,6 +4564,16 @@ void ASTReader::ReadKnownNamespaces(
}
}
+void ASTReader::ReadTentativeDefinitions(
+ SmallVectorImpl<VarDecl *> &TentativeDefs) {
+ for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) {
+ VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I]));
+ if (Var)
+ TentativeDefs.push_back(Var);
+ }
+ TentativeDefinitions.clear();
+}
+
void ASTReader::LoadSelector(Selector Sel) {
// It would be complicated to avoid reading the methods anyway. So don't.
ReadMethodPool(Sel);
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 14824a0810..1acc140acd 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -2805,10 +2805,13 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
// TentativeDefinitions order. Generally, this record will be empty for
// headers.
RecordData TentativeDefinitions;
- for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) {
- AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions);
+ for (Sema::TentativeDefinitionsType::iterator
+ T = SemaRef.TentativeDefinitions.begin(0, true),
+ TEnd = SemaRef.TentativeDefinitions.end();
+ T != TEnd; ++T) {
+ AddDeclRef(*T, TentativeDefinitions);
}
-
+
// Build a record containing all of the file scoped decls in this file.
RecordData UnusedFileScopedDecls;
for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i)
@@ -3072,11 +3075,13 @@ void ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls,
// Build a record containing all of the new tentative definitions in this
// file, in TentativeDefinitions order.
RecordData TentativeDefinitions;
- for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) {
- if (SemaRef.TentativeDefinitions[i]->getPCHLevel() == 0)
- AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions);
+ for (Sema::TentativeDefinitionsType::iterator
+ T = SemaRef.TentativeDefinitions.begin(0, true),
+ TEnd = SemaRef.TentativeDefinitions.end();
+ T != TEnd; ++T) {
+ AddDeclRef(*T, TentativeDefinitions);
}
-
+
// Build a record containing all of the file scoped decls in this file.
RecordData UnusedFileScopedDecls;
for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i) {