[membehavior] Fix base memory behavior/releasing of Load/Store for ownership.

load, store in ossa can have side-effects and stores can release. Specifically:

Memory Behavior
---------------

* Load: unqualified, trivial, take have a read side-effect, but copy retains so
  has side-effects.

* Store: unqualified, trivial, init may write but assign releases so it may have
  side-effects.

Release Behavior
----------------

* Load: No changes.

* Store: May release if store has assign as an ownership qualifier.
This commit is contained in:
Michael Gottesman
2020-11-02 12:14:23 -08:00
parent 891e115b53
commit c3681a6eef
4 changed files with 80 additions and 16 deletions

View File

@@ -242,12 +242,15 @@ MemBehavior MemoryBehaviorVisitor::visitLoadInst(LoadInst *LI) {
if (!mayAlias(LI->getOperand()))
return MemBehavior::None;
// A take is modelled as a write. See MemoryBehavior::MayWrite.
if (LI->getOwnershipQualifier() == LoadOwnershipQualifier::Take)
return MemBehavior::MayReadWrite;
LLVM_DEBUG(llvm::dbgs() << " Could not prove that load inst does not alias "
"pointer. Returning may read.\n");
"pointer. ");
if (LI->getOwnershipQualifier() == LoadOwnershipQualifier::Take) {
LLVM_DEBUG(llvm::dbgs() << "Is a take so return MayReadWrite.\n");
return MemBehavior::MayReadWrite;
}
LLVM_DEBUG(llvm::dbgs() << "Not a take so returning MayRead.\n");
return MemBehavior::MayRead;
}
@@ -257,15 +260,17 @@ MemBehavior MemoryBehaviorVisitor::visitStoreInst(StoreInst *SI) {
if (isLetValue() && (getAccessBase(SI->getDest()) != getValueAddress())) {
return MemBehavior::None;
}
// If the store dest cannot alias the pointer in question, then the
// specified value cannot be modified by the store.
if (!mayAlias(SI->getDest()))
// If the store dest cannot alias the pointer in question and we are not
// releasing anything due to an assign, then the specified value cannot be
// modified by the store.
if (!mayAlias(SI->getDest()) &&
SI->getOwnershipQualifier() != StoreOwnershipQualifier::Assign)
return MemBehavior::None;
// Otherwise, a store just writes.
LLVM_DEBUG(llvm::dbgs() << " Could not prove store does not alias inst. "
"Returning MayWrite.\n");
return MemBehavior::MayWrite;
"Returning default mem behavior.\n");
return SI->getMemoryBehavior();
}
MemBehavior MemoryBehaviorVisitor::visitCopyAddrInst(CopyAddrInst *CAI) {