///
class DominatorTreeBase : public DominatorBase {
public:
- class Node;
+ class DomTreeNode;
protected:
- std::map<BasicBlock*, Node*> Nodes;
+ std::map<BasicBlock*, DomTreeNode*> DomTreeNodes;
void reset();
- typedef std::map<BasicBlock*, Node*> NodeMapType;
+ typedef std::map<BasicBlock*, DomTreeNode*> DomTreeNodeMapType;
- Node *RootNode;
+ DomTreeNode *RootNode;
struct InfoRec {
unsigned Semi;
std::map<BasicBlock*, InfoRec> Info;
public:
- class Node {
+ class DomTreeNode {
friend class DominatorTree;
friend struct PostDominatorTree;
friend class DominatorTreeBase;
BasicBlock *TheBB;
- Node *IDom;
- std::vector<Node*> Children;
+ DomTreeNode *IDom;
+ std::vector<DomTreeNode*> Children;
public:
- typedef std::vector<Node*>::iterator iterator;
- typedef std::vector<Node*>::const_iterator const_iterator;
+ typedef std::vector<DomTreeNode*>::iterator iterator;
+ typedef std::vector<DomTreeNode*>::const_iterator const_iterator;
iterator begin() { return Children.begin(); }
iterator end() { return Children.end(); }
const_iterator end() const { return Children.end(); }
inline BasicBlock *getBlock() const { return TheBB; }
- inline Node *getIDom() const { return IDom; }
- inline const std::vector<Node*> &getChildren() const { return Children; }
+ inline DomTreeNode *getIDom() const { return IDom; }
+ inline const std::vector<DomTreeNode*> &getChildren() const { return Children; }
/// properlyDominates - Returns true iff this dominates N and this != N.
/// Note that this is not a constant time operation!
///
- bool properlyDominates(const Node *N) const {
- const Node *IDom;
+ bool properlyDominates(const DomTreeNode *N) const {
+ const DomTreeNode *IDom;
if (this == 0 || N == 0) return false;
while ((IDom = N->getIDom()) != 0 && IDom != this)
N = IDom; // Walk up the tree
/// dominates - Returns true iff this dominates N. Note that this is not a
/// constant time operation!
///
- inline bool dominates(const Node *N) const {
+ inline bool dominates(const DomTreeNode *N) const {
if (N == this) return true; // A node trivially dominates itself.
return properlyDominates(N);
}
private:
- inline Node(BasicBlock *BB, Node *iDom) : TheBB(BB), IDom(iDom) {}
- inline Node *addChild(Node *C) { Children.push_back(C); return C; }
+ inline DomTreeNode(BasicBlock *BB, DomTreeNode *iDom) : TheBB(BB), IDom(iDom) {}
+ inline DomTreeNode *addChild(DomTreeNode *C) { Children.push_back(C); return C; }
- void setIDom(Node *NewIDom);
+ void setIDom(DomTreeNode *NewIDom);
};
public:
/// getNode - return the (Post)DominatorTree node for the specified basic
/// block. This is the same as using operator[] on this class.
///
- inline Node *getNode(BasicBlock *BB) const {
- NodeMapType::const_iterator i = Nodes.find(BB);
- return (i != Nodes.end()) ? i->second : 0;
+ inline DomTreeNode *getNode(BasicBlock *BB) const {
+ DomTreeNodeMapType::const_iterator i = DomTreeNodes.find(BB);
+ return (i != DomTreeNodes.end()) ? i->second : 0;
}
- inline Node *operator[](BasicBlock *BB) const {
+ inline DomTreeNode *operator[](BasicBlock *BB) const {
return getNode(BB);
}
/// post-dominance information must be capable of dealing with this
/// possibility.
///
- Node *getRootNode() { return RootNode; }
- const Node *getRootNode() const { return RootNode; }
+ DomTreeNode *getRootNode() { return RootNode; }
+ const DomTreeNode *getRootNode() const { return RootNode; }
//===--------------------------------------------------------------------===//
// API to update (Post)DominatorTree information based on modifications to
/// creates a new node as a child of IDomNode, linking it into the children
/// list of the immediate dominator.
///
- Node *createNewNode(BasicBlock *BB, Node *IDomNode) {
+ DomTreeNode *createNewNode(BasicBlock *BB, DomTreeNode *IDomNode) {
assert(getNode(BB) == 0 && "Block already in dominator tree!");
assert(IDomNode && "Not immediate dominator specified for block!");
- return Nodes[BB] = IDomNode->addChild(new Node(BB, IDomNode));
+ return DomTreeNodes[BB] = IDomNode->addChild(new DomTreeNode(BB, IDomNode));
}
/// changeImmediateDominator - This method is used to update the dominator
/// tree information when a node's immediate dominator changes.
///
- void changeImmediateDominator(Node *N, Node *NewIDom) {
+ void changeImmediateDominator(DomTreeNode *N, DomTreeNode *NewIDom) {
assert(N && NewIDom && "Cannot change null node pointers!");
N->setIDom(NewIDom);
}
/// block.
void removeNode(BasicBlock *BB) {
assert(getNode(BB) && "Removing node that isn't in dominator tree.");
- Nodes.erase(BB);
+ DomTreeNodes.erase(BB);
}
/// print - Convert to human readable form
}
private:
void calculate(Function& F);
- Node *getNodeForBlock(BasicBlock *BB);
+ DomTreeNode *getNodeForBlock(BasicBlock *BB);
unsigned DFSPass(BasicBlock *V, InfoRec &VInfo, unsigned N);
void Compress(BasicBlock *V);
BasicBlock *Eval(BasicBlock *v);
/// DominatorTree GraphTraits specialization so the DominatorTree can be
/// iterable by generic graph iterators.
///
-template <> struct GraphTraits<DominatorTree::Node*> {
- typedef DominatorTree::Node NodeType;
+template <> struct GraphTraits<DominatorTree::DomTreeNode*> {
+ typedef DominatorTree::DomTreeNode NodeType;
typedef NodeType::iterator ChildIteratorType;
static NodeType *getEntryNode(NodeType *N) {
};
template <> struct GraphTraits<DominatorTree*>
- : public GraphTraits<DominatorTree::Node*> {
+ : public GraphTraits<DominatorTree::DomTreeNode*> {
static NodeType *getEntryNode(DominatorTree *DT) {
return DT->getRootNode();
}
}
private:
const DomSetType &calculate(const DominatorTree &DT,
- const DominatorTree::Node *Node);
+ const DominatorTree::DomTreeNode *Node);
};
}
private:
void calculate(Function &F);
- Node *getNodeForBlock(BasicBlock *BB);
+ DomTreeNode *getNodeForBlock(BasicBlock *BB);
unsigned DFSPass(BasicBlock *V, InfoRec &VInfo,unsigned N);
void Compress(BasicBlock *V, InfoRec &VInfo);
BasicBlock *Eval(BasicBlock *V);
Frontiers.clear();
PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
Roots = DT.getRoots();
- if (const DominatorTree::Node *Root = DT.getRootNode())
+ if (const DominatorTree::DomTreeNode *Root = DT.getRootNode())
calculate(DT, Root);
return false;
}
private:
const DomSetType &calculate(const PostDominatorTree &DT,
- const DominatorTree::Node *Node);
+ const DominatorTree::DomTreeNode *Node);
};
} // End llvm namespace
// one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
// which postdominates all real exits if there are multiple exit blocks.
BasicBlock *Root = Roots.size() == 1 ? Roots[0] : 0;
- Nodes[Root] = RootNode = new Node(Root, 0);
+ DomTreeNodes[Root] = RootNode = new DomTreeNode(Root, 0);
// Loop over all of the reachable blocks in the function...
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
if (BasicBlock *ImmPostDom = getIDom(I)) { // Reachable block.
- Node *&BBNode = Nodes[I];
+ DomTreeNode *&BBNode = DomTreeNodes[I];
if (!BBNode) { // Haven't calculated this node yet?
// Get or calculate the node for the immediate dominator
- Node *IPDomNode = getNodeForBlock(ImmPostDom);
+ DomTreeNode *IPDomNode = getNodeForBlock(ImmPostDom);
// Add a new tree node for this BasicBlock, and link it as a child of
// IDomNode
- BBNode = IPDomNode->addChild(new Node(I, IPDomNode));
+ BBNode = IPDomNode->addChild(new DomTreeNode(I, IPDomNode));
}
}
}
-DominatorTreeBase::Node *PostDominatorTree::getNodeForBlock(BasicBlock *BB) {
- Node *&BBNode = Nodes[BB];
+DominatorTreeBase::DomTreeNode *PostDominatorTree::getNodeForBlock(BasicBlock *BB) {
+ DomTreeNode *&BBNode = DomTreeNodes[BB];
if (BBNode) return BBNode;
// Haven't calculated this node yet? Get or calculate the node for the
// immediate postdominator.
BasicBlock *IPDom = getIDom(BB);
- Node *IPDomNode = getNodeForBlock(IPDom);
+ DomTreeNode *IPDomNode = getNodeForBlock(IPDom);
// Add a new tree node for this BasicBlock, and link it as a child of
// IDomNode
- return BBNode = IPDomNode->addChild(new Node(BB, IPDomNode));
+ return BBNode = IPDomNode->addChild(new DomTreeNode(BB, IPDomNode));
}
//===----------------------------------------------------------------------===//
// Haven't calculated this node yet? Get or calculate the node for the
// immediate dominator.
- PostDominatorTree::Node *node = getAnalysis<PostDominatorTree>().getNode(BB);
+ PostDominatorTree::DomTreeNode *node = getAnalysis<PostDominatorTree>().getNode(BB);
// If we are unreachable, we may not have an immediate dominator.
if (!node)
ETNode *&BBNode = Nodes[BB];
if (!BBNode) {
ETNode *IDomNode = NULL;
- PostDominatorTree::Node *node = DT.getNode(BB);
+ PostDominatorTree::DomTreeNode *node = DT.getNode(BB);
if (node && node->getIDom())
IDomNode = getNodeForBlock(node->getIDom()->getBlock());
const DominanceFrontier::DomSetType &
PostDominanceFrontier::calculate(const PostDominatorTree &DT,
- const DominatorTree::Node *Node) {
+ const DominatorTree::DomTreeNode *Node) {
// Loop over CFG successors to calculate DFlocal[Node]
BasicBlock *BB = Node->getBlock();
DomSetType &S = Frontiers[BB]; // The new set to fill in...
for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB);
SI != SE; ++SI) {
// Does Node immediately dominate this predecessor?
- DominatorTree::Node *SINode = DT[*SI];
+ DominatorTree::DomTreeNode *SINode = DT[*SI];
if (SINode && SINode->getIDom() != Node)
S.insert(*SI);
}
// Loop through and visit the nodes that Node immediately dominates (Node's
// children in the IDomTree)
//
- for (PostDominatorTree::Node::const_iterator
+ for (PostDominatorTree::DomTreeNode::const_iterator
NI = Node->begin(), NE = Node->end(); NI != NE; ++NI) {
- DominatorTree::Node *IDominee = *NI;
+ DominatorTree::DomTreeNode *IDominee = *NI;
const DomSetType &ChildDF = calculate(DT, IDominee);
DomSetType::const_iterator CDFI = ChildDF.begin(), CDFE = ChildDF.end();
// postdominator that is alive, and the last postdominator that is
// dead...
//
- PostDominatorTree::Node *LastNode = DT[TI->getSuccessor(i)];
- PostDominatorTree::Node *NextNode = 0;
+ PostDominatorTree::DomTreeNode *LastNode = DT[TI->getSuccessor(i)];
+ PostDominatorTree::DomTreeNode *NextNode = 0;
if (LastNode) {
NextNode = LastNode->getIDom();
// Traverse the CFG of the function in dominator order, so that we see each
// instruction after we see its operands.
- for (df_iterator<DominatorTree::Node*> DI = df_begin(DT.getRootNode()),
+ for (df_iterator<DominatorTree::DomTreeNode*> DI = df_begin(DT.getRootNode()),
E = df_end(DT.getRootNode()); DI != E; ++DI) {
BasicBlock *BB = DI->getBlock();
// For a given block, calculate the generated expressions, temporaries,
// and the AVAIL_OUT set
void CalculateAvailOut(ValueTable& VN, std::set<Value*, ExprLT>& MS,
- DominatorTree::Node* DI,
+ DominatorTree::DomTreeNode* DI,
std::set<Value*, ExprLT>& currExps,
std::set<PHINode*>& currPhis,
std::set<Value*, ExprLT>& currTemps,
}
void GVNPRE::CalculateAvailOut(GVNPRE::ValueTable& VN, std::set<Value*, ExprLT>& MS,
- DominatorTree::Node* DI,
+ DominatorTree::DomTreeNode* DI,
std::set<Value*, ExprLT>& currExps,
std::set<PHINode*>& currPhis,
std::set<Value*, ExprLT>& currTemps,
// First Phase of BuildSets - calculate AVAIL_OUT
// Top-down walk of the dominator tree
- for (df_iterator<DominatorTree::Node*> DI = df_begin(DT.getRootNode()),
+ for (df_iterator<DominatorTree::DomTreeNode*> DI = df_begin(DT.getRootNode()),
E = df_end(DT.getRootNode()); DI != E; ++DI) {
// Get the sets to update for this block
std::set<Value*, ExprLT> anticOut;
// Top-down walk of the postdominator tree
- for (df_iterator<PostDominatorTree::Node*> PDI =
+ for (df_iterator<PostDominatorTree::DomTreeNode*> PDI =
df_begin(PDT.getRootNode()), E = df_end(DT.getRootNode());
PDI != E; ++PDI) {
BasicBlock* BB = PDI->getBlock();
/// visit uses before definitions, allowing us to sink a loop body in one
/// pass without iteration.
///
- void SinkRegion(DominatorTree::Node *N);
+ void SinkRegion(DominatorTree::DomTreeNode *N);
/// HoistRegion - Walk the specified region of the CFG (defined by all
/// blocks dominated by the specified block, and that are in the current
/// visit definitions before uses, allowing us to hoist a loop body in one
/// pass without iteration.
///
- void HoistRegion(DominatorTree::Node *N);
+ void HoistRegion(DominatorTree::DomTreeNode *N);
/// inSubLoop - Little predicate that returns true if the specified basic
/// block is in a subloop of the current one, not the current one itself.
if (BlockInLoop == LoopHeader)
return true;
- DominatorTree::Node *BlockInLoopNode = DT->getNode(BlockInLoop);
- DominatorTree::Node *IDom = DT->getNode(ExitBlock);
+ DominatorTree::DomTreeNode *BlockInLoopNode = DT->getNode(BlockInLoop);
+ DominatorTree::DomTreeNode *IDom = DT->getNode(ExitBlock);
// Because the exit block is not in the loop, we know we have to get _at
// least_ its immediate dominator.
/// uses before definitions, allowing us to sink a loop body in one pass without
/// iteration.
///
-void LICM::SinkRegion(DominatorTree::Node *N) {
+void LICM::SinkRegion(DominatorTree::DomTreeNode *N) {
assert(N != 0 && "Null dominator tree node?");
BasicBlock *BB = N->getBlock();
if (!CurLoop->contains(BB)) return;
// We are processing blocks in reverse dfo, so process children first...
- const std::vector<DominatorTree::Node*> &Children = N->getChildren();
+ const std::vector<DominatorTree::DomTreeNode*> &Children = N->getChildren();
for (unsigned i = 0, e = Children.size(); i != e; ++i)
SinkRegion(Children[i]);
/// first order w.r.t the DominatorTree. This allows us to visit definitions
/// before uses, allowing us to hoist a loop body in one pass without iteration.
///
-void LICM::HoistRegion(DominatorTree::Node *N) {
+void LICM::HoistRegion(DominatorTree::DomTreeNode *N) {
assert(N != 0 && "Null dominator tree node?");
BasicBlock *BB = N->getBlock();
hoist(I);
}
- const std::vector<DominatorTree::Node*> &Children = N->getChildren();
+ const std::vector<DominatorTree::DomTreeNode*> &Children = N->getChildren();
for (unsigned i = 0, e = Children.size(); i != e; ++i)
HoistRegion(Children[i]);
}
UnreachableBlocks UB;
ValueRanges *VR;
- std::vector<DominatorTree::Node *> WorkList;
+ std::vector<DominatorTree::DomTreeNode *> WorkList;
public:
static char ID; // Pass identification, replacement for typeid
class VISIBILITY_HIDDEN Forwards : public InstVisitor<Forwards> {
friend class InstVisitor<Forwards>;
PredicateSimplifier *PS;
- DominatorTree::Node *DTNode;
+ DominatorTree::DomTreeNode *DTNode;
public:
InequalityGraph &IG;
UnreachableBlocks &UB;
ValueRanges &VR;
- Forwards(PredicateSimplifier *PS, DominatorTree::Node *DTNode)
+ Forwards(PredicateSimplifier *PS, DominatorTree::DomTreeNode *DTNode)
: PS(PS), DTNode(DTNode), IG(*PS->IG), UB(PS->UB), VR(*PS->VR) {}
void visitTerminatorInst(TerminatorInst &TI);
// Used by terminator instructions to proceed from the current basic
// block to the next. Verifies that "current" dominates "next",
// then calls visitBasicBlock.
- void proceedToSuccessors(DominatorTree::Node *Current) {
- for (DominatorTree::Node::iterator I = Current->begin(),
+ void proceedToSuccessors(DominatorTree::DomTreeNode *Current) {
+ for (DominatorTree::DomTreeNode::iterator I = Current->begin(),
E = Current->end(); I != E; ++I) {
WorkList.push_back(*I);
}
}
- void proceedToSuccessor(DominatorTree::Node *Next) {
+ void proceedToSuccessor(DominatorTree::DomTreeNode *Next) {
WorkList.push_back(Next);
}
// Visits each instruction in the basic block.
- void visitBasicBlock(DominatorTree::Node *Node) {
+ void visitBasicBlock(DominatorTree::DomTreeNode *Node) {
BasicBlock *BB = Node->getBlock();
ETNode *ET = Forest->getNodeForBlock(BB);
DOUT << "Entering Basic Block: " << BB->getName()
// Tries to simplify each Instruction and add new properties to
// the PropertySet.
- void visitInstruction(Instruction *I, DominatorTree::Node *DT, ETNode *ET) {
+ void visitInstruction(Instruction *I, DominatorTree::DomTreeNode *DT, ETNode *ET) {
DOUT << "Considering instruction " << *I << "\n";
DEBUG(IG->dump());
WorkList.push_back(DT->getRootNode());
do {
- DominatorTree::Node *DTNode = WorkList.back();
+ DominatorTree::DomTreeNode *DTNode = WorkList.back();
WorkList.pop_back();
if (!UB.isDead(DTNode->getBlock())) visitBasicBlock(DTNode);
} while (!WorkList.empty());
return;
}
- for (DominatorTree::Node::iterator I = DTNode->begin(), E = DTNode->end();
+ for (DominatorTree::DomTreeNode::iterator I = DTNode->begin(), E = DTNode->end();
I != E; ++I) {
BasicBlock *Dest = (*I)->getBlock();
DOUT << "Branch thinking about %" << Dest->getName()
// Set the EQProperty in each of the cases BBs, and the NEProperties
// in the default BB.
- for (DominatorTree::Node::iterator I = DTNode->begin(), E = DTNode->end();
+ for (DominatorTree::DomTreeNode::iterator I = DTNode->begin(), E = DTNode->end();
I != E; ++I) {
BasicBlock *BB = (*I)->getBlock();
DOUT << "Switch thinking about BB %" << BB->getName()
// Should we update DominatorTree information?
if (DominatorTree *DT = P->getAnalysisToUpdate<DominatorTree>()) {
- DominatorTree::Node *TINode = DT->getNode(TIBB);
+ DominatorTree::DomTreeNode *TINode = DT->getNode(TIBB);
// The new block is not the immediate dominator for any other nodes, but
// TINode is the immediate dominator for the new node.
//
if (TINode) { // Don't break unreachable code!
- DominatorTree::Node *NewBBNode = DT->createNewNode(NewBB, TINode);
- DominatorTree::Node *DestBBNode = 0;
+ DominatorTree::DomTreeNode *NewBBNode = DT->createNewNode(NewBB, TINode);
+ DominatorTree::DomTreeNode *DestBBNode = 0;
// If NewBBDominatesDestBB hasn't been computed yet, do so with DT.
if (!OtherPreds.empty()) {
DestBBNode = DT->getNode(DestBB);
while (!OtherPreds.empty() && NewBBDominatesDestBB) {
- if (DominatorTree::Node *OPNode = DT->getNode(OtherPreds.back()))
+ if (DominatorTree::DomTreeNode *OPNode = DT->getNode(OtherPreds.back()))
NewBBDominatesDestBB = DestBBNode->dominates(OPNode);
OtherPreds.pop_back();
}
void getLoopValuesUsedOutsideLoop(Loop *L,
SetVector<Instruction*> &AffectedValues);
- Value *GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst,
- std::map<DominatorTree::Node*, Value*> &Phis);
+ Value *GetValueForBlock(DominatorTree::DomTreeNode *BB, Instruction *OrigInst,
+ std::map<DominatorTree::DomTreeNode*, Value*> &Phis);
/// inLoop - returns true if the given block is within the current loop
const bool inLoop(BasicBlock* B) {
++NumLCSSA; // We are applying the transformation
// Keep track of the blocks that have the value available already.
- std::map<DominatorTree::Node*, Value*> Phis;
+ std::map<DominatorTree::DomTreeNode*, Value*> Phis;
- DominatorTree::Node *InstrNode = DT->getNode(Instr->getParent());
+ DominatorTree::DomTreeNode *InstrNode = DT->getNode(Instr->getParent());
// Insert the LCSSA phi's into the exit blocks (dominated by the value), and
// add them to the Phi's map.
for (std::vector<BasicBlock*>::const_iterator BBI = exitBlocks.begin(),
BBE = exitBlocks.end(); BBI != BBE; ++BBI) {
BasicBlock *BB = *BBI;
- DominatorTree::Node *ExitBBNode = DT->getNode(BB);
+ DominatorTree::DomTreeNode *ExitBBNode = DT->getNode(BB);
Value *&Phi = Phis[ExitBBNode];
if (!Phi && InstrNode->dominates(ExitBBNode)) {
PHINode *PN = new PHINode(Instr->getType(), Instr->getName()+".lcssa",
/// GetValueForBlock - Get the value to use within the specified basic block.
/// available values are in Phis.
-Value *LCSSA::GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst,
- std::map<DominatorTree::Node*, Value*> &Phis) {
+Value *LCSSA::GetValueForBlock(DominatorTree::DomTreeNode *BB, Instruction *OrigInst,
+ std::map<DominatorTree::DomTreeNode*, Value*> &Phis) {
// If there is no dominator info for this BB, it is unreachable.
if (BB == 0)
return UndefValue::get(OrigInst->getType());
Value *&V = Phis[BB];
if (V) return V;
- DominatorTree::Node *IDom = BB->getIDom();
+ DominatorTree::DomTreeNode *IDom = BB->getIDom();
// Otherwise, there are two cases: we either have to insert a PHI node or we
// don't. We need to insert a PHI node if this block is not dominated by one
}
assert(NewBBIDom && "No immediate dominator found??");
}
- DominatorTree::Node *NewBBIDomNode = DT->getNode(NewBBIDom);
+ DominatorTree::DomTreeNode *NewBBIDomNode = DT->getNode(NewBBIDom);
// Create the new dominator tree node... and set the idom of NewBB.
- DominatorTree::Node *NewBBNode = DT->createNewNode(NewBB, NewBBIDomNode);
+ DominatorTree::DomTreeNode *NewBBNode = DT->createNewNode(NewBB, NewBBIDomNode);
// If NewBB strictly dominates other blocks, then it is now the immediate
// dominator of NewBBSucc. Update the dominator tree as appropriate.
if (NewBBDominatesNewBBSucc) {
- DominatorTree::Node *NewBBSuccNode = DT->getNode(NewBBSucc);
+ DominatorTree::DomTreeNode *NewBBSuccNode = DT->getNode(NewBBSucc);
DT->changeImmediateDominator(NewBBSuccNode, NewBBNode);
}
}
void DominatorTree::calculate(Function& F) {
BasicBlock* Root = Roots[0];
- Nodes[Root] = RootNode = new Node(Root, 0); // Add a node for the root...
+ DomTreeNodes[Root] = RootNode = new DomTreeNode(Root, 0); // Add a node for the root...
Vertex.push_back(0);
// Loop over all of the reachable blocks in the function...
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
if (BasicBlock *ImmDom = getIDom(I)) { // Reachable block.
- Node *&BBNode = Nodes[I];
+ DomTreeNode *&BBNode = DomTreeNodes[I];
if (!BBNode) { // Haven't calculated this node yet?
// Get or calculate the node for the immediate dominator
- Node *IDomNode = getNodeForBlock(ImmDom);
+ DomTreeNode *IDomNode = getNodeForBlock(ImmDom);
// Add a new tree node for this BasicBlock, and link it as a child of
// IDomNode
- BBNode = IDomNode->addChild(new Node(I, IDomNode));
+ BBNode = IDomNode->addChild(new DomTreeNode(I, IDomNode));
}
}
// DominatorTreeBase::reset - Free all of the tree node memory.
//
void DominatorTreeBase::reset() {
- for (NodeMapType::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I)
+ for (DomTreeNodeMapType::iterator I = DomTreeNodes.begin(), E = DomTreeNodes.end(); I != E; ++I)
delete I->second;
- Nodes.clear();
+ DomTreeNodes.clear();
IDoms.clear();
Roots.clear();
Vertex.clear();
RootNode = 0;
}
-void DominatorTreeBase::Node::setIDom(Node *NewIDom) {
+void DominatorTreeBase::DomTreeNode::setIDom(DomTreeNode *NewIDom) {
assert(IDom && "No immediate dominator?");
if (IDom != NewIDom) {
- std::vector<Node*>::iterator I =
+ 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!");
}
}
-DominatorTreeBase::Node *DominatorTree::getNodeForBlock(BasicBlock *BB) {
- Node *&BBNode = Nodes[BB];
+DominatorTreeBase::DomTreeNode *DominatorTree::getNodeForBlock(BasicBlock *BB) {
+ DomTreeNode *&BBNode = DomTreeNodes[BB];
if (BBNode) return BBNode;
// Haven't calculated this node yet? Get or calculate the node for the
// immediate dominator.
BasicBlock *IDom = getIDom(BB);
- Node *IDomNode = getNodeForBlock(IDom);
+ DomTreeNode *IDomNode = getNodeForBlock(IDom);
// Add a new tree node for this BasicBlock, and link it as a child of
// IDomNode
- return BBNode = IDomNode->addChild(new Node(BB, IDomNode));
+ return BBNode = IDomNode->addChild(new DomTreeNode(BB, IDomNode));
}
static std::ostream &operator<<(std::ostream &o,
- const DominatorTreeBase::Node *Node) {
+ const DominatorTreeBase::DomTreeNode *Node) {
if (Node->getBlock())
WriteAsOperand(o, Node->getBlock(), false);
else
return o << "\n";
}
-static void PrintDomTree(const DominatorTreeBase::Node *N, std::ostream &o,
+static void PrintDomTree(const DominatorTreeBase::DomTreeNode *N, std::ostream &o,
unsigned Lev) {
o << std::string(2*Lev, ' ') << "[" << Lev << "] " << N;
- for (DominatorTreeBase::Node::const_iterator I = N->begin(), E = N->end();
+ for (DominatorTreeBase::DomTreeNode::const_iterator I = N->begin(), E = N->end();
I != E; ++I)
PrintDomTree(*I, o, Lev+1);
}
class DFCalculateWorkObject {
public:
DFCalculateWorkObject(BasicBlock *B, BasicBlock *P,
- const DominatorTree::Node *N,
- const DominatorTree::Node *PN)
- : currentBB(B), parentBB(P), Node(N), parentNode(PN) {}
+ const DominatorTree::DomTreeNode *N,
+ const DominatorTree::DomTreeNode *PN)
+ : currentBB(B), parentBB(P), DomTreeNode(N), parentNode(PN) {}
BasicBlock *currentBB;
BasicBlock *parentBB;
- const DominatorTree::Node *Node;
- const DominatorTree::Node *parentNode;
+ const DominatorTree::DomTreeNode *DomTreeNode;
+ const DominatorTree::DomTreeNode *parentNode;
};
}
const DominanceFrontier::DomSetType &
DominanceFrontier::calculate(const DominatorTree &DT,
- const DominatorTree::Node *Node) {
+ const DominatorTree::DomTreeNode *Node) {
BasicBlock *BB = Node->getBlock();
DomSetType *Result = NULL;
BasicBlock *currentBB = currentW->currentBB;
BasicBlock *parentBB = currentW->parentBB;
- const DominatorTree::Node *currentNode = currentW->Node;
- const DominatorTree::Node *parentNode = currentW->parentNode;
+ const DominatorTree::DomTreeNode *currentNode = currentW->DomTreeNode;
+ const DominatorTree::DomTreeNode *parentNode = currentW->parentNode;
assert (currentBB && "Invalid work object. Missing current Basic Block");
assert (currentNode && "Invalid work object. Missing current Node");
DomSetType &S = Frontiers[currentBB];
// Loop through and visit the nodes that Node immediately dominates (Node's
// children in the IDomTree)
bool visitChild = false;
- for (DominatorTree::Node::const_iterator NI = currentNode->begin(),
+ for (DominatorTree::DomTreeNode::const_iterator NI = currentNode->begin(),
NE = currentNode->end(); NI != NE; ++NI) {
- DominatorTree::Node *IDominee = *NI;
+ DominatorTree::DomTreeNode *IDominee = *NI;
BasicBlock *childBB = IDominee->getBlock();
if (visited.count(childBB) == 0) {
workList.push_back(DFCalculateWorkObject(childBB, currentBB,
// Haven't calculated this node yet? Get or calculate the node for the
// immediate dominator.
- DominatorTree::Node *node= getAnalysis<DominatorTree>().getNode(BB);
+ DominatorTree::DomTreeNode *node= getAnalysis<DominatorTree>().getNode(BB);
// If we are unreachable, we may not have an immediate dominator.
if (!node || !node->getIDom())
Function *F = Root->getParent();
// Loop over all of the reachable blocks in the function...
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
- DominatorTree::Node* node = DT.getNode(I);
+ DominatorTree::DomTreeNode* node = DT.getNode(I);
if (node && node->getIDom()) { // Reachable block.
BasicBlock* ImmDom = node->getIDom()->getBlock();
ETNode *&BBNode = Nodes[I];