#include "llvm/Support/CFG.h"
#include "llvm/Support/Compiler.h"
#include <algorithm>
+#include <map>
#include <set>
namespace llvm {
protected:
std::vector<NodeT*> Roots;
const bool IsPostDominators;
- inline DominatorBase(bool isPostDom) :
+ inline explicit DominatorBase(bool isPostDom) :
Roots(), IsPostDominators(isPostDom) {}
public:
return C;
}
+ size_t getNumChildren() const {
+ return Children.size();
+ }
+
void setIDom(DomTreeNodeBase<NodeT> *NewIDom) {
assert(IDom && "No immediate dominator?");
if (IDom != NewIDom) {
unsigned int SlowQueries;
// Information record used during immediate dominators computation.
struct InfoRec {
+ unsigned DFSNum;
unsigned Semi;
unsigned Size;
- NodeT *Label, *Parent, *Child, *Ancestor;
+ NodeT *Label, *Child;
+ unsigned Parent, Ancestor;
std::vector<NodeT*> Bucket;
- InfoRec() : Semi(0), Size(0), Label(0), Parent(0), Child(0), Ancestor(0) {}
+ InfoRec() : DFSNum(0), Semi(0), Size(0), Label(0), Child(0), Parent(0),
+ Ancestor(0) {}
};
DenseMap<NodeT*, NodeT*> IDoms;
bool NewBBDominatesNewBBSucc = true;
{
typename GraphT::NodeType* OnePred = PredBlocks[0];
- unsigned i = 1, e = PredBlocks.size();
+ size_t i = 1, e = PredBlocks.size();
for (i = 1; !DT.isReachableFromEntry(OnePred); ++i) {
assert(i != e && "Didn't find reachable pred?");
OnePred = PredBlocks[i];
}
public:
- DominatorTreeBase(bool isPostDom)
+ explicit DominatorTreeBase(bool isPostDom)
: DominatorBase<NodeT>(isPostDom), DFSInfoValid(false), SlowQueries(0) {}
virtual ~DominatorTreeBase() { reset(); }
///
virtual void print(std::ostream &o, const Module* ) const {
o << "=============================--------------------------------\n";
- o << "Inorder Dominator Tree: ";
+ if (this->isPostDominator())
+ o << "Inorder PostDominator Tree: ";
+ else
+ o << "Inorder Dominator Tree: ";
if (this->DFSInfoValid)
o << "DFSNumbers invalid: " << SlowQueries << " slow queries.";
o << "\n";
template<class GraphT>
friend void Link(DominatorTreeBase<typename GraphT::NodeType>& DT,
- typename GraphT::NodeType* V,
- typename GraphT::NodeType* W,
+ unsigned DFSNumV, typename GraphT::NodeType* W,
typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &WInfo);
template<class GraphT>
SmallVector<std::pair<DomTreeNodeBase<NodeT>*,
typename DomTreeNodeBase<NodeT>::iterator>, 32> WorkStack;
- for (unsigned i = 0, e = this->Roots.size(); i != e; ++i) {
+ for (unsigned i = 0, e = (unsigned)this->Roots.size(); i != e; ++i) {
DomTreeNodeBase<NodeT> *ThisRoot = getNode(this->Roots[i]);
WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin()));
ThisRoot->DFSNumIn = DFSNum++;
// Haven't calculated this node yet? Get or calculate the node for the
// immediate dominator.
NodeT *IDom = getIDom(BB);
+
+ assert(IDom || this->DomTreeNodes[NULL]);
DomTreeNodeBase<NodeT> *IDomNode = getNodeForBlock(IDom);
// Add a new tree node for this BasicBlock, and link it as a child of
}
inline void addRoot(NodeT* BB) {
- // Unreachable block is not a root node.
- if (!isa<UnreachableInst>(&BB->back()))
- this->Roots.push_back(BB);
+ this->Roots.push_back(BB);
}
public: