@@ -32,29 +32,47 @@ class DeadEndBlocks;
3232// / Returns true if v is an address or trivial.
3333bool isValueAddressOrTrivial (SILValue v);
3434
35- // / Is this an operand that can forward both owned and guaranteed ownership into
36- // / one of the operand's owner instruction's result.
37- bool isOwnershipForwardingUse (Operand *op);
38-
39- // / Is this an operand that can forward guaranteed ownership into one of the
40- // / operand's owner instruction's result.
41- bool isGuaranteedForwardingUse (Operand *op);
42-
43- // / Is this an operand that can forward owned ownership into one of the
44- // / operand's owner instruction's result.
45- bool isOwnedForwardingUse (Operand *use);
35+ // / Is the opcode that produces \p value capable of forwarding guaranteed
36+ // / values?
37+ // /
38+ // / This may be true even if the current instance of the instruction is not a
39+ // / ForwardingBorrow. If true, then the operation may be trivially rewritten
40+ // / with Guaranteed ownership.
41+ bool canOpcodeForwardGuaranteedValues (SILValue value);
4642
47- // / Is this a value that is the result of an instruction that forwards
48- // / guaranteed ownership from one of its operands.
49- bool isGuaranteedForwardingValue (SILValue value);
43+ // / Is the opcode that consumes \p use capable of forwarding guaranteed values?
44+ // /
45+ // / This may be true even if \p use is not a ForwardingBorrow. If true, then the
46+ // / operation may be trivially rewritten with Guaranteed ownership.
47+ bool canOpcodeForwardGuaranteedValues (Operand *use);
48+
49+ // This is the use-def equivalent of use->getOperandOwnership() ==
50+ // OperandOwnership::ForwardingBorrow.
51+ inline bool isForwardingBorrow (SILValue value) {
52+ assert (value.getOwnershipKind () == OwnershipKind::Guaranteed);
53+ return canOpcodeForwardGuaranteedValues (value);
54+ }
55+
56+ // / Is the opcode that produces \p value capable of forwarding owned values?
57+ // /
58+ // / This may be true even if the current instance of the instruction is not a
59+ // / ForwardingConsume. If true, then the operation may be trivially rewritten
60+ // / with Owned ownership.
61+ bool canOpcodeForwardOwnedValues (SILValue value);
5062
51- // / Is this value the result of an instruction that 'forward's owned ownership,
52- // / but may not be able to forward guaranteed ownership.
63+ // / Is this opcode that consumes \p use capable of forwarding owned values?
5364// /
54- // / This will be either a multiple value instruction resuilt, a single value
55- // / instruction that forwards or an argument that forwards the ownership from a
56- // / previous terminator.
57- bool isOwnedForwardingValue (SILValue value);
65+ // / This may be true even if the current instance of the instruction is not a
66+ // / ForwardingConsume. If true, then the operation may be trivially rewritten
67+ // / with Owned ownership.
68+ bool canOpcodeForwardOwnedValues (Operand *use);
69+
70+ // This is the use-def equivalent of use->getOperandOwnership() ==
71+ // OperandOwnership::ForwardingConsume.
72+ inline bool isForwardingConsume (SILValue value) {
73+ assert (value.getOwnershipKind () == OwnershipKind::Owned);
74+ return canOpcodeForwardOwnedValues (value);
75+ }
5876
5977class ForwardingOperand {
6078 Operand *use;
@@ -225,25 +243,6 @@ struct BorrowingOperand {
225243 llvm_unreachable (" Covered switch isn't covered?!" );
226244 }
227245
228- // / Is this a borrow scope operand that can open new borrow scopes
229- // / for owned values.
230- bool canAcceptOwnedValues () const {
231- switch (kind) {
232- // begin_borrow can take any parameter
233- case BorrowingOperandKind::BeginBorrow:
234- // Yield can implicit borrow owned values.
235- case BorrowingOperandKind::Yield:
236- // FullApplySites can implicit borrow owned values.
237- case BorrowingOperandKind::BeginApply:
238- case BorrowingOperandKind::Apply:
239- case BorrowingOperandKind::TryApply:
240- return true ;
241- case BorrowingOperandKind::Branch:
242- return false ;
243- }
244- llvm_unreachable (" Covered switch isn't covered?!" );
245- }
246-
247246 // / Is the result of this instruction also a borrow introducer?
248247 // /
249248 // / TODO: This needs a better name.
0 commit comments