Skip to content

Commit ef088e8

Browse files
committed
[sil-performance-inliner] Fix recent performance regressions
Do not perform any inlining of generics if it is not enabled. Don't do it even for always inline functions.
1 parent 493a7ce commit ef088e8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ SILFunction *SILPerformanceInliner::getEligibleFunction(FullApplySite AI) {
298298
return nullptr;
299299
}
300300

301+
if (!EnableSILInliningOfGenerics && AI.hasSubstitutions()) {
302+
// Inlining of generics is not allowed.
303+
return nullptr;
304+
}
305+
301306
// IRGen cannot handle partial_applies containing opened_extistentials
302307
// in its substitutions list.
303308
if (calleeHasPartialApplyWithOpenedExistentials(AI)) {
@@ -322,6 +327,8 @@ bool SILPerformanceInliner::isProfitableToInline(FullApplySite AI,
322327
SILFunction *Callee = AI.getReferencedFunction();
323328
bool IsGeneric = !AI.getSubstitutions().empty();
324329

330+
assert(EnableSILInliningOfGenerics || !IsGeneric);
331+
325332
// Bail out if this generic call can be optimized by means of
326333
// the generic specialization, because we prefer generic specialization
327334
// to inlining of generics.
@@ -381,8 +388,8 @@ bool SILPerformanceInliner::isProfitableToInline(FullApplySite AI,
381388

382389
auto Subs = FAI.getSubstitutions();
383390

384-
// Bail if it is not a generic call.
385-
if (Subs.empty())
391+
// Bail if it is not a generic call or inlining of generics is forbidden.
392+
if (!EnableSILInliningOfGenerics || Subs.empty())
386393
continue;
387394

388395
if (!isa<FunctionRefInst>(def) && !isa<ClassMethodInst>(def) &&
@@ -539,6 +546,9 @@ static Optional<bool> shouldInlineGeneric(FullApplySite AI) {
539546
assert(!AI.getSubstitutions().empty() &&
540547
"Expected a generic apply");
541548

549+
if (!EnableSILInliningOfGenerics)
550+
return false;
551+
542552
// If all substitutions are concrete, then there is no need to perform the
543553
// generic inlining. Let the generic specializer create a specialized
544554
// function and then decide if it is beneficial to inline it.
@@ -560,9 +570,6 @@ static Optional<bool> shouldInlineGeneric(FullApplySite AI) {
560570
if (Callee->getInlineStrategy() == AlwaysInline || Callee->isTransparent())
561571
return true;
562572

563-
if (!EnableSILInliningOfGenerics)
564-
return false;
565-
566573
// It is not clear yet if this function should be decided or not.
567574
return None;
568575
}

0 commit comments

Comments
 (0)