@@ -782,17 +782,46 @@ class PerformanceDiagnosticsPass : public SILModuleTransform {
782782 }
783783
784784 if (getModule ()->getOptions ().EmbeddedSwift ) {
785+ // Run embedded Swift SIL checks for metatype/existential use, and
786+ // allocation use (under -no-allocations mode). Try to start with public
787+ // and exported functions to get better call tree information.
788+ SmallVector<SILFunction *, 8 > externallyVisibleFunctions;
789+ SmallVector<SILFunction *, 8 > vtableMembers;
790+ SmallVector<SILFunction *, 8 > others;
791+ SmallVector<SILFunction *, 8 > constructorsAndDestructors;
792+
785793 for (SILFunction &function : *module ) {
786- // Don't check constructors and destructors directly, they will be
787- // checked if called from other functions, with better source loc info.
788794 auto func = function.getLocation ().getAsASTNode <AbstractFunctionDecl>();
789795 if (func) {
790796 if (isa<DestructorDecl>(func) || isa<ConstructorDecl>(func)) {
797+ constructorsAndDestructors.push_back (&function);
798+ continue ;
799+ }
800+ if (getMethodDispatch (func) == MethodDispatch::Class) {
801+ vtableMembers.push_back (&function);
791802 continue ;
792803 }
793804 }
794805
795- diagnoser.visitFunctionEmbeddedSwift (&function);
806+ if (function.isPossiblyUsedExternally ()) {
807+ externallyVisibleFunctions.push_back (&function);
808+ continue ;
809+ }
810+
811+ others.push_back (&function);
812+ }
813+
814+ for (SILFunction *function : externallyVisibleFunctions) {
815+ diagnoser.visitFunctionEmbeddedSwift (function);
816+ }
817+ for (SILFunction *function : vtableMembers) {
818+ diagnoser.visitFunctionEmbeddedSwift (function);
819+ }
820+ for (SILFunction *function : others) {
821+ diagnoser.visitFunctionEmbeddedSwift (function);
822+ }
823+ for (SILFunction *function : constructorsAndDestructors) {
824+ diagnoser.visitFunctionEmbeddedSwift (function);
796825 }
797826 }
798827 }
0 commit comments