Skip to content

Commit ddeef64

Browse files
committed
Re-add support for try_apply instruction and update tests.
Re-work tests based on updated optimizations and check specialized functions.
1 parent 809f569 commit ddeef64

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -859,12 +859,6 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
859859
FullApplySite Apply,
860860
const llvm::SmallDenseMap<unsigned, ConcreteOpenedExistentialInfo> &COAIs,
861861
SILBuilderContext &BuilderCtx) {
862-
863-
// Bail on try_apply.
864-
// TODO: support try_apply.
865-
if (isa<TryApplyInst>(Apply))
866-
return nullptr;
867-
868862
// Ensure that the callee is polymorphic.
869863
assert(Apply.getOrigCalleeType()->isPolymorphic());
870864

@@ -945,9 +939,15 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
945939
}
946940
// Now create the new apply instruction.
947941
SILBuilderWithScope ApplyBuilder(Apply.getInstruction(), BuilderCtx);
948-
FullApplySite NewApply = ApplyBuilder.createApply(
949-
Apply.getLoc(), Apply.getCallee(), NewCallSubs, NewArgs,
950-
cast<ApplyInst>(Apply)->isNonThrowing());
942+
FullApplySite NewApply;
943+
if (auto *TAI = dyn_cast<TryApplyInst>(Apply))
944+
NewApply = ApplyBuilder.createTryApply(
945+
Apply.getLoc(), Apply.getCallee(), NewCallSubs, NewArgs,
946+
TAI->getNormalBB(), TAI->getErrorBB());
947+
else
948+
NewApply = ApplyBuilder.createApply(
949+
Apply.getLoc(), Apply.getCallee(), NewCallSubs, NewArgs,
950+
cast<ApplyInst>(Apply)->isNonThrowing());
951951

952952
if (auto NewAI = dyn_cast<ApplyInst>(NewApply))
953953
replaceInstUsesWith(*cast<ApplyInst>(Apply.getInstruction()), NewAI);

test/SILOptimizer/existential_specializer_indirect_class.sil

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -O -wmo -enable-sil-verify-all %s | %FileCheck %s
1+
// RUN: %target-sil-opt -O -wmo -enable-sil-verify-all -sil-disable-pass=DeadFunctionElimination %s | %FileCheck %s
22

33
sil_stage canonical
44

@@ -15,46 +15,42 @@ sil @test_indirect_class_protocol : $@convention(thin) (@in ClassProtocol) -> ()
1515
bb0(%0 : $*ClassProtocol):
1616
// CHECK-NEXT: %1 = load %0
1717
// CHECK-NEXT: strong_release %1
18-
// CHECK-NEXT: strong_release %1
1918
destroy_addr %0 : $*ClassProtocol
2019
// CHECK-NEXT: return undef
2120
return undef : $()
2221
}
2322

24-
// CHECK-LABEL: sil [signature_optimized_thunk] [always_inline] @test_indirect_class_protocol_guaranteed : $@convention(thin) (@in_guaranteed ClassProtocol) -> ()
25-
sil @test_indirect_class_protocol_guaranteed : $@convention(thin) (@in_guaranteed ClassProtocol) -> () {
23+
// Check that all the opened types are optimized away in the specialization of test_indirect_class_protocol_guaranteed
24+
// CHECK-LABEL: sil shared @$s39test_indirect_class_protocol_guaranteedTf4e_n : $@convention(thin) <τ_0_0 where τ_0_0 : ClassProtocol> (@in_guaranteed τ_0_0) -> ()
2625
// CHECK-NEXT: //
27-
// CHECK-NEXT: bb0(%0 : $*ClassProtocol):
26+
// CHECK-NEXT: bb0(%0 : $*τ_0_0):
27+
// CHECK-NEXT: [[INPUT:%1]] = load %0
28+
// CHECK-NEXT: [[METHOD:%.*]] = witness_method $C, #ClassProtocol.method
29+
// CHECK-NEXT: [[ARG:%.*]] = unchecked_ref_cast [[INPUT]]
30+
// CHECK-NEXT: apply [[METHOD]]<C>([[ARG]])
31+
// CHECK-NEXT: return undef
32+
33+
sil @test_indirect_class_protocol_guaranteed : $@convention(thin) (@in_guaranteed ClassProtocol) -> () {
2834
bb0(%0 : $*ClassProtocol):
29-
// CHECK-NEXT: [[INPUT:%1]] = load %0
3035
%1 = load %0 : $*ClassProtocol
31-
// CHECK-NEXT: [[OPENED:%.*]] = open_existential_ref [[INPUT]]
32-
// CHECK-NEXT: [[CLOSED:%.*]] = unchecked_ref_cast [[OPENED]]
3336
%2 = open_existential_ref %1 : $ClassProtocol to $@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF") ClassProtocol
34-
// CHECK-NEXT: [[METHOD:%.*]] = witness_method $C, #ClassProtocol.method
3537
%f = witness_method $@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF") ClassProtocol, #ClassProtocol.method!1 : <Self: ClassProtocol> (Self) -> () -> (), %2 : $@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF") ClassProtocol : $@convention(witness_method : ClassProtocol) <Self: ClassProtocol> (@guaranteed Self) -> ()
36-
// CHECK-NEXT: apply [[METHOD]]<C>([[CLOSED]])
3738
apply %f<@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF") ClassProtocol>(%2) : $@convention(witness_method : ClassProtocol) <Self: ClassProtocol> (@guaranteed Self) -> ()
38-
// CHECK-NEXT: strong_release [[INPUT]]
39-
// CHECK-NEXT: return undef
4039
return undef : $()
4140
}
4241

43-
// CHECK-LABEL: sil @invoke_indirect_class_protocol : $@convention(thin) (@guaranteed C) -> ()
44-
45-
// Make sure both applies were inlined.
46-
42+
// Check that a specialization of test_indirect_class_protocol is created.
43+
// CHECK-LABEL: sil shared [signature_optimized_thunk] [always_inline] @$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5 : $@convention(thin) (@owned C) -> ()
4744
// CHECK-NEXT: //
4845
// CHECK-NEXT: bb0(%0 : $C):
49-
50-
// CHECK-NEXT: [[METHOD:%.*]] = witness_method $C, #ClassProtocol.method
51-
// CHECK-NEXT: strong_retain %0
52-
// CHECK-NEXT: apply [[METHOD]]<C>(%0)
53-
54-
// CHECK-NEXT: strong_release %0
55-
// CHECK-NEXT: strong_release %0
5646
// CHECK-NEXT: strong_release %0
47+
// CHECK-NEXT: return undef
48+
// CHECK-LABEL: end sil function '$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5'
5749

50+
// Check the generated specialization of test_indirect_class_protocol
51+
// CHECK-LABEL: sil shared @$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5Tf4d_n : $@convention(thin) () -> ()
52+
// Make sure *everything* was inlined / optimized away
53+
// CHECK-NEXT: bb0:
5854
// CHECK-NEXT: return undef
5955

6056
sil @invoke_indirect_class_protocol : $@convention(thin) (@guaranteed C) -> () {

0 commit comments

Comments
 (0)