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
This commit is contained in:
Jonathan D. Turner 2011-07-21 21:15:19 +00:00
Родитель 23d7df5ce3
Коммит 1da901467f
2 изменённых файлов: 46 добавлений и 25 удалений

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

@ -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.

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

@ -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);
}