1//===- DomTreeUpdater.cpp - DomTree/Post DomTree Updater --------*- C++ -*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file implements the DomTreeUpdater class, which provides a uniform way 10// to update dominator tree related data structures. 12//===----------------------------------------------------------------------===// 24templateclassGenericDomTreeUpdater<DomTreeUpdater, DominatorTree,
28GenericDomTreeUpdater<DomTreeUpdater, DominatorTree,
29 PostDominatorTree>::recalculate(Function &
F);
32GenericDomTreeUpdater<DomTreeUpdater, DominatorTree, PostDominatorTree>::
33 applyUpdatesImpl<
/*IsForward=*/true>();
35GenericDomTreeUpdater<DomTreeUpdater, DominatorTree, PostDominatorTree>::
36 applyUpdatesImpl<
/*IsForward=*/false>();
38bool DomTreeUpdater::forceFlushDeletedBB() {
43// After calling deleteBB or callbackDeleteBB under Lazy UpdateStrategy, 44// validateDeleteBB() removes all instructions of DelBB and adds an 45// UnreachableInst as its terminator. So we check whether the BasicBlock to 46// delete only has an UnreachableInst inside. 47assert(BB->size() == 1 && isa<UnreachableInst>(BB->getTerminator()) &&
48"DelBB has been modified while awaiting deletion.");
50 BB->eraseFromParent();
57// The DT and PDT require the nodes related to updates 58// are not deleted when update functions are called. 59// So BasicBlock deletions must be pended when the 60// UpdateStrategy is Lazy. When the UpdateStrategy is 61// Eager, the BasicBlock will be deleted immediately. 63 validateDeleteBB(DelBB);
64if (
Strategy == UpdateStrategy::Lazy) {
75 validateDeleteBB(DelBB);
76if (
Strategy == UpdateStrategy::Lazy) {
77 Callbacks.push_back(CallBackOnDeletion(DelBB, Callback));
88void DomTreeUpdater::validateDeleteBB(
BasicBlock *DelBB) {
89assert(DelBB &&
"Invalid push_back of nullptr DelBB.");
91// DelBB is unreachable and all its instructions are dead. 92while (!DelBB->
empty()) {
94// Replace used instructions with an arbitrary value (poison). 99// Make sure DelBB has a valid terminator instruction. As long as DelBB is a 100// Child of Function F it must contain valid IR. 101new UnreachableInst(DelBB->
getContext(), DelBB);
107#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 109OS <<
"Pending Callbacks:\n";
111for (
constauto &BB : Callbacks) {
115OS << BB->getName() <<
"(";
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines a set of templates that efficiently compute a dominator tree over a generic graph.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Basic Block Representation.
void removeFromParent()
Unlink 'this' from the containing function, but do not delete it.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
LLVMContext & getContext() const
Get the context in which this basic block lives.
const Instruction & back() const
LLVM_DUMP_METHOD void dump() const
Debug method to help view the internal state of this class.
void callbackDeleteBB(BasicBlock *DelBB, std::function< void(BasicBlock *)> Callback)
Delete DelBB.
void deleteBB(BasicBlock *DelBB)
Delete DelBB.
SmallPtrSet< BasicBlockT *, 8 > DeletedBBs
void eraseDelBBNode(BasicBlockT *DelBB)
Erase Basic Block node before it is unlinked from Function in the DomTree and PostDomTree.
const UpdateStrategy Strategy
LLVM_DUMP_METHOD void dump() const
Debug method to help view the internal state of this class.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool pred_empty(const BasicBlock *BB)