LLVM 19.0.0git
Classes | Public Types | Public Member Functions | List of all members
llvm::DomTreeUpdater Class Reference

#include "llvm/Analysis/DomTreeUpdater.h"

Public Types

enum class  UpdateStrategy : unsigned char { Eager = 0 , Lazy = 1 }
 

Public Member Functions

 DomTreeUpdater (UpdateStrategy Strategy_)
 
 DomTreeUpdater (DominatorTree &DT_, UpdateStrategy Strategy_)
 
 DomTreeUpdater (DominatorTree *DT_, UpdateStrategy Strategy_)
 
 DomTreeUpdater (PostDominatorTree &PDT_, UpdateStrategy Strategy_)
 
 DomTreeUpdater (PostDominatorTree *PDT_, UpdateStrategy Strategy_)
 
 DomTreeUpdater (DominatorTree &DT_, PostDominatorTree &PDT_, UpdateStrategy Strategy_)
 
 DomTreeUpdater (DominatorTree *DT_, PostDominatorTree *PDT_, UpdateStrategy Strategy_)
 
 ~DomTreeUpdater ()
 
bool isLazy () const
 Returns true if the current strategy is Lazy.
 
bool isEager () const
 Returns true if the current strategy is Eager.
 
bool hasDomTree () const
 Returns true if it holds a DominatorTree.
 
bool hasPostDomTree () const
 Returns true if it holds a PostDominatorTree.
 
bool hasPendingDeletedBB () const
 Returns true if there is BasicBlock awaiting deletion.
 
bool isBBPendingDeletion (BasicBlock *DelBB) const
 Returns true if DelBB is awaiting deletion.
 
bool hasPendingUpdates () const
 Returns true if either of DT or PDT is valid and the tree has at least one update pending.
 
bool hasPendingDomTreeUpdates () const
 Returns true if there are DominatorTree updates queued.
 
bool hasPendingPostDomTreeUpdates () const
 Returns true if there are PostDominatorTree updates queued.
 
LLVM_DUMP_METHOD void dump () const
 Debug method to help view the internal state of this class.
 
Mutation APIs

These methods provide APIs for submitting updates to the DominatorTree and the PostDominatorTree.

Note: There are two strategies to update the DominatorTree and the PostDominatorTree:

  1. Eager UpdateStrategy: Updates are submitted and then flushed immediately.
  2. Lazy UpdateStrategy: Updates are submitted but only flushed when you explicitly call Flush APIs. It is recommended to use this update strategy when you submit a bunch of updates multiple times which can then add up to a large number of updates between two queries on the DominatorTree. The incremental updater can reschedule the updates or decide to recalculate the dominator tree in order to speedup the updating process depending on the number of updates.

Although GenericDomTree provides several update primitives, it is not encouraged to use these APIs directly.

void applyUpdates (ArrayRef< DominatorTree::UpdateType > Updates)
 Submit updates to all available trees.
 
void applyUpdatesPermissive (ArrayRef< DominatorTree::UpdateType > Updates)
 Submit updates to all available trees.
 
void recalculate (Function &F)
 Notify DTU that the entry block was replaced.
 
void deleteBB (BasicBlock *DelBB)
 Delete DelBB.
 
void callbackDeleteBB (BasicBlock *DelBB, std::function< void(BasicBlock *)> Callback)
 Delete DelBB.
 
Flush APIs

CAUTION! By the moment these flush APIs are called, the current CFG needs to be the same as the CFG which DTU is in sync with + all updates submitted.

DominatorTreegetDomTree ()
 Flush DomTree updates and return DomTree.
 
PostDominatorTreegetPostDomTree ()
 Flush PostDomTree updates and return PostDomTree.
 
void flush ()
 Apply all pending updates to available trees and flush all BasicBlocks awaiting deletion.
 

Detailed Description

Examples
/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/llvm/include/llvm/Transforms/Utils/Local.h.

Definition at line 28 of file DomTreeUpdater.h.

Member Enumeration Documentation

◆ UpdateStrategy

Enumerator
Eager 
Lazy 

Definition at line 30 of file DomTreeUpdater.h.

Constructor & Destructor Documentation

◆ DomTreeUpdater() [1/7]

