This implements the algorithm suggested in https://reviews.llvm.org/D35028#800177 with a slight variation/implementation detail. We could have BBs which don't have corresponding nodes in the dominator, so we need to handle that case as well. We also need an additional worklist for the dead block to avoid iterator invalidation issues (or at least, this was the easiest way I could think how to solve this problem).
This is WIP for two reasons:
- I want the utility to have a better name for the utility [but I need to think about it, suggestions welcome]
- I want to test it a little more. It passes the testsuite & bootstrap, but I'll try on something else I have available internally.