@@ -969,7 +969,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
969969 SelectorTable &SelTable = Reader.getContext ().Selectors ;
970970 unsigned N = endian::readNext<uint16_t , llvm::endianness::little>(d);
971971 const IdentifierInfo *FirstII = Reader.getLocalIdentifier (
972- F, endian::readNext<IdentifierID , llvm::endianness::little>(d));
972+ F, endian::readNext<uint32_t , llvm::endianness::little>(d));
973973 if (N == 0 )
974974 return SelTable.getNullarySelector (FirstII);
975975 else if (N == 1 )
@@ -979,7 +979,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
979979 Args.push_back (FirstII);
980980 for (unsigned I = 1 ; I != N; ++I)
981981 Args.push_back (Reader.getLocalIdentifier (
982- F, endian::readNext<IdentifierID , llvm::endianness::little>(d)));
982+ F, endian::readNext<uint32_t , llvm::endianness::little>(d)));
983983
984984 return SelTable.getSelector (N, Args.data ());
985985}
@@ -1062,8 +1062,7 @@ static bool readBit(unsigned &Bits) {
10621062IdentifierID ASTIdentifierLookupTrait::ReadIdentifierID (const unsigned char *d) {
10631063 using namespace llvm ::support;
10641064
1065- IdentifierID RawID =
1066- endian::readNext<IdentifierID, llvm::endianness::little>(d);
1065+ unsigned RawID = endian::readNext<uint32_t , llvm::endianness::little>(d);
10671066 return Reader.getGlobalIdentifierID (F, RawID >> 1 );
10681067}
10691068
@@ -1081,12 +1080,9 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
10811080 unsigned DataLen) {
10821081 using namespace llvm ::support;
10831082
1084- IdentifierID RawID =
1085- endian::readNext<IdentifierID, llvm::endianness::little>(d);
1083+ unsigned RawID = endian::readNext<uint32_t , llvm::endianness::little>(d);
10861084 bool IsInteresting = RawID & 0x01 ;
10871085
1088- DataLen -= sizeof (IdentifierID);
1089-
10901086 // Wipe out the "is interesting" bit.
10911087 RawID = RawID >> 1 ;
10921088
@@ -1117,7 +1113,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
11171113 bool HadMacroDefinition = readBit (Bits);
11181114
11191115 assert (Bits == 0 && " Extra bits in the identifier?" );
1120- DataLen -= sizeof ( uint16_t ) * 2 ;
1116+ DataLen -= 8 ;
11211117
11221118 // Set or check the various bits in the IdentifierInfo structure.
11231119 // Token IDs are read-only.
@@ -1244,7 +1240,7 @@ ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) {
12441240 case DeclarationName::CXXLiteralOperatorName:
12451241 case DeclarationName::CXXDeductionGuideName:
12461242 Data = (uint64_t )Reader.getLocalIdentifier (
1247- F, endian::readNext<IdentifierID , llvm::endianness::little>(d));
1243+ F, endian::readNext<uint32_t , llvm::endianness::little>(d));
12481244 break ;
12491245 case DeclarationName::ObjCZeroArgSelector:
12501246 case DeclarationName::ObjCOneArgSelector:
@@ -2115,7 +2111,7 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
21152111 HFI.DirInfo = (Flags >> 1 ) & 0x07 ;
21162112 HFI.IndexHeaderMapHeader = Flags & 0x01 ;
21172113 HFI.LazyControllingMacro = Reader.getGlobalIdentifierID (
2118- M, endian::readNext<IdentifierID , llvm::endianness::little>(d));
2114+ M, endian::readNext<uint32_t , llvm::endianness::little>(d));
21192115 if (unsigned FrameworkOffset =
21202116 endian::readNext<uint32_t , llvm::endianness::little>(d)) {
21212117 // The framework offset is 1 greater than the actual offset,
@@ -3513,11 +3509,24 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
35133509 " duplicate IDENTIFIER_OFFSET record in AST file" );
35143510 F.IdentifierOffsets = (const uint32_t *)Blob.data ();
35153511 F.LocalNumIdentifiers = Record[0 ];
3512+ unsigned LocalBaseIdentifierID = Record[1 ];
35163513 F.BaseIdentifierID = getTotalNumIdentifiers ();
35173514
3518- if (F.LocalNumIdentifiers > 0 )
3515+ if (F.LocalNumIdentifiers > 0 ) {
3516+ // Introduce the global -> local mapping for identifiers within this
3517+ // module.
3518+ GlobalIdentifierMap.insert (std::make_pair (getTotalNumIdentifiers () + 1 ,
3519+ &F));
3520+
3521+ // Introduce the local -> global mapping for identifiers within this
3522+ // module.
3523+ F.IdentifierRemap .insertOrReplace (
3524+ std::make_pair (LocalBaseIdentifierID,
3525+ F.BaseIdentifierID - LocalBaseIdentifierID));
3526+
35193527 IdentifiersLoaded.resize (IdentifiersLoaded.size ()
35203528 + F.LocalNumIdentifiers );
3529+ }
35213530 break ;
35223531 }
35233532
@@ -4104,6 +4113,7 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
41044113 F.ModuleOffsetMap = StringRef ();
41054114
41064115 using RemapBuilder = ContinuousRangeMap<uint32_t , int , 2 >::Builder;
4116+ RemapBuilder IdentifierRemap (F.IdentifierRemap );
41074117 RemapBuilder MacroRemap (F.MacroRemap );
41084118 RemapBuilder PreprocessedEntityRemap (F.PreprocessedEntityRemap );
41094119 RemapBuilder SubmoduleRemap (F.SubmoduleRemap );
@@ -4135,6 +4145,8 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
41354145
41364146 ImportedModuleVector.push_back (OM);
41374147
4148+ uint32_t IdentifierIDOffset =
4149+ endian::readNext<uint32_t , llvm::endianness::little>(Data);
41384150 uint32_t MacroIDOffset =
41394151 endian::readNext<uint32_t , llvm::endianness::little>(Data);
41404152 uint32_t PreprocessedEntityIDOffset =
@@ -4152,6 +4164,7 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
41524164 static_cast <int >(BaseOffset - Offset)));
41534165 };
41544166
4167+ mapOffset (IdentifierIDOffset, OM->BaseIdentifierID , IdentifierRemap);
41554168 mapOffset (MacroIDOffset, OM->BaseMacroID , MacroRemap);
41564169 mapOffset (PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID ,
41574170 PreprocessedEntityRemap);
@@ -8289,6 +8302,7 @@ LLVM_DUMP_METHOD void ASTReader::dump() {
82898302 llvm::errs () << " *** PCH/ModuleFile Remappings:\n " ;
82908303 dumpModuleIDMap (" Global bit offset map" , GlobalBitOffsetsMap);
82918304 dumpModuleIDMap (" Global source location entry map" , GlobalSLocEntryMap);
8305+ dumpModuleIDMap (" Global identifier map" , GlobalIdentifierMap);
82928306 dumpModuleIDMap (" Global macro map" , GlobalMacroMap);
82938307 dumpModuleIDMap (" Global submodule map" , GlobalSubmoduleMap);
82948308 dumpModuleIDMap (" Global selector map" , GlobalSelectorMap);
@@ -8928,9 +8942,8 @@ void ASTReader::LoadSelector(Selector Sel) {
89288942
89298943void ASTReader::SetIdentifierInfo (IdentifierID ID, IdentifierInfo *II) {
89308944 assert (ID && " Non-zero identifier ID required" );
8931- unsigned Index = translateIdentifierIDToIndex (ID).second ;
8932- assert (Index < IdentifiersLoaded.size () && " identifier ID out of range" );
8933- IdentifiersLoaded[Index] = II;
8945+ assert (ID <= IdentifiersLoaded.size () && " identifier ID out of range" );
8946+ IdentifiersLoaded[ID - 1 ] = II;
89348947 if (DeserializationListener)
89358948 DeserializationListener->IdentifierRead (ID, II);
89368949}
@@ -8983,22 +8996,6 @@ void ASTReader::SetGloballyVisibleDecls(
89838996 }
89848997}
89858998
8986- std::pair<ModuleFile *, unsigned >
8987- ASTReader::translateIdentifierIDToIndex (IdentifierID ID) const {
8988- if (ID == 0 )
8989- return {nullptr , 0 };
8990-
8991- unsigned ModuleFileIndex = ID >> 32 ;
8992- unsigned LocalID = ID & llvm::maskTrailingOnes<IdentifierID>(32 );
8993-
8994- assert (ModuleFileIndex && " not translating loaded IdentifierID?" );
8995- assert (getModuleManager ().size () > ModuleFileIndex - 1 );
8996-
8997- ModuleFile &MF = getModuleManager ()[ModuleFileIndex - 1 ];
8998- assert (LocalID < MF.LocalNumIdentifiers );
8999- return {&MF, MF.BaseIdentifierID + LocalID};
9000- }
9001-
90028999IdentifierInfo *ASTReader::DecodeIdentifierInfo (IdentifierID ID) {
90039000 if (ID == 0 )
90049001 return nullptr ;
@@ -9008,48 +9005,45 @@ IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
90089005 return nullptr ;
90099006 }
90109007
9011- auto [M, Index] = translateIdentifierIDToIndex (ID);
9012- if (!IdentifiersLoaded[Index]) {
9013- assert (M != nullptr && " Untranslated Identifier ID?" );
9014- assert (Index >= M->BaseIdentifierID );
9015- unsigned LocalIndex = Index - M->BaseIdentifierID ;
9008+ ID -= 1 ;
9009+ if (!IdentifiersLoaded[ID]) {
9010+ GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find (ID + 1 );
9011+ assert (I != GlobalIdentifierMap.end () && " Corrupted global identifier map" );
9012+ ModuleFile *M = I->second ;
9013+ unsigned Index = ID - M->BaseIdentifierID ;
90169014 const unsigned char *Data =
9017- M->IdentifierTableData + M->IdentifierOffsets [LocalIndex ];
9015+ M->IdentifierTableData + M->IdentifierOffsets [Index ];
90189016
90199017 ASTIdentifierLookupTrait Trait (*this , *M);
90209018 auto KeyDataLen = Trait.ReadKeyDataLength (Data);
90219019 auto Key = Trait.ReadKey (Data, KeyDataLen.first );
90229020 auto &II = PP.getIdentifierTable ().get (Key);
9023- IdentifiersLoaded[Index ] = &II;
9021+ IdentifiersLoaded[ID ] = &II;
90249022 markIdentifierFromAST (*this , II);
90259023 if (DeserializationListener)
9026- DeserializationListener->IdentifierRead (ID, &II);
9024+ DeserializationListener->IdentifierRead (ID + 1 , &II);
90279025 }
90289026
9029- return IdentifiersLoaded[Index ];
9027+ return IdentifiersLoaded[ID ];
90309028}
90319029
9032- IdentifierInfo *ASTReader::getLocalIdentifier (ModuleFile &M, uint64_t LocalID) {
9030+ IdentifierInfo *ASTReader::getLocalIdentifier (ModuleFile &M, unsigned LocalID) {
90339031 return DecodeIdentifierInfo (getGlobalIdentifierID (M, LocalID));
90349032}
90359033
9036- IdentifierID ASTReader::getGlobalIdentifierID (ModuleFile &M, uint64_t LocalID) {
9034+ IdentifierID ASTReader::getGlobalIdentifierID (ModuleFile &M, unsigned LocalID) {
90379035 if (LocalID < NUM_PREDEF_IDENT_IDS)
90389036 return LocalID;
90399037
90409038 if (!M.ModuleOffsetMap .empty ())
90419039 ReadModuleOffsetMap (M);
90429040
9043- unsigned ModuleFileIndex = LocalID >> 32 ;
9044- LocalID &= llvm::maskTrailingOnes<IdentifierID>(32 );
9045- ModuleFile *MF =
9046- ModuleFileIndex ? M.TransitiveImports [ModuleFileIndex - 1 ] : &M;
9047- assert (MF && " malformed identifier ID encoding?" );
9048-
9049- if (!ModuleFileIndex)
9050- LocalID -= NUM_PREDEF_IDENT_IDS;
9041+ ContinuousRangeMap<uint32_t , int , 2 >::iterator I
9042+ = M.IdentifierRemap .find (LocalID - NUM_PREDEF_IDENT_IDS);
9043+ assert (I != M.IdentifierRemap .end ()
9044+ && " Invalid index into identifier index remap" );
90519045
9052- return ((IdentifierID)(MF-> Index + 1 ) << 32 ) | LocalID ;
9046+ return LocalID + I-> second ;
90539047}
90549048
90559049MacroInfo *ASTReader::getMacro (MacroID ID) {
0 commit comments