@@ -315,8 +315,7 @@ namespace {
315315 << " for layout " << Layout::Code << " \n " );
316316 }
317317
318- bool ShouldSerializeAll;
319- bool SerializeDebugInfoSIL;
318+ const SerializationOptions &Options;
320319
321320 void addMandatorySILFunction (const SILFunction *F,
322321 bool emitDeclarationsForOnoneSupport);
@@ -399,10 +398,9 @@ namespace {
399398 IdentifierID addSILFunctionRef (SILFunction *F);
400399
401400 public:
402- SILSerializer (Serializer &S, llvm::BitstreamWriter &Out, bool serializeAll,
403- bool serializeDebugInfo)
404- : S(S), Out(Out), ShouldSerializeAll(serializeAll),
405- SerializeDebugInfoSIL (serializeDebugInfo) {}
401+ SILSerializer (Serializer &S, llvm::BitstreamWriter &Out,
402+ const SerializationOptions &options)
403+ : S(S), Out(Out), Options(options) {}
406404
407405 void writeSILModule (const SILModule *SILMod);
408406 };
@@ -544,7 +542,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
544542 // Otherwise, the generic specializer fails to remap references to functions
545543 // in debug scopes to their specialized versions which breaks IRGen.
546544 // TODO: add an assertion in IRGen when the specializer fails to remap.
547- if (!NoBody || SerializeDebugInfoSIL)
545+ if (!NoBody || Options. SerializeDebugInfoSIL )
548546 if (auto *genericEnv = F.getGenericEnvironment ())
549547 genericSigID = S.addGenericSignatureRef (genericEnv->getGenericSignature ());
550548
@@ -691,7 +689,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
691689 DebugScopeMap.clear ();
692690 SourceLocMap.clear ();
693691
694- if (SerializeDebugInfoSIL)
692+ if (Options. SerializeDebugInfoSIL )
695693 writeDebugScopes (F.getDebugScope (), F.getModule ().getSourceManager ());
696694 // Assign a unique ID to each basic block of the SILFunction.
697695 unsigned BasicID = 0 ;
@@ -781,13 +779,13 @@ void SILSerializer::writeSILBasicBlock(const SILBasicBlock &BB) {
781779 const SILDebugScope *Prev = nullptr ;
782780 auto &SM = BB.getParent ()->getModule ().getSourceManager ();
783781 for (const SILInstruction &SI : BB) {
784- if (SerializeDebugInfoSIL) {
782+ if (Options. SerializeDebugInfoSIL ) {
785783 if (SI.getDebugScope () != Prev) {
786784 Prev = SI.getDebugScope ();
787785 writeDebugScopes (Prev, SM);
788786 }
789787 }
790- if (SerializeDebugInfoSIL) {
788+ if (Options. SerializeDebugInfoSIL ) {
791789 writeSourceLoc (SI.getLoc (), SM);
792790 }
793791
@@ -1060,7 +1058,7 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
10601058 }
10611059
10621060 case SILInstructionKind::DebugValueInst: {
1063- if (!SerializeDebugInfoSIL)
1061+ if (!Options. SerializeDebugInfoSIL )
10641062 return ;
10651063 auto DVI = cast<DebugValueInst>(&SI);
10661064 unsigned attrs = unsigned (DVI->poisonRefs () & 0x1 );
@@ -3287,7 +3285,7 @@ void SILSerializer::writeSILGlobalVar(const SILGlobalVariable &g) {
32873285void SILSerializer::writeSILVTable (const SILVTable &vt) {
32883286 // Do not emit vtables for non-public classes unless everything has to be
32893287 // serialized.
3290- if (!ShouldSerializeAll &&
3288+ if (!Options. SerializeAllSIL &&
32913289 vt.getClass ()->getEffectiveAccess () < swift::AccessLevel::Package)
32923290 return ;
32933291
@@ -3313,7 +3311,7 @@ void SILSerializer::writeSILVTable(const SILVTable &vt) {
33133311 SmallVector<uint64_t , 4 > ListOfValues;
33143312 SILFunction *impl = entry.getImplementation ();
33153313
3316- if (ShouldSerializeAll ||
3314+ if (Options. SerializeAllSIL ||
33173315 (vt.isAnySerialized () &&
33183316 impl->hasValidLinkageForFragileRef (vt.getSerializedKind ()))) {
33193317 handleSILDeclRef (S, entry.getMethod (), ListOfValues);
@@ -3333,12 +3331,12 @@ void SILSerializer::writeSILVTable(const SILVTable &vt) {
33333331void SILSerializer::writeSILMoveOnlyDeinit (const SILMoveOnlyDeinit &deinit) {
33343332 // Do not emit deinit for non-public nominal types unless everything has to be
33353333 // serialized.
3336- if (!ShouldSerializeAll && deinit.getNominalDecl ()->getEffectiveAccess () <
3334+ if (!Options. SerializeAllSIL && deinit.getNominalDecl ()->getEffectiveAccess () <
33373335 swift::AccessLevel::Package)
33383336 return ;
33393337
33403338 SILFunction *impl = deinit.getImplementation ();
3341- if (!ShouldSerializeAll &&
3339+ if (!Options. SerializeAllSIL &&
33423340 // Package CMO for MoveOnlyDeinit is not supported so
33433341 // pass the IsSerialized argument to keep the behavior
33443342 // consistent with or without the optimization.
@@ -3734,7 +3732,7 @@ bool SILSerializer::shouldEmitFunctionBody(const SILFunction *F,
37343732 }
37353733
37363734 // If we are asked to serialize everything, go ahead and do it.
3737- if (ShouldSerializeAll )
3735+ if (Options. SerializeAllSIL )
37383736 return true ;
37393737
37403738 // If F is serialized, we should always emit its body.
@@ -3814,29 +3812,29 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) {
38143812 // serialize everything.
38153813 // FIXME: Resilience: could write out vtable for fragile classes.
38163814 for (const auto &vt : SILMod->getVTables ()) {
3817- if ((ShouldSerializeAll || vt->isAnySerialized ()) &&
3815+ if ((Options. SerializeAllSIL || vt->isAnySerialized ()) &&
38183816 SILMod->shouldSerializeEntitiesAssociatedWithDeclContext (vt->getClass ()))
38193817 writeSILVTable (*vt);
38203818 }
38213819
38223820 for (const auto &deinit : SILMod->getMoveOnlyDeinits ()) {
3823- if ((ShouldSerializeAll || deinit->isAnySerialized ()) &&
3821+ if ((Options. SerializeAllSIL || deinit->isAnySerialized ()) &&
38243822 SILMod->shouldSerializeEntitiesAssociatedWithDeclContext (
38253823 deinit->getNominalDecl ()))
38263824 writeSILMoveOnlyDeinit (*deinit);
38273825 }
38283826
38293827 // Write out property descriptors.
38303828 for (const SILProperty &prop : SILMod->getPropertyList ()) {
3831- if ((ShouldSerializeAll || prop.isAnySerialized ()) &&
3829+ if ((Options. SerializeAllSIL || prop.isAnySerialized ()) &&
38323830 SILMod->shouldSerializeEntitiesAssociatedWithDeclContext (
38333831 prop.getDecl ()->getInnermostDeclContext ()))
38343832 writeSILProperty (prop);
38353833 }
38363834
38373835 // Write out fragile WitnessTables.
38383836 for (const SILWitnessTable &wt : SILMod->getWitnessTables ()) {
3839- if ((ShouldSerializeAll || wt.isAnySerialized ()) &&
3837+ if ((Options. SerializeAllSIL || wt.isAnySerialized ()) &&
38403838 SILMod->shouldSerializeEntitiesAssociatedWithDeclContext (
38413839 wt.getConformance ()->getDeclContext ()))
38423840 writeSILWitnessTable (wt);
@@ -3860,7 +3858,7 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) {
38603858
38613859 // Add global variables that must be emitted to the list.
38623860 for (const SILGlobalVariable &g : SILMod->getSILGlobals ()) {
3863- if (g.isAnySerialized () || ShouldSerializeAll )
3861+ if (g.isAnySerialized () || Options. SerializeAllSIL )
38643862 addReferencedGlobalVariable (&g);
38653863 }
38663864
@@ -3894,7 +3892,7 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) {
38943892 // TODO(TF-893): Consider checking
38953893 // `SILMod->shouldSerializeEntitiesAssociatedWithDeclContext` on the JVP/VJP
38963894 // functions.
3897- if ((ShouldSerializeAll || diffWitness.isSerialized ()))
3895+ if ((Options. SerializeAllSIL || diffWitness.isSerialized ()))
38983896 DifferentiabilityWitnessesToEmit.insert (&diffWitness);
38993897 }
39003898 for (auto *diffWitness : DifferentiabilityWitnessesToEmit)
@@ -3945,11 +3943,10 @@ void SILSerializer::writeSILModule(const SILModule *SILMod) {
39453943 writeIndexTables ();
39463944}
39473945
3948- void Serializer::writeSIL (const SILModule *SILMod, bool serializeAllSIL,
3949- bool serializeDebugInfo) {
3946+ void Serializer::writeSIL (const SILModule *SILMod) {
39503947 if (!SILMod)
39513948 return ;
39523949
3953- SILSerializer SILSer (*this , Out, serializeAllSIL, serializeDebugInfo );
3950+ SILSerializer SILSer (*this , Out, Options );
39543951 SILSer.writeSILModule (SILMod);
39553952}
0 commit comments