mirror of
https://github.com/apple/swift.git
synced 2025-12-25 12:15:36 +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.
163 lines
7.8 KiB
Plaintext
163 lines
7.8 KiB
Plaintext
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-ir | %FileCheck %s
|
|
|
|
// REQUIRES: CPU=x86_64
|
|
|
|
// Generated from
|
|
// var x : Int32 = 2
|
|
// public func f() -> Int32 { return x }
|
|
// with swiftc -O -parse-as-library -emit-sil
|
|
|
|
import Builtin
|
|
import Swift
|
|
|
|
struct S {
|
|
var m : Int32
|
|
}
|
|
|
|
public struct S2 {
|
|
public var i, j : Int32
|
|
var s : S
|
|
}
|
|
|
|
// CHECK: %Ts5Int32V = type <{ i32 }>
|
|
// CHECK: %T18static_initializer2S2V = type <{ %Ts5Int32V, %Ts5Int32V, %T18static_initializer1SV }>
|
|
// CHECK: %T18static_initializer1SV = type <{ %Ts5Int32V }>
|
|
// CHECK: %T18static_initializer16TestArrayStorageC_tailelems0c = type { [1 x i64], %T18static_initializer16TestArrayStorageC_tailelems0 }
|
|
// CHECK: %T18static_initializer16TestArrayStorageC_tailelems0 = type <{ %swift.refcounted, %Ts5Int32V, [4 x i8], %Ts5Int64V, %Ts5Int64V }>
|
|
// CHECK: %T18static_initializer16TestArrayStorageC_tailelems1c = type { [2 x i64], %T18static_initializer16TestArrayStorageC_tailelems1 }
|
|
// CHECK: %T18static_initializer16TestArrayStorageC_tailelems1 = type <{ %swift.refcounted, %Ts5Int32V, [12 x i8], %Ts7Float80V }>
|
|
// CHECK: %T18static_initializer16TestArrayStorageC_tailelems3 = type <{ %swift.refcounted, %Ts5Int32V, [1 x i8], [1 x i8] }>
|
|
|
|
sil_global @$S2ch1xSiv : $Int32 = {
|
|
%1 = integer_literal $Builtin.Int32, 2
|
|
%initval = struct $Int32 (%1 : $Builtin.Int32)
|
|
}
|
|
// CHECK: @"$S2ch1xSiv" = {{(protected )?}}global %Ts5Int32V <{ i32 2 }>, align 4
|
|
|
|
sil_global @$S6nested1xAA2S2Vv : $S2 = {
|
|
%1 = integer_literal $Builtin.Int32, 2
|
|
%2 = struct $Int32 (%1 : $Builtin.Int32)
|
|
%3 = integer_literal $Builtin.Int32, 3
|
|
%4 = struct $Int32 (%3 : $Builtin.Int32)
|
|
%5 = integer_literal $Builtin.Int32, 4
|
|
%6 = struct $Int32 (%5 : $Builtin.Int32)
|
|
%7 = struct $S (%6 : $Int32)
|
|
%initval = struct $S2 (%2 : $Int32, %4 : $Int32, %7 : $S)
|
|
}
|
|
// CHECK: @"$S6nested1xAA2S2Vv" = {{(protected )?}}global %T18static_initializer2S2V <{ %Ts5Int32V <{ i32 2 }>, %Ts5Int32V <{ i32 3 }>, %T18static_initializer1SV <{ %Ts5Int32V <{ i32 4 }> }> }>, align 4
|
|
|
|
final class TestArrayStorage {
|
|
@sil_stored var count: Int32
|
|
init()
|
|
}
|
|
|
|
sil_vtable TestArrayStorage { }
|
|
|
|
struct TestArray {
|
|
var storage : TestArrayStorage
|
|
}
|
|
|
|
sil_global @static_array : $TestArrayStorage = {
|
|
%0 = integer_literal $Builtin.Int32, 2
|
|
%1 = integer_literal $Builtin.Int64, 10
|
|
%2 = integer_literal $Builtin.Int64, 20
|
|
%3 = struct $Int32 (%0 : $Builtin.Int32)
|
|
%4 = struct $Int64 (%1 : $Builtin.Int64)
|
|
%5 = struct $Int64 (%2 : $Builtin.Int64)
|
|
%initval = object $TestArrayStorage (%3 : $Int32, [tail_elems] %4 : $Int64, %5 : $Int64)
|
|
}
|
|
// CHECK: @static_array = {{(protected )?}}global %T18static_initializer16TestArrayStorageC_tailelems0c { [1 x i64] zeroinitializer, %T18static_initializer16TestArrayStorageC_tailelems0 <{ %swift.refcounted zeroinitializer, %Ts5Int32V <{ i32 2 }>, [4 x i8] undef, %Ts5Int64V <{ i64 10 }>, %Ts5Int64V <{ i64 20 }> }> }, align 8
|
|
|
|
sil_global @static_aligned_array : $TestArrayStorage = {
|
|
%0 = integer_literal $Builtin.Int32, 2
|
|
%1 = float_literal $Builtin.FPIEEE80, 0x3FFE8000000000000000
|
|
%3 = struct $Int32 (%0 : $Builtin.Int32)
|
|
%4 = struct $Float80 (%1 : $Builtin.FPIEEE80)
|
|
%initval = object $TestArrayStorage (%3 : $Int32, [tail_elems] %4 : $Float80)
|
|
}
|
|
// CHECK: @static_aligned_array = {{(protected )?}}global %T18static_initializer16TestArrayStorageC_tailelems1c { [2 x i64] zeroinitializer, %T18static_initializer16TestArrayStorageC_tailelems1 <{ %swift.refcounted zeroinitializer, %Ts5Int32V <{ i32 2 }>, [12 x i8] undef, %Ts7Float80V <{ x86_fp80 0xK3FFE8000000000000000 }> }> }, align 16
|
|
|
|
final class ClassWithEmptyField {
|
|
@sil_stored var x: Int32
|
|
@sil_stored var y: ()
|
|
init()
|
|
}
|
|
|
|
sil_vtable ClassWithEmptyField { }
|
|
|
|
sil_global @static_class_with_empty_field : $ClassWithEmptyField = {
|
|
%0 = integer_literal $Builtin.Int32, 2
|
|
%3 = struct $Int32 (%0 : $Builtin.Int32)
|
|
%5 = tuple ()
|
|
%initval = object $ClassWithEmptyField (%3 : $Int32, %5 : $())
|
|
}
|
|
// CHECK: @static_class_with_empty_field = {{(protected )?}}global %T18static_initializer19ClassWithEmptyFieldC_tailelems2c { [1 x i64] zeroinitializer, %T18static_initializer19ClassWithEmptyFieldC_tailelems2 <{ %swift.refcounted zeroinitializer, %Ts5Int32V <{ i32 2 }> }> }, align 8
|
|
|
|
struct Empty { }
|
|
|
|
sil_global @static_array_with_empty_element : $TestArrayStorage = {
|
|
%0 = struct $Empty () // users: %7, %7
|
|
%1 = integer_literal $Builtin.Int32, 2
|
|
%2 = struct $Int32 (%1 : $Builtin.Int32)
|
|
%initval = object $TestArrayStorage (%2 : $Int32, [tail_elems] %0 : $Empty, %0 : $Empty)
|
|
}
|
|
// CHECK: @static_array_with_empty_element = {{(protected )?}}global %T18static_initializer16TestArrayStorageC_tailelems3c { [1 x i64] zeroinitializer, %T18static_initializer16TestArrayStorageC_tailelems3 <{ %swift.refcounted zeroinitializer, %Ts5Int32V <{ i32 2 }>, [1 x i8] undef, [1 x i8] undef }> }, align 8
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc i8* @_TF2cha1xSi() {{.*}} {
|
|
// CHECK-NEXT: entry:
|
|
// CHECK-NEXT: ret i8* bitcast (%Ts5Int32V* @"$S2ch1xSiv" to i8*)
|
|
sil [global_init] @_TF2cha1xSi : $@convention(thin) () -> Builtin.RawPointer {
|
|
bb0:
|
|
%0 = global_addr @$S2ch1xSiv : $*Int32
|
|
%1 = address_to_pointer %0 : $*Int32 to $Builtin.RawPointer
|
|
return %1 : $Builtin.RawPointer
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc i32 @"$S2ch1fSiyF"() {{.*}} {
|
|
// CHECK-NEXT: entry:
|
|
// CHECK-NEXT: load i32, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* @"$S2ch1xSiv", i32 0, i32 0)
|
|
// CHECK-NEXT: ret
|
|
sil @$S2ch1fSiyF : $@convention(thin) () -> Int32 {
|
|
bb0:
|
|
%0 = global_addr @$S2ch1xSiv : $*Int32
|
|
%1 = load %0 : $*Int32
|
|
return %1 : $Int32
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc i8* @_TF6nesteda1xVS_2S2() {{.*}} {
|
|
// CHECK-NEXT: entry:
|
|
// CHECK-NEXT: ret i8* bitcast (%T18static_initializer2S2V* @"$S6nested1xAA2S2Vv" to i8*)
|
|
sil [global_init] @_TF6nesteda1xVS_2S2 : $@convention(thin) () -> Builtin.RawPointer {
|
|
bb0:
|
|
%0 = global_addr @$S6nested1xAA2S2Vv : $*S2
|
|
%1 = address_to_pointer %0 : $*S2 to $Builtin.RawPointer
|
|
return %1 : $Builtin.RawPointer
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc { i64, i32 } @"$S6nested1fAA2S2VyF"() {{.*}} {
|
|
// CHECK-NEXT: entry:
|
|
// CHECK: load i32, i32* getelementptr inbounds (%T18static_initializer2S2V, %T18static_initializer2S2V* @"$S6nested1xAA2S2Vv", i32 0, i32 0, i32 0)
|
|
// CHECK-NEXT: load i32, i32* getelementptr inbounds (%T18static_initializer2S2V, %T18static_initializer2S2V* @"$S6nested1xAA2S2Vv", i32 0, i32 1, i32 0)
|
|
// CHECK-NEXT: load i32, i32* getelementptr inbounds (%T18static_initializer2S2V, %T18static_initializer2S2V* @"$S6nested1xAA2S2Vv", i32 0, i32 2, i32 0, i32 0)
|
|
sil @$S6nested1fAA2S2VyF : $@convention(thin) () -> S2 {
|
|
bb0:
|
|
%0 = global_addr @$S6nested1xAA2S2Vv : $*S2
|
|
%1 = load %0 : $*S2
|
|
return %1 : $S2
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc %T18static_initializer16TestArrayStorageC* @return_static_array() {{.*}} {
|
|
sil @return_static_array : $@convention(thin) () -> TestArray {
|
|
bb0:
|
|
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$S18static_initializer16TestArrayStorageCMa"(i64 0)
|
|
// CHECK: [[MD:%[0-9]+]] = extractvalue %swift.metadata_response [[TMP]], 0
|
|
// CHECK: [[O:%[0-9a-z]+]] = call %swift.refcounted* @swift_initStaticObject(%swift.type* [[MD]], %swift.refcounted* getelementptr inbounds (%T18static_initializer16TestArrayStorageC_tailelems0c, %T18static_initializer16TestArrayStorageC_tailelems0c* @static_array, i32 0, i32 1, i32 0))
|
|
// CHECK: [[R:%[0-9]+]] = bitcast %swift.refcounted* [[O]] to %T18static_initializer16TestArrayStorageC_tailelems0*
|
|
// CHECK: [[R2:%[0-9]+]] = bitcast %T18static_initializer16TestArrayStorageC_tailelems0* [[R]] to %T18static_initializer16TestArrayStorageC*
|
|
// CHECK: ret %T18static_initializer16TestArrayStorageC* [[R2]]
|
|
%0 = global_value @static_array : $TestArrayStorage
|
|
%1 = struct $TestArray (%0 : $TestArrayStorage)
|
|
return %1 : $TestArray
|
|
}
|
|
|