Skip to content

Commit bb92451

Browse files
authored
Merge pull request #79321 from eeckstein/inlining-heuristic
PerformanceInliner: allow inlining of small functions even if the caller block limit is exceeded
2 parents 773561c + 6af5876 commit bb92451

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

docs/HighLevelSILOptimizations.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,30 @@ Optimize semantics attribute
392392
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
393393

394394
The optimize attribute adds function-specific directives to the optimizer.
395-
396395
The optimize attribute supports the following tags:
397396

398-
sil.specialize.generic.never
397+
optimize.sil.specialize.generic.never
399398

400-
The sil optimizer should never create generic specializations of this function.
399+
Disable generic specializations of this function.
401400

402401
optimize.sil.specialize.generic.partial.never
403402

404-
The sil optimizer should never create generic partial specializations of this function.
403+
Disable create generic partial specializations of this function.
404+
405+
optimize.sil.specialize.generic.size.never
406+
407+
Disable generic specializations of this function when optimizing for code
408+
size (-Osize).
409+
410+
optimize.sil.specialize.owned2guarantee.never
411+
412+
Disable function signature optimization which converts an "owned" to a
413+
"guaranteed" function parameter.
414+
415+
optimize.sil.inline.aggressive
416+
417+
Inlines into this function more aggressively than it would be done without
418+
this attribute.
405419

406420
Availability checks
407421
~~~~~~~~~~~~~~~~~~~

include/swift/AST/SemanticAttrs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER,
7575
"optimize.sil.specialize.generic.size.never")
7676
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_OWNED2GUARANTEE_NEVER,
7777
"optimize.sil.specialize.owned2guarantee.never")
78+
SEMANTICS_ATTR(OPTIMIZE_SIL_INLINE_AGGRESSIVE,
79+
"optimize.sil.inline.aggressive")
7880

7981
// To be used on a nominal type declaration.
8082
// Assumes that a class (or class references inside a nominal type) are immortal.

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,12 @@ void SILPerformanceInliner::collectAppliesToInline(
11511151
// caller block limit at this point. In such a case, we continue. This
11521152
// will ensure that any further non inline always functions are skipped,
11531153
// but we /do/ inline any inline_always functions remaining.
1154-
if (NumCallerBlocks > OverallCallerBlockLimit)
1154+
if (NumCallerBlocks > OverallCallerBlockLimit &&
1155+
// Still allow inlining of small functions.
1156+
!hasMaxNumberOfBasicBlocks(Callee, 8) &&
1157+
!Caller->hasSemanticsAttr(semantics::OPTIMIZE_SIL_INLINE_AGGRESSIVE)) {
11551158
continue;
1159+
}
11561160

11571161
// Otherwise, calculate our block weights and determine if we want to
11581162
// inline this.

0 commit comments

Comments
 (0)