[PATCH] D56120: [BasicBlockUtils] Generalize DeleteDeadBlock to deal with multiple dead blocks

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 27 23:44:00 PST 2018


mkazantsev created this revision.
mkazantsev added reviewers: asbirlea, chandlerc, anna, skatkov, reames.

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
    make relevant DT updates;
    remove all instructions (replace with undef if needed);
    replace terminator with unreacheable;
  for each block
    delete block;

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


https://reviews.llvm.org/D56120

Files:
  include/llvm/Transforms/Utils/BasicBlockUtils.h
  lib/Transforms/Utils/BasicBlockUtils.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56120.179607.patch
Type: text/x-patch
Size: 4965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181228/26a9ce30/attachment.bin>


More information about the llvm-commits mailing list