From: Douglas Gregor Date: Fri, 29 Jul 2011 00:56:45 +0000 (+0000) Subject: In the ASTReader, replace the continuous range maps whose value types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9827a8049a793f23c62ade8f24f0c66c2dbf6741;p=clang In the ASTReader, replace the continuous range maps whose value types were (Module*, Offset) with equivalent maps whose value type is just a Module*. The offsets have moved into corresponding "Base" fields within the Module itself, where they will also be helpful for local->global translation (eventually). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136441 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index a42d97eba6..1d6c536f28 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -252,6 +252,9 @@ public: /// stored. const uint32_t *IdentifierOffsets; + /// \brief Base identifier ID for identifiers local to this module. + serialization::IdentID BaseIdentifierID; + /// \brief Actual data for the on-disk hash table of identifiers. /// /// This pointer points into a memory buffer, where the on-disk hash @@ -280,6 +283,10 @@ public: /// \brief The offset of the start of the preprocessor detail cursor. uint64_t PreprocessorDetailStartOffset; + /// \brief Base preprocessed entity ID for preprocessed entities local to + /// this module. + serialization::PreprocessedEntityID BasePreprocessedEntityID; + /// \brief The number of macro definitions in this file. unsigned LocalNumMacroDefinitions; @@ -287,6 +294,10 @@ public: /// record in the AST file. const uint32_t *MacroDefinitionOffsets; + /// \brief Base macro definition ID for macro definitions local to this + /// module. + serialization::MacroID BaseMacroDefinitionID; + // === Header search information === /// \brief The number of local HeaderFileInfo structures. @@ -318,6 +329,9 @@ public: /// where each selector resides. const uint32_t *SelectorOffsets; + /// \brief Base selector ID for selectors local to this module. + serialization::SelectorID BaseSelectorID; + /// \brief A pointer to the character data that comprises the selector table /// /// The SelectorOffsets table refers into this memory. @@ -343,14 +357,20 @@ public: /// \brief Offset of each declaration within the bitstream, indexed /// by the declaration ID (-1). const uint32_t *DeclOffsets; - + + /// \brief Base declaration ID for declarations local to this module. + serialization::DeclID BaseDeclID; + /// \brief The number of C++ base specifier sets in this AST file. unsigned LocalNumCXXBaseSpecifiers; /// \brief Offset of each C++ base specifier set within the bitstream, /// indexed by the C++ base specifier set ID (-1). const uint32_t *CXXBaseSpecifiersOffsets; - + + /// \brief Base base specifier ID for base specifiers local to this module. + serialization::CXXBaseSpecifiersID BaseCXXBaseSpecifiersID; + // === Types === /// \brief The number of types in this AST file. @@ -565,13 +585,11 @@ private: /// = I + 1 has already been loaded. std::vector DeclsLoaded; - typedef ContinuousRangeMap, 4> + typedef ContinuousRangeMap 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. + /// declaration resides. GlobalDeclMapType GlobalDeclMap; typedef std::pair FileOffset; @@ -646,8 +664,7 @@ private: /// been loaded. std::vector IdentifiersLoaded; - typedef ContinuousRangeMap, 4> + typedef ContinuousRangeMap GlobalIdentifierMapType; /// \brief Mapping from global identifer IDs to the module in which the @@ -662,8 +679,7 @@ private: /// been loaded. SmallVector SelectorsLoaded; - typedef ContinuousRangeMap, 4> + typedef ContinuousRangeMap GlobalSelectorMapType; /// \brief Mapping from global selector IDs to the module in which the @@ -674,8 +690,7 @@ private: /// \brief The macro definitions we have already loaded. SmallVector MacroDefinitionsLoaded; - typedef ContinuousRangeMap, 4> + typedef ContinuousRangeMap GlobalMacroDefinitionMapType; /// \brief Mapping from global macro definition IDs to the module in which the @@ -688,7 +703,7 @@ private: /// record resides. llvm::DenseMap UnreadMacroRecordOffsets; - typedef ContinuousRangeMap, 4> + typedef ContinuousRangeMap GlobalPreprocessedEntityMapType; /// \brief Mapping from global preprocessing entity IDs to the module in @@ -696,8 +711,7 @@ private: /// added to the global preprocessing entitiy ID to produce a local ID. GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap; - typedef ContinuousRangeMap, 4> + typedef ContinuousRangeMap GlobalCXXBaseSpecifiersMapType; /// \brief Mapping from global CXX base specifier IDs to the module in which diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 77286b7898..ae90fb1d2b 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1851,11 +1851,11 @@ MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID); assert(I != GlobalMacroDefinitionMap.end() && "Corrupted global macro definition map"); - Module &F = *I->second.first; - unsigned Index = ID - 1 + I->second.second; - SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); - F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); - LoadPreprocessedEntity(F); + Module &M = *I->second; + unsigned Index = ID - 1 - M.BaseMacroDefinitionID; + SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); + M.PreprocessorDetailCursor.JumpToBit(M.MacroDefinitionOffsets[Index]); + LoadPreprocessedEntity(M); } return MacroDefinitionsLoaded[ID - 1]; @@ -2069,12 +2069,11 @@ ASTReader::ReadASTBlock(Module &F) { } F.DeclOffsets = (const uint32_t *)BlobStart; F.LocalNumDecls = Record[0]; + F.BaseDeclID = getTotalNumDecls(); // Introduce the global -> local mapping for declarations within this // AST file. - GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1, - std::make_pair(&F, - -getTotalNumDecls()))); + GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1, &F)); DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); break; @@ -2145,13 +2144,12 @@ ASTReader::ReadASTBlock(Module &F) { } F.IdentifierOffsets = (const uint32_t *)BlobStart; F.LocalNumIdentifiers = Record[0]; + F.BaseIdentifierID = getTotalNumIdentifiers(); // Introduce the global -> local mapping for identifiers within this AST // file - GlobalIdentifierMap.insert( - std::make_pair(getTotalNumIdentifiers() + 1, - std::make_pair(&F, - -getTotalNumIdentifiers()))); + GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, + &F)); IdentifiersLoaded.resize(IdentifiersLoaded.size() +F.LocalNumIdentifiers); break; @@ -2212,13 +2210,11 @@ ASTReader::ReadASTBlock(Module &F) { case SELECTOR_OFFSETS: F.SelectorOffsets = (const uint32_t *)BlobStart; F.LocalNumSelectors = Record[0]; + F.BaseSelectorID = getTotalNumSelectors(); // Introduce the global -> local mapping for identifiers within this AST // file - GlobalSelectorMap.insert( - std::make_pair(getTotalNumSelectors() + 1, - std::make_pair(&F, - -getTotalNumSelectors()))); + GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors() + 1, &F)); SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); break; @@ -2428,16 +2424,14 @@ ASTReader::ReadASTBlock(Module &F) { StartingID = getTotalNumPreprocessedEntities(); } - GlobalPreprocessedEntityMap.insert( - std::make_pair(StartingID, - std::make_pair(&F, -(int)StartingID))); + F.BaseMacroDefinitionID = getTotalNumMacroDefinitions(); + F.BasePreprocessedEntityID = StartingID; // Introduce the global -> local mapping for macro definitions within // this AST file. + GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); GlobalMacroDefinitionMap.insert( - std::make_pair(getTotalNumMacroDefinitions() + 1, - std::make_pair(&F, - -getTotalNumMacroDefinitions()))); + std::make_pair(getTotalNumMacroDefinitions() + 1, &F)); MacroDefinitionsLoaded.resize( MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions); break; @@ -2473,11 +2467,9 @@ ASTReader::ReadASTBlock(Module &F) { F.LocalNumCXXBaseSpecifiers = Record[0]; F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; - - GlobalCXXBaseSpecifiersMap.insert(std::make_pair( - getTotalNumCXXBaseSpecifiers() + 1, - std::make_pair(&F, - -getTotalNumCXXBaseSpecifiers()))); + F.BaseCXXBaseSpecifiersID = getTotalNumCXXBaseSpecifiers(); + GlobalCXXBaseSpecifiersMap.insert( + std::make_pair(getTotalNumCXXBaseSpecifiers() + 1, &F)); NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; break; @@ -4051,10 +4043,9 @@ ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { assert (I != GlobalCXXBaseSpecifiersMap.end() && "Corrupted global CXX base specifiers map"); - return I->second.first->CXXBaseSpecifiersOffsets[ID - 1 + - I->second.second] + - I->second.first->GlobalBitOffset; - + Module *M = I->second; + return M->CXXBaseSpecifiersOffsets[ID - 1 - M->BaseCXXBaseSpecifiersID] + + M->GlobalBitOffset; } CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { @@ -4374,14 +4365,13 @@ void ASTReader::dump() { dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); dumpModuleIDMap("Global type map", GlobalTypeMap); - dumpModuleIDOffsetMap("Global declaration map", GlobalDeclMap); - dumpModuleIDOffsetMap("Global identifier map", GlobalIdentifierMap); - dumpModuleIDOffsetMap("Global selector map", GlobalSelectorMap); - dumpModuleIDOffsetMap("Global macro definition map", - GlobalMacroDefinitionMap); - dumpModuleIDOffsetMap("Global preprocessed entity map", - GlobalPreprocessedEntityMap); - + dumpModuleIDMap("Global declaration map", GlobalDeclMap); + dumpModuleIDMap("Global C++ base specifiers map", GlobalCXXBaseSpecifiersMap); + dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); + dumpModuleIDMap("Global selector map", GlobalSelectorMap); + dumpModuleIDMap("Global macro definition map", GlobalMacroDefinitionMap); + dumpModuleIDMap("Global preprocessed entity map", + GlobalPreprocessedEntityMap); } /// Return the amount of memory used by memory buffers, breaking down @@ -4758,9 +4748,9 @@ IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { if (!IdentifiersLoaded[ID]) { GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); - unsigned Index = ID + I->second.second; - const char *Str = I->second.first->IdentifierTableData - + I->second.first->IdentifierOffsets[Index]; + Module *M = I->second; + unsigned Index = ID - M->BaseIdentifierID; + const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; // 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(). @@ -4809,11 +4799,11 @@ Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { // Load this selector from the selector table. GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); - Module &F = *I->second.first; - ASTSelectorLookupTrait Trait(*this, F); - unsigned Idx = ID - 1 + I->second.second; + Module &M = *I->second; + ASTSelectorLookupTrait Trait(*this, M); + unsigned Idx = ID - 1 - M.BaseSelectorID; SelectorsLoaded[ID - 1] = - Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); + Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); if (DeserializationListener) DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); } diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 5b36743992..546ca4dbe4 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1406,8 +1406,8 @@ ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) { 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]); + Module *M = I->second; + return RecordLocation(M, M->DeclOffsets[Index - M->BaseDeclID]); } ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {