OSSA: Rewrite address cloning code to fix issues.

Generalize the AccessUseDefChainCloner in MemAccessUtils. It was
always meant to work this way, just needed a client.

Add a new API AccessUseDefChainCloner::canCloneUseDefChain().

Add a bailout for begin_borrow and mark_dependence. Those
projections may appear on an access path, but they can't be
individually cloned without compensating.

Delete InteriorPointerAddressRebaseUseDefChainCloner.

Add a check in OwnershipRAUWHelper for canCloneUseDefChain.

Add test cases for begin_borrow and mark_dependence.
This commit is contained in:
Andrew Trick
2021-02-24 21:29:13 -08:00
parent 3f38669945
commit 66752e9724
4 changed files with 188 additions and 119 deletions

View File

@@ -1340,11 +1340,21 @@ hoistLoadsAndStores(AccessPath accessPath, SILLoop *loop) {
}
}
assert(storeAddr && "hoistLoadsAndStores requires a store in the loop");
SILValue initialAddr = cloneUseDefChain(
storeAddr, preheader->getTerminator(), [&](SILValue srcAddr) {
// Clone projections until the address dominates preheader.
return !DomTree->dominates(srcAddr->getParentBlock(), preheader);
});
auto checkBase = [&](SILValue srcAddr) {
// Clone projections until the address dominates preheader.
if (DomTree->dominates(srcAddr->getParentBlock(), preheader))
return srcAddr;
// return an invalid SILValue to continue cloning.
return SILValue();
};
SILValue initialAddr =
cloneUseDefChain(storeAddr, preheader->getTerminator(), checkBase);
// cloneUseDefChain may currently fail if a begin_borrow or mark_dependence is
// in the chain.
if (!initialAddr)
return;
LoadInst *initialLoad =
B.createLoad(preheader->getTerminator()->getLoc(), initialAddr,
LoadOwnershipQualifier::Unqualified);