@@ -941,6 +941,7 @@ void ASTWriter::WriteBlockInfoBlock() {
941941 RECORD (PP_ASSUME_NONNULL_LOC);
942942 RECORD (PP_UNSAFE_BUFFER_USAGE);
943943 RECORD (VTABLES_TO_EMIT);
944+ RECORD (AVAILABILITY_DOMAIN_TABLE);
944945
945946 // SourceManager Block.
946947 BLOCK (SOURCE_MANAGER_BLOCK);
@@ -3392,6 +3393,76 @@ uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context,
33923393 return Offset;
33933394}
33943395
3396+ namespace {
3397+ class AvailabilityDomainsTableTrait {
3398+ public:
3399+ using key_type = StringRef;
3400+ using key_type_ref = key_type;
3401+ using data_type = clang::serialization::DeclID;
3402+ using data_type_ref = const data_type &;
3403+ using hash_value_type = uint32_t ;
3404+ using offset_type = unsigned ;
3405+
3406+ hash_value_type ComputeHash (key_type_ref Key) { return llvm::djbHash (Key); }
3407+
3408+ std::pair<unsigned , unsigned >
3409+ EmitKeyDataLength (raw_ostream &Out, key_type_ref Key, data_type_ref) {
3410+ uint32_t KeyLength = Key.size ();
3411+ uint32_t DataLength = sizeof (data_type);
3412+
3413+ llvm::support::endian::Writer Writer (Out, llvm::endianness::little);
3414+ Writer.write <uint16_t >(KeyLength);
3415+ Writer.write <uint16_t >(DataLength);
3416+ return {KeyLength, DataLength};
3417+ }
3418+
3419+ void EmitKey (raw_ostream &Out, key_type_ref Key, unsigned ) { Out << Key; }
3420+
3421+ void EmitData (raw_ostream &Out, key_type_ref, data_type_ref Data, unsigned ) {
3422+ llvm::support::endian::Writer writer (Out, llvm::endianness::little);
3423+ writer.write <data_type>(Data);
3424+ }
3425+ };
3426+ } // namespace
3427+
3428+ void ASTWriter::writeAvailabilityDomainDecls (ASTContext &Context) {
3429+ using namespace llvm ;
3430+ if (Context.AvailabilityDomainMap .empty ())
3431+ return ;
3432+
3433+ AvailabilityDomainsTableTrait GeneratorTrait;
3434+ llvm::OnDiskChainedHashTableGenerator<AvailabilityDomainsTableTrait>
3435+ Generator;
3436+
3437+ for (auto &P : Context.AvailabilityDomainMap )
3438+ Generator.insert (P.first , GetDeclRef (P.second ).getRawValue (),
3439+ GeneratorTrait);
3440+
3441+ // Create the on-disk hash table in a buffer.
3442+ SmallString<4096 > AvailDomainTable;
3443+ uint32_t BucketOffset;
3444+ {
3445+ using namespace llvm ::support;
3446+ llvm::raw_svector_ostream Out (AvailDomainTable);
3447+ // Make sure that no bucket is at offset 0
3448+ endian::write<uint32_t >(Out, 0 , llvm::endianness::little);
3449+ BucketOffset = Generator.Emit (Out, GeneratorTrait);
3450+ }
3451+
3452+ // Create a blob abbreviation.
3453+ auto Abbrev = std::make_shared<BitCodeAbbrev>();
3454+ Abbrev->Add (BitCodeAbbrevOp (AVAILABILITY_DOMAIN_TABLE));
3455+ Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Fixed, 32 ));
3456+ Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Blob));
3457+ unsigned MethodPoolAbbrev = Stream.EmitAbbrev (std::move (Abbrev));
3458+
3459+ // Write the table.
3460+ {
3461+ RecordData::value_type Record[] = {AVAILABILITY_DOMAIN_TABLE, BucketOffset};
3462+ Stream.EmitRecordWithBlob (MethodPoolAbbrev, Record, AvailDomainTable);
3463+ }
3464+ }
3465+
33953466void ASTWriter::WriteTypeDeclOffsets () {
33963467 using namespace llvm ;
33973468
@@ -5798,6 +5869,8 @@ void ASTWriter::WriteDeclAndTypes(ASTContext &Context) {
57985869 // Write the visible updates to DeclContexts.
57995870 for (auto *DC : UpdatedDeclContexts)
58005871 WriteDeclContextVisibleUpdate (Context, DC);
5872+
5873+ writeAvailabilityDomainDecls (Context);
58015874}
58025875
58035876void ASTWriter::WriteDeclUpdatesBlocks (ASTContext &Context,
0 commit comments