Skip to content

[mandatory-combine] Improve basic block traversal when initializing worklist #27598

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

Conversation

gottesmm
Copy link
Contributor

This PR contains two different small improvements to mandatory combine that will not change the output of the pass, but generally make the pass safer and easier to maintain. Specifically:

  1. The first patch just causes mandatory combine to bail early when we see a function that is an external declaration before we do anything else. This just provides a nice invariant I use in the next patch.

  2. The second patch cleans up the worklist initialization in mandatory combine. Specifically, I:
    a. Simplified the data structures.
    b. Changed the "visited block" set to ensure that we only add blocks once to the worklist instead of inserting the blocks into the worklist and then using the set to filter out if we had already popped the block off the worklist before. This is more efficient and simplifies the code. I changed the name of the set to fit closer to its new role: blockAlreadyAddedToWorklist.


[mandatory-combine] Simplify block traversal used to initialize worklist.

Previously, we were using a pointer set to ensure that was checked when a value
was popped off the worklist. In this commit, I change the code so that we
instead use the set to guard insertion into the worklist.

I changed the name of the set to blockAlreadyAddedToWorklist. Hopefully that
will make things a bit clearer.

…claration.

Beyond creating a nice invariant, I am going to be using this invariant in some
small code improvements to MandatoryCombine that assume we have an initial basic
block.
…ist.

Previously, we were using a pointer set to ensure that was checked when a value
was popped off the worklist. In this commit, I change the code so that we
instead use the set to guard insertion into the worklist.

I changed the name of the set to blockAlreadyAddedToWorklist. Hopefully that
will make things a bit clearer.
@gottesmm
Copy link
Contributor Author

@swift-ci asan test

@gottesmm
Copy link
Contributor Author

@swift-ci test

@nate-chandler
Copy link
Contributor

Do any of these changes apply to SILCombiner::addReachableCodeToWorklist?

Copy link
Contributor

@nate-chandler nate-chandler left a comment

Choose a reason for hiding this comment

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

LGTM

@gottesmm
Copy link
Contributor Author

@nate-chandler Maybe? I would rather do that in a different PR at another time (feel free to grab that task if you want). I just saw this when I was seeing if I needed to add code to mandatory combiner to ensure that changing #27599 did not mess with codegen. Turns out I didn't need to change anything. But I found this locally so I thought I would upstream it.

@gottesmm gottesmm merged commit 48e4ddb into swiftlang:master Oct 10, 2019
@gottesmm gottesmm deleted the pr-86500d6ad50210ce9319f02bd3347793bc8b52af branch October 10, 2019 16:44
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