[cfe-commits] r135548 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTReaderDecl.cpp
Douglas Gregor
dgregor at apple.com
Tue Jul 19 17:27:43 PDT 2011
Author: dgregor
Date: Tue Jul 19 19:27:43 2011
New Revision: 135548
URL: http://llvm.org/viewvc/llvm-project?rev=135548&view=rev
Log:
Use a ContinuousRangeMap to map from the global declaration ID in the
AST reader down to the AST file + local ID within that file, rather
than lamely walking the PCH chain. There's no actual functionality
change now, but this is cleaner and more general.
Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=135548&r1=135547&r2=135548&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Jul 19 19:27:43 2011
@@ -474,10 +474,19 @@
/// = I + 1 has already been loaded.
std::vector<Decl *> DeclsLoaded;
+ typedef ContinuousRangeMap<serialization::DeclID,
+ std::pair<PerFileData *, int32_t>, 4>
+ GlobalDeclMapType;
+ /// \brief Mapping from global declaration IDs to the module in which the
+ /// declaration resides along with the offset that should be added to the
+ /// global declaration ID to produce a local ID.
+ GlobalDeclMapType GlobalDeclMap;
+
typedef std::pair<PerFileData *, uint64_t> FileOffset;
typedef llvm::SmallVector<FileOffset, 2> FileOffsetsTy;
typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
DeclUpdateOffsetsMap;
+
/// \brief Declarations that have modifications residing in a later file
/// in the chain.
DeclUpdateOffsetsMap DeclUpdateOffsets;
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=135548&r1=135547&r2=135548&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Jul 19 19:27:43 2011
@@ -2046,6 +2046,13 @@
}
F.DeclOffsets = (const uint32_t *)BlobStart;
F.LocalNumDecls = Record[0];
+
+ // Introduce the global -> local mapping for declarations within this
+ GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1,
+ std::make_pair(&F,
+ -getTotalNumDecls())));
+ DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls);
+
break;
case TU_UPDATE_LEXICAL: {
@@ -2522,14 +2529,13 @@
}
// Allocate space for loaded slocentries, identifiers, decls and types.
- unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0,
+ unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0,
TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0,
TotalNumSelectors = 0;
for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries;
TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers;
TotalNumTypes += Chain[I]->LocalNumTypes;
- TotalNumDecls += Chain[I]->LocalNumDecls;
TotalNumPreallocatedPreprocessingEntities +=
Chain[I]->NumPreallocatedPreprocessingEntities;
TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions;
@@ -2537,7 +2543,6 @@
}
IdentifiersLoaded.resize(TotalNumIdentifiers);
TypesLoaded.resize(TotalNumTypes);
- DeclsLoaded.resize(TotalNumDecls);
MacroDefinitionsLoaded.resize(TotalNumMacroDefs);
if (PP) {
if (TotalNumIdentifiers > 0)
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=135548&r1=135547&r2=135548&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Tue Jul 19 19:27:43 2011
@@ -1408,7 +1408,7 @@
return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
}
-/// \brief Get the correct cursor and offset for loading a type.
+/// \brief Get the correct cursor and offset for loading a declaration.
ASTReader::RecordLocation
ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
// See if there's an override.
@@ -1416,15 +1416,10 @@
if (It != ReplacedDecls.end())
return RecordLocation(It->second.first, It->second.second);
- PerFileData *F = 0;
- for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
- F = Chain[N - I - 1];
- if (Index < F->LocalNumDecls)
- break;
- Index -= F->LocalNumDecls;
- }
- assert(F && F->LocalNumDecls > Index && "Broken chain");
- return RecordLocation(F, F->DeclOffsets[Index]);
+ GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
+ assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
+ return RecordLocation(I->second.first,
+ I->second.first->DeclOffsets[Index + I->second.second]);
}
void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
More information about the cfe-commits
mailing list