@@ -842,11 +842,11 @@ inline SingleValueInstruction *SILNode::castToSingleValueInstruction() {
842
842
inst->getKind () <= SILInstructionKind::Last_##ID; \
843
843
}
844
844
845
- // / A single value inst that also forwards either owned or guaranteed ownership.
845
+ // / A single value inst that forwards a static ownership from one (or all) of
846
+ // / its operands.
846
847
// /
847
- // / The specific forwarded ownership is static since it is set upon
848
- // / construction. After that point the instruction can not have a different form
849
- // / of ownership.
848
+ // / The ownership kind is set on construction and afterwards must be changed
849
+ // / explicitly using setOwnershipKind().
850
850
class OwnershipForwardingSingleValueInst : public SingleValueInstruction {
851
851
ValueOwnershipKind ownershipKind;
852
852
@@ -5457,8 +5457,7 @@ class SelectEnumInstBase
5457
5457
NullablePtr<EnumElementDecl> getSingleTrueElement () const ;
5458
5458
};
5459
5459
5460
- // / A select enum inst that produces a static OwnershipKind set upon the
5461
- // / instruction's construction.
5460
+ // / A select enum inst that produces a static OwnershipKind.
5462
5461
class OwnershipForwardingSelectEnumInstBase : public SelectEnumInstBase {
5463
5462
ValueOwnershipKind ownershipKind;
5464
5463
@@ -6409,16 +6408,34 @@ class UncheckedOwnershipConversionInst
6409
6408
// / the base must not be moved before any instructions which depend on the
6410
6409
// / result of this instruction, exactly as if the address had been obviously
6411
6410
// / derived from that operand (e.g. using ``ref_element_addr``). The result is
6412
- // / always equal to the first operand.
6411
+ // / always equal to the first operand and thus forwards ownership through the
6412
+ // / first operand. This is a "regular" use of the second operand (i.e. the
6413
+ // / second operand must be live at the use point).
6414
+ // /
6415
+ // / Example:
6416
+ // /
6417
+ // / %base = ...
6418
+ // / %value = ... @trivial value ...
6419
+ // / %value_dependent_on_base = mark_dependence %value on %base
6420
+ // / ...
6421
+ // / use(%value_dependent_on_base) (1)
6422
+ // / ...
6423
+ // / destroy_value %base (2)
6424
+ // /
6425
+ // / (2) can never move before (1). In English this is a way for the compiler
6426
+ // / writer to say to the optimizer: 'This subset of uses of "value" (the uses of
6427
+ // / result) have a dependence on "base" being alive. Do not allow for things
6428
+ // / that /may/ destroy base to be moved earlier than any of these uses of
6429
+ // / "value"'.
6413
6430
class MarkDependenceInst
6414
6431
: public InstructionBase<SILInstructionKind::MarkDependenceInst,
6415
- SingleValueInstruction > {
6432
+ OwnershipForwardingSingleValueInst > {
6416
6433
friend SILBuilder;
6417
6434
6418
6435
FixedOperandList<2 > Operands;
6419
6436
6420
6437
MarkDependenceInst (SILDebugLocation DebugLoc, SILValue value, SILValue base)
6421
- : InstructionBase(DebugLoc, value->getType ()),
6438
+ : InstructionBase(DebugLoc, value->getType (), value.getOwnershipKind() ),
6422
6439
Operands{this , value, base} {}
6423
6440
6424
6441
public:
0 commit comments