llvm.org GIT mirror llvm / 22fca38
[GraphTraits] Replace all NodeType usage with NodeRef This should finish the GraphTraits migration. Differential Revision: http://reviews.llvm.org/D23730 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279475 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Shen 3 years ago
24 changed file(s) with 144 addition(s) and 237 deletion(s). Raw diff Collapse all Expand all
2626 struct GraphTraits {
2727 // Elements to provide:
2828
29 // NOTICE: We are in a transition from migration interfaces that require
30 // NodeType *, to NodeRef. NodeRef is required to be cheap to copy, but does
31 // not have to be a raw pointer. In the transition, user should define
32 // NodeType, and NodeRef = NodeType *.
33 //
34 // typedef NodeType - Type of Node in the graph
35 // typedef NodeRef - NodeType *
29 // typedef NodeRef - Type of Node token in the graph, which should
30 // be cheap to copy.
3631 // typedef ChildIteratorType - Type used to iterate over children in graph,
37 // dereference to a NodeRef
32 // dereference to a NodeRef.
3833
3934 // static NodeRef getEntryNode(const GraphType &)
4035 // Return the entry node of the graph
408408 // Provide graph traits for tranversing call graphs using standard graph
409409 // traversals.
410410 template <> struct GraphTraits {
411 typedef CallGraphNode NodeType;
412411 typedef CallGraphNode *NodeRef;
413412
414413 typedef CallGraphNode::CallRecord CGNPairTy;
415414
416 static NodeType *getEntryNode(CallGraphNode *CGN) { return CGN; }
415 static NodeRef getEntryNode(CallGraphNode *CGN) { return CGN; }
417416
418417 static CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
419418
420 typedef mapped_iterator<NodeType::iterator, decltype(&CGNGetValue)>
419 typedef mapped_iterator<CallGraphNode::iterator, decltype(&CGNGetValue)>
421420 ChildIteratorType;
422421
423 static inline ChildIteratorType child_begin(NodeType *N) {
422 static inline ChildIteratorType child_begin(NodeRef N) {
424423 return ChildIteratorType(N->begin(), &CGNGetValue);
425424 }
426 static inline ChildIteratorType child_end(NodeType *N) {
425 static inline ChildIteratorType child_end(NodeRef N) {
427426 return ChildIteratorType(N->end(), &CGNGetValue);
428427 }
429428 };
430429
431430 template <> struct GraphTraits {
432 typedef const CallGraphNode NodeType;
433431 typedef const CallGraphNode *NodeRef;
434432
435433 typedef CallGraphNode::CallRecord CGNPairTy;
436434
437 static NodeType *getEntryNode(const CallGraphNode *CGN) { return CGN; }
435 static NodeRef getEntryNode(const CallGraphNode *CGN) { return CGN; }
438436
439437 static const CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
440438
441 typedef mapped_iterator<NodeType::const_iterator, decltype(&CGNGetValue)>
439 typedef mapped_iterator<CallGraphNode::const_iterator, decltype(&CGNGetValue)>
442440 ChildIteratorType;
443441
444 static inline ChildIteratorType child_begin(NodeType *N) {
442 static inline ChildIteratorType child_begin(NodeRef N) {
445443 return ChildIteratorType(N->begin(), &CGNGetValue);
446444 }
447 static inline ChildIteratorType child_end(NodeType *N) {
445 static inline ChildIteratorType child_end(NodeRef N) {
448446 return ChildIteratorType(N->end(), &CGNGetValue);
449447 }
450448 };
451449
452450 template <>
453451 struct GraphTraits : public GraphTraits {
454 static NodeType *getEntryNode(CallGraph *CGN) {
452 static NodeRef getEntryNode(CallGraph *CGN) {
455453 return CGN->getExternalCallingNode(); // Start at the external node!
456454 }
457455 typedef std::pair>
474472 template <>
475473 struct GraphTraits : public GraphTraits<
476474 const CallGraphNode *> {
477 static NodeType *getEntryNode(const CallGraph *CGN) {
475 static NodeRef getEntryNode(const CallGraph *CGN) {
478476 return CGN->getExternalCallingNode(); // Start at the external node!
479477 }
480478 typedef std::pair>
120120 }
121121
122122 template <> struct GraphTraits {
123 typedef Interval NodeType;
123 typedef Interval *NodeRef;
124124 typedef Interval::succ_iterator ChildIteratorType;
125125
126 static NodeType *getEntryNode(Interval *I) { return I; }
126 static NodeRef getEntryNode(Interval *I) { return I; }
127127
128128 /// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
129 static inline ChildIteratorType child_begin(NodeType *N) {
129 static inline ChildIteratorType child_begin(NodeRef N) {
130130 return succ_begin(N);
131131 }
132 static inline ChildIteratorType child_end(NodeType *N) {
133 return succ_end(N);
134 }
132 static inline ChildIteratorType child_end(NodeRef N) { return succ_end(N); }
135133 };
136134
137135 template <> struct GraphTraits > {
138 typedef Interval NodeType;
136 typedef Interval *NodeRef;
139137 typedef Interval::pred_iterator ChildIteratorType;
140 static NodeType *getEntryNode(Inverse G) { return G.Graph; }
141 static inline ChildIteratorType child_begin(NodeType *N) {
138 static NodeRef getEntryNode(Inverse G) { return G.Graph; }
139 static inline ChildIteratorType child_begin(NodeRef N) {
142140 return pred_begin(N);
143141 }
144 static inline ChildIteratorType child_end(NodeType *N) {
145 return pred_end(N);
146 }
142 static inline ChildIteratorType child_end(NodeRef N) { return pred_end(N); }
147143 };
148144
149145 } // End llvm namespace
952952
953953 // Provide GraphTraits specializations for call graphs.
954954 template <> struct GraphTraits {
955 typedef LazyCallGraph::Node NodeType;
955 typedef LazyCallGraph::Node *NodeRef;
956956 typedef LazyCallGraph::edge_iterator ChildIteratorType;
957957
958 static NodeType *getEntryNode(NodeType *N) { return N; }
959 static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
960 static ChildIteratorType child_end(NodeType *N) { return N->end(); }
958 static NodeRef getEntryNode(NodeRef N) { return N; }
959 static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
960 static ChildIteratorType child_end(NodeRef N) { return N->end(); }
961961 };
962962 template <> struct GraphTraits {
963 typedef LazyCallGraph::Node NodeType;
963 typedef LazyCallGraph::Node *NodeRef;
964964 typedef LazyCallGraph::edge_iterator ChildIteratorType;
965965
966 static NodeType *getEntryNode(NodeType *N) { return N; }
967 static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
968 static ChildIteratorType child_end(NodeType *N) { return N->end(); }
966 static NodeRef getEntryNode(NodeRef N) { return N; }
967 static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
968 static ChildIteratorType child_end(NodeRef N) { return N->end(); }
969969 };
970970
971971 /// An analysis pass which computes the call graph for a module.
760760
761761 // Allow clients to walk the list of nested loops...
762762 template <> struct GraphTraits {
763 typedef const Loop NodeType;
764763 typedef const Loop *NodeRef;
765764 typedef LoopInfo::iterator ChildIteratorType;
766765
767 static NodeType *getEntryNode(const Loop *L) { return L; }
768 static inline ChildIteratorType child_begin(NodeType *N) {
769 return N->begin();
770 }
771 static inline ChildIteratorType child_end(NodeType *N) {
772 return N->end();
773 }
766 static NodeRef getEntryNode(const Loop *L) { return L; }
767 static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
768 static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
774769 };
775770
776771 template <> struct GraphTraits {
777 typedef Loop NodeType;
778772 typedef Loop *NodeRef;
779773 typedef LoopInfo::iterator ChildIteratorType;
780774
781 static NodeType *getEntryNode(Loop *L) { return L; }
782 static inline ChildIteratorType child_begin(NodeType *N) {
783 return N->begin();
784 }
785 static inline ChildIteratorType child_end(NodeType *N) {
786 return N->end();
787 }
775 static NodeRef getEntryNode(Loop *L) { return L; }
776 static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
777 static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
788778 };
789779
790780 /// \brief Analysis pass that exposes the \c LoopInfo for a function.
8888
8989 template <> struct GraphTraits
9090 : public GraphTraits {
91 static NodeType *getEntryNode(PostDominatorTree *DT) {
91 static NodeRef getEntryNode(PostDominatorTree *DT) {
9292 return DT->getRootNode();
9393 }
9494
254254
255255 #define RegionNodeGraphTraits(NodeT, BlockT, RegionT) \
256256 template <> struct GraphTraits { \
257 typedef NodeT NodeType; \
258257 typedef NodeT *NodeRef; \
259258 typedef RNSuccIterator ChildIteratorType; \
260259 static NodeRef getEntryNode(NodeRef N) { return N; } \
266265 } \
267266 }; \
268267 template <> struct GraphTraits> { \
269 typedef NodeT NodeType; \
270268 typedef NodeT *NodeRef; \
271269 typedef RNSuccIterator, BlockT, RegionT> \
272270 ChildIteratorType; \
727727 //
728728
729729 template <> struct GraphTraits {
730 typedef MachineBasicBlock NodeType;
731730 typedef MachineBasicBlock *NodeRef;
732731 typedef MachineBasicBlock::succ_iterator ChildIteratorType;
733732
734 static NodeType *getEntryNode(MachineBasicBlock *BB) { return BB; }
735 static inline ChildIteratorType child_begin(NodeType *N) {
733 static NodeRef getEntryNode(MachineBasicBlock *BB) { return BB; }
734 static inline ChildIteratorType child_begin(NodeRef N) {
736735 return N->succ_begin();
737736 }
738 static inline ChildIteratorType child_end(NodeType *N) {
739 return N->succ_end();
740 }
737 static inline ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
741738 };
742739
743740 template <> struct GraphTraits {
744 typedef const MachineBasicBlock NodeType;
745741 typedef const MachineBasicBlock *NodeRef;
746742 typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
747743
748 static NodeType *getEntryNode(const MachineBasicBlock *BB) { return BB; }
749 static inline ChildIteratorType child_begin(NodeType *N) {
744 static NodeRef getEntryNode(const MachineBasicBlock *BB) { return BB; }
745 static inline ChildIteratorType child_begin(NodeRef N) {
750746 return N->succ_begin();
751747 }
752 static inline ChildIteratorType child_end(NodeType *N) {
753 return N->succ_end();
754 }
748 static inline ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
755749 };
756750
757751 // Provide specializations of GraphTraits to be able to treat a
761755 // instead of the successor edges.
762756 //
763757 template <> struct GraphTraits > {
764 typedef MachineBasicBlock NodeType;
765758 typedef MachineBasicBlock *NodeRef;
766759 typedef MachineBasicBlock::pred_iterator ChildIteratorType;
767 static NodeType *getEntryNode(Inverse G) {
760 static NodeRef getEntryNode(Inverse G) {
768761 return G.Graph;
769762 }
770 static inline ChildIteratorType child_begin(NodeType *N) {
763 static inline ChildIteratorType child_begin(NodeRef N) {
771764 return N->pred_begin();
772765 }
773 static inline ChildIteratorType child_end(NodeType *N) {
774 return N->pred_end();
775 }
766 static inline ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
776767 };
777768
778769 template <> struct GraphTraits > {
779 typedef const MachineBasicBlock NodeType;
780770 typedef const MachineBasicBlock *NodeRef;
781771 typedef MachineBasicBlock::const_pred_iterator ChildIteratorType;
782 static NodeType *getEntryNode(Inverse*> G) {
772 static NodeRef getEntryNode(Inverse*> G) {
783773 return G.Graph;
784774 }
785 static inline ChildIteratorType child_begin(NodeType *N) {
775 static inline ChildIteratorType child_begin(NodeRef N) {
786776 return N->pred_begin();
787777 }
788 static inline ChildIteratorType child_end(NodeType *N) {
789 return N->pred_end();
790 }
778 static inline ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
791779 };
792780
793781
270270
271271 template
272272 struct MachineDomTreeGraphTraitsBase {
273 typedef Node NodeType;
274273 typedef Node *NodeRef;
275274 typedef ChildIterator ChildIteratorType;
276275
277 static NodeType *getEntryNode(NodeType *N) { return N; }
278 static inline ChildIteratorType child_begin(NodeType *N) {
279 return N->begin();
280 }
281 static inline ChildIteratorType child_end(NodeType *N) { return N->end(); }
276 static NodeRef getEntryNode(NodeRef N) { return N; }
277 static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
278 static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
282279 };
283280
284281 template struct GraphTraits;
296293
297294 template <> struct GraphTraits
298295 : public GraphTraits {
299 static NodeType *getEntryNode(MachineDominatorTree *DT) {
296 static NodeRef getEntryNode(MachineDominatorTree *DT) {
300297 return DT->getRootNode();
301298 }
302299 };
613613 //
614614 template <> struct GraphTraits :
615615 public GraphTraits {
616 static NodeType *getEntryNode(MachineFunction *F) {
617 return &F->front();
618 }
616 static NodeRef getEntryNode(MachineFunction *F) { return &F->front(); }
619617
620618 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
621619 typedef pointer_iterator nodes_iterator;
629627 };
630628 template <> struct GraphTraits :
631629 public GraphTraits {
632 static NodeType *getEntryNode(const MachineFunction *F) {
633 return &F->front();
634 }
630 static NodeRef getEntryNode(const MachineFunction *F) { return &F->front(); }
635631
636632 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
637633 typedef pointer_iterator nodes_iterator;
654650 //
655651 template <> struct GraphTraits > :
656652 public GraphTraits > {
657 static NodeType *getEntryNode(Inverse*> G) {
653 static NodeRef getEntryNode(Inverse*> G) {
658654 return &G.Graph->front();
659655 }
660656 };
661657 template <> struct GraphTraits > :
662658 public GraphTraits > {
663 static NodeType *getEntryNode(Inverse G) {
659 static NodeRef getEntryNode(Inverse G) {
664660 return &G.Graph->front();
665661 }
666662 };
161161
162162 // Allow clients to walk the list of nested loops...
163163 template <> struct GraphTraits {
164 typedef const MachineLoop NodeType;
165164 typedef const MachineLoop *NodeRef;
166165 typedef MachineLoopInfo::iterator ChildIteratorType;
167166
168 static NodeType *getEntryNode(const MachineLoop *L) { return L; }
169 static inline ChildIteratorType child_begin(NodeType *N) {
170 return N->begin();
171 }
172 static inline ChildIteratorType child_end(NodeType *N) {
173 return N->end();
174 }
167 static NodeRef getEntryNode(const MachineLoop *L) { return L; }
168 static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
169 static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
175170 };
176171
177172 template <> struct GraphTraits {
178 typedef MachineLoop NodeType;
179173 typedef MachineLoop *NodeRef;
180174 typedef MachineLoopInfo::iterator ChildIteratorType;
181175
182 static NodeType *getEntryNode(MachineLoop *L) { return L; }
183 static inline ChildIteratorType child_begin(NodeType *N) {
184 return N->begin();
185 }
186 static inline ChildIteratorType child_end(NodeType *N) {
187 return N->end();
188 }
176 static NodeRef getEntryNode(MachineLoop *L) { return L; }
177 static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
178 static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
189179 };
190180
191181 } // End llvm namespace
141141
142142 template <> struct GraphTraits
143143 : public GraphTraits > {
144 typedef df_iterator, false,
145 GraphTraits > > nodes_iterator;
144 typedef df_iterator, false,
145 GraphTraits>>
146 nodes_iterator;
146147
147 static NodeType *getEntryNode(MachineRegionInfo *RI) {
148 static NodeRef getEntryNode(MachineRegionInfo *RI) {
148149 return GraphTraits >::getEntryNode(RI->getTopLevelRegion());
149150 }
150151 static nodes_iterator nodes_begin(MachineRegionInfo* RI) {
157158
158159 template <> struct GraphTraits
159160 : public GraphTraits {
160 typedef df_iterator, false,
161 GraphTraits > > nodes_iterator;
161 typedef df_iterator, false,
162 GraphTraits>>
163 nodes_iterator;
162164
163 static NodeType *getEntryNode(MachineRegionInfoPass *RI) {
165 static NodeRef getEntryNode(MachineRegionInfoPass *RI) {
164166 return GraphTraits::getEntryNode(&RI->getRegionInfo());
165167 }
166168 static nodes_iterator nodes_begin(MachineRegionInfoPass* RI) {
678678 };
679679
680680 template <> struct GraphTraits {
681 typedef SUnit NodeType;
682681 typedef SUnit *NodeRef;
683682 typedef SUnitIterator ChildIteratorType;
684 static inline NodeType *getEntryNode(SUnit *N) { return N; }
685 static inline ChildIteratorType child_begin(NodeType *N) {
683 static inline NodeRef getEntryNode(SUnit *N) { return N; }
684 static inline ChildIteratorType child_begin(NodeRef N) {
686685 return SUnitIterator::begin(N);
687686 }
688 static inline ChildIteratorType child_end(NodeType *N) {
687 static inline ChildIteratorType child_end(NodeRef N) {
689688 return SUnitIterator::end(N);
690689 }
691690 };
20542054 };
20552055
20562056 template <> struct GraphTraits {
2057 typedef SDNode NodeType;
20582057 typedef SDNode *NodeRef;
20592058 typedef SDNodeIterator ChildIteratorType;
2060 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2061 static inline ChildIteratorType child_begin(NodeType *N) {
2059 static inline NodeRef getEntryNode(SDNode *N) { return N; }
2060 static inline ChildIteratorType child_begin(NodeRef N) {
20622061 return SDNodeIterator::begin(N);
20632062 }
2064 static inline ChildIteratorType child_end(NodeType *N) {
2063 static inline ChildIteratorType child_end(NodeRef N) {
20652064 return SDNodeIterator::end(N);
20662065 }
20672066 };
153153 // graph of basic blocks...
154154
155155 template <> struct GraphTraits {
156 typedef BasicBlock NodeType;
157156 typedef BasicBlock *NodeRef;
158157 typedef succ_iterator ChildIteratorType;
159158
160 static NodeType *getEntryNode(BasicBlock *BB) { return BB; }
161 static inline ChildIteratorType child_begin(NodeType *N) {
159 static NodeRef getEntryNode(BasicBlock *BB) { return BB; }
160 static inline ChildIteratorType child_begin(NodeRef N) {
162161 return succ_begin(N);
163162 }
164 static inline ChildIteratorType child_end(NodeType *N) {
165 return succ_end(N);
166 }
163 static inline ChildIteratorType child_end(NodeRef N) { return succ_end(N); }
167164 };
168165
169166 template <> struct GraphTraits {
170 typedef const BasicBlock NodeType;
171167 typedef const BasicBlock *NodeRef;
172168 typedef succ_const_iterator ChildIteratorType;
173169
174 static NodeType *getEntryNode(const BasicBlock *BB) { return BB; }
175
176 static inline ChildIteratorType child_begin(NodeType *N) {
170 static NodeRef getEntryNode(const BasicBlock *BB) { return BB; }
171
172 static inline ChildIteratorType child_begin(NodeRef N) {
177173 return succ_begin(N);
178174 }
179 static inline ChildIteratorType child_end(NodeType *N) {
180 return succ_end(N);
181 }
175 static inline ChildIteratorType child_end(NodeRef N) { return succ_end(N); }
182176 };
183177
184178 // Provide specializations of GraphTraits to be able to treat a function as a
187181 // instead of the successor edges.
188182 //
189183 template <> struct GraphTraits > {
190 typedef BasicBlock NodeType;
191184 typedef BasicBlock *NodeRef;
192185 typedef pred_iterator ChildIteratorType;
193 static NodeType *getEntryNode(Inverse G) { return G.Graph; }
194 static inline ChildIteratorType child_begin(NodeType *N) {
186 static NodeRef getEntryNode(Inverse G) { return G.Graph; }
187 static inline ChildIteratorType child_begin(NodeRef N) {
195188 return pred_begin(N);
196189 }
197 static inline ChildIteratorType child_end(NodeType *N) {
198 return pred_end(N);
199 }
190 static inline ChildIteratorType child_end(NodeRef N) { return pred_end(N); }
200191 };
201192
202193 template <> struct GraphTraits > {
203 typedef const BasicBlock NodeType;
204194 typedef const BasicBlock *NodeRef;
205195 typedef const_pred_iterator ChildIteratorType;
206 static NodeType *getEntryNode(Inverse G) {
207 return G.Graph;
208 }
209 static inline ChildIteratorType child_begin(NodeType *N) {
196 static NodeRef getEntryNode(Inverse G) { return G.Graph; }
197 static inline ChildIteratorType child_begin(NodeRef N) {
210198 return pred_begin(N);
211199 }
212 static inline ChildIteratorType child_end(NodeType *N) {
213 return pred_end(N);
214 }
200 static inline ChildIteratorType child_end(NodeRef N) { return pred_end(N); }
215201 };
216202
217203
225211 // except that the root node is implicitly the first node of the function.
226212 //
227213 template <> struct GraphTraits : public GraphTraits {
228 static NodeType *getEntryNode(Function *F) { return &F->getEntryBlock(); }
214 static NodeRef getEntryNode(Function *F) { return &F->getEntryBlock(); }
229215
230216 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
231217 typedef pointer_iterator nodes_iterator;
239225 };
240226 template <> struct GraphTraits :
241227 public GraphTraits {
242 static NodeType *getEntryNode(const Function *F) {return &F->getEntryBlock();}
228 static NodeRef getEntryNode(const Function *F) { return &F->getEntryBlock(); }
243229
244230 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
245231 typedef pointer_iterator nodes_iterator;
260246 //
261247 template <> struct GraphTraits > :
262248 public GraphTraits > {
263 static NodeType *getEntryNode(Inverse*> G) {
249 static NodeRef getEntryNode(Inverse*> G) {
264250 return &G.Graph->getEntryBlock();
265251 }
266252 };
267253 template <> struct GraphTraits > :
268254 public GraphTraits > {
269 static NodeType *getEntryNode(Inverse G) {
255 static NodeRef getEntryNode(Inverse G) {
270256 return &G.Graph->getEntryBlock();
271257 }
272258 };
154154 // iterable by generic graph iterators.
155155
156156 template struct DomTreeGraphTraitsBase {
157 typedef Node NodeType;
158157 typedef Node *NodeRef;
159158 typedef ChildIterator ChildIteratorType;
160 typedef df_iterator> nodes_iterator;
161
162 static NodeType *getEntryNode(NodeType *N) { return N; }
163 static inline ChildIteratorType child_begin(NodeType *N) {
164 return N->begin();
165 }
166 static inline ChildIteratorType child_end(NodeType *N) { return N->end(); }
167
168 static nodes_iterator nodes_begin(NodeType *N) {
159 typedef df_iterator> nodes_iterator;
160
161 static NodeRef getEntryNode(NodeRef N) { return N; }
162 static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
163 static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
164
165 static nodes_iterator nodes_begin(NodeRef N) {
169166 return df_begin(getEntryNode(N));
170167 }
171168
172 static nodes_iterator nodes_end(NodeType *N) {
173 return df_end(getEntryNode(N));
174 }
169 static nodes_iterator nodes_end(NodeRef N) { return df_end(getEntryNode(N)); }
175170 };
176171
177172 template <>
185180
186181 template <> struct GraphTraits
187182 : public GraphTraits {
188 static NodeType *getEntryNode(DominatorTree *DT) {
189 return DT->getRootNode();
190 }
183 static NodeRef getEntryNode(DominatorTree *DT) { return DT->getRootNode(); }
191184
192185 static nodes_iterator nodes_begin(DominatorTree *N) {
193186 return df_begin(getEntryNode(N));
428428 // graph of sub types.
429429
430430 template <> struct GraphTraits {
431 typedef Type NodeType;
432431 typedef Type *NodeRef;
433432 typedef Type::subtype_iterator ChildIteratorType;
434433
435 static inline NodeType *getEntryNode(Type *T) { return T; }
436 static inline ChildIteratorType child_begin(NodeType *N) {
434 static inline NodeRef getEntryNode(Type *T) { return T; }
435 static inline ChildIteratorType child_begin(NodeRef N) {
437436 return N->subtype_begin();
438437 }
439 static inline ChildIteratorType child_end(NodeType *N) {
438 static inline ChildIteratorType child_end(NodeRef N) {
440439 return N->subtype_end();
441440 }
442441 };
443442
444443 template <> struct GraphTraits {
445 typedef const Type NodeType;
446444 typedef const Type *NodeRef;
447445 typedef Type::subtype_iterator ChildIteratorType;
448446
449 static inline NodeType *getEntryNode(NodeType *T) { return T; }
450 static inline ChildIteratorType child_begin(NodeType *N) {
447 static inline NodeRef getEntryNode(NodeRef T) { return T; }
448 static inline ChildIteratorType child_begin(NodeRef N) {
451449 return N->subtype_begin();
452450 }
453 static inline ChildIteratorType child_end(NodeType *N) {
451 static inline ChildIteratorType child_end(NodeRef N) {
454452 return N->subtype_end();
455453 }
456454 };
875875 /// \brief GraphTraits for a MemoryAccess, which walks defs in the normal case,
876876 /// and uses in the inverse case.
877877 template <> struct GraphTraits {
878 using NodeType = MemoryAccess;
878 using NodeRef = MemoryAccess *;
879879 using ChildIteratorType = memoryaccess_def_iterator;
880880
881 static NodeType *getEntryNode(NodeType *N) { return N; }
882 static inline ChildIteratorType child_begin(NodeType *N) {
881 static NodeRef getEntryNode(NodeRef N) { return N; }
882 static inline ChildIteratorType child_begin(NodeRef N) {
883883 return N->defs_begin();
884884 }
885 static inline ChildIteratorType child_end(NodeType *N) {
886 return N->defs_end();
887 }
885 static inline ChildIteratorType child_end(NodeRef N) { return N->defs_end(); }
888886 };
889887
890888 template <> struct GraphTraits> {
891 using NodeType = MemoryAccess;
889 using NodeRef = MemoryAccess *;
892890 using ChildIteratorType = MemoryAccess::iterator;
893891
894 static NodeType *getEntryNode(NodeType *N) { return N; }
895 static inline ChildIteratorType child_begin(NodeType *N) {
892 static NodeRef getEntryNode(NodeRef N) { return N; }
893 static inline ChildIteratorType child_begin(NodeRef N) {
896894 return N->user_begin();
897895 }
898 static inline ChildIteratorType child_end(NodeType *N) {
899 return N->user_end();
900 }
896 static inline ChildIteratorType child_end(NodeRef N) { return N->user_end(); }
901897 };
902898
903899 /// \brief Provide an iterator that walks defs, giving both the memory access,
5959
6060 template <>
6161 struct GraphTraits {
62 typedef const BasicBlock NodeType;
6362 typedef const BasicBlock *NodeRef;
6463 typedef succ_const_iterator ChildIteratorType;
6564 typedef pointer_iterator nodes_iterator;
6665
67 static inline const NodeType *getEntryNode(const BlockFrequencyInfo *G) {
66 static inline NodeRef getEntryNode(const BlockFrequencyInfo *G) {
6867 return &G->getFunction()->front();
6968 }
70 static ChildIteratorType child_begin(const NodeType *N) {
69 static ChildIteratorType child_begin(const NodeRef N) {
7170 return succ_begin(N);
7271 }
73 static ChildIteratorType child_end(const NodeType *N) {
74 return succ_end(N);
75 }
72 static ChildIteratorType child_end(const NodeRef N) { return succ_end(N); }
7673 static nodes_iterator nodes_begin(const BlockFrequencyInfo *G) {
7774 return nodes_iterator(G->getFunction()->begin());
7875 }
627627 template <> struct GraphTraits {
628628 typedef bfi_detail::IrreducibleGraph GraphT;
629629
630 typedef const GraphT::IrrNode NodeType;
631630 typedef const GraphT::IrrNode *NodeRef;
632631 typedef GraphT::IrrNode::iterator ChildIteratorType;
633632
634 static const NodeType *getEntryNode(const GraphT &G) {
635 return G.StartIrr;
636 }
637 static ChildIteratorType child_begin(NodeType *N) { return N->succ_begin(); }
638 static ChildIteratorType child_end(NodeType *N) { return N->succ_end(); }
633 static NodeRef getEntryNode(const GraphT &G) { return G.StartIrr; }
634 static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
635 static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
639636 };
640637 } // end namespace llvm
641638
5151 namespace llvm {
5252
5353 template <> struct GraphTraits {
54 typedef const MachineBasicBlock NodeType;
5554 typedef const MachineBasicBlock *NodeRef;
5655 typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
5756 typedef pointer_iterator nodes_iterator;
5857
59 static inline const NodeType *
60 getEntryNode(const MachineBlockFrequencyInfo *G) {
58 static inline NodeRef getEntryNode(const MachineBlockFrequencyInfo *G) {
6159 return &G->getFunction()->front();
6260 }
6361
64 static ChildIteratorType child_begin(const NodeType *N) {
62 static ChildIteratorType child_begin(const NodeRef N) {
6563 return N->succ_begin();
6664 }
6765
68 static ChildIteratorType child_end(const NodeType *N) {
69 return N->succ_end();
70 }
66 static ChildIteratorType child_end(const NodeRef N) { return N->succ_end(); }
7167
7268 static nodes_iterator nodes_begin(const MachineBlockFrequencyInfo *G) {
7369 return nodes_iterator(G->getFunction()->begin());
331331
332332 namespace llvm {
333333 template <> struct GraphTraits {
334 typedef ArgumentGraphNode NodeType;
335334 typedef ArgumentGraphNode *NodeRef;
336335 typedef SmallVectorImpl::iterator ChildIteratorType;
337336
338 static inline NodeType *getEntryNode(NodeType *A) { return A; }
339 static inline ChildIteratorType child_begin(NodeType *N) {
337 static inline NodeRef getEntryNode(NodeRef A) { return A; }
338 static inline ChildIteratorType child_begin(NodeRef N) {
340339 return N->Uses.begin();
341340 }
342 static inline ChildIteratorType child_end(NodeType *N) {
343 return N->Uses.end();
344 }
341 static inline ChildIteratorType child_end(NodeRef N) { return N->Uses.end(); }
345342 };
346343 template <>
347344 struct GraphTraits : public GraphTraits {
348 static NodeType *getEntryNode(ArgumentGraph *AG) {
349 return AG->getEntryNode();
350 }
345 static NodeRef getEntryNode(ArgumentGraph *AG) { return AG->getEntryNode(); }
351346 static ChildIteratorType nodes_begin(ArgumentGraph *AG) {
352347 return AG->begin();
353348 }
228228
229229 template
230230 struct GraphTraits > {
231 typedef typename Graph::NodeType NodeType;
232231 typedef typename Graph::NodeType *NodeRef;
233232 typedef typename Graph::ChildIterator ChildIteratorType;
234233
235 static inline NodeType *getEntryNode(const Graph &G) { return G.AccessNode(0); }
236 static inline ChildIteratorType child_begin(NodeType *Node) {
237 return Graph::child_begin(Node);
234 static inline NodeRef getEntryNode(const Graph &G) {
235 return G.AccessNode(0);
236 }
237 static inline ChildIteratorType child_begin(NodeRef Node) {
238 return Graph::child_begin(Node);
238239 }
239 static inline ChildIteratorType child_end(NodeType *Node) {
240 static inline ChildIteratorType child_end(NodeRef Node) {
240241 return Graph::child_end(Node);
241242 }
242243 };
1616 namespace {
1717
1818 template void canSpecializeGraphTraitsIterators(Ty *G) {
19 typedef typename GraphTraits::NodeType NodeTy;
19 typedef typename GraphTraits::NodeRef NodeRef;
2020
2121 auto I = GraphTraits::nodes_begin(G);
2222 auto E = GraphTraits::nodes_end(G);
2323 auto X = ++I;
2424
2525 // Should be able to iterate over all nodes of the graph.
26 static_assert(std::is_sameTy *>::value,
26 static_assert(std::is_sameRef>::value,
2727 "Node type does not match");
28 static_assert(std::is_sameTy *>::value,
28 static_assert(std::is_sameRef>::value,
2929 "Node type does not match");
30 static_assert(std::is_sameTy *>::value,
30 static_assert(std::is_sameRef>::value,
3131 "Node type does not match");
3232
33 NodeTy *N = GraphTraits::getEntryNode(G);
33 NodeRef N = GraphTraits::getEntryNode(G);
3434
35 auto S = GraphTraits::child_begin(N);
36 auto F = GraphTraits::child_end(N);
35 auto S = GraphTraits::child_begin(N);
36 auto F = GraphTraits::child_end(N);
3737
3838 // Should be able to iterate over immediate successors of a node.
39 static_assert(std::is_sameTy *>::value,
39 static_assert(std::is_sameRef>::value,
4040 "Node type does not match");
41 static_assert(std::is_sameTy *>::value,
41 static_assert(std::is_sameRef>::value,
4242 "Node type does not match");
4343 }
4444