[cfe-commits] r108528 - in /cfe/trunk: include/clang/Frontend/PCHDeserializationListener.h include/clang/Frontend/PCHWriter.h lib/Frontend/GeneratePCH.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Fri Jul 16 09:36:56 PDT 2010
Author: cornedbee
Date: Fri Jul 16 11:36:56 2010
New Revision: 108528
URL: http://llvm.org/viewvc/llvm-project?rev=108528&view=rev
Log:
Add a little more data to chained PCHs. WIP
Modified:
cfe/trunk/include/clang/Frontend/PCHDeserializationListener.h
cfe/trunk/include/clang/Frontend/PCHWriter.h
cfe/trunk/lib/Frontend/GeneratePCH.cpp
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
Modified: cfe/trunk/include/clang/Frontend/PCHDeserializationListener.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHDeserializationListener.h?rev=108528&r1=108527&r2=108528&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHDeserializationListener.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHDeserializationListener.h Fri Jul 16 11:36:56 2010
@@ -27,7 +27,10 @@
~PCHDeserializationListener() {}
public:
+ /// \brief A type was deserialized from the PCH. The ID here has the qualifier
+ /// bits already removed, and T is guaranteed to be locally unqualified
virtual void TypeRead(pch::TypeID ID, QualType T) = 0;
+ /// \brief A decl was deserialized from the PCH.
virtual void DeclRead(pch::DeclID ID, const Decl *D) = 0;
};
Modified: cfe/trunk/include/clang/Frontend/PCHWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHWriter.h?rev=108528&r1=108527&r2=108528&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHWriter.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHWriter.h Fri Jul 16 11:36:56 2010
@@ -106,12 +106,15 @@
void *Stored;
bool IsType;
};
-
+
/// \brief The declarations and types to emit.
std::queue<DeclOrType> DeclTypesToEmit;
-
+
+ /// \brief The first ID number we can use for our own declarations.
+ pch::DeclID FirstDeclID;
+
/// \brief Map that provides the ID numbers of each declaration within
- /// the output stream.
+ /// the output stream, as well as those deserialized from a chained PCH.
///
/// The ID numbers of declarations are consecutive (in order of
/// discovery) and start at 2. 1 is reserved for the translation
@@ -122,8 +125,11 @@
/// the declaration's ID.
std::vector<uint32_t> DeclOffsets;
+ /// \brief The first ID number we can use for our own types.
+ pch::TypeID FirstTypeID;
+
/// \brief Map that provides the ID numbers of each type within the
- /// output stream.
+ /// output stream, plus those deserialized from a chained PCH.
///
/// The ID numbers of types are consecutive (in order of discovery)
/// and start at 1. 0 is reserved for NULL. When types are actually
@@ -234,7 +240,7 @@
void WriteType(QualType T);
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
-
+ void WriteTypeDeclOffsets();
void WriteMethodPool(Sema &SemaRef);
void WriteIdentifierTable(Preprocessor &PP);
void WriteAttributeRecord(const Attr *Attr);
Modified: cfe/trunk/lib/Frontend/GeneratePCH.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/GeneratePCH.cpp?rev=108528&r1=108527&r2=108528&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/GeneratePCH.cpp (original)
+++ cfe/trunk/lib/Frontend/GeneratePCH.cpp Fri Jul 16 11:36:56 2010
@@ -54,7 +54,10 @@
// Install a stat() listener to keep track of all of the stat()
// calls.
StatCalls = new MemorizeStatCalls;
- PP.getFileManager().addStatCache(StatCalls, /*AtBeginning=*/true);
+ // If we have a chain, we want new stat calls only, so install the memorizer
+ // *after* the already installed PCHReader's stat cache.
+ PP.getFileManager().addStatCache(StatCalls,
+ /*AtBeginning=*/!Chain);
}
void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=108528&r1=108527&r2=108528&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Jul 16 11:36:56 2010
@@ -2632,7 +2632,8 @@
TypesLoaded[Index] = ReadTypeRecord(TypeOffsets[Index]);
TypesLoaded[Index]->setFromPCH();
if (DeserializationListener)
- DeserializationListener->TypeRead(ID, TypesLoaded[Index]);
+ DeserializationListener->TypeRead(ID >> Qualifiers::FastWidth,
+ TypesLoaded[Index]);
}
return TypesLoaded[Index].withFastQualifiers(FastQuals);
@@ -2682,7 +2683,7 @@
if (!DeclsLoaded[0]) {
ReadDeclRecord(DeclOffsets[0], 0);
if (DeserializationListener)
- DeserializationListener->DeclRead(0, DeclsLoaded[0]);
+ DeserializationListener->DeclRead(1, DeclsLoaded[0]);
}
return cast<TranslationUnitDecl>(DeclsLoaded[0]);
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=108528&r1=108527&r2=108528&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Jul 16 11:36:56 2010
@@ -1501,6 +1501,37 @@
return Offset;
}
+void PCHWriter::WriteTypeDeclOffsets() {
+ using namespace llvm;
+ RecordData Record;
+
+ // Write the type offsets array
+ BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
+ Abbrev->Add(BitCodeAbbrevOp(pch::TYPE_OFFSET));
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block
+ unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
+ Record.clear();
+ Record.push_back(pch::TYPE_OFFSET);
+ Record.push_back(TypeOffsets.size());
+ Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record,
+ (const char *)&TypeOffsets.front(),
+ TypeOffsets.size() * sizeof(TypeOffsets[0]));
+
+ // Write the declaration offsets array
+ Abbrev = new BitCodeAbbrev();
+ Abbrev->Add(BitCodeAbbrevOp(pch::DECL_OFFSET));
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block
+ unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
+ Record.clear();
+ Record.push_back(pch::DECL_OFFSET);
+ Record.push_back(DeclOffsets.size());
+ Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record,
+ (const char *)&DeclOffsets.front(),
+ DeclOffsets.size() * sizeof(DeclOffsets[0]));
+}
+
//===----------------------------------------------------------------------===//
// Global Method Pool and Selector Serialization
//===----------------------------------------------------------------------===//
@@ -2074,11 +2105,16 @@
}
PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream, PCHReader *Chain)
- : Stream(Stream), Chain(Chain), NextTypeID(pch::NUM_PREDEF_TYPE_IDS),
+ : Stream(Stream), Chain(Chain), FirstDeclID(1),
+ FirstTypeID(pch::NUM_PREDEF_TYPE_IDS),
CollectedStmts(&StmtsToEmit), NumStatements(0), NumMacros(0),
NumLexicalDeclContexts(0), NumVisibleDeclContexts(0) {
- if (Chain)
+ if (Chain) {
Chain->setDeserializationListener(this);
+ FirstDeclID += Chain->getTotalNumDecls();
+ FirstTypeID += Chain->getTotalNumTypes();
+ }
+ NextTypeID = FirstTypeID;
}
void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
@@ -2211,31 +2247,7 @@
WriteMethodPool(SemaRef);
WriteIdentifierTable(PP);
- // Write the type offsets array
- BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
- Abbrev->Add(BitCodeAbbrevOp(pch::TYPE_OFFSET));
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block
- unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
- Record.clear();
- Record.push_back(pch::TYPE_OFFSET);
- Record.push_back(TypeOffsets.size());
- Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record,
- (const char *)&TypeOffsets.front(),
- TypeOffsets.size() * sizeof(TypeOffsets[0]));
-
- // Write the declaration offsets array
- Abbrev = new BitCodeAbbrev();
- Abbrev->Add(BitCodeAbbrevOp(pch::DECL_OFFSET));
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block
- unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
- Record.clear();
- Record.push_back(pch::DECL_OFFSET);
- Record.push_back(DeclOffsets.size());
- Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record,
- (const char *)&DeclOffsets.front(),
- DeclOffsets.size() * sizeof(DeclOffsets[0]));
+ WriteTypeDeclOffsets();
// Write the record containing external, unnamed definitions.
if (!ExternalDefinitions.empty())
@@ -2283,12 +2295,15 @@
ASTContext &Context = SemaRef.Context;
Preprocessor &PP = SemaRef.PP;
(void)PP;
-
+
RecordData Record;
Stream.EnterSubblock(pch::PCH_BLOCK_ID, 5);
WriteMetadata(Context, isysroot);
- // FIXME: StatCache
- // FIXME: Source manager block
+ if (StatCalls && !isysroot)
+ WriteStatCache(*StatCalls);
+ // FIXME: Source manager block should only write new stuff, which could be
+ // done by tracking the largest ID in the chain
+ WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot);
// The special types are in the chained PCH.
@@ -2302,7 +2317,6 @@
for (DeclContext::decl_iterator I = TU->decls_begin(), E = TU->decls_end();
I != E; ++I) {
if ((*I)->getPCHLevel() == 0) {
- (*I)->dump();
DeclTypesToEmit.push(*I);
}
}
@@ -2322,8 +2336,7 @@
// FIXME: Preprocessor
// FIXME: Method pool
// FIXME: Identifier table
- // FIXME: Type offsets
- // FIXME: Declaration offsets
+ WriteTypeDeclOffsets();
// FIXME: External unnamed definitions
// FIXME: Tentative definitions
// FIXME: Unused static functions
@@ -2741,8 +2754,10 @@
}
void PCHWriter::TypeRead(pch::TypeID ID, QualType T) {
+ TypeIDs[T] = ID;
}
void PCHWriter::DeclRead(pch::DeclID ID, const Decl *D) {
+ DeclIDs[D] = ID;
}
More information about the cfe-commits
mailing list