Skip to content

Commit 2f32455

Browse files
committed
Merge pull request #1422 from gottesmm/full-apply-site-callee-function-fixes
Make some changes suggested by post commit review.
2 parents 0d307d4 + 8b4b5ac commit 2f32455

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,9 @@ class ApplyInstBase<Impl, Base, false> : public Base {
692692

693693
/// Gets the referenced function if the callee is a function_ref instruction.
694694
SILFunction *getReferencedFunction() const {
695-
auto *FRI = dyn_cast<FunctionRefInst>(getCallee());
696-
if (!FRI)
697-
return nullptr;
698-
return FRI->getReferencedFunction();
695+
if (auto *FRI = dyn_cast<FunctionRefInst>(getCallee()))
696+
return FRI->getReferencedFunction();
697+
return nullptr;
699698
}
700699

701700
/// Get the type of the callee without the applied substitutions.
@@ -4591,6 +4590,11 @@ SILFunction *ApplyInstBase<Impl, Base, false>::getCalleeFunction() const {
45914590
continue;
45924591
}
45934592

4593+
if (auto *CFI = dyn_cast<ConvertFunctionInst>(Callee)) {
4594+
Callee = CFI->getConverted();
4595+
continue;
4596+
}
4597+
45944598
return nullptr;
45954599
}
45964600
}

test/SILOptimizer/basic-instruction-properties.sil

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ class X {
1212
func foo()
1313
}
1414

15+
class Y : X {}
16+
1517
sil_vtable X {}
18+
sil_vtable Y {}
1619

1720
sil [readnone] @full_apply_site_effects_callee_1 : $@convention(thin) (@owned X) -> ()
1821
sil [readnone] @full_apply_site_effects_callee_2 : $@convention(thin) (@owned X, @owned X, @owned X) -> ()
1922

2023
// CHECK-LABEL: @full_apply_site_effects
21-
// CHECK: Inst #: 8
22-
// CHECK: apply
23-
// CHECK: Mem Behavior: None
24-
// CHECK: Release Behavior: MayRelease
2524
// CHECK: Inst #: 9
2625
// CHECK: apply
2726
// CHECK: Mem Behavior: None
@@ -44,8 +43,17 @@ sil [readnone] @full_apply_site_effects_callee_2 : $@convention(thin) (@owned X,
4443
// CHECK: Release Behavior: MayRelease
4544
// CHECK: Inst #: 14
4645
// CHECK: apply
46+
// CHECK: Mem Behavior: None
47+
// CHECK: Release Behavior: MayRelease
48+
// CHECK: Inst #: 15
49+
// CHECK: apply
4750
// CHECK: Mem Behavior: MayHaveSideEffects
4851
// CHECK: Release Behavior: MayRelease
52+
// CHECK: Inst #: 16
53+
// CHECK: Inst #: 17
54+
// CHECK: apply
55+
// CHECK: Mem Behavior: None
56+
// CHECK: Release Behavior: MayRelease
4957
sil @full_apply_site_effects : $@convention(thin) (@owned X) -> () {
5058
bb0(%0 : $X):
5159
%1 = function_ref @full_apply_site_effects_callee_1 : $@convention(thin) (@owned X) -> ()
@@ -56,6 +64,7 @@ bb0(%0 : $X):
5664
%6 = partial_apply %5(%0) : $@callee_owned @convention(thick) (@owned X, @owned X) -> ()
5765
%7 = partial_apply %6(%0) : $@callee_owned @convention(thick) (@owned X) -> ()
5866
%8 = class_method %0 : $X, #X.foo!1 : X -> () -> (), $@convention(method) (@guaranteed X) -> ()
67+
%9 = convert_function %6 : $@callee_owned @convention(thick) (@owned X) -> () to $@callee_owned @convention(thick) (@owned Y) -> ()
5968

6069
apply %1(%0) : $@convention(thin) (@owned X) -> ()
6170
apply %2() : $@callee_owned @convention(thick) () -> ()
@@ -68,5 +77,8 @@ bb0(%0 : $X):
6877
// Make sure we properly handle full apply sites for which we can not
6978
// trivially find an absolute referenced function.
7079
apply %8(%0) : $@convention(method) (@guaranteed X) -> ()
80+
81+
%10 = unchecked_ref_cast %0 : $X to $Y
82+
apply %9(%10) : $@callee_owned @convention(thick) (@owned Y) -> ()
7183
return undef : $()
7284
}

0 commit comments

Comments
 (0)