@@ -121,63 +121,63 @@ SHOULD_NEVER_VISIT_INST(GetAsyncContinuation)
121
121
}
122
122
123
123
// Instructions that require trivial operands.
124
- OPERAND_OWNERSHIP (None , AwaitAsyncContinuation)
125
- OPERAND_OWNERSHIP(None , AbortApply)
126
- OPERAND_OWNERSHIP(None , AddressToPointer)
127
- OPERAND_OWNERSHIP(None , AllocRef) // with tail operand
128
- OPERAND_OWNERSHIP(None , AllocRefDynamic) // with tail operand
129
- OPERAND_OWNERSHIP(None , BeginAccess)
130
- OPERAND_OWNERSHIP(None , BeginUnpairedAccess)
131
- OPERAND_OWNERSHIP(None , BindMemory)
132
- OPERAND_OWNERSHIP(None , CheckedCastAddrBranch)
133
- OPERAND_OWNERSHIP(None , CondBranch)
134
- OPERAND_OWNERSHIP(None , CondFail)
135
- OPERAND_OWNERSHIP(None , CopyAddr)
136
- OPERAND_OWNERSHIP(None , DeallocStack)
137
- OPERAND_OWNERSHIP(None , DebugValueAddr)
138
- OPERAND_OWNERSHIP(None , DeinitExistentialAddr)
139
- OPERAND_OWNERSHIP(None , DestroyAddr)
140
- OPERAND_OWNERSHIP(None , EndAccess)
141
- OPERAND_OWNERSHIP(None , EndApply)
142
- OPERAND_OWNERSHIP(None , EndUnpairedAccess)
143
- OPERAND_OWNERSHIP(None , GetAsyncContinuationAddr)
144
- OPERAND_OWNERSHIP(None , IndexAddr)
145
- OPERAND_OWNERSHIP(None , IndexRawPointer)
146
- OPERAND_OWNERSHIP(None , InitBlockStorageHeader)
147
- OPERAND_OWNERSHIP(None , InitEnumDataAddr)
148
- OPERAND_OWNERSHIP(None , InitExistentialAddr)
149
- OPERAND_OWNERSHIP(None , InitExistentialMetatype)
150
- OPERAND_OWNERSHIP(None , InjectEnumAddr)
151
- OPERAND_OWNERSHIP(None , IsUnique)
152
- OPERAND_OWNERSHIP(None , Load)
153
- OPERAND_OWNERSHIP(None , LoadBorrow)
154
- OPERAND_OWNERSHIP(None , MarkFunctionEscape)
155
- OPERAND_OWNERSHIP(None , ObjCExistentialMetatypeToObject)
156
- OPERAND_OWNERSHIP(None , ObjCMetatypeToObject)
157
- OPERAND_OWNERSHIP(None , ObjCToThickMetatype)
158
- OPERAND_OWNERSHIP(None , OpenExistentialAddr)
159
- OPERAND_OWNERSHIP(None , OpenExistentialMetatype)
160
- OPERAND_OWNERSHIP(None , PointerToAddress)
161
- OPERAND_OWNERSHIP(None , PointerToThinFunction)
162
- OPERAND_OWNERSHIP(None , ProjectBlockStorage)
163
- OPERAND_OWNERSHIP(None , ProjectValueBuffer)
164
- OPERAND_OWNERSHIP(None , RawPointerToRef)
165
- OPERAND_OWNERSHIP(None , SelectEnumAddr)
166
- OPERAND_OWNERSHIP(None , SelectValue)
167
- OPERAND_OWNERSHIP(None , StructElementAddr)
168
- OPERAND_OWNERSHIP(None , SwitchEnumAddr)
169
- OPERAND_OWNERSHIP(None , SwitchValue)
170
- OPERAND_OWNERSHIP(None , TailAddr)
171
- OPERAND_OWNERSHIP(None , ThickToObjCMetatype)
172
- OPERAND_OWNERSHIP(None , ThinFunctionToPointer)
173
- OPERAND_OWNERSHIP(None , ThinToThickFunction)
174
- OPERAND_OWNERSHIP(None , TupleElementAddr)
175
- OPERAND_OWNERSHIP(None , UncheckedAddrCast)
176
- OPERAND_OWNERSHIP(None , UncheckedRefCastAddr)
177
- OPERAND_OWNERSHIP(None , UncheckedTakeEnumDataAddr)
178
- OPERAND_OWNERSHIP(None , UnconditionalCheckedCastAddr)
179
- OPERAND_OWNERSHIP(None , AllocValueBuffer)
180
- OPERAND_OWNERSHIP(None , DeallocValueBuffer)
124
+ OPERAND_OWNERSHIP (TrivialUse , AwaitAsyncContinuation)
125
+ OPERAND_OWNERSHIP(TrivialUse , AbortApply)
126
+ OPERAND_OWNERSHIP(TrivialUse , AddressToPointer)
127
+ OPERAND_OWNERSHIP(TrivialUse , AllocRef) // with tail operand
128
+ OPERAND_OWNERSHIP(TrivialUse , AllocRefDynamic) // with tail operand
129
+ OPERAND_OWNERSHIP(TrivialUse , BeginAccess)
130
+ OPERAND_OWNERSHIP(TrivialUse , BeginUnpairedAccess)
131
+ OPERAND_OWNERSHIP(TrivialUse , BindMemory)
132
+ OPERAND_OWNERSHIP(TrivialUse , CheckedCastAddrBranch)
133
+ OPERAND_OWNERSHIP(TrivialUse , CondBranch)
134
+ OPERAND_OWNERSHIP(TrivialUse , CondFail)
135
+ OPERAND_OWNERSHIP(TrivialUse , CopyAddr)
136
+ OPERAND_OWNERSHIP(TrivialUse , DeallocStack)
137
+ OPERAND_OWNERSHIP(TrivialUse , DebugValueAddr)
138
+ OPERAND_OWNERSHIP(TrivialUse , DeinitExistentialAddr)
139
+ OPERAND_OWNERSHIP(TrivialUse , DestroyAddr)
140
+ OPERAND_OWNERSHIP(TrivialUse , EndAccess)
141
+ OPERAND_OWNERSHIP(TrivialUse , EndApply)
142
+ OPERAND_OWNERSHIP(TrivialUse , EndUnpairedAccess)
143
+ OPERAND_OWNERSHIP(TrivialUse , GetAsyncContinuationAddr)
144
+ OPERAND_OWNERSHIP(TrivialUse , IndexAddr)
145
+ OPERAND_OWNERSHIP(TrivialUse , IndexRawPointer)
146
+ OPERAND_OWNERSHIP(TrivialUse , InitBlockStorageHeader)
147
+ OPERAND_OWNERSHIP(TrivialUse , InitEnumDataAddr)
148
+ OPERAND_OWNERSHIP(TrivialUse , InitExistentialAddr)
149
+ OPERAND_OWNERSHIP(TrivialUse , InitExistentialMetatype)
150
+ OPERAND_OWNERSHIP(TrivialUse , InjectEnumAddr)
151
+ OPERAND_OWNERSHIP(TrivialUse , IsUnique)
152
+ OPERAND_OWNERSHIP(TrivialUse , Load)
153
+ OPERAND_OWNERSHIP(TrivialUse , LoadBorrow)
154
+ OPERAND_OWNERSHIP(TrivialUse , MarkFunctionEscape)
155
+ OPERAND_OWNERSHIP(TrivialUse , ObjCExistentialMetatypeToObject)
156
+ OPERAND_OWNERSHIP(TrivialUse , ObjCMetatypeToObject)
157
+ OPERAND_OWNERSHIP(TrivialUse , ObjCToThickMetatype)
158
+ OPERAND_OWNERSHIP(TrivialUse , OpenExistentialAddr)
159
+ OPERAND_OWNERSHIP(TrivialUse , OpenExistentialMetatype)
160
+ OPERAND_OWNERSHIP(TrivialUse , PointerToAddress)
161
+ OPERAND_OWNERSHIP(TrivialUse , PointerToThinFunction)
162
+ OPERAND_OWNERSHIP(TrivialUse , ProjectBlockStorage)
163
+ OPERAND_OWNERSHIP(TrivialUse , ProjectValueBuffer)
164
+ OPERAND_OWNERSHIP(TrivialUse , RawPointerToRef)
165
+ OPERAND_OWNERSHIP(TrivialUse , SelectEnumAddr)
166
+ OPERAND_OWNERSHIP(TrivialUse , SelectValue)
167
+ OPERAND_OWNERSHIP(TrivialUse , StructElementAddr)
168
+ OPERAND_OWNERSHIP(TrivialUse , SwitchEnumAddr)
169
+ OPERAND_OWNERSHIP(TrivialUse , SwitchValue)
170
+ OPERAND_OWNERSHIP(TrivialUse , TailAddr)
171
+ OPERAND_OWNERSHIP(TrivialUse , ThickToObjCMetatype)
172
+ OPERAND_OWNERSHIP(TrivialUse , ThinFunctionToPointer)
173
+ OPERAND_OWNERSHIP(TrivialUse , ThinToThickFunction)
174
+ OPERAND_OWNERSHIP(TrivialUse , TupleElementAddr)
175
+ OPERAND_OWNERSHIP(TrivialUse , UncheckedAddrCast)
176
+ OPERAND_OWNERSHIP(TrivialUse , UncheckedRefCastAddr)
177
+ OPERAND_OWNERSHIP(TrivialUse , UncheckedTakeEnumDataAddr)
178
+ OPERAND_OWNERSHIP(TrivialUse , UnconditionalCheckedCastAddr)
179
+ OPERAND_OWNERSHIP(TrivialUse , AllocValueBuffer)
180
+ OPERAND_OWNERSHIP(TrivialUse , DeallocValueBuffer)
181
181
182
182
// Use an owned or guaranteed value only for the duration of the operation.
183
183
OPERAND_OWNERSHIP(InstantaneousUse, ExistentialMetatype)
@@ -263,13 +263,14 @@ OPERAND_OWNERSHIP(ForwardingBorrow, OpenExistentialBoxValue)
263
263
OPERAND_OWNERSHIP(EndBorrow, EndBorrow)
264
264
265
265
#define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
266
- OPERAND_OWNERSHIP (None , Load##Name)
266
+ OPERAND_OWNERSHIP (TrivialUse , Load##Name)
267
267
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
268
268
OPERAND_OWNERSHIP (DestroyingConsume, Name##Release)
269
269
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
270
270
NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, " ..." ) \
271
271
ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, " ..." )
272
- #define UNCHECKED_REF_STORAGE (Name, ...) OPERAND_OWNERSHIP(None, Name##ToRef)
272
+ #define UNCHECKED_REF_STORAGE (Name, ...) \
273
+ OPERAND_OWNERSHIP (TrivialUse, Name##ToRef)
273
274
#include " swift/AST/ReferenceStorage.def"
274
275
275
276
#define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
@@ -345,7 +346,7 @@ OperandOwnershipClassifier::visitBeginBorrowInst(BeginBorrowInst *borrow) {
345
346
case OwnershipKind::Any:
346
347
llvm_unreachable (" invalid value ownership" );
347
348
case OwnershipKind::None:
348
- return OperandOwnership::None ;
349
+ return OperandOwnership::TrivialUse ;
349
350
case OwnershipKind::Unowned:
350
351
// FIXME: disallow borrowing an Unowned value. Temporarily model it as an
351
352
// instantaneous use until SILGenFunction::emitClassMemberDestruction is
@@ -365,7 +366,7 @@ visitDeallocPartialRefInst(DeallocPartialRefInst *i) {
365
366
if (getValue () == i->getInstance ()) {
366
367
return OperandOwnership::DestroyingConsume;
367
368
}
368
- return OperandOwnership::None ;
369
+ return OperandOwnership::TrivialUse ;
369
370
}
370
371
371
372
OperandOwnership
@@ -395,7 +396,7 @@ OperandOwnershipClassifier::visitStoreBorrowInst(StoreBorrowInst *i) {
395
396
if (getValue () == i->getSrc ()) {
396
397
return OperandOwnership::ForwardingBorrow;
397
398
}
398
- return OperandOwnership::None ;
399
+ return OperandOwnership::TrivialUse ;
399
400
}
400
401
401
402
static OperandOwnership getFunctionArgOwnership (SILArgumentConvention argConv) {
@@ -428,7 +429,7 @@ OperandOwnershipClassifier::visitFullApply(FullApplySite apply) {
428
429
// Before considering conventions, filter all (trivial) indirect
429
430
// arguments. This also rules out result arguments.
430
431
if (getValue ()->getType ().isAddress ()) {
431
- return OperandOwnership::None ;
432
+ return OperandOwnership::TrivialUse ;
432
433
}
433
434
SILArgumentConvention argConv = apply.isCalleeOperand (op)
434
435
? SILArgumentConvention (apply.getSubstCalleeType ()->getCalleeConvention ())
@@ -472,7 +473,7 @@ OperandOwnershipClassifier::visitPartialApplyInst(PartialApplyInst *i) {
472
473
OperandOwnership OperandOwnershipClassifier::visitYieldInst (YieldInst *i) {
473
474
// Before considering conventions, filter all indirect arguments.
474
475
if (getValue ()->getType ().isAddress ()) {
475
- return OperandOwnership::None ;
476
+ return OperandOwnership::TrivialUse ;
476
477
}
477
478
auto fnType = i->getFunction ()->getLoweredFunctionType ();
478
479
SILArgumentConvention argConv (
@@ -486,7 +487,7 @@ OperandOwnership OperandOwnershipClassifier::visitReturnInst(ReturnInst *i) {
486
487
case OwnershipKind::Guaranteed:
487
488
llvm_unreachable (" invalid value ownership" );
488
489
case OwnershipKind::None:
489
- return OperandOwnership::None ;
490
+ return OperandOwnership::TrivialUse ;
490
491
case OwnershipKind::Unowned:
491
492
return OperandOwnership::UnownedInstantaneousUse;
492
493
case OwnershipKind::Owned:
@@ -496,7 +497,7 @@ OperandOwnership OperandOwnershipClassifier::visitReturnInst(ReturnInst *i) {
496
497
497
498
OperandOwnership OperandOwnershipClassifier::visitAssignInst (AssignInst *i) {
498
499
if (getValue () != i->getSrc ()) {
499
- return OperandOwnership::None ;
500
+ return OperandOwnership::TrivialUse ;
500
501
}
501
502
return OperandOwnership::DestroyingConsume;
502
503
}
@@ -507,14 +508,14 @@ OperandOwnershipClassifier::visitAssignByWrapperInst(AssignByWrapperInst *i) {
507
508
return OperandOwnership::DestroyingConsume;
508
509
}
509
510
if (getValue () == i->getDest ()) {
510
- return OperandOwnership::None ;
511
+ return OperandOwnership::TrivialUse ;
511
512
}
512
513
return OperandOwnership::InstantaneousUse; // initializer/setter closure
513
514
}
514
515
515
516
OperandOwnership OperandOwnershipClassifier::visitStoreInst (StoreInst *i) {
516
517
if (getValue () != i->getSrc ()) {
517
- return OperandOwnership::None ;
518
+ return OperandOwnership::TrivialUse ;
518
519
}
519
520
return OperandOwnership::DestroyingConsume;
520
521
}
@@ -560,7 +561,7 @@ struct OperandOwnershipBuiltinClassifier
560
561
OperandOwnership visitLLVMIntrinsic (BuiltinInst *bi, llvm::Intrinsic::ID id) {
561
562
// LLVM intrinsics do not traffic in ownership, so if we have a result, it
562
563
// must be trivial.
563
- return OperandOwnership::None ;
564
+ return OperandOwnership::TrivialUse ;
564
565
}
565
566
566
567
// BUILTIN_TYPE_CHECKER_OPERATION does not live past the type checker.
@@ -741,10 +742,10 @@ BUILTIN_OPERAND_OWNERSHIP(ForwardingBorrow, AutoDiffAllocateSubcontext)
741
742
BUILTIN_OPERAND_OWNERSHIP(ForwardingBorrow, AutoDiffProjectTopLevelSubcontext)
742
743
743
744
// FIXME: ConvertTaskToJob is documented as taking NativePointer. It's operand's
744
- // ownership should be 'None '.
745
+ // ownership should be 'TrivialUse '.
745
746
BUILTIN_OPERAND_OWNERSHIP(ForwardingConsume, ConvertTaskToJob)
746
747
747
- BUILTIN_OPERAND_OWNERSHIP(None , AutoDiffCreateLinearMapContext)
748
+ BUILTIN_OPERAND_OWNERSHIP(TrivialUse , AutoDiffCreateLinearMapContext)
748
749
749
750
#undef BUILTIN_OPERAND_OWNERSHIP
750
751
@@ -776,14 +777,12 @@ OperandOwnership OperandOwnershipClassifier::visitBuiltinInst(BuiltinInst *bi) {
776
777
// ===----------------------------------------------------------------------===//
777
778
778
779
OperandOwnership Operand::getOperandOwnership () const {
779
- // We consider type dependent uses to be instantaneous uses.
780
- //
781
- // NOTE: We could instead try to exclude type dependent uses from our system,
782
- // but that adds a bunch of Optionals and unnecessary types. This doesn't hurt
783
- // anything and allows us to eliminate Optionals and thus confusion in between
784
- // Optional::None and OwnershipKind::None.
780
+ // NOTE: NonUse distinguishes itself from InstantaneousUse because it does not
781
+ // require liveness. Discrimating such uses in the enum avoids the need to
782
+ // return an Optional<OperandOwnership>::None, which could be confused with
783
+ // OwnershipKind::None.
785
784
if (isTypeDependent ())
786
- return OperandOwnership::InstantaneousUse ;
785
+ return OperandOwnership::NonUse ;
787
786
788
787
// If we do not have ownership enabled, just return any. This ensures that we
789
788
// do not have any consuming uses and everything from an ownership perspective
0 commit comments