forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum_value_semantics.sil
251 lines (232 loc) · 12.8 KB
/
enum_value_semantics.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// RUN: %target-swift-frontend %s -gnone -emit-ir | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
// REQUIRES: CPU=x86_64
import Builtin
// CHECK: @_TWVO20enum_value_semantics20SinglePayloadTrivial = constant [25 x i8*] [
// CHECK: i8* bitcast (void (i8*, %swift.type*)* @__swift_noop_void_return to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy9_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, %swift.type*)* @__swift_noop_self_return to i8*),
// CHECK: i8* bitcast (void (i8*, %swift.type*)* @__swift_noop_void_return to i8*),
// CHECK: i8* bitcast (void (i8*, %swift.type*)* @__swift_noop_void_return to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy9_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy9_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy9_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy9_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy9_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy9_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, %swift.type*)* @__swift_noop_self_return to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy9_8 to i8*),
// CHECK: i8* bitcast (void (i8*, %swift.type*)* @__swift_noop_void_return to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, i64, %swift.type*)* @__swift_memcpy_array16_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, i64, %swift.type*)* @__swift_memmove_array16_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, i64, %swift.type*)* @__swift_memmove_array16_8 to i8*),
// CHECK: i8* inttoptr (i64 9 to i8*),
// CHECK: i8* inttoptr (i64 2097159 to i8*),
// CHECK: i8* inttoptr (i64 16 to i8*),
// CHECK: i8* null,
// CHECK: i8* null,
// CHECK: i8* null,
// CHECK: i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @_TwugO20enum_value_semantics20SinglePayloadTrivial to i8*),
// CHECK: i8* bitcast (void (%swift.opaque*, %swift.type*)* @_TwupO20enum_value_semantics20SinglePayloadTrivial to i8*)
// CHECK: ]
// CHECK: @_TMfO20enum_value_semantics20SinglePayloadTrivial = internal constant { {{.*}}* } {
// CHECK: i8** getelementptr inbounds ([25 x i8*], [25 x i8*]* @_TWVO20enum_value_semantics20SinglePayloadTrivial, i32 0, i32 0),
// CHECK: i64 2,
// CHECK: {{.*}}* @_TMnO20enum_value_semantics20SinglePayloadTrivial,
// CHECK: %swift.type* null
// CHECK: }
// CHECK: @_TWVO20enum_value_semantics23SinglePayloadNontrivial = constant [25 x i8*] [
// CHECK: i8* bitcast (void ([24 x i8]*, %swift.type*)* @_TwXXO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (%swift.opaque* ([24 x i8]*, [24 x i8]*, %swift.type*)* @_TwCPO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (i8* (i8*, %swift.type*)* @__swift_noop_self_return to i8*),
// CHECK: i8* bitcast (void (i8*, %swift.type*)* @__swift_noop_void_return to i8*),
// CHECK: i8* bitcast (void (%swift.opaque*, %swift.type*)* @_TwxxO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (%swift.opaque* ([24 x i8]*, %swift.opaque*, %swift.type*)* @_TwCpO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (%swift.opaque* (%swift.opaque*, %swift.opaque*, %swift.type*)* @_TwcpO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (%swift.opaque* (%swift.opaque*, %swift.opaque*, %swift.type*)* @_TwcaO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy8_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy8_8 to i8*),
// CHECK: i8* bitcast (%swift.opaque* (%swift.opaque*, %swift.opaque*, %swift.type*)* @_TwtaO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (i8* (i8*, %swift.type*)* @__swift_noop_self_return to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy8_8 to i8*),
// CHECK: i8* bitcast (void (%swift.opaque*, i64, %swift.type*)* @_TwXxO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (%swift.opaque* (%swift.opaque*, %swift.opaque*, i64, %swift.type*)* @_TwCcO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, i64, %swift.type*)* @__swift_memmove_array8_8 to i8*),
// CHECK: i8* bitcast (i8* (i8*, i8*, i64, %swift.type*)* @__swift_memmove_array8_8 to i8*),
// CHECK: i8* inttoptr (i64 8 to i8*),
// -- 0x250007
// CHECK: i8* inttoptr (i64 2424839 to i8*),
// CHECK: i8* inttoptr (i64 8 to i8*),
// -- on Darwin, first 4GB are unmapped: 0x7ffffffc
// -- on Linux, only safe to assume first 4KB: 0x7fd
// CHECK: i8* inttoptr (i64 {{2045|2147483644}} to i8*)
// CHECK: i8* bitcast (void (%swift.opaque*, i32, %swift.type*)* @_TwxsO20enum_value_semantics23SinglePayloadNontrivial to i8*)
// CHECK: i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @_TwxgO20enum_value_semantics23SinglePayloadNontrivial to i8*)
// CHECK: i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @_TwugO20enum_value_semantics23SinglePayloadNontrivial to i8*),
// CHECK: i8* bitcast (void (%swift.opaque*, %swift.type*)* @_TwupO20enum_value_semantics23SinglePayloadNontrivial to i8*)
// CHECK: ]
// CHECK: @_TMfO20enum_value_semantics23SinglePayloadNontrivial = internal constant { {{.*}}* } {
// CHECK: i8** getelementptr inbounds ([25 x i8*], [25 x i8*]* @_TWVO20enum_value_semantics23SinglePayloadNontrivial, i32 0, i32 0),
// CHECK: i64 2,
// CHECK: {{.*}}* @_TMnO20enum_value_semantics23SinglePayloadNontrivial,
// CHECK: %swift.type* null
// CHECK: }
// CHECK: @_TMPO20enum_value_semantics18GenericFixedLayout = global {{[{].*\* [}]}} {
// CHECK: %swift.type* (%swift.type_pattern*, i8**)* @create_generic_metadata_GenericFixedLayout
// CHECK: i32 48, i16 1, i16 8,
// CHECK: [16 x i8*] zeroinitializer,
// CHECK: i8** getelementptr inbounds ([25 x i8*], [25 x i8*]* @_TWVO20enum_value_semantics18GenericFixedLayout, i32 0, i32 0),
// CHECK: i64 2,
// CHECK: {{.*}}* @_TMnO20enum_value_semantics18GenericFixedLayout,
// CHECK: %swift.type* null,
// CHECK: %swift.type* null,
// CHECK: %swift.type** null
// CHECK: }
enum NoPayload {
case a
case b
case c
}
enum SinglePayloadTrivial {
case payload(Builtin.Int64)
case a
case b
case c
}
enum SinglePayloadNontrivial {
case payload(Builtin.NativeObject)
case a
case b
case c
}
sil @single_payload_nontrivial_copy_destroy : $(SinglePayloadNontrivial) -> () {
bb0(%0 : $SinglePayloadNontrivial):
retain_value %0 : $SinglePayloadNontrivial
release_value %0 : $SinglePayloadNontrivial
%v = tuple ()
return %v : $()
}
// CHECK: define void @single_payload_nontrivial_copy_destroy(i64)
// CHECK: switch i64 %0, label [[PRESENT:%.*]] [
// CHECK-NEXT: i64 0, label [[NOT_PRESENT:%.*]]
// CHECK-NEXT: i64 2, label [[NOT_PRESENT]]
// CHECK-NEXT: i64 4, label [[NOT_PRESENT]]
// CHECK-NEXT: ]
// CHECK: [[T0:%.*]] = inttoptr i64 [[V:%.*]] to %swift.refcounted*
// CHECK-NEXT: call void @swift_retain(%swift.refcounted* [[T0]])
// CHECK-NEXT: br label [[NOT_PRESENT]]
// CHECK: switch i64 %0, label [[PRESENT:%.*]] [
// CHECK-NEXT: i64 0, label [[NOT_PRESENT:%.*]]
// CHECK-NEXT: i64 2, label [[NOT_PRESENT]]
// CHECK-NEXT: i64 4, label [[NOT_PRESENT]]
// CHECK-NEXT: ]
// CHECK: [[T0:%.*]] = inttoptr i64 [[V:%.*]] to %swift.refcounted*
// CHECK-NEXT: call void @swift_release(%swift.refcounted* [[T0]])
// CHECK-NEXT: br label [[NOT_PRESENT]]
// CHECK: ret void
// -- NoPayload getExtraInhabitants
// CHECK: define linkonce_odr hidden i32 @_TwxgO20enum_value_semantics9NoPayload
// CHECK: [[VALUE:%.*]] = load i8, i8* {{%.*}}, align 1
// CHECK: [[ZEXT:%.*]] = zext i8 [[VALUE]] to i32
// CHECK: [[SUB:%.*]] = sub i32 [[ZEXT]], 3
// CHECK: [[EXTRA:%.*]] = icmp slt i32 [[SUB]], 0
// CHECK: [[RES:%.*]] = select i1 [[EXTRA]], i32 -1, i32 [[SUB]]
// CHECK: ret i32 [[RES]]
// -- SinglePayloadNontrivial destroyBuffer
// CHECK: define linkonce_odr hidden void @_TwxxO20enum_value_semantics23SinglePayloadNontrivial(%swift.opaque* [[OBJ:%.*]], %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: [[ADDR:%.*]] = bitcast %swift.opaque* [[OBJ]] to %O20enum_value_semantics23SinglePayloadNontrivial*
// CHECK: [[PAYLOAD_ADDR:%.*]] = bitcast %O20enum_value_semantics23SinglePayloadNontrivial* [[ADDR]] to i64*
// CHECK: [[PAYLOAD:%.*]] = load i64, i64* [[PAYLOAD_ADDR]], align 8
// CHECK: switch i64 %2, label %[[RELEASE_PAYLOAD:[0-9]+]] [
// CHECK: i64 0, label %[[DONE:[0-9]+]]
// CHECK: i64 2, label %[[DONE]]
// CHECK: i64 4, label %[[DONE]]
// CHECK: ]
// CHECK: ; <label>:[[RELEASE_PAYLOAD]]
// CHECK: [[DATA_ADDR:%.*]] = bitcast %O20enum_value_semantics23SinglePayloadNontrivial* [[ADDR]] to %swift.refcounted**
// CHECK: [[DATA:%.*]] = load %swift.refcounted*, %swift.refcounted** [[DATA_ADDR]], align 8
// CHECK: call void @swift_release(%swift.refcounted* [[DATA]])
// CHECK: br label %[[DONE]]
// CHECK: ; <label>:[[DONE]]
// CHECK: ret void
// CHECK: }
enum MultiPayloadTrivial {
case payload1(Builtin.Int64)
case payload2(Builtin.Int32, Builtin.Int32)
case a
case b
case c
}
enum MultiPayloadNontrivial {
case payload1(Builtin.NativeObject)
case payload2(Builtin.Int64)
case payload3(Builtin.Int64, Builtin.UnknownObject)
case payload4(Builtin.Int64, Builtin.Int64)
case a
case b
case c
}
// -- MultiPayloadNontrivial destroyBuffer
// CHECK: define linkonce_odr hidden void @_TwxxO20enum_value_semantics22MultiPayloadNontrivial(%swift.opaque* [[OBJ:%.*]], %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: [[ADDR:%.*]] = bitcast %swift.opaque* [[OBJ]] to %O20enum_value_semantics22MultiPayloadNontrivial*
// CHECK: [[PAYLOAD_ADDR:%.*]] = bitcast %O20enum_value_semantics22MultiPayloadNontrivial* [[ADDR]] to { i64, i64 }*
// CHECK: [[PAYLOAD_0_ADDR:%.*]] = getelementptr
// CHECK: [[PAYLOAD_0:%.*]] = load i64, i64* [[PAYLOAD_0_ADDR]], align 8
// CHECK: [[PAYLOAD_1_ADDR:%.*]] = getelementptr
// CHECK: [[PAYLOAD_1:%.*]] = load i64, i64* [[PAYLOAD_1_ADDR]], align 8
// CHECK: [[T0:%.*]] = getelementptr inbounds %O20enum_value_semantics22MultiPayloadNontrivial, %O20enum_value_semantics22MultiPayloadNontrivial* %0, i32 0, i32 1
// CHECK: [[TAG_ADDR:%.*]] = bitcast [1 x i8]* [[T0]] to i3*
// CHECK: [[TAG:%.*]] = load i3, i3* [[TAG_ADDR]], align 8
// CHECK: switch i3 [[TAG]], label %[[END:[0-9]+]] [
// CHECK: i3 0, label %[[PAYLOAD1_DESTROY:[0-9]+]]
// CHECK: i3 2, label %[[PAYLOAD3_DESTROY:[0-9]+]]
// CHECK: ]
// CHECK: ; <label>:[[PAYLOAD1_DESTROY]]
// CHECK: [[PAYLOAD1_VAL:%.*]] = inttoptr i64 [[PAYLOAD_0]] to %swift.refcounted*
// CHECK: call void @swift_release(%swift.refcounted* [[PAYLOAD1_VAL]])
// CHECK: br label %[[END]]
// CHECK: ; <label>:[[PAYLOAD3_DESTROY]]
// CHECK: [[PAYLOAD3_1_VAL:%.*]] = inttoptr i64 [[PAYLOAD_1]] to %objc_object*
// CHECK: call void @objc_release(%objc_object* [[PAYLOAD3_1_VAL]])
// CHECK: br label %[[END]]
// CHECK: ; <label>:[[END]]
// CHECK: ret void
// CHECK: }
enum MultiPayloadNontrivialSpareBits {
case payload1(Builtin.NativeObject)
case payload2(Builtin.Int64)
case payload3(Builtin.Int64, Builtin.UnknownObject)
case a
case b
case c
}
// -- MultiPayloadNontrivialSpareBits destroyBuffer
// CHECK: define linkonce_odr hidden void @_TwxxO20enum_value_semantics31MultiPayloadNontrivialSpareBits(%swift.opaque* [[OBJ:%.*]], %swift.type* %Self) {{.*}} {
// CHECK: entry:
// CHECK: [[ADDR:%.*]] = bitcast %swift.opaque* [[OBJ]] to %O20enum_value_semantics31MultiPayloadNontrivialSpareBits*
// CHECK: [[PAYLOAD_ADDR:%.*]] = bitcast %O20enum_value_semantics31MultiPayloadNontrivialSpareBits* [[ADDR]] to { i64, i64 }*
// CHECK: [[PAYLOAD_0_ADDR:%.*]] = getelementptr
// CHECK: [[PAYLOAD_0:%.*]] = load i64, i64* [[PAYLOAD_0_ADDR]], align 8
// CHECK: [[PAYLOAD_1_ADDR:%.*]] = getelementptr
// CHECK: [[PAYLOAD_1:%.*]] = load i64, i64* [[PAYLOAD_1_ADDR]], align 8
// CHECK: switch i2 [[SPARE_BITS:%.*]], label %[[END:[0-9]+]] [
// CHECK: i2 0, label %[[PAYLOAD1_DESTROY:[0-9]+]]
// CHECK: i2 -2, label %[[PAYLOAD3_DESTROY:[0-9]+]]
// CHECK: ]
// CHECK: ; <label>:[[PAYLOAD1_DESTROY]]
// CHECK: [[PAYLOAD1_VAL:%.*]] = inttoptr i64 [[PAYLOAD_0]] to %swift.refcounted*
// CHECK: call void @swift_release(%swift.refcounted* [[PAYLOAD1_VAL]])
// CHECK: br label %[[END]]
// CHECK: ; <label>:[[PAYLOAD3_DESTROY]]
// CHECK: [[MASKED:%.*]] = and i64 [[PAYLOAD_1]]
// CHECK: [[PAYLOAD3_1_VAL:%.*]] = inttoptr i64 [[MASKED]] to %objc_object*
// CHECK: call void @objc_release(%objc_object* [[PAYLOAD3_1_VAL]])
// CHECK: br label %[[END]]
// CHECK: ; <label>:[[END]]
// CHECK: ret void
// CHECK: }
enum GenericFixedLayout<T> {
case foo(Builtin.Int64)
case bar(Builtin.NativeObject)
}