Files
swift-mirror/test/IRGen/enum_function.sil
Xin Tong 4e46dacc3d Completely replace swift_retain_noresult with swift_retain. this is part of a series of commits
to remove reference forwarding for some of the ARC entry points. rdar://22724641. After this
commit, swift_retain_noresult will be completely replaced by swift_retain and LLVMARCOpts.cpp
will no longer canonicalize swift_retain to swift_retain_noresult as now swift_retain returns no
reference.

Swift SVN r32058
2015-09-18 01:51:17 +00:00

59 lines
2.0 KiB
Plaintext

// RUN: %target-swift-frontend -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 void @test1([[WORD:i64]], [[WORD]])
// CHECK-32: define hidden void @test1([[WORD:i32]], [[WORD]])
sil hidden @test1 : $@convention(thin) (@owned Optional<() -> ()>) -> () {
bb0(%0 : $Optional<() -> ()>):
// CHECK: [[T0:%.*]] = icmp eq [[WORD]] %0, 0
// CHECK: br i1 [[T0]], label
// CHECK: [[FNPTR:%.*]] = inttoptr [[WORD]] %0 to i8*
// CHECK: [[CTX:%.*]] = inttoptr [[WORD]] %1 to %swift.refcounted*
// CHECK: call void @swift_retain(%swift.refcounted* [[CTX]])
// CHECK: br label
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 : $@callee_owned (@out (), @in ()) -> ()):
%2 = alloc_stack $()
%3 = alloc_stack $()
// CHECK: [[FNPTR3:%.*]] = bitcast i8* [[FNPTR2]] to void (%swift.opaque*, %swift.opaque*, %swift.refcounted*)*
// CHECK: call void [[FNPTR3]](%swift.opaque* noalias nocapture sret undef, %swift.opaque* noalias nocapture undef, %swift.refcounted* [[CTX2]])
apply %1(%3#1, %2#1) : $@callee_owned (@out (), @in ()) -> ()
dealloc_stack %3#0 : $*@local_storage ()
dealloc_stack %2#0 : $*@local_storage ()
// CHECK: br label [[CONT:%[0-9]+]]
br bb3
bb2:
%4 = function_ref @test_helper : $@convention(thin) () -> ()
apply %4() : $@convention(thin) () -> ()
// CHECK: call void @test_helper()
// CHECK: br label [[CONT]]
br bb3
bb3:
%5 = tuple ()
// CHECK: ret void
return %5 : $()
}