forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum_function.sil
58 lines (48 loc) · 2.04 KB
/
enum_function.sil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// 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 : $()
}