llvm.org GIT mirror llvm / e15402f
Change the Dominators recalculate() function to only rely on GraphTraits This is a patch by Guoping Long! As part of utilizing LLVM Dominator computation in Clang, made two changes to LLVM dominators tree implementation: - (1) Change the recalculate() template function to only rely on GraphTraits. - (2) Add a size() method to GraphTraits template class to query the number of nodes in the graph. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145837 91177308-0d34-0410-b5e6-96231b3b80d8 Anna Zaks 8 years ago
5 changed file(s) with 20 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
4242 // typedef ...iterator nodes_iterator;
4343 // static nodes_iterator nodes_begin(GraphType *G)
4444 // static nodes_iterator nodes_end (GraphType *G)
45 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
46
47 // static unsigned size (GraphType *G)
48 // Return total number of nodes in the graph
4549 //
46 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
4750
4851
4952 // If anyone tries to use this class without having an appropriate
170170
171171 // it might be that some blocks did not get a DFS number (e.g., blocks of
172172 // infinite loops). In these cases an artificial exit node is required.
173 MultipleRoots |= (DT.isPostDominator() && N != F.size());
173 MultipleRoots |= (DT.isPostDominator() && N != GraphTraits::size(&F));
174174
175175 // When naively implemented, the Lengauer-Tarjan algorithm requires a separate
176176 // bucket for each vertex. However, this is unnecessary, because each vertex
652652 /// recalculate - compute a dominator tree for the given function
653653 template
654654 void recalculate(FT& F) {
655 typedef GraphTraits TraitsTy;
655656 reset();
656657 this->Vertex.push_back(0);
657658
658659 if (!this->IsPostDominators) {
659660 // Initialize root
660 this->Roots.push_back(&F.front());
661 this->IDoms[&F.front()] = 0;
662 this->DomTreeNodes[&F.front()] = 0;
661 NodeT *entry = TraitsTy::getEntryNode(&F);
662 this->Roots.push_back(entry);
663 this->IDoms[entry] = 0;
664 this->DomTreeNodes[entry] = 0;
663665
664666 Calculate(*this, F);
665667 } else {
666668 // Initialize the roots list
667 for (typename FT::iterator I = F.begin(), E = F.end(); I != E; ++I) {
668 if (std::distance(GraphTraits::child_begin(I),
669 GraphTraits::child_end(I)) == 0)
669 for (typename TraitsTy::nodes_iterator I = TraitsTy::nodes_begin(&F),
670 E = TraitsTy::nodes_end(&F); I != E; ++I) {
671 if (std::distance(TraitsTy::child_begin(I),
672 TraitsTy::child_end(I)) == 0)
670673 addRoot(I);
671674
672675 // Prepopulate maps so that we don't get iterator invalidation issues later.
436436 typedef MachineFunction::iterator nodes_iterator;
437437 static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); }
438438 static nodes_iterator nodes_end (MachineFunction *F) { return F->end(); }
439 static unsigned size (MachineFunction *F) { return F->size(); }
439440 };
440441 template <> struct GraphTraits :
441442 public GraphTraits {
451452 static nodes_iterator nodes_end (const MachineFunction *F) {
452453 return F->end();
453454 }
455 static unsigned size (const MachineFunction *F) {
456 return F->size();
457 }
454458 };
455459
456460
313313 typedef Function::iterator nodes_iterator;
314314 static nodes_iterator nodes_begin(Function *F) { return F->begin(); }
315315 static nodes_iterator nodes_end (Function *F) { return F->end(); }
316 static unsigned size (Function *F) { return F->size(); }
316317 };
317318 template <> struct GraphTraits :
318319 public GraphTraits {
322323 typedef Function::const_iterator nodes_iterator;
323324 static nodes_iterator nodes_begin(const Function *F) { return F->begin(); }
324325 static nodes_iterator nodes_end (const Function *F) { return F->end(); }
326 static unsigned size (const Function *F) { return F->size(); }
325327 };
326328
327329