llvm.org GIT mirror llvm / f6e737e
[GraphTraits] Make nodes_iterator dereference to NodeType*/NodeRef Currently nodes_iterator may dereference to a NodeType* or a NodeType&. Make them all dereference to NodeType*, which is NodeRef later. Differential Revision: https://reviews.llvm.org/D23704 Differential Revision: https://reviews.llvm.org/D23705 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279326 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Shen 4 years ago
16 changed file(s) with 59 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
3333 //
3434 // typedef NodeType - Type of Node in the graph
3535 // typedef NodeRef - NodeType *
36 // typedef ChildIteratorType - Type used to iterate over children in graph
36 // typedef ChildIteratorType - Type used to iterate over children in graph,
37 // dereference to a NodeRef
3738
3839 // static NodeRef getEntryNode(const GraphType &)
3940 // Return the entry node of the graph
4445 // node list for the specified node.
4546 //
4647
47 // typedef ...iterator nodes_iterator;
48 // typedef ...iterator nodes_iterator; - dereference to a NodeRef
4849 // static nodes_iterator nodes_begin(GraphType *G)
4950 // static nodes_iterator nodes_end (GraphType *G)
5051 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
12701270 for (NodeIter I = GTraits::nodes_begin(Graph),
12711271 E = GTraits::nodes_end(Graph);
12721272 I != E; ++I) {
1273 NodeRef N = &*I;
1273 NodeRef N = *I;
12741274 MaxFrequency =
12751275 std::max(MaxFrequency, Graph->getBlockFreq(N).getFrequency());
12761276 }
459459 }
460460 typedef std::pair>
461461 PairTy;
462 typedef std::pointer_to_unary_function&>
462 typedef std::pointer_to_unary_function*>
463463 DerefFun;
464464
465465 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
471471 return map_iterator(CG->end(), DerefFun(CGdereference));
472472 }
473473
474 static CallGraphNode &CGdereference(const PairTy &P) { return *P.second; }
474 static CallGraphNode *CGdereference(const PairTy &P) { return P.second.get(); }
475475 };
476476
477477 template <>
482482 }
483483 typedef std::pair>
484484 PairTy;
485 typedef std::pointer_to_unary_function&>
485 typedef std::pointer_to_unary_function*>
486486 DerefFun;
487487
488488 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
494494 return map_iterator(CG->end(), DerefFun(CGdereference));
495495 }
496496
497 static const CallGraphNode &CGdereference(const PairTy &P) {
498 return *P.second;
497 static const CallGraphNode *CGdereference(const PairTy &P) {
498 return P.second.get();
499499 }
500500 };
501501
624624 }
625625
626626 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
627 typedef MachineFunction::iterator nodes_iterator;
628 static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); }
629 static nodes_iterator nodes_end (MachineFunction *F) { return F->end(); }
627 typedef pointer_iterator nodes_iterator;
628 static nodes_iterator nodes_begin(MachineFunction *F) {
629 return nodes_iterator(F->begin());
630 }
631 static nodes_iterator nodes_end(MachineFunction *F) {
632 return nodes_iterator(F->end());
633 }
630634 static unsigned size (MachineFunction *F) { return F->size(); }
631635 };
632636 template <> struct GraphTraits :
636640 }
637641
638642 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
639 typedef MachineFunction::const_iterator nodes_iterator;
643 typedef pointer_iterator nodes_iterator;
640644 static nodes_iterator nodes_begin(const MachineFunction *F) {
641 return F->begin();
645 return nodes_iterator(F->begin());
642646 }
643647 static nodes_iterator nodes_end (const MachineFunction *F) {
644 return F->end();
648 return nodes_iterator(F->end());
645649 }
646650 static unsigned size (const MachineFunction *F) {
647651 return F->size();
691691 };
692692
693693 template <> struct GraphTraits : public GraphTraits {
694 typedef std::vector::iterator nodes_iterator;
694 typedef pointer_iterator::iterator> nodes_iterator;
695695 static nodes_iterator nodes_begin(ScheduleDAG *G) {
696 return G->SUnits.begin();
696 return nodes_iterator(G->SUnits.begin());
697697 }
698698 static nodes_iterator nodes_end(ScheduleDAG *G) {
699 return G->SUnits.end();
699 return nodes_iterator(G->SUnits.end());
700700 }
701701 };
702702
14151415 };
14161416
14171417 template <> struct GraphTraits : public GraphTraits {
1418 typedef SelectionDAG::allnodes_iterator nodes_iterator;
1418 typedef pointer_iterator nodes_iterator;
14191419 static nodes_iterator nodes_begin(SelectionDAG *G) {
1420 return G->allnodes_begin();
1420 return nodes_iterator(G->allnodes_begin());
14211421 }
14221422 static nodes_iterator nodes_end(SelectionDAG *G) {
1423 return G->allnodes_end();
1423 return nodes_iterator(G->allnodes_end());
14241424 }
14251425 };
14261426
228228 static NodeType *getEntryNode(Function *F) { return &F->getEntryBlock(); }
229229
230230 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
231 typedef Function::iterator nodes_iterator;
232 static nodes_iterator nodes_begin(Function *F) { return F->begin(); }
233 static nodes_iterator nodes_end (Function *F) { return F->end(); }
231 typedef pointer_iterator nodes_iterator;
232 static nodes_iterator nodes_begin(Function *F) {
233 return nodes_iterator(F->begin());
234 }
235 static nodes_iterator nodes_end(Function *F) {
236 return nodes_iterator(F->end());
237 }
234238 static size_t size (Function *F) { return F->size(); }
235239 };
236240 template <> struct GraphTraits :
238242 static NodeType *getEntryNode(const Function *F) {return &F->getEntryBlock();}
239243
240244 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
241 typedef Function::const_iterator nodes_iterator;
242 static nodes_iterator nodes_begin(const Function *F) { return F->begin(); }
243 static nodes_iterator nodes_end (const Function *F) { return F->end(); }
245 typedef pointer_iterator nodes_iterator;
246 static nodes_iterator nodes_begin(const Function *F) {
247 return nodes_iterator(F->begin());
248 }
249 static nodes_iterator nodes_end(const Function *F) {
250 return nodes_iterator(F->end());
251 }
244252 static size_t size (const Function *F) { return F->size(); }
245253 };
246254
749749 for (typename TraitsTy::nodes_iterator I = TraitsTy::nodes_begin(&F),
750750 E = TraitsTy::nodes_end(&F);
751751 I != E; ++I)
752 if (TraitsTy::child_begin(&*I) == TraitsTy::child_end(&*I))
753 addRoot(&*I);
752 if (TraitsTy::child_begin(*I) == TraitsTy::child_end(*I))
753 addRoot(*I);
754754
755755 Calculate>(*this, F);
756756 }
144144 // Loop over the graph, printing it out...
145145 for (node_iterator I = GTraits::nodes_begin(G), E = GTraits::nodes_end(G);
146146 I != E; ++I)
147 if (!isNodeHidden(&*I))
148 writeNode(&*I);
149 }
150
151 bool isNodeHidden(NodeRef const *Node) {
152 return isNodeHidden(*Node);
147 if (!isNodeHidden(*I))
148 writeNode(*I);
153149 }
154150
155151 bool isNodeHidden(NodeRef Node) {
156152 return DTraits.isNodeHidden(Node);
157 }
158
159 void writeNode(NodeRef const *Node) {
160 writeNode(*Node);
161153 }
162154
163155 void writeNode(NodeRef Node) {
6262 typedef const BasicBlock NodeType;
6363 typedef const BasicBlock *NodeRef;
6464 typedef succ_const_iterator ChildIteratorType;
65 typedef Function::const_iterator nodes_iterator;
65 typedef pointer_iterator nodes_iterator;
6666
6767 static inline const NodeType *getEntryNode(const BlockFrequencyInfo *G) {
6868 return &G->getFunction()->front();
7474 return succ_end(N);
7575 }
7676 static nodes_iterator nodes_begin(const BlockFrequencyInfo *G) {
77 return G->getFunction()->begin();
77 return nodes_iterator(G->getFunction()->begin());
7878 }
7979 static nodes_iterator nodes_end(const BlockFrequencyInfo *G) {
80 return G->getFunction()->end();
80 return nodes_iterator(G->getFunction()->end());
8181 }
8282 };
8383
5454 typedef const MachineBasicBlock NodeType;
5555 typedef const MachineBasicBlock *NodeRef;
5656 typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
57 typedef MachineFunction::const_iterator nodes_iterator;
57 typedef pointer_iterator nodes_iterator;
5858
5959 static inline const NodeType *
6060 getEntryNode(const MachineBlockFrequencyInfo *G) {
7070 }
7171
7272 static nodes_iterator nodes_begin(const MachineBlockFrequencyInfo *G) {
73 return G->getFunction()->begin();
73 return nodes_iterator(G->getFunction()->begin());
7474 }
7575
7676 static nodes_iterator nodes_end(const MachineBlockFrequencyInfo *G) {
77 return G->getFunction()->end();
77 return nodes_iterator(G->getFunction()->end());
7878 }
7979 };
8080
839839 } //while, "one iteration" over the function.
840840
841841 MachineBasicBlock *EntryMBB =
842 &*GraphTraits::nodes_begin(FuncRep);
842 *GraphTraits::nodes_begin(FuncRep);
843843 if (EntryMBB->succ_size() == 0) {
844844 Finish = true;
845845 DEBUG(
862862 } while (!Finish && MakeProgress);
863863
864864 // Misc wrap up to maintain the consistency of the Function representation.
865 wrapup(&*GraphTraits::nodes_begin(FuncRep));
865 wrapup(*GraphTraits::nodes_begin(FuncRep));
866866
867867 // Detach retired Block, release memory.
868868 for (MBBInfoMap::iterator It = BlockInfoMap.begin(), E = BlockInfoMap.end();
906906
907907 //walk through all the block in func to check for unreachable
908908 typedef GraphTraits GTM;
909 MachineFunction::iterator It = GTM::nodes_begin(MF), E = GTM::nodes_end(MF);
909 auto It = GTM::nodes_begin(MF), E = GTM::nodes_end(MF);
910910 for (; It != E; ++It) {
911 MachineBasicBlock *MBB = &(*It);
911 MachineBasicBlock *MBB = *It;
912912 SccNum = getSCCNum(MBB);
913913 if (SccNum == INVALIDSCCNUM)
914914 dbgs() << "unreachable block BB" << MBB->getNumber() << "\n";
210210 // ensures that all bases of a candidate are in Candidates when we process it.
211211 for (auto Node = GraphTraits::nodes_begin(DT);
212212 Node != GraphTraits::nodes_end(DT); ++Node) {
213 BasicBlock *BB = Node->getBlock();
213 BasicBlock *BB = (*Node)->getBlock();
214214 for (auto I = BB->begin(); I != BB->end(); ++I) {
215215 if (SE->isSCEVable(I->getType()) && isPotentiallyNaryReassociable(&*I)) {
216216 const SCEV *OldSCEV = SE->getSCEV(&*I);
11511151 DominatingExprs.clear();
11521152 for (auto Node = GraphTraits::nodes_begin(DT);
11531153 Node != GraphTraits::nodes_end(DT); ++Node) {
1154 BasicBlock *BB = Node->getBlock();
1154 BasicBlock *BB = (*Node)->getBlock();
11551155 for (auto I = BB->begin(); I != BB->end(); ) {
11561156 Instruction *Cur = &*I++;
11571157 Changed |= reuniteExts(Cur);
675675 // all bases of a candidate are in Candidates when we process it.
676676 for (auto node = GraphTraits::nodes_begin(DT);
677677 node != GraphTraits::nodes_end(DT); ++node) {
678 for (auto &I : *node->getBlock())
678 for (auto &I : *(*node)->getBlock())
679679 allocateCandidatesAndFindBasis(&I);
680680 }
681681
2323 auto X = ++I;
2424
2525 // Should be able to iterate over all nodes of the graph.
26 static_assert(std::is_same&>::value,
26 static_assert(std::is_same*>::value,
2727 "Node type does not match");
28 static_assert(std::is_same&>::value,
28 static_assert(std::is_same*>::value,
2929 "Node type does not match");
30 static_assert(std::is_same&>::value,
30 static_assert(std::is_same*>::value,
3131 "Node type does not match");
3232
3333 NodeTy *N = GraphTraits::getEntryNode(G);