Files
swift-mirror/test/IRGen/enum_function.sil
Arnold Schwaighofer 39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00

51 lines
1.6 KiB
Plaintext

// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -gnone -emit-ir | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
// REQUIRES: CPU=x86_64
sil_stage canonical
import Swift
sil hidden @test_helper : $@convention(thin) () -> () {
bb0:
%0 = tuple ()
return %0 : $()
}
// CHECK-64: define hidden swiftcc void @test1([[WORD:i64]], [[WORD]])
// CHECK-32: define hidden swiftcc void @test1([[WORD:i32]], [[WORD]])
sil hidden @test1 : $@convention(thin) (@owned Optional<() -> ()>) -> () {
bb0(%0 : $Optional<() -> ()>):
// CHECK: call void @_T0SqWy
retain_value %0 : $Optional<() -> ()>
// CHECK: icmp eq i64 %0, 0
switch_enum %0 : $Optional<() -> ()>, case #Optional.some!enumelt.1: bb1, case #Optional.none!enumelt: bb2
// CHECK: [[FNPTR:%.*]] = inttoptr [[WORD]] %0 to i8*
// CHECK: [[CTX:%.*]] = inttoptr [[WORD]] %1 to %swift.refcounted*
// CHECK: br label
// CHECK: [[FNPTR2:%.*]] = phi i8* [ [[FNPTR]], {{%.*}} ]
// CHECK: [[CTX2:%.*]] = phi %swift.refcounted* [ [[CTX]], {{%.*}} ]
bb1(%1 : $() -> ()):
// CHECK: [[FNPTR3:%.*]] = bitcast i8* [[FNPTR2]] to void (%swift.refcounted*)*
// CHECK: call swiftcc void [[FNPTR3]](%swift.refcounted* swiftself [[CTX2]])
apply %1() : $() -> ()
// CHECK: br label [[CONT:%[0-9]+]]
br bb3
bb2:
%4 = function_ref @test_helper : $@convention(thin) () -> ()
apply %4() : $@convention(thin) () -> ()
// CHECK: call swiftcc void @test_helper()
// CHECK: br label [[CONT]]
br bb3
bb3:
%5 = tuple ()
// CHECK: ret void
return %5 : $()
}