Skip to content

Commit a440302

Browse files
committed
Inliner: Add @_semantics("inline_late")
@_semantics(inline_late) for inlining only outside the standard library in the late performance inliner. It can be beneficial to run the inliner only outside the standard library when code size has been reduced far enough that inlining can take place based on the inliner's heuristics. rdar://33099675 SR-5360
1 parent bc9f6e5 commit a440302

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/SILOptimizer/Utils/PerformanceInlinerUtils.h"
14+
#include "swift/Strings.h"
1415

1516
//===----------------------------------------------------------------------===//
1617
// ConstantTracker
@@ -630,20 +631,32 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI,
630631
if (!Callee) {
631632
return nullptr;
632633
}
634+
auto ModuleName = Callee->getModule().getSwiftModule()->getName().str();
635+
bool IsInStdlib = (ModuleName == STDLIB_NAME || ModuleName == SWIFT_ONONE_SUPPORT);
633636

634637
// Don't inline functions that are marked with the @_semantics or @effects
635638
// attribute if the inliner is asked not to inline them.
636639
if (Callee->hasSemanticsAttrs() || Callee->hasEffectsKind()) {
637640
if (WhatToInline == InlineSelection::NoSemanticsAndGlobalInit) {
638641
if (shouldSkipApplyDuringEarlyInlining(AI))
639642
return nullptr;
643+
if (Callee->hasSemanticsAttr("inline_late"))
644+
return nullptr;
640645
}
641646
// The "availability" semantics attribute is treated like global-init.
642647
if (Callee->hasSemanticsAttrs() &&
643648
WhatToInline != InlineSelection::Everything &&
644-
Callee->hasSemanticsAttrThatStartsWith("availability")) {
649+
(Callee->hasSemanticsAttrThatStartsWith("availability") ||
650+
(Callee->hasSemanticsAttrThatStartsWith("inline_late")))) {
645651
return nullptr;
646652
}
653+
if (Callee->hasSemanticsAttrs() &&
654+
WhatToInline == InlineSelection::Everything) {
655+
if (Callee->hasSemanticsAttrThatStartsWith("inline_late") && IsInStdlib) {
656+
return nullptr;
657+
}
658+
}
659+
647660
} else if (Callee->isGlobalInit()) {
648661
if (WhatToInline != InlineSelection::Everything) {
649662
return nullptr;

test/SILOptimizer/inline_late.sil

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -early-inline -sil-inline-threshold=50 | %FileCheck %s
2+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -late-inline -sil-inline-threshold=50 | %FileCheck %s --check-prefix=LATE
3+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -late-inline -sil-inline-threshold=50 -module-name Swift | %FileCheck %s --check-prefix=STDLIBLATE
4+
5+
sil_stage canonical
6+
7+
import Builtin
8+
9+
sil [_semantics "inline_late"] @inline_late_func : $@convention(thin) () -> Builtin.Int32 {
10+
bb0:
11+
%0 = integer_literal $Builtin.Int32, 3
12+
return %0 : $Builtin.Int32
13+
}
14+
15+
//CHECK-LABEL: caller_func5
16+
//CHECK: function_ref
17+
//CHECK: apply
18+
//CHECK-NEXT: ret
19+
20+
//STDLIBLATE-LABEL: caller_func5
21+
//STDLIBLATE: function_ref
22+
//STDLIBLATE: apply
23+
//STDLIBLATE-NEXT: ret
24+
25+
26+
//LATE-LABEL: caller_func5
27+
//LATE: integer_literal
28+
//LATE-NOT: function_ref
29+
//LATE-NOT: apply
30+
//LATE-NEXT: ret
31+
32+
sil @caller_func5 : $@convention(thin) () -> Builtin.Int32 {
33+
bb0:
34+
%0 = function_ref @inline_late_func : $@convention(thin) () -> Builtin.Int32
35+
%1 = apply %0() : $@convention(thin) () -> Builtin.Int32
36+
return %1 : $Builtin.Int32
37+
}

0 commit comments

Comments
 (0)