Skip to content

[sil-performance-inliner] Fix recent performance regressions #7652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/SILOptimizer/Transforms/PerformanceInliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ SILFunction *SILPerformanceInliner::getEligibleFunction(FullApplySite AI) {
return nullptr;
}

if (!EnableSILInliningOfGenerics && AI.hasSubstitutions()) {
// Inlining of generics is not allowed.
return nullptr;
}

// IRGen cannot handle partial_applies containing opened_extistentials
// in its substitutions list.
if (calleeHasPartialApplyWithOpenedExistentials(AI)) {
Expand All @@ -322,6 +327,8 @@ bool SILPerformanceInliner::isProfitableToInline(FullApplySite AI,
SILFunction *Callee = AI.getReferencedFunction();
bool IsGeneric = !AI.getSubstitutions().empty();

assert(EnableSILInliningOfGenerics || !IsGeneric);

// Bail out if this generic call can be optimized by means of
// the generic specialization, because we prefer generic specialization
// to inlining of generics.
Expand Down Expand Up @@ -381,8 +388,8 @@ bool SILPerformanceInliner::isProfitableToInline(FullApplySite AI,

auto Subs = FAI.getSubstitutions();

// Bail if it is not a generic call.
if (Subs.empty())
// Bail if it is not a generic call or inlining of generics is forbidden.
if (!EnableSILInliningOfGenerics || Subs.empty())
continue;

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

if (!EnableSILInliningOfGenerics)
return false;

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

if (!EnableSILInliningOfGenerics)
return false;

// It is not clear yet if this function should be decided or not.
return None;
}
Expand Down