mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-05 19:29:01 +00:00
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
This commit is contained in:
parent
537d5c27ff
commit
1aad74c9e8
@ -22,6 +22,7 @@
|
|||||||
#define LLVM_ANALYSIS_DOMINATORS_H
|
#define LLVM_ANALYSIS_DOMINATORS_H
|
||||||
|
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
|
#include <algorithm>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
|
|
||||||
@ -59,32 +60,56 @@ public:
|
|||||||
// DomTreeNode - Dominator Tree Node
|
// DomTreeNode - Dominator Tree Node
|
||||||
class DominatorTreeBase;
|
class DominatorTreeBase;
|
||||||
class PostDominatorTree;
|
class PostDominatorTree;
|
||||||
class DomTreeNode {
|
class MachineBasicBlock;
|
||||||
BasicBlock *TheBB;
|
|
||||||
DomTreeNode *IDom;
|
template <class NodeT>
|
||||||
std::vector<DomTreeNode*> Children;
|
class DomTreeNodeBase {
|
||||||
|
NodeT *TheBB;
|
||||||
|
DomTreeNodeBase<NodeT> *IDom;
|
||||||
|
std::vector<DomTreeNodeBase<NodeT> *> Children;
|
||||||
int DFSNumIn, DFSNumOut;
|
int DFSNumIn, DFSNumOut;
|
||||||
|
|
||||||
friend class DominatorTreeBase;
|
friend class DominatorTreeBase;
|
||||||
friend class PostDominatorTree;
|
friend class PostDominatorTree;
|
||||||
public:
|
public:
|
||||||
typedef std::vector<DomTreeNode*>::iterator iterator;
|
typedef typename std::vector<DomTreeNodeBase<NodeT> *>::iterator iterator;
|
||||||
typedef std::vector<DomTreeNode*>::const_iterator const_iterator;
|
typedef typename std::vector<DomTreeNodeBase<NodeT> *>::const_iterator
|
||||||
|
const_iterator;
|
||||||
|
|
||||||
iterator begin() { return Children.begin(); }
|
iterator begin() { return Children.begin(); }
|
||||||
iterator end() { return Children.end(); }
|
iterator end() { return Children.end(); }
|
||||||
const_iterator begin() const { return Children.begin(); }
|
const_iterator begin() const { return Children.begin(); }
|
||||||
const_iterator end() const { return Children.end(); }
|
const_iterator end() const { return Children.end(); }
|
||||||
|
|
||||||
BasicBlock *getBlock() const { return TheBB; }
|
NodeT *getBlock() const { return TheBB; }
|
||||||
DomTreeNode *getIDom() const { return IDom; }
|
DomTreeNodeBase<NodeT> *getIDom() const { return IDom; }
|
||||||
const std::vector<DomTreeNode*> &getChildren() const { return Children; }
|
const std::vector<DomTreeNodeBase<NodeT>*> &getChildren() const {
|
||||||
|
return Children;
|
||||||
|
}
|
||||||
|
|
||||||
DomTreeNode(BasicBlock *BB, DomTreeNode *iDom)
|
DomTreeNodeBase(NodeT *BB, DomTreeNodeBase<NodeT> *iDom)
|
||||||
: TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) { }
|
: TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) { }
|
||||||
DomTreeNode *addChild(DomTreeNode *C) { Children.push_back(C); return C; }
|
|
||||||
void setIDom(DomTreeNode *NewIDom);
|
DomTreeNodeBase<NodeT> *addChild(DomTreeNodeBase<NodeT> *C) {
|
||||||
|
Children.push_back(C);
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIDom(DomTreeNodeBase<NodeT> *NewIDom) {
|
||||||
|
assert(IDom && "No immediate dominator?");
|
||||||
|
if (IDom != NewIDom) {
|
||||||
|
std::vector<DomTreeNodeBase<BasicBlock>*>::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
|
/// getDFSNumIn/getDFSNumOut - These are an internal implementation detail, do
|
||||||
/// not call them.
|
/// not call them.
|
||||||
@ -93,12 +118,15 @@ public:
|
|||||||
private:
|
private:
|
||||||
// Return true if this node is dominated by other. Use this only if DFS info
|
// Return true if this node is dominated by other. Use this only if DFS info
|
||||||
// is valid.
|
// is valid.
|
||||||
bool DominatedBy(const DomTreeNode *other) const {
|
bool DominatedBy(const DomTreeNodeBase<NodeT> *other) const {
|
||||||
return this->DFSNumIn >= other->DFSNumIn &&
|
return this->DFSNumIn >= other->DFSNumIn &&
|
||||||
this->DFSNumOut <= other->DFSNumOut;
|
this->DFSNumOut <= other->DFSNumOut;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef DomTreeNodeBase<BasicBlock> DomTreeNode;
|
||||||
|
typedef DomTreeNodeBase<MachineBasicBlock> MachineDomTreeNode;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
/// DominatorTree - Calculate the immediate dominator tree for a function.
|
/// DominatorTree - Calculate the immediate dominator tree for a function.
|
||||||
///
|
///
|
||||||
@ -162,7 +190,8 @@ public:
|
|||||||
/// properlyDominates - Returns true iff this dominates N and this != N.
|
/// properlyDominates - Returns true iff this dominates N and this != N.
|
||||||
/// Note that this is not a constant time operation!
|
/// 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;
|
if (A == 0 || B == 0) return false;
|
||||||
return dominatedBySlowTreeWalk(A, B);
|
return dominatedBySlowTreeWalk(A, B);
|
||||||
}
|
}
|
||||||
@ -188,7 +217,8 @@ public:
|
|||||||
/// dominates - Returns true iff A dominates B. Note that this is not a
|
/// dominates - Returns true iff A dominates B. Note that this is not a
|
||||||
/// constant time operation!
|
/// constant time operation!
|
||||||
///
|
///
|
||||||
inline bool dominates(const DomTreeNode *A, DomTreeNode *B) {
|
inline bool dominates(const DomTreeNode *A,
|
||||||
|
DomTreeNode *B) {
|
||||||
if (B == A)
|
if (B == A)
|
||||||
return true; // A node trivially dominates itself.
|
return true; // A node trivially dominates itself.
|
||||||
|
|
||||||
@ -243,7 +273,8 @@ 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.
|
||||||
///
|
///
|
||||||
void changeImmediateDominator(DomTreeNode *N, DomTreeNode *NewIDom) {
|
void changeImmediateDominator(DomTreeNode *N,
|
||||||
|
DomTreeNode *NewIDom) {
|
||||||
assert(N && NewIDom && "Cannot change null node pointers!");
|
assert(N && NewIDom && "Cannot change null node pointers!");
|
||||||
DFSInfoValid = false;
|
DFSInfoValid = false;
|
||||||
N->setIDom(NewIDom);
|
N->setIDom(NewIDom);
|
||||||
@ -334,7 +365,7 @@ public:
|
|||||||
/// DominatorTree GraphTraits specialization so the DominatorTree can be
|
/// DominatorTree GraphTraits specialization so the DominatorTree can be
|
||||||
/// iterable by generic graph iterators.
|
/// iterable by generic graph iterators.
|
||||||
///
|
///
|
||||||
template <> struct GraphTraits<DomTreeNode*> {
|
template <> struct GraphTraits<DomTreeNode *> {
|
||||||
typedef DomTreeNode NodeType;
|
typedef DomTreeNode NodeType;
|
||||||
typedef NodeType::iterator ChildIteratorType;
|
typedef NodeType::iterator ChildIteratorType;
|
||||||
|
|
||||||
@ -350,7 +381,7 @@ template <> struct GraphTraits<DomTreeNode*> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <> struct GraphTraits<DominatorTree*>
|
template <> struct GraphTraits<DominatorTree*>
|
||||||
: public GraphTraits<DomTreeNode*> {
|
: public GraphTraits<DomTreeNode *> {
|
||||||
static NodeType *getEntryNode(DominatorTree *DT) {
|
static NodeType *getEntryNode(DominatorTree *DT) {
|
||||||
return DT->getRootNode();
|
return DT->getRootNode();
|
||||||
}
|
}
|
||||||
|
@ -276,22 +276,6 @@ BasicBlock *DominatorTreeBase::findNearestCommonDominator(BasicBlock *A,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomTreeNode::setIDom(DomTreeNode *NewIDom) {
|
|
||||||
assert(IDom && "No immediate dominator?");
|
|
||||||
if (IDom != NewIDom) {
|
|
||||||
std::vector<DomTreeNode*>::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) {
|
static std::ostream &operator<<(std::ostream &o, const DomTreeNode *Node) {
|
||||||
if (Node->getBlock())
|
if (Node->getBlock())
|
||||||
WriteAsOperand(o, Node->getBlock(), false);
|
WriteAsOperand(o, Node->getBlock(), false);
|
||||||
|
Loading…
Reference in New Issue
Block a user