@@ -969,7 +969,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
969
969
SelectorTable &SelTable = Reader.getContext().Selectors;
970
970
unsigned N = endian::readNext<uint16_t, llvm::endianness::little>(d);
971
971
const IdentifierInfo *FirstII = Reader.getLocalIdentifier(
972
- F, endian::readNext<uint32_t , llvm::endianness::little>(d));
972
+ F, endian::readNext<IdentifierID , llvm::endianness::little>(d));
973
973
if (N == 0)
974
974
return SelTable.getNullarySelector(FirstII);
975
975
else if (N == 1)
@@ -979,7 +979,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
979
979
Args.push_back(FirstII);
980
980
for (unsigned I = 1; I != N; ++I)
981
981
Args.push_back(Reader.getLocalIdentifier(
982
- F, endian::readNext<uint32_t , llvm::endianness::little>(d)));
982
+ F, endian::readNext<IdentifierID , llvm::endianness::little>(d)));
983
983
984
984
return SelTable.getSelector(N, Args.data());
985
985
}
@@ -1062,7 +1062,8 @@ static bool readBit(unsigned &Bits) {
1062
1062
IdentifierID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) {
1063
1063
using namespace llvm::support;
1064
1064
1065
- unsigned RawID = endian::readNext<uint32_t, llvm::endianness::little>(d);
1065
+ IdentifierID RawID =
1066
+ endian::readNext<IdentifierID, llvm::endianness::little>(d);
1066
1067
return Reader.getGlobalIdentifierID(F, RawID >> 1);
1067
1068
}
1068
1069
@@ -1080,9 +1081,12 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
1080
1081
unsigned DataLen) {
1081
1082
using namespace llvm::support;
1082
1083
1083
- unsigned RawID = endian::readNext<uint32_t, llvm::endianness::little>(d);
1084
+ IdentifierID RawID =
1085
+ endian::readNext<IdentifierID, llvm::endianness::little>(d);
1084
1086
bool IsInteresting = RawID & 0x01;
1085
1087
1088
+ DataLen -= sizeof(IdentifierID);
1089
+
1086
1090
// Wipe out the "is interesting" bit.
1087
1091
RawID = RawID >> 1;
1088
1092
@@ -1113,7 +1117,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
1113
1117
bool HadMacroDefinition = readBit(Bits);
1114
1118
1115
1119
assert(Bits == 0 && "Extra bits in the identifier?");
1116
- DataLen -= 8 ;
1120
+ DataLen -= sizeof(uint16_t) * 2 ;
1117
1121
1118
1122
// Set or check the various bits in the IdentifierInfo structure.
1119
1123
// Token IDs are read-only.
@@ -1240,7 +1244,7 @@ ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) {
1240
1244
case DeclarationName::CXXLiteralOperatorName:
1241
1245
case DeclarationName::CXXDeductionGuideName:
1242
1246
Data = (uint64_t)Reader.getLocalIdentifier(
1243
- F, endian::readNext<uint32_t , llvm::endianness::little>(d));
1247
+ F, endian::readNext<IdentifierID , llvm::endianness::little>(d));
1244
1248
break;
1245
1249
case DeclarationName::ObjCZeroArgSelector:
1246
1250
case DeclarationName::ObjCOneArgSelector:
@@ -2111,7 +2115,7 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
2111
2115
HFI.DirInfo = (Flags >> 1) & 0x07;
2112
2116
HFI.IndexHeaderMapHeader = Flags & 0x01;
2113
2117
HFI.LazyControllingMacro = Reader.getGlobalIdentifierID(
2114
- M, endian::readNext<uint32_t , llvm::endianness::little>(d));
2118
+ M, endian::readNext<IdentifierID , llvm::endianness::little>(d));
2115
2119
if (unsigned FrameworkOffset =
2116
2120
endian::readNext<uint32_t, llvm::endianness::little>(d)) {
2117
2121
// The framework offset is 1 greater than the actual offset,
@@ -3509,24 +3513,11 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
3509
3513
"duplicate IDENTIFIER_OFFSET record in AST file");
3510
3514
F.IdentifierOffsets = (const uint32_t *)Blob.data();
3511
3515
F.LocalNumIdentifiers = Record[0];
3512
- unsigned LocalBaseIdentifierID = Record[1];
3513
3516
F.BaseIdentifierID = getTotalNumIdentifiers();
3514
3517
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
-
3518
+ if (F.LocalNumIdentifiers > 0)
3527
3519
IdentifiersLoaded.resize(IdentifiersLoaded.size()
3528
3520
+ F.LocalNumIdentifiers);
3529
- }
3530
3521
break;
3531
3522
}
3532
3523
@@ -4113,7 +4104,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4113
4104
F.ModuleOffsetMap = StringRef();
4114
4105
4115
4106
using RemapBuilder = ContinuousRangeMap<uint32_t, int, 2>::Builder;
4116
- RemapBuilder IdentifierRemap(F.IdentifierRemap);
4117
4107
RemapBuilder MacroRemap(F.MacroRemap);
4118
4108
RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap);
4119
4109
RemapBuilder SubmoduleRemap(F.SubmoduleRemap);
@@ -4145,8 +4135,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4145
4135
4146
4136
ImportedModuleVector.push_back(OM);
4147
4137
4148
- uint32_t IdentifierIDOffset =
4149
- endian::readNext<uint32_t, llvm::endianness::little>(Data);
4150
4138
uint32_t MacroIDOffset =
4151
4139
endian::readNext<uint32_t, llvm::endianness::little>(Data);
4152
4140
uint32_t PreprocessedEntityIDOffset =
@@ -4164,7 +4152,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4164
4152
static_cast<int>(BaseOffset - Offset)));
4165
4153
};
4166
4154
4167
- mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap);
4168
4155
mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap);
4169
4156
mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID,
4170
4157
PreprocessedEntityRemap);
@@ -8302,7 +8289,6 @@ LLVM_DUMP_METHOD void ASTReader::dump() {
8302
8289
llvm::errs() << "*** PCH/ModuleFile Remappings:\n";
8303
8290
dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap);
8304
8291
dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap);
8305
- dumpModuleIDMap("Global identifier map", GlobalIdentifierMap);
8306
8292
dumpModuleIDMap("Global macro map", GlobalMacroMap);
8307
8293
dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap);
8308
8294
dumpModuleIDMap("Global selector map", GlobalSelectorMap);
@@ -8942,8 +8928,9 @@ void ASTReader::LoadSelector(Selector Sel) {
8942
8928
8943
8929
void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) {
8944
8930
assert(ID && "Non-zero identifier ID required");
8945
- assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range");
8946
- IdentifiersLoaded[ID - 1] = II;
8931
+ unsigned Index = translateIdentifierIDToIndex(ID).second;
8932
+ assert(Index < IdentifiersLoaded.size() && "identifier ID out of range");
8933
+ IdentifiersLoaded[Index] = II;
8947
8934
if (DeserializationListener)
8948
8935
DeserializationListener->IdentifierRead(ID, II);
8949
8936
}
@@ -8996,6 +8983,22 @@ void ASTReader::SetGloballyVisibleDecls(
8996
8983
}
8997
8984
}
8998
8985
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
+
8999
9002
IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
9000
9003
if (ID == 0)
9001
9004
return nullptr;
@@ -9005,45 +9008,48 @@ IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
9005
9008
return nullptr;
9006
9009
}
9007
9010
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;
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;
9014
9016
const unsigned char *Data =
9015
- M->IdentifierTableData + M->IdentifierOffsets[Index ];
9017
+ M->IdentifierTableData + M->IdentifierOffsets[LocalIndex ];
9016
9018
9017
9019
ASTIdentifierLookupTrait Trait(*this, *M);
9018
9020
auto KeyDataLen = Trait.ReadKeyDataLength(Data);
9019
9021
auto Key = Trait.ReadKey(Data, KeyDataLen.first);
9020
9022
auto &II = PP.getIdentifierTable().get(Key);
9021
- IdentifiersLoaded[ID ] = &II;
9023
+ IdentifiersLoaded[Index ] = &II;
9022
9024
markIdentifierFromAST(*this, II);
9023
9025
if (DeserializationListener)
9024
- DeserializationListener->IdentifierRead(ID + 1 , &II);
9026
+ DeserializationListener->IdentifierRead(ID, &II);
9025
9027
}
9026
9028
9027
- return IdentifiersLoaded[ID ];
9029
+ return IdentifiersLoaded[Index ];
9028
9030
}
9029
9031
9030
- IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) {
9032
+ IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, uint64_t LocalID) {
9031
9033
return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID));
9032
9034
}
9033
9035
9034
- IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) {
9036
+ IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, uint64_t LocalID) {
9035
9037
if (LocalID < NUM_PREDEF_IDENT_IDS)
9036
9038
return LocalID;
9037
9039
9038
9040
if (!M.ModuleOffsetMap.empty())
9039
9041
ReadModuleOffsetMap(M);
9040
9042
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");
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?");
9045
9048
9046
- return LocalID + I->second;
9049
+ if (!ModuleFileIndex)
9050
+ LocalID -= NUM_PREDEF_IDENT_IDS;
9051
+
9052
+ return ((IdentifierID)(MF->Index + 1) << 32) | LocalID;
9047
9053
}
9048
9054
9049
9055
MacroInfo *ASTReader::getMacro(MacroID ID) {
0 commit comments