@@ -1182,6 +1182,9 @@ class OwnershipForwardingMixin {
11821182// /
11831183// / The ownership kind is set on construction and afterwards must be changed
11841184// / explicitly using setOwnershipKind().
1185+ // /
1186+ // / TODO: This name is extremely misleading because it may apply to an
1187+ // / operation that has no operand at all, like `enum .None`.
11851188class FirstArgOwnershipForwardingSingleValueInst
11861189 : public SingleValueInstruction,
11871190 public OwnershipForwardingMixin {
@@ -1668,6 +1671,8 @@ class UnaryInstructionBase : public InstructionBase<Kind, Base> {
16681671
16691672 Operand &getOperandRef () { return Operands[0 ]; }
16701673
1674+ const Operand &getOperandRef () const { return Operands[0 ]; }
1675+
16711676 ArrayRef<Operand> getAllOperands () const { return Operands.asArray (); }
16721677 MutableArrayRef<Operand> getAllOperands () { return Operands.asArray (); }
16731678
@@ -1808,6 +1813,10 @@ class UnaryInstructionWithTypeDependentOperandsBase
18081813 return this ->getAllOperands ()[0 ];
18091814 }
18101815
1816+ const Operand &getOperandRef () const {
1817+ return this ->getAllOperands ()[0 ];
1818+ }
1819+
18111820 ArrayRef<Operand> getTypeDependentOperands () const {
18121821 return this ->getAllOperands ().slice (1 );
18131822 }
@@ -6203,6 +6212,8 @@ class EnumInst
62036212
62046213 Operand &getOperandRef () { return OptionalOperand->asArray ()[0 ]; }
62056214
6215+ const Operand &getOperandRef () const { return OptionalOperand->asArray ()[0 ]; }
6216+
62066217 ArrayRef<Operand> getAllOperands () const {
62076218 return OptionalOperand ? OptionalOperand->asArray () : ArrayRef<Operand>{};
62086219 }
@@ -8384,31 +8395,50 @@ class TermInst : public NonValueInstruction {
83848395
83858396 TermKind getTermKind () const { return TermKind (getKind ()); }
83868397
8387- // / Returns true if this is a transformation terminator.
8398+ // / Returns true if this terminator may have a result, represented as a block
8399+ // / argument in any of its successor blocks.
83888400 // /
8389- // / The first operand is the transformed source.
8390- bool isTransformationTerminator () const {
8401+ // / Phis (whose operands originate from BranchInst terminators) are not
8402+ // / terminator results.
8403+ // /
8404+ // / CondBr might produce block arguments for legacy reasons. This is gradually
8405+ // / being deprecated. For now, they are considered phis. In OSSA, these "phis"
8406+ // / must be trivial and critical edges cannot be present.
8407+ bool mayHaveTerminatorResult () const {
83918408 switch (getTermKind ()) {
83928409 case TermKind::UnwindInst:
83938410 case TermKind::UnreachableInst:
83948411 case TermKind::ReturnInst:
83958412 case TermKind::ThrowInst:
83968413 case TermKind::YieldInst:
8397- case TermKind::TryApplyInst:
8398- case TermKind::BranchInst:
83998414 case TermKind::CondBranchInst:
8400- case TermKind::SwitchValueInst :
8415+ case TermKind::BranchInst :
84018416 case TermKind::SwitchEnumAddrInst:
8402- case TermKind::DynamicMethodBranchInst:
84038417 case TermKind::CheckedCastAddrBranchInst:
8404- case TermKind::AwaitAsyncContinuationInst:
84058418 return false ;
8406- case TermKind::SwitchEnumInst:
84078419 case TermKind::CheckedCastBranchInst:
8420+ case TermKind::SwitchEnumInst:
8421+ case TermKind::SwitchValueInst:
8422+ case TermKind::TryApplyInst:
8423+ case TermKind::AwaitAsyncContinuationInst:
8424+ case TermKind::DynamicMethodBranchInst:
84088425 return true ;
84098426 }
84108427 llvm_unreachable (" Covered switch isn't covered." );
84118428 }
8429+
8430+ // / Returns an Operand reference if this terminator forwards ownership of a
8431+ // / single operand to a single result for at least one successor
8432+ // / block. Otherwise returns nullptr.
8433+ // /
8434+ // / By convention, terminators can forward ownership of at most one operand to
8435+ // / at most one result. The operand value might not be directly forwarded. For
8436+ // / example, a switch forwards ownership of the enum type into ownership of
8437+ // / the payload.
8438+ // /
8439+ // / Postcondition: each successor has zero or one block arguments which
8440+ // / represents the forwaded result.
8441+ const Operand *forwardedOperand () const ;
84128442};
84138443
84148444// Forwards the first operand to a result in each successor block.
@@ -8442,6 +8472,10 @@ class OwnershipForwardingTermInst : public TermInst,
84428472
84438473 SILValue getOperand () const { return getAllOperands ()[0 ].get (); }
84448474
8475+ Operand &getOperandRef () { return getAllOperands ()[0 ]; }
8476+
8477+ const Operand &getOperandRef () const { return getAllOperands ()[0 ]; }
8478+
84458479 // / Create a result for this terminator on the given successor block.
84468480 SILPhiArgument *createResult (SILBasicBlock *succ, SILType resultTy);
84478481};
0 commit comments