This is an archive of the discontinued LLVM Phabricator instance.

[BasicBlockUtils] Generalize DeleteDeadBlock to deal with multiple dead blocks
ClosedPublic

Authored by mkazantsev on Dec 27 2018, 11:43 PM.

Details

Summary

Utility function DeleteDeadBlock expects that all predecessors of a block being
deleted are already deleted, with the exception of single-block loop. It makes it
hard to use for deletion of a set of blocks that may contain cyclic dependencies.
The is no correct order of invocations of this function that does not produce
dangling pointers on already deleted blocks.

This patch introduces a generalized version of this function DeleteDeadBlocks
that allows us to remove multiple blocks at once, even if there are cycles among
them. The only requirement is that no block being deleted should have a predecessor
that is not being deleted.

The logic of DeleteDeadBlocks is following:

for each block
  create relevant DT updates;
  remove all instructions (replace with undef if needed);
  replace terminator with unreacheable;
apply DT updates;
for each block
  delete block;

Therefore, DeleteDeadBlock becomes a particular case of
the general algorithm called for a single block.

Diff Detail

Repository
rL LLVM

Event Timeline

mkazantsev created this revision.Dec 27 2018, 11:43 PM
mkazantsev edited the summary of this revision. (Show Details)
skatkov accepted this revision.Jan 13 2019, 11:16 PM
This revision is now accepted and ready to land.Jan 13 2019, 11:16 PM
This revision was automatically updated to reflect the committed changes.