llvm.org GIT mirror llvm / cb10552
[Dominators] Make IsPostDominator a template parameter Summary: DominatorTreeBase used to have IsPostDominators (bool) member to indicate if the tree is a dominator or a postdominator tree. This made it possible to switch between the two 'modes' at runtime, but it isn't used in practice anywhere. This patch makes IsPostDominator a template argument. This way, it is easier to switch between different algorithms at compile-time based on this argument and design external utilities around it. It also makes it impossible to incidentally assign a postdominator tree to a dominator tree (and vice versa), and to further simplify template code in GenericDominatorTreeConstruction. Reviewers: dberlin, sanjoy, davide, grosser Reviewed By: dberlin Subscribers: mzolotukhin, llvm-commits Differential Revision: https://reviews.llvm.org/D35315 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308040 91177308-0d34-0410-b5e6-96231b3b80d8 Jakub Kuderski 2 years ago
21 changed file(s) with 178 addition(s) and 154 deletion(s). Raw diff Collapse all Expand all
2828 /// DominanceFrontierBase - Common base class for computing forward and inverse
2929 /// dominance frontiers for a function.
3030 ///
31 template >
31 template , bool IsPostDom>
3232 class DominanceFrontierBase {
33 public:
33 public:
3434 typedef std::set DomSetType; // Dom set for a bb
3535 typedef std::map DomSetMapType; // Dom set map
3636
3939
4040 DomSetMapType Frontiers;
4141 std::vector Roots;
42 const bool IsPostDominators;
43
44 public:
45 DominanceFrontierBase(bool isPostDom) : IsPostDominators(isPostDom) {}
42 static constexpr bool IsPostDominators = IsPostDom;
43
44 public:
45 DominanceFrontierBase() = default;
4646
4747 /// getRoots - Return the root blocks of the current CFG. This may include
4848 /// multiple blocks if we are computing post dominators. For forward
9595
9696 /// compare - Return true if the other dominance frontier base matches
9797 /// this dominance frontier base. Otherwise return false.
98 bool compare(DominanceFrontierBase &Other) const;
98 bool compare(DominanceFrontierBase &Other) const;
9999
100100 /// print - Convert to human readable form
101101 ///
112112 /// used to compute a forward dominator frontiers.
113113 ///
114114 template
115 class ForwardDominanceFrontierBase : public DominanceFrontierBase {
116 private:
115 class ForwardDominanceFrontierBase
116 : public DominanceFrontierBase {
117 private:
117118 typedef GraphTraits BlockTraits;
118119
119120 public:
120 typedef DominatorTreeBase DomTreeT;
121 typedef DomTreeNodeBase DomTreeNodeT;
122 typedef typename DominanceFrontierBase::DomSetType DomSetType;
123
124 ForwardDominanceFrontierBase() : DominanceFrontierBase(false) {}
125
126 void analyze(DomTreeT &DT) {
127 this->Roots = DT.getRoots();
128 assert(this->Roots.size() == 1 &&
129 "Only one entry block for forward domfronts!");
130 calculate(DT, DT[this->Roots[0]]);
121 typedef DomTreeBase DomTreeT;
122 typedef DomTreeNodeBase DomTreeNodeT;
123 typedef typename DominanceFrontierBase::DomSetType DomSetType;
124
125 void analyze(DomTreeT &DT) {
126 this->Roots = DT.getRoots();
127 assert(this->Roots.size() == 1 &&
128 "Only one entry block for forward domfronts!");
129 calculate(DT, DT[this->Roots[0]]);
131130 }
132131
133132 const DomSetType &calculate(const DomTreeT &DT, const DomTreeNodeT *Node);
135134
136135 class DominanceFrontier : public ForwardDominanceFrontierBase {
137136 public:
138 typedef DominatorTreeBase DomTreeT;
139 typedef DomTreeNodeBase DomTreeNodeT;
140 typedef DominanceFrontierBase::DomSetType DomSetType;
141 typedef DominanceFrontierBase::iterator iterator;
142 typedef DominanceFrontierBase::const_iterator const_iterator;
143
144 /// Handle invalidation explicitly.
145 bool invalidate(Function &F, const PreservedAnalyses &PA,
146 FunctionAnalysisManager::Invalidator &);
137 typedef DomTreeBase DomTreeT;
138 typedef DomTreeNodeBase DomTreeNodeT;
139 typedef DominanceFrontierBase::DomSetType DomSetType;
140 typedef DominanceFrontierBase::iterator iterator;
141 typedef DominanceFrontierBase::const_iterator
142 const_iterator;
143
144 /// Handle invalidation explicitly.
145 bool invalidate(Function &F, const PreservedAnalyses &PA,
146 FunctionAnalysisManager::Invalidator &);
147147 };
148148
149149 class DominanceFrontierWrapperPass : public FunctionPass {
167167 void dump() const;
168168 };
169169
170 extern template class DominanceFrontierBase>;
170 extern template class DominanceFrontierBase, false>;
171 extern template class DominanceFrontierBase;
171172 extern template class ForwardDominanceFrontierBase;
172173
173174 /// \brief Analysis pass which computes a \c DominanceFrontier.
3838 const DomTreeNodeT *parentNode;
3939 };
4040
41 template
42 void DominanceFrontierBase::removeBlock(BlockT *BB) {
41 template
42 void DominanceFrontierBase::removeBlock(BlockT *BB) {
4343 assert(find(BB) != end() && "Block is not in DominanceFrontier!");
4444 for (iterator I = begin(), E = end(); I != E; ++I)
4545 I->second.erase(BB);
4646 Frontiers.erase(BB);
4747 }
4848
49 template
50 void DominanceFrontierBase::addToFrontier(iterator I,
51 BlockT *Node) {
49 template
50 void DominanceFrontierBase::addToFrontier(iterator I,
51 BlockT *Node) {
5252 assert(I != end() && "BB is not in DominanceFrontier!");
5353 assert(I->second.count(Node) && "Node is not in DominanceFrontier of BB");
5454 I->second.erase(Node);
5555 }
5656
57 template
58 void DominanceFrontierBase::removeFromFrontier(iterator I,
59 BlockT *Node) {
57 template
58 void DominanceFrontierBase::removeFromFrontier(
59 iterator I, BlockT *Node) {
6060 assert(I != end() && "BB is not in DominanceFrontier!");
6161 assert(I->second.count(Node) && "Node is not in DominanceFrontier of BB");
6262 I->second.erase(Node);
6363 }
6464
65 template
66 bool DominanceFrontierBase::compareDomSet(DomSetType &DS1,
67 const DomSetType &DS2) const {
65 template
66 bool DominanceFrontierBase::compareDomSet(
67 DomSetType &DS1, const DomSetType &DS2) const {
6868 std::set tmpSet;
6969 for (BlockT *BB : DS2)
7070 tmpSet.insert(BB);
8787 return false;
8888 }
8989
90 template
91 bool DominanceFrontierBase::compare(
92 DominanceFrontierBase &Other) const {
90 template
91 bool DominanceFrontierBase::compare(
92 DominanceFrontierBase &Other) const {
9393 DomSetMapType tmpFrontiers;
9494 for (typename DomSetMapType::const_iterator I = Other.begin(),
9595 E = Other.end();
117117 return false;
118118 }
119119
120 template
121 void DominanceFrontierBase::print(raw_ostream &OS) const {
120 template
121 void DominanceFrontierBase::print(raw_ostream &OS) const {
122122 for (const_iterator I = begin(), E = end(); I != E; ++I) {
123123 OS << " DomFrontier for BB ";
124124 if (I->first)
141141 }
142142
143143 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
144 template
145 void DominanceFrontierBase::dump() const {
144 template
145 void DominanceFrontierBase::dump() const {
146146 print(dbgs());
147147 }
148148 #endif
4141 /// By default, liveness is not used to prune the IDF computation.
4242 /// The template parameters should be either BasicBlock* or Inverse
4343 /// *>, depending on if you want the forward or reverse IDF.
44 template >
44 template , bool IsPostDom>
4545 class IDFCalculator {
46
47 public:
48 IDFCalculator(DominatorTreeBase &DT) : DT(DT), useLiveIn(false) {}
46 public:
47 IDFCalculator(DominatorTreeBase &DT)
48 : DT(DT), useLiveIn(false) {}
4949
5050 /// \brief Give the IDF calculator the set of blocks in which the value is
5151 /// defined. This is equivalent to the set of starting blocks it should be
8383 void calculate(SmallVectorImpl &IDFBlocks);
8484
8585 private:
86 DominatorTreeBase &DT;
87 bool useLiveIn;
88 const SmallPtrSetImpl *LiveInBlocks;
89 const SmallPtrSetImpl *DefBlocks;
86 DominatorTreeBase &DT;
87 bool useLiveIn;
88 const SmallPtrSetImpl *LiveInBlocks;
89 const SmallPtrSetImpl *DefBlocks;
9090 };
91 typedef IDFCalculator ForwardIDFCalculator;
92 typedef IDFCalculator<Inverse> ReverseIDFCalculator;
91 typedef IDFCalculator<BasicBlock *, false> ForwardIDFCalculator;
92 typedef IDFCalculator, true> ReverseIDFCalculator;
9393 }
9494 #endif
5555 class MDNode;
5656 class PHINode;
5757 class raw_ostream;
58 template class DominatorTreeBase;
58 template
59 class DominatorTreeBase;
5960 template class LoopInfoBase;
6061 template class LoopBase;
6162
662663 }
663664
664665 /// Create the loop forest using a stable algorithm.
665 void analyze(const DominatorTreeBase> &DomTree);
666 void analyze(const DominatorTreeBase, false> &DomTree);
666667
667668 // Debugging
668669 void print(raw_ostream &OS) const;
669670
670 void verify(const DominatorTreeBase> &DomTree) const;
671 void verify(const DominatorTreeBase, false> &DomTree) const;
671672 };
672673
673674 // Implementation in LoopInfoImpl.h
682683 LoopInfo(const LoopInfo &) = delete;
683684 public:
684685 LoopInfo() {}
685 explicit LoopInfo(const DominatorTreeBase> &DomTree);
686 explicit LoopInfo(const DominatorTreeBase, false> &DomTree);
686687
687688 LoopInfo(LoopInfo &&Arg) : BaseT(std::move(static_cast(Arg))) {}
688689 LoopInfo &operator=(LoopInfo &&RHS) {
339339 /// Discover a subloop with the specified backedges such that: All blocks within
340340 /// this loop are mapped to this loop or a subloop. And all subloops within this
341341 /// loop have their parent loop set to this loop or a subloop.
342 template
343 static void discoverAndMapSubloop(LoopT *L, ArrayRef Backedges,
344 LoopInfoBase *LI,
345 const DominatorTreeBase &DomTree) {
342 template
343 static void discoverAndMapSubloop(
344 LoopT *L, ArrayRef Backedges, LoopInfoBase *LI,
345 const DomTreeBase &DomTree) {
346346 typedef GraphTraits > InvBlockTraits;
347347
348348 unsigned NumBlocks = 0;
461461 ///
462462 /// The Block vectors are inclusive, so step 3 requires loop-depth number of
463463 /// insertions per block.
464 template
465 void LoopInfoBase::
466 analyze(const DominatorTreeBase &DomTree) {
467
464 template
465 void LoopInfoBase::analyze(
466 const DomTreeBase &DomTree) {
468467 // Postorder traversal of the dominator tree.
469468 const DomTreeNodeBase *DomRoot = DomTree.getRootNode();
470469 for (auto DomNode : post_order(DomRoot)) {
606605
607606 template
608607 void LoopInfoBase::verify(
609 const DominatorTreeBase &DomTree) const {
608 const DomTreeBase &DomTree) const {
610609 DenseSet Loops;
611610 for (iterator I = begin(), E = end(); I != E; ++I) {
612611 assert(!(*I)->getParentLoop() && "Top-level loop has a parent!");
2121 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
2222 /// compute the post-dominator tree.
2323 ///
24 struct PostDominatorTree : public DominatorTreeBase {
25 typedef DominatorTreeBase Base;
26
27 PostDominatorTree() : DominatorTreeBase(true) {}
24 struct PostDominatorTree : public PostDomTreeBase {
25 typedef PostDomTreeBase Base;
2826
2927 /// Handle invalidation explicitly.
3028 bool invalidate(Function &F, const PreservedAnalyses &PA,
2222 ForwardDominanceFrontierBase Base;
2323
2424 public:
25 using DomTreeT = DominatorTreeBase;
26 using DomTreeNodeT = DomTreeNodeBase;
27 using DomSetType = DominanceFrontierBase::DomSetType;
28 using iterator = DominanceFrontierBase::iterator;
29 using const_iterator =
30 DominanceFrontierBase::const_iterator;
25 using DomTreeT = DomTreeBase;
26 using DomTreeNodeT = DomTreeNodeBase;
27 using DomSetType = DominanceFrontierBase::DomSetType;
28 using iterator = DominanceFrontierBase::iterator;
29 using const_iterator =
30 DominanceFrontierBase::const_iterator;
3131
32 MachineDominanceFrontier(const MachineDominanceFrontier &) = delete;
33 MachineDominanceFrontier &
34 operator=(const MachineDominanceFrontier &) = delete;
32 MachineDominanceFrontier(const MachineDominanceFrontier &) = delete;
33 MachineDominanceFrontier &operator=(const MachineDominanceFrontier &) = delete;
3534
36 static char ID;
35 static char ID;
3736
38 MachineDominanceFrontier();
37 MachineDominanceFrontier();
3938
40 DominanceFrontierBase &getBase() {
41 return Base;
42 }
39 DominanceFrontierBase &getBase() { return Base; }
4340
44 inline const std::vector &getRoots() const {
45 return Base.getRoots();
41 inline const std::vector &getRoots() const {
42 return Base.getRoots();
4643 }
4744
4845 MachineBasicBlock *getRoot() const {
9794 return Base.compareDomSet(DS1, DS2);
9895 }
9996
100 bool compare(DominanceFrontierBase> &Other) const {
97 bool compare(DominanceFrontierBase, false> &Other) const {
10198 return Base.compare(Other);
10299 }
103100
2727
2828 namespace llvm {
2929
30 template<>
31 inline void DominatorTreeBase::addRoot(MachineBasicBlock* MBB) {
30 template <>
31 inline void DominatorTreeBase::addRoot(
32 MachineBasicBlock *MBB) {
3233 this->Roots.push_back(MBB);
3334 }
3435
3536 extern template class DomTreeNodeBase;
36 extern template class DominatorTreeBase>;
37 extern template class DominatorTreeBase, false>; // DomTree
38 extern template class DominatorTreeBase; // PostDomTree
3739
3840 using MachineDomTreeNode = DomTreeNodeBase;
3941
6466 mutable SmallSet NewBBs;
6567
6668 /// The DominatorTreeBase that is used to compute a normal dominator tree
67 std::unique_ptrinatorTreeBase> DT;
69 std::unique_ptrTreeBase> DT;
6870
6971 /// \brief Apply all the recorded critical edges to the DT.
7072 /// This updates the underlying DT information in a way that uses
7880
7981 MachineDominatorTree();
8082
81 DominatorTreeBase &getBase() {
82 if (!DT)
83 DT.reset(new DominatorTreeBase(false));
83 DomTreeBase &getBase() {
84 if (!DT) DT.reset(new DomTreeBase());
8485 applySplitCriticalEdges();
8586 return *DT;
8687 }
2525 ///
2626 struct MachinePostDominatorTree : public MachineFunctionPass {
2727 private:
28 DominatorTreeBase *DT;
28 PostDomTreeBase *DT;
2929
3030 public:
3131 static char ID;
3333 class raw_ostream;
3434
3535 extern template class DomTreeNodeBase;
36 extern template class DominatorTreeBase>;
36 extern template class DominatorTreeBase, false>; // DomTree
37 extern template class DominatorTreeBase; // PostDomTree
3738
3839 namespace DomTreeBuilder {
39 using BBDomTree = DominatorTreeBase;
40 using BBDomTree = DomTreeBase;
41 using BBPostDomTree = PostDomTreeBase;
4042
4143 extern template void Calculate(BBDomTree &DT, Function &F);
44 extern template void Calculate(BBPostDomTree &DT,
45 Function &F);
4246
4347 extern template bool Verify(const BBDomTree &DT);
48 extern template bool Verify(const BBPostDomTree &DT);
4449 } // namespace DomTreeBuilder
4550
4651 using DomTreeNode = DomTreeNodeBase;
113118 /// the dominator tree is initially constructed may still exist in the tree,
114119 /// even if the tree is properly updated. Calling code should not rely on the
115120 /// preceding statements; this is stated only to assist human understanding.
116 class DominatorTree : public DominatorTreeBase {
117 public:
118 using Base = DominatorTreeBase;
119
120 DominatorTree() : DominatorTreeBase(false) {}
121 explicit DominatorTree(Function &F) : DominatorTreeBase(false) {
122 recalculate(F);
123 }
121 class DominatorTree : public DominatorTreeBase {
122 public:
123 using Base = DominatorTreeBase;
124
125 DominatorTree() = default;
126 explicit DominatorTree(Function &F) { recalculate(F); }
124127
125128 /// Handle invalidation explicitly.
126129 bool invalidate(Function &F, const PreservedAnalyses &PA,
4040
4141 namespace llvm {
4242
43 template <class NodeT> class DominatorTreeBase;
43 template <typename NodeT, bool IsPostDom>
44 class DominatorTreeBase;
4445
4546 /// \brief Base class for the actual dominator tree node.
4647 template class DomTreeNodeBase {
4748 friend struct PostDominatorTree;
48 friend class DominatorTreeBase>;
49 friend class DominatorTreeBase, false>;
50 friend class DominatorTreeBase;
4951
5052 NodeT *TheBB;
5153 DomTreeNodeBase *IDom;
184186 void Calculate(DomTreeT &DT, FuncT &F);
185187
186188 // The verify function is provided in a separate header but referenced here.
187 template <class DomTreeT>
189 template <typename DomTreeT>
188190 bool Verify(const DomTreeT &DT);
189191 } // namespace DomTreeBuilder
190192
192194 ///
193195 /// This class is a generic template over graph nodes. It is instantiated for
194196 /// various graphs in the LLVM IR or in the code generator.
195 template <class NodeT> class DominatorTreeBase {
197 template <typename NodeT, bool IsPostDom>
198 class DominatorTreeBase {
196199 protected:
197200 std::vector Roots;
198 bool IsPostDominators;
199201
200202 using DomTreeNodeMapType =
201203 DenseMap>>;
212214 "Currently DominatorTreeBase supports only pointer nodes");
213215 using NodeType = NodeT;
214216 using NodePtr = NodeT *;
215 explicit DominatorTreeBase(bool isPostDom) : IsPostDominators(isPostDom) {}
217 static constexpr bool IsPostDominator = IsPostDom;
218
219 DominatorTreeBase() = default;
216220
217221 DominatorTreeBase(DominatorTreeBase &&Arg)
218222 : Roots(std::move(Arg.Roots)),
219 IsPostDominators(Arg.IsPostDominators),
220223 DomTreeNodes(std::move(Arg.DomTreeNodes)),
221224 RootNode(std::move(Arg.RootNode)),
222225 DFSInfoValid(std::move(Arg.DFSInfoValid)),
226229
227230 DominatorTreeBase &operator=(DominatorTreeBase &&RHS) {
228231 Roots = std::move(RHS.Roots);
229 IsPostDominators = RHS.IsPostDominators;
230232 DomTreeNodes = std::move(RHS.DomTreeNodes);
231233 RootNode = std::move(RHS.RootNode);
232234 DFSInfoValid = std::move(RHS.DFSInfoValid);
246248
247249 /// isPostDominator - Returns true if analysis based of postdoms
248250 ///
249 bool isPostDominator() const { return IsPostDominators; }
251 bool isPostDominator() const { return IsPostDominator; }
250252
251253 /// compare - Return false if the other dominator tree base matches this
252254 /// dominator tree base. Otherwise return true.
521523 /// splitBlock - BB is split and now it has one successor. Update dominator
522524 /// tree to reflect this change.
523525 void splitBlock(NodeT *NewBB) {
524 if (this->IsPostDominators)
526 if (IsPostDominator)
525527 Split>(NewBB);
526528 else
527529 Split(NewBB);
599601 using TraitsTy = GraphTraits;
600602 reset();
601603
602 if (!IsPostDominators) {
604 if (!IsPostDominator) {
603605 // Initialize root
604606 NodeT *entry = TraitsTy::getEntryNode(&F);
605607 addRoot(entry);
707709 }
708710 };
709711
712 template
713 using DomTreeBase = DominatorTreeBase;
714
715 template
716 using PostDomTreeBase = DominatorTreeBase;
717
710718 // These two functions are declared out of line as a workaround for building
711719 // with old (< r147295) versions of clang because of pr11642.
712 template
713 bool DominatorTreeBase::dominates(const NodeT *A, const NodeT *B) const {
720 template
721 bool DominatorTreeBase::dominates(const NodeT *A,
722 const NodeT *B) const {
714723 if (A == B)
715724 return true;
716725
720729 return dominates(getNode(const_cast(A)),
721730 getNode(const_cast(B)));
722731 }
723 template
724 bool DominatorTreeBase::properlyDominates(const NodeT *A,
725 const NodeT *B) const {
732 template
733 bool DominatorTreeBase::properlyDominates(
734 const NodeT *A, const NodeT *B) const {
726735 if (A == B)
727736 return false;
728737
1313 using namespace llvm;
1414
1515 namespace llvm {
16 template class DominanceFrontierBase>;
16 template class DominanceFrontierBase, false>;
17 template class DominanceFrontierBase;
1718 template class ForwardDominanceFrontierBase;
1819 }
1920
1616 #include
1717
1818 namespace llvm {
19 template
20 void IDFCalculator::calculate(
19 template
20 void IDFCalculator::calculate(
2121 SmallVectorImpl &PHIBlocks) {
2222 // Use a priority queue keyed on dominator tree level so that inserted nodes
2323 // are handled from the bottom of the dominator tree upwards.
8787 }
8888 }
8989
90 template class IDFCalculator;
91 template class IDFCalculator<Inverse>;
90 template class IDFCalculator<BasicBlock *, false>;
91 template class IDFCalculator, true>;
9292 }
608608 return NearLoop;
609609 }
610610
611 LoopInfo::LoopInfo(const DominatorTreeBase &DomTree) {
611 LoopInfo::LoopInfo(const DomTreeBase &DomTree) {
612612 analyze(DomTree);
613613 }
614614
2121 using namespace llvm;
2222
2323 #define DEBUG_TYPE "postdomtree"
24
25 template class llvm::DominatorTreeBase; // PostDomTreeBase
2426
2527 //===----------------------------------------------------------------------===//
2628 // PostDominatorTree Implementation
1414 using namespace llvm;
1515
1616 namespace llvm {
17 template class DominanceFrontierBase>;
17 template class DominanceFrontierBase, false>;
18 template class DominanceFrontierBase;
1819 template class ForwardDominanceFrontierBase;
1920 }
2021
3030
3131 namespace llvm {
3232 template class DomTreeNodeBase;
33 template class DominatorTreeBase>;
33 template class DominatorTreeBase, false>; // DomTreeBase
3434 }
3535
3636 char MachineDominatorTree::ID = 0;
4848 bool MachineDominatorTree::runOnMachineFunction(MachineFunction &F) {
4949 CriticalEdgesToSplit.clear();
5050 NewBBs.clear();
51 DT.reset(new DominatorTreeBase(false));
51 DT.reset(new DomTreeBase());
5252 DT->recalculate(F);
5353 return false;
5454 }
143143 return;
144144 MachineFunction &F = *getRoot()->getParent();
145145
146 DominatorTreeBase OtherDT(false);
146 DomTreeBase OtherDT;
147147 OtherDT.recalculate(F);
148148 if (getRootNode()->getBlock() != OtherDT.getRootNode()->getBlock() ||
149149 DT->compare(OtherDT)) {
1515
1616 using namespace llvm;
1717
18 namespace llvm {
19 template class DominatorTreeBase; // PostDomTreeBase
20 }
21
1822 char MachinePostDominatorTree::ID = 0;
1923
2024 //declare initializeMachinePostDominatorTreePass
2327
2428 MachinePostDominatorTree::MachinePostDominatorTree() : MachineFunctionPass(ID) {
2529 initializeMachinePostDominatorTreePass(*PassRegistry::getPassRegistry());
26 DT = new DominatorTreeBase(true); //true indicate
27 // postdominator
30 DT = new PostDomTreeBase();
2831 }
2932
3033 FunctionPass *
6060 //===----------------------------------------------------------------------===//
6161
6262 template class llvm::DomTreeNodeBase;
63 template class llvm::DominatorTreeBase>;
63 template class llvm::DominatorTreeBase, false>; // DomTreeBase
64 template class llvm::DominatorTreeBase; // PostDomTreeBase
6465
6566 template void
6667 llvm::DomTreeBuilder::Calculate(
6768 DomTreeBuilder::BBDomTree &DT, Function &F);
69 template void
70 llvm::DomTreeBuilder::Calculate(
71 DomTreeBuilder::BBPostDomTree &DT, Function &F);
6872
6973 template bool llvm::DomTreeBuilder::Verify(
7074 const DomTreeBuilder::BBDomTree &DT);
75 template bool llvm::DomTreeBuilder::Verify(
76 const DomTreeBuilder::BBPostDomTree &DT);
7177
7278 bool DominatorTree::invalidate(Function &F, const PreservedAnalyses &PA,
7379 FunctionAnalysisManager::Invalidator &) {
172172 void printBlockEquivalence(raw_ostream &OS, const BasicBlock *BB);
173173 bool computeBlockWeights(Function &F);
174174 void findEquivalenceClasses(Function &F);
175 template
175176 void findEquivalencesFor(BasicBlock *BB1, ArrayRef Descendants,
176 DominatorTreeBase> *DomTree);
177 DominatorTreeBase, IsPostDom> *DomTree);
178
177179 void propagateWeights(Function &F);
178180 uint64_t visitEdge(Edge E, unsigned *NumUnknownEdges, Edge *UnknownEdge);
179181 void buildEdges(Function &F);
216218
217219 /// \brief Dominance, post-dominance and loop information.
218220 std::unique_ptr DT;
219 std::unique_ptr<DominatorTreeBase> PDT;
221 std::unique_ptr<PostDomTreeBase> PDT;
220222 std::unique_ptr LI;
221223
222224 AssumptionCacheTracker *ACT;
772774 /// \param DomTree Opposite dominator tree. If \p Descendants is filled
773775 /// with blocks from \p BB1's dominator tree, then
774776 /// this is the post-dominator tree, and vice versa.
777 template
775778 void SampleProfileLoader::findEquivalencesFor(
776779 BasicBlock *BB1, ArrayRef Descendants,
777 DominatorTreeBase> *DomTree) {
780 DominatorTreeBase, IsPostDom> *DomTree) {
778781 const BasicBlock *EC = EquivalenceClass[BB1];
779782 uint64_t Weight = BlockWeights[EC];
780783 for (const auto *BB2 : Descendants) {
12821285 DT.reset(new DominatorTree);
12831286 DT->recalculate(F);
12841287
1285 PDT.reset(new DominatorTreeBase(true));
1288 PDT.reset(new PostDomTreeBase());
12861289 PDT->recalculate(F);
12871290
12881291 LI.reset(new LoopInfo);
1818
1919 using namespace llvm;
2020
21 struct PostDomTree : PostDomTreeBase {
22 PostDomTree(Function &F) { recalculate(F); }
23 };
24
2125 /// Build the dominator tree for the function and run the Test.
22 static void
23 runWithDomTree(Module &M, StringRef FuncName,
24 function_ref
25 DominatorTreeBase *PDT)>
26 Test) {
26 static void runWithDomTree(
27 Module &M, StringRef FuncName,
28 function_ref Test) {
2729 auto *F = M.getFunction(FuncName);
2830 ASSERT_NE(F, nullptr) << "Could not find " << FuncName;
2931 // Compute the dominator tree for the function.
3032 DominatorTree DT(*F);
31 DominatorTreeBase PDT(/*isPostDom*/ true);
32 PDT.recalculate(*F);
33 PostDomTree PDT(*F);
3334 Test(*F, &DT, &PDT);
3435 }
3536
7172 std::unique_ptr M = makeLLVMModule(Context, ModuleString);
7273
7374 runWithDomTree(
74 *M, "f",
75 [&](Function &F, DominatorTree *DT, DominatorTreeBase *PDT) {
75 *M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) {
7676 Function::iterator FI = F.begin();
7777
7878 BasicBlock *BB0 = &*FI++;
292292 std::unique_ptr M = makeLLVMModule(Context, ModuleString);
293293
294294 runWithDomTree(
295 *M, "f",
296 [&](Function &F, DominatorTree *DT, DominatorTreeBase *PDT) {
295 *M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) {
297296 Function::iterator FI = F.begin();
298297
299298 BasicBlock *BB0 = &*FI++;