From 159ef37735f21ae373282e0c53cbd9b6af1e0dfd Mon Sep 17 00:00:00 2001 From: Jakub Kuderski Date: Fri, 27 Sep 2019 19:33:39 +0000 Subject: [PATCH] Revert [Dominators][CodeGen] Clean up MachineDominators This reverts r373101 (git commit 72c57ec3e6b320c31274dadb888dc16772b8e7b6) llvm-svn: 373117 --- llvm/include/llvm/CodeGen/MachineDominators.h | 63 +++++++++++++++------------ llvm/lib/CodeGen/MachineDominators.cpp | 16 +++++-- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineDominators.h b/llvm/include/llvm/CodeGen/MachineDominators.h index e4d7a02..d2200080 100644 --- a/llvm/include/llvm/CodeGen/MachineDominators.h +++ b/llvm/include/llvm/CodeGen/MachineDominators.h @@ -44,8 +44,6 @@ using MachineDomTreeNode = DomTreeNodeBase; /// compute a normal dominator tree. /// class MachineDominatorTree : public MachineFunctionPass { - using DomTreeT = DomTreeBase; - /// Helper structure used to hold all the basic blocks /// involved in the split of a critical edge. struct CriticalEdge { @@ -67,8 +65,8 @@ class MachineDominatorTree : public MachineFunctionPass { /// such as BB == elt.NewBB. mutable SmallSet NewBBs; - /// The DominatorTreeBase that is used to compute a normal dominator tree. - std::unique_ptr DT; + /// The DominatorTreeBase that is used to compute a normal dominator tree + std::unique_ptr> DT; /// Apply all the recorded critical edges to the DT. /// This updates the underlying DT information in a way that uses @@ -82,8 +80,8 @@ public: MachineDominatorTree(); - DomTreeT &getBase() { - if (!DT) DT.reset(new DomTreeT()); + DomTreeBase &getBase() { + if (!DT) DT.reset(new DomTreeBase()); applySplitCriticalEdges(); return *DT; } @@ -94,30 +92,31 @@ public: /// multiple blocks if we are computing post dominators. For forward /// dominators, this will always be a single block (the entry node). /// - const SmallVectorImpl &getRoots() const { + inline const SmallVectorImpl &getRoots() const { applySplitCriticalEdges(); return DT->getRoots(); } - MachineBasicBlock *getRoot() const { + inline MachineBasicBlock *getRoot() const { applySplitCriticalEdges(); return DT->getRoot(); } - MachineDomTreeNode *getRootNode() const { + inline MachineDomTreeNode *getRootNode() const { applySplitCriticalEdges(); return DT->getRootNode(); } bool runOnMachineFunction(MachineFunction &F) override; - bool dominates(const MachineDomTreeNode *A, - const MachineDomTreeNode *B) const { + inline bool dominates(const MachineDomTreeNode* A, + const MachineDomTreeNode* B) const { applySplitCriticalEdges(); return DT->dominates(A, B); } - bool dominates(const MachineBasicBlock *A, const MachineBasicBlock *B) const { + inline bool dominates(const MachineBasicBlock* A, + const MachineBasicBlock* B) const { applySplitCriticalEdges(); return DT->dominates(A, B); } @@ -134,30 +133,36 @@ public: for (; &*I != A && &*I != B; ++I) /*empty*/ ; - return &*I == A; + //if(!DT.IsPostDominators) { + // 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; + //} } - bool properlyDominates(const MachineDomTreeNode *A, - const MachineDomTreeNode *B) const { + inline bool properlyDominates(const MachineDomTreeNode* A, + const MachineDomTreeNode* B) const { applySplitCriticalEdges(); return DT->properlyDominates(A, B); } - bool properlyDominates(const MachineBasicBlock *A, - const MachineBasicBlock *B) const { + inline bool properlyDominates(const MachineBasicBlock* A, + const MachineBasicBlock* B) const { applySplitCriticalEdges(); return DT->properlyDominates(A, B); } /// findNearestCommonDominator - Find nearest common dominator basic block /// for basic block A and B. If there is no such block then return NULL. - MachineBasicBlock *findNearestCommonDominator(MachineBasicBlock *A, - MachineBasicBlock *B) { + inline MachineBasicBlock *findNearestCommonDominator(MachineBasicBlock *A, + MachineBasicBlock *B) { applySplitCriticalEdges(); return DT->findNearestCommonDominator(A, B); } - MachineDomTreeNode *operator[](MachineBasicBlock *BB) const { + inline MachineDomTreeNode *operator[](MachineBasicBlock *BB) const { applySplitCriticalEdges(); return DT->getNode(BB); } @@ -165,7 +170,7 @@ public: /// getNode - return the (Post)DominatorTree node for the specified basic /// block. This is the same as using operator[] on this class. /// - MachineDomTreeNode *getNode(MachineBasicBlock *BB) const { + inline MachineDomTreeNode *getNode(MachineBasicBlock *BB) const { applySplitCriticalEdges(); return DT->getNode(BB); } @@ -173,8 +178,8 @@ public: /// 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 /// the children list of the immediate dominator. - MachineDomTreeNode *addNewBlock(MachineBasicBlock *BB, - MachineBasicBlock *DomBB) { + inline MachineDomTreeNode *addNewBlock(MachineBasicBlock *BB, + MachineBasicBlock *DomBB) { applySplitCriticalEdges(); return DT->addNewBlock(BB, DomBB); } @@ -182,14 +187,14 @@ public: /// changeImmediateDominator - This method is used to update the dominator /// tree information when a node's immediate dominator changes. /// - void changeImmediateDominator(MachineBasicBlock *N, - MachineBasicBlock *NewIDom) { + inline void changeImmediateDominator(MachineBasicBlock *N, + MachineBasicBlock* NewIDom) { applySplitCriticalEdges(); DT->changeImmediateDominator(N, NewIDom); } - void changeImmediateDominator(MachineDomTreeNode *N, - MachineDomTreeNode *NewIDom) { + inline void changeImmediateDominator(MachineDomTreeNode *N, + MachineDomTreeNode* NewIDom) { applySplitCriticalEdges(); DT->changeImmediateDominator(N, NewIDom); } @@ -197,14 +202,14 @@ public: /// eraseNode - Removes a node from the dominator tree. Block must not /// dominate any other blocks. Removes node from its immediate dominator's /// children list. Deletes dominator node associated with basic block BB. - void eraseNode(MachineBasicBlock *BB) { + inline void eraseNode(MachineBasicBlock *BB) { applySplitCriticalEdges(); DT->eraseNode(BB); } /// splitBlock - BB is split and now it has one successor. Update dominator /// tree to reflect this change. - void splitBlock(MachineBasicBlock* NewBB) { + inline void splitBlock(MachineBasicBlock* NewBB) { applySplitCriticalEdges(); DT->splitBlock(NewBB); } diff --git a/llvm/lib/CodeGen/MachineDominators.cpp b/llvm/lib/CodeGen/MachineDominators.cpp index a7d7b6e..1dfba86 100644 --- a/llvm/lib/CodeGen/MachineDominators.cpp +++ b/llvm/lib/CodeGen/MachineDominators.cpp @@ -64,11 +64,21 @@ void MachineDominatorTree::releaseMemory() { } void MachineDominatorTree::verifyAnalysis() const { - if (DT && VerifyMachineDomInfo) - if (!DT->verify(DomTreeT::VerificationLevel::Basic)) { - errs() << "MachineDominatorTree verification failed\n"; + if (DT && VerifyMachineDomInfo) { + MachineFunction &F = *getRoot()->getParent(); + + DomTreeBase 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(); } + } } void MachineDominatorTree::print(raw_ostream &OS, const Module*) const { -- 2.7.4