[mandatory-combine] Improve basic block traversal when initializing worklist #27598
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.
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.