Skip to content

Commit d0ca07b

Browse files
committed
[perf-inliner] Do not inline non-ossa funcs into ossa transparent funcs.
This is a temporary restriction for this round of ownership work until I update the perf pipeline for ownership.
1 parent 66fc758 commit d0ca07b

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,16 @@ bool SILPerformanceInliner::inlineCallsIntoFunction(SILFunction *Caller) {
891891
if (!Callee->shouldOptimize()) {
892892
continue;
893893
}
894-
894+
895+
// If we have a callee that doesn't have ownership, but the caller does have
896+
// ownership... do not inline. The two modes are incompatible. Today this
897+
// should only happen with transparent functions.
898+
if (!Callee->hasOwnership() && Caller->hasOwnership()) {
899+
assert(Caller->isTransparent() &&
900+
"Should only happen with transparent functions");
901+
continue;
902+
}
903+
895904
SmallVector<SILValue, 8> Args;
896905
for (const auto &Arg : AI.getArguments())
897906
Args.push_back(Arg);

test/SILOptimizer/devirt_ctors_ownership.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class ABC {
1313

1414

1515
// This is our c'tor.
16-
sil @_TFC4main3ABCcfMS0_FT1ySi_S0_ : $@convention(method) (Int64, @owned ABC) -> @owned ABC {
17-
bb0(%0 : $Int64, %1 : $ABC):
16+
sil [ossa] @_TFC4main3ABCcfMS0_FT1ySi_S0_ : $@convention(method) (Int64, @owned ABC) -> @owned ABC {
17+
bb0(%0 : $Int64, %1 : @owned $ABC):
1818
return %1 : $ABC // id: %38
1919
}
2020

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -inline | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
8+
// Make sure that we do not try to inline non-ossa functions into ossa
9+
// functions. This can only occur with transparent functions today.
10+
11+
// We do not need a filecheck here since if we inline, the strong_release will
12+
// hit assertions since strong_release is a non-ossa instruction that can never
13+
// be in an ossa function.
14+
sil [transparent] [ossa] @ossa_transparent_caller : $@convention(thin) (@owned Builtin.NativeObject) -> () {
15+
bb0(%0 : @owned $Builtin.NativeObject):
16+
%1 = function_ref @non_ossa_callee : $@convention(thin) (@owned Builtin.NativeObject) -> ()
17+
apply %1(%0) : $@convention(thin) (@owned Builtin.NativeObject) -> ()
18+
%9999 = tuple()
19+
return %9999 : $()
20+
}
21+
22+
// We put in this filecheck test to make sure that without the [ossa] bit, we
23+
// /would/ inline.
24+
//
25+
// CHECK-LABEL: sil [transparent] @non_ossa_caller : $@convention(thin) (@owned Builtin.NativeObject) -> () {
26+
// CHECK: strong_release
27+
// CHECK: } // end sil function 'non_ossa_caller'
28+
sil [transparent] @non_ossa_caller : $@convention(thin) (@owned Builtin.NativeObject) -> () {
29+
bb0(%0 : $Builtin.NativeObject):
30+
%1 = function_ref @non_ossa_callee : $@convention(thin) (@owned Builtin.NativeObject) -> ()
31+
apply %1(%0) : $@convention(thin) (@owned Builtin.NativeObject) -> ()
32+
%9999 = tuple()
33+
return %9999 : $()
34+
}
35+
36+
sil @non_ossa_callee : $@convention(thin) (@owned Builtin.NativeObject) -> () {
37+
bb0(%0 : $Builtin.NativeObject):
38+
strong_release %0 : $Builtin.NativeObject
39+
%9999 = tuple()
40+
return %9999 : $()
41+
}

0 commit comments

Comments
 (0)