@@ -3355,20 +3355,11 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
3355
3355
" duplicate TYPE_OFFSET record in AST file" );
3356
3356
F.TypeOffsets = reinterpret_cast <const UnalignedUInt64 *>(Blob.data ());
3357
3357
F.LocalNumTypes = Record[0 ];
3358
- unsigned LocalBaseTypeIndex = Record[1 ];
3359
3358
F.BaseTypeIndex = getTotalNumTypes ();
3360
3359
3361
- if (F.LocalNumTypes > 0 ) {
3362
- // Introduce the global -> local mapping for types within this module.
3363
- GlobalTypeMap.insert (std::make_pair (getTotalNumTypes (), &F));
3364
-
3365
- // Introduce the local -> global mapping for types within this module.
3366
- F.TypeRemap .insertOrReplace (
3367
- std::make_pair (LocalBaseTypeIndex,
3368
- F.BaseTypeIndex - LocalBaseTypeIndex));
3369
-
3360
+ if (F.LocalNumTypes > 0 )
3370
3361
TypesLoaded.resize (TypesLoaded.size () + F.LocalNumTypes );
3371
- }
3362
+
3372
3363
break ;
3373
3364
}
3374
3365
@@ -4031,7 +4022,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4031
4022
RemapBuilder PreprocessedEntityRemap (F.PreprocessedEntityRemap );
4032
4023
RemapBuilder SubmoduleRemap (F.SubmoduleRemap );
4033
4024
RemapBuilder SelectorRemap (F.SelectorRemap );
4034
- RemapBuilder TypeRemap (F.TypeRemap );
4035
4025
4036
4026
auto &ImportedModuleVector = F.TransitiveImports ;
4037
4027
assert (ImportedModuleVector.empty ());
@@ -4067,8 +4057,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4067
4057
endian::readNext<uint32_t , llvm::endianness::little>(Data);
4068
4058
uint32_t SelectorIDOffset =
4069
4059
endian::readNext<uint32_t , llvm::endianness::little>(Data);
4070
- uint32_t TypeIndexOffset =
4071
- endian::readNext<uint32_t , llvm::endianness::little>(Data);
4072
4060
4073
4061
auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset,
4074
4062
RemapBuilder &Remap) {
@@ -4083,7 +4071,6 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
4083
4071
PreprocessedEntityRemap);
4084
4072
mapOffset (SubmoduleIDOffset, OM->BaseSubmoduleID , SubmoduleRemap);
4085
4073
mapOffset (SelectorIDOffset, OM->BaseSelectorID , SelectorRemap);
4086
- mapOffset (TypeIndexOffset, OM->BaseTypeIndex , TypeRemap);
4087
4074
}
4088
4075
}
4089
4076
@@ -5062,12 +5049,12 @@ void ASTReader::InitializeContext() {
5062
5049
5063
5050
// Load the special types.
5064
5051
if (SpecialTypes.size () >= NumSpecialTypeIDs) {
5065
- if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
5052
+ if (TypeID String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
5066
5053
if (!Context.CFConstantStringTypeDecl )
5067
5054
Context.setCFConstantStringType (GetType (String));
5068
5055
}
5069
5056
5070
- if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) {
5057
+ if (TypeID File = SpecialTypes[SPECIAL_TYPE_FILE]) {
5071
5058
QualType FileType = GetType (File);
5072
5059
if (FileType.isNull ()) {
5073
5060
Error (" FILE type is NULL" );
@@ -5088,7 +5075,7 @@ void ASTReader::InitializeContext() {
5088
5075
}
5089
5076
}
5090
5077
5091
- if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) {
5078
+ if (TypeID Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) {
5092
5079
QualType Jmp_bufType = GetType (Jmp_buf);
5093
5080
if (Jmp_bufType.isNull ()) {
5094
5081
Error (" jmp_buf type is NULL" );
@@ -5109,7 +5096,7 @@ void ASTReader::InitializeContext() {
5109
5096
}
5110
5097
}
5111
5098
5112
- if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) {
5099
+ if (TypeID Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) {
5113
5100
QualType Sigjmp_bufType = GetType (Sigjmp_buf);
5114
5101
if (Sigjmp_bufType.isNull ()) {
5115
5102
Error (" sigjmp_buf type is NULL" );
@@ -5127,25 +5114,24 @@ void ASTReader::InitializeContext() {
5127
5114
}
5128
5115
}
5129
5116
5130
- if (unsigned ObjCIdRedef
5131
- = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) {
5117
+ if (TypeID ObjCIdRedef = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) {
5132
5118
if (Context.ObjCIdRedefinitionType .isNull ())
5133
5119
Context.ObjCIdRedefinitionType = GetType (ObjCIdRedef);
5134
5120
}
5135
5121
5136
- if (unsigned ObjCClassRedef
5137
- = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) {
5122
+ if (TypeID ObjCClassRedef =
5123
+ SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) {
5138
5124
if (Context.ObjCClassRedefinitionType .isNull ())
5139
5125
Context.ObjCClassRedefinitionType = GetType (ObjCClassRedef);
5140
5126
}
5141
5127
5142
- if (unsigned ObjCSelRedef
5143
- = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) {
5128
+ if (TypeID ObjCSelRedef =
5129
+ SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) {
5144
5130
if (Context.ObjCSelRedefinitionType .isNull ())
5145
5131
Context.ObjCSelRedefinitionType = GetType (ObjCSelRedef);
5146
5132
}
5147
5133
5148
- if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) {
5134
+ if (TypeID Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) {
5149
5135
QualType Ucontext_tType = GetType (Ucontext_t);
5150
5136
if (Ucontext_tType.isNull ()) {
5151
5137
Error (" ucontext_t type is NULL" );
@@ -6630,10 +6616,8 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) {
6630
6616
}
6631
6617
6632
6618
// / Get the correct cursor and offset for loading a type.
6633
- ASTReader::RecordLocation ASTReader::TypeCursorForIndex (unsigned Index) {
6634
- GlobalTypeMapType::iterator I = GlobalTypeMap.find (Index);
6635
- assert (I != GlobalTypeMap.end () && " Corrupted global type map" );
6636
- ModuleFile *M = I->second ;
6619
+ ASTReader::RecordLocation ASTReader::TypeCursorForIndex (TypeID ID) {
6620
+ auto [M, Index] = translateTypeIDToIndex (ID);
6637
6621
return RecordLocation (M, M->TypeOffsets [Index - M->BaseTypeIndex ].get () +
6638
6622
M->DeclsBlockStartOffset );
6639
6623
}
@@ -6654,10 +6638,10 @@ static std::optional<Type::TypeClass> getTypeClassForCode(TypeCode code) {
6654
6638
// / routine actually reads the record corresponding to the type at the given
6655
6639
// / location. It is a helper routine for GetType, which deals with reading type
6656
6640
// / IDs.
6657
- QualType ASTReader::readTypeRecord (unsigned Index ) {
6641
+ QualType ASTReader::readTypeRecord (TypeID ID ) {
6658
6642
assert (ContextObj && " reading type with no AST context" );
6659
6643
ASTContext &Context = *ContextObj;
6660
- RecordLocation Loc = TypeCursorForIndex (Index );
6644
+ RecordLocation Loc = TypeCursorForIndex (ID );
6661
6645
BitstreamCursor &DeclsCursor = Loc.F ->DeclsCursor ;
6662
6646
6663
6647
// Keep track of where we are in the stream, then jump back there
@@ -7098,14 +7082,25 @@ TypeSourceInfo *ASTRecordReader::readTypeSourceInfo() {
7098
7082
return TInfo;
7099
7083
}
7100
7084
7085
+ std::pair<ModuleFile *, unsigned >
7086
+ ASTReader::translateTypeIDToIndex (serialization::TypeID ID) const {
7087
+ unsigned Index =
7088
+ (ID & llvm::maskTrailingOnes<TypeID>(32 )) >> Qualifiers::FastWidth;
7089
+
7090
+ ModuleFile *OwningModuleFile = getOwningModuleFile (ID);
7091
+ assert (OwningModuleFile &&
7092
+ " untranslated type ID or local type ID shouldn't be in TypesLoaded" );
7093
+ return {OwningModuleFile, OwningModuleFile->BaseTypeIndex + Index};
7094
+ }
7095
+
7101
7096
QualType ASTReader::GetType (TypeID ID) {
7102
7097
assert (ContextObj && " reading type with no AST context" );
7103
7098
ASTContext &Context = *ContextObj;
7104
7099
7105
7100
unsigned FastQuals = ID & Qualifiers::FastMask;
7106
- unsigned Index = ID >> Qualifiers::FastWidth;
7107
7101
7108
- if (Index < NUM_PREDEF_TYPE_IDS) {
7102
+ if (uint64_t Index = ID >> Qualifiers::FastWidth;
7103
+ Index < NUM_PREDEF_TYPE_IDS) {
7109
7104
QualType T;
7110
7105
switch ((PredefinedTypeIDs)Index) {
7111
7106
case PREDEF_TYPE_LAST_ID:
@@ -7374,10 +7369,11 @@ QualType ASTReader::GetType(TypeID ID) {
7374
7369
return T.withFastQualifiers (FastQuals);
7375
7370
}
7376
7371
7377
- Index -= NUM_PREDEF_TYPE_IDS;
7372
+ unsigned Index = translateTypeIDToIndex (ID).second ;
7373
+
7378
7374
assert (Index < TypesLoaded.size () && " Type index out-of-range" );
7379
7375
if (TypesLoaded[Index].isNull ()) {
7380
- TypesLoaded[Index] = readTypeRecord (Index );
7376
+ TypesLoaded[Index] = readTypeRecord (ID );
7381
7377
if (TypesLoaded[Index].isNull ())
7382
7378
return QualType ();
7383
7379
@@ -7390,27 +7386,28 @@ QualType ASTReader::GetType(TypeID ID) {
7390
7386
return TypesLoaded[Index].withFastQualifiers (FastQuals);
7391
7387
}
7392
7388
7393
- QualType ASTReader::getLocalType (ModuleFile &F, unsigned LocalID) {
7389
+ QualType ASTReader::getLocalType (ModuleFile &F, TypeID LocalID) {
7394
7390
return GetType (getGlobalTypeID (F, LocalID));
7395
7391
}
7396
7392
7397
- serialization::TypeID
7398
- ASTReader::getGlobalTypeID (ModuleFile &F, unsigned LocalID) const {
7399
- unsigned FastQuals = LocalID & Qualifiers::FastMask;
7400
- unsigned LocalIndex = LocalID >> Qualifiers::FastWidth;
7401
-
7402
- if (LocalIndex < NUM_PREDEF_TYPE_IDS)
7393
+ serialization::TypeID ASTReader::getGlobalTypeID (ModuleFile &F,
7394
+ TypeID LocalID) const {
7395
+ if ((LocalID >> Qualifiers::FastWidth) < NUM_PREDEF_TYPE_IDS)
7403
7396
return LocalID;
7404
7397
7405
7398
if (!F.ModuleOffsetMap .empty ())
7406
7399
ReadModuleOffsetMap (F);
7407
7400
7408
- ContinuousRangeMap<uint32_t , int , 2 >::iterator I
7409
- = F.TypeRemap .find (LocalIndex - NUM_PREDEF_TYPE_IDS);
7410
- assert (I != F.TypeRemap .end () && " Invalid index into type index remap" );
7401
+ unsigned ModuleFileIndex = LocalID >> 32 ;
7402
+ LocalID &= llvm::maskTrailingOnes<TypeID>(32 );
7411
7403
7412
- unsigned GlobalIndex = LocalIndex + I->second ;
7413
- return (GlobalIndex << Qualifiers::FastWidth) | FastQuals;
7404
+ if (ModuleFileIndex == 0 )
7405
+ LocalID -= NUM_PREDEF_TYPE_IDS << Qualifiers::FastWidth;
7406
+
7407
+ ModuleFile &MF =
7408
+ ModuleFileIndex ? *F.TransitiveImports [ModuleFileIndex - 1 ] : F;
7409
+ ModuleFileIndex = MF.Index + 1 ;
7410
+ return ((uint64_t )ModuleFileIndex << 32 ) | LocalID;
7414
7411
}
7415
7412
7416
7413
TemplateArgumentLocInfo
@@ -7648,6 +7645,16 @@ ModuleFile *ASTReader::getOwningModuleFile(GlobalDeclID ID) const {
7648
7645
return &getModuleManager ()[ModuleFileIndex - 1 ];
7649
7646
}
7650
7647
7648
+ ModuleFile *ASTReader::getOwningModuleFile (TypeID ID) const {
7649
+ if (ID < NUM_PREDEF_TYPE_IDS)
7650
+ return nullptr ;
7651
+
7652
+ uint64_t ModuleFileIndex = ID >> 32 ;
7653
+ assert (ModuleFileIndex && " Untranslated Local Decl?" );
7654
+
7655
+ return &getModuleManager ()[ModuleFileIndex - 1 ];
7656
+ }
7657
+
7651
7658
ModuleFile *ASTReader::getOwningModuleFile (const Decl *D) const {
7652
7659
if (!D->isFromASTFile ())
7653
7660
return nullptr ;
@@ -8165,7 +8172,6 @@ LLVM_DUMP_METHOD void ASTReader::dump() {
8165
8172
llvm::errs () << " *** PCH/ModuleFile Remappings:\n " ;
8166
8173
dumpModuleIDMap (" Global bit offset map" , GlobalBitOffsetsMap);
8167
8174
dumpModuleIDMap (" Global source location entry map" , GlobalSLocEntryMap);
8168
- dumpModuleIDMap (" Global type map" , GlobalTypeMap);
8169
8175
dumpModuleIDMap (" Global macro map" , GlobalMacroMap);
8170
8176
dumpModuleIDMap (" Global submodule map" , GlobalSubmoduleMap);
8171
8177
dumpModuleIDMap (" Global selector map" , GlobalSelectorMap);
0 commit comments