Skip to content

Commit c612b56

Browse files
committed
[Serialization] No transitive identifier change
1 parent bf9f481 commit c612b56

File tree

10 files changed

+214
-85
lines changed

10 files changed

+214
-85
lines changed

clang/include/clang/Lex/ExternalPreprocessorSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ExternalPreprocessorSource {
3636
/// Return the identifier associated with the given ID number.
3737
///
3838
/// The ID 0 is associated with the NULL identifier.
39-
virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
39+
virtual IdentifierInfo *GetIdentifier(uint64_t ID) = 0;
4040

4141
/// Map a module ID to a module.
4242
virtual Module *getModule(unsigned ModuleID) = 0;

clang/include/clang/Lex/HeaderSearch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct HeaderFileInfo {
124124
/// This ID number will be non-zero when there is a controlling
125125
/// macro whose IdentifierInfo may not yet have been loaded from
126126
/// external storage.
127-
unsigned ControllingMacroID = 0;
127+
uint64_t ControllingMacroID = 0;
128128

129129
/// If this file has a \#ifndef XXX (or equivalent) guard that
130130
/// protects the entire contents of the file, this is the identifier

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const unsigned VERSION_MINOR = 1;
5959
///
6060
/// The ID numbers of identifiers are consecutive (in order of discovery)
6161
/// and start at 1. 0 is reserved for NULL.
62-
using IdentifierID = uint32_t;
62+
using IdentifierID = uint64_t;
6363

6464
/// The number of predefined identifier IDs.
6565
const unsigned int NUM_PREDEF_IDENT_IDS = 1;

clang/include/clang/Serialization/ASTReader.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,6 @@ class ASTReader
657657
/// been loaded.
658658
std::vector<IdentifierInfo *> IdentifiersLoaded;
659659

660-
using GlobalIdentifierMapType =
661-
ContinuousRangeMap<serialization::IdentifierID, ModuleFile *, 4>;
662-
663-
/// Mapping from global identifier IDs to the module in which the
664-
/// identifier resides along with the offset that should be added to the
665-
/// global identifier ID to produce a local ID.
666-
GlobalIdentifierMapType GlobalIdentifierMap;
667-
668660
/// A vector containing macros that have already been
669661
/// loaded.
670662
///
@@ -1536,6 +1528,11 @@ class ASTReader
15361528
/// Translate a \param GlobalDeclID to the index of DeclsLoaded array.
15371529
unsigned translateGlobalDeclIDToIndex(GlobalDeclID ID) const;
15381530

1531+
/// Translate an \param IdentifierID ID to the index of IdentifiersLoaded
1532+
/// array and the corresponding module file.
1533+
std::pair<ModuleFile *, unsigned>
1534+
translateIdentifierIDToIndex(serialization::IdentifierID ID) const;
1535+
15391536
public:
15401537
/// Load the AST file and validate its contents against the given
15411538
/// Preprocessor.
@@ -2120,7 +2117,7 @@ class ASTReader
21202117
/// Load a selector from disk, registering its ID if it exists.
21212118
void LoadSelector(Selector Sel);
21222119

2123-
void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
2120+
void SetIdentifierInfo(serialization::IdentifierID ID, IdentifierInfo *II);
21242121
void SetGloballyVisibleDecls(IdentifierInfo *II,
21252122
const SmallVectorImpl<GlobalDeclID> &DeclIDs,
21262123
SmallVectorImpl<Decl *> *Decls = nullptr);
@@ -2145,10 +2142,10 @@ class ASTReader
21452142
return DecodeIdentifierInfo(ID);
21462143
}
21472144

2148-
IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
2145+
IdentifierInfo *getLocalIdentifier(ModuleFile &M, uint64_t LocalID);
21492146

21502147
serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
2151-
unsigned LocalID);
2148+
uint64_t LocalID);
21522149

21532150
void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
21542151

