25 #ifndef LLVM_SUPPORT_GENERICDOMTREECONSTRUCTION_H
26 #define LLVM_SUPPORT_GENERICDOMTREECONSTRUCTION_H
33 template<
class GraphT>
41 VInfo.DFSNum = VInfo.Semi = ++
N;
47 InfoRec &SuccVInfo = DT.
Info[*
SI];
48 if (SuccVInfo.Semi == 0) {
50 N = DTDFSPass(DT, *
SI, N);
54 bool IsChildOfArtificialExit = (N != 0);
57 typename GraphT::ChildIteratorType>, 32> Worklist;
58 Worklist.push_back(std::make_pair(V, GraphT::child_begin(V)));
59 while (!Worklist.empty()) {
60 typename GraphT::NodeType* BB = Worklist.back().first;
61 typename GraphT::ChildIteratorType NextSucc = Worklist.back().second;
67 if (NextSucc == GraphT::child_begin(BB)) {
73 if (IsChildOfArtificialExit)
76 IsChildOfArtificialExit =
false;
81 unsigned BBDFSNum = BBInfo.
DFSNum;
84 if (NextSucc == GraphT::child_end(BB)) {
90 ++Worklist.back().second;
93 typename GraphT::NodeType* Succ = *NextSucc;
97 if (SuccVInfo.
Semi == 0) {
98 SuccVInfo.
Parent = BBDFSNum;
99 Worklist.push_back(std::make_pair(Succ, GraphT::child_begin(Succ)));
106 template<
class GraphT>
112 if (VInInfo.
DFSNum < LastLinked)
118 if (VInInfo.
Parent >= LastLinked)
121 while (!Work.
empty()) {
128 if (Visited.
insert(VAncestor).second && VInfo.
Parent >= LastLinked) {
135 if (VInfo.
Parent < LastLinked)
142 if (DT.
Info[VAncestorLabel].Semi < DT.
Info[VLabel].Semi)
143 VInfo.
Label = VAncestorLabel;
147 return VInInfo.
Label;
150 template<
class FuncT,
class NodeT>
156 bool MultipleRoots = (DT.Roots.size() > 1);
161 BBInfo.
Label =
nullptr;
163 DT.Vertex.push_back(
nullptr);
168 for (
unsigned i = 0, e = static_cast<unsigned>(DT.Roots.size());
170 N = DFSPass<GraphT>(DT, DT.Roots[i], N);
188 for (
unsigned i = 1; i <=
N; ++i)
191 for (
unsigned i = N; i >= 2; --i) {
197 for (
unsigned j = i; Buckets[j] != i; j = Buckets[j]) {
200 DT.IDoms[V] = DT.Info[U].Semi < i ? U : W;
208 for (
typename InvTraits::ChildIteratorType CI =
209 InvTraits::child_begin(W),
210 E = InvTraits::child_end(W); CI != E; ++CI) {
212 if (DT.Info.count(N)) {
213 unsigned SemiU = DT.Info[Eval<GraphT>(DT,
N, i + 1)].Semi;
214 if (SemiU < WInfo.
Semi)
223 DT.IDoms[W] = DT.Vertex[WInfo.
Parent];
225 Buckets[i] = Buckets[WInfo.
Semi];
226 Buckets[WInfo.
Semi] = i;
232 for (
unsigned j = 1; Buckets[j] != 1; j = Buckets[j]) {
239 for (
unsigned i = 2; i <=
N; ++i) {
242 if (WIDom != DT.Vertex[DT.Info[W].Semi])
243 WIDom = DT.IDoms[WIDom];
246 if (DT.Roots.empty())
return;
255 (DT.DomTreeNodes[Root] =
256 llvm::make_unique<DomTreeNodeBase<typename GraphT::NodeType>>(
257 Root,
nullptr)).get();
260 for (
unsigned i = 2; i <=
N; ++i) {
264 if (DT.DomTreeNodes[W])
269 assert(ImmDom || DT.DomTreeNodes[
nullptr]);
273 DT.getNodeForBlock(ImmDom);
277 DT.DomTreeNodes[W] = IDomNode->
addChild(
286 DT.Vertex.shrink_to_fit();
288 DT.updateDFSNumbers();
std::vector< NodeT * > Roots
void push_back(const T &Elt)
unsigned DFSPass(DominatorTreeBase< typename GraphT::NodeType > &DT, typename GraphT::NodeType *V, unsigned N)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Base class for the actual dominator tree node.
Interval::succ_iterator succ_end(Interval *I)
Core dominator tree base class.
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
std::vector< NodeT * > Vertex
std::unique_ptr< DomTreeNodeBase< NodeT > > addChild(std::unique_ptr< DomTreeNodeBase< NodeT >> C)
DenseMap< NodeT *, InfoRec > Info
void Calculate(DominatorTreeBase< typename GraphTraits< N >::NodeType > &DT, FuncT &F)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
GraphType::UnknownGraphTypeError NodeType
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
GraphT::NodeType * Eval(DominatorTreeBase< typename GraphT::NodeType > &DT, typename GraphT::NodeType *VIn, unsigned LastLinked)
This file defines a set of templates that efficiently compute a dominator tree over a generic graph...