mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
PerformanceInliner: enable generic inlining of co-routines
Co-routines are so expensive (e.g. Array.subscript.read) that it makes sense to enable generic inlining of co-routines.
This will speed up array iteration (e.g. for elem in array { }) in a generic context significantly.
Another example is ManagedBuffer.header.read, which gets much faster.
In both cases, the speedup is mainly because there is no malloc happening anymore.
https://bugs.swift.org/browse/SR-11231
rdar://problem/53777612
This commit is contained in:
@@ -262,8 +262,6 @@ bool SILPerformanceInliner::isProfitableToInline(
|
||||
assert(Callee);
|
||||
bool IsGeneric = AI.hasSubstitutions();
|
||||
|
||||
assert(EnableSILInliningOfGenerics || !IsGeneric);
|
||||
|
||||
// Start with a base benefit.
|
||||
int BaseBenefit = RemovedCallBenefit;
|
||||
|
||||
@@ -555,17 +553,26 @@ static Optional<bool> shouldInlineGeneric(FullApplySite AI) {
|
||||
if (Callee->getInlineStrategy() == AlwaysInline || Callee->isTransparent())
|
||||
return true;
|
||||
|
||||
// All other generic functions should not be inlined if this kind of inlining
|
||||
// is disabled.
|
||||
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.
|
||||
if (!AI.getSubstitutionMap().hasArchetypes())
|
||||
return false;
|
||||
|
||||
if (Callee->getLoweredFunctionType()->getCoroutineKind() !=
|
||||
SILCoroutineKind::None) {
|
||||
// Co-routines are so expensive (e.g. Array.subscript.read) that we always
|
||||
// enable inlining them in a generic context. Though the final inlining
|
||||
// decision is done by the usual heuristics. Therefore we return None and
|
||||
// not true.
|
||||
return None;
|
||||
}
|
||||
|
||||
// All other generic functions should not be inlined if this kind of inlining
|
||||
// is disabled.
|
||||
if (!EnableSILInliningOfGenerics)
|
||||
return false;
|
||||
|
||||
// It is not clear yet if this function should be decided or not.
|
||||
return None;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user