clang/include/clang/Serialization/ModuleFile.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,6 @@ class ModuleFile {
310310
/// Base identifier ID for identifiers local to this module.
311311
serialization::IdentifierID BaseIdentifierID = 0;
312312

313-
/// Remapping table for identifier IDs in this module.
314-
ContinuousRangeMap<uint32_t, int, 2> IdentifierRemap;
315-
316313
/// Actual data for the on-disk hash table of identifiers.
317314
///
318315
/// This pointer points into a memory buffer, where the on-disk hash

clang/lib/Serialization/ASTReader.cpp

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
918918
SelectorTable &SelTable = Reader.getContext().Selectors;
919919
unsigned N = endian::readNext<uint16_t, llvm::endianness::little>(d);
920920
const IdentifierInfo *FirstII = Reader.getLocalIdentifier(
921-
F, endian::readNext<uint32_t, llvm::endianness::little>(d));
921+
F, endian::readNext<IdentifierID, llvm::endianness::little>(d));
922922
if (N == 0)
923923
return SelTable.getNullarySelector(FirstII);
924924
else if (N == 1)
@@ -928,7 +928,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
928928
Args.push_back(FirstII);
929929
for (unsigned I = 1; I != N; ++I)
930930
Args.push_back(Reader.getLocalIdentifier(
931-
F, endian::readNext<uint32_t, llvm::endianness::little>(d)));
931+
F, endian::readNext<IdentifierID, llvm::endianness::little>(d)));
932932

933933
return SelTable.getSelector(N, Args.data());
934934
}
@@ -1009,7 +1009,8 @@ static bool readBit(unsigned &Bits) {
10091009
IdentifierID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) {
10101010
using namespace llvm::support;
10111011

1012-
unsigned RawID = endian::readNext<uint32_t, llvm::endianness::little>(d);
1012+
IdentifierID RawID =
1013+
endian::readNext<IdentifierID, llvm::endianness::little>(d);
10131014
return Reader.getGlobalIdentifierID(F, RawID >> 1);
10141015
}
10151016

@@ -1027,9 +1028,12 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
10271028
unsigned DataLen) {
10281029
using namespace llvm::support;
10291030

1030-
unsigned RawID = endian::readNext<uint32_t, llvm::endianness::little>(d);
1031+
IdentifierID RawID =
1032+
endian::readNext<IdentifierID, llvm::endianness::little>(d);
10311033
bool IsInteresting = RawID & 0x01;
10321034

1035+
DataLen -= sizeof(IdentifierID);
1036+
10331037
// Wipe out the "is interesting" bit.
10341038
RawID = RawID >> 1;
10351039

@@ -1060,7 +1064,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
10601064
bool HadMacroDefinition = readBit(Bits);
10611065

10621066
assert(Bits == 0 && "Extra bits in the identifier?");
1063-
DataLen -= 8;
1067+
DataLen -= sizeof(uint16_t) * 2;
10641068

10651069
// Set or check the various bits in the IdentifierInfo structure.
10661070
// Token IDs are read-only.
@@ -1186,7 +1190,7 @@ ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) {
11861190
case DeclarationName::CXXLiteralOperatorName:
11871191
case DeclarationName::CXXDeductionGuideName:
11881192
Data = (uint64_t)Reader.getLocalIdentifier(
1189-
F, endian::readNext<uint32_t, llvm::endianness::little>(d));
1193+
F, endian::readNext<IdentifierID, llvm::endianness::little>(d));
11901194
break;
11911195
case DeclarationName::ObjCZeroArgSelector:
11921196
case DeclarationName::ObjCOneArgSelector:
@@ -2055,7 +2059,7 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
20552059
HFI.DirInfo = (Flags >> 1) & 0x07;
20562060
HFI.IndexHeaderMapHeader = Flags & 0x01;
20572061
HFI.ControllingMacroID = Reader.getGlobalIdentifierID(
2058-
M, endian::readNext<uint32_t, llvm::endianness::little>(d));
2062+
M, endian::readNext<IdentifierID, llvm::endianness::little>(d));
20592063
if (unsigned FrameworkOffset =
20602064
endian::readNext<uint32_t, llvm::endianness::little>(d)) {
20612065
// The framework offset is 1 greater than the actual offset,
@@ -3429,24 +3433,11 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
34293433
"duplicate IDENTIFIER_OFFSET record in AST file");
34303434
F.IdentifierOffsets = (const uint32_t *)Blob.data();
34313435
F.LocalNumIdentifiers = Record[0];
3432-
unsigned LocalBaseIdentifierID = Record[1];
34333436
F.BaseIdentifierID = getTotalNumIdentifiers();
34343437

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)
34473439
IdentifiersLoaded.resize(IdentifiersLoaded.size()
34483440
+ F.LocalNumIdentifiers);
3449-
}
34503441
break;
34513442
}
34523443

