Use a ContinuousRangeMap to map from the global identifier ID in the

AST reader down to the AST file + local ID, rather than walking the
PCH chain. No functionality change; this is generalization and cleanup.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135551 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2011-07-20 00:59:32 +00:00
Родитель 07e5f1a704
Коммит 67268d0238
2 изменённых файлов: 27 добавлений и 19 удалений

Просмотреть файл

@ -477,6 +477,7 @@ private:
typedef ContinuousRangeMap<serialization::DeclID, typedef ContinuousRangeMap<serialization::DeclID,
std::pair<PerFileData *, int32_t>, 4> std::pair<PerFileData *, int32_t>, 4>
GlobalDeclMapType; GlobalDeclMapType;
/// \brief Mapping from global declaration IDs to the module in which the /// \brief Mapping from global declaration IDs to the module in which the
/// declaration resides along with the offset that should be added to the /// declaration resides along with the offset that should be added to the
/// global declaration ID to produce a local ID. /// global declaration ID to produce a local ID.
@ -553,6 +554,15 @@ private:
/// been loaded. /// been loaded.
std::vector<IdentifierInfo *> IdentifiersLoaded; std::vector<IdentifierInfo *> IdentifiersLoaded;
typedef ContinuousRangeMap<serialization::IdentID,
std::pair<PerFileData *, int32_t>, 4>
GlobalIdentifierMapType;
/// \brief Mapping from global identifer IDs to the module in which the
/// identifier resides along with the offset that should be added to the
/// global identifier ID to produce a local ID.
GlobalIdentifierMapType GlobalIdentifierMap;
/// \brief A vector containing selectors that have already been loaded. /// \brief A vector containing selectors that have already been loaded.
/// ///
/// This vector is indexed by the Selector ID (-1). NULL selector /// This vector is indexed by the Selector ID (-1). NULL selector

Просмотреть файл

@ -2048,11 +2048,11 @@ ASTReader::ReadASTBlock(PerFileData &F) {
F.LocalNumDecls = Record[0]; F.LocalNumDecls = Record[0];
// Introduce the global -> local mapping for declarations within this // Introduce the global -> local mapping for declarations within this
// AST file.
GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1, GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1,
std::make_pair(&F, std::make_pair(&F,
-getTotalNumDecls()))); -getTotalNumDecls())));
DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls);
break; break;
case TU_UPDATE_LEXICAL: { case TU_UPDATE_LEXICAL: {
@ -2119,6 +2119,14 @@ ASTReader::ReadASTBlock(PerFileData &F) {
} }
F.IdentifierOffsets = (const uint32_t *)BlobStart; F.IdentifierOffsets = (const uint32_t *)BlobStart;
F.LocalNumIdentifiers = Record[0]; F.LocalNumIdentifiers = Record[0];
// Introduce the global -> local mapping for identifiers within this AST
// file
GlobalIdentifierMap.insert(
std::make_pair(getTotalNumIdentifiers() + 1,
std::make_pair(&F,
-getTotalNumIdentifiers())));
IdentifiersLoaded.resize(IdentifiersLoaded.size() +F.LocalNumIdentifiers);
break; break;
case EXTERNAL_DEFINITIONS: case EXTERNAL_DEFINITIONS:
@ -2529,24 +2537,21 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
} }
// Allocate space for loaded slocentries, identifiers, decls and types. // Allocate space for loaded slocentries, identifiers, decls and types.
unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, unsigned TotalNumTypes = 0,
TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0,
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;
TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers;
TotalNumTypes += Chain[I]->LocalNumTypes; TotalNumTypes += Chain[I]->LocalNumTypes;
TotalNumPreallocatedPreprocessingEntities += TotalNumPreallocatedPreprocessingEntities +=
Chain[I]->NumPreallocatedPreprocessingEntities; Chain[I]->NumPreallocatedPreprocessingEntities;
TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions;
TotalNumSelectors += Chain[I]->LocalNumSelectors; TotalNumSelectors += Chain[I]->LocalNumSelectors;
} }
IdentifiersLoaded.resize(TotalNumIdentifiers);
TypesLoaded.resize(TotalNumTypes); TypesLoaded.resize(TotalNumTypes);
MacroDefinitionsLoaded.resize(TotalNumMacroDefs); MacroDefinitionsLoaded.resize(TotalNumMacroDefs);
if (PP) { if (PP) {
if (TotalNumIdentifiers > 0) PP->getHeaderSearchInfo().SetExternalLookup(this);
PP->getHeaderSearchInfo().SetExternalLookup(this);
if (TotalNumPreallocatedPreprocessingEntities > 0) { if (TotalNumPreallocatedPreprocessingEntities > 0) {
if (!PP->getPreprocessingRecord()) if (!PP->getPreprocessingRecord())
PP->createPreprocessingRecord(true); PP->createPreprocessingRecord(true);
@ -4602,18 +4607,11 @@ IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) {
assert(PP && "Forgot to set Preprocessor ?"); assert(PP && "Forgot to set Preprocessor ?");
ID -= 1; ID -= 1;
if (!IdentifiersLoaded[ID]) { if (!IdentifiersLoaded[ID]) {
unsigned Index = ID; GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1);
const char *Str = 0; assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map");
for (unsigned I = 0, N = Chain.size(); I != N; ++I) { unsigned Index = ID + I->second.second;
PerFileData *F = Chain[N - I - 1]; const char *Str = I->second.first->IdentifierTableData
if (Index < F->LocalNumIdentifiers) { + I->second.first->IdentifierOffsets[Index];
uint32_t Offset = F->IdentifierOffsets[Index];
Str = F->IdentifierTableData + Offset;
break;
}
Index -= F->LocalNumIdentifiers;
}
assert(Str && "Broken Chain");
// All of the strings in the AST file are preceded by a 16-bit length. // All of the strings in the AST file are preceded by a 16-bit length.
// Extract that 16-bit length to avoid having to execute strlen(). // Extract that 16-bit length to avoid having to execute strlen().