Skip to content

Commit a752b44

Browse files
committed
Merge pull request #2712 from trentxintong/SFSO
Change FSO explosion heurisitics.
2 parents 06b2fce + d8e11f5 commit a752b44

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

include/swift/SILOptimizer/Utils/FunctionSignatureOptUtils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ struct ArgumentDescriptor {
104104
if (!canOptimizeLiveArg())
105105
return false;
106106

107+
// If this argument is @owned and we can not find all the releases for it
108+
// try to explode it, maybe we can find some of the releases and O2G some
109+
// of its components.
110+
//
111+
// This is a potentially a very profitable optimization. Ignore other
112+
// heuristics.
113+
if (hasConvention(SILArgumentConvention::Direct_Owned) &&
114+
ERM.hasSomeReleasesForArgument(Arg))
115+
return true;
116+
107117
// See if the projection tree consists of potentially multiple levels of
108118
// structs containing one field. In such a case, there is no point in
109119
// exploding the argument.

test/SILOptimizer/functionsigopts.sil

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,64 @@ struct lotsoffield {
4242
init()
4343
}
4444

45+
struct goo {
46+
var left : foo
47+
var right : foo
48+
var top : foo
49+
var bottom : foo
50+
}
51+
4552
sil @use_Int : $@convention(thin) (Int) -> ()
4653

54+
55+
// CHECK-LABEL: sil [thunk] [always_inline] @argument_with_incomplete_epilogue_release
56+
// CHECK: [[IN2:%.*]] = struct_extract [[IN1:%.*]] : $goo, #goo.top
57+
// CHECK: function_ref @_TTSf4g_n___TTSf4s__argument_with_incomplete_epilogue_release : $@convention(thin) (@guaranteed foo, @owned foo) -> ()
58+
// CHECK: release_value [[IN2]]
59+
sil @argument_with_incomplete_epilogue_release : $@convention(thin) (@owned goo) -> () {
60+
bb0(%0 : $goo):
61+
// make inline costs = 2
62+
%c1 = builtin "assert_configuration"() : $Builtin.Int32
63+
%c2 = builtin "assert_configuration"() : $Builtin.Int32
64+
%c3 = builtin "assert_configuration"() : $Builtin.Int32
65+
%c4 = builtin "assert_configuration"() : $Builtin.Int32
66+
%c5 = builtin "assert_configuration"() : $Builtin.Int32
67+
%c6 = builtin "assert_configuration"() : $Builtin.Int32
68+
%c7 = builtin "assert_configuration"() : $Builtin.Int32
69+
%c8 = builtin "assert_configuration"() : $Builtin.Int32
70+
%c9 = builtin "assert_configuration"() : $Builtin.Int32
71+
%c10 = builtin "assert_configuration"() : $Builtin.Int32
72+
%c11 = builtin "assert_configuration"() : $Builtin.Int32
73+
%c12 = builtin "assert_configuration"() : $Builtin.Int32
74+
%c13 = builtin "assert_configuration"() : $Builtin.Int32
75+
%c14 = builtin "assert_configuration"() : $Builtin.Int32
76+
%c15 = builtin "assert_configuration"() : $Builtin.Int32
77+
%c16 = builtin "assert_configuration"() : $Builtin.Int32
78+
%c17 = builtin "assert_configuration"() : $Builtin.Int32
79+
%c18 = builtin "assert_configuration"() : $Builtin.Int32
80+
%c19 = builtin "assert_configuration"() : $Builtin.Int32
81+
%c20 = builtin "assert_configuration"() : $Builtin.Int32
82+
%c21 = builtin "assert_configuration"() : $Builtin.Int32
83+
%c22 = builtin "assert_configuration"() : $Builtin.Int32
84+
85+
86+
87+
%1 = struct_extract %0 : $goo, #goo.top
88+
%2 = ref_element_addr %1 : $foo, #foo.a
89+
%3 = load %2 : $*Int
90+
%4 = function_ref @use_Int : $@convention(thin) (Int) -> ()
91+
apply %4(%3) : $@convention(thin) (Int) -> ()
92+
93+
%5 = struct_extract %0 : $goo, #goo.bottom
94+
%6 = ref_element_addr %5 : $foo, #foo.a
95+
%7 = load %6 : $*Int
96+
apply %4(%7) : $@convention(thin) (Int) -> ()
97+
98+
release_value %1 : $foo
99+
%8 = tuple ()
100+
return %8 : $()
101+
}
102+
47103
// We do this check separately to ensure that this does not occur anywhere in
48104
// the output for the file. (Maybe this is an interesting enough feature to add to FileCheck?).
49105

@@ -174,6 +230,7 @@ bb0(%0 : $boo):
174230
return %4 : $(Int, Int)
175231
}
176232

233+
177234
// CHECK-LABEL: sil [fragile] @dead_arg_no_callsites : $@convention(thin) (Builtin.NativeObject, Builtin.NativeObject) -> () {
178235
// CHECK-NOT: function_ref @_TTSf4d_n__dead_arg_no_callsites
179236
sil [fragile] @dead_arg_no_callsites : $@convention(thin) (Builtin.NativeObject, Builtin.NativeObject) -> () {
@@ -720,7 +777,13 @@ bb0(%0 : $boo):
720777
return %5 : $()
721778
}
722779

723-
780+
sil [fragile] @argument_with_incomplete_epilogue_release_callsite : $@convention(thin) (@owned goo) -> () {
781+
bb0(%0 : $goo):
782+
%2 = function_ref @argument_with_incomplete_epilogue_release : $@convention(thin) (@owned goo) -> ()
783+
%4 = apply %2(%0) : $@convention(thin) (@owned goo) -> ()
784+
%5 = tuple()
785+
return %5 : $()
786+
}
724787

725788

726789
//========================================

0 commit comments

Comments
 (0)