@@ -4038,7 +4029,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
40384029
F.ModuleOffsetMap = StringRef();
40394030

40404031
using RemapBuilder = ContinuousRangeMap<uint32_t, int, 2>::Builder;
4041-
RemapBuilder IdentifierRemap(F.IdentifierRemap);
40424032
RemapBuilder MacroRemap(F.MacroRemap);
40434033
RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap);
40444034
RemapBuilder SubmoduleRemap(F.SubmoduleRemap);
@@ -4071,8 +4061,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
40714061

40724062
ImportedModuleVector.push_back(OM);
40734063

4074-
uint32_t IdentifierIDOffset =
4075-
endian::readNext<uint32_t, llvm::endianness::little>(Data);
40764064
uint32_t MacroIDOffset =
40774065
endian::readNext<uint32_t, llvm::endianness::little>(Data);
40784066
uint32_t PreprocessedEntityIDOffset =
@@ -4092,7 +4080,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
40924080
static_cast<int>(BaseOffset - Offset)));
40934081
};
40944082

4095-
mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap);
40964083
mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap);
40974084
mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID,
40984085
PreprocessedEntityRemap);
@@ -8181,7 +8168,6 @@ LLVM_DUMP_METHOD void ASTReader::dump() {
81818168
dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap);
81828169
dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap);
81838170
dumpModuleIDMap("Global type map", GlobalTypeMap);
8184-
dumpModuleIDMap("Global identifier map", GlobalIdentifierMap);
81858171
dumpModuleIDMap("Global macro map", GlobalMacroMap);
81868172
dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap);
81878173
dumpModuleIDMap("Global selector map", GlobalSelectorMap);
@@ -8822,8 +8808,9 @@ void ASTReader::LoadSelector(Selector Sel) {
88228808

88238809
void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) {
88248810
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;
88278814
if (DeserializationListener)
88288815
DeserializationListener->IdentifierRead(ID, II);
88298816
}
@@ -8876,6 +8863,22 @@ void ASTReader::SetGloballyVisibleDecls(
88768863
}
88778864
}
88788865

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+
88798882
IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
88808883
if (ID == 0)
88818884
return nullptr;
@@ -8885,45 +8888,48 @@ IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
88858888
return nullptr;
88868889
}
88878890

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;
88948896
const unsigned char *Data =
8895-
M->IdentifierTableData + M->IdentifierOffsets[Index];
8897+
M->IdentifierTableData + M->IdentifierOffsets[LocalIndex];
88968898

88978899
ASTIdentifierLookupTrait Trait(*this, *M);
88988900
auto KeyDataLen = Trait.ReadKeyDataLength(Data);
88998901
auto Key = Trait.ReadKey(Data, KeyDataLen.first);
89008902
auto &II = PP.getIdentifierTable().get(Key);
8901-
IdentifiersLoaded[ID] = &II;
8903+
IdentifiersLoaded[Index] = &II;
89028904
markIdentifierFromAST(*this, II);
89038905
if (DeserializationListener)
8904-
DeserializationListener->IdentifierRead(ID + 1, &II);
8906+
DeserializationListener->IdentifierRead(ID, &II);
89058907
}
89068908

8907-
return IdentifiersLoaded[ID];
8909+
return IdentifiersLoaded[Index];
89088910
}
89098911

8910-
IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) {
8912+
IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, uint64_t LocalID) {
89118913
return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID));
89128914
}
89138915

8914-
IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) {
8916+
IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, uint64_t LocalID) {
89158917
if (LocalID < NUM_PREDEF_IDENT_IDS)
89168918
return LocalID;
89178919

89188920
if (!M.ModuleOffsetMap.empty())
89198921
ReadModuleOffsetMap(M);
89208922

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?");
89258928

8926-
return LocalID + I->second;
8929+
if (!ModuleFileIndex)
8930+
LocalID -= NUM_PREDEF_IDENT_IDS;
8931+
8932+
return ((IdentifierID)(MF->Index + 1) << 32) | LocalID;
89278933
}
89288934

89298935
MacroInfo *ASTReader::getMacro(MacroID ID) {

0 commit comments

Comments
 (0)