@@ -60,15 +60,11 @@ class CrossModuleOptimization {
60
60
// / avoid code size increase.
61
61
bool conservative;
62
62
63
- // / True if CMO should serialize literally everything in the module,
64
- // / regardless of linkage.
65
- bool everything;
66
-
67
63
typedef llvm::DenseMap<SILFunction *, bool > FunctionFlags;
68
64
69
65
public:
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) { }
72
68
73
69
void serializeFunctionsInModule ();
74
70
@@ -168,10 +164,9 @@ void CrossModuleOptimization::serializeFunctionsInModule() {
168
164
169
165
// Start with public functions.
170
166
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 ))
173
169
serializeFunction (&F, canSerializeFlags);
174
- }
175
170
}
176
171
}
177
172
}
@@ -194,11 +189,6 @@ bool CrossModuleOptimization::canSerializeFunction(
194
189
// it to true at the end of this function.
195
190
canSerializeFlags[function] = false ;
196
191
197
- if (everything) {
198
- canSerializeFlags[function] = true ;
199
- return true ;
200
- }
201
-
202
192
if (DeclContext *funcCtxt = function->getDeclContext ()) {
203
193
if (!canUseFromInline (funcCtxt))
204
194
return false ;
@@ -402,9 +392,6 @@ static bool couldBeLinkedStatically(DeclContext *funcCtxt, SILModule &module) {
402
392
403
393
// / Returns true if the \p declCtxt can be used from a serialized function.
404
394
bool CrossModuleOptimization::canUseFromInline (DeclContext *declCtxt) {
405
- if (everything)
406
- return true ;
407
-
408
395
if (!M.getSwiftModule ()->canBeUsedForCrossModuleOptimization (declCtxt))
409
396
return false ;
410
397
@@ -423,9 +410,6 @@ bool CrossModuleOptimization::canUseFromInline(DeclContext *declCtxt) {
423
410
424
411
// / Returns true if the function \p func can be used from a serialized function.
425
412
bool CrossModuleOptimization::canUseFromInline (SILFunction *function) {
426
- if (everything)
427
- return true ;
428
-
429
413
if (DeclContext *funcCtxt = function->getDeclContext ()) {
430
414
if (!canUseFromInline (funcCtxt))
431
415
return false ;
@@ -455,12 +439,14 @@ bool CrossModuleOptimization::shouldSerialize(SILFunction *function) {
455
439
if (function->isSerialized ())
456
440
return false ;
457
441
458
- if (everything)
459
- return true ;
460
-
461
442
if (function->hasSemanticsAttr (" optimize.no.crossmodule" ))
462
443
return false ;
463
444
445
+ // In embedded Swift we serialize everything.
446
+ if (SerializeEverything ||
447
+ function->getASTContext ().LangOpts .hasFeature (Feature::Embedded))
448
+ return true ;
449
+
464
450
if (!conservative) {
465
451
// The basic heuristic: serialize all generic functions, because it makes a
466
452
// huge difference if generic functions can be specialized or not.
@@ -666,29 +652,23 @@ class CrossModuleOptimizationPass: public SILModuleTransform {
666
652
return ;
667
653
if (!M.isWholeModule ())
668
654
return ;
669
-
655
+
670
656
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
+ }
689
669
}
690
670
691
- CrossModuleOptimization CMO (M, conservative, everything );
671
+ CrossModuleOptimization CMO (M, conservative);
692
672
CMO.serializeFunctionsInModule ();
693
673
}
694
674
};
0 commit comments