1 //===- GenericDomTree.h - Generic dominator trees for graphs ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file defines a set of templates that efficiently compute a dominator
12 /// tree over a generic graph. This is used typically in LLVM for fast
13 /// dominance queries on the CFG, but is fully generic w.r.t. the underlying
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_SUPPORT_GENERICDOMTREE_H
19 #define LLVM_SUPPORT_GENERICDOMTREE_H
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/DepthFirstIterator.h"
23 #include "llvm/ADT/GraphTraits.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/ADT/SmallPtrSet.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/Support/Compiler.h"
28 #include "llvm/Support/raw_ostream.h"
33 /// \brief Base class that other, more interesting dominator analyses
35 template <class NodeT> class DominatorBase {
37 std::vector<NodeT *> Roots;
38 bool IsPostDominators;
39 explicit DominatorBase(bool isPostDom)
40 : Roots(), IsPostDominators(isPostDom) {}
41 DominatorBase(DominatorBase &&Arg)
42 : Roots(std::move(Arg.Roots)),
43 IsPostDominators(std::move(Arg.IsPostDominators)) {
46 DominatorBase &operator=(DominatorBase &&RHS) {
47 Roots = std::move(RHS.Roots);
48 IsPostDominators = std::move(RHS.IsPostDominators);
54 /// getRoots - Return the root blocks of the current CFG. This may include
55 /// multiple blocks if we are computing post dominators. For forward
56 /// dominators, this will always be a single block (the entry node).
58 const std::vector<NodeT *> &getRoots() const { return Roots; }
60 /// isPostDominator - Returns true if analysis based of postdoms
62 bool isPostDominator() const { return IsPostDominators; }
65 template <class NodeT> class DominatorTreeBase;
66 struct PostDominatorTree;
68 /// \brief Base class for the actual dominator tree node.
69 template <class NodeT> class DomTreeNodeBase {
71 DomTreeNodeBase<NodeT> *IDom;
72 std::vector<DomTreeNodeBase<NodeT> *> Children;
73 mutable int DFSNumIn, DFSNumOut;
75 template <class N> friend class DominatorTreeBase;
76 friend struct PostDominatorTree;
79 typedef typename std::vector<DomTreeNodeBase<NodeT> *>::iterator iterator;
80 typedef typename std::vector<DomTreeNodeBase<NodeT> *>::const_iterator
83 iterator begin() { return Children.begin(); }
84 iterator end() { return Children.end(); }
85 const_iterator begin() const { return Children.begin(); }
86 const_iterator end() const { return Children.end(); }
88 NodeT *getBlock() const { return TheBB; }
89 DomTreeNodeBase<NodeT> *getIDom() const { return IDom; }
90 const std::vector<DomTreeNodeBase<NodeT> *> &getChildren() const {
94 DomTreeNodeBase(NodeT *BB, DomTreeNodeBase<NodeT> *iDom)
95 : TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) {}
97 std::unique_ptr<DomTreeNodeBase<NodeT>>
98 addChild(std::unique_ptr<DomTreeNodeBase<NodeT>> C) {
99 Children.push_back(C.get());
103 size_t getNumChildren() const { return Children.size(); }
105 void clearAllChildren() { Children.clear(); }
107 bool compare(const DomTreeNodeBase<NodeT> *Other) const {
108 if (getNumChildren() != Other->getNumChildren())
111 SmallPtrSet<const NodeT *, 4> OtherChildren;
112 for (const DomTreeNodeBase *I : *Other) {
113 const NodeT *Nd = I->getBlock();
114 OtherChildren.insert(Nd);
117 for (const DomTreeNodeBase *I : *this) {
118 const NodeT *N = I->getBlock();
119 if (OtherChildren.count(N) == 0)
125 void setIDom(DomTreeNodeBase<NodeT> *NewIDom) {
126 assert(IDom && "No immediate dominator?");
127 if (IDom != NewIDom) {
128 typename std::vector<DomTreeNodeBase<NodeT> *>::iterator I =
129 std::find(IDom->Children.begin(), IDom->Children.end(), this);
130 assert(I != IDom->Children.end() &&
131 "Not in immediate dominator children set!");
132 // I am no longer your child...
133 IDom->Children.erase(I);
135 // Switch to new dominator
137 IDom->Children.push_back(this);
141 /// getDFSNumIn/getDFSNumOut - These return the DFS visitation order for nodes
142 /// in the dominator tree. They are only guaranteed valid if
143 /// updateDFSNumbers() has been called.
144 unsigned getDFSNumIn() const { return DFSNumIn; }
145 unsigned getDFSNumOut() const { return DFSNumOut; }
148 // Return true if this node is dominated by other. Use this only if DFS info
150 bool DominatedBy(const DomTreeNodeBase<NodeT> *other) const {
151 return this->DFSNumIn >= other->DFSNumIn &&
152 this->DFSNumOut <= other->DFSNumOut;
156 template <class NodeT>
157 raw_ostream &operator<<(raw_ostream &o, const DomTreeNodeBase<NodeT> *Node) {
158 if (Node->getBlock())
159 Node->getBlock()->printAsOperand(o, false);
161 o << " <<exit node>>";
163 o << " {" << Node->getDFSNumIn() << "," << Node->getDFSNumOut() << "}";
168 template <class NodeT>
169 void PrintDomTree(const DomTreeNodeBase<NodeT> *N, raw_ostream &o,
171 o.indent(2 * Lev) << "[" << Lev << "] " << N;
172 for (typename DomTreeNodeBase<NodeT>::const_iterator I = N->begin(),
175 PrintDomTree<NodeT>(*I, o, Lev + 1);
178 // The calculate routine is provided in a separate header but referenced here.
179 template <class FuncT, class N>
180 void Calculate(DominatorTreeBase<typename GraphTraits<N>::NodeType> &DT,
183 /// \brief Core dominator tree base class.
185 /// This class is a generic template over graph nodes. It is instantiated for
186 /// various graphs in the LLVM IR or in the code generator.
187 template <class NodeT> class DominatorTreeBase : public DominatorBase<NodeT> {
188 DominatorTreeBase(const DominatorTreeBase &) = delete;
189 DominatorTreeBase &operator=(const DominatorTreeBase &) = delete;
191 bool dominatedBySlowTreeWalk(const DomTreeNodeBase<NodeT> *A,
192 const DomTreeNodeBase<NodeT> *B) const {
194 assert(isReachableFromEntry(B));
195 assert(isReachableFromEntry(A));
197 const DomTreeNodeBase<NodeT> *IDom;
198 while ((IDom = B->getIDom()) != nullptr && IDom != A && IDom != B)
199 B = IDom; // Walk up the tree
200 return IDom != nullptr;
203 /// \brief Wipe this tree's state without releasing any resources.
205 /// This is essentially a post-move helper only. It leaves the object in an
206 /// assignable and destroyable state, but otherwise invalid.
208 DomTreeNodes.clear();
216 typedef DenseMap<NodeT *, std::unique_ptr<DomTreeNodeBase<NodeT>>>
218 DomTreeNodeMapType DomTreeNodes;
219 DomTreeNodeBase<NodeT> *RootNode;
221 mutable bool DFSInfoValid;
222 mutable unsigned int SlowQueries;
223 // Information record used during immediate dominators computation.
230 InfoRec() : DFSNum(0), Parent(0), Semi(0), Label(nullptr) {}
233 DenseMap<NodeT *, NodeT *> IDoms;
235 // Vertex - Map the DFS number to the NodeT*
236 std::vector<NodeT *> Vertex;
238 // Info - Collection of information used during the computation of idoms.
239 DenseMap<NodeT *, InfoRec> Info;
242 DomTreeNodes.clear();
247 DFSInfoValid = false;
251 // NewBB is split and now it has one successor. Update dominator tree to
252 // reflect this change.
253 template <class N, class GraphT>
254 void Split(DominatorTreeBase<typename GraphT::NodeType> &DT,
255 typename GraphT::NodeType *NewBB) {
256 assert(std::distance(GraphT::child_begin(NewBB),
257 GraphT::child_end(NewBB)) == 1 &&
258 "NewBB should have a single successor!");
259 typename GraphT::NodeType *NewBBSucc = *GraphT::child_begin(NewBB);
261 std::vector<typename GraphT::NodeType *> PredBlocks;
262 typedef GraphTraits<Inverse<N>> InvTraits;
263 for (typename InvTraits::ChildIteratorType
264 PI = InvTraits::child_begin(NewBB),
265 PE = InvTraits::child_end(NewBB);
267 PredBlocks.push_back(*PI);
269 assert(!PredBlocks.empty() && "No predblocks?");
271 bool NewBBDominatesNewBBSucc = true;
272 for (typename InvTraits::ChildIteratorType
273 PI = InvTraits::child_begin(NewBBSucc),
274 E = InvTraits::child_end(NewBBSucc);
276 typename InvTraits::NodeType *ND = *PI;
277 if (ND != NewBB && !DT.dominates(NewBBSucc, ND) &&
278 DT.isReachableFromEntry(ND)) {
279 NewBBDominatesNewBBSucc = false;
284 // Find NewBB's immediate dominator and create new dominator tree node for
286 NodeT *NewBBIDom = nullptr;
288 for (i = 0; i < PredBlocks.size(); ++i)
289 if (DT.isReachableFromEntry(PredBlocks[i])) {
290 NewBBIDom = PredBlocks[i];
294 // It's possible that none of the predecessors of NewBB are reachable;
295 // in that case, NewBB itself is unreachable, so nothing needs to be
300 for (i = i + 1; i < PredBlocks.size(); ++i) {
301 if (DT.isReachableFromEntry(PredBlocks[i]))
302 NewBBIDom = DT.findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
305 // Create the new dominator tree node... and set the idom of NewBB.
306 DomTreeNodeBase<NodeT> *NewBBNode = DT.addNewBlock(NewBB, NewBBIDom);
308 // If NewBB strictly dominates other blocks, then it is now the immediate
309 // dominator of NewBBSucc. Update the dominator tree as appropriate.
310 if (NewBBDominatesNewBBSucc) {
311 DomTreeNodeBase<NodeT> *NewBBSuccNode = DT.getNode(NewBBSucc);
312 DT.changeImmediateDominator(NewBBSuccNode, NewBBNode);
317 explicit DominatorTreeBase(bool isPostDom)
318 : DominatorBase<NodeT>(isPostDom), DFSInfoValid(false), SlowQueries(0) {}
320 DominatorTreeBase(DominatorTreeBase &&Arg)
321 : DominatorBase<NodeT>(
322 std::move(static_cast<DominatorBase<NodeT> &>(Arg))),
323 DomTreeNodes(std::move(Arg.DomTreeNodes)),
324 RootNode(std::move(Arg.RootNode)),
325 DFSInfoValid(std::move(Arg.DFSInfoValid)),
326 SlowQueries(std::move(Arg.SlowQueries)), IDoms(std::move(Arg.IDoms)),
327 Vertex(std::move(Arg.Vertex)), Info(std::move(Arg.Info)) {
330 DominatorTreeBase &operator=(DominatorTreeBase &&RHS) {
331 DominatorBase<NodeT>::operator=(
332 std::move(static_cast<DominatorBase<NodeT> &>(RHS)));
333 DomTreeNodes = std::move(RHS.DomTreeNodes);
334 RootNode = std::move(RHS.RootNode);
335 DFSInfoValid = std::move(RHS.DFSInfoValid);
336 SlowQueries = std::move(RHS.SlowQueries);
337 IDoms = std::move(RHS.IDoms);
338 Vertex = std::move(RHS.Vertex);
339 Info = std::move(RHS.Info);
344 /// compare - Return false if the other dominator tree base matches this
345 /// dominator tree base. Otherwise return true.
346 bool compare(const DominatorTreeBase &Other) const {
348 const DomTreeNodeMapType &OtherDomTreeNodes = Other.DomTreeNodes;
349 if (DomTreeNodes.size() != OtherDomTreeNodes.size())
352 for (const auto &DomTreeNode : this->DomTreeNodes) {
353 NodeT *BB = DomTreeNode.first;
354 typename DomTreeNodeMapType::const_iterator OI =
355 OtherDomTreeNodes.find(BB);
356 if (OI == OtherDomTreeNodes.end())
359 DomTreeNodeBase<NodeT> &MyNd = *DomTreeNode.second;
360 DomTreeNodeBase<NodeT> &OtherNd = *OI->second;
362 if (MyNd.compare(&OtherNd))
369 void releaseMemory() { reset(); }
371 /// getNode - return the (Post)DominatorTree node for the specified basic
372 /// block. This is the same as using operator[] on this class. The result
373 /// may (but is not required to) be null for a forward (backwards)
374 /// statically unreachable block.
375 DomTreeNodeBase<NodeT> *getNode(NodeT *BB) const {
376 auto I = DomTreeNodes.find(BB);
377 if (I != DomTreeNodes.end())
378 return I->second.get();
383 DomTreeNodeBase<NodeT> *operator[](NodeT *BB) const { return getNode(BB); }
385 /// getRootNode - This returns the entry node for the CFG of the function. If
386 /// this tree represents the post-dominance relations for a function, however,
387 /// this root may be a node with the block == NULL. This is the case when
388 /// there are multiple exit nodes from a particular function. Consumers of
389 /// post-dominance information must be capable of dealing with this
392 DomTreeNodeBase<NodeT> *getRootNode() { return RootNode; }
393 const DomTreeNodeBase<NodeT> *getRootNode() const { return RootNode; }
395 /// Get all nodes dominated by R, including R itself.
396 void getDescendants(NodeT *R, SmallVectorImpl<NodeT *> &Result) const {
398 const DomTreeNodeBase<NodeT> *RN = getNode(R);
400 return; // If R is unreachable, it will not be present in the DOM tree.
401 SmallVector<const DomTreeNodeBase<NodeT> *, 8> WL;
404 while (!WL.empty()) {
405 const DomTreeNodeBase<NodeT> *N = WL.pop_back_val();
406 Result.push_back(N->getBlock());
407 WL.append(N->begin(), N->end());
411 /// properlyDominates - Returns true iff A dominates B and A != B.
412 /// Note that this is not a constant time operation!
414 bool properlyDominates(const DomTreeNodeBase<NodeT> *A,
415 const DomTreeNodeBase<NodeT> *B) const {
420 return dominates(A, B);
423 bool properlyDominates(const NodeT *A, const NodeT *B) const;
425 /// isReachableFromEntry - Return true if A is dominated by the entry
426 /// block of the function containing it.
427 bool isReachableFromEntry(const NodeT *A) const {
428 assert(!this->isPostDominator() &&
429 "This is not implemented for post dominators");
430 return isReachableFromEntry(getNode(const_cast<NodeT *>(A)));
433 bool isReachableFromEntry(const DomTreeNodeBase<NodeT> *A) const { return A; }
435 /// dominates - Returns true iff A dominates B. Note that this is not a
436 /// constant time operation!
438 bool dominates(const DomTreeNodeBase<NodeT> *A,
439 const DomTreeNodeBase<NodeT> *B) const {
440 // A node trivially dominates itself.
444 // An unreachable node is dominated by anything.
445 if (!isReachableFromEntry(B))
448 // And dominates nothing.
449 if (!isReachableFromEntry(A))
452 // Compare the result of the tree walk and the dfs numbers, if expensive
453 // checks are enabled.
454 #ifdef EXPENSIVE_CHECKS
455 assert((!DFSInfoValid ||
456 (dominatedBySlowTreeWalk(A, B) == B->DominatedBy(A))) &&
457 "Tree walk disagrees with dfs numbers!");
461 return B->DominatedBy(A);
463 // If we end up with too many slow queries, just update the
464 // DFS numbers on the theory that we are going to keep querying.
466 if (SlowQueries > 32) {
468 return B->DominatedBy(A);
471 return dominatedBySlowTreeWalk(A, B);
474 bool dominates(const NodeT *A, const NodeT *B) const;
476 NodeT *getRoot() const {
477 assert(this->Roots.size() == 1 && "Should always have entry node!");
478 return this->Roots[0];
481 /// findNearestCommonDominator - Find nearest common dominator basic block
482 /// for basic block A and B. If there is no such block then return NULL.
483 NodeT *findNearestCommonDominator(NodeT *A, NodeT *B) {
484 assert(A->getParent() == B->getParent() &&
485 "Two blocks are not in same function");
487 // If either A or B is a entry block then it is nearest common dominator
488 // (for forward-dominators).
489 if (!this->isPostDominator()) {
490 NodeT &Entry = A->getParent()->front();
491 if (A == &Entry || B == &Entry)
495 // If B dominates A then B is nearest common dominator.
499 // If A dominates B then A is nearest common dominator.
503 DomTreeNodeBase<NodeT> *NodeA = getNode(A);
504 DomTreeNodeBase<NodeT> *NodeB = getNode(B);
506 // If we have DFS info, then we can avoid all allocations by just querying
507 // it from each IDom. Note that because we call 'dominates' twice above, we
508 // expect to call through this code at most 16 times in a row without
509 // building valid DFS information. This is important as below is a *very*
512 DomTreeNodeBase<NodeT> *IDomA = NodeA->getIDom();
514 if (NodeB->DominatedBy(IDomA))
515 return IDomA->getBlock();
516 IDomA = IDomA->getIDom();
521 // Collect NodeA dominators set.
522 SmallPtrSet<DomTreeNodeBase<NodeT> *, 16> NodeADoms;
523 NodeADoms.insert(NodeA);
524 DomTreeNodeBase<NodeT> *IDomA = NodeA->getIDom();
526 NodeADoms.insert(IDomA);
527 IDomA = IDomA->getIDom();
530 // Walk NodeB immediate dominators chain and find common dominator node.
531 DomTreeNodeBase<NodeT> *IDomB = NodeB->getIDom();
533 if (NodeADoms.count(IDomB) != 0)
534 return IDomB->getBlock();
536 IDomB = IDomB->getIDom();
542 const NodeT *findNearestCommonDominator(const NodeT *A, const NodeT *B) {
543 // Cast away the const qualifiers here. This is ok since
544 // const is re-introduced on the return type.
545 return findNearestCommonDominator(const_cast<NodeT *>(A),
546 const_cast<NodeT *>(B));
549 //===--------------------------------------------------------------------===//
550 // API to update (Post)DominatorTree information based on modifications to
553 /// addNewBlock - Add a new node to the dominator tree information. This
554 /// creates a new node as a child of DomBB dominator node,linking it into
555 /// the children list of the immediate dominator.
556 DomTreeNodeBase<NodeT> *addNewBlock(NodeT *BB, NodeT *DomBB) {
557 assert(getNode(BB) == nullptr && "Block already in dominator tree!");
558 DomTreeNodeBase<NodeT> *IDomNode = getNode(DomBB);
559 assert(IDomNode && "Not immediate dominator specified for block!");
560 DFSInfoValid = false;
561 return (DomTreeNodes[BB] = IDomNode->addChild(
562 llvm::make_unique<DomTreeNodeBase<NodeT>>(BB, IDomNode))).get();
565 /// changeImmediateDominator - This method is used to update the dominator
566 /// tree information when a node's immediate dominator changes.
568 void changeImmediateDominator(DomTreeNodeBase<NodeT> *N,
569 DomTreeNodeBase<NodeT> *NewIDom) {
570 assert(N && NewIDom && "Cannot change null node pointers!");
571 DFSInfoValid = false;
575 void changeImmediateDominator(NodeT *BB, NodeT *NewBB) {
576 changeImmediateDominator(getNode(BB), getNode(NewBB));
579 /// eraseNode - Removes a node from the dominator tree. Block must not
580 /// dominate any other blocks. Removes node from its immediate dominator's
581 /// children list. Deletes dominator node associated with basic block BB.
582 void eraseNode(NodeT *BB) {
583 DomTreeNodeBase<NodeT> *Node = getNode(BB);
584 assert(Node && "Removing node that isn't in dominator tree.");
585 assert(Node->getChildren().empty() && "Node is not a leaf node.");
587 // Remove node from immediate dominator's children list.
588 DomTreeNodeBase<NodeT> *IDom = Node->getIDom();
590 typename std::vector<DomTreeNodeBase<NodeT> *>::iterator I =
591 std::find(IDom->Children.begin(), IDom->Children.end(), Node);
592 assert(I != IDom->Children.end() &&
593 "Not in immediate dominator children set!");
594 // I am no longer your child...
595 IDom->Children.erase(I);
598 DomTreeNodes.erase(BB);
601 /// splitBlock - BB is split and now it has one successor. Update dominator
602 /// tree to reflect this change.
603 void splitBlock(NodeT *NewBB) {
604 if (this->IsPostDominators)
605 this->Split<Inverse<NodeT *>, GraphTraits<Inverse<NodeT *>>>(*this,
608 this->Split<NodeT *, GraphTraits<NodeT *>>(*this, NewBB);
611 /// print - Convert to human readable form
613 void print(raw_ostream &o) const {
614 o << "=============================--------------------------------\n";
615 if (this->isPostDominator())
616 o << "Inorder PostDominator Tree: ";
618 o << "Inorder Dominator Tree: ";
619 if (!this->DFSInfoValid)
620 o << "DFSNumbers invalid: " << SlowQueries << " slow queries.";
623 // The postdom tree can have a null root if there are no returns.
625 PrintDomTree<NodeT>(getRootNode(), o, 1);
629 template <class GraphT>
630 friend typename GraphT::NodeType *
631 Eval(DominatorTreeBase<typename GraphT::NodeType> &DT,
632 typename GraphT::NodeType *V, unsigned LastLinked);
634 template <class GraphT>
635 friend unsigned DFSPass(DominatorTreeBase<typename GraphT::NodeType> &DT,
636 typename GraphT::NodeType *V, unsigned N);
638 template <class FuncT, class N>
640 Calculate(DominatorTreeBase<typename GraphTraits<N>::NodeType> &DT, FuncT &F);
643 DomTreeNodeBase<NodeT> *getNodeForBlock(NodeT *BB) {
644 if (DomTreeNodeBase<NodeT> *Node = getNode(BB))
647 // Haven't calculated this node yet? Get or calculate the node for the
648 // immediate dominator.
649 NodeT *IDom = getIDom(BB);
651 assert(IDom || this->DomTreeNodes[nullptr]);
652 DomTreeNodeBase<NodeT> *IDomNode = getNodeForBlock(IDom);
654 // Add a new tree node for this NodeT, and link it as a child of
656 return (this->DomTreeNodes[BB] = IDomNode->addChild(
657 llvm::make_unique<DomTreeNodeBase<NodeT>>(BB, IDomNode))).get();
660 NodeT *getIDom(NodeT *BB) const { return IDoms.lookup(BB); }
662 void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
665 /// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
666 /// dominator tree in dfs order.
667 void updateDFSNumbers() const {
676 SmallVector<std::pair<const DomTreeNodeBase<NodeT> *,
677 typename DomTreeNodeBase<NodeT>::const_iterator>,
680 const DomTreeNodeBase<NodeT> *ThisRoot = getRootNode();
685 // Even in the case of multiple exits that form the post dominator root
686 // nodes, do not iterate over all exits, but start from the virtual root
687 // node. Otherwise bbs, that are not post dominated by any exit but by the
688 // virtual root node, will never be assigned a DFS number.
689 WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin()));
690 ThisRoot->DFSNumIn = DFSNum++;
692 while (!WorkStack.empty()) {
693 const DomTreeNodeBase<NodeT> *Node = WorkStack.back().first;
694 typename DomTreeNodeBase<NodeT>::const_iterator ChildIt =
695 WorkStack.back().second;
697 // If we visited all of the children of this node, "recurse" back up the
698 // stack setting the DFOutNum.
699 if (ChildIt == Node->end()) {
700 Node->DFSNumOut = DFSNum++;
701 WorkStack.pop_back();
703 // Otherwise, recursively visit this child.
704 const DomTreeNodeBase<NodeT> *Child = *ChildIt;
705 ++WorkStack.back().second;
707 WorkStack.push_back(std::make_pair(Child, Child->begin()));
708 Child->DFSNumIn = DFSNum++;
716 /// recalculate - compute a dominator tree for the given function
717 template <class FT> void recalculate(FT &F) {
718 typedef GraphTraits<FT *> TraitsTy;
720 this->Vertex.push_back(nullptr);
722 if (!this->IsPostDominators) {
724 NodeT *entry = TraitsTy::getEntryNode(&F);
727 Calculate<FT, NodeT *>(*this, F);
729 // Initialize the roots list
730 for (typename TraitsTy::nodes_iterator I = TraitsTy::nodes_begin(&F),
731 E = TraitsTy::nodes_end(&F);
733 if (TraitsTy::child_begin(&*I) == TraitsTy::child_end(&*I))
736 Calculate<FT, Inverse<NodeT *>>(*this, F);
741 // These two functions are declared out of line as a workaround for building
742 // with old (< r147295) versions of clang because of pr11642.
743 template <class NodeT>
744 bool DominatorTreeBase<NodeT>::dominates(const NodeT *A, const NodeT *B) const {
748 // Cast away the const qualifiers here. This is ok since
749 // this function doesn't actually return the values returned
751 return dominates(getNode(const_cast<NodeT *>(A)),
752 getNode(const_cast<NodeT *>(B)));
754 template <class NodeT>
755 bool DominatorTreeBase<NodeT>::properlyDominates(const NodeT *A,
756 const NodeT *B) const {
760 // Cast away the const qualifiers here. This is ok since
761 // this function doesn't actually return the values returned
763 return dominates(getNode(const_cast<NodeT *>(A)),
764 getNode(const_cast<NodeT *>(B)));