[cfe-commits] r135622 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp
Jonathan D. Turner
jonathan.d.turner at gmail.com
Wed Jul 20 14:31:33 PDT 2011
Author: jonturner
Date: Wed Jul 20 16:31:32 2011
New Revision: 135622
URL: http://llvm.org/viewvc/llvm-project?rev=135622&view=rev
Log:
Continuing to improve and generalize how IDs are handled in ASTReader. This patch cleans up and generalizes TypeID loading and uses a similar table-lookup to Doug's previous Decl patch.
Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=135622&r1=135621&r2=135622&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Wed Jul 20 16:31:32 2011
@@ -457,6 +457,15 @@
/// ID = (I + 1) << FastQual::Width has already been loaded
std::vector<QualType> TypesLoaded;
+ typedef ContinuousRangeMap<serialization::TypeID,
+ std::pair<PerFileData *, int32_t>, 4>
+ GlobalTypeMapType;
+
+ /// \brief Mapping from global type IDs to the module in which the
+ /// type resides along with the offset that should be added to the
+ /// global type ID to produce a local ID.
+ GlobalTypeMapType GlobalTypeMap;
+
/// \brief Map that provides the ID numbers of each type within the
/// output stream, plus those deserialized from a chained PCH.
///
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=135622&r1=135621&r2=135622&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Jul 20 16:31:32 2011
@@ -2033,6 +2033,13 @@
}
F.TypeOffsets = (const uint32_t *)BlobStart;
F.LocalNumTypes = Record[0];
+
+ // Introduce the global -> local mapping for types within this
+ // AST file.
+ GlobalTypeMap.insert(std::make_pair(getTotalNumTypes() + 1,
+ std::make_pair(&F,
+ -getTotalNumTypes())));
+ TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes);
break;
case DECL_OFFSET:
@@ -2551,14 +2558,12 @@
}
// Allocate space for loaded slocentries, identifiers, decls and types.
- unsigned TotalNumTypes = 0, TotalNumPreallocatedPreprocessingEntities = 0;
+ unsigned TotalNumPreallocatedPreprocessingEntities = 0;
for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries;
- TotalNumTypes += Chain[I]->LocalNumTypes;
TotalNumPreallocatedPreprocessingEntities +=
Chain[I]->NumPreallocatedPreprocessingEntities;
}
- TypesLoaded.resize(TotalNumTypes);
if (PP) {
PP->getHeaderSearchInfo().SetExternalLookup(this);
if (TotalNumPreallocatedPreprocessingEntities > 0) {
@@ -3157,15 +3162,10 @@
/// \brief Get the correct cursor and offset for loading a type.
ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) {
- PerFileData *F = 0;
- for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
- F = Chain[N - I - 1];
- if (Index < F->LocalNumTypes)
- break;
- Index -= F->LocalNumTypes;
- }
- assert(F && F->LocalNumTypes > Index && "Broken chain");
- return RecordLocation(F, F->TypeOffsets[Index]);
+ GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index+1);
+ assert(I != GlobalTypeMap.end() && "Corrupted global type map");
+ return RecordLocation(I->second.first,
+ I->second.first->TypeOffsets[Index + I->second.second]);
}
/// \brief Read and return the type with the given index..
More information about the cfe-commits
mailing list