Change source manager serialization to be less tied to the PCH model.

llvm-svn: 114575
This commit is contained in:
Sebastian Redl 2010-09-22 20:19:08 +00:00
parent ba28207dcd
commit c1d035f6a3
3 changed files with 29 additions and 20 deletions

View File

@ -228,8 +228,8 @@ private:
/// AST file. /// AST file.
const uint32_t *SLocOffsets; const uint32_t *SLocOffsets;
/// \brief The next SourceLocation offset after reading this file. /// \brief The entire size of this module's source location offset range.
unsigned NextOffset; unsigned LocalSLocSize;
// === Identifiers === // === Identifiers ===
@ -255,6 +255,10 @@ private:
// === Macros === // === Macros ===
/// \brief The cursor to the start of the preprocessor block, which stores
/// all of the macro definitions.
llvm::BitstreamCursor MacroCursor;
/// \brief The number of macro definitions in this file. /// \brief The number of macro definitions in this file.
unsigned LocalNumMacroDefinitions; unsigned LocalNumMacroDefinitions;
@ -264,10 +268,6 @@ private:
// === Selectors === // === Selectors ===
/// \brief The cursor to the start of the preprocessor block, which stores
/// all of the macro definitions.
llvm::BitstreamCursor MacroCursor;
/// \brief The number of selectors new to this file. /// \brief The number of selectors new to this file.
/// ///
/// This is the number of entries in SelectorOffsets. /// This is the number of entries in SelectorOffsets.
@ -568,6 +568,9 @@ private:
/// \brief The number of source location entries in the chain. /// \brief The number of source location entries in the chain.
unsigned TotalNumSLocEntries; unsigned TotalNumSLocEntries;
/// \brief The next offset for a SLocEntry after everything in this reader.
unsigned NextSLocOffset;
/// \brief The number of statements (and expressions) de-serialized /// \brief The number of statements (and expressions) de-serialized
/// from the chain. /// from the chain.
unsigned NumStatementsRead; unsigned NumStatementsRead;
@ -788,6 +791,11 @@ public:
return TotalNumSLocEntries; return TotalNumSLocEntries;
} }
/// \brief Returns the next SLocEntry offset after the chain.
unsigned getNextSLocOffset() const {
return NextSLocOffset;
}
/// \brief Returns the number of identifiers found in the chain. /// \brief Returns the number of identifiers found in the chain.
unsigned getTotalNumIdentifiers() const { unsigned getTotalNumIdentifiers() const {
return static_cast<unsigned>(IdentifiersLoaded.size()); return static_cast<unsigned>(IdentifiersLoaded.size());

View File

@ -1879,7 +1879,7 @@ ASTReader::ReadASTBlock(PerFileData &F) {
case SOURCE_LOCATION_OFFSETS: case SOURCE_LOCATION_OFFSETS:
F.SLocOffsets = (const uint32_t *)BlobStart; F.SLocOffsets = (const uint32_t *)BlobStart;
F.LocalNumSLocEntries = Record[0]; F.LocalNumSLocEntries = Record[0];
F.NextOffset = Record[1]; F.LocalSLocSize = Record[1];
break; break;
case SOURCE_LOCATION_PRELOADS: case SOURCE_LOCATION_PRELOADS:
@ -2000,6 +2000,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName) {
TotalNumSelectors = 0; TotalNumSelectors = 0;
for (unsigned I = 0, N = Chain.size(); I != N; ++I) { for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries;
NextSLocOffset += Chain[I]->LocalSLocSize;
TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers;
TotalNumTypes += Chain[I]->LocalNumTypes; TotalNumTypes += Chain[I]->LocalNumTypes;
TotalNumDecls += Chain[I]->LocalNumDecls; TotalNumDecls += Chain[I]->LocalNumDecls;
@ -2008,8 +2009,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName) {
TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions;
TotalNumSelectors += Chain[I]->LocalNumSelectors; TotalNumSelectors += Chain[I]->LocalNumSelectors;
} }
SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset);
Chain.front()->NextOffset);
IdentifiersLoaded.resize(TotalNumIdentifiers); IdentifiersLoaded.resize(TotalNumIdentifiers);
TypesLoaded.resize(TotalNumTypes); TypesLoaded.resize(TotalNumTypes);
DeclsLoaded.resize(TotalNumDecls); DeclsLoaded.resize(TotalNumDecls);
@ -4089,9 +4089,9 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context,
Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context),
Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation),
NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0),
TotalNumSLocEntries(0), NumStatementsRead(0), TotalNumStatements(0), TotalNumSLocEntries(0), NextSLocOffset(0), NumStatementsRead(0),
NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0),
NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0),
TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0),
TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0),
TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) {
@ -4105,12 +4105,12 @@ ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0),
isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0), isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0),
NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0), NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0),
NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0),
TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0),
NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0),
NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0),
NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0),
NumCurrentElementsDeserializing(0) { TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) {
RelocatablePCH = false; RelocatablePCH = false;
} }
@ -4140,7 +4140,7 @@ ASTReader::~ASTReader() {
} }
ASTReader::PerFileData::PerFileData() ASTReader::PerFileData::PerFileData()
: SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), : SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0),
LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0),
IdentifierLookupTable(0), LocalNumMacroDefinitions(0), IdentifierLookupTable(0), LocalNumMacroDefinitions(0),
MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0), MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0),

View File

@ -1228,7 +1228,8 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
Record.clear(); Record.clear();
Record.push_back(SOURCE_LOCATION_OFFSETS); Record.push_back(SOURCE_LOCATION_OFFSETS);
Record.push_back(SLocEntryOffsets.size()); Record.push_back(SLocEntryOffsets.size());
Record.push_back(SourceMgr.getNextOffset()); unsigned BaseOffset = Chain ? Chain->getNextSLocOffset() : 0;
Record.push_back(SourceMgr.getNextOffset() - BaseOffset);
Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
(const char *)data(SLocEntryOffsets), (const char *)data(SLocEntryOffsets),
SLocEntryOffsets.size()*sizeof(SLocEntryOffsets[0])); SLocEntryOffsets.size()*sizeof(SLocEntryOffsets[0]));