Skip to content

Require that hop_to_executor eventually actually takes an executor #36643

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 3 commits into from
Mar 31, 2021

Conversation

rjmccall
Copy link
Contributor

Currently the SIL hop_to_executor instruction can take either a Builtin.Executor or an actor reference. The runtime operation requires an executor, and custom executors mean that the distinction is important. We want to be able to optimize executor hops, including eliminating the actor-to-executor derivation, but we also want to be able to statically optimize the executor lowerings that we actually have to do.

Thread this needle by doing the lowering in a pass that runs after hop_to_executor optimization but before IRGen.

@rjmccall rjmccall requested review from atrick and eeckstein March 30, 2021 06:58
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2a1e54c8ce428e2bd38adbb7aeacd99845e1529f

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2a1e54c8ce428e2bd38adbb7aeacd99845e1529f

@DougGregor
Copy link
Member

@swift-ci please smoke test

@rjmccall rjmccall force-pushed the lower-hop-to-actor branch from 2a1e54c to 0b2d4a5 Compare March 30, 2021 22:07
@rjmccall rjmccall force-pushed the lower-hop-to-actor branch 2 times, most recently from 300d9bf to 4536ef1 Compare March 30, 2021 22:11
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4536ef1a49493a40d3a64e92658a12b3ee91ccf3

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4536ef1a49493a40d3a64e92658a12b3ee91ccf3

The comment in LowerHopToActor explains the design here.
We want SILGen to emit hops to actors, ignoring executors,
because it's easier to fully optimize in a world where deriving
an executor is a non-trivial operation.  But we also want something
prior to IRGen to lower the executor derivation because there are
useful static optimizations we can do, such as doing the derivation
exactly once on a dominance path and strength-reducing the derivation
(e.g. exploiting static knowledge that an actor is a default actor).

There are probably phase-ordering problems with doing this so late,
but hopefully they're restricted to situations like actors that
share an executor.  We'll want to optimize that eventually, but
in the meantime, this unblocks the executor work.
@rjmccall rjmccall force-pushed the lower-hop-to-actor branch from 4536ef1 to 4f6f8b3 Compare March 31, 2021 00:09
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4f6f8b3

@rjmccall
Copy link
Contributor Author

@swift-ci Please smoke test Linux

@rjmccall
Copy link
Contributor Author

@swift-ci Please test Linux

@rjmccall
Copy link
Contributor Author

@eeckstein Please let me know what you think about the new implementation. We should be able to use this for CSE as well, although I didn't try.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4f6f8b3

@rjmccall
Copy link
Contributor Author

@swift-ci Please test Linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4f6f8b3

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

Thanks, looks much better now.
Basically LGTM. I just have a few suggestions for improvements.

void runInDominanceOrderWithScopes(DominanceInfo *dominance, Fn &&fn,
Trackers &...trackers) {
using TrackingStackNode = TrackingScopes<Trackers...>;
llvm::SmallVector<std::unique_ptr<TrackingStackNode>, 8> trackingStack;
Copy link
Contributor

Choose a reason for hiding this comment

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

The maximum size of trackingStack is the number of blocks in the function. If you pre-allocate (e.g. reserve) an array of TrackingStackNode (not pointers!) with this size then you don't need to alloc a new StrackingStackNode for each block. Maybe just use a plain old C array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can try to optimize this so that it doesn't require heap-allocation, sure. But this is already better than CSE, FWIW.

@rjmccall
Copy link
Contributor Author

@swift-ci Please test Linux

@rjmccall rjmccall merged commit 4344541 into swiftlang:main Mar 31, 2021
@rjmccall rjmccall deleted the lower-hop-to-actor branch March 31, 2021 20:31
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.

4 participants