forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum_value_semantics_special_cases.sil
199 lines (177 loc) · 11.2 KB
/
enum_value_semantics_special_cases.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// RUN: %target-swift-frontend %s -emit-ir | FileCheck %s
// REQUIRES: CPU=x86_64
import Builtin
// Enums consisting of a retainable pointer and a single empty case use nullable
// pointer value semantics.
enum NullableRefcounted {
case Ref(Builtin.NativeObject)
case None
}
// CHECK-LABEL: define linkonce_odr hidden void @_TwxxO34enum_value_semantics_special_cases18NullableRefcounted(%swift.opaque* %object, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %object to %O34enum_value_semantics_special_cases18NullableRefcounted*
// CHECK: %1 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %0 to %swift.refcounted**
// CHECK: %2 = load %swift.refcounted*, %swift.refcounted** %1, align 8
// CHECK: call void @swift_release(%swift.refcounted* %2) {{#[0-9]+}}
// CHECK: ret void
// CHECK: }
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @_TwcpO34enum_value_semantics_special_cases18NullableRefcounted(%swift.opaque* %dest, %swift.opaque* %src, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %dest to %O34enum_value_semantics_special_cases18NullableRefcounted*
// CHECK: %1 = bitcast %swift.opaque* %src to %O34enum_value_semantics_special_cases18NullableRefcounted*
// CHECK: %2 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %0 to %swift.refcounted**
// CHECK: %3 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %1 to %swift.refcounted**
// CHECK: %4 = load %swift.refcounted*, %swift.refcounted** %3, align 8
// CHECK: call void @swift_retain(%swift.refcounted* %4) {{#[0-9]+}}
// CHECK: store %swift.refcounted* %4, %swift.refcounted** %2, align 8
// CHECK: %5 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %0 to %swift.opaque*
// CHECK: ret %swift.opaque* %5
// CHECK: }
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @_TwcaO34enum_value_semantics_special_cases18NullableRefcounted(%swift.opaque* %dest, %swift.opaque* %src, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %dest to %O34enum_value_semantics_special_cases18NullableRefcounted*
// CHECK: %1 = bitcast %swift.opaque* %src to %O34enum_value_semantics_special_cases18NullableRefcounted*
// CHECK: %2 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %0 to %swift.refcounted**
// CHECK: %3 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %1 to %swift.refcounted**
// CHECK: %4 = load %swift.refcounted*, %swift.refcounted** %2, align 8
// CHECK: %5 = load %swift.refcounted*, %swift.refcounted** %3, align 8
// CHECK: call void @swift_retain(%swift.refcounted* %5) {{#[0-9]+}}
// CHECK: store %swift.refcounted* %5, %swift.refcounted** %2, align 8
// CHECK: call void @swift_release(%swift.refcounted* %4) {{#[0-9]+}}
// CHECK: %6 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %0 to %swift.opaque*
// CHECK: ret %swift.opaque* %6
// CHECK: }
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @_TwtaO34enum_value_semantics_special_cases18NullableRefcounted(%swift.opaque* %dest, %swift.opaque* %src, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %dest to %O34enum_value_semantics_special_cases18NullableRefcounted*
// CHECK: %1 = bitcast %swift.opaque* %src to %O34enum_value_semantics_special_cases18NullableRefcounted*
// CHECK: %2 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %0 to %swift.refcounted**
// CHECK: %3 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %1 to %swift.refcounted**
// CHECK: %4 = load %swift.refcounted*, %swift.refcounted** %2, align 8
// CHECK: %5 = load %swift.refcounted*, %swift.refcounted** %3, align 8
// CHECK: store %swift.refcounted* %5, %swift.refcounted** %2, align 8
// CHECK: call void @swift_release(%swift.refcounted* %4) {{#[0-9]+}}
// CHECK: %6 = bitcast %O34enum_value_semantics_special_cases18NullableRefcounted* %0 to %swift.opaque*
// CHECK: ret %swift.opaque* %6
// CHECK: }
// Enums consisting of a retainable block pointer and a single empty case use
// nullable block pointer value semantics.
enum NullableBlockRefcounted {
case Ref(@convention(block) () -> ())
case None
}
// CHECK-LABEL: define linkonce_odr hidden void @_TwxxO34enum_value_semantics_special_cases23NullableBlockRefcounted(%swift.opaque* %object, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %object to %O34enum_value_semantics_special_cases23NullableBlockRefcounted*
// CHECK: %1 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %0 to %objc_block**
// CHECK: %2 = load %objc_block*, %objc_block** %1, align 8
// CHECK: call void @_Block_release(%objc_block* %2) {{#[0-9]+}}
// CHECK: ret void
// CHECK: }
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @_TwcpO34enum_value_semantics_special_cases23NullableBlockRefcounted(%swift.opaque* %dest, %swift.opaque* %src, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %dest to %O34enum_value_semantics_special_cases23NullableBlockRefcounted*
// CHECK: %1 = bitcast %swift.opaque* %src to %O34enum_value_semantics_special_cases23NullableBlockRefcounted*
// CHECK: %2 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %0 to %objc_block**
// CHECK: %3 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %1 to %objc_block**
// CHECK: %4 = load %objc_block*, %objc_block** %3, align 8
// CHECK: %5 = call %objc_block* @_Block_copy(%objc_block* %4)
// CHECK: store %objc_block* %4, %objc_block** %2, align 8
// CHECK: %6 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %0 to %swift.opaque*
// CHECK: ret %swift.opaque* %6
// CHECK: }
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @_TwcaO34enum_value_semantics_special_cases23NullableBlockRefcounted(%swift.opaque* %dest, %swift.opaque* %src, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %dest to %O34enum_value_semantics_special_cases23NullableBlockRefcounted*
// CHECK: %1 = bitcast %swift.opaque* %src to %O34enum_value_semantics_special_cases23NullableBlockRefcounted*
// CHECK: %2 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %0 to %objc_block**
// CHECK: %3 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %1 to %objc_block**
// CHECK: %4 = load %objc_block*, %objc_block** %2, align 8
// CHECK: %5 = load %objc_block*, %objc_block** %3, align 8
// CHECK: %6 = call %objc_block* @_Block_copy(%objc_block* %5)
// CHECK: store %objc_block* %5, %objc_block** %2, align 8
// CHECK: call void @_Block_release(%objc_block* %4) {{#[0-9]+}}
// CHECK: %7 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %0 to %swift.opaque*
// CHECK: ret %swift.opaque* %7
// CHECK: }
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @_TwtaO34enum_value_semantics_special_cases23NullableBlockRefcounted(%swift.opaque* %dest, %swift.opaque* %src, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %dest to %O34enum_value_semantics_special_cases23NullableBlockRefcounted*
// CHECK: %1 = bitcast %swift.opaque* %src to %O34enum_value_semantics_special_cases23NullableBlockRefcounted*
// CHECK: %2 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %0 to %objc_block**
// CHECK: %3 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %1 to %objc_block**
// CHECK: %4 = load %objc_block*, %objc_block** %2, align 8
// CHECK: %5 = load %objc_block*, %objc_block** %3, align 8
// CHECK: store %objc_block* %5, %objc_block** %2, align 8
// CHECK: call void @_Block_release(%objc_block* %4) {{#[0-9]+}}
// CHECK: %6 = bitcast %O34enum_value_semantics_special_cases23NullableBlockRefcounted* %0 to %swift.opaque*
// CHECK: ret %swift.opaque* %6
// CHECK: }
// With multiple empty cases, the nullable pointer semantics aren't used.
enum MultipleEmptyRefcounted {
case Ref(Builtin.NativeObject)
case A
case B
}
// CHECK-LABEL: define linkonce_odr hidden void @_TwxxO34enum_value_semantics_special_cases23MultipleEmptyRefcounted(%swift.opaque* %object, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %object to %O34enum_value_semantics_special_cases23MultipleEmptyRefcounted*
// CHECK: %1 = bitcast %O34enum_value_semantics_special_cases23MultipleEmptyRefcounted* %0 to i64*
// CHECK: %2 = load i64, i64* %1, align 8
// CHECK: switch i64 %2, label %3 [
// CHECK: i64 0, label %5
// CHECK: i64 2, label %5
// CHECK: ]
// CHECK: ; <label>:3 ; preds = %entry
// CHECK: %4 = bitcast %O34enum_value_semantics_special_cases23MultipleEmptyRefcounted* %0 to %swift.refcounted**
// CHECK: %toDestroy = load %swift.refcounted*, %swift.refcounted** %4, align 8
// CHECK: call void @swift_release(%swift.refcounted* %toDestroy) {{#[0-9]+}}
// CHECK: br label %5
// CHECK: ; <label>:5 ; preds = %3, %entry, %entry
// CHECK: ret void
// CHECK: }
// Enums consisting of all retainable pointers and at most one empty case
// use tagged pointer value semantics—we mask off the tag bits and pass the
// pointer to the r/r functions.
class C {}
sil_vtable C {}
class D {}
sil_vtable D {}
sil @_TFC34enum_value_semantics_special_cases1CD : $@convention(method) (C) -> ()
sil @_TFC34enum_value_semantics_special_cases1DD : $@convention(method) (D) -> ()
enum AllRefcounted {
case Ref(Builtin.NativeObject)
case CRef(C)
case DRef(D)
case None
}
// CHECK-LABEL: define linkonce_odr hidden void @_TwxxO34enum_value_semantics_special_cases13AllRefcounted(%swift.opaque* %object, %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %object to %O34enum_value_semantics_special_cases13AllRefcounted*
// CHECK: %1 = bitcast %O34enum_value_semantics_special_cases13AllRefcounted* %0 to i64*
// CHECK: %2 = load i64, i64* %1, align 8
// -- 0x3fffffffffffffff
// CHECK: %3 = and i64 %2, 4611686018427387903
// CHECK: %4 = inttoptr i64 %3 to %swift.refcounted*
// CHECK: call void @swift_release(%swift.refcounted* %4) {{#[0-9]+}}
// CHECK: ret void
// CHECK: }
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @_TwcpO34enum_value_semantics_special_cases13AllRefcounted(%swift.opaque* %dest, %swift.opaque* %src, %swift.type* %Self) {{.*}} {
// CHECK: %3 = load i64, i64* %2, align 8
// -- 0x3fffffffffffffff
// CHECK: %4 = and i64 %3, 4611686018427387903
// CHECK: %5 = inttoptr i64 %4 to %swift.refcounted*
// CHECK: call void @swift_retain(%swift.refcounted* %5) #1
// CHECK: %6 = bitcast %O34enum_value_semantics_special_cases13AllRefcounted* %0 to i64*
// -- NB: The original loaded value is stored, not the masked one.
// CHECK: store i64 %3, i64* %6, align 8
// CHECK: }
enum AllRefcountedTwoSimple {
case Ref(Builtin.NativeObject)
case CRef(C)
case DRef(D)
case None
case Nothing
}
// CHECK-LABEL: define linkonce_odr hidden void @_TwxxO34enum_value_semantics_special_cases22AllRefcountedTwoSimple
// CHECK: switch