2014-01-13 11:52:56 +01:00
|
|
|
//===- GenericDomTree.h - Generic dominator trees for graphs ----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
///
|
|
|
|
/// This file defines a set of templates that efficiently compute a dominator
|
|
|
|
/// tree over a generic graph. This is used typically in LLVM for fast
|
|
|
|
/// dominance queries on the CFG, but is fully generic w.r.t. the underlying
|
|
|
|
/// graph types.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 18:26:38 +02:00
|
|
|
#ifndef LLVM_SUPPORT_GENERICDOMTREE_H
|
|
|
|
#define LLVM_SUPPORT_GENERICDOMTREE_H
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DepthFirstIterator.h"
|
|
|
|
#include "llvm/ADT/GraphTraits.h"
|
2015-02-13 10:09:03 +01:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2014-01-13 11:52:56 +01:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2015-01-14 04:55:58 +01:00
|
|
|
/// \brief Base class that other, more interesting dominator analyses
|
2014-01-13 11:52:56 +01:00
|
|
|
/// inherit from.
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class NodeT> class DominatorBase {
|
2014-01-13 11:52:56 +01:00
|
|
|
protected:
|
2015-01-14 04:56:00 +01:00
|
|
|
std::vector<NodeT *> Roots;
|
2015-01-14 11:07:19 +01:00
|
|
|
bool IsPostDominators;
|
2015-01-14 04:58:50 +01:00
|
|
|
explicit DominatorBase(bool isPostDom)
|
2015-01-14 04:56:00 +01:00
|
|
|
: Roots(), IsPostDominators(isPostDom) {}
|
2015-01-14 11:07:19 +01:00
|
|
|
DominatorBase(DominatorBase &&Arg)
|
|
|
|
: Roots(std::move(Arg.Roots)),
|
|
|
|
IsPostDominators(std::move(Arg.IsPostDominators)) {
|
|
|
|
Arg.Roots.clear();
|
|
|
|
}
|
|
|
|
DominatorBase &operator=(DominatorBase &&RHS) {
|
|
|
|
Roots = std::move(RHS.Roots);
|
|
|
|
IsPostDominators = std::move(RHS.IsPostDominators);
|
|
|
|
RHS.Roots.clear();
|
|
|
|
return *this;
|
|
|
|
}
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
public:
|
2014-01-13 11:52:56 +01:00
|
|
|
/// 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).
|
|
|
|
///
|
2015-01-14 04:58:50 +01:00
|
|
|
const std::vector<NodeT *> &getRoots() const { return Roots; }
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
/// isPostDominator - Returns true if analysis based of postdoms
|
|
|
|
///
|
|
|
|
bool isPostDominator() const { return IsPostDominators; }
|
|
|
|
};
|
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class NodeT> class DominatorTreeBase;
|
2014-01-13 11:52:56 +01:00
|
|
|
struct PostDominatorTree;
|
|
|
|
|
2015-01-14 04:55:58 +01:00
|
|
|
/// \brief Base class for the actual dominator tree node.
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class NodeT> class DomTreeNodeBase {
|
2014-01-13 11:52:56 +01:00
|
|
|
NodeT *TheBB;
|
|
|
|
DomTreeNodeBase<NodeT> *IDom;
|
|
|
|
std::vector<DomTreeNodeBase<NodeT> *> Children;
|
2014-01-13 12:58:34 +01:00
|
|
|
mutable int DFSNumIn, DFSNumOut;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class N> friend class DominatorTreeBase;
|
2014-01-13 11:52:56 +01:00
|
|
|
friend struct PostDominatorTree;
|
2015-01-14 04:56:00 +01:00
|
|
|
|
2014-01-13 11:52:56 +01:00
|
|
|
public:
|
|
|
|
typedef typename std::vector<DomTreeNodeBase<NodeT> *>::iterator iterator;
|
|
|
|
typedef typename std::vector<DomTreeNodeBase<NodeT> *>::const_iterator
|
2015-01-14 04:56:00 +01:00
|
|
|
const_iterator;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
iterator begin() { return Children.begin(); }
|
|
|
|
iterator end() { return Children.end(); }
|
2014-01-13 11:52:56 +01:00
|
|
|
const_iterator begin() const { return Children.begin(); }
|
2015-01-14 04:56:00 +01:00
|
|
|
const_iterator end() const { return Children.end(); }
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
NodeT *getBlock() const { return TheBB; }
|
|
|
|
DomTreeNodeBase<NodeT> *getIDom() const { return IDom; }
|
2015-01-14 04:56:00 +01:00
|
|
|
const std::vector<DomTreeNodeBase<NodeT> *> &getChildren() const {
|
2014-01-13 11:52:56 +01:00
|
|
|
return Children;
|
|
|
|
}
|
|
|
|
|
|
|
|
DomTreeNodeBase(NodeT *BB, DomTreeNodeBase<NodeT> *iDom)
|
2015-01-14 04:56:00 +01:00
|
|
|
: TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) {}
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 20:55:27 +01:00
|
|
|
std::unique_ptr<DomTreeNodeBase<NodeT>>
|
|
|
|
addChild(std::unique_ptr<DomTreeNodeBase<NodeT>> C) {
|
|
|
|
Children.push_back(C.get());
|
2014-01-13 11:52:56 +01:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
size_t getNumChildren() const { return Children.size(); }
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
void clearAllChildren() { Children.clear(); }
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
bool compare(const DomTreeNodeBase<NodeT> *Other) const {
|
|
|
|
if (getNumChildren() != Other->getNumChildren())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
SmallPtrSet<const NodeT *, 4> OtherChildren;
|
|
|
|
for (const_iterator I = Other->begin(), E = Other->end(); I != E; ++I) {
|
|
|
|
const NodeT *Nd = (*I)->getBlock();
|
|
|
|
OtherChildren.insert(Nd);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const_iterator I = begin(), E = end(); I != E; ++I) {
|
|
|
|
const NodeT *N = (*I)->getBlock();
|
|
|
|
if (OtherChildren.count(N) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIDom(DomTreeNodeBase<NodeT> *NewIDom) {
|
|
|
|
assert(IDom && "No immediate dominator?");
|
|
|
|
if (IDom != NewIDom) {
|
2015-01-14 04:56:00 +01:00
|
|
|
typename std::vector<DomTreeNodeBase<NodeT> *>::iterator I =
|
|
|
|
std::find(IDom->Children.begin(), IDom->Children.end(), this);
|
2014-01-13 11:52:56 +01:00
|
|
|
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.
|
|
|
|
unsigned getDFSNumIn() const { return DFSNumIn; }
|
|
|
|
unsigned getDFSNumOut() const { return DFSNumOut; }
|
2015-01-14 04:56:00 +01:00
|
|
|
|
2014-01-13 11:52:56 +01:00
|
|
|
private:
|
|
|
|
// Return true if this node is dominated by other. Use this only if DFS info
|
|
|
|
// is valid.
|
|
|
|
bool DominatedBy(const DomTreeNodeBase<NodeT> *other) const {
|
|
|
|
return this->DFSNumIn >= other->DFSNumIn &&
|
2015-01-14 04:56:00 +01:00
|
|
|
this->DFSNumOut <= other->DFSNumOut;
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class NodeT>
|
2015-01-14 04:58:50 +01:00
|
|
|
raw_ostream &operator<<(raw_ostream &o, const DomTreeNodeBase<NodeT> *Node) {
|
2014-01-13 11:52:56 +01:00
|
|
|
if (Node->getBlock())
|
|
|
|
Node->getBlock()->printAsOperand(o, false);
|
|
|
|
else
|
|
|
|
o << " <<exit node>>";
|
|
|
|
|
|
|
|
o << " {" << Node->getDFSNumIn() << "," << Node->getDFSNumOut() << "}";
|
|
|
|
|
|
|
|
return o << "\n";
|
|
|
|
}
|
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class NodeT>
|
2015-01-14 04:58:50 +01:00
|
|
|
void PrintDomTree(const DomTreeNodeBase<NodeT> *N, raw_ostream &o,
|
|
|
|
unsigned Lev) {
|
2015-01-14 04:56:00 +01:00
|
|
|
o.indent(2 * Lev) << "[" << Lev << "] " << N;
|
2014-01-13 11:52:56 +01:00
|
|
|
for (typename DomTreeNodeBase<NodeT>::const_iterator I = N->begin(),
|
2015-01-14 04:56:00 +01:00
|
|
|
E = N->end();
|
|
|
|
I != E; ++I)
|
|
|
|
PrintDomTree<NodeT>(*I, o, Lev + 1);
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 04:55:58 +01:00
|
|
|
// The calculate routine is provided in a separate header but referenced here.
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class FuncT, class N>
|
|
|
|
void Calculate(DominatorTreeBase<typename GraphTraits<N>::NodeType> &DT,
|
|
|
|
FuncT &F);
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 04:55:58 +01:00
|
|
|
/// \brief Core dominator tree base class.
|
|
|
|
///
|
|
|
|
/// This class is a generic template over graph nodes. It is instantiated for
|
|
|
|
/// various graphs in the LLVM IR or in the code generator.
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class NodeT> class DominatorTreeBase : public DominatorBase<NodeT> {
|
2015-02-15 23:54:22 +01:00
|
|
|
DominatorTreeBase(const DominatorTreeBase &) = delete;
|
|
|
|
DominatorTreeBase &operator=(const DominatorTreeBase &) = delete;
|
2015-01-14 11:07:19 +01:00
|
|
|
|
2014-01-13 11:52:56 +01:00
|
|
|
bool dominatedBySlowTreeWalk(const DomTreeNodeBase<NodeT> *A,
|
|
|
|
const DomTreeNodeBase<NodeT> *B) const {
|
|
|
|
assert(A != B);
|
|
|
|
assert(isReachableFromEntry(B));
|
|
|
|
assert(isReachableFromEntry(A));
|
|
|
|
|
|
|
|
const DomTreeNodeBase<NodeT> *IDom;
|
2014-04-09 08:08:46 +02:00
|
|
|
while ((IDom = B->getIDom()) != nullptr && IDom != A && IDom != B)
|
2015-01-14 04:56:00 +01:00
|
|
|
B = IDom; // Walk up the tree
|
2014-04-09 08:08:46 +02:00
|
|
|
return IDom != nullptr;
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 11:07:19 +01:00
|
|
|
/// \brief Wipe this tree's state without releasing any resources.
|
|
|
|
///
|
|
|
|
/// This is essentially a post-move helper only. It leaves the object in an
|
|
|
|
/// assignable and destroyable state, but otherwise invalid.
|
|
|
|
void wipe() {
|
|
|
|
DomTreeNodes.clear();
|
|
|
|
IDoms.clear();
|
|
|
|
Vertex.clear();
|
|
|
|
Info.clear();
|
|
|
|
RootNode = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-13 11:52:56 +01:00
|
|
|
protected:
|
2015-01-14 20:55:27 +01:00
|
|
|
typedef DenseMap<NodeT *, std::unique_ptr<DomTreeNodeBase<NodeT>>>
|
|
|
|
DomTreeNodeMapType;
|
2014-01-13 11:52:56 +01:00
|
|
|
DomTreeNodeMapType DomTreeNodes;
|
|
|
|
DomTreeNodeBase<NodeT> *RootNode;
|
|
|
|
|
2014-01-13 12:58:34 +01:00
|
|
|
mutable bool DFSInfoValid;
|
|
|
|
mutable unsigned int SlowQueries;
|
2014-01-13 11:52:56 +01:00
|
|
|
// Information record used during immediate dominators computation.
|
|
|
|
struct InfoRec {
|
|
|
|
unsigned DFSNum;
|
|
|
|
unsigned Parent;
|
|
|
|
unsigned Semi;
|
|
|
|
NodeT *Label;
|
|
|
|
|
2014-04-09 08:08:46 +02:00
|
|
|
InfoRec() : DFSNum(0), Parent(0), Semi(0), Label(nullptr) {}
|
2014-01-13 11:52:56 +01:00
|
|
|
};
|
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
DenseMap<NodeT *, NodeT *> IDoms;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
// Vertex - Map the DFS number to the NodeT*
|
2015-01-14 04:56:00 +01:00
|
|
|
std::vector<NodeT *> Vertex;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
// Info - Collection of information used during the computation of idoms.
|
2015-01-14 04:56:00 +01:00
|
|
|
DenseMap<NodeT *, InfoRec> Info;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
DomTreeNodes.clear();
|
|
|
|
IDoms.clear();
|
|
|
|
this->Roots.clear();
|
|
|
|
Vertex.clear();
|
2014-04-09 08:08:46 +02:00
|
|
|
RootNode = nullptr;
|
2015-04-14 21:49:26 +02:00
|
|
|
DFSInfoValid = false;
|
|
|
|
SlowQueries = 0;
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewBB is split and now it has one successor. Update dominator tree to
|
|
|
|
// reflect this change.
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class N, class GraphT>
|
|
|
|
void Split(DominatorTreeBase<typename GraphT::NodeType> &DT,
|
|
|
|
typename GraphT::NodeType *NewBB) {
|
2014-01-13 11:52:56 +01:00
|
|
|
assert(std::distance(GraphT::child_begin(NewBB),
|
|
|
|
GraphT::child_end(NewBB)) == 1 &&
|
|
|
|
"NewBB should have a single successor!");
|
2015-01-14 04:56:00 +01:00
|
|
|
typename GraphT::NodeType *NewBBSucc = *GraphT::child_begin(NewBB);
|
|
|
|
|
|
|
|
std::vector<typename GraphT::NodeType *> PredBlocks;
|
|
|
|
typedef GraphTraits<Inverse<N>> InvTraits;
|
|
|
|
for (typename InvTraits::ChildIteratorType
|
|
|
|
PI = InvTraits::child_begin(NewBB),
|
|
|
|
PE = InvTraits::child_end(NewBB);
|
|
|
|
PI != PE; ++PI)
|
2014-01-13 11:52:56 +01:00
|
|
|
PredBlocks.push_back(*PI);
|
|
|
|
|
|
|
|
assert(!PredBlocks.empty() && "No predblocks?");
|
|
|
|
|
|
|
|
bool NewBBDominatesNewBBSucc = true;
|
2015-01-14 04:56:00 +01:00
|
|
|
for (typename InvTraits::ChildIteratorType
|
|
|
|
PI = InvTraits::child_begin(NewBBSucc),
|
|
|
|
E = InvTraits::child_end(NewBBSucc);
|
|
|
|
PI != E; ++PI) {
|
2014-01-13 11:52:56 +01:00
|
|
|
typename InvTraits::NodeType *ND = *PI;
|
|
|
|
if (ND != NewBB && !DT.dominates(NewBBSucc, ND) &&
|
|
|
|
DT.isReachableFromEntry(ND)) {
|
|
|
|
NewBBDominatesNewBBSucc = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find NewBB's immediate dominator and create new dominator tree node for
|
|
|
|
// NewBB.
|
2014-04-09 08:08:46 +02:00
|
|
|
NodeT *NewBBIDom = nullptr;
|
2014-01-13 11:52:56 +01:00
|
|
|
unsigned i = 0;
|
|
|
|
for (i = 0; i < PredBlocks.size(); ++i)
|
|
|
|
if (DT.isReachableFromEntry(PredBlocks[i])) {
|
|
|
|
NewBBIDom = PredBlocks[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's possible that none of the predecessors of NewBB are reachable;
|
|
|
|
// in that case, NewBB itself is unreachable, so nothing needs to be
|
|
|
|
// changed.
|
|
|
|
if (!NewBBIDom)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = i + 1; i < PredBlocks.size(); ++i) {
|
|
|
|
if (DT.isReachableFromEntry(PredBlocks[i]))
|
|
|
|
NewBBIDom = DT.findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the new dominator tree node... and set the idom of NewBB.
|
|
|
|
DomTreeNodeBase<NodeT> *NewBBNode = DT.addNewBlock(NewBB, NewBBIDom);
|
|
|
|
|
|
|
|
// If NewBB strictly dominates other blocks, then it is now the immediate
|
|
|
|
// dominator of NewBBSucc. Update the dominator tree as appropriate.
|
|
|
|
if (NewBBDominatesNewBBSucc) {
|
|
|
|
DomTreeNodeBase<NodeT> *NewBBSuccNode = DT.getNode(NewBBSucc);
|
|
|
|
DT.changeImmediateDominator(NewBBSuccNode, NewBBNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit DominatorTreeBase(bool isPostDom)
|
2015-01-14 04:56:00 +01:00
|
|
|
: DominatorBase<NodeT>(isPostDom), DFSInfoValid(false), SlowQueries(0) {}
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 11:07:19 +01:00
|
|
|
DominatorTreeBase(DominatorTreeBase &&Arg)
|
|
|
|
: DominatorBase<NodeT>(
|
|
|
|
std::move(static_cast<DominatorBase<NodeT> &>(Arg))),
|
|
|
|
DomTreeNodes(std::move(Arg.DomTreeNodes)),
|
|
|
|
RootNode(std::move(Arg.RootNode)),
|
|
|
|
DFSInfoValid(std::move(Arg.DFSInfoValid)),
|
|
|
|
SlowQueries(std::move(Arg.SlowQueries)), IDoms(std::move(Arg.IDoms)),
|
|
|
|
Vertex(std::move(Arg.Vertex)), Info(std::move(Arg.Info)) {
|
|
|
|
Arg.wipe();
|
|
|
|
}
|
|
|
|
DominatorTreeBase &operator=(DominatorTreeBase &&RHS) {
|
|
|
|
DominatorBase<NodeT>::operator=(
|
|
|
|
std::move(static_cast<DominatorBase<NodeT> &>(RHS)));
|
|
|
|
DomTreeNodes = std::move(RHS.DomTreeNodes);
|
|
|
|
RootNode = std::move(RHS.RootNode);
|
|
|
|
DFSInfoValid = std::move(RHS.DFSInfoValid);
|
|
|
|
SlowQueries = std::move(RHS.SlowQueries);
|
|
|
|
IDoms = std::move(RHS.IDoms);
|
|
|
|
Vertex = std::move(RHS.Vertex);
|
|
|
|
Info = std::move(RHS.Info);
|
|
|
|
RHS.wipe();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-01-13 11:52:56 +01:00
|
|
|
/// compare - Return false if the other dominator tree base matches this
|
|
|
|
/// dominator tree base. Otherwise return true.
|
2014-01-13 14:07:17 +01:00
|
|
|
bool compare(const DominatorTreeBase &Other) const {
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
const DomTreeNodeMapType &OtherDomTreeNodes = Other.DomTreeNodes;
|
|
|
|
if (DomTreeNodes.size() != OtherDomTreeNodes.size())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (typename DomTreeNodeMapType::const_iterator
|
2015-01-14 04:56:00 +01:00
|
|
|
I = this->DomTreeNodes.begin(),
|
|
|
|
E = this->DomTreeNodes.end();
|
|
|
|
I != E; ++I) {
|
2014-01-13 11:52:56 +01:00
|
|
|
NodeT *BB = I->first;
|
2015-01-14 04:56:00 +01:00
|
|
|
typename DomTreeNodeMapType::const_iterator OI =
|
|
|
|
OtherDomTreeNodes.find(BB);
|
2014-01-13 11:52:56 +01:00
|
|
|
if (OI == OtherDomTreeNodes.end())
|
|
|
|
return true;
|
|
|
|
|
2015-01-14 20:55:27 +01:00
|
|
|
DomTreeNodeBase<NodeT> &MyNd = *I->second;
|
|
|
|
DomTreeNodeBase<NodeT> &OtherNd = *OI->second;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 20:55:27 +01:00
|
|
|
if (MyNd.compare(&OtherNd))
|
2014-01-13 11:52:56 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-14 11:33:21 +01:00
|
|
|
void releaseMemory() { reset(); }
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
/// getNode - return the (Post)DominatorTree node for the specified basic
|
|
|
|
/// block. This is the same as using operator[] on this class.
|
|
|
|
///
|
2015-01-14 04:58:50 +01:00
|
|
|
DomTreeNodeBase<NodeT> *getNode(NodeT *BB) const {
|
2015-01-14 20:55:27 +01:00
|
|
|
auto I = DomTreeNodes.find(BB);
|
|
|
|
if (I != DomTreeNodes.end())
|
|
|
|
return I->second.get();
|
|
|
|
return nullptr;
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 04:58:50 +01:00
|
|
|
DomTreeNodeBase<NodeT> *operator[](NodeT *BB) const { return getNode(BB); }
|
2014-07-02 08:50:48 +02:00
|
|
|
|
2014-01-13 11:52:56 +01:00
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
DomTreeNodeBase<NodeT> *getRootNode() { return RootNode; }
|
|
|
|
const DomTreeNodeBase<NodeT> *getRootNode() const { return RootNode; }
|
|
|
|
|
|
|
|
/// Get all nodes dominated by R, including R itself.
|
|
|
|
void getDescendants(NodeT *R, SmallVectorImpl<NodeT *> &Result) const {
|
|
|
|
Result.clear();
|
|
|
|
const DomTreeNodeBase<NodeT> *RN = getNode(R);
|
2014-04-09 08:08:46 +02:00
|
|
|
if (!RN)
|
2014-01-13 11:52:56 +01:00
|
|
|
return; // If R is unreachable, it will not be present in the DOM tree.
|
|
|
|
SmallVector<const DomTreeNodeBase<NodeT> *, 8> WL;
|
|
|
|
WL.push_back(RN);
|
|
|
|
|
|
|
|
while (!WL.empty()) {
|
|
|
|
const DomTreeNodeBase<NodeT> *N = WL.pop_back_val();
|
|
|
|
Result.push_back(N->getBlock());
|
|
|
|
WL.append(N->begin(), N->end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// properlyDominates - Returns true iff A dominates B and A != B.
|
|
|
|
/// Note that this is not a constant time operation!
|
|
|
|
///
|
|
|
|
bool properlyDominates(const DomTreeNodeBase<NodeT> *A,
|
2014-01-13 12:58:34 +01:00
|
|
|
const DomTreeNodeBase<NodeT> *B) const {
|
2014-04-09 08:08:46 +02:00
|
|
|
if (!A || !B)
|
2014-01-13 11:52:56 +01:00
|
|
|
return false;
|
|
|
|
if (A == B)
|
|
|
|
return false;
|
|
|
|
return dominates(A, B);
|
|
|
|
}
|
|
|
|
|
2014-01-13 12:58:34 +01:00
|
|
|
bool properlyDominates(const NodeT *A, const NodeT *B) const;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
/// isReachableFromEntry - Return true if A is dominated by the entry
|
|
|
|
/// block of the function containing it.
|
2015-01-14 04:56:00 +01:00
|
|
|
bool isReachableFromEntry(const NodeT *A) const {
|
2014-01-13 11:52:56 +01:00
|
|
|
assert(!this->isPostDominator() &&
|
|
|
|
"This is not implemented for post dominators");
|
|
|
|
return isReachableFromEntry(getNode(const_cast<NodeT *>(A)));
|
|
|
|
}
|
|
|
|
|
2015-01-14 04:58:50 +01:00
|
|
|
bool isReachableFromEntry(const DomTreeNodeBase<NodeT> *A) const { return A; }
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
/// dominates - Returns true iff A dominates B. Note that this is not a
|
|
|
|
/// constant time operation!
|
|
|
|
///
|
2015-01-14 04:58:50 +01:00
|
|
|
bool dominates(const DomTreeNodeBase<NodeT> *A,
|
|
|
|
const DomTreeNodeBase<NodeT> *B) const {
|
2014-01-13 11:52:56 +01:00
|
|
|
// A node trivially dominates itself.
|
|
|
|
if (B == A)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// An unreachable node is dominated by anything.
|
|
|
|
if (!isReachableFromEntry(B))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// And dominates nothing.
|
|
|
|
if (!isReachableFromEntry(A))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Compare the result of the tree walk and the dfs numbers, if expensive
|
|
|
|
// checks are enabled.
|
|
|
|
#ifdef XDEBUG
|
|
|
|
assert((!DFSInfoValid ||
|
|
|
|
(dominatedBySlowTreeWalk(A, B) == B->DominatedBy(A))) &&
|
|
|
|
"Tree walk disagrees with dfs numbers!");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dominatedBySlowTreeWalk(A, B);
|
|
|
|
}
|
|
|
|
|
2014-01-13 12:58:34 +01:00
|
|
|
bool dominates(const NodeT *A, const NodeT *B) const;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
NodeT *getRoot() const {
|
|
|
|
assert(this->Roots.size() == 1 && "Should always have entry node!");
|
|
|
|
return this->Roots[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// findNearestCommonDominator - Find nearest common dominator basic block
|
|
|
|
/// for basic block A and B. If there is no such block then return NULL.
|
|
|
|
NodeT *findNearestCommonDominator(NodeT *A, NodeT *B) {
|
|
|
|
assert(A->getParent() == B->getParent() &&
|
|
|
|
"Two blocks are not in same function");
|
|
|
|
|
|
|
|
// If either A or B is a entry block then it is nearest common dominator
|
|
|
|
// (for forward-dominators).
|
|
|
|
if (!this->isPostDominator()) {
|
|
|
|
NodeT &Entry = A->getParent()->front();
|
|
|
|
if (A == &Entry || B == &Entry)
|
|
|
|
return &Entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If B dominates A then B is nearest common dominator.
|
|
|
|
if (dominates(B, A))
|
|
|
|
return B;
|
|
|
|
|
|
|
|
// If A dominates B then A is nearest common dominator.
|
|
|
|
if (dominates(A, B))
|
|
|
|
return A;
|
|
|
|
|
|
|
|
DomTreeNodeBase<NodeT> *NodeA = getNode(A);
|
|
|
|
DomTreeNodeBase<NodeT> *NodeB = getNode(B);
|
|
|
|
|
2014-04-28 11:34:03 +02:00
|
|
|
// If we have DFS info, then we can avoid all allocations by just querying
|
|
|
|
// it from each IDom. Note that because we call 'dominates' twice above, we
|
|
|
|
// expect to call through this code at most 16 times in a row without
|
|
|
|
// building valid DFS information. This is important as below is a *very*
|
|
|
|
// slow tree walk.
|
|
|
|
if (DFSInfoValid) {
|
|
|
|
DomTreeNodeBase<NodeT> *IDomA = NodeA->getIDom();
|
|
|
|
while (IDomA) {
|
|
|
|
if (NodeB->DominatedBy(IDomA))
|
|
|
|
return IDomA->getBlock();
|
|
|
|
IDomA = IDomA->getIDom();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-13 11:52:56 +01:00
|
|
|
// Collect NodeA dominators set.
|
2015-01-14 04:56:00 +01:00
|
|
|
SmallPtrSet<DomTreeNodeBase<NodeT> *, 16> NodeADoms;
|
2014-01-13 11:52:56 +01:00
|
|
|
NodeADoms.insert(NodeA);
|
|
|
|
DomTreeNodeBase<NodeT> *IDomA = NodeA->getIDom();
|
|
|
|
while (IDomA) {
|
|
|
|
NodeADoms.insert(IDomA);
|
|
|
|
IDomA = IDomA->getIDom();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Walk NodeB immediate dominators chain and find common dominator node.
|
|
|
|
DomTreeNodeBase<NodeT> *IDomB = NodeB->getIDom();
|
|
|
|
while (IDomB) {
|
|
|
|
if (NodeADoms.count(IDomB) != 0)
|
|
|
|
return IDomB->getBlock();
|
|
|
|
|
|
|
|
IDomB = IDomB->getIDom();
|
|
|
|
}
|
|
|
|
|
2014-04-09 08:08:46 +02:00
|
|
|
return nullptr;
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const NodeT *findNearestCommonDominator(const NodeT *A, const NodeT *B) {
|
|
|
|
// Cast away the const qualifiers here. This is ok since
|
|
|
|
// const is re-introduced on the return type.
|
|
|
|
return findNearestCommonDominator(const_cast<NodeT *>(A),
|
|
|
|
const_cast<NodeT *>(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.
|
|
|
|
DomTreeNodeBase<NodeT> *addNewBlock(NodeT *BB, NodeT *DomBB) {
|
2014-04-14 02:51:57 +02:00
|
|
|
assert(getNode(BB) == nullptr && "Block already in dominator tree!");
|
2014-01-13 11:52:56 +01:00
|
|
|
DomTreeNodeBase<NodeT> *IDomNode = getNode(DomBB);
|
|
|
|
assert(IDomNode && "Not immediate dominator specified for block!");
|
|
|
|
DFSInfoValid = false;
|
2015-01-14 20:55:27 +01:00
|
|
|
return (DomTreeNodes[BB] = IDomNode->addChild(
|
|
|
|
llvm::make_unique<DomTreeNodeBase<NodeT>>(BB, IDomNode))).get();
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// changeImmediateDominator - This method is used to update the dominator
|
|
|
|
/// tree information when a node's immediate dominator changes.
|
|
|
|
///
|
|
|
|
void changeImmediateDominator(DomTreeNodeBase<NodeT> *N,
|
|
|
|
DomTreeNodeBase<NodeT> *NewIDom) {
|
|
|
|
assert(N && NewIDom && "Cannot change null node pointers!");
|
|
|
|
DFSInfoValid = false;
|
|
|
|
N->setIDom(NewIDom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeImmediateDominator(NodeT *BB, NodeT *NewBB) {
|
|
|
|
changeImmediateDominator(getNode(BB), getNode(NewBB));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// eraseNode - Removes a node from the dominator tree. Block must not
|
|
|
|
/// dominate any other blocks. Removes node from its immediate dominator's
|
|
|
|
/// children list. Deletes dominator node associated with basic block BB.
|
|
|
|
void eraseNode(NodeT *BB) {
|
|
|
|
DomTreeNodeBase<NodeT> *Node = getNode(BB);
|
|
|
|
assert(Node && "Removing node that isn't in dominator tree.");
|
|
|
|
assert(Node->getChildren().empty() && "Node is not a leaf node.");
|
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
// Remove node from immediate dominator's children list.
|
2014-01-13 11:52:56 +01:00
|
|
|
DomTreeNodeBase<NodeT> *IDom = Node->getIDom();
|
|
|
|
if (IDom) {
|
2015-01-14 04:56:00 +01:00
|
|
|
typename std::vector<DomTreeNodeBase<NodeT> *>::iterator I =
|
|
|
|
std::find(IDom->Children.begin(), IDom->Children.end(), Node);
|
2014-01-13 11:52:56 +01:00
|
|
|
assert(I != IDom->Children.end() &&
|
|
|
|
"Not in immediate dominator children set!");
|
|
|
|
// I am no longer your child...
|
|
|
|
IDom->Children.erase(I);
|
|
|
|
}
|
|
|
|
|
|
|
|
DomTreeNodes.erase(BB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// splitBlock - BB is split and now it has one successor. Update dominator
|
|
|
|
/// tree to reflect this change.
|
2015-01-14 04:56:00 +01:00
|
|
|
void splitBlock(NodeT *NewBB) {
|
2014-01-13 11:52:56 +01:00
|
|
|
if (this->IsPostDominators)
|
2015-01-14 04:56:00 +01:00
|
|
|
this->Split<Inverse<NodeT *>, GraphTraits<Inverse<NodeT *>>>(*this,
|
|
|
|
NewBB);
|
2014-01-13 11:52:56 +01:00
|
|
|
else
|
2015-01-14 04:56:00 +01:00
|
|
|
this->Split<NodeT *, GraphTraits<NodeT *>>(*this, NewBB);
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// print - Convert to human readable form
|
|
|
|
///
|
|
|
|
void print(raw_ostream &o) const {
|
|
|
|
o << "=============================--------------------------------\n";
|
|
|
|
if (this->isPostDominator())
|
|
|
|
o << "Inorder PostDominator Tree: ";
|
|
|
|
else
|
|
|
|
o << "Inorder Dominator Tree: ";
|
|
|
|
if (!this->DFSInfoValid)
|
|
|
|
o << "DFSNumbers invalid: " << SlowQueries << " slow queries.";
|
|
|
|
o << "\n";
|
|
|
|
|
|
|
|
// The postdom tree can have a null root if there are no returns.
|
|
|
|
if (getRootNode())
|
|
|
|
PrintDomTree<NodeT>(getRootNode(), o, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class GraphT>
|
|
|
|
friend typename GraphT::NodeType *
|
|
|
|
Eval(DominatorTreeBase<typename GraphT::NodeType> &DT,
|
|
|
|
typename GraphT::NodeType *V, unsigned LastLinked);
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class GraphT>
|
|
|
|
friend unsigned DFSPass(DominatorTreeBase<typename GraphT::NodeType> &DT,
|
|
|
|
typename GraphT::NodeType *V, unsigned N);
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class FuncT, class N>
|
|
|
|
friend void
|
|
|
|
Calculate(DominatorTreeBase<typename GraphTraits<N>::NodeType> &DT, FuncT &F);
|
2014-01-13 11:52:56 +01:00
|
|
|
|
Make updateDFSNumbers API public
Summary:
There are a number of passes that could be sped up by using dominator tree DFS numbers to order or compare things across multiple bbs
(MemorySSA, MergedLoadStoreMotion, EarlyCSE, Sinking, GVN, NewGVN, for starters :P).
For example, GVN/CSE elimination can be done with a simple stack/etc (instead of full-on scoped hash table or repeated leader set walks)
if the DFS pair is stored next to leaders.
The dominator tree keeps them, and the DOM tree nodes expose them as public, but you have no guarantee they are up to date (and in fact,
if you split blocks or whatever during your pass, they definitely won't be)
This means passes either have to compute their own versions[1], or make 32 queries, or ....
Rather than try to hide this, i just made the API public, and make it do nothing if the numbers are already valid.
[1] Which we want as a non-recursive walk, which is not pretty, sadly,
because it cannot use the depth first iterators since you don't get called on the way back up. So you either have to do one walk with po_iterator
and one with df_iterator, or write your own non-recursive walk that looks identical to the one in updateDFSNumbers.
Reviewers: chandlerc
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D8946
llvm-svn: 234930
2015-04-14 21:09:16 +02:00
|
|
|
|
|
|
|
DomTreeNodeBase<NodeT> *getNodeForBlock(NodeT *BB) {
|
|
|
|
if (DomTreeNodeBase<NodeT> *Node = getNode(BB))
|
|
|
|
return Node;
|
|
|
|
|
|
|
|
// Haven't calculated this node yet? Get or calculate the node for the
|
|
|
|
// immediate dominator.
|
|
|
|
NodeT *IDom = getIDom(BB);
|
|
|
|
|
|
|
|
assert(IDom || this->DomTreeNodes[nullptr]);
|
|
|
|
DomTreeNodeBase<NodeT> *IDomNode = getNodeForBlock(IDom);
|
|
|
|
|
|
|
|
// Add a new tree node for this NodeT, and link it as a child of
|
|
|
|
// IDomNode
|
|
|
|
return (this->DomTreeNodes[BB] = IDomNode->addChild(
|
|
|
|
llvm::make_unique<DomTreeNodeBase<NodeT>>(BB, IDomNode))).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeT *getIDom(NodeT *BB) const { return IDoms.lookup(BB); }
|
|
|
|
|
|
|
|
void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
|
|
|
|
|
|
|
|
public:
|
2014-01-13 11:52:56 +01:00
|
|
|
/// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
|
|
|
|
/// dominator tree in dfs order.
|
2014-01-13 12:58:34 +01:00
|
|
|
void updateDFSNumbers() const {
|
2015-04-14 21:49:26 +02:00
|
|
|
|
|
|
|
if (DFSInfoValid) {
|
|
|
|
SlowQueries = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-13 11:52:56 +01:00
|
|
|
unsigned DFSNum = 0;
|
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
SmallVector<std::pair<const DomTreeNodeBase<NodeT> *,
|
|
|
|
typename DomTreeNodeBase<NodeT>::const_iterator>,
|
|
|
|
32> WorkStack;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2014-01-13 12:58:34 +01:00
|
|
|
const DomTreeNodeBase<NodeT> *ThisRoot = getRootNode();
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
if (!ThisRoot)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Even in the case of multiple exits that form the post dominator root
|
|
|
|
// nodes, do not iterate over all exits, but start from the virtual root
|
|
|
|
// node. Otherwise bbs, that are not post dominated by any exit but by the
|
|
|
|
// virtual root node, will never be assigned a DFS number.
|
|
|
|
WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin()));
|
|
|
|
ThisRoot->DFSNumIn = DFSNum++;
|
|
|
|
|
|
|
|
while (!WorkStack.empty()) {
|
2014-01-13 12:58:34 +01:00
|
|
|
const DomTreeNodeBase<NodeT> *Node = WorkStack.back().first;
|
|
|
|
typename DomTreeNodeBase<NodeT>::const_iterator ChildIt =
|
2015-01-14 04:56:00 +01:00
|
|
|
WorkStack.back().second;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
// If we visited all of the children of this node, "recurse" back up the
|
|
|
|
// stack setting the DFOutNum.
|
|
|
|
if (ChildIt == Node->end()) {
|
|
|
|
Node->DFSNumOut = DFSNum++;
|
|
|
|
WorkStack.pop_back();
|
|
|
|
} else {
|
|
|
|
// Otherwise, recursively visit this child.
|
2014-01-13 12:58:34 +01:00
|
|
|
const DomTreeNodeBase<NodeT> *Child = *ChildIt;
|
2014-01-13 11:52:56 +01:00
|
|
|
++WorkStack.back().second;
|
|
|
|
|
|
|
|
WorkStack.push_back(std::make_pair(Child, Child->begin()));
|
|
|
|
Child->DFSNumIn = DFSNum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SlowQueries = 0;
|
|
|
|
DFSInfoValid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// recalculate - compute a dominator tree for the given function
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class FT> void recalculate(FT &F) {
|
|
|
|
typedef GraphTraits<FT *> TraitsTy;
|
2014-01-13 11:52:56 +01:00
|
|
|
reset();
|
2014-04-09 08:08:46 +02:00
|
|
|
this->Vertex.push_back(nullptr);
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
if (!this->IsPostDominators) {
|
|
|
|
// Initialize root
|
|
|
|
NodeT *entry = TraitsTy::getEntryNode(&F);
|
|
|
|
this->Roots.push_back(entry);
|
2014-04-09 08:08:46 +02:00
|
|
|
this->IDoms[entry] = nullptr;
|
|
|
|
this->DomTreeNodes[entry] = nullptr;
|
2014-01-13 11:52:56 +01:00
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
Calculate<FT, NodeT *>(*this, F);
|
2014-01-13 11:52:56 +01:00
|
|
|
} else {
|
|
|
|
// Initialize the roots list
|
|
|
|
for (typename TraitsTy::nodes_iterator I = TraitsTy::nodes_begin(&F),
|
2015-01-14 04:56:00 +01:00
|
|
|
E = TraitsTy::nodes_end(&F);
|
|
|
|
I != E; ++I) {
|
2014-01-13 11:52:56 +01:00
|
|
|
if (TraitsTy::child_begin(I) == TraitsTy::child_end(I))
|
|
|
|
addRoot(I);
|
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
// Prepopulate maps so that we don't get iterator invalidation issues
|
|
|
|
// later.
|
2014-04-09 08:08:46 +02:00
|
|
|
this->IDoms[I] = nullptr;
|
|
|
|
this->DomTreeNodes[I] = nullptr;
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 04:56:00 +01:00
|
|
|
Calculate<FT, Inverse<NodeT *>>(*this, F);
|
2014-01-13 11:52:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// These two functions are declared out of line as a workaround for building
|
|
|
|
// with old (< r147295) versions of clang because of pr11642.
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class NodeT>
|
2014-01-13 12:58:34 +01:00
|
|
|
bool DominatorTreeBase<NodeT>::dominates(const NodeT *A, const NodeT *B) const {
|
2014-01-13 11:52:56 +01:00
|
|
|
if (A == B)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Cast away the const qualifiers here. This is ok since
|
|
|
|
// this function doesn't actually return the values returned
|
|
|
|
// from getNode.
|
|
|
|
return dominates(getNode(const_cast<NodeT *>(A)),
|
|
|
|
getNode(const_cast<NodeT *>(B)));
|
|
|
|
}
|
2015-01-14 04:56:00 +01:00
|
|
|
template <class NodeT>
|
|
|
|
bool DominatorTreeBase<NodeT>::properlyDominates(const NodeT *A,
|
|
|
|
const NodeT *B) const {
|
2014-01-13 11:52:56 +01:00
|
|
|
if (A == B)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Cast away the const qualifiers here. This is ok since
|
|
|
|
// this function doesn't actually return the values returned
|
|
|
|
// from getNode.
|
|
|
|
return dominates(getNode(const_cast<NodeT *>(A)),
|
|
|
|
getNode(const_cast<NodeT *>(B)));
|
|
|
|
}
|
|
|
|
|
2015-06-23 11:49:53 +02:00
|
|
|
}
|
2014-01-13 11:52:56 +01:00
|
|
|
|
|
|
|
#endif
|