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