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
40 changes: 26 additions & 14 deletions include/swift/SIL/OwnershipUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ inline bool isForwardingConsume(SILValue value) {
return canOpcodeForwardOwnedValues(value);
}

/// Find all "use points" of \p guaranteedValue that determine its lifetime
/// requirement.
/// Find leaf "use points" of \p guaranteedValue that determine its lifetime
/// requirement. If \p usePoints is nullptr, then the simply returns true if no
/// PointerEscape use was found.
///
/// Precondition: \p guaranteedValue is not a BorrowedValue.
///
Expand All @@ -99,10 +100,10 @@ inline bool isForwardingConsume(SILValue value) {
/// When this is called on a value that does not introduce a new scope, none of
/// the use points can be EndBorrows or Reborrows. Those uses are only allowed
/// on borrow-introducing values.
bool findInnerTransitiveGuaranteedUses(SILValue guaranteedValue,
SmallVectorImpl<Operand *> &usePoints);
bool findInnerTransitiveGuaranteedUses(
SILValue guaranteedValue, SmallVectorImpl<Operand *> *usePoints = nullptr);

/// Find all "use points" of a guaranteed value within its enclosing borrow
/// Find leaf "use points" of a guaranteed value within its enclosing borrow
/// scope (without looking through reborrows). To find the use points of the
/// extended borrow scope, after looking through reborrows, use
/// findExtendedTransitiveGuaranteedUses() instead.
Expand Down Expand Up @@ -662,12 +663,19 @@ bool getAllBorrowIntroducingValues(SILValue value,
/// introducer, then we return a .some(BorrowScopeIntroducingValue).
BorrowedValue getSingleBorrowIntroducingValue(SILValue inputValue);

enum class AddressUseKind { NonEscaping, PointerEscape, Unknown };

inline AddressUseKind meet(AddressUseKind lhs, AddressUseKind rhs) {
return (lhs > rhs) ? lhs : rhs;
}

/// The algorithm that is used to determine what the verifier will consider to
/// be transitive uses of the given address. Used to implement \see
/// findTransitiveUses.
bool findTransitiveUsesForAddress(
SILValue address, SmallVectorImpl<Operand *> &foundUses,
std::function<void(Operand *)> *onError = nullptr);
AddressUseKind
findTransitiveUsesForAddress(SILValue address,
SmallVectorImpl<Operand *> *foundUses = nullptr,
std::function<void(Operand *)> *onError = nullptr);

class InteriorPointerOperandKind {
public:
Expand Down Expand Up @@ -834,15 +842,19 @@ struct InteriorPointerOperand {
llvm_unreachable("Covered switch isn't covered?!");
}

/// Transitively compute the list of uses that this interior pointer operand
/// puts on its parent guaranted value.
/// Transitively compute the list of leaf uses that this interior pointer
/// operand puts on its parent guaranted value.
///
/// If \p foundUses is nullptr, this simply returns true if no PointerEscapes
/// were found.
///
/// Example: Uses of a ref_element_addr can not occur outside of the lifetime
/// of the instruction's operand. The uses of that address act as liveness
/// requirements to ensure that the underlying class is alive at all use
/// points.
bool findTransitiveUses(SmallVectorImpl<Operand *> &foundUses,
std::function<void(Operand *)> *onError = nullptr) {
AddressUseKind
findTransitiveUses(SmallVectorImpl<Operand *> *foundUses = nullptr,
std::function<void(Operand *)> *onError = nullptr) {
return findTransitiveUsesForAddress(getProjectedAddress(), foundUses,
onError);
}
Expand Down Expand Up @@ -912,8 +924,8 @@ struct AddressOwnership {
}

/// Transitively compute uses of this base address.
bool findTransitiveUses(SmallVectorImpl<Operand *> &foundUses) {
return findTransitiveUsesForAddress(base.getBaseAddress(), foundUses);
AddressUseKind findTransitiveUses(SmallVectorImpl<Operand *> &foundUses) {
return findTransitiveUsesForAddress(base.getBaseAddress(), &foundUses);
}

/// Return true of all \p uses occur before the end of the address' lifetime
Expand Down
6 changes: 6 additions & 0 deletions include/swift/SIL/SILValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,12 @@ class Operand {
/// Returns true if this ends the lifetime of an owned operand.
bool isConsuming() const;

bool endsLocalBorrowScope() const {
auto ownership = getOperandOwnership();
return ownership == OperandOwnership::EndBorrow
|| ownership == OperandOwnership::Reborrow;
}

SILBasicBlock *getParentBlock() const;
SILFunction *getParentFunction() const;

Expand Down
Loading