Skip to content

Inliner: Add @_semantics("inline_late") #10892

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
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "swift/SILOptimizer/Utils/PerformanceInlinerUtils.h"
#include "swift/Strings.h"

//===----------------------------------------------------------------------===//
// ConstantTracker
Expand Down Expand Up @@ -630,20 +631,32 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI,
if (!Callee) {
return nullptr;
}
auto ModuleName = Callee->getModule().getSwiftModule()->getName().str();
bool IsInStdlib = (ModuleName == STDLIB_NAME || ModuleName == SWIFT_ONONE_SUPPORT);

// Don't inline functions that are marked with the @_semantics or @effects
// attribute if the inliner is asked not to inline them.
if (Callee->hasSemanticsAttrs() || Callee->hasEffectsKind()) {
if (WhatToInline == InlineSelection::NoSemanticsAndGlobalInit) {
if (shouldSkipApplyDuringEarlyInlining(AI))
return nullptr;
if (Callee->hasSemanticsAttr("inline_late"))
return nullptr;
}
// The "availability" semantics attribute is treated like global-init.
if (Callee->hasSemanticsAttrs() &&
WhatToInline != InlineSelection::Everything &&
Callee->hasSemanticsAttrThatStartsWith("availability")) {
(Callee->hasSemanticsAttrThatStartsWith("availability") ||
(Callee->hasSemanticsAttrThatStartsWith("inline_late")))) {
return nullptr;
}
if (Callee->hasSemanticsAttrs() &&
WhatToInline == InlineSelection::Everything) {
if (Callee->hasSemanticsAttrThatStartsWith("inline_late") && IsInStdlib) {
return nullptr;
}
}

} else if (Callee->isGlobalInit()) {
if (WhatToInline != InlineSelection::Everything) {
return nullptr;
Expand Down
37 changes: 37 additions & 0 deletions test/SILOptimizer/inline_late.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -early-inline -sil-inline-threshold=50 | %FileCheck %s
// 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
// 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

sil_stage canonical

import Builtin

sil [_semantics "inline_late"] @inline_late_func : $@convention(thin) () -> Builtin.Int32 {
bb0:
%0 = integer_literal $Builtin.Int32, 3
return %0 : $Builtin.Int32
}

//CHECK-LABEL: caller_func5
//CHECK: function_ref
//CHECK: apply
//CHECK-NEXT: ret

//STDLIBLATE-LABEL: caller_func5
//STDLIBLATE: function_ref
//STDLIBLATE: apply
//STDLIBLATE-NEXT: ret


//LATE-LABEL: caller_func5
//LATE: integer_literal
//LATE-NOT: function_ref
//LATE-NOT: apply
//LATE-NEXT: ret

sil @caller_func5 : $@convention(thin) () -> Builtin.Int32 {
bb0:
%0 = function_ref @inline_late_func : $@convention(thin) () -> Builtin.Int32
%1 = apply %0() : $@convention(thin) () -> Builtin.Int32
return %1 : $Builtin.Int32
}