llvm-project/llvm/lib/Transforms/Utils
Max Kazantsev 1f73310e1e [BasicBlockUtils] Generalize DeleteDeadBlock to deal with multiple dead blocks
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.

Differential Revision: https://reviews.llvm.org/D56120
Reviewed By: skatkov

llvm-svn: 351045
2019-01-14 10:26:26 +00:00
..
ASanStackFrameLayout.cpp
AddDiscriminators.cpp [llvm] API for encoding/decoding DWARF discriminators. 2018-12-21 22:48:50 +00:00
BasicBlockUtils.cpp [BasicBlockUtils] Generalize DeleteDeadBlock to deal with multiple dead blocks 2019-01-14 10:26:26 +00:00
BreakCriticalEdges.cpp [TI removal] Make variables declared as `TerminatorInst` and initialized 2018-10-15 10:04:59 +00:00
BuildLibCalls.cpp Add a emitUnaryFloatFnCall version that fetches the function name from TLI 2018-10-18 06:27:53 +00:00
BypassSlowDivision.cpp [BypassSlowDivision] Teach bypass slow division not to interfere with div by constant where constants have been constant hoisted, but not moved from their basic block 2018-08-21 17:15:33 +00:00
CMakeLists.txt [ThinLTO] Handle chains of aliases 2019-01-04 19:04:54 +00:00
CallPromotionUtils.cpp [ICP] Remove incompatible attributes at indirect-call promoted callsites. 2018-11-26 22:03:52 +00:00
CanonicalizeAliases.cpp [ThinLTO] Handle chains of aliases 2019-01-04 19:04:54 +00:00
CloneFunction.cpp [CSP, Cloning] Update DuplicateInstructionsInSplitBetween to use DomTreeUpdater. 2018-11-13 17:54:43 +00:00
CloneModule.cpp Allow creating llvm::Function in non-zero address spaces 2018-08-23 09:25:17 +00:00
CodeExtractor.cpp [CodeExtractor] Do not extract unsafe lifetime markers 2019-01-04 17:43:22 +00:00
CtorUtils.cpp [Transforms] Prefer static and avoid namespaces, NFC 2018-11-19 22:19:05 +00:00
DemoteRegToStack.cpp [IR] Replace `isa<TerminatorInst>` with `isTerminator()`. 2018-08-26 09:51:22 +00:00
EntryExitInstrumenter.cpp EntryExitInstrumenter: Handle musttail calls 2018-04-06 10:14:09 +00:00
EscapeEnumerator.cpp [TI removal] Make variables declared as `TerminatorInst` and initialized 2018-10-15 10:04:59 +00:00
Evaluator.cpp [IR] Add Instruction::isLifetimeStartOrEnd, NFC 2018-12-21 21:49:40 +00:00
FlattenCFG.cpp [TI removal] Make variables declared as `TerminatorInst` and initialized 2018-10-15 10:04:59 +00:00
FunctionComparator.cpp Remove unnecessary fallthrough annotation after unreachable 2018-11-01 19:11:05 +00:00
FunctionImportUtils.cpp [ThinLTO] Compute synthetic function entry count 2018-12-13 19:54:27 +00:00
GlobalStatus.cpp [GlobalOpt] Fix exponential compile-time with selects. 2018-01-31 20:42:25 +00:00
GuardUtils.cpp Revert r340921 "[NFC] Unify guards detection" 2018-08-29 12:21:32 +00:00
ImportedFunctionsInliningStatistics.cpp Use the container form llvm::sort(C, ...) 2018-09-30 22:31:29 +00:00
InlineFunction.cpp [CallSite removal] Migrate all Alias Analysis APIs to use the newly 2019-01-07 05:42:51 +00:00
InstructionNamer.cpp Transforms: Introduce Transforms/Utils.h rather than spreading the declarations amongst Scalar.h and IPO.h 2018-03-28 17:44:36 +00:00
IntegerDivision.cpp Remove trailing space 2018-07-30 19:41:25 +00:00
LCSSA.cpp [DebugInfo][LCSSA] Rewrite pre-existing debug values outside loop 2018-10-16 08:06:48 +00:00
LLVMBuild.txt
LibCallsShrinkWrap.cpp [TI removal] Remove `TerminatorInst` from BasicBlockUtils.h 2018-10-15 09:34:05 +00:00
Local.cpp [IR] Add Instruction::isLifetimeStartOrEnd, NFC 2018-12-21 21:49:40 +00:00
LoopRotationUtils.cpp Update MemorySSA in LoopRotate. 2018-10-24 22:46:45 +00:00
LoopSimplify.cpp [TI removal] Make variables declared as `TerminatorInst` and initialized 2018-10-15 10:04:59 +00:00
LoopUnroll.cpp [llvm] API for encoding/decoding DWARF discriminators. 2018-12-21 22:48:50 +00:00
LoopUnrollAndJam.cpp [llvm] API for encoding/decoding DWARF discriminators. 2018-12-21 22:48:50 +00:00
LoopUnrollPeel.cpp [LoopUnroll] Don't verify domtree by default with +Asserts. 2018-12-21 01:28:49 +00:00
LoopUnrollRuntime.cpp [UnrollRuntime] Fix domTree failures in multiexit unrolling 2019-01-08 17:16:25 +00:00
LoopUtils.cpp Introduce llvm.loop.parallel_accesses and llvm.access.group metadata. 2018-12-20 04:58:07 +00:00
LoopVersioning.cpp [LoopVersioning] Don't modify the list that we iterate over in addPHINodes 2018-05-22 08:33:02 +00:00
LowerInvoke.cpp Support a funclet operand bundle in LowerInvoke 2018-05-09 00:53:50 +00:00
LowerMemIntrinsics.cpp [TI removal] Remove `TerminatorInst` from BasicBlockUtils.h 2018-10-15 09:34:05 +00:00
LowerSwitch.cpp llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...) 2018-09-27 02:13:45 +00:00
Mem2Reg.cpp Transforms: Introduce Transforms/Utils.h rather than spreading the declarations amongst Scalar.h and IPO.h 2018-03-28 17:44:36 +00:00
MetaRenamer.cpp Remove trailing space 2018-07-30 19:41:25 +00:00
ModuleUtils.cpp [NewPM] Port Msan 2019-01-03 13:42:44 +00:00
NameAnonGlobals.cpp
PredicateInfo.cpp ADT/STLExtras: Introduce llvm::empty; NFC 2018-10-31 00:23:23 +00:00
PromoteMemoryToRegister.cpp [IR] Add Instruction::isLifetimeStartOrEnd, NFC 2018-12-21 21:49:40 +00:00
SSAUpdater.cpp [DebugInfo][LCSSA] Rewrite pre-existing debug values outside loop 2018-10-16 08:06:48 +00:00
SSAUpdaterBulk.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
SanitizerStats.cpp
SimplifyCFG.cpp Introduce llvm.loop.parallel_accesses and llvm.access.group metadata. 2018-12-20 04:58:07 +00:00
SimplifyIndVar.cpp [IndVars] Drop "exact" flag from lshr and udiv when substituting their args 2018-10-11 07:22:26 +00:00
SimplifyLibCalls.cpp [SimplifyLibCalls] Fix memchr expansion for constant strings. 2019-01-09 23:39:26 +00:00
SplitModule.cpp llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...) 2018-09-27 02:13:45 +00:00
StripGCRelocates.cpp Fix a couple of layering violations in Transforms 2018-03-21 22:34:23 +00:00
StripNonLineTableDebugInfo.cpp Fix some layering in StripNonLineTableDebugInfo, moving its declaration from IPO.h to Utils.h to match its implementation 2018-03-29 22:42:08 +00:00
SymbolRewriter.cpp Remove trailing space 2018-07-30 19:41:25 +00:00
UnifyFunctionExitNodes.cpp Remove trailing space 2018-07-30 19:41:25 +00:00
Utils.cpp [ThinLTO] Handle chains of aliases 2019-01-04 19:04:54 +00:00
VNCoercion.cpp [GVN] Avoid casting a vector of size less than 8 bits to i8 2018-06-21 21:43:20 +00:00
ValueMapper.cpp Teach ValueMapper to use ODR uniqued types when available 2018-01-30 20:16:32 +00:00