Skip to content

Commit 7d843f7

Browse files
committed
[SILOptimizer] A signature optimized function should have specialized linkage.
Previously this would mean that specialization of a public function are public, which is incorrect.
1 parent f94f16b commit 7d843f7

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -637,18 +637,7 @@ void FunctionSignatureTransform::createFunctionSignatureOptimizedFunction() {
637637
// Create the optimized function !
638638
SILModule &M = F->getModule();
639639
std::string Name = createOptimizedSILFunctionName();
640-
641-
// Any function that can be seen in other compilation units within this module
642-
// (either because the function is from another module, or because it public
643-
// or internal) needs to be considered shared, because those compilation units
644-
// may choose to do exactly the same specialization. However, specializations
645-
// of serialized functions are serialized too, and so behave more like the
646-
// original.
647-
SILLinkage linkage = F->getLinkage();
648-
auto localVisibleInOtherObjects =
649-
!hasPrivateVisibility(linkage) && !F->isSerialized();
650-
if (isAvailableExternally(linkage) || localVisibleInOtherObjects)
651-
linkage = SILLinkage::Shared;
640+
SILLinkage linkage = getSpecializedLinkage(F, F->getLinkage());
652641

653642
DEBUG(llvm::dbgs() << " -> create specialized function " << Name << "\n");
654643

test/SILOptimizer/functionsigopts.sil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ bb0(%0 : $*T):
17431743
// Check that we specialized this function by removing the dead argument and
17441744
// copied everything appropriately.
17451745

1746-
// CHECK-LABEL: sil [serialized] @_T023dead_arg_with_callsitesTfq4dn_n : $@convention(thin) (Builtin.NativeObject) -> () {
1746+
// CHECK-LABEL: sil shared [serialized] @_T023dead_arg_with_callsitesTfq4dn_n : $@convention(thin) (Builtin.NativeObject) -> () {
17471747
// CHECK: bb0([[INPUT_ARG:%[0-9]+]] : $Builtin.NativeObject):
17481748
// CHECK: cond_br undef, bb1, bb2
17491749
// CHECK: bb1:
@@ -1757,16 +1757,16 @@ bb0(%0 : $*T):
17571757
// CHECK-NEXT: tuple
17581758
// CHECK-NEXT: return
17591759

1760-
// CHECK-LABEL: sil private [serialized] @_T031private_dead_arg_with_callsitesTfq4dn_n : $@convention(thin) (Builtin.NativeObject) -> () {
1760+
// CHECK-LABEL: sil shared [serialized] @_T031private_dead_arg_with_callsitesTfq4dn_n : $@convention(thin) (Builtin.NativeObject) -> () {
17611761
// CHECK: bb0(
17621762

1763-
// CHECK-LABEL: sil [serialized] @_T037owned_to_guaranteed_with_error_resultTfq4gn_n : $@convention(thin) (@guaranteed Builtin.NativeObject, Int) -> (Int, @error Error) {
1763+
// CHECK-LABEL: sil shared [serialized] @_T037owned_to_guaranteed_with_error_resultTfq4gn_n : $@convention(thin) (@guaranteed Builtin.NativeObject, Int) -> (Int, @error Error) {
17641764
// CHECK-NOT: release
17651765
// CHECK: throw
17661766

1767-
// CHECK-LABEL: sil [serialized] @_T042owned_to_guaranteed_simple_singlebb_calleeTfq4g_n : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
1767+
// CHECK-LABEL: sil shared [serialized] @_T042owned_to_guaranteed_simple_singlebb_calleeTfq4g_n : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
17681768

1769-
// CHECK-LABEL: sil [serialized] @_T055owned_to_guaranteed_multibb_callee_with_release_in_exitTfq4dg_n : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
1769+
// CHECK-LABEL: sil shared [serialized] @_T055owned_to_guaranteed_multibb_callee_with_release_in_exitTfq4dg_n : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
17701770
// CHECK: bb0(
17711771
// CHECK: function_ref user
17721772
// CHECK: function_ref @user
@@ -1784,7 +1784,7 @@ bb0(%0 : $*T):
17841784
// Also make sure we have change the calling convention to freestanding from
17851785
// method because we have changed the self argument.
17861786

1787-
// CHECK-LABEL: sil [serialized] @_T014array_semanticTfq4g_n : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
1787+
// CHECK-LABEL: sil shared [serialized] @_T014array_semanticTfq4g_n : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
17881788
// CHECK: bb0(%0 : $Builtin.NativeObject)
17891789
// CHECK: function_ref user
17901790
// CHECK: function_ref @user

test/SILOptimizer/functionsigopts_sroa.sil

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -908,14 +908,14 @@ bb0(%0 : $SingleFieldLvl1):
908908

909909
// Check Statements for generated code.
910910

911-
// CHECK-LABEL: sil [serialized] @_T029single_level_dead_root_calleeTfq4x_n : $@convention(thin) (Builtin.Int32) -> Builtin.Int32 {
911+
// CHECK-LABEL: sil shared [serialized] @_T029single_level_dead_root_calleeTfq4x_n : $@convention(thin) (Builtin.Int32) -> Builtin.Int32 {
912912
// CHECK: bb0([[IN:%.*]] : $Builtin.Int32):
913913
// CHECK: [[UN:%.*]] = struct $S1 (undef : $Builtin.Int16, [[IN]] : $Builtin.Int32)
914914
// CHECK: struct_extract [[UN]] : $S1, #S1.f2
915915
// CHECK: return [[IN]] : $Builtin.Int32
916916

917917

918-
// CHECK-LABEL: sil [serialized] @_T029single_level_live_root_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int32) -> Builtin.Int32 {
918+
// CHECK-LABEL: sil shared [serialized] @_T029single_level_live_root_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int32) -> Builtin.Int32 {
919919
// CHECK: bb0([[IN1:%.*]] : $Builtin.Int16, [[IN2:%.*]] : $Builtin.Int32):
920920
// CHECK: [[STRUCT:%.*]] = struct $S1 ([[IN1]] : $Builtin.Int16, [[IN2]] : $Builtin.Int32)
921921
// CHECK: [[STRUCT2:%.*]] = struct $S1 ([[IN1]] : $Builtin.Int16, [[IN2]] : $Builtin.Int32)
@@ -925,7 +925,7 @@ bb0(%0 : $SingleFieldLvl1):
925925
// CHECK: return [[IN2]]
926926

927927

928-
// CHECK-LABEL: sil [serialized] @_T042multiple_level_all_root_fields_used_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int64) -> (Builtin.Int16, Builtin.Int64) {
928+
// CHECK-LABEL: sil shared [serialized] @_T042multiple_level_all_root_fields_used_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int64) -> (Builtin.Int16, Builtin.Int64) {
929929
// CHECK: bb0([[IN1:%.*]] : $Builtin.Int16, [[IN2:%.*]] : $Builtin.Int64):
930930
// CHECK: [[STRUCT1:%.*]] = struct $S1 ([[IN1]] : $Builtin.Int16, undef : $Builtin.Int32)
931931
// CHECK: [[STRUCT2:%.*]] = struct $S2 (%2 : $S1, [[IN2]] : $Builtin.Int64)
@@ -936,7 +936,7 @@ bb0(%0 : $SingleFieldLvl1):
936936
// CHECK: return [[OUT]]
937937

938938

939-
// CHECK-LABEL: sil [serialized] @_T053multiple_level_no_root_fields_have_direct_uses_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int64) -> (Builtin.Int16, Builtin.Int64) {
939+
// CHECK-LABEL: sil shared [serialized] @_T053multiple_level_no_root_fields_have_direct_uses_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int64) -> (Builtin.Int16, Builtin.Int64) {
940940
// CHECK: bb0([[IN1:%.*]] : $Builtin.Int16, [[IN2:%.*]] : $Builtin.Int64):
941941
// CHECK: [[STRUCT1:%.*]] = struct $S1 ([[IN1]] : $Builtin.Int16, undef : $Builtin.Int32)
942942
// CHECK: [[STRUCT2:%.*]] = struct $S2 ([[STRUCT1]] : $S1, [[IN2]] : $Builtin.Int64)
@@ -946,7 +946,7 @@ bb0(%0 : $SingleFieldLvl1):
946946
// CHECK: return [[OUT]]
947947

948948

949-
// CHECK-LABEL: sil [serialized] @_T043multiple_level_root_must_be_reformed_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int32, Builtin.Int64) -> (Builtin.Int16, Builtin.Int64) {
949+
// CHECK-LABEL: sil shared [serialized] @_T043multiple_level_root_must_be_reformed_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int32, Builtin.Int64) -> (Builtin.Int16, Builtin.Int64) {
950950
// CHECK: bb0([[IN1:%.*]] : $Builtin.Int16, [[IN2:%.*]] : $Builtin.Int32, [[IN3:%.*]] : $Builtin.Int64):
951951
// CHECK: [[STRUCT1:%.*]] = struct $S1 ([[IN1]] : $Builtin.Int16, [[IN2]] : $Builtin.Int32)
952952
// CHECK: [[STRUCT3:%.*]] = struct $S2 ([[STRUCT1]] : $S1, [[IN3]] : $Builtin.Int64)
@@ -960,7 +960,7 @@ bb0(%0 : $SingleFieldLvl1):
960960

961961

962962

963-
// CHECK-LABEL: sil [serialized] @_T021owned_struct_1_calleeTfq4dgX_n : $@convention(thin) (@guaranteed S4, Builtin.Int16, Builtin.Int32) -> (Builtin.Int16, Builtin.Int32, Builtin.Int16, Builtin.Int32) {
963+
// CHECK-LABEL: sil shared [serialized] @_T021owned_struct_1_calleeTfq4dgX_n : $@convention(thin) (@guaranteed S4, Builtin.Int16, Builtin.Int32) -> (Builtin.Int16, Builtin.Int32, Builtin.Int16, Builtin.Int32) {
964964
// CHECK: bb0([[IN1:%.*]] : $S4, [[IN2:%.*]] : $Builtin.Int16, [[IN3:%.*]] : $Builtin.Int32):
965965
// CHECK: [[STRUCT1:%.*]] = struct $S1 ([[IN2]] : $Builtin.Int16, [[IN3]] : $Builtin.Int32)
966966
// CHECK: [[STRUCT3:%.*]] = struct $S5 ([[IN1]] : $S4, [[STRUCT1]] : $S1)
@@ -970,7 +970,7 @@ bb0(%0 : $SingleFieldLvl1):
970970
// CHECK: [[OUT:%.*]] = tuple ([[IN2]] : $Builtin.Int16, [[IN3]] : $Builtin.Int32, [[IN2]] : $Builtin.Int16, [[IN3]] : $Builtin.Int32)
971971
// CHECK: return [[OUT]] : $(Builtin.Int16, Builtin.Int32, Builtin.Int16, Builtin.Int32)
972972

973-
// CHECK-LABEL: sil [serialized] @_T021owned_struct_2_calleeTfq4ndgXdn_n : $@convention(thin) (Builtin.Int256, @guaranteed S4, Builtin.Int16, Builtin.Int32, Builtin.Int128) -> (Builtin.Int256, Builtin.Int16, Builtin.Int32, Builtin.Int128) {
973+
// CHECK-LABEL: sil shared [serialized] @_T021owned_struct_2_calleeTfq4ndgXdn_n : $@convention(thin) (Builtin.Int256, @guaranteed S4, Builtin.Int16, Builtin.Int32, Builtin.Int128) -> (Builtin.Int256, Builtin.Int16, Builtin.Int32, Builtin.Int128) {
974974
// CHECK: bb0([[IN1:%.*]] : $Builtin.Int256, [[IN2:%.*]] : $S4, [[IN3:%.*]] : $Builtin.Int16, [[IN4:%.*]] : $Builtin.Int32, [[IN5:%.*]] : $Builtin.Int128):
975975
// CHECK: [[STRUCT1:%.*]] = struct $S1 ([[IN3]] : $Builtin.Int16, [[IN4]] : $Builtin.Int32)
976976
// CHECK: [[STRUCT3:%.*]] = struct $S5 ([[IN2]] : $S4, [[STRUCT1]] : $S1)
@@ -983,7 +983,7 @@ bb0(%0 : $SingleFieldLvl1):
983983
// CHECK: [[OUT]] : $(Builtin.Int256, Builtin.Int16, Builtin.Int32, Builtin.Int128)
984984

985985

986-
// CHECK-LABEL: sil [serialized] @_T018ignore_ptrs_calleeTfq4nxx_n : $@convention(thin) (@in S1, Builtin.Int16, Builtin.Int16) -> (Builtin.Int16, Builtin.Int16) {
986+
// CHECK-LABEL: sil shared [serialized] @_T018ignore_ptrs_calleeTfq4nxx_n : $@convention(thin) (@in S1, Builtin.Int16, Builtin.Int16) -> (Builtin.Int16, Builtin.Int16) {
987987
// CHECK: bb0([[IN1:%.*]] : $*S1, [[IN2:%.*]] : $Builtin.Int16, [[IN3:%.*]] : $Builtin.Int16):
988988
// CHECK: [[STRUCT2:%.*]] = struct $S1 ([[IN2]] : $Builtin.Int16, undef : $Builtin.Int32)
989989
// CHECK: [[STRUCT1:%.*]] = struct $S1 ([[IN3]] : $Builtin.Int16, undef : $Builtin.Int32)
@@ -996,7 +996,7 @@ bb0(%0 : $SingleFieldLvl1):
996996
// CHECK: [[OUT:%.*]] = tuple ([[IN2]] : $Builtin.Int16, [[IN3]] : $Builtin.Int16)
997997
// CHECK: return [[OUT]] : $(Builtin.Int16, Builtin.Int16)
998998

999-
// CHECK-LABEL: sil [serialized] @_T030check_out_of_order_uses_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int32) -> () {
999+
// CHECK-LABEL: sil shared [serialized] @_T030check_out_of_order_uses_calleeTfq4x_n : $@convention(thin) (Builtin.Int16, Builtin.Int32) -> () {
10001000
// CHECK: bb0([[IN1:%.*]] : $Builtin.Int16, [[IN2:%.*]] : $Builtin.Int32):
10011001
// CHECK: [[STRUCT0:%.*]] = struct $S1 ([[IN1]] : $Builtin.Int16, [[IN2]] : $Builtin.Int32)
10021002
// CHECK: debug_value [[STRUCT0]]
@@ -1008,6 +1008,6 @@ bb0(%0 : $SingleFieldLvl1):
10081008
// CHECK: apply [[FN2]]([[IN1]]) : $@convention(thin) (Builtin.Int16) -> ()
10091009

10101010

1011-
// CHECK-LABEL: sil [serialized] @_T014class_callee_1Tfq4gn_n : $@convention(thin) (@guaranteed C1, Builtin.Int32) -> Builtin.Int32 {
1011+
// CHECK-LABEL: sil shared [serialized] @_T014class_callee_1Tfq4gn_n : $@convention(thin) (@guaranteed C1, Builtin.Int32) -> Builtin.Int32 {
10121012
// CHECK: bb0({{%.*}} : $C1, [[IN:%.*]] : $Builtin.Int32):
10131013
// CHECK: return [[IN]] : $Builtin.Int32

0 commit comments

Comments
 (0)