llvm.org GIT mirror llvm / 1a2e7d2
[Dominators] Simplify templates Summary: DominatorTreeBase and related classes used overcomplicated template machinery. This patch simplifies them and gets rid of DominatorTreeBaseTraits and DominatorTreeBaseByTraits, which weren't actually used outside the DomTree construction. Reviewers: dberlin, sanjoy, davide, grosser Reviewed By: dberlin, davide, grosser Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35285 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307953 91177308-0d34-0410-b5e6-96231b3b80d8 Jakub Kuderski 3 years ago
4 changed file(s) with 39 addition(s) and 82 deletion(s). Raw diff Collapse all Expand all
3636 extern template class DominatorTreeBase;
3737
3838 namespace DomTreeBuilder {
39 extern template void Calculate(
40 DominatorTreeBaseByGraphTraits> &DT, Function &F);
41
42 extern template void Calculate>(
43 DominatorTreeBaseByGraphTraits>> &DT,
44 Function &F);
45
46 extern template bool Verify(
47 const DominatorTreeBaseByGraphTraits> &DT);
48
49 extern template bool Verify>(
50 const DominatorTreeBaseByGraphTraits>>
51 &DT);
39 using BBDomTree = DominatorTreeBase;
40
41 extern template void Calculate(BBDomTree &DT, Function &F);
42
43 extern template bool Verify(const BBDomTree &DT);
5244 } // namespace DomTreeBuilder
5345
5446 using DomTreeNode = DomTreeNodeBase;
4242
4343 template class DominatorTreeBase;
4444
45 namespace detail {
46
47 template struct DominatorTreeBaseTraits {
48 static_assert(std::is_pointer::value,
49 "Currently NodeRef must be a pointer type.");
50 using type = DominatorTreeBase<
51 typename std::remove_pointer::type>;
52 };
53
54 } // end namespace detail
55
56 template
57 using DominatorTreeBaseByGraphTraits =
58 typename detail::DominatorTreeBaseTraits::type;
59
6045 /// \brief Base class for the actual dominator tree node.
6146 template class DomTreeNodeBase {
6247 friend struct PostDominatorTree;
63 template friend class DominatorTreeBase;
48 friend class DominatorTreeBase;
6449
6550 NodeT *TheBB;
6651 DomTreeNodeBase *IDom;
191176 }
192177
193178 namespace DomTreeBuilder {
194 template <class NodeT>
179 template <typename DomTreeT>
195180 struct SemiNCAInfo;
196181
197182 // The calculate routine is provided in a separate header but referenced here.
198 template
199 void Calculate(DominatorTreeBaseByGraphTraits> &DT, FuncT &F);
183 template
184 void Calculate(DomTreeT &DT, FuncT &F);
200185
201186 // The verify function is provided in a separate header but referenced here.
202 template
203 bool Verify(const DominatorTreeBaseByGraphTraits> &DT);
187 template
188 bool Verify(const DomTreeT &DT);
204189 } // namespace DomTreeBuilder
205190
206191 /// \brief Core dominator tree base class.
220205 mutable bool DFSInfoValid = false;
221206 mutable unsigned int SlowQueries = 0;
222207
223 friend struct DomTreeBuilder::SemiNCAInfo;
224 using SNCAInfoTy = DomTreeBuilder::SemiNCAInfo>;
208 friend struct DomTreeBuilder::SemiNCAInfo>;
225209
226210 public:
211 static_assert(std::is_pointer::NodeRef>::value,
212 "Currently DominatorTreeBase supports only pointer nodes");
213 using NodeType = NodeT;
214 using NodePtr = NodeT *;
227215 explicit DominatorTreeBase(bool isPostDom) : IsPostDominators(isPostDom) {}
228216
229217 DominatorTreeBase(DominatorTreeBase &&Arg)
611599 using TraitsTy = GraphTraits;
612600 reset();
613601
614 if (!this->IsPostDominators) {
602 if (!IsPostDominators) {
615603 // Initialize root
616604 NodeT *entry = TraitsTy::getEntryNode(&F);
617605 addRoot(entry);
618
619 DomTreeBuilder::Calculate(*this, F);
620606 } else {
621607 // Initialize the roots list
622608 for (auto *Node : nodes(&F))
623609 if (TraitsTy::child_begin(Node) == TraitsTy::child_end(Node))
624610 addRoot(Node);
625
626 DomTreeBuilder::Calculate>(*this, F);
627 }
611 }
612
613 DomTreeBuilder::Calculate(*this, F);
628614 }
629615
630616 /// verify - check parent and sibling property
631 bool verify() const {
632 return this->isPostDominator()
633 ? DomTreeBuilder::Verify>(*this)
634 : DomTreeBuilder::Verify(*this);
635 }
617 bool verify() const { return DomTreeBuilder::Verify(*this); }
636618
637619 protected:
638620 void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
639621
640622 void reset() {
641623 DomTreeNodes.clear();
642 this->Roots.clear();
624 Roots.clear();
643625 RootNode = nullptr;
644626 DFSInfoValid = false;
645627 SlowQueries = 0;
4848 }
4949 };
5050
51 // Information record used by Semi-NCA during tree construction.
52 template NodeT>
51 template DomTreeT>
5352 struct SemiNCAInfo {
54 using NodePtr = NodeT *;
55 using DomTreeT = DominatorTreeBase;
53 using NodePtr = typename DomTreeT::NodePtr;
54 using NodeT = typename DomTreeT::NodeType;
5655 using TreeNodePtr = DomTreeNodeBase *;
5756
57 // Information record used by Semi-NCA during tree construction.
5858 struct InfoRec {
5959 unsigned DFSNum = 0;
6060 unsigned Parent = 0;
523523 }
524524 };
525525
526 template
527 void Calculate(DominatorTreeBaseByGraphTraits> &DT,
528 FuncT &F) {
529 using NodePtr = typename GraphTraits::NodeRef;
530 static_assert(std::is_pointer::value,
531 "NodePtr should be a pointer type");
532 SemiNCAInfo::type> SNCA;
526
527 template
528 void Calculate(DomTreeT &DT, FuncT &F) {
529 SemiNCAInfo SNCA;
533530 SNCA.calculateFromScratch(DT, GraphTraits::size(&F));
534531 }
535532
536 template
537 bool Verify(const DominatorTreeBaseByGraphTraits> &DT) {
538 using NodePtr = typename GraphTraits::NodeRef;
539 static_assert(std::is_pointer::value,
540 "NodePtr should be a pointer type");
541 SemiNCAInfo::type> SNCA;
542
533 template
534 bool Verify(const DomTreeT &DT) {
535 SemiNCAInfo SNCA;
543536 return SNCA.verifyReachability(DT) && SNCA.VerifyLevels(DT) &&
544537 SNCA.verifyNCD(DT) && SNCA.verifyParentProperty(DT) &&
545538 SNCA.verifySiblingProperty(DT);
6262 template class llvm::DomTreeNodeBase;
6363 template class llvm::DominatorTreeBase;
6464
65 template void llvm::DomTreeBuilder::Calculate(
66 DominatorTreeBase<
67 typename std::remove_pointer::NodeRef>::type>
68 &DT,
69 Function &F);
70 template void llvm::DomTreeBuilder::Calculate>(
71 DominatorTreeBase
72 GraphTraits>::NodeRef>::type> &DT,
73 Function &F);
74 template bool llvm::DomTreeBuilder::Verify(
75 const DominatorTreeBase<
76 typename std::remove_pointer::NodeRef>::type>
77 &DT);
78 template bool llvm::DomTreeBuilder::Verify>(
79 const DominatorTreeBase
80 GraphTraits>::NodeRef>::type> &DT);
65 template void
66 llvm::DomTreeBuilder::Calculate(
67 DomTreeBuilder::BBDomTree &DT, Function &F);
68
69 template bool llvm::DomTreeBuilder::Verify(
70 const DomTreeBuilder::BBDomTree &DT);
8171
8272 bool DominatorTree::invalidate(Function &F, const PreservedAnalyses &PA,
8373 FunctionAnalysisManager::Invalidator &) {