The logic in the -unreachableblockelim pass does the following:
- It traverses the function it's given in depth-first order and creates a set of basic blocks that are unreachable from the function's entry node.
- It iterates over each of those unreachable blocks and (1) removes any successors' references to the dead block, and (2) replaces any uses of instructions from the dead block with null.
The logic in (2) above is identical to what the llvm::DeleteDeadBlocks
function from BasicBlockUtils.h does. The only difference is that
llvm::DeleteDeadBlocks replaces uses of instructions from dead blocks
not with null, but with undef.
Replace the duplicate logic in the -unreachableblockelim pass with a
call to llvm::DeleteDeadBlocks. This results in less code but no
functional change (NFC).