mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This includes global generic and non-generic global access functions, protocol associated type access functions, swift_getGenericMetadata, and generic type completion functions. The main part of this change is that the functions now need to take a MetadataRequest and return a MetadataResponse, which is capable of expressing that the request can fail. The state of the returned metadata is reported as an second, independent return value; this allows the caller to easily check the possibility of failure without having to mask it out from the returned metadata pointer, as well as allowing it to be easily ignored. Also, change metadata access functions to use swiftcc to ensure that this return value is indeed returned in two separate registers. Also, change protocol associated conformance access functions to use swiftcc. This isn't really related, but for some reason it snuck in. Since it's clearly the right thing to do, and since I really didn't want to retroactively tease that back out from all the rest of the test changes, I've left it in. Also, change generic metadata access functions to either pass all the generic arguments directly or pass them all indirectly. I don't know how we ended up with the hybrid approach. I needed to change all the code-generation and calls here anyway in order to pass the request parameter, and I figured I might as well change the ABI to something sensible.
150 lines
5.7 KiB
Plaintext
150 lines
5.7 KiB
Plaintext
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -stack-promotion-limit 48 -Onone -emit-ir %s | %FileCheck %s -DINT=i%target-ptrsize
|
|
|
|
import Builtin
|
|
import Swift
|
|
|
|
class TestClass {
|
|
@sil_stored var a : Int64
|
|
init()
|
|
}
|
|
|
|
struct TestStruct {
|
|
@sil_stored var a : Int64
|
|
@sil_stored var b : Int64
|
|
@sil_stored var c : Int64
|
|
}
|
|
|
|
class BigClass {
|
|
@sil_stored var a : Int64
|
|
@sil_stored var b : Int64
|
|
@sil_stored var c : Int64
|
|
@sil_stored var d : Int64
|
|
@sil_stored var e : Int64
|
|
@sil_stored var f : Int64
|
|
@sil_stored var g : Int64
|
|
init()
|
|
}
|
|
|
|
sil_vtable TestClass {}
|
|
sil_vtable BigClass {}
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @simple_promote
|
|
// CHECK: %reference.raw = alloca %[[C:[a-zA-Z0-9_]+]], align 8
|
|
// CHECK-NEXT: [[MR:%[0-9]+]] = call swiftcc %swift.metadata_response @"$S17class_stack_alloc9TestClassCMa"([[INT]] 0)
|
|
// CHECK-NEXT: [[M:%.*]] = extractvalue %swift.metadata_response [[MR]], 0
|
|
// CHECK-NEXT: [[O:%[0-9]+]] = bitcast %[[C]]* %reference.raw to %swift.refcounted*
|
|
// CHECK-NEXT: %reference.new = call %swift.refcounted* @swift_initStackObject(%swift.type* [[M]], %swift.refcounted* [[O]])
|
|
// CHECK-NEXT: [[R:%[0-9]+]] = bitcast %swift.refcounted* %reference.new to %[[C]]*
|
|
// CHECK-NEXT: call {{.*}} @swift_release {{.*}} [[R]])
|
|
// CHECK-NEXT: [[O2:%[0-9]+]] = bitcast %[[C]]* [[R]] to i8*
|
|
// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[O2]])
|
|
// CHECK-NEXT: ret void
|
|
sil @simple_promote : $@convention(thin) () -> () {
|
|
bb0:
|
|
%o1 = alloc_ref [stack] $TestClass
|
|
strong_release %o1 : $TestClass
|
|
dealloc_ref [stack] %o1 : $TestClass
|
|
|
|
%r = tuple()
|
|
return %r : $()
|
|
}
|
|
|
|
// A stack promotion limit of 48 bytes allows that one of the two alloc_refs
|
|
// can be allocated on the stack.
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @exceed_limit
|
|
// CHECK: alloca {{.*}}TestClass
|
|
// CHECK: alloca {{.*}}TestStruct
|
|
// CHECK-NOT: alloca
|
|
// CHECK: call %swift.refcounted* @swift_initStackObject
|
|
// CHECK: call noalias %swift.refcounted* @swift_allocObject
|
|
// CHECK: ret void
|
|
sil @exceed_limit : $@convention(thin) () -> () {
|
|
bb0:
|
|
%o1 = alloc_ref [stack] $TestClass
|
|
%o2 = alloc_ref [stack] $TestClass
|
|
|
|
%s1 = alloc_stack $TestStruct
|
|
|
|
%f = function_ref @unknown_func : $@convention(thin) (@inout TestStruct) -> ()
|
|
%a = apply %f(%s1) : $@convention(thin) (@inout TestStruct) -> ()
|
|
|
|
dealloc_stack %s1 : $*TestStruct
|
|
|
|
strong_release %o1 : $TestClass
|
|
strong_release %o2 : $TestClass
|
|
dealloc_ref [stack] %o2 : $TestClass
|
|
dealloc_ref [stack] %o1 : $TestClass
|
|
|
|
%r = tuple()
|
|
return %r : $()
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @promoted_with_devirtualized_release
|
|
// CHECK: %reference.raw = alloca %[[C:[a-zA-Z0-9_]+]], align 8
|
|
// CHECK-NEXT: [[MR:%[0-9]+]] = call swiftcc %swift.metadata_response @"$S17class_stack_alloc9TestClassCMa"([[INT]] 0)
|
|
// CHECK-NEXT: [[M:%.*]] = extractvalue %swift.metadata_response [[MR]], 0
|
|
// CHECK-NEXT: [[O:%[0-9]+]] = bitcast %[[C]]* %reference.raw to %swift.refcounted*
|
|
// CHECK-NEXT: %reference.new = call %swift.refcounted* @swift_initStackObject(%swift.type* [[M]], %swift.refcounted* [[O]])
|
|
// CHECK-NEXT: [[R:%[0-9]+]] = bitcast %swift.refcounted* %reference.new to %[[C]]*
|
|
// CHECK-NEXT: call {{.*}} @swift_setDeallocating {{.*}}(%[[C]]* [[R]])
|
|
// CHECK-NEXT: call swiftcc void @not_inlined_destructor(%[[C]]* [[R]])
|
|
// CHECK-NEXT: [[O2:%[0-9]+]] = bitcast %[[C]]* [[R]] to i8*
|
|
// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[O2]])
|
|
// CHECK-NEXT: ret void
|
|
sil @promoted_with_devirtualized_release : $@convention(thin) () -> () {
|
|
bb0:
|
|
%o1 = alloc_ref [stack] $TestClass
|
|
set_deallocating %o1 : $TestClass
|
|
%f = function_ref @not_inlined_destructor : $@convention(thin) (TestClass) -> ()
|
|
%a = apply %f(%o1) : $@convention(thin) (TestClass) -> ()
|
|
dealloc_ref [stack] %o1 : $TestClass
|
|
|
|
%r = tuple()
|
|
return %r : $()
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @promoted_with_inlined_devirtualized_release
|
|
// CHECK: %reference.raw = alloca %[[C:[a-zA-Z0-9_]+]], align 8
|
|
// CHECK-NEXT: [[MR:%[0-9]+]] = call swiftcc %swift.metadata_response @"$S17class_stack_alloc9TestClassCMa"([[INT]] 0)
|
|
// CHECK-NEXT: [[M:%.*]] = extractvalue %swift.metadata_response [[MR]], 0
|
|
// CHECK-NEXT: [[O:%[0-9]+]] = bitcast %[[C]]* %reference.raw to %swift.refcounted*
|
|
// CHECK-NEXT: %reference.new = call %swift.refcounted* @swift_initStackObject(%swift.type* [[M]], %swift.refcounted* [[O]])
|
|
// CHECK-NEXT: [[R:%[0-9]+]] = bitcast %swift.refcounted* %reference.new to %[[C]]*
|
|
// CHECK-NOT: call
|
|
// CHECK: [[O2:%[0-9]+]] = bitcast %[[C]]* [[R]] to i8*
|
|
// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[O2]])
|
|
// CHECK-NEXT: ret void
|
|
sil @promoted_with_inlined_devirtualized_release : $@convention(thin) () -> () {
|
|
bb0:
|
|
%o1 = alloc_ref [stack] $TestClass
|
|
set_deallocating %o1 : $TestClass
|
|
dealloc_ref %o1 : $TestClass
|
|
dealloc_ref [stack] %o1 : $TestClass
|
|
|
|
%r = tuple()
|
|
return %r : $()
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @not_promoted_with_inlined_devirtualized_release
|
|
// CHECK: [[O:%[0-9]+]] = call {{.*}} @swift_allocObject
|
|
// CHECK-NEXT: [[BC:%[0-9]+]] = bitcast %swift.refcounted* [[O]] to
|
|
// CHECK-NEXT: call {{.*}} @swift_setDeallocating {{.*}}({{.*}} [[BC]])
|
|
// CHECK-NEXT: [[BC2:%[0-9]+]] = bitcast {{.*}} [[BC]] to %swift.refcounted*
|
|
// CHECK-NEXT: call void @swift_deallocClassInstance(%swift.refcounted* [[BC2]], {{.*}})
|
|
// CHECK-NEXT: ret void
|
|
sil @not_promoted_with_inlined_devirtualized_release : $@convention(thin) () -> () {
|
|
bb0:
|
|
%o1 = alloc_ref [stack] $BigClass
|
|
set_deallocating %o1 : $BigClass
|
|
dealloc_ref %o1 : $BigClass
|
|
dealloc_ref [stack] %o1 : $BigClass
|
|
|
|
%r = tuple()
|
|
return %r : $()
|
|
}
|
|
|
|
sil @not_inlined_destructor : $@convention(thin) (TestClass) -> ()
|
|
sil @unknown_func : $@convention(thin) (@inout TestStruct) -> ()
|
|
|