summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/PCHWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-26 03:49:13 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-26 03:49:13 +0000
commit1970d887abb9b154658e64f37bb514135a0ace6d (patch)
tree4d466bc0755848a15205256d5ec2cf25d1e5b305 /clang/lib/Frontend/PCHWriter.cpp
parent32887f0274cbb332f344a19b91d12b58eeaca637 (diff)
downloadbcm5719-llvm-1970d887abb9b154658e64f37bb514135a0ace6d.tar.gz
bcm5719-llvm-1970d887abb9b154658e64f37bb514135a0ace6d.zip
When writing a PCH file, write multiple type and declaration blocks as
necessary and iterate until all types and declarations have been written. This reduces the Cocoa.h PCH file size by about 4% (since we don't write types we don't need), and fixes problems where writing a declaration generates a new type. This doesn't seem to have any impact on performance either way. llvm-svn: 70109
Diffstat (limited to 'clang/lib/Frontend/PCHWriter.cpp')
-rw-r--r--clang/lib/Frontend/PCHWriter.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/clang/lib/Frontend/PCHWriter.cpp b/clang/lib/Frontend/PCHWriter.cpp
index 9056f58c6ff..a43e59961a5 100644
--- a/clang/lib/Frontend/PCHWriter.cpp
+++ b/clang/lib/Frontend/PCHWriter.cpp
@@ -1674,15 +1674,12 @@ void PCHWriter::WriteTypesBlock(ASTContext &Context) {
// Enter the types block.
Stream.EnterSubblock(pch::TYPES_BLOCK_ID, 2);
- // Emit all of the types in the ASTContext
- for (std::vector<Type*>::const_iterator T = Context.getTypes().begin(),
- TEnd = Context.getTypes().end();
- T != TEnd; ++T) {
- // Builtin types are never serialized.
- if (isa<BuiltinType>(*T))
- continue;
-
- WriteType(*T);
+ // Emit all of the types that need to be emitted (so far).
+ while (!TypesToEmit.empty()) {
+ const Type *T = TypesToEmit.front();
+ TypesToEmit.pop();
+ assert(!isa<BuiltinType>(T) && "Built-in types are not serialized");
+ WriteType(T);
}
// Exit the types block
@@ -2409,8 +2406,16 @@ void PCHWriter::WritePCH(Sema &SemaRef) {
WriteLanguageOptions(Context.getLangOptions());
WriteSourceManagerBlock(Context.getSourceManager(), PP);
WritePreprocessor(PP);
- WriteTypesBlock(Context);
- WriteDeclsBlock(Context);
+
+ // Keep writing types and declarations until all types and
+ // declarations have been written.
+ do {
+ if (!DeclsToEmit.empty())
+ WriteDeclsBlock(Context);
+ if (!TypesToEmit.empty())
+ WriteTypesBlock(Context);
+ } while (!(DeclsToEmit.empty() && TypesToEmit.empty()));
+
WriteMethodPool(SemaRef);
WriteIdentifierTable(PP);
@@ -2559,8 +2564,12 @@ void PCHWriter::AddTypeRef(QualType T, RecordData &Record) {
}
pch::TypeID &ID = TypeIDs[T.getTypePtr()];
- if (ID == 0) // we haven't seen this type before
+ if (ID == 0) {
+ // We haven't seen this type before. Assign it a new ID and put it
+ // into the queu of types to emit.
ID = NextTypeID++;
+ TypesToEmit.push(T.getTypePtr());
+ }
// Encode the type qualifiers in the type reference.
Record.push_back((ID << 3) | T.getCVRQualifiers());
OpenPOWER on IntegriCloud