-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[membehavior] Fix base memory behavior/releasing of Load/Store for ownership #34543
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
[membehavior] Fix base memory behavior/releasing of Load/Store for ownership #34543
Conversation
@swift-ci test |
I think there maybe more that we need to do here. Specifically: This suggests we may want load [take] to be RW if we do not separate the notion of initialization from memory read/write: It is unclear to me if we want this to be may have side effects if we have release. @eeckstein would love your thoughts. |
The code in side effect analysis is also inconsistent here where load is not updated to handle load [take] correctly: assuming that we want it to be RW. |
Also load/store need update for load [copy]/store [assign] to be treated as retain/releasing. |
Build failed |
AFAICT, MemoryBehaviorVisitor::visitLoadInst is correct.
Yes, in case of store [assign], it should be MayHaveSideEffects. Also this is wrong in case of store [assign]:
because even if the V does not alias the destination address, the destructor of the re-assigned object might write to V. |
520b061
to
fcf1585
Compare
@eeckstein did another round. Put in your suggestions. Any thoughts on how to test this? |
@swift-ci test |
@@ -242,13 +242,9 @@ MemBehavior MemoryBehaviorVisitor::visitLoadInst(LoadInst *LI) { | |||
if (!mayAlias(LI->getOperand())) | |||
return MemBehavior::None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eeckstein one thing we need to think about is do we consider from a membehavior perspective that the retain from a load [copy] is an issue as well in terms of side-effects. I imagine probably not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it is not. Therefore the original version of visitLoad() is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly the sort of thing that needs to be specified in the definition of MemBehavior: writes to non-programmer visible memory, particularly refcounts, are not considered write or side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to do that, we should model retain behavior in MemBehavior explicitly. That would be the right way to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is true. If you look in SILNodes.def we consider retain to have side-effects since we don't model retains separately in MemBehavior. See:
I agree with you if we model retains separately in membehavior.
Build failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except MemoryBehaviorVisitor::visitLoadInst()
@@ -242,13 +242,9 @@ MemBehavior MemoryBehaviorVisitor::visitLoadInst(LoadInst *LI) { | |||
if (!mayAlias(LI->getOperand())) | |||
return MemBehavior::None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it is not. Therefore the original version of visitLoad() is correct.
…nership. 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.
fcf1585
to
c3681a6
Compare
@eeckstein I fixed your suggestion. |
Erik is out until tomorrow. I changed what he asked and beyond that he said LGTM. So this is good to go.
@swift-ci smoke test |
@gottesmm It is very important to run the benchmarks for such changes |
Sorry, I should have clarified a few things.
and
The first API is implemented in SILInstruction::getMemoryBehavior() and for most instructions - including retain instructions - it uses the value from SILNodes.def. It is more conservative than the AliasAnalysis API and it treats retain instructions as general reading/writing/sideeffect instructions. The AliasAnalysis API is more precise, because it returns the memory effect in respect to a given address V: does the instruction read or write from/to that address? This API is implemented with the MemoryBehaviorVisitor. We could add SILInstruction::mayRetain(), but so far it was not needed. |
@eeckstein I'll revert this in a PR and look at the perf. |
@eeckstein @gottesmm this is a good explanation, but none of this is specified in MemBehavior's definition: Nor is it specified on the relevant top level APIs: |
@atrick I don't see anything substantial missing in the documentation of these APIs. Of course, it still can be improved (e.g. mention how the SILInstruction API handles retain instructions), but that could be said about all of our code base. In my previous comment I mainly clarified how these APIs are implemented. |
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.