@@ -60,15 +60,11 @@ class CrossModuleOptimization {
6060 // / avoid code size increase.
6161 bool conservative;
6262
63- // / True if CMO should serialize literally everything in the module,
64- // / regardless of linkage.
65- bool everything;
66-
6763 typedef llvm::DenseMap<SILFunction *, bool > FunctionFlags;
6864
6965public:
70- CrossModuleOptimization (SILModule &M, bool conservative, bool everything )
71- : M(M), conservative(conservative), everything(everything) { }
66+ CrossModuleOptimization (SILModule &M, bool conservative)
67+ : M(M), conservative(conservative) { }
7268
7369 void serializeFunctionsInModule ();
7470
@@ -168,10 +164,9 @@ void CrossModuleOptimization::serializeFunctionsInModule() {
168164
169165 // Start with public functions.
170166 for (SILFunction &F : M) {
171- if (F.getLinkage () == SILLinkage::Public || everything ) {
172- if (canSerializeFunction (&F, canSerializeFlags, /* maxDepth*/ 64 )) {
167+ if (F.getLinkage () == SILLinkage::Public) {
168+ if (canSerializeFunction (&F, canSerializeFlags, /* maxDepth*/ 64 ))
173169 serializeFunction (&F, canSerializeFlags);
174- }
175170 }
176171 }
177172}
@@ -194,11 +189,6 @@ bool CrossModuleOptimization::canSerializeFunction(
194189 // it to true at the end of this function.
195190 canSerializeFlags[function] = false ;
196191
197- if (everything) {
198- canSerializeFlags[function] = true ;
199- return true ;
200- }
201-
202192 if (DeclContext *funcCtxt = function->getDeclContext ()) {
203193 if (!canUseFromInline (funcCtxt))
204194 return false ;
@@ -402,9 +392,6 @@ static bool couldBeLinkedStatically(DeclContext *funcCtxt, SILModule &module) {
402392
403393// / Returns true if the \p declCtxt can be used from a serialized function.
404394bool CrossModuleOptimization::canUseFromInline (DeclContext *declCtxt) {
405- if (everything)
406- return true ;
407-
408395 if (!M.getSwiftModule ()->canBeUsedForCrossModuleOptimization (declCtxt))
409396 return false ;
410397
@@ -423,9 +410,6 @@ bool CrossModuleOptimization::canUseFromInline(DeclContext *declCtxt) {
423410
424411// / Returns true if the function \p func can be used from a serialized function.
425412bool CrossModuleOptimization::canUseFromInline (SILFunction *function) {
426- if (everything)
427- return true ;
428-
429413 if (DeclContext *funcCtxt = function->getDeclContext ()) {
430414 if (!canUseFromInline (funcCtxt))
431415 return false ;
@@ -455,12 +439,14 @@ bool CrossModuleOptimization::shouldSerialize(SILFunction *function) {
455439 if (function->isSerialized ())
456440 return false ;
457441
458- if (everything)
459- return true ;
460-
461442 if (function->hasSemanticsAttr (" optimize.no.crossmodule" ))
462443 return false ;
463444
445+ // In embedded Swift we serialize everything.
446+ if (SerializeEverything ||
447+ function->getASTContext ().LangOpts .hasFeature (Feature::Embedded))
448+ return true ;
449+
464450 if (!conservative) {
465451 // The basic heuristic: serialize all generic functions, because it makes a
466452 // huge difference if generic functions can be specialized or not.
@@ -666,29 +652,23 @@ class CrossModuleOptimizationPass: public SILModuleTransform {
666652 return ;
667653 if (!M.isWholeModule ())
668654 return ;
669-
655+
670656 bool conservative = false ;
671- bool everything = SerializeEverything;
672- switch (M.getOptions ().CMOMode ) {
673- case swift::CrossModuleOptimizationMode::Off:
674- break ;
675- case swift::CrossModuleOptimizationMode::Default:
676- conservative = true ;
677- break ;
678- case swift::CrossModuleOptimizationMode::Aggressive:
679- conservative = false ;
680- break ;
681- case swift::CrossModuleOptimizationMode::Everything:
682- everything = true ;
683- break ;
684- }
685-
686- if (!everything &&
687- M.getOptions ().CMOMode == swift::CrossModuleOptimizationMode::Off) {
688- return ;
657+ // In embedded Swift we serialize everything.
658+ if (!M.getASTContext ().LangOpts .hasFeature (Feature::Embedded)) {
659+ switch (M.getOptions ().CMOMode ) {
660+ case swift::CrossModuleOptimizationMode::Off:
661+ return ;
662+ case swift::CrossModuleOptimizationMode::Default:
663+ conservative = true ;
664+ break ;
665+ case swift::CrossModuleOptimizationMode::Aggressive:
666+ conservative = false ;
667+ break ;
668+ }
689669 }
690670
691- CrossModuleOptimization CMO (M, conservative, everything );
671+ CrossModuleOptimization CMO (M, conservative);
692672 CMO.serializeFunctionsInModule ();
693673 }
694674};
0 commit comments