@@ -515,6 +515,16 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
515
515
// / result index, or None if it is not defined by an instruction.
516
516
Optional<DefiningInstructionResult> getDefiningInstructionResult ();
517
517
518
+ // / Returns the ValueOwnershipKind that describes this SILValue's ownership
519
+ // / semantics if the SILValue has ownership semantics. Returns is a value
520
+ // / without any Ownership Semantics.
521
+ // /
522
+ // / An example of a SILValue without ownership semantics is a
523
+ // / struct_element_addr.
524
+ // /
525
+ // / NOTE: This is implemented in ValueOwnership.cpp not SILValue.cpp.
526
+ ValueOwnershipKind getOwnershipKind () const ;
527
+
518
528
static bool classof (SILNodePointer node) {
519
529
return node->getKind () >= SILNodeKind::First_ValueBase &&
520
530
node->getKind () <= SILNodeKind::Last_ValueBase;
@@ -592,6 +602,8 @@ class SILValue {
592
602
593
603
// / If this SILValue is a result of an instruction, return its
594
604
// / defining instruction. Returns nullptr otherwise.
605
+ // /
606
+ // / FIXME: remove this redundant API from SILValue.
595
607
SILInstruction *getDefiningInstruction () {
596
608
return Value->getDefiningInstruction ();
597
609
}
@@ -610,7 +622,11 @@ class SILValue {
610
622
// / struct_element_addr.
611
623
// /
612
624
// / NOTE: This is implemented in ValueOwnership.cpp not SILValue.cpp.
613
- ValueOwnershipKind getOwnershipKind () const ;
625
+ // /
626
+ // / FIXME: remove this redundant API from SILValue.
627
+ ValueOwnershipKind getOwnershipKind () const {
628
+ return Value->getOwnershipKind ();
629
+ }
614
630
615
631
// / Verify that this SILValue and its uses respects ownership invariants.
616
632
void verifyOwnership (DeadEndBlocks *DEBlocks) const ;
@@ -660,6 +676,11 @@ class OwnershipConstraint {
660
676
return lifetimeConstraint;
661
677
}
662
678
679
+ bool isConsuming () const {
680
+ return ownershipKind == OwnershipKind::Owned
681
+ && lifetimeConstraint == UseLifetimeConstraint::LifetimeEnding;
682
+ }
683
+
663
684
bool satisfiedBy (const Operand *use) const ;
664
685
665
686
bool satisfiesConstraint (ValueOwnershipKind testKind) const {
@@ -880,15 +901,20 @@ inline bool canAcceptUnownedValue(OperandOwnership operandOwnership) {
880
901
}
881
902
}
882
903
883
- // / Return the OperandOwnership for a forwarded operand when the forwarded
884
- // / result has this ValueOwnershipKind. \p allowUnowned is true for a subset
885
- // / of forwarding operations that are allowed to propagate Unowned values.
904
+ // / Return the OperandOwnership for a forwarded operand when the forwarding
905
+ // / operation has this "forwarding ownership" (as returned by
906
+ // / getForwardingOwnershipKind()). \p allowUnowned is true for a subset of
907
+ // / forwarding operations that are allowed to propagate Unowned values.
908
+ // /
909
+ // / Forwarding ownership is determined by the forwarding instruction's constant
910
+ // / ownership attribute. If forwarding ownership is owned, then the instruction
911
+ // / moves owned operand to its result, ending its lifetime. If forwarding
912
+ // / ownership is guaranteed, then the instruction propagates the lifetime of its
913
+ // / borrows operand through its result.
886
914
// /
887
- // / The ownership of a forwarded value is derived from the forwarding
888
- // / instruction's constant ownership attribute. If the result is owned, then the
889
- // / instruction moves owned operand to its result, ending its lifetime. If the
890
- // / result is guaranteed value, then the instruction propagates the lifetime of
891
- // / its borrows operand through its result.
915
+ // / The resulting forwarded value typically has forwarding ownership, but may
916
+ // / differ when the result is trivial type. e.g. an owned or guaranteed value
917
+ // / can be cast to a trivial type using owned or guaranteed forwarding.
892
918
inline OperandOwnership
893
919
ValueOwnershipKind::getForwardingOperandOwnership (bool allowUnowned) const {
894
920
switch (value) {
0 commit comments