@@ -1051,6 +1051,22 @@ static bool hasCodeCoverageInstrumentation(SILFunction &f, SILModule &m) {
10511051 return f.getProfiler () && m.getOptions ().EmitProfileCoverageMapping ;
10521052}
10531053
1054+ // Eagerly emit functions that are externally visible. Functions with code
1055+ // coverage instrumentation must also be eagerly emitted. So must functions
1056+ // that are a dynamic replacement for another.
1057+ static bool isLazilyEmittedFunction (SILFunction &f, SILModule &m) {
1058+ if (f.isPossiblyUsedExternally ())
1059+ return false ;
1060+
1061+ if (f.getDynamicallyReplacedFunction ())
1062+ return false ;
1063+
1064+ if (hasCodeCoverageInstrumentation (f, m))
1065+ return false ;
1066+
1067+ return true ;
1068+ }
1069+
10541070void IRGenerator::emitGlobalTopLevel (
10551071 const std::vector<std::string> &linkerDirectives) {
10561072 // Generate order numbers for the functions in the SIL module that
@@ -1082,13 +1098,9 @@ void IRGenerator::emitGlobalTopLevel(
10821098 }
10831099
10841100 // Emit SIL functions.
1085- for (SILFunction &f : PrimaryIGM->getSILModule ()) {
1086- // Eagerly emit functions that are externally visible. Functions with code
1087- // coverage instrumentation must also be eagerly emitted. So must functions
1088- // that are a dynamic replacement for another.
1089- if (!f.isPossiblyUsedExternally () &&
1090- !f.getDynamicallyReplacedFunction () &&
1091- !hasCodeCoverageInstrumentation (f, PrimaryIGM->getSILModule ()))
1101+ auto &m = PrimaryIGM->getSILModule ();
1102+ for (SILFunction &f : m) {
1103+ if (isLazilyEmittedFunction (f, m))
10921104 continue ;
10931105
10941106 CurrentIGMPtr IGM = getGenModule (&f);
@@ -2937,8 +2949,8 @@ llvm::Function *IRGenModule::getAddrOfSILFunction(
29372949 }
29382950
29392951 // Otherwise, if we have a lazy definition for it, be sure to queue that up.
2940- } else if (isDefinition && !forDefinition && !f-> isPossiblyUsedExternally () &&
2941- ! hasCodeCoverageInstrumentation (*f, getSILModule ())) {
2952+ } else if (isDefinition && !forDefinition &&
2953+ isLazilyEmittedFunction (*f, getSILModule ())) {
29422954 IRGen.addLazyFunction (f);
29432955 }
29442956
0 commit comments