aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan D. Turner <jonathan.d.turner@gmail.com>2011-07-21 21:15:19 +0000
committerJonathan D. Turner <jonathan.d.turner@gmail.com>2011-07-21 21:15:19 +0000
commit1da901467f72d1733704b068e22089813a1962fd (patch)
treef92a5e8284d5fc7a046cf67b079b389f8dac42bc
parent23d7df5ce30f4a068e13ad6cb81d473365d260db (diff)
Cleaning up more of the ID situation in the AST reader. This patch relaxes and generalizes how CXX base specifiers are identified and loaded by using a ContinuousRangeMap. This also adds a global bit offset (or base) to the PerFileData.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135705 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Serialization/ASTReader.h22
-rw-r--r--lib/Serialization/ASTReader.cpp49
2 files changed, 46 insertions, 25 deletions
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index d7b574a774..24fc070ec1 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -244,6 +244,9 @@ private:
/// \brief The size of this file, in bits.
uint64_t SizeInBits;
+ /// \brief The global bit offset (or base) of this module
+ uint64_t GlobalBitOffset;
+
/// \brief The bitstream reader from which we'll read the AST file.
llvm::BitstreamReader StreamFile;
@@ -613,6 +616,15 @@ private:
/// added to the global preprocessing entitiy ID to produce a local ID.
GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
+ typedef ContinuousRangeMap<serialization::CXXBaseSpecifiersID,
+ std::pair<PerFileData *, int32_t>, 4>
+ GlobalCXXBaseSpecifiersMapType;
+
+ /// \brief Mapping from global CXX base specifier IDs to the module in which the
+ /// CXX base specifier resides along with the offset that should be added to the
+ /// global CXX base specifer ID to produce a local ID.
+ GlobalCXXBaseSpecifiersMapType GlobalCXXBaseSpecifiersMap;
+
/// \name CodeGen-relevant special data
/// \brief Fields containing data that is relevant to CodeGen.
//@{
@@ -793,9 +805,15 @@ private:
/// Number of visible decl contexts read/total.
unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
+ /// Total size of modules, in bits, currently loaded
+ uint64_t TotalModulesSizeInBits;
+
/// \brief Number of Decl/types that are currently deserializing.
unsigned NumCurrentElementsDeserializing;
+ /// Number of CXX base specifiers currently loaded
+ unsigned NumCXXBaseSpecifiersLoaded;
+
/// \brief An IdentifierInfo that has been loaded but whose top-level
/// declarations of the same name have not (yet) been loaded.
struct PendingIdentifierInfo {
@@ -1067,7 +1085,9 @@ public:
}
/// \brief Returns the number of C++ base specifiers found in the chain.
- unsigned getTotalNumCXXBaseSpecifiers() const;
+ unsigned getTotalNumCXXBaseSpecifiers() const {
+ return NumCXXBaseSpecifiersLoaded;
+ }
/// \brief Reads a TemplateArgumentLocInfo appropriate for the
/// given TemplateArgument kind.
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index be2b79d403..c8f5db214c 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -2427,6 +2427,17 @@ ASTReader::ReadASTBlock(PerFileData &F) {
F.LocalNumCXXBaseSpecifiers = Record[0];
F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart;
+
+ GlobalCXXBaseSpecifiersMap.insert(std::make_pair(
+ getTotalNumCXXBaseSpecifiers() + 1,
+ std::make_pair(&F,
+ -getTotalNumCXXBaseSpecifiers())));
+
+ NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers;
+
+ F.GlobalBitOffset = TotalModulesSizeInBits;
+ TotalModulesSizeInBits += F.SizeInBits;
+
break;
}
@@ -3920,14 +3931,6 @@ TypeIdx ASTReader::GetTypeIdx(QualType T) const {
return I->second;
}
-unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const {
- unsigned Result = 0;
- for (unsigned I = 0, N = Chain.size(); I != N; ++I)
- Result += Chain[I]->LocalNumCXXBaseSpecifiers;
-
- return Result;
-}
-
TemplateArgumentLocInfo
ASTReader::GetTemplateArgumentLocInfo(PerFileData &F,
TemplateArgument::ArgKind Kind,
@@ -3984,21 +3987,17 @@ uint64_t
ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) {
if (ID == 0)
return 0;
-
- --ID;
- uint64_t Offset = 0;
- for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
- PerFileData &F = *Chain[N - I - 1];
- if (ID < F.LocalNumCXXBaseSpecifiers)
- return Offset + F.CXXBaseSpecifiersOffsets[ID];
-
- ID -= F.LocalNumCXXBaseSpecifiers;
- Offset += F.SizeInBits;
- }
+ GlobalCXXBaseSpecifiersMapType::iterator I =
+ GlobalCXXBaseSpecifiersMap.find(ID);
+
+ assert (I != GlobalCXXBaseSpecifiersMap.end() &&
+ "Corrupted global CXX base specifiers map");
- assert(false && "CXXBaseSpecifiers not found");
- return 0;
+ return I->second.first->CXXBaseSpecifiersOffsets[ID - 1 +
+ I->second.second] +
+ I->second.first->GlobalBitOffset;
+
}
CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
@@ -5309,8 +5308,9 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context,
TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0),
NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0),
NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0),
- NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0),
- NumCurrentElementsDeserializing(0)
+ NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0),
+ TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0),
+ NumCXXBaseSpecifiersLoaded(0)
{
SourceMgr.setExternalSLocEntrySource(this);
}
@@ -5328,7 +5328,8 @@ ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0),
TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0),
TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0),
- TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0)
+ TotalVisibleDeclContexts(0), TotalModulesSizeInBits(0),
+ NumCurrentElementsDeserializing(0), NumCXXBaseSpecifiersLoaded(0)
{
SourceMgr.setExternalSLocEntrySource(this);
}