llvm::DomTreeUpdater::DomTreeUpdater ( UpdateStrategy  Strategy_)
inlineexplicit

Definition at line 32 of file DomTreeUpdater.h.

◆ DomTreeUpdater() [2/7]

llvm::DomTreeUpdater::DomTreeUpdater ( DominatorTree DT_,
UpdateStrategy  Strategy_ 
)
inline

Definition at line 33 of file DomTreeUpdater.h.

◆ DomTreeUpdater() [3/7]

llvm::DomTreeUpdater::DomTreeUpdater ( DominatorTree DT_,
UpdateStrategy  Strategy_ 
)
inline

Definition at line 35 of file DomTreeUpdater.h.

◆ DomTreeUpdater() [4/7]

llvm::DomTreeUpdater::DomTreeUpdater ( PostDominatorTree PDT_,
UpdateStrategy  Strategy_ 
)
inline

Definition at line 37 of file DomTreeUpdater.h.

◆ DomTreeUpdater() [5/7]

llvm::DomTreeUpdater::DomTreeUpdater ( PostDominatorTree PDT_,
UpdateStrategy  Strategy_ 
)
inline

Definition at line 39 of file DomTreeUpdater.h.

◆ DomTreeUpdater() [6/7]

llvm::DomTreeUpdater::DomTreeUpdater ( DominatorTree DT_,
PostDominatorTree PDT_,
UpdateStrategy  Strategy_ 
)
inline

Definition at line 41 of file DomTreeUpdater.h.

◆ DomTreeUpdater() [7/7]

llvm::DomTreeUpdater::DomTreeUpdater ( DominatorTree DT_,
PostDominatorTree PDT_,
UpdateStrategy  Strategy_ 
)
inline

Definition at line 44 of file DomTreeUpdater.h.

◆ ~DomTreeUpdater()

llvm::DomTreeUpdater::~DomTreeUpdater ( )
inline

Definition at line 48 of file DomTreeUpdater.h.

References flush().

Member Function Documentation

◆ applyUpdates()

void llvm::DomTreeUpdater::applyUpdates ( ArrayRef< DominatorTree::UpdateType Updates)

Submit updates to all available trees.

The Eager Strategy flushes updates immediately while the Lazy Strategy queues the updates.

Note: The "existence" of an edge in a CFG refers to the CFG which DTU is in sync with + all updates before that single update.

CAUTION!

  1. It is required for the state of the LLVM IR to be updated before submitting the updates because the internal update routine will analyze the current state of the CFG to determine whether an update is valid.
  2. It is illegal to submit any update that has already been submitted, i.e., you are supposed not to insert an existent edge or delete a nonexistent edge.

Definition at line 230 of file DomTreeUpdater.cpp.

References llvm::DominatorTreeBase< NodeT, IsPostDom >::applyUpdates(), Lazy, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::ArrayRef< T >::size(), and llvm::SmallVectorBase< Size_T >::size().

Referenced by llvm::breakLoopBackedge(), llvm::changeToCall(), llvm::changeToInvokeAndSplitBasicBlock(), llvm::changeToUnreachable(), llvm::ConstantFoldTerminator(), createUnreachableSwitchDefault(), llvm::DeleteDeadBlocks(), llvm::deleteDeadLoop(), llvm::DuplicateInstructionsInSplitBetween(), llvm::ehAwareSplitEdge(), eliminateDeadSwitchCases(), expandToSwitch(), FoldCondBranchOnValueKnownInPredecessorImpl(), llvm::FoldReturnIntoUncondBranch(), FoldTwoEntryPHINode(), llvm::MergeBlockIntoPredecessor(), performBranchToCommonDestFolding(), removeEmptyCleanup(), removeSwitchAfterSelectFold(), removeUndefIntroducingPredecessor(), llvm::removeUnwindEdge(), replaceConditionalBranchesOnConstant(), runImpl(), SimplifyCondBranchToCondBranch(), llvm::SplitBlockAndInsertIfThenElse(), llvm::splitBlockBefore(), SplitBlockImpl(), SwitchToLookupTable(), tailMergeBlocksWithSimilarFunctionTerminators(), TryToMergeLandingPad(), llvm::TryToSimplifyUncondBranchFromEmptyBlock(), tryWidenCondBranchToCondBranch(), llvm::UnrollLoop(), and UpdateAnalysisInformation().

