OSSA ownership optimization RAUW utility fixes.

Verify that the OwnershipRAUWUtility always preserves the original
borrow scope by exhaustively switching over OperandOwnership.

And related cleanup.
This commit is contained in:
Andrew Trick
2021-01-22 20:19:30 -08:00
parent 1f1123f6c0
commit a2fac95f9f
7 changed files with 136 additions and 102 deletions

View File

@@ -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
@@ -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; }

View File

@@ -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.
@@ -67,6 +70,8 @@ struct OwnershipFixupContext {
void clear() {
jointPostDomSetComputer.clear();
transitiveBorrowedUses.clear();
recursiveReborrows.clear();
extraAddressFixupInfo.allAddressUsesFromOldValue.clear();
extraAddressFixupInfo.intPtrOp = InteriorPointerOperand();
}