forked from OSchip/llvm-project
[Dominators][CodeGen] Clean up MachineDominators
Summary: This is a cleanup patch for MachineDominatorTree. It would be an NFC, except for replacing custom DomTree verification with the generic one. Reviewers: tstellar, tpr, nhaehnle, arsenm, NutshellySima, grosser, hliao Reviewed By: arsenm Subscribers: wdng, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67976 llvm-svn: 373101
This commit is contained in:
parent
1a55431a03
commit
72c57ec3e6
|
@ -44,6 +44,8 @@ using MachineDomTreeNode = DomTreeNodeBase<MachineBasicBlock>;
|
||||||
/// compute a normal dominator tree.
|
/// compute a normal dominator tree.
|
||||||
///
|
///
|
||||||
class MachineDominatorTree : public MachineFunctionPass {
|
class MachineDominatorTree : public MachineFunctionPass {
|
||||||
|
using DomTreeT = DomTreeBase<MachineBasicBlock>;
|
||||||
|
|
||||||
/// Helper structure used to hold all the basic blocks
|
/// Helper structure used to hold all the basic blocks
|
||||||
/// involved in the split of a critical edge.
|
/// involved in the split of a critical edge.
|
||||||
struct CriticalEdge {
|
struct CriticalEdge {
|
||||||
|
@ -65,8 +67,8 @@ class MachineDominatorTree : public MachineFunctionPass {
|
||||||
/// such as BB == elt.NewBB.
|
/// such as BB == elt.NewBB.
|
||||||
mutable SmallSet<MachineBasicBlock *, 32> NewBBs;
|
mutable SmallSet<MachineBasicBlock *, 32> NewBBs;
|
||||||
|
|
||||||
/// The DominatorTreeBase that is used to compute a normal dominator tree
|
/// The DominatorTreeBase that is used to compute a normal dominator tree.
|
||||||
std::unique_ptr<DomTreeBase<MachineBasicBlock>> DT;
|
std::unique_ptr<DomTreeT> DT;
|
||||||
|
|
||||||
/// Apply all the recorded critical edges to the DT.
|
/// Apply all the recorded critical edges to the DT.
|
||||||
/// This updates the underlying DT information in a way that uses
|
/// This updates the underlying DT information in a way that uses
|
||||||
|
@ -80,8 +82,8 @@ public:
|
||||||
|
|
||||||
MachineDominatorTree();
|
MachineDominatorTree();
|
||||||
|
|
||||||
DomTreeBase<MachineBasicBlock> &getBase() {
|
DomTreeT &getBase() {
|
||||||
if (!DT) DT.reset(new DomTreeBase<MachineBasicBlock>());
|
if (!DT) DT.reset(new DomTreeT());
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return *DT;
|
return *DT;
|
||||||
}
|
}
|
||||||
|
@ -92,31 +94,30 @@ public:
|
||||||
/// multiple blocks if we are computing post dominators. For forward
|
/// multiple blocks if we are computing post dominators. For forward
|
||||||
/// dominators, this will always be a single block (the entry node).
|
/// dominators, this will always be a single block (the entry node).
|
||||||
///
|
///
|
||||||
inline const SmallVectorImpl<MachineBasicBlock*> &getRoots() const {
|
const SmallVectorImpl<MachineBasicBlock*> &getRoots() const {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->getRoots();
|
return DT->getRoots();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline MachineBasicBlock *getRoot() const {
|
MachineBasicBlock *getRoot() const {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->getRoot();
|
return DT->getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline MachineDomTreeNode *getRootNode() const {
|
MachineDomTreeNode *getRootNode() const {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->getRootNode();
|
return DT->getRootNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnMachineFunction(MachineFunction &F) override;
|
bool runOnMachineFunction(MachineFunction &F) override;
|
||||||
|
|
||||||
inline bool dominates(const MachineDomTreeNode* A,
|
bool dominates(const MachineDomTreeNode *A,
|
||||||
const MachineDomTreeNode* B) const {
|
const MachineDomTreeNode *B) const {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->dominates(A, B);
|
return DT->dominates(A, B);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool dominates(const MachineBasicBlock* A,
|
bool dominates(const MachineBasicBlock *A, const MachineBasicBlock *B) const {
|
||||||
const MachineBasicBlock* B) const {
|
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->dominates(A, B);
|
return DT->dominates(A, B);
|
||||||
}
|
}
|
||||||
|
@ -133,36 +134,30 @@ public:
|
||||||
for (; &*I != A && &*I != B; ++I)
|
for (; &*I != A && &*I != B; ++I)
|
||||||
/*empty*/ ;
|
/*empty*/ ;
|
||||||
|
|
||||||
//if(!DT.IsPostDominators) {
|
return &*I == A;
|
||||||
// A dominates B if it is found first in the basic block.
|
|
||||||
return &*I == A;
|
|
||||||
//} else {
|
|
||||||
// // A post-dominates B if B is found first in the basic block.
|
|
||||||
// return &*I == B;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool properlyDominates(const MachineDomTreeNode* A,
|
bool properlyDominates(const MachineDomTreeNode *A,
|
||||||
const MachineDomTreeNode* B) const {
|
const MachineDomTreeNode *B) const {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->properlyDominates(A, B);
|
return DT->properlyDominates(A, B);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool properlyDominates(const MachineBasicBlock* A,
|
bool properlyDominates(const MachineBasicBlock *A,
|
||||||
const MachineBasicBlock* B) const {
|
const MachineBasicBlock *B) const {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->properlyDominates(A, B);
|
return DT->properlyDominates(A, B);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// findNearestCommonDominator - Find nearest common dominator basic block
|
/// findNearestCommonDominator - Find nearest common dominator basic block
|
||||||
/// for basic block A and B. If there is no such block then return NULL.
|
/// for basic block A and B. If there is no such block then return NULL.
|
||||||
inline MachineBasicBlock *findNearestCommonDominator(MachineBasicBlock *A,
|
MachineBasicBlock *findNearestCommonDominator(MachineBasicBlock *A,
|
||||||
MachineBasicBlock *B) {
|
MachineBasicBlock *B) {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->findNearestCommonDominator(A, B);
|
return DT->findNearestCommonDominator(A, B);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
|
MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->getNode(BB);
|
return DT->getNode(BB);
|
||||||
}
|
}
|
||||||
|
@ -170,7 +165,7 @@ public:
|
||||||
/// getNode - return the (Post)DominatorTree node for the specified basic
|
/// getNode - return the (Post)DominatorTree node for the specified basic
|
||||||
/// block. This is the same as using operator[] on this class.
|
/// block. This is the same as using operator[] on this class.
|
||||||
///
|
///
|
||||||
inline MachineDomTreeNode *getNode(MachineBasicBlock *BB) const {
|
MachineDomTreeNode *getNode(MachineBasicBlock *BB) const {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->getNode(BB);
|
return DT->getNode(BB);
|
||||||
}
|
}
|
||||||
|
@ -178,8 +173,8 @@ public:
|
||||||
/// addNewBlock - Add a new node to the dominator tree information. This
|
/// addNewBlock - Add a new node to the dominator tree information. This
|
||||||
/// creates a new node as a child of DomBB dominator node,linking it into
|
/// creates a new node as a child of DomBB dominator node,linking it into
|
||||||
/// the children list of the immediate dominator.
|
/// the children list of the immediate dominator.
|
||||||
inline MachineDomTreeNode *addNewBlock(MachineBasicBlock *BB,
|
MachineDomTreeNode *addNewBlock(MachineBasicBlock *BB,
|
||||||
MachineBasicBlock *DomBB) {
|
MachineBasicBlock *DomBB) {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
return DT->addNewBlock(BB, DomBB);
|
return DT->addNewBlock(BB, DomBB);
|
||||||
}
|
}
|
||||||
|
@ -187,14 +182,14 @@ public:
|
||||||
/// changeImmediateDominator - This method is used to update the dominator
|
/// changeImmediateDominator - This method is used to update the dominator
|
||||||
/// tree information when a node's immediate dominator changes.
|
/// tree information when a node's immediate dominator changes.
|
||||||
///
|
///
|
||||||
inline void changeImmediateDominator(MachineBasicBlock *N,
|
void changeImmediateDominator(MachineBasicBlock *N,
|
||||||
MachineBasicBlock* NewIDom) {
|
MachineBasicBlock *NewIDom) {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
DT->changeImmediateDominator(N, NewIDom);
|
DT->changeImmediateDominator(N, NewIDom);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void changeImmediateDominator(MachineDomTreeNode *N,
|
void changeImmediateDominator(MachineDomTreeNode *N,
|
||||||
MachineDomTreeNode* NewIDom) {
|
MachineDomTreeNode *NewIDom) {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
DT->changeImmediateDominator(N, NewIDom);
|
DT->changeImmediateDominator(N, NewIDom);
|
||||||
}
|
}
|
||||||
|
@ -202,14 +197,14 @@ public:
|
||||||
/// eraseNode - Removes a node from the dominator tree. Block must not
|
/// eraseNode - Removes a node from the dominator tree. Block must not
|
||||||
/// dominate any other blocks. Removes node from its immediate dominator's
|
/// dominate any other blocks. Removes node from its immediate dominator's
|
||||||
/// children list. Deletes dominator node associated with basic block BB.
|
/// children list. Deletes dominator node associated with basic block BB.
|
||||||
inline void eraseNode(MachineBasicBlock *BB) {
|
void eraseNode(MachineBasicBlock *BB) {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
DT->eraseNode(BB);
|
DT->eraseNode(BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// splitBlock - BB is split and now it has one successor. Update dominator
|
/// splitBlock - BB is split and now it has one successor. Update dominator
|
||||||
/// tree to reflect this change.
|
/// tree to reflect this change.
|
||||||
inline void splitBlock(MachineBasicBlock* NewBB) {
|
void splitBlock(MachineBasicBlock* NewBB) {
|
||||||
applySplitCriticalEdges();
|
applySplitCriticalEdges();
|
||||||
DT->splitBlock(NewBB);
|
DT->splitBlock(NewBB);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,21 +64,11 @@ void MachineDominatorTree::releaseMemory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineDominatorTree::verifyAnalysis() const {
|
void MachineDominatorTree::verifyAnalysis() const {
|
||||||
if (DT && VerifyMachineDomInfo) {
|
if (DT && VerifyMachineDomInfo)
|
||||||
MachineFunction &F = *getRoot()->getParent();
|
if (!DT->verify(DomTreeT::VerificationLevel::Basic)) {
|
||||||
|
errs() << "MachineDominatorTree verification failed\n";
|
||||||
DomTreeBase<MachineBasicBlock> OtherDT;
|
|
||||||
OtherDT.recalculate(F);
|
|
||||||
if (getRootNode()->getBlock() != OtherDT.getRootNode()->getBlock() ||
|
|
||||||
DT->compare(OtherDT)) {
|
|
||||||
errs() << "MachineDominatorTree for function " << F.getName()
|
|
||||||
<< " is not up to date!\nComputed:\n";
|
|
||||||
DT->print(errs());
|
|
||||||
errs() << "\nActual:\n";
|
|
||||||
OtherDT.print(errs());
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineDominatorTree::print(raw_ostream &OS, const Module*) const {
|
void MachineDominatorTree::print(raw_ostream &OS, const Module*) const {
|
||||||
|
|
Loading…
Reference in New Issue