◆ applyUpdatesPermissive()

void llvm::DomTreeUpdater::applyUpdatesPermissive ( ArrayRef< DominatorTree::UpdateType Updates)

Submit updates to all available trees.

It will also

  1. discard duplicated updates,
  2. remove invalid updates. (Invalid updates means deletion of an edge that still exists or insertion of an edge that does not exist.) The Eager Strategy flushes updates immediately while the Lazy Strategy queues the updates.

Note: The "existence" of an edge in a CFG refers to the CFG which DTU is in sync with + all updates before that single update.

CAUTION!

  1. It is required for the state of the LLVM IR to be updated before submitting the updates because the internal update routine will analyze the current state of the CFG to determine whether an update is valid.
  2. It is illegal to submit any update that has already been submitted, i.e., you are supposed not to insert an existent edge or delete a nonexistent edge.
  3. It is only legal to submit updates to an edge in the order CFG changes are made. The order you submit updates on different edges is not restricted.

Definition at line 249 of file DomTreeUpdater.cpp.

References llvm::DominatorTreeBase< NodeT, IsPostDom >::applyUpdates(), llvm::SmallSet< T, N, C >::count(), llvm::SmallSet< T, N, C >::insert(), isLazy(), Lazy, and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by llvm::MergeBasicBlockIntoOnlyPred(), processSwitch(), llvm::SCCPSolver::removeNonFeasibleEdges(), splitCallSite(), and llvm::UnrollAndJamLoop().

◆ callbackDeleteBB()

void llvm::DomTreeUpdater::callbackDeleteBB ( BasicBlock DelBB,
std::function< void(BasicBlock *)>  Callback 
)

Delete DelBB.

DelBB will be removed from its Parent and erased from available trees if it exists. Then the callback will be called. Finally, DelBB will be deleted. Under Eager UpdateStrategy, DelBB will be processed immediately. Under Lazy UpdateStrategy, DelBB will be queued until a flush event and all available trees are up-to-date. Assert if any instruction of DelBB is modified while awaiting deletion. Multiple callbacks can be queued for one DelBB under Lazy UpdateStrategy.

Definition at line 189 of file DomTreeUpdater.cpp.

References Lazy, and llvm::BasicBlock::removeFromParent().

◆ deleteBB()

void llvm::DomTreeUpdater::deleteBB ( BasicBlock DelBB)

Delete DelBB.

DelBB will be removed from its Parent and erased from available trees if it exists and finally get deleted. Under Eager UpdateStrategy, DelBB will be processed immediately. Under Lazy UpdateStrategy, DelBB will be queued until a flush event and all available trees are up-to-date. Assert if any instruction of DelBB is modified while awaiting deletion. When both DT and PDT are nullptrs, DelBB will be queued until flush() is called.

Definition at line 177 of file DomTreeUpdater.cpp.

References Lazy, and llvm::BasicBlock::removeFromParent().

Referenced by llvm::DeleteDeadBlocks(), llvm::MergeBasicBlockIntoOnlyPred(), runSCCP(), and splitCallSite().

◆ dump()

LLVM_DUMP_METHOD void llvm::DomTreeUpdater::dump ( ) const

◆ flush()

void llvm::DomTreeUpdater::flush ( )

Apply all pending updates to available trees and flush all BasicBlocks awaiting deletion.

Definition at line 73 of file DomTreeUpdater.cpp.

Referenced by llvm::ehAwareSplitEdge(), llvm::JumpThreadingPass::run(), and ~DomTreeUpdater().

◆ getDomTree()

DominatorTree & llvm::DomTreeUpdater::getDomTree ( )

Flush DomTree updates and return DomTree.

It flushes Deleted BBs if both trees are up-to-date. It must only be called when it has a DomTree.

Definition at line 303 of file DomTreeUpdater.cpp.

References assert().

Referenced by runImpl(), llvm::RewriteStatepointsForGC::runOnFunction(), shouldSplitOnPredicatedArgument(), llvm::splitBlockBefore(), llvm::UnrollAndJamLoop(), llvm::UnrollLoop(), and UpdateAnalysisInformation().

◆ getPostDomTree()

PostDominatorTree & llvm::DomTreeUpdater::getPostDomTree ( )

Flush PostDomTree updates and return PostDomTree.

It flushes Deleted BBs if both trees are up-to-date. It must only be called when it has a PostDomTree.

Definition at line 310 of file DomTreeUpdater.cpp.

References assert().

◆ hasDomTree()

bool llvm::DomTreeUpdater::hasDomTree ( ) const
inline

Returns true if it holds a DominatorTree.

Definition at line 57 of file DomTreeUpdater.h.

Referenced by llvm::MergeBasicBlockIntoOnlyPred(), shouldSplitOnPredicatedArgument(), and UpdateAnalysisInformation().

◆ hasPendingDeletedBB()

bool llvm::DomTreeUpdater::hasPendingDeletedBB ( ) const
inline

Returns true if there is BasicBlock awaiting deletion.

The deletion will only happen until a flush event and all available trees are up-to-date. Returns false under Eager UpdateStrategy.

Definition at line 66 of file DomTreeUpdater.h.

◆ hasPendingDomTreeUpdates()

bool llvm::DomTreeUpdater::hasPendingDomTreeUpdates ( ) const

Returns true if there are DominatorTree updates queued.

Returns false under Eager UpdateStrategy or DT is nullptr.

Definition at line 154 of file DomTreeUpdater.cpp.

References llvm::SmallVectorBase< Size_T >::size().

Referenced by hasPendingUpdates().

◆ hasPendingPostDomTreeUpdates()

bool llvm::DomTreeUpdater::hasPendingPostDomTreeUpdates ( ) const

Returns true if there are PostDominatorTree updates queued.

Returns false under Eager UpdateStrategy or PDT is nullptr.

Definition at line 160 of file DomTreeUpdater.cpp.

References llvm::SmallVectorBase< Size_T >::size().

Referenced by hasPendingUpdates().

◆ hasPendingUpdates()

bool llvm::DomTreeUpdater::hasPendingUpdates ( ) const

Returns true if either of DT or PDT is valid and the tree has at least one update pending.

If DT or PDT is nullptr it is treated as having no pending updates. This function does not check whether there is BasicBlock awaiting deletion. Returns false under Eager UpdateStrategy.

Definition at line 150 of file DomTreeUpdater.cpp.

References hasPendingDomTreeUpdates(), and hasPendingPostDomTreeUpdates().

◆ hasPostDomTree()

bool llvm::DomTreeUpdater::hasPostDomTree ( ) const
inline

Returns true if it holds a PostDominatorTree.

Definition at line 60 of file DomTreeUpdater.h.

◆ isBBPendingDeletion()

bool llvm::DomTreeUpdater::isBBPendingDeletion ( llvm::BasicBlock DelBB) const

Returns true if DelBB is awaiting deletion.

Returns false under Eager UpdateStrategy.

Definition at line 166 of file DomTreeUpdater.cpp.

References Eager.

Referenced by iterativelySimplifyCFG(), llvm::removeUnreachableBlocks(), and tailMergeBlocksWithSimilarFunctionTerminators().

◆ isEager()

bool llvm::DomTreeUpdater::isEager ( ) const
inline

Returns true if the current strategy is Eager.

Definition at line 54 of file DomTreeUpdater.h.

References Eager.

◆ isLazy()

bool llvm::DomTreeUpdater::isLazy ( ) const
inline

Returns true if the current strategy is Lazy.

Definition at line 51 of file DomTreeUpdater.h.

References Lazy.

Referenced by applyUpdatesPermissive().

◆ recalculate()

void llvm::DomTreeUpdater::recalculate ( Function F)

Notify DTU that the entry block was replaced.

Recalculate all available trees and flush all BasicBlocks awaiting deletion immediately.

Definition at line 120 of file DomTreeUpdater.cpp.

References Eager, F, llvm::DominatorTreeBase< NodeT, IsPostDom >::recalculate(), and llvm::SmallVectorBase< Size_T >::size().

Referenced by llvm::MergeBasicBlockIntoOnlyPred(), and UpdateAnalysisInformation().


The documentation for this class was generated from the following files: