@@ -107,8 +107,6 @@ class CrossModuleOptimization {
107107
108108 bool canUseFromInline (SILFunction *func);
109109
110- bool shouldSerialize (SILFunction *F);
111-
112110 void serializeFunction (SILFunction *function,
113111 const FunctionFlags &canSerializeFlags);
114112
@@ -510,10 +508,34 @@ bool CrossModuleOptimization::canSerializeFunction(
510508 return false ;
511509 }
512510
513- // Ask the heuristic.
514- if (!shouldSerialize (function))
511+ if (function->hasSemanticsAttr (" optimize.no.crossmodule" ))
515512 return false ;
516513
514+ // If package-cmo is enabled, we don't want to limit inlining
515+ // or should at least increase the size limit.
516+ bool skipSizeLimitCheck = isPackageCMOEnabled (M.getSwiftModule ());
517+
518+ if (!conservative) {
519+ // The basic heuristic: serialize all generic functions, because it makes a
520+ // huge difference if generic functions can be specialized or not.
521+ if (function->getLoweredFunctionType ()->isPolymorphic ())
522+ skipSizeLimitCheck = true ;
523+ if (function->getLinkage () == SILLinkage::Shared)
524+ skipSizeLimitCheck = true ;
525+ }
526+
527+ if (!skipSizeLimitCheck) {
528+ // Also serialize "small" non-generic functions.
529+ int size = 0 ;
530+ for (SILBasicBlock &block : *function) {
531+ for (SILInstruction &inst : block) {
532+ size += (int )instructionInlineCost (inst);
533+ if (size >= CMOFunctionSizeLimit)
534+ return false ;
535+ }
536+ }
537+ }
538+
517539 // Check if any instruction prevents serializing the function.
518540 InstructionVisitor visitor (*function, *this , InstructionVisitor::VisitMode::DetectSerializableInst);
519541
@@ -767,45 +789,6 @@ bool CrossModuleOptimization::canUseFromInline(SILFunction *function) {
767789 return true ;
768790}
769791
770- // / Decide whether to serialize a function.
771- bool CrossModuleOptimization::shouldSerialize (SILFunction *function) {
772- // Check if we already handled this function before.
773- if (isSerializedWithRightKind (M, function))
774- return false ;
775-
776- if (everything)
777- return true ;
778-
779- if (function->hasSemanticsAttr (" optimize.no.crossmodule" ))
780- return false ;
781-
782- if (!conservative) {
783- // The basic heuristic: serialize all generic functions, because it makes a
784- // huge difference if generic functions can be specialized or not.
785- if (function->getLoweredFunctionType ()->isPolymorphic ())
786- return true ;
787-
788- if (function->getLinkage () == SILLinkage::Shared)
789- return true ;
790- }
791-
792- // If package-cmo is enabled, we don't want to limit inlining
793- // or should at least increase the cap.
794- if (!M.getSwiftModule ()->serializePackageEnabled ()) {
795- // Also serialize "small" non-generic functions.
796- int size = 0 ;
797- for (SILBasicBlock &block : *function) {
798- for (SILInstruction &inst : block) {
799- size += (int )instructionInlineCost (inst);
800- if (size >= CMOFunctionSizeLimit)
801- return false ;
802- }
803- }
804- }
805-
806- return true ;
807- }
808-
809792// / Serialize \p function and recursively all referenced functions which are
810793// / marked in \p canSerializeFlags.
811794void CrossModuleOptimization::serializeFunction (SILFunction *function,
0 commit comments