Skip to content

Extend findInitExistential for cases when ApplySite argument is a global_addr #17361

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

Merged
merged 1 commit into from
Jul 11, 2018

Conversation

rajbarik
Copy link
Contributor

Determine InitExistential for an apply argument that is a global_addr.

Pattern 1:

%3 = global_addr @$P : $*SomeP
%4 = init_existential_addr %3 : $*SomeP, $SomeC
%5 = alloc_ref $SomeC
store %5 to %4 : $*SomeC
%10 = apply %9(%3) : $@convention(thin) (@in_guaranteed SomeP)

Pattern 2:

%3 = global_addr @$P : $*SomeP
%9 = open_existential_addr mutable_access %3 : $*SomeP to $*@opened SomeP
%15 = apply %11(%9) : $@convention(thin) (@in_guaranteed SomeP)

No test cases yet, will be merged as part of the large PR #13991

@rajbarik
Copy link
Contributor Author

@gottesmm @slavapestov @atrick Can you review this PR? This Pr refactors the old code for findInitExistentialFromGlobalAddr to findInitExistentialFromGlobalAddrAndCopyAddr and adds a new interface for finding init_existential for an apply argument who happens to be a global_addr, findInitExistentialFromGlobalAddrAndApply . This function is currently not being used, hence no new tests. I will use this interface when #13991 lands fully.

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally looks good and the comments are nice. The only comments I have are the misleading variable names above.


/// Find InitExistential from global_addr and an apply argument.
SILValue findInitExistentialFromGlobalAddrAndApply(GlobalAddrInst *GAI,
ApplySite AI, int ArgIdx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever I see uses of an "apply" without the type spelled out, I like to know when I'm dealing with an ApplySite vs. ApplyInst, and which code is potentially handling try_apply. Since "AI" is an acronym for ApplyInst, this is misleading. (I suspect this is backward in so much of our code because someone did a massive replace on the type without changing variable names?) Let's not make it worse.


/// %10 = apply %9(%3) : $@convention(thin) (@in_guaranteed SomeP)
static SILValue findInitExistentialFromGlobalAddr(GlobalAddrInst *GAI,
SILInstruction *AI) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI is misleading again here. This is not always an ApplyInst. It's just some arbitrary use of the global_addr.

/// %9 = open_existential_addr mutable_access %3 : $*SomeP to $*@opened SomeP
/// %15 = apply %11(%9) : $@convention(thin) (@in_guaranteed SomeP)
SILValue swift::findInitExistentialFromGlobalAddrAndApply(GlobalAddrInst *GAI,
ApplySite AI,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, calling this AI leads me to believe that it's not potentially a try_apply.

@rajbarik rajbarik force-pushed the raj-globaladdr-refactor branch from a7f56d5 to 42257c2 Compare June 20, 2018 21:00
@rajbarik
Copy link
Contributor Author

Thanks @atrick. Should be fixed now.


/// %10 = apply %9(%3) : $@convention(thin) (@in_guaranteed SomeP)
static SILValue findInitExistentialFromGlobalAddr(GlobalAddrInst *GAI,
SILInstruction *Insn) {
Copy link
Contributor

@atrick atrick Jun 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you should probably comment that Insn is assumed to be a direct user of GAI (e.g. copy_addr or apply in the pattern above) and that a valid init_existential_addr value is returned only if this routine can prove that the value it initializes is the same value in memory at the given use point. Looking at this again, I don't understand why the return type is SILValue and not InitExistentialAddrInst*.

@rajbarik rajbarik force-pushed the raj-globaladdr-refactor branch from 42257c2 to 392469a Compare June 21, 2018 20:50
@rajbarik
Copy link
Contributor Author

@atrick Thanks for the suggestion -- added the assumption. The reason it returns SILValue is because for convenience in use in getAddressOfStackInit below that returns a SILValue.

@atrick
Copy link
Contributor

atrick commented Jun 21, 2018

Ok. FYI, any SingleValueInstruction such as this is castable to SILValue.

@slavapestov slavapestov self-assigned this Jun 27, 2018
@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

1 similar comment
@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor

Please update the existing SILCombiner self concrete type peephole to use the new function and add a SIL test.

@slavapestov slavapestov merged commit 4bcf8f6 into swiftlang:master Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants