@@ -1051,6 +1051,22 @@ static bool hasCodeCoverageInstrumentation(SILFunction &f, SILModule &m) {
1051
1051
return f.getProfiler () && m.getOptions ().EmitProfileCoverageMapping ;
1052
1052
}
1053
1053
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
+
1054
1070
void IRGenerator::emitGlobalTopLevel (
1055
1071
const std::vector<std::string> &linkerDirectives) {
1056
1072
// Generate order numbers for the functions in the SIL module that
@@ -1082,13 +1098,9 @@ void IRGenerator::emitGlobalTopLevel(
1082
1098
}
1083
1099
1084
1100
// 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))
1092
1104
continue ;
1093
1105
1094
1106
CurrentIGMPtr IGM = getGenModule (&f);
@@ -2937,8 +2949,8 @@ llvm::Function *IRGenModule::getAddrOfSILFunction(
2937
2949
}
2938
2950
2939
2951
// 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 ())) {
2942
2954
IRGen.addLazyFunction (f);
2943
2955
}
2944
2956
0 commit comments