@@ -187,6 +187,17 @@ CONSTANT_OWNERSHIP_INST(Owned, LoadUnowned)
187
187
CONSTANT_OWNERSHIP_INST(Owned, LoadWeak)
188
188
CONSTANT_OWNERSHIP_INST(Owned, PartialApply)
189
189
CONSTANT_OWNERSHIP_INST(Owned, StrongPin)
190
+ CONSTANT_OWNERSHIP_INST(Owned, ThinToThickFunction)
191
+
192
+ // One would think that these /should/ be unowned. In truth they are owned since
193
+ // objc metatypes do not go through the retain/release fast path. In their
194
+ // implementations of retain/release nothing happens, so this is safe.
195
+ //
196
+ // You could even have an optimization that just always removed retain/release
197
+ // operations on these objects.
198
+ CONSTANT_OWNERSHIP_INST(Owned, ObjCExistentialMetatypeToObject)
199
+ CONSTANT_OWNERSHIP_INST(Owned, ObjCMetatypeToObject)
200
+
190
201
// All addresses have trivial ownership. The values stored at the address may
191
202
// not though.
192
203
CONSTANT_OWNERSHIP_INST(Trivial, AddressToPointer)
@@ -213,9 +224,6 @@ CONSTANT_OWNERSHIP_INST(Trivial, MarkFunctionEscape)
213
224
CONSTANT_OWNERSHIP_INST(Trivial, MarkUninitialized)
214
225
CONSTANT_OWNERSHIP_INST(Trivial, MarkUninitializedBehavior)
215
226
CONSTANT_OWNERSHIP_INST(Trivial, Metatype)
216
- CONSTANT_OWNERSHIP_INST(Trivial,
217
- ObjCExistentialMetatypeToObject) // Is this right?
218
- CONSTANT_OWNERSHIP_INST(Trivial, ObjCMetatypeToObject) // Is this right?
219
227
CONSTANT_OWNERSHIP_INST(Trivial, ObjCProtocol) // Is this right?
220
228
CONSTANT_OWNERSHIP_INST(Trivial, ObjCToThickMetatype)
221
229
CONSTANT_OWNERSHIP_INST(Trivial, OpenExistentialAddr)
@@ -238,10 +246,8 @@ CONSTANT_OWNERSHIP_INST(Trivial, SuperMethod)
238
246
CONSTANT_OWNERSHIP_INST(Trivial, TailAddr)
239
247
CONSTANT_OWNERSHIP_INST(Trivial, ThickToObjCMetatype)
240
248
CONSTANT_OWNERSHIP_INST(Trivial, ThinFunctionToPointer)
241
- CONSTANT_OWNERSHIP_INST(Trivial, ThinToThickFunction)
242
249
CONSTANT_OWNERSHIP_INST(Trivial, TupleElementAddr)
243
250
CONSTANT_OWNERSHIP_INST(Trivial, UncheckedAddrCast)
244
- CONSTANT_OWNERSHIP_INST(Trivial, UncheckedBitwiseCast)
245
251
CONSTANT_OWNERSHIP_INST(Trivial, UncheckedRefCastAddr)
246
252
CONSTANT_OWNERSHIP_INST(Trivial, UncheckedTakeEnumDataAddr)
247
253
CONSTANT_OWNERSHIP_INST(Trivial, UncheckedTrivialBitCast)
@@ -392,6 +398,35 @@ FORWARDING_OWNERSHIP_INST(UnconditionalCheckedCast)
392
398
FORWARDING_OWNERSHIP_INST(Upcast)
393
399
#undef FORWARDING_OWNERSHIP_INST
394
400
401
+ ValueOwnershipKind
402
+ ValueOwnershipKindVisitor::
403
+ visitUncheckedBitwiseCastInst (UncheckedBitwiseCastInst *UBCI) {
404
+ ValueOwnershipKind OpOwnership = UBCI->getOperand ().getOwnershipKind ();
405
+ bool ResultTypeIsTrivial = UBCI->getType ().isTrivial (UBCI->getModule ());
406
+
407
+ // First check if our operand has a trivial value ownership kind...
408
+ if (OpOwnership == ValueOwnershipKind::Trivial) {
409
+ // If we do have a trivial value ownership kind, see if our result type is
410
+ // trivial or non-trivial. If it is trivial, then we have trivial
411
+ // ownership. Otherwise, we have unowned ownership since from an ownership
412
+ // perspective, the value has instantaneously come into existance and
413
+ // nothing has taken ownership of it.
414
+ if (ResultTypeIsTrivial) {
415
+ return ValueOwnershipKind::Trivial;
416
+ }
417
+ return ValueOwnershipKind::Unowned;
418
+ }
419
+
420
+ // If our operand has non-trivial ownership, but our result does, then of
421
+ // course the result has trivial ownership.
422
+ if (ResultTypeIsTrivial) {
423
+ return ValueOwnershipKind::Trivial;
424
+ }
425
+
426
+ // Otherwise, we forward our ownership.
427
+ return visitForwardingInst (UBCI);
428
+ }
429
+
395
430
// An enum without payload is trivial. One with non-trivial payload is
396
431
// forwarding.
397
432
ValueOwnershipKind
0 commit comments