-//===- llvm/Analysis/Dominators.h - Dominator Info Calculation ---*- C++ -*--=//
+//===- llvm/Analysis/Dominators.h - Dominator Info Calculation --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
//
// This file defines the following classes:
-// 1. DominatorSet: Calculates the [reverse] dominator set for a function
-// 2. ImmediateDominators: Calculates and holds a mapping between BasicBlocks
-// and their immediate dominator.
-// 3. DominatorTree: Represent the ImmediateDominator as an explicit tree
-// structure.
-// 4. DominanceFrontier: Calculate and hold the dominance frontier for a
+// 1. DominatorTree: Represent dominators as an explicit tree structure.
+// 2. DominanceFrontier: Calculate and hold the dominance frontier for a
// function.
//
// These data structures are listed in increasing order of complexity. It
-// takes longer to calculate the dominator frontier, for example, than the
-// ImmediateDominator mapping.
-//
+// takes longer to calculate the dominator frontier, for example, than the
+// DominatorTree mapping.
+//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_DOMINATORS_H
-#define LLVM_DOMINATORS_H
+#ifndef LLVM_ANALYSIS_DOMINATORS_H
+#define LLVM_ANALYSIS_DOMINATORS_H
#include "llvm/Pass.h"
#include <set>
+
+namespace llvm {
+
class Instruction;
+template <typename GraphType> struct GraphTraits;
+
//===----------------------------------------------------------------------===//
-//
-// DominatorBase - Base class that other, more interesting dominator analyses
-// inherit from.
-//
+/// DominatorBase - Base class that other, more interesting dominator analyses
+/// inherit from.
+///
class DominatorBase : public FunctionPass {
protected:
- BasicBlock *Root;
+ std::vector<BasicBlock*> Roots;
const bool IsPostDominators;
-
- inline DominatorBase(bool isPostDom) : Root(0), IsPostDominators(isPostDom) {}
+ inline DominatorBase(intptr_t ID, bool isPostDom) :
+ FunctionPass(ID), Roots(), IsPostDominators(isPostDom) {}
public:
- inline BasicBlock *getRoot() const { return Root; }
- // Returns true if analysis based of postdoms
+ /// getRoots - Return the root blocks of the current CFG. This may include
+ /// multiple blocks if we are computing post dominators. For forward
+ /// dominators, this will always be a single block (the entry node).
+ ///
+ inline const std::vector<BasicBlock*> &getRoots() const { return Roots; }
+
+ /// isPostDominator - Returns true if analysis based of postdoms
+ ///
bool isPostDominator() const { return IsPostDominators; }
};
+
//===----------------------------------------------------------------------===//
-//
-// DominatorSet - Maintain a set<BasicBlock*> for every basic block in a
-// function, that represents the blocks that dominate the block.
-//
-class DominatorSetBase : public DominatorBase {
-public:
- typedef std::set<BasicBlock*> DomSetType; // Dom set for a bb
- // Map of dom sets
- typedef std::map<BasicBlock*, DomSetType> DomSetMapType;
-protected:
- DomSetMapType Doms;
+// DomTreeNode - Dominator Tree Node
+class DominatorTreeBase;
+class PostDominatorTree;
+class DomTreeNode {
+ BasicBlock *TheBB;
+ DomTreeNode *IDom;
+ std::vector<DomTreeNode*> Children;
+ int DFSNumIn, DFSNumOut;
+
+ friend class DominatorTreeBase;
+ friend class PostDominatorTree;
public:
- DominatorSetBase(bool isPostDom) : DominatorBase(isPostDom) {}
-
- virtual void releaseMemory() { Doms.clear(); }
+ 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 begin() const { return Children.begin(); }
+ const_iterator end() const { return Children.end(); }
+
+ inline BasicBlock *getBlock() const { return TheBB; }
+ inline DomTreeNode *getIDom() const { return IDom; }
+ inline const std::vector<DomTreeNode*> &getChildren() const { return Children; }
+
+ inline DomTreeNode(BasicBlock *BB, DomTreeNode *iDom)
+ : TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) { }
+ inline DomTreeNode *addChild(DomTreeNode *C) { Children.push_back(C); return C; }
+ void setIDom(DomTreeNode *NewIDom);
- // Accessor interface:
- typedef DomSetMapType::const_iterator const_iterator;
- typedef DomSetMapType::iterator iterator;
- inline const_iterator begin() const { return Doms.begin(); }
- inline iterator begin() { return Doms.begin(); }
- inline const_iterator end() const { return Doms.end(); }
- inline iterator end() { return Doms.end(); }
- inline const_iterator find(BasicBlock* B) const { return Doms.find(B); }
- inline iterator find(BasicBlock* B) { return Doms.find(B); }
-
- // getDominators - Return the set of basic blocks that dominate the specified
- // block.
- //
- inline const DomSetType &getDominators(BasicBlock *BB) const {
- const_iterator I = find(BB);
- assert(I != end() && "BB not in function!");
- return I->second;
- }
-
- // dominates - Return true if A dominates B.
- //
- inline bool dominates(BasicBlock *A, BasicBlock *B) const {
- return getDominators(B).count(A) != 0;
+private:
+ // Return true if this node is dominated by other. Use this only if DFS info is valid.
+ bool DominatedBy(const DomTreeNode *other) const {
+ return this->DFSNumIn >= other->DFSNumIn &&
+ this->DFSNumOut <= other->DFSNumOut;
}
- // dominates - Return true if A dominates B. This performs the special checks
- // neccesary if A and B are in the same basic block.
- //
- bool dominates(Instruction *A, Instruction *B) const;
-};
-
-
-//===-------------------------------------
-// DominatorSet Class - Concrete subclass of DominatorSetBase that is used to
-// compute a normal dominator set.
-//
-struct DominatorSet : public DominatorSetBase {
- static AnalysisID ID; // Build dominator set
-
- DominatorSet() : DominatorSetBase(false) {}
-
- virtual bool runOnFunction(Function &F);
-
- // getAnalysisUsage - This simply provides a dominator set
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.setPreservesAll();
- AU.addProvided(ID);
- }
+ /// assignDFSNumber - Assign In and Out numbers while walking dominator tree
+ /// in dfs order.
+ void assignDFSNumber(int num);
};
+//===----------------------------------------------------------------------===//
+/// DominatorTree - Calculate the immediate dominator tree for a function.
+///
+class DominatorTreeBase : public DominatorBase {
-//===-------------------------------------
-// DominatorSet Class - Concrete subclass of DominatorSetBase that is used to
-// compute the post-dominator set.
-//
-struct PostDominatorSet : public DominatorSetBase {
- static AnalysisID ID; // Build post-dominator set
+protected:
+ void reset();
+ typedef std::map<BasicBlock*, DomTreeNode*> DomTreeNodeMapType;
+ DomTreeNodeMapType DomTreeNodes;
+ DomTreeNode *RootNode;
- PostDominatorSet() : DominatorSetBase(true) {}
+ bool DFSInfoValid;
+ unsigned int SlowQueries;
+ // Information record used during immediate dominators computation.
+ struct InfoRec {
+ unsigned Semi;
+ unsigned Size;
+ BasicBlock *Label, *Parent, *Child, *Ancestor;
- virtual bool runOnFunction(Function &F);
+ std::vector<BasicBlock*> Bucket;
- // getAnalysisUsage - This obviously provides a dominator set, but it also
- // uses the UnifyFunctionExitNode pass if building post-dominators
- //
- virtual void getAnalysisUsage(AnalysisUsage &AU) const;
-};
+ InfoRec() : Semi(0), Size(0), Label(0), Parent(0), Child(0), Ancestor(0){}
+ };
+ std::map<BasicBlock*, BasicBlock*> IDoms;
+ // Vertex - Map the DFS number to the BasicBlock*
+ std::vector<BasicBlock*> Vertex;
+ // Info - Collection of information used during the computation of idoms.
+ std::map<BasicBlock*, InfoRec> Info;
+ void updateDFSNumbers();
-//===----------------------------------------------------------------------===//
-//
-// ImmediateDominators - Calculate the immediate dominator for each node in a
-// function.
-//
-class ImmediateDominatorsBase : public DominatorBase {
-protected:
- std::map<BasicBlock*, BasicBlock*> IDoms;
- void calcIDoms(const DominatorSetBase &DS);
-public:
- ImmediateDominatorsBase(bool isPostDom) : DominatorBase(isPostDom) {}
+ public:
+ DominatorTreeBase(intptr_t ID, bool isPostDom)
+ : DominatorBase(ID, isPostDom), DFSInfoValid(false), SlowQueries(0) {}
+ ~DominatorTreeBase() { reset(); }
- virtual void releaseMemory() { IDoms.clear(); }
+ virtual void releaseMemory() { reset(); }
- // Accessor interface:
- typedef std::map<BasicBlock*, BasicBlock*> IDomMapType;
- typedef IDomMapType::const_iterator const_iterator;
- inline const_iterator begin() const { return IDoms.begin(); }
- inline const_iterator end() const { return IDoms.end(); }
- inline const_iterator find(BasicBlock* B) const { return IDoms.find(B);}
-
- // operator[] - Return the idom for the specified basic block. The start
- // node returns null, because it does not have an immediate dominator.
- //
- inline BasicBlock *operator[](BasicBlock *BB) const {
- std::map<BasicBlock*, BasicBlock*>::const_iterator I = IDoms.find(BB);
- return I != IDoms.end() ? I->second : 0;
+ /// getNode - return the (Post)DominatorTree node for the specified basic
+ /// block. This is the same as using operator[] on this class.
+ ///
+ inline DomTreeNode *getNode(BasicBlock *BB) const {
+ DomTreeNodeMapType::const_iterator i = DomTreeNodes.find(BB);
+ return (i != DomTreeNodes.end()) ? i->second : 0;
}
-};
-//===-------------------------------------
-// ImmediateDominators Class - Concrete subclass of ImmediateDominatorsBase that
-// is used to compute a normal immediate dominator set.
-//
-struct ImmediateDominators : public ImmediateDominatorsBase {
- static AnalysisID ID; // Build immediate dominators
+ inline DomTreeNode *operator[](BasicBlock *BB) const {
+ return getNode(BB);
+ }
- ImmediateDominators() : ImmediateDominatorsBase(false) {}
+ /// getIDomBlock - return basic block BB's immediate dominator basic block.
+ ///
+ BasicBlock *getIDomBlock(BasicBlock *BB) {
+ DomTreeNode *N = getNode(BB);
+ assert (N && "Missing dominator tree node");
+ DomTreeNode *I = N->getIDom();
+ assert (N && "Missing immediate dominator");
+ return I->getBlock();
+ }
- virtual bool runOnFunction(Function &F) {
- IDoms.clear(); // Reset from the last time we were run...
- DominatorSet &DS = getAnalysis<DominatorSet>();
- Root = DS.getRoot();
- calcIDoms(DS);
- return false;
+ /// getRootNode - This returns the entry node for the CFG of the function. If
+ /// this tree represents the post-dominance relations for a function, however,
+ /// this root may be a node with the block == NULL. This is the case when
+ /// there are multiple exit nodes from a particular function. Consumers of
+ /// post-dominance information must be capable of dealing with this
+ /// possibility.
+ ///
+ DomTreeNode *getRootNode() { return RootNode; }
+ const DomTreeNode *getRootNode() const { return RootNode; }
+
+ /// 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 {
+ if (A == 0 || B == 0) return false;
+ return dominatedBySlowTreeWalk(A, B);
}
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.setPreservesAll();
- AU.addProvided(ID);
- AU.addRequired(DominatorSet::ID);
+ inline bool properlyDominates(BasicBlock *A, BasicBlock *B) {
+ return properlyDominates(getNode(A), getNode(B));
}
-};
+ bool dominatedBySlowTreeWalk(const DomTreeNode *A,
+ const DomTreeNode *B) const {
+ const DomTreeNode *IDom;
+ if (A == 0 || B == 0) return false;
+ while ((IDom = B->getIDom()) != 0 && IDom != A && IDom != B)
+ B = IDom; // Walk up the tree
+ return IDom != 0;
+ }
-//===-------------------------------------
-// ImmediatePostDominators Class - Concrete subclass of ImmediateDominatorsBase
-// that is used to compute the immediate post-dominators.
-//
-struct ImmediatePostDominators : public ImmediateDominatorsBase {
- static AnalysisID ID; // Build immediate postdominators
- ImmediatePostDominators() : ImmediateDominatorsBase(true) {}
+ /// isReachableFromEntry - Return true if A is dominated by the entry
+ /// block of the function containing it.
+ const bool isReachableFromEntry(BasicBlock* A);
+
+ /// dominates - Returns true iff A dominates B. Note that this is not a
+ /// constant time operation!
+ ///
+ inline bool dominates(const DomTreeNode *A, DomTreeNode *B) {
+ if (B == A)
+ return true; // A node trivially dominates itself.
+
+ if (A == 0 || B == 0)
+ return false;
+
+ if (DFSInfoValid)
+ return B->DominatedBy(A);
+
+ // If we end up with too many slow queries, just update the
+ // DFS numbers on the theory that we are going to keep querying.
+ SlowQueries++;
+ if (SlowQueries > 32) {
+ updateDFSNumbers();
+ return B->DominatedBy(A);
+ }
- virtual bool runOnFunction(Function &F) {
- IDoms.clear(); // Reset from the last time we were run...
- PostDominatorSet &DS = getAnalysis<PostDominatorSet>();
- Root = DS.getRoot();
- calcIDoms(DS);
- return false;
+ return dominatedBySlowTreeWalk(A, B);
}
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.setPreservesAll();
- AU.addRequired(PostDominatorSet::ID);
- AU.addProvided(ID);
+ inline bool dominates(BasicBlock *A, BasicBlock *B) {
+ if (A == B)
+ return true;
+
+ return dominates(getNode(A), getNode(B));
}
-};
-
-
-//===----------------------------------------------------------------------===//
-//
-// DominatorTree - Calculate the immediate dominator tree for a function.
-//
-class DominatorTreeBase : public DominatorBase {
-protected:
- class Node2;
-public:
- typedef Node2 Node;
-protected:
- std::map<BasicBlock*, Node*> Nodes;
- void reset();
- typedef std::map<BasicBlock*, Node*> NodeMapType;
-public:
- class Node2 : public std::vector<Node*> {
- friend class DominatorTree;
- friend class PostDominatorTree;
- BasicBlock *TheNode;
- Node2 *IDom;
- public:
- inline BasicBlock *getNode() const { return TheNode; }
- inline Node2 *getIDom() const { return IDom; }
- inline const std::vector<Node*> &getChildren() const { return *this; }
-
- // dominates - Returns true iff this dominates N. Note that this is not a
- // constant time operation!
- inline bool dominates(const Node2 *N) const {
- const Node2 *IDom;
- while ((IDom = N->getIDom()) != 0 && IDom != this)
- N = IDom; // Walk up the tree
- return IDom != 0;
- }
+ /// findNearestCommonDominator - Find nearest common dominator basic block
+ /// for basic block A and B. If there is no such block then return NULL.
+ BasicBlock *findNearestCommonDominator(BasicBlock *A, BasicBlock *B);
+
+ // dominates - Return true if A dominates B. This performs the
+ // special checks necessary if A and B are in the same basic block.
+ bool dominates(Instruction *A, Instruction *B);
+
+ //===--------------------------------------------------------------------===//
+ // API to update (Post)DominatorTree information based on modifications to
+ // the CFG...
+
+ /// 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.
+ DomTreeNode *addNewBlock(BasicBlock *BB, BasicBlock *DomBB) {
+ assert(getNode(BB) == 0 && "Block already in dominator tree!");
+ DomTreeNode *IDomNode = getNode(DomBB);
+ assert(IDomNode && "Not immediate dominator specified for block!");
+ DFSInfoValid = false;
+ return DomTreeNodes[BB] =
+ IDomNode->addChild(new DomTreeNode(BB, IDomNode));
+ }
- private:
- inline Node2(BasicBlock *node, Node *iDom)
- : TheNode(node), IDom(iDom) {}
- inline Node2 *addChild(Node *C) { push_back(C); return C; }
- };
+ /// changeImmediateDominator - This method is used to update the dominator
+ /// tree information when a node's immediate dominator changes.
+ ///
+ void changeImmediateDominator(DomTreeNode *N, DomTreeNode *NewIDom) {
+ assert(N && NewIDom && "Cannot change null node pointers!");
+ DFSInfoValid = false;
+ N->setIDom(NewIDom);
+ }
-public:
- DominatorTreeBase(bool isPostDom) : DominatorBase(isPostDom) {}
- ~DominatorTreeBase() { reset(); }
+ void changeImmediateDominator(BasicBlock *BB, BasicBlock *NewBB) {
+ changeImmediateDominator(getNode(BB), getNode(NewBB));
+ }
- virtual void releaseMemory() { reset(); }
+ /// removeNode - Removes a node from the dominator tree. Block must not
+ /// dominate any other blocks. Invalidates any node pointing to removed
+ /// block.
+ void removeNode(BasicBlock *BB) {
+ assert(getNode(BB) && "Removing node that isn't in dominator tree.");
+ DomTreeNodes.erase(BB);
+ }
- inline Node *operator[](BasicBlock *BB) const {
- NodeMapType::const_iterator i = Nodes.find(BB);
- return (i != Nodes.end()) ? i->second : 0;
+ /// print - Convert to human readable form
+ ///
+ virtual void print(std::ostream &OS, const Module* = 0) const;
+ void print(std::ostream *OS, const Module* M = 0) const {
+ if (OS) print(*OS, M);
}
+ virtual void dump();
};
-
//===-------------------------------------
-// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
-// compute a normal dominator tree.
-//
-struct DominatorTree : public DominatorTreeBase {
- static AnalysisID ID; // Build dominator tree
-
- DominatorTree() : DominatorTreeBase(false) {}
-
- virtual bool runOnFunction(Function &F) {
- reset(); // Reset from the last time we were run...
- DominatorSet &DS = getAnalysis<DominatorSet>();
- Root = DS.getRoot();
- calculate(DS);
- return false;
+/// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
+/// compute a normal dominator tree.
+///
+class DominatorTree : public DominatorTreeBase {
+public:
+ static char ID; // Pass ID, replacement for typeid
+ DominatorTree() : DominatorTreeBase((intptr_t)&ID, false) {}
+
+ BasicBlock *getRoot() const {
+ assert(Roots.size() == 1 && "Should always have entry node!");
+ return Roots[0];
}
-
+
+ virtual bool runOnFunction(Function &F);
+
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
- AU.addProvided(ID);
- AU.addRequired(DominatorSet::ID);
}
+
+ /// splitBlock
+ /// BB is split and now it has one successor. Update dominator tree to
+ /// reflect this change.
+ void splitBlock(BasicBlock *BB);
private:
- void calculate(const DominatorSet &DS);
+ void calculate(Function& F);
+ DomTreeNode *getNodeForBlock(BasicBlock *BB);
+ unsigned DFSPass(BasicBlock *V, InfoRec &VInfo, unsigned N);
+ void Compress(BasicBlock *V);
+ BasicBlock *Eval(BasicBlock *v);
+ void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
+ inline BasicBlock *getIDom(BasicBlock *BB) const {
+ std::map<BasicBlock*, BasicBlock*>::const_iterator I = IDoms.find(BB);
+ return I != IDoms.end() ? I->second : 0;
+ }
};
-
//===-------------------------------------
-// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
-// compute the a post-dominator tree.
-//
-struct PostDominatorTree : public DominatorTreeBase {
- static AnalysisID ID; // Build immediate postdominators
-
- PostDominatorTree() : DominatorTreeBase(true) {}
-
- virtual bool runOnFunction(Function &F) {
- reset(); // Reset from the last time we were run...
- PostDominatorSet &DS = getAnalysis<PostDominatorSet>();
- Root = DS.getRoot();
- calculate(DS);
- return false;
+/// DominatorTree GraphTraits specialization so the DominatorTree can be
+/// iterable by generic graph iterators.
+///
+template <> struct GraphTraits<DomTreeNode*> {
+ typedef DomTreeNode NodeType;
+ typedef NodeType::iterator ChildIteratorType;
+
+ static NodeType *getEntryNode(NodeType *N) {
+ return N;
+ }
+ static inline ChildIteratorType child_begin(NodeType* N) {
+ return N->begin();
+ }
+ static inline ChildIteratorType child_end(NodeType* N) {
+ return N->end();
}
+};
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.setPreservesAll();
- AU.addRequired(PostDominatorSet::ID);
- AU.addProvided(ID);
+template <> struct GraphTraits<DominatorTree*>
+ : public GraphTraits<DomTreeNode*> {
+ static NodeType *getEntryNode(DominatorTree *DT) {
+ return DT->getRootNode();
}
-private:
- void calculate(const PostDominatorSet &DS);
};
//===----------------------------------------------------------------------===//
-//
-// DominanceFrontier - Calculate the dominance frontiers for a function.
-//
+/// DominanceFrontierBase - Common base class for computing forward and inverse
+/// dominance frontiers for a function.
+///
class DominanceFrontierBase : public DominatorBase {
public:
typedef std::set<BasicBlock*> DomSetType; // Dom set for a bb
protected:
DomSetMapType Frontiers;
public:
- DominanceFrontierBase(bool isPostDom) : DominatorBase(isPostDom) {}
+ DominanceFrontierBase(intptr_t ID, bool isPostDom)
+ : DominatorBase(ID, isPostDom) {}
virtual void releaseMemory() { Frontiers.clear(); }
// Accessor interface:
+ typedef DomSetMapType::iterator iterator;
typedef DomSetMapType::const_iterator const_iterator;
- inline const_iterator begin() const { return Frontiers.begin(); }
- inline const_iterator end() const { return Frontiers.end(); }
- inline const_iterator find(BasicBlock* B) const { return Frontiers.find(B); }
-};
-
-
-//===-------------------------------------
-// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
-// compute a normal dominator tree.
-//
-struct DominanceFrontier : public DominanceFrontierBase {
- static AnalysisID ID; // Build dominance frontier
+ iterator begin() { return Frontiers.begin(); }
+ const_iterator begin() const { return Frontiers.begin(); }
+ iterator end() { return Frontiers.end(); }
+ const_iterator end() const { return Frontiers.end(); }
+ iterator find(BasicBlock *B) { return Frontiers.find(B); }
+ const_iterator find(BasicBlock *B) const { return Frontiers.find(B); }
+
+ void addBasicBlock(BasicBlock *BB, const DomSetType &frontier) {
+ assert(find(BB) == end() && "Block already in DominanceFrontier!");
+ Frontiers.insert(std::make_pair(BB, frontier));
+ }
- DominanceFrontier() : DominanceFrontierBase(false) {}
+ void addToFrontier(iterator I, BasicBlock *Node) {
+ assert(I != end() && "BB is not in DominanceFrontier!");
+ I->second.insert(Node);
+ }
- virtual bool runOnFunction(Function &) {
- Frontiers.clear();
- DominatorTree &DT = getAnalysis<DominatorTree>();
- Root = DT.getRoot();
- calculate(DT, DT[Root]);
- return false;
+ void removeFromFrontier(iterator I, BasicBlock *Node) {
+ assert(I != end() && "BB is not in DominanceFrontier!");
+ assert(I->second.count(Node) && "Node is not in DominanceFrontier of BB");
+ I->second.erase(Node);
}
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.setPreservesAll();
- AU.addProvided(ID);
- AU.addRequired(DominatorTree::ID);
+ /// print - Convert to human readable form
+ ///
+ virtual void print(std::ostream &OS, const Module* = 0) const;
+ void print(std::ostream *OS, const Module* M = 0) const {
+ if (OS) print(*OS, M);
}
-private:
- const DomSetType &calculate(const DominatorTree &DT,
- const DominatorTree::Node *Node);
+ virtual void dump();
};
//===-------------------------------------
+/// DominanceFrontier Class - Concrete subclass of DominanceFrontierBase that is
+/// used to compute a forward dominator frontiers.
+///
+class DominanceFrontier : public DominanceFrontierBase {
+public:
+ static char ID; // Pass ID, replacement for typeid
+ DominanceFrontier() :
+ DominanceFrontierBase((intptr_t)& ID, false) {}
-// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
-// used to compute the a post-dominance frontier.
-//
-struct PostDominanceFrontier : public DominanceFrontierBase {
- static AnalysisID ID; // Build post dominance frontier
-
- PostDominanceFrontier() : DominanceFrontierBase(true) {}
+ BasicBlock *getRoot() const {
+ assert(Roots.size() == 1 && "Should always have entry node!");
+ return Roots[0];
+ }
virtual bool runOnFunction(Function &) {
Frontiers.clear();
- PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
- Root = DT.getRoot();
- calculate(DT, DT[Root]);
+ DominatorTree &DT = getAnalysis<DominatorTree>();
+ Roots = DT.getRoots();
+ assert(Roots.size() == 1 && "Only one entry block for forward domfronts!");
+ calculate(DT, DT[Roots[0]]);
return false;
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
- AU.addRequired(PostDominatorTree::ID);
- AU.addProvided(ID);
+ AU.addRequired<DominatorTree>();
}
+
+ /// splitBlock
+ /// BB is split and now it has one successor. Update dominace frontier to
+ /// reflect this change.
+ void splitBlock(BasicBlock *BB);
+
private:
- const DomSetType &calculate(const PostDominatorTree &DT,
- const DominatorTree::Node *Node);
+ const DomSetType &calculate(const DominatorTree &DT,
+ const DomTreeNode *Node);
};
+
+} // End llvm namespace
+
#endif