Skip to content

OSSA ownership optimization RAUW utility fixes. #35571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2021
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
27 changes: 13 additions & 14 deletions include/swift/SIL/OwnershipUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ inline bool isForwardingConsume(SILValue value) {
}

class ForwardingOperand {
Operand *use;

ForwardingOperand(Operand *use) : use(use) {}
Operand *use = nullptr;

public:
static ForwardingOperand get(Operand *use);
explicit ForwardingOperand(Operand *use);

OwnershipConstraint getOwnershipConstraint() const {
// We use a force unwrap since a ForwardingOperand should always have an
Expand Down Expand Up @@ -665,25 +663,26 @@ struct InteriorPointerOperand {
llvm_unreachable("Covered switch isn't covered?!");
}

/// Compute the list of implicit uses that this interior pointer operand puts
/// on its parent guaranted value.
/// Transitively compute the list of uses that this interior pointer operand
/// puts on its parent guaranted value.
///
/// 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 getImplicitUses(SmallVectorImpl<Operand *> &foundUses,
std::function<void(Operand *)> *onError = nullptr) {
return getImplicitUsesForAddress(getProjectedAddress(), foundUses, onError);
bool findTransitiveUses(SmallVectorImpl<Operand *> &foundUses,
std::function<void(Operand *)> *onError = nullptr) {
return findTransitiveUsesForAddress(getProjectedAddress(), foundUses,
onError);
}

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

Operand *operator->() { return operand; }
const Operand *operator->() const { return operand; }
Expand Down
5 changes: 5 additions & 0 deletions include/swift/SILOptimizer/Utils/OwnershipOptUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct OwnershipFixupContext {
DeadEndBlocks &deBlocks;
JointPostDominanceSetComputer &jointPostDomSetComputer;

SmallVector<Operand *, 8> transitiveBorrowedUses;
SmallVector<BorrowingOperand, 8> recursiveReborrows;

/// Extra state initialized by OwnershipRAUWFixupHelper::get() that we use
/// when RAUWing addresses. This ensures we do not need to recompute this
/// state when we perform the actual RAUW.
Expand Down Expand Up @@ -67,6 +70,8 @@ struct OwnershipFixupContext {

void clear() {
jointPostDomSetComputer.clear();
transitiveBorrowedUses.clear();
recursiveReborrows.clear();
extraAddressFixupInfo.allAddressUsesFromOldValue.clear();
extraAddressFixupInfo.intPtrOp = InteriorPointerOperand();
}
Expand Down
14 changes: 7 additions & 7 deletions lib/SIL/Utils/OwnershipUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ bool BorrowedValue::visitInteriorPointerOperands(
// InteriorPointerOperand
//===----------------------------------------------------------------------===//

bool InteriorPointerOperand::getImplicitUsesForAddress(
bool InteriorPointerOperand::findTransitiveUsesForAddress(
SILValue projectedAddress, SmallVectorImpl<Operand *> &foundUses,
std::function<void(Operand *)> *onError) {
SmallVector<Operand *, 8> worklist(projectedAddress->getUses());
Expand Down Expand Up @@ -882,12 +882,12 @@ OwnedValueIntroducer swift::getSingleOwnedValueIntroducer(SILValue inputValue) {
// Forwarding Operand
//===----------------------------------------------------------------------===//

ForwardingOperand ForwardingOperand::get(Operand *use) {
ForwardingOperand::ForwardingOperand(Operand *use) {
if (use->isTypeDependent())
return nullptr;
return;

if (!OwnershipForwardingMixin::isa(use->getUser())) {
return nullptr;
return;
}
#ifndef NDEBUG
switch (use->getOperandOwnership()) {
Expand All @@ -909,7 +909,7 @@ ForwardingOperand ForwardingOperand::get(Operand *use) {
llvm_unreachable("this isn't the operand being forwarding!");
}
#endif
return {use};
this->use = use;
}

ValueOwnershipKind ForwardingOperand::getOwnershipKind() const {
Expand Down Expand Up @@ -1008,7 +1008,7 @@ void ForwardingOperand::setOwnershipKind(ValueOwnershipKind newKind) const {
return;
}

llvm_unreachable("Out of sync with ForwardingOperand::get?!");
llvm_unreachable("Out of sync with OperandOwnership");
}

void ForwardingOperand::replaceOwnershipKind(ValueOwnershipKind oldKind,
Expand Down Expand Up @@ -1075,7 +1075,7 @@ void ForwardingOperand::replaceOwnershipKind(ValueOwnershipKind oldKind,
return;
}

llvm_unreachable("Missing Case! Out of sync with ForwardingOperand::get?!");
llvm_unreachable("Missing Case! Out of sync with OperandOwnership");
}

SILValue ForwardingOperand::getSingleForwardedValue() const {
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/Verifier/SILOwnershipVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ bool SILValueOwnershipChecker::gatherUsers(
<< "Address User: " << *op->getUser();
});
};
foundError |= interiorPointerOperand.getImplicitUses(
foundError |= interiorPointerOperand.findTransitiveUses(
nonLifetimeEndingUsers, &onError);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/SemanticARC/CopyValueOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ static bool canJoinIfCopyDiesInFunctionExitingBlock(
}

static Operand *lookThroughSingleForwardingUse(Operand *use) {
auto forwardingOperand = ForwardingOperand::get(use);
ForwardingOperand forwardingOperand(use);
if (!forwardingOperand)
return nullptr;
auto forwardedValue = forwardingOperand.getSingleForwardedValue();
Expand Down Expand Up @@ -423,7 +423,7 @@ static bool tryJoinIfDestroyConsumingUseInSameBlock(
// If not, see if this use did have a forwardedValue but that forwardedValue
// has multiple end lifetime uses. In that case, we can optimize if there
// aren't any uses/etc
auto forwardingOperand = ForwardingOperand::get(currentForwardingUse);
ForwardingOperand forwardingOperand(currentForwardingUse);
if (!forwardingOperand)
return false;
auto forwardedValue = forwardingOperand.getSingleForwardedValue();
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/SemanticARC/OwnershipLiveRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void OwnershipLiveRange::convertOwnedGeneralForwardingUsesToGuaranteed() && {
while (!ownershipForwardingUses.empty()) {
auto *use = ownershipForwardingUses.back();
ownershipForwardingUses = ownershipForwardingUses.drop_back();
auto operand = ForwardingOperand::get(use);
ForwardingOperand operand(use);
operand.replaceOwnershipKind(OwnershipKind::Owned,
OwnershipKind::Guaranteed);
}
Expand Down
Loading