@@ -469,10 +469,16 @@ void addFunctionPasses(SILPassPipelinePlan &P,
469469 // makes a change we'll end up restarting the function passes on the
470470 // current function (after optimizing any new callees).
471471 P.addDevirtualizer ();
472- P.addGenericSpecializer ();
473- // Run devirtualizer after the specializer, because many
474- // class_method/witness_method instructions may use concrete types now.
475- P.addDevirtualizer ();
472+ // MandatoryPerformanceOptimizations already took care of all specializations
473+ // in embedded Swift mode, running the generic specializer might introduce
474+ // more generic calls from non-generic functions, which breaks the assumptions
475+ // of embedded Swift.
476+ if (!P.getOptions ().EmbeddedSwift ) {
477+ P.addGenericSpecializer ();
478+ // Run devirtualizer after the specializer, because many
479+ // class_method/witness_method instructions may use concrete types now.
480+ P.addDevirtualizer ();
481+ }
476482 P.addARCSequenceOpts ();
477483
478484 if (P.getOptions ().EnableOSSAModules ) {
@@ -754,8 +760,14 @@ static void addMidLevelFunctionPipeline(SILPassPipelinePlan &P) {
754760static void addLowLevelPassPipeline (SILPassPipelinePlan &P) {
755761 P.startPipeline (" LowLevel,Function" , true /* isFunctionPassPipeline*/ );
756762
757- // Should be after FunctionSignatureOpts and before the last inliner.
758- P.addReleaseDevirtualizer ();
763+ // MandatoryPerformanceOptimizations already took care of all specializations
764+ // in embedded Swift mode, running the release devirtualizer might introduce
765+ // more generic calls from non-generic functions, which breaks the assumptions
766+ // of embedded Swift.
767+ if (!P.getOptions ().EmbeddedSwift ) {
768+ // Should be after FunctionSignatureOpts and before the last inliner.
769+ P.addReleaseDevirtualizer ();
770+ }
759771
760772 addFunctionPasses (P, OptimizationLevelKind::LowLevel);
761773
@@ -967,13 +979,6 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
967979 // Perform optimizations that specialize.
968980 addClosureSpecializePassPipeline (P);
969981
970- // For embedded Swift: We need to re-run VTableSpecializer in case the
971- // performance inliner and specializer ended up discovering new generic
972- // classes.
973- if (Options.EmbeddedSwift ) {
974- P.addVTableSpecializer ();
975- }
976-
977982 // Run another iteration of the SSA optimizations to optimize the
978983 // devirtualized inline caches and constants propagated into closures
979984 // (CapturePropagation).
0 commit comments