@@ -107,8 +107,6 @@ class CrossModuleOptimization {
107
107
108
108
bool canUseFromInline (SILFunction *func);
109
109
110
- bool shouldSerialize (SILFunction *F);
111
-
112
110
void serializeFunction (SILFunction *function,
113
111
const FunctionFlags &canSerializeFlags);
114
112
@@ -510,10 +508,34 @@ bool CrossModuleOptimization::canSerializeFunction(
510
508
return false ;
511
509
}
512
510
513
- // Ask the heuristic.
514
- if (!shouldSerialize (function))
511
+ if (function->hasSemanticsAttr (" optimize.no.crossmodule" ))
515
512
return false ;
516
513
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
+
517
539
// Check if any instruction prevents serializing the function.
518
540
InstructionVisitor visitor (*function, *this , InstructionVisitor::VisitMode::DetectSerializableInst);
519
541
@@ -767,45 +789,6 @@ bool CrossModuleOptimization::canUseFromInline(SILFunction *function) {
767
789
return true ;
768
790
}
769
791
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
-
809
792
// / Serialize \p function and recursively all referenced functions which are
810
793
// / marked in \p canSerializeFlags.
811
794
void CrossModuleOptimization::serializeFunction (SILFunction *function,
0 commit comments