Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/SIL/Instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -832,16 +832,16 @@ load-ownership-kind ::= 'take'
```

Loads the value at address `%0` from memory. `T` must be a loadable
type. This does not affect the reference count, if any, of the loaded
type. An unqualified load does not affect the reference count, if any, of the loaded
value; the value must be retained explicitly if necessary. It is
undefined behavior to load from uninitialized memory or to load from an
address that points to deallocated storage.

In OSSA the ownership kind specifies how to handle ownership:
- **trivial**: the loaded value is trivial and no further action must be taken
than to load the raw bits of the value
- **copy**: the loaded value is copied and the original value stays in the
memory location.
- **copy**: the loaded value is copied (e.g., retained) and the original value
stays in the memory location.
- **take**: the value is _moved_ from the memory location without copying.
After the `load`, the memory location remains uninitialized.

Expand Down
9 changes: 8 additions & 1 deletion lib/SIL/Utils/InstructionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
case SILInstructionKind::CopyableToMoveOnlyWrapperValueInst:
case SILInstructionKind::MoveOnlyWrapperToCopyableValueInst:
case SILInstructionKind::UncheckedOwnershipConversionInst:
case SILInstructionKind::LoadInst:
case SILInstructionKind::LoadBorrowInst:
case SILInstructionKind::BeginBorrowInst:
case SILInstructionKind::BorrowedFromInst:
Expand Down Expand Up @@ -626,6 +625,14 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
case SILInstructionKind::TypeValueInst:
case SILInstructionKind::IgnoredUseInst:
return RuntimeEffect::NoEffect;

case SILInstructionKind::LoadInst: {
if (cast<LoadInst>(inst)->getOwnershipQualifier() == LoadOwnershipQualifier::Copy) {
return ifNonTrivial(inst->getOperand(0)->getType(),
RuntimeEffect::RefCounting);
}
return RuntimeEffect::NoEffect;
}

case SILInstructionKind::OpenExistentialMetatypeInst:
case SILInstructionKind::OpenExistentialBoxInst:
Expand Down