diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-26 03:49:13 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-26 03:49:13 +0000 |
commit | 366809a4e9340b3458b471e2294a75a9f09ea304 (patch) | |
tree | fa1043cff0bb3ee648a50aa86bff0e5f69ef45c4 | |
parent | 609e72f55a04cbef59a7d493d5121c066ca3dff5 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70109 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Frontend/PCHWriter.h | 4 | ||||
-rw-r--r-- | lib/Frontend/PCHReader.cpp | 1 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 33 |
3 files changed, 26 insertions, 12 deletions
diff --git a/include/clang/Frontend/PCHWriter.h b/include/clang/Frontend/PCHWriter.h index 034c1afb28..a26d944811 100644 --- a/include/clang/Frontend/PCHWriter.h +++ b/include/clang/Frontend/PCHWriter.h @@ -86,6 +86,10 @@ private: /// \brief The type ID that will be assigned to the next new type. pch::TypeID NextTypeID; + /// \brief Queue containing the types that we still need to + /// emit. + std::queue<const Type *> TypesToEmit; + /// \brief Map that provides the ID numbers of each identifier in /// the output stream. /// diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 9970eb2b09..0407ed8996 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -2563,6 +2563,7 @@ QualType PCHReader::GetType(pch::TypeID ID) { } Index -= pch::NUM_PREDEF_TYPE_IDS; + assert(Index < TypesLoaded.size() && "Type index out-of-range"); if (!TypesLoaded[Index]) TypesLoaded[Index] = ReadTypeRecord(TypeOffsets[Index]).getTypePtr(); diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 9056f58c6f..a43e59961a 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/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()); |