@@ -1425,10 +1425,9 @@ bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M,
1425
1425
return false;
1426
1426
}
1427
1427
1428
- bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M,
1429
- BitstreamCursor &Cursor,
1430
- uint64_t Offset, GlobalDeclID ID,
1431
- bool IsModuleLocal) {
1428
+ bool ASTReader::ReadVisibleDeclContextStorage(
1429
+ ModuleFile &M, BitstreamCursor &Cursor, uint64_t Offset, GlobalDeclID ID,
1430
+ ASTReader::VisibleDeclContextStorageKind VisibleKind) {
1432
1431
assert(Offset != 0);
1433
1432
1434
1433
SavedStreamPosition SavedPosition(Cursor);
@@ -1452,22 +1451,42 @@ bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M,
1452
1451
return true;
1453
1452
}
1454
1453
unsigned RecCode = MaybeRecCode.get();
1455
- if (!IsModuleLocal && RecCode != DECL_CONTEXT_VISIBLE) {
1456
- Error("Expected visible lookup table block");
1457
- return true;
1458
- }
1459
- if (IsModuleLocal && RecCode != DECL_CONTEXT_MODULE_LOCAL_VISIBLE) {
1460
- Error("Expected module local visible lookup table block");
1461
- return true;
1454
+ switch (VisibleKind) {
1455
+ case VisibleDeclContextStorageKind::GenerallyVisible:
1456
+ if (RecCode != DECL_CONTEXT_VISIBLE) {
1457
+ Error("Expected visible lookup table block");
1458
+ return true;
1459
+ }
1460
+ break;
1461
+ case VisibleDeclContextStorageKind::ModuleLocalVisible:
1462
+ if (RecCode != DECL_CONTEXT_MODULE_LOCAL_VISIBLE) {
1463
+ Error("Expected module local visible lookup table block");
1464
+ return true;
1465
+ }
1466
+ break;
1467
+ case VisibleDeclContextStorageKind::TULocalVisible:
1468
+ if (RecCode != DECL_CONTEXT_TU_LOCAL_VISIBLE) {
1469
+ Error("Expected TU local lookup table block");
1470
+ return true;
1471
+ }
1472
+ break;
1462
1473
}
1463
1474
1464
1475
// We can't safely determine the primary context yet, so delay attaching the
1465
1476
// lookup table until we're done with recursive deserialization.
1466
1477
auto *Data = (const unsigned char*)Blob.data();
1467
- if (!IsModuleLocal)
1478
+ switch (VisibleKind) {
1479
+ case VisibleDeclContextStorageKind::GenerallyVisible:
1468
1480
PendingVisibleUpdates[ID].push_back(UpdateData{&M, Data});
1469
- else
1481
+ break;
1482
+ case VisibleDeclContextStorageKind::ModuleLocalVisible:
1470
1483
PendingModuleLocalVisibleUpdates[ID].push_back(UpdateData{&M, Data});
1484
+ break;
1485
+ case VisibleDeclContextStorageKind::TULocalVisible:
1486
+ if (M.Kind == MK_MainFile)
1487
+ TULocalUpdates[ID].push_back(UpdateData{&M, Data});
1488
+ break;
1489
+ }
1471
1490
return false;
1472
1491
}
1473
1492
@@ -3613,6 +3632,21 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
3613
3632
break;
3614
3633
}
3615
3634
3635
+ case UPDATE_TU_LOCAL_VISIBLE: {
3636
+ if (F.Kind != MK_MainFile)
3637
+ break;
3638
+ unsigned Idx = 0;
3639
+ GlobalDeclID ID = ReadDeclID(F, Record, Idx);
3640
+ auto *Data = (const unsigned char *)Blob.data();
3641
+ TULocalUpdates[ID].push_back(UpdateData{&F, Data});
3642
+ // If we've already loaded the decl, perform the updates when we finish
3643
+ // loading this block.
3644
+ if (Decl *D = GetExistingDecl(ID))
3645
+ PendingUpdateRecords.push_back(
3646
+ PendingUpdateRecord(ID, D, /*JustLoaded=*/false));
3647
+ break;
3648
+ }
3649
+
3616
3650
case CXX_ADDED_TEMPLATE_SPECIALIZATION: {
3617
3651
unsigned Idx = 0;
3618
3652
GlobalDeclID ID = ReadDeclID(F, Record, Idx);
@@ -3717,6 +3751,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
3717
3751
TotalLexicalDeclContexts += Record[2];
3718
3752
TotalVisibleDeclContexts += Record[3];
3719
3753
TotalModuleLocalVisibleDeclContexts += Record[4];
3754
+ TotalTULocalVisibleDeclContexts += Record[5];
3720
3755
break;
3721
3756
3722
3757
case UNUSED_FILESCOPED_DECLS:
@@ -4002,7 +4037,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
4002
4037
break;
4003
4038
4004
4039
case DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD: {
4005
- if (Record.size() % 4 != 0)
4040
+ if (Record.size() % 5 != 0)
4006
4041
return llvm::createStringError(
4007
4042
std::errc::illegal_byte_sequence,
4008
4043
"invalid DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD block in AST "
@@ -4021,9 +4056,12 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
4021
4056
uint64_t LocalModuleLocalOffset = Record[I++];
4022
4057
uint64_t ModuleLocalOffset =
4023
4058
LocalModuleLocalOffset ? BaseOffset + LocalModuleLocalOffset : 0;
4059
+ uint64_t TULocalLocalOffset = Record[I++];
4060
+ uint64_t TULocalOffset =
4061
+ TULocalLocalOffset ? BaseOffset + TULocalLocalOffset : 0;
4024
4062
4025
4063
DelayedNamespaceOffsetMap[ID] = {LexicalOffset, VisibleOffset,
4026
- ModuleLocalOffset};
4064
+ ModuleLocalOffset, TULocalOffset };
4027
4065
4028
4066
assert(!GetExistingDecl(ID) &&
4029
4067
"We shouldn't load the namespace in the front of delayed "
@@ -8473,6 +8511,15 @@ bool ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC,
8473
8511
}
8474
8512
}
8475
8513
8514
+ if (auto It = TULocalLookups.find(DC); It != TULocalLookups.end()) {
8515
+ ++NumTULocalVisibleDeclContexts;
8516
+ for (GlobalDeclID ID : It->second.Table.find(Name)) {
8517
+ NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
8518
+ if (ND->getDeclName() == Name && Found.insert(ND).second)
8519
+ Decls.push_back(ND);
8520
+ }
8521
+ }
8522
+
8476
8523
SetExternalVisibleDeclsForName(DC, Name, Decls);
8477
8524
return !Decls.empty();
8478
8525
}
@@ -8500,6 +8547,7 @@ void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) {
8500
8547
8501
8548
findAll(Lookups, NumVisibleDeclContextsRead);
8502
8549
findAll(ModuleLocalLookups, NumModuleLocalVisibleDeclContexts);
8550
+ findAll(TULocalLookups, NumTULocalVisibleDeclContexts);
8503
8551
8504
8552
for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
8505
8553
SetExternalVisibleDeclsForName(DC, I->first, I->second);
@@ -8519,6 +8567,12 @@ ASTReader::getModuleLocalLookupTables(DeclContext *Primary) const {
8519
8567
return I == ModuleLocalLookups.end() ? nullptr : &I->second;
8520
8568
}
8521
8569
8570
+ const serialization::reader::DeclContextLookupTable *
8571
+ ASTReader::getTULocalLookupTables(DeclContext *Primary) const {
8572
+ auto I = TULocalLookups.find(Primary);
8573
+ return I == TULocalLookups.end() ? nullptr : &I->second;
8574
+ }
8575
+
8522
8576
serialization::reader::LazySpecializationInfoLookupTable *
8523
8577
ASTReader::getLoadedSpecializationsLookupTables(const Decl *D, bool IsPartial) {
8524
8578
assert(D->isCanonicalDecl());
@@ -8634,6 +8688,11 @@ void ASTReader::PrintStats() {
8634
8688
NumModuleLocalVisibleDeclContexts, TotalModuleLocalVisibleDeclContexts,
8635
8689
((float)NumModuleLocalVisibleDeclContexts /
8636
8690
TotalModuleLocalVisibleDeclContexts * 100));
8691
+ if (TotalTULocalVisibleDeclContexts)
8692
+ std::fprintf(stderr, " %u/%u visible declcontexts in GMF read (%f%%)\n",
8693
+ NumTULocalVisibleDeclContexts, TotalTULocalVisibleDeclContexts,
8694
+ ((float)NumTULocalVisibleDeclContexts /
8695
+ TotalTULocalVisibleDeclContexts * 100));
8637
8696
if (TotalNumMethodPoolEntries)
8638
8697
std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n",
8639
8698
NumMethodPoolEntriesRead, TotalNumMethodPoolEntries,
0 commit comments