Files
swift-mirror/test/IRGen/simple_partial_apply.sil
2023-06-23 06:57:38 -07:00

58 lines
3.4 KiB
Plaintext

// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-cpu
sil_stage canonical
import Swift
class C {}
sil_vtable C {}
struct SingleRefcounted {
var c: C
}
// CHECK-LABEL: define {{.*}} @escape_partial_apply_swift_class
// CHECK-arm64e: call i64 @llvm.ptrauth.resign
// CHECK: [[FPTR:%.*]] = insertvalue { ptr, ptr } undef, ptr {{.*}}, 0
// CHECK-NEXT: [[FCTX:%.*]] = insertvalue { ptr, ptr } [[FPTR]], ptr {{.*}}, 1
// CHECK-NEXT: ret { ptr, ptr } [[FCTX]]
sil @escape_partial_apply_swift_class : $@convention(thin) (@convention(method) (Int, @guaranteed C) -> Int, @guaranteed C) -> @callee_guaranteed (Int) -> Int {
entry(%body : $@convention(method) (Int, @guaranteed C) -> Int, %context : $C):
%closure = partial_apply [callee_guaranteed] %body(%context) : $@convention(method) (Int, @guaranteed C) -> Int
return %closure : $@callee_guaranteed (Int) -> Int
}
// Can't reuse the method because it does not have swiftself.
// CHECK-LABEL: define {{.*}} @escape_partial_apply_swift_single_refcount_struct
// CHECK: [[CTXT:%.*]] = call {{.*}} @swift_allocObject
// CHECK: [[FCTX:%.*]] = insertvalue { ptr, ptr } { ptr @"$sTA{{.*}}", ptr undef }, ptr [[CTXT]], 1
// CHECK-NEXT: ret { ptr, ptr } [[FCTX]]
sil @escape_partial_apply_swift_single_refcount_struct : $@convention(thin) (@convention(method) (Int, @guaranteed SingleRefcounted) -> Int, @guaranteed SingleRefcounted) -> @callee_guaranteed (Int) -> Int {
entry(%body : $@convention(method) (Int, @guaranteed SingleRefcounted) -> Int, %context : $SingleRefcounted):
%closure = partial_apply [callee_guaranteed] %body(%context) : $@convention(method) (Int, @guaranteed SingleRefcounted) -> Int
return %closure : $@callee_guaranteed (Int) -> Int
}
// CHECK-LABEL: define {{.*}} @noescape_partial_apply_swift_indirect
// CHECK: call {{.*}}void %2(ptr {{.*}}, ptr %1, ptr {{.*}}%3)
sil @noescape_partial_apply_swift_indirect : $@convention(thin) (@convention(method) (Int, @in_guaranteed C) -> Int, @in_guaranteed C, @guaranteed @callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()) -> () {
entry(%body : $@convention(method) (Int, @in_guaranteed C) -> Int, %context : $*C, %cont : $@callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()):
%closure = partial_apply [callee_guaranteed] [on_stack] %body(%context) : $@convention(method) (Int, @in_guaranteed C) -> Int
%x = apply %cont(%closure) : $@callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()
dealloc_stack %closure : $@noescape @callee_guaranteed (Int) -> Int
return undef : $()
}
// Can't reuse the method because it does not have swiftself.
// CHECK-LABEL: define {{.*}} @noescape_partial_apply_swift_direct_word
// CHECK: call swiftcc void {{.*}}(ptr @"$sTA{{.*}}", ptr {{.*}}, ptr swiftself {{.*}})
sil @noescape_partial_apply_swift_direct_word : $@convention(thin) (@convention(method) (Int, Int) -> Int, Int, @guaranteed @callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()) -> () {
entry(%body : $@convention(method) (Int, Int) -> Int, %context : $Int, %cont : $@callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()):
%closure = partial_apply [callee_guaranteed] [on_stack] %body(%context) : $@convention(method) (Int, Int) -> Int
%x = apply %cont(%closure) : $@callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()
dealloc_stack %closure : $@noescape @callee_guaranteed (Int) -> Int
return undef : $()
}