@@ -918,7 +918,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
918
918
SelectorTable &SelTable = Reader.getContext().Selectors;
919
919
unsigned N = endian::readNext<uint16_t, llvm::endianness::little>(d);
920
920
const IdentifierInfo *FirstII = Reader.getLocalIdentifier(
921
- F, endian::readNext<uint32_t , llvm::endianness::little>(d));
921
+ F, endian::readNext<IdentifierID , llvm::endianness::little>(d));
922
922
if (N == 0)
923
923
return SelTable.getNullarySelector(FirstII);
924
924
else if (N == 1)
@@ -928,7 +928,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
928
928
Args.push_back(FirstII);
929
929
for (unsigned I = 1; I != N; ++I)
930
930
Args.push_back(Reader.getLocalIdentifier(
931
- F, endian::readNext<uint32_t , llvm::endianness::little>(d)));
931
+ F, endian::readNext<IdentifierID , llvm::endianness::little>(d)));
932
932
933
933
return SelTable.getSelector(N, Args.data());
934
934
}
@@ -1009,7 +1009,8 @@ static bool readBit(unsigned &Bits) {
1009
1009
IdentifierID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) {
1010
1010
using namespace llvm::support;
1011
1011
1012
- unsigned RawID = endian::readNext<uint32_t , llvm::endianness::little>(d);
1012
+ IdentifierID RawID =
1013
+ endian::readNext<IdentifierID, llvm::endianness::little>(d);
1013
1014
return Reader.getGlobalIdentifierID(F, RawID >> 1);
1014
1015
}
1015
1016
@@ -1027,9 +1028,12 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
1027
1028
unsigned DataLen) {
1028
1029
using namespace llvm::support;
1029
1030
1030
- unsigned RawID = endian::readNext<uint32_t , llvm::endianness::little>(d);
1031
+ IdentifierID RawID =
1032
+ endian::readNext<IdentifierID, llvm::endianness::little>(d);
1031
1033
bool IsInteresting = RawID & 0x01;
1032
1034
1035
+ DataLen -= sizeof(IdentifierID);
1036
+
1033
1037
// Wipe out the "is interesting" bit.
1034
1038
RawID = RawID >> 1;
1035
1039
@@ -1060,7 +1064,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
1060
1064
bool HadMacroDefinition = readBit(Bits);
1061
1065
1062
1066
assert(Bits == 0 && "Extra bits in the identifier?");
1063
- DataLen -= 8 ;
1067
+ DataLen -= sizeof(uint16_t) * 2 ;
1064
1068
1065
1069
// Set or check the various bits in the IdentifierInfo structure.
1066
1070
// Token IDs are read-only.
@@ -1186,7 +1190,7 @@ ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) {
1186
1190
case DeclarationName::CXXLiteralOperatorName:
1187
1191
case DeclarationName::CXXDeductionGuideName:
1188
1192
Data = (uint64_t)Reader.getLocalIdentifier(
1189
- F, endian::readNext<uint32_t , llvm::endianness::little>(d));
1193
+ F, endian::readNext<IdentifierID , llvm::endianness::little>(d));
1190
1194
break;
1191
1195
case DeclarationName::ObjCZeroArgSelector:
1192
1196
case DeclarationName::ObjCOneArgSelector:
@@ -2055,7 +2059,7 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
2055
2059
HFI.DirInfo = (Flags >> 1) & 0x07;
2056
2060
HFI.IndexHeaderMapHeader = Flags & 0x01;
2057
2061
HFI.ControllingMacroID = Reader.getGlobalIdentifierID(
2058
- M, endian::readNext<uint32_t , llvm::endianness::little>(d));
2062
+ M, endian::readNext<IdentifierID , llvm::endianness::little>(d));
2059
2063
if (unsigned FrameworkOffset =
2060
2064
endian::readNext<uint32_t, llvm::endianness::little>(d)) {
2061
2065
// The framework offset is 1 greater than the actual offset,
@@ -3429,24 +3433,11 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
3429
3433
"duplicate IDENTIFIER_OFFSET record in AST file");
3430
3434
F.IdentifierOffsets = (const uint32_t *)Blob.data();
3431
3435
F.LocalNumIdentifiers = Record[0];
3432
- unsigned LocalBaseIdentifierID = Record[1 ];
3433
3436
F.BaseIdentifierID = getTotalNumIdentifiers();
3434
3437
3435
- if (F.LocalNumIdentifiers > 0 ) {
3436
- // Introduce the global -> local mapping for identifiers within this
3437
- // module.
3438
- GlobalIdentifierMap.insert (std::make_pair (getTotalNumIdentifiers () + 1 ,
3439
- &F));
3440
-
3441
- // Introduce the local -> global mapping for identifiers within this
3442
- // module.
3443
- F.IdentifierRemap .insertOrReplace (
3444
- std::make_pair (LocalBaseIdentifierID,
3445
- F.BaseIdentifierID - LocalBaseIdentifierID));
3446
-
3438
+ if (F.LocalNumIdentifiers > 0)
3447
3439
IdentifiersLoaded.resize(IdentifiersLoaded.size()
3448
3440
+ F.LocalNumIdentifiers);
3449
- }
3450
3441
break;
3451
3442
}
3452
3443
@@ -4038,7 +4029,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4038
4029
F.ModuleOffsetMap = StringRef();
4039
4030
4040
4031
using RemapBuilder = ContinuousRangeMap<uint32_t, int, 2>::Builder;
4041
- RemapBuilder IdentifierRemap (F.IdentifierRemap );
4042
4032
RemapBuilder MacroRemap(F.MacroRemap);
4043
4033
RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap);
4044
4034
RemapBuilder SubmoduleRemap(F.SubmoduleRemap);
@@ -4071,8 +4061,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4071
4061
4072
4062
ImportedModuleVector.push_back(OM);
4073
4063
4074
- uint32_t IdentifierIDOffset =
4075
- endian::readNext<uint32_t , llvm::endianness::little>(Data);
4076
4064
uint32_t MacroIDOffset =
4077
4065
endian::readNext<uint32_t, llvm::endianness::little>(Data);
4078
4066
uint32_t PreprocessedEntityIDOffset =
@@ -4092,7 +4080,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4092
4080
static_cast<int>(BaseOffset - Offset)));
4093
4081
};
4094
4082
4095
- mapOffset (IdentifierIDOffset, OM->BaseIdentifierID , IdentifierRemap);
4096
4083
mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap);
4097
4084
mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID,
4098
4085
PreprocessedEntityRemap);
@@ -8181,7 +8168,6 @@ LLVM_DUMP_METHOD void ASTReader::dump() {
8181
8168
dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap);
8182
8169
dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap);
8183
8170
dumpModuleIDMap("Global type map", GlobalTypeMap);
8184
- dumpModuleIDMap (" Global identifier map" , GlobalIdentifierMap);
8185
8171
dumpModuleIDMap("Global macro map", GlobalMacroMap);
8186
8172
dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap);
8187
8173
dumpModuleIDMap("Global selector map", GlobalSelectorMap);
@@ -8822,8 +8808,9 @@ void ASTReader::LoadSelector(Selector Sel) {
8822
8808
8823
8809
void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) {
8824
8810
assert(ID && "Non-zero identifier ID required");
8825
- assert (ID <= IdentifiersLoaded.size () && " identifier ID out of range" );
8826
- IdentifiersLoaded[ID - 1 ] = II;
8811
+ unsigned Index = translateIdentifierIDToIndex(ID).second;
8812
+ assert(Index < IdentifiersLoaded.size() && "identifier ID out of range");
8813
+ IdentifiersLoaded[Index] = II;
8827
8814
if (DeserializationListener)
8828
8815
DeserializationListener->IdentifierRead(ID, II);
8829
8816
}
@@ -8876,6 +8863,22 @@ void ASTReader::SetGloballyVisibleDecls(
8876
8863
}
8877
8864
}
8878
8865
8866
+ std::pair<ModuleFile *, unsigned>
8867
+ ASTReader::translateIdentifierIDToIndex(IdentifierID ID) const {
8868
+ if (ID == 0)
8869
+ return {nullptr, 0};
8870
+
8871
+ unsigned ModuleFileIndex = ID >> 32;
8872
+ unsigned LocalID = ID & llvm::maskTrailingOnes<IdentifierID>(32);
8873
+
8874
+ assert(ModuleFileIndex && "not translating loaded IdentifierID?");
8875
+ assert(getModuleManager().size() > ModuleFileIndex - 1);
8876
+
8877
+ ModuleFile &MF = getModuleManager()[ModuleFileIndex - 1];
8878
+ assert(LocalID < MF.LocalNumIdentifiers);
8879
+ return {&MF, MF.BaseIdentifierID + LocalID};
8880
+ }
8881
+
8879
8882
IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
8880
8883
if (ID == 0)
8881
8884
return nullptr;
@@ -8885,45 +8888,48 @@ IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
8885
8888
return nullptr;
8886
8889
}
8887
8890
8888
- ID -= 1 ;
8889
- if (!IdentifiersLoaded[ID]) {
8890
- GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find (ID + 1 );
8891
- assert (I != GlobalIdentifierMap.end () && " Corrupted global identifier map" );
8892
- ModuleFile *M = I->second ;
8893
- unsigned Index = ID - M->BaseIdentifierID ;
8891
+ auto [M, Index] = translateIdentifierIDToIndex(ID);
8892
+ if (!IdentifiersLoaded[Index]) {
8893
+ assert(M != nullptr && "Untranslated Identifier ID?");
8894
+ assert(Index >= M->BaseIdentifierID);
8895
+ unsigned LocalIndex = Index - M->BaseIdentifierID;
8894
8896
const unsigned char *Data =
8895
- M->IdentifierTableData + M->IdentifierOffsets [Index ];
8897
+ M->IdentifierTableData + M->IdentifierOffsets[LocalIndex ];
8896
8898
8897
8899
ASTIdentifierLookupTrait Trait(*this, *M);
8898
8900
auto KeyDataLen = Trait.ReadKeyDataLength(Data);
8899
8901
auto Key = Trait.ReadKey(Data, KeyDataLen.first);
8900
8902
auto &II = PP.getIdentifierTable().get(Key);
8901
- IdentifiersLoaded[ID ] = &II;
8903
+ IdentifiersLoaded[Index ] = &II;
8902
8904
markIdentifierFromAST(*this, II);
8903
8905
if (DeserializationListener)
8904
- DeserializationListener->IdentifierRead (ID + 1 , &II);
8906
+ DeserializationListener->IdentifierRead(ID, &II);
8905
8907
}
8906
8908
8907
- return IdentifiersLoaded[ID ];
8909
+ return IdentifiersLoaded[Index ];
8908
8910
}
8909
8911
8910
- IdentifierInfo *ASTReader::getLocalIdentifier (ModuleFile &M, unsigned LocalID) {
8912
+ IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, uint64_t LocalID) {
8911
8913
return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID));
8912
8914
}
8913
8915
8914
- IdentifierID ASTReader::getGlobalIdentifierID (ModuleFile &M, unsigned LocalID) {
8916
+ IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, uint64_t LocalID) {
8915
8917
if (LocalID < NUM_PREDEF_IDENT_IDS)
8916
8918
return LocalID;
8917
8919
8918
8920
if (!M.ModuleOffsetMap.empty())
8919
8921
ReadModuleOffsetMap(M);
8920
8922
8921
- ContinuousRangeMap<uint32_t , int , 2 >::iterator I
8922
- = M.IdentifierRemap .find (LocalID - NUM_PREDEF_IDENT_IDS);
8923
- assert (I != M.IdentifierRemap .end ()
8924
- && " Invalid index into identifier index remap" );
8923
+ unsigned ModuleFileIndex = LocalID >> 32;
8924
+ LocalID &= llvm::maskTrailingOnes<IdentifierID>(32);
8925
+ ModuleFile *MF =
8926
+ ModuleFileIndex ? M.DependentModules[ModuleFileIndex - 1] : &M;
8927
+ assert(MF && "malformed identifier ID encoding?");
8925
8928
8926
- return LocalID + I->second ;
8929
+ if (!ModuleFileIndex)
8930
+ LocalID -= NUM_PREDEF_IDENT_IDS;
8931
+
8932
+ return ((IdentifierID)(MF->Index + 1) << 32) | LocalID;
8927
8933
}
8928
8934
8929
8935
MacroInfo *ASTReader::getMacro(MacroID ID) {
0 commit comments