From: Owen Anderson Date: Mon, 8 Oct 2007 07:44:39 +0000 (+0000) Subject: Begin the process of allowing DomTree on MBB's. Step One: template DomTreeNode by... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1aad74c9e8aba2ad0493620d35966ee3964c1ecb;p=oota-llvm.git Begin the process of allowing DomTree on MBB's. Step One: template DomTreeNode by making it a typedef of a templated DomTreeNodeBase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42743 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h index abff3998cec..6dcf2a42410 100644 --- a/include/llvm/Analysis/Dominators.h +++ b/include/llvm/Analysis/Dominators.h @@ -22,6 +22,7 @@ #define LLVM_ANALYSIS_DOMINATORS_H #include "llvm/Pass.h" +#include #include #include "llvm/ADT/DenseMap.h" @@ -59,32 +60,56 @@ public: // DomTreeNode - Dominator Tree Node class DominatorTreeBase; class PostDominatorTree; -class DomTreeNode { - BasicBlock *TheBB; - DomTreeNode *IDom; - std::vector Children; +class MachineBasicBlock; + +template +class DomTreeNodeBase { + NodeT *TheBB; + DomTreeNodeBase *IDom; + std::vector *> Children; int DFSNumIn, DFSNumOut; friend class DominatorTreeBase; friend class PostDominatorTree; public: - typedef std::vector::iterator iterator; - typedef std::vector::const_iterator const_iterator; + typedef typename std::vector *>::iterator iterator; + typedef typename std::vector *>::const_iterator + const_iterator; iterator begin() { return Children.begin(); } iterator end() { return Children.end(); } const_iterator begin() const { return Children.begin(); } const_iterator end() const { return Children.end(); } - BasicBlock *getBlock() const { return TheBB; } - DomTreeNode *getIDom() const { return IDom; } - const std::vector &getChildren() const { return Children; } + NodeT *getBlock() const { return TheBB; } + DomTreeNodeBase *getIDom() const { return IDom; } + const std::vector*> &getChildren() const { + return Children; + } - DomTreeNode(BasicBlock *BB, DomTreeNode *iDom) + DomTreeNodeBase(NodeT *BB, DomTreeNodeBase *iDom) : TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) { } - DomTreeNode *addChild(DomTreeNode *C) { Children.push_back(C); return C; } - void setIDom(DomTreeNode *NewIDom); - + + DomTreeNodeBase *addChild(DomTreeNodeBase *C) { + Children.push_back(C); + return C; + } + + void setIDom(DomTreeNodeBase *NewIDom) { + assert(IDom && "No immediate dominator?"); + if (IDom != NewIDom) { + std::vector*>::iterator I = + std::find(IDom->Children.begin(), IDom->Children.end(), this); + assert(I != IDom->Children.end() && + "Not in immediate dominator children set!"); + // I am no longer your child... + IDom->Children.erase(I); + + // Switch to new dominator + IDom = NewIDom; + IDom->Children.push_back(this); + } + } /// getDFSNumIn/getDFSNumOut - These are an internal implementation detail, do /// not call them. @@ -93,12 +118,15 @@ public: private: // Return true if this node is dominated by other. Use this only if DFS info // is valid. - bool DominatedBy(const DomTreeNode *other) const { + bool DominatedBy(const DomTreeNodeBase *other) const { return this->DFSNumIn >= other->DFSNumIn && this->DFSNumOut <= other->DFSNumOut; } }; +typedef DomTreeNodeBase DomTreeNode; +typedef DomTreeNodeBase MachineDomTreeNode; + //===----------------------------------------------------------------------===// /// DominatorTree - Calculate the immediate dominator tree for a function. /// @@ -162,7 +190,8 @@ public: /// properlyDominates - Returns true iff this dominates N and this != N. /// Note that this is not a constant time operation! /// - bool properlyDominates(const DomTreeNode *A, DomTreeNode *B) const { + bool properlyDominates(const DomTreeNode *A, + DomTreeNode *B) const { if (A == 0 || B == 0) return false; return dominatedBySlowTreeWalk(A, B); } @@ -188,7 +217,8 @@ public: /// dominates - Returns true iff A dominates B. Note that this is not a /// constant time operation! /// - inline bool dominates(const DomTreeNode *A, DomTreeNode *B) { + inline bool dominates(const DomTreeNode *A, + DomTreeNode *B) { if (B == A) return true; // A node trivially dominates itself. @@ -243,7 +273,8 @@ public: /// changeImmediateDominator - This method is used to update the dominator /// tree information when a node's immediate dominator changes. /// - void changeImmediateDominator(DomTreeNode *N, DomTreeNode *NewIDom) { + void changeImmediateDominator(DomTreeNode *N, + DomTreeNode *NewIDom) { assert(N && NewIDom && "Cannot change null node pointers!"); DFSInfoValid = false; N->setIDom(NewIDom); @@ -334,7 +365,7 @@ public: /// DominatorTree GraphTraits specialization so the DominatorTree can be /// iterable by generic graph iterators. /// -template <> struct GraphTraits { +template <> struct GraphTraits { typedef DomTreeNode NodeType; typedef NodeType::iterator ChildIteratorType; @@ -350,7 +381,7 @@ template <> struct GraphTraits { }; template <> struct GraphTraits - : public GraphTraits { + : public GraphTraits { static NodeType *getEntryNode(DominatorTree *DT) { return DT->getRootNode(); } diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index 4e728ac3d44..84a60257d22 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -276,22 +276,6 @@ BasicBlock *DominatorTreeBase::findNearestCommonDominator(BasicBlock *A, return NULL; } -void DomTreeNode::setIDom(DomTreeNode *NewIDom) { - assert(IDom && "No immediate dominator?"); - if (IDom != NewIDom) { - std::vector::iterator I = - std::find(IDom->Children.begin(), IDom->Children.end(), this); - assert(I != IDom->Children.end() && - "Not in immediate dominator children set!"); - // I am no longer your child... - IDom->Children.erase(I); - - // Switch to new dominator - IDom = NewIDom; - IDom->Children.push_back(this); - } -} - static std::ostream &operator<<(std::ostream &o, const DomTreeNode *Node) { if (Node->getBlock()) WriteAsOperand(o, Node->getBlock(), false);