-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[sil-combine] Update sil combine for Ownership [part 1] #35246
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
Conversation
812242e
to
63d7b21
Compare
@swift-ci smoke test |
Just an intermediate check that I didn't miss anything before I upload a bunch more patches. |
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 reviewed all 10 commits currently in the PR, through [sil-combine] Enable switch_value to be optimized in OSSA. a0ac0b3
It all looks great. Nothing needs to be revised, just a bit of commentary.
@@ -805,6 +806,8 @@ static bool isZeroLoadFromEmptyCollection(LoadInst *LI) { | |||
case ValueKind::UpcastInst: | |||
case ValueKind::RawPointerToRefInst: | |||
case ValueKind::AddressToPointerInst: | |||
case ValueKind::BeginBorrowInst: | |||
case ValueKind::CopyValueInst: |
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.
fyi, this is just an example of one of the 100+ places we should use AccessedStorageVisitor so we're not maintaining them all
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.
Sure. Maybe I can fix that in a subsequent commit.
LoadInst *EnumVal = Builder.createLoad(SEAI->getLoc(), Addr, | ||
LoadOwnershipQualifier::Unqualified); | ||
Builder.createSwitchEnum(SEAI->getLoc(), EnumVal, Default, Cases); | ||
SILValue EnumVal = Builder.emitLoadBorrowOperation(SEAI->getLoc(), Addr); |
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.
It took me a while to figure out how this is safe. It would help to comment that this only creates a trivial load-borrow scope to cover the switch_enum terminator and its block argument results, so nothing can write to memory within this scope.
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'll add to 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 looked, I do have a comment a line or two above:
// Promote switch_enum_addr to switch_enum if the enum is loadable.
// switch_enum_addr %ptr : $*Optional<SomeClass>, case ...
// ->
// %value = load %ptr
// switch_enum %value
//
// If we are using ownership, we perform a load_borrow right before the new
// switch_enum and end the borrow scope right afterwards.
Going to fix the comments in post-commit and do more work in a different PR that builds on this. |
@swift-ci smoke test |
a0ac0b3
to
0ca8a98
Compare
@atrick I actually fixed the issues your brought up in this PR since I wanted to make it so that my patch around ref_to_* used pointer escape instead of unowned instantaneous use as per our conversations. |
@swift-ci smoke test |
@swift-ci smoke test OS X platform |
1 similar comment
@swift-ci smoke test OS X platform |
@shahmishal hitting weird failures. |
// operand perspective we treat them as a pointer escape and from a value | ||
// perspective, they return a value with OwnershipKind::Unowned. | ||
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \ | ||
OPERAND_OWNERSHIP(PointerEscape, RefTo##Name) \ |
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.
@atrick this is what I was talking about.
@swift-ci smoke test OS X platform |
1 similar comment
@swift-ci smoke test OS X platform |
@swift-ci clean smoke test linux platform |
a97b0ce
to
0471653
Compare
@swift-ci smoke test |
Got a merge conflict from one of Andy's commits. |
…Unowned so should be treated as PointerEscapes. These instructions model a conversion in between ownership kinds without the result actually being owned by anything. As a result: 1. From an operand perspective, the instruction is treated like a pointer escape. 2. From a value perspective, the instruction returns a value with OwnershipKind::Unowned (to force the value to be copied before it can be used in an owned or guaranteed way) and Example: ``` sil @example : $@convention(thin) (@owned Klass) -> @owned @sil_unowned Klass { bb0(%0 : @owned $Klass): // Note that the ref_to_unowned does not consume %0 but instead converts %0 // from a "strong" value to a "safe unowned" value. A "safe unowned" value is // a value that corresponds to an 'unowned' value at the Swift level that use // unowned reference counting. At the SIL level these values can be recognized // by their types having the type attribute @sil_unowned. We have not // incremented the unowned ref count of %1 so we must treat %1 as unowned. %1 = ref_to_unowned %0 : $Klass // Then before we can use %2 in any way as a "safe unowned" value we need to // bump its unowned ref count by making a copy of the value. %2 will be a // "safe unowned" value with OwnershipKind::Owned ensuring that we decrement // the unowned ref count and do not leak said ref count. %2 = copy_value %1 : $@sil_unowned $Klass // Then since the original ref_to_unowned did not consume %0, we need to // destroy it here. destroy_value %0 : $Klass // And then return out OwnershipKind::Owned @sil_unowned Klass. return %2 : $@sil_unowned $Klass } ```
…ent upstreamed work.
…g the checks we don't pass yet. In the subsequent commits, I am going to enable individual groups of filecheck tests. This will let me avoid having to extract out individual test cases as I upstream. NOTE: I disabled the CHECK lines by just s/CHECK/XHECK/g. I left in the CHECK-LABEL so FileCheck still has something to chew on initially.
…e.sil. These are mostly handled by inst simplify and simple DCE functionality.
…upport LoadBorrow. NOTE: The stdlib count/capacity propagation code is tested in an end<->end fashion in a separate Swift test. Once I flip the switch, that test will run. The code is pretty simple, so I feel relatively confident with it.
…es for ownership.
This routine never touches values with non-trivial ownership, so I just removed the early exit and updated the style.
0471653
to
b206d00
Compare
@swift-ci smoke test |
@swift-ci smoke test linux platform |
1 similar comment
@swift-ci smoke test linux platform |
@gottesmm are there any functional changes here? I'm guessing not because it was only smoke tested! |
No description provided.