Skip to content

Move mandatory inlining cleanup to mandatory combine #28396

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

zoecarver
Copy link
Contributor

This patch makes MandatoryInlining a SILModuleTransform instead of a SILFunctionTransform. It also moves the function removal cleanup to MandatoryCombine so that it will be run on every function. This is better because then we don't have to iterate over every function in a module twice in MandatoryInlining. And now, both can remain a SILFunctionTransform. It also has the benefit of allowing MandatoryCombine to exit early sometimes.

The successor to #28394.

cc @gottesmm

@gottesmm
Copy link
Contributor

This is the wrong way to do this. What we want to do is move stuff into the mandatory combiner since it runs after diagnostics. That way we can make it easy for SourceKit to not run this sort of code.

@zoecarver
Copy link
Contributor Author

I re-wrote this patch fixing most of the issues that you brought up. I removed changes to MandatoryCombine. I'll either add those to this patch later or add them in another patch.

The basic flow of this pass is now:

  • Collect apply instructions.
  • Try to devitalize applys.
  • Iterate over every apply and try to inline it. Otherwise, continue.
  • Add the apply's callee to the pass manager worklist so it will also try to be inlined (instead of trying to inline it recursively).
  • If any functions were inlined, add them to the worklist as well so the now-dead functions can be removed.

The recursive inlining is now removed. All mandatory inlining tests pass (assuming I ran the right tests).

There are still a few things I want to clean up (see TODOs). I'll probably fix those in a different patch, though.

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

Some initial comments. I want to read this code in more detail before it lands.


// First collect all the applies
SmallVector<FullApplySite, 12> applyInsts;
while (SILBasicBlock *block = domOrder.getNext()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to use the dominator info here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't. I'll remove it.

Copy link
Contributor Author

@zoecarver zoecarver Nov 22, 2019

Choose a reason for hiding this comment

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

Hmm. To be honest, I'm not quite sure why reading the blocks in dominance order fixes this, but, when inlining an auto closure with -enable-ownership-stripping-after-serialization, the verifier fails because convert_escape_to_noescape [not_guaranteed] not allowed after mandatory passes. Using dominance order fixes that.

Edit: see test_chained_short_circuit for example.

@@ -665,6 +667,7 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
SILPassPipelinePlan P(Options);

P.startPipeline("Mandatory Combines");
P.addMandatoryInlining();
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be necessary. Please remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gottesmm
Copy link
Contributor

So I was thinking about this a little bit. We need to do this differently/split this up. Here is my suggestion:

  1. Why don't we create a separate PR that just moves cleanup code (and leaves everything else the same). This would mean eliminating the code in cleanup callee and moving that to the Mandatory Combiner. No passes should be moved around, it should just require having the mandatory inliner not cleaning up after itself and leaving that later for the mandatory combiner.

  2. There is more complexity here around the pass manager. I can explain it in more detail offline, but I think that this may be a bit more complex than a simple cleanup. Maybe we do 1 in the short term and then circle back around to this?

@zoecarver
Copy link
Contributor Author

@gottesmm, that sounds good to me.

I'll look into making a cleanup patch. I'm not 100% sure the cleanup done here is necessary, though. I think the mandatory combiner might already handle this. I'll double-check and make a patch if not.

I would also be interested to learn more about the pass manager. Feel free to reach out to me whenever (no rush, though, I'm sure you're busy).

@zoecarver
Copy link
Contributor Author

Closing for now. Might reopen later.

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.

2 participants