Skip to content

Commit 22fca38

Browse files
committed
[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
1 parent d47df87 commit 22fca38

24 files changed

+141
-234
lines changed

include/llvm/ADT/GraphTraits.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,10 @@ template<class GraphType>
2727
struct GraphTraits {
2828
// Elements to provide:
2929

30-
// NOTICE: We are in a transition from migration interfaces that require
31-
// NodeType *, to NodeRef. NodeRef is required to be cheap to copy, but does
32-
// not have to be a raw pointer. In the transition, user should define
33-
// NodeType, and NodeRef = NodeType *.
34-
//
35-
// typedef NodeType - Type of Node in the graph
36-
// typedef NodeRef - NodeType *
30+
// typedef NodeRef - Type of Node token in the graph, which should
31+
// be cheap to copy.
3732
// typedef ChildIteratorType - Type used to iterate over children in graph,
38-
// dereference to a NodeRef
33+
// dereference to a NodeRef.
3934

4035
// static NodeRef getEntryNode(const GraphType &)
4136
// Return the entry node of the graph

include/llvm/Analysis/CallGraph.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -409,50 +409,48 @@ class CallGraphWrapperPass : public ModulePass {
409409
// Provide graph traits for tranversing call graphs using standard graph
410410
// traversals.
411411
template <> struct GraphTraits<CallGraphNode *> {
412-
typedef CallGraphNode NodeType;
413412
typedef CallGraphNode *NodeRef;
414413

415414
typedef CallGraphNode::CallRecord CGNPairTy;
416415

417-
static NodeType *getEntryNode(CallGraphNode *CGN) { return CGN; }
416+
static NodeRef getEntryNode(CallGraphNode *CGN) { return CGN; }
418417

419418
static CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
420419

421-
typedef mapped_iterator<NodeType::iterator, decltype(&CGNGetValue)>
420+
typedef mapped_iterator<CallGraphNode::iterator, decltype(&CGNGetValue)>
422421
ChildIteratorType;
423422

424-
static inline ChildIteratorType child_begin(NodeType *N) {
423+
static inline ChildIteratorType child_begin(NodeRef N) {
425424
return ChildIteratorType(N->begin(), &CGNGetValue);
426425
}
427-
static inline ChildIteratorType child_end(NodeType *N) {
426+
static inline ChildIteratorType child_end(NodeRef N) {
428427
return ChildIteratorType(N->end(), &CGNGetValue);
429428
}
430429
};
431430

432431
template <> struct GraphTraits<const CallGraphNode *> {
433-
typedef const CallGraphNode NodeType;
434432
typedef const CallGraphNode *NodeRef;
435433

436434
typedef CallGraphNode::CallRecord CGNPairTy;
437435

438-
static NodeType *getEntryNode(const CallGraphNode *CGN) { return CGN; }
436+
static NodeRef getEntryNode(const CallGraphNode *CGN) { return CGN; }
439437

440438
static const CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
441439

442-
typedef mapped_iterator<NodeType::const_iterator, decltype(&CGNGetValue)>
440+
typedef mapped_iterator<CallGraphNode::const_iterator, decltype(&CGNGetValue)>
443441
ChildIteratorType;
444442

445-
static inline ChildIteratorType child_begin(NodeType *N) {
443+
static inline ChildIteratorType child_begin(NodeRef N) {
446444
return ChildIteratorType(N->begin(), &CGNGetValue);
447445
}
448-
static inline ChildIteratorType child_end(NodeType *N) {
446+
static inline ChildIteratorType child_end(NodeRef N) {
449447
return ChildIteratorType(N->end(), &CGNGetValue);
450448
}
451449
};
452450

453451
template <>
454452
struct GraphTraits<CallGraph *> : public GraphTraits<CallGraphNode *> {
455-
static NodeType *getEntryNode(CallGraph *CGN) {
453+
static NodeRef getEntryNode(CallGraph *CGN) {
456454
return CGN->getExternalCallingNode(); // Start at the external node!
457455
}
458456
typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
@@ -475,7 +473,7 @@ struct GraphTraits<CallGraph *> : public GraphTraits<CallGraphNode *> {
475473
template <>
476474
struct GraphTraits<const CallGraph *> : public GraphTraits<
477475
const CallGraphNode *> {
478-
static NodeType *getEntryNode(const CallGraph *CGN) {
476+
static NodeRef getEntryNode(const CallGraph *CGN) {
479477
return CGN->getExternalCallingNode(); // Start at the external node!
480478
}
481479
typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>

include/llvm/Analysis/Interval.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,30 +121,26 @@ inline Interval::pred_iterator pred_end(Interval *I) {
121121
}
122122

123123
template <> struct GraphTraits<Interval*> {
124-
typedef Interval NodeType;
124+
typedef Interval *NodeRef;
125125
typedef Interval::succ_iterator ChildIteratorType;
126126

127-
static NodeType *getEntryNode(Interval *I) { return I; }
127+
static NodeRef getEntryNode(Interval *I) { return I; }
128128

129129
/// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
130-
static inline ChildIteratorType child_begin(NodeType *N) {
130+
static inline ChildIteratorType child_begin(NodeRef N) {
131131
return succ_begin(N);
132132
}
133-
static inline ChildIteratorType child_end(NodeType *N) {
134-
return succ_end(N);
135-
}
133+
static inline ChildIteratorType child_end(NodeRef N) { return succ_end(N); }
136134
};
137135

138136
template <> struct GraphTraits<Inverse<Interval*> > {
139-
typedef Interval NodeType;
137+
typedef Interval *NodeRef;
140138
typedef Interval::pred_iterator ChildIteratorType;
141-
static NodeType *getEntryNode(Inverse<Interval *> G) { return G.Graph; }
142-
static inline ChildIteratorType child_begin(NodeType *N) {
139+
static NodeRef getEntryNode(Inverse<Interval *> G) { return G.Graph; }
140+
static inline ChildIteratorType child_begin(NodeRef N) {
143141
return pred_begin(N);
144142
}
145-
static inline ChildIteratorType child_end(NodeType *N) {
146-
return pred_end(N);
147-
}
143+
static inline ChildIteratorType child_end(NodeRef N) { return pred_end(N); }
148144
};
149145

150146
} // End llvm namespace

include/llvm/Analysis/LazyCallGraph.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -953,20 +953,20 @@ inline LazyCallGraph::Node &LazyCallGraph::Edge::getNode(LazyCallGraph &G) {
953953

954954
// Provide GraphTraits specializations for call graphs.
955955
template <> struct GraphTraits<LazyCallGraph::Node *> {
956-
typedef LazyCallGraph::Node NodeType;
956+
typedef LazyCallGraph::Node *NodeRef;
957957
typedef LazyCallGraph::edge_iterator ChildIteratorType;
958958

959-
static NodeType *getEntryNode(NodeType *N) { return N; }
960-
static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
961-
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
959+
static NodeRef getEntryNode(NodeRef N) { return N; }
960+
static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
961+
static ChildIteratorType child_end(NodeRef N) { return N->end(); }
962962
};
963963
template <> struct GraphTraits<LazyCallGraph *> {
964-
typedef LazyCallGraph::Node NodeType;
964+
typedef LazyCallGraph::Node *NodeRef;
965965
typedef LazyCallGraph::edge_iterator ChildIteratorType;
966966

967-
static NodeType *getEntryNode(NodeType *N) { return N; }
968-
static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
969-
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
967+
static NodeRef getEntryNode(NodeRef N) { return N; }
968+
static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
969+
static ChildIteratorType child_end(NodeRef N) { return N->end(); }
970970
};
971971

972972
/// An analysis pass which computes the call graph for a module.

include/llvm/Analysis/LoopInfo.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -761,31 +761,21 @@ class LoopInfo : public LoopInfoBase<BasicBlock, Loop> {
761761

762762
// Allow clients to walk the list of nested loops...
763763
template <> struct GraphTraits<const Loop*> {
764-
typedef const Loop NodeType;
765764
typedef const Loop *NodeRef;
766765
typedef LoopInfo::iterator ChildIteratorType;
767766

768-
static NodeType *getEntryNode(const Loop *L) { return L; }
769-
static inline ChildIteratorType child_begin(NodeType *N) {
770-
return N->begin();
771-
}
772-
static inline ChildIteratorType child_end(NodeType *N) {
773-
return N->end();
774-
}
767+
static NodeRef getEntryNode(const Loop *L) { return L; }
768+
static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
769+
static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
775770
};
776771

777772
template <> struct GraphTraits<Loop*> {
778-
typedef Loop NodeType;
779773
typedef Loop *NodeRef;
780774
typedef LoopInfo::iterator ChildIteratorType;
781775

782-
static NodeType *getEntryNode(Loop *L) { return L; }
783-
static inline ChildIteratorType child_begin(NodeType *N) {
784-
return N->begin();
785-
}
786-
static inline ChildIteratorType child_end(NodeType *N) {
787-
return N->end();
788-
}
776+
static NodeRef getEntryNode(Loop *L) { return L; }
777+
static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
778+
static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
789779
};
790780

791781
/// \brief Analysis pass that exposes the \c LoopInfo for a function.

include/llvm/Analysis/PostDominators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ FunctionPass* createPostDomTree();
8989

9090
template <> struct GraphTraits<PostDominatorTree*>
9191
: public GraphTraits<DomTreeNode*> {
92-
static NodeType *getEntryNode(PostDominatorTree *DT) {
92+
static NodeRef getEntryNode(PostDominatorTree *DT) {
9393
return DT->getRootNode();
9494
}
9595

include/llvm/Analysis/RegionIterator.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ inline RNSuccIterator<NodeRef, BlockT, RegionT> succ_end(NodeRef Node) {
255255

256256
#define RegionNodeGraphTraits(NodeT, BlockT, RegionT) \
257257
template <> struct GraphTraits<NodeT *> { \
258-
typedef NodeT NodeType; \
259258
typedef NodeT *NodeRef; \
260259
typedef RNSuccIterator<NodeRef, BlockT, RegionT> ChildIteratorType; \
261260
static NodeRef getEntryNode(NodeRef N) { return N; } \
@@ -267,7 +266,6 @@ inline RNSuccIterator<NodeRef, BlockT, RegionT> succ_end(NodeRef Node) {
267266
} \
268267
}; \
269268
template <> struct GraphTraits<FlatIt<NodeT *>> { \
270-
typedef NodeT NodeType; \
271269
typedef NodeT *NodeRef; \
272270
typedef RNSuccIterator<FlatIt<NodeRef>, BlockT, RegionT> \
273271
ChildIteratorType; \

include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -728,31 +728,25 @@ struct MBB2NumberFunctor :
728728
//
729729

730730
template <> struct GraphTraits<MachineBasicBlock *> {
731-
typedef MachineBasicBlock NodeType;
732731
typedef MachineBasicBlock *NodeRef;
733732
typedef MachineBasicBlock::succ_iterator ChildIteratorType;
734733

735-
static NodeType *getEntryNode(MachineBasicBlock *BB) { return BB; }
736-
static inline ChildIteratorType child_begin(NodeType *N) {
734+
static NodeRef getEntryNode(MachineBasicBlock *BB) { return BB; }
735+
static inline ChildIteratorType child_begin(NodeRef N) {
737736
return N->succ_begin();
738737
}
739-
static inline ChildIteratorType child_end(NodeType *N) {
740-
return N->succ_end();
741-
}
738+
static inline ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
742739
};
743740

744741
template <> struct GraphTraits<const MachineBasicBlock *> {
745-
typedef const MachineBasicBlock NodeType;
746742
typedef const MachineBasicBlock *NodeRef;
747743
typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
748744

749-
static NodeType *getEntryNode(const MachineBasicBlock *BB) { return BB; }
750-
static inline ChildIteratorType child_begin(NodeType *N) {
745+
static NodeRef getEntryNode(const MachineBasicBlock *BB) { return BB; }
746+
static inline ChildIteratorType child_begin(NodeRef N) {
751747
return N->succ_begin();
752748
}
753-
static inline ChildIteratorType child_end(NodeType *N) {
754-
return N->succ_end();
755-
}
749+
static inline ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
756750
};
757751

758752
// Provide specializations of GraphTraits to be able to treat a
@@ -762,33 +756,27 @@ template <> struct GraphTraits<const MachineBasicBlock *> {
762756
// instead of the successor edges.
763757
//
764758
template <> struct GraphTraits<Inverse<MachineBasicBlock*> > {
765-
typedef MachineBasicBlock NodeType;
766759
typedef MachineBasicBlock *NodeRef;
767760
typedef MachineBasicBlock::pred_iterator ChildIteratorType;
768-
static NodeType *getEntryNode(Inverse<MachineBasicBlock *> G) {
761+
static NodeRef getEntryNode(Inverse<MachineBasicBlock *> G) {
769762
return G.Graph;
770763
}
771-
static inline ChildIteratorType child_begin(NodeType *N) {
764+
static inline ChildIteratorType child_begin(NodeRef N) {
772765
return N->pred_begin();
773766
}
774-
static inline ChildIteratorType child_end(NodeType *N) {
775-
return N->pred_end();
776-
}
767+
static inline ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
777768
};
778769

779770
template <> struct GraphTraits<Inverse<const MachineBasicBlock*> > {
780-
typedef const MachineBasicBlock NodeType;
781771
typedef const MachineBasicBlock *NodeRef;
782772
typedef MachineBasicBlock::const_pred_iterator ChildIteratorType;
783-
static NodeType *getEntryNode(Inverse<const MachineBasicBlock*> G) {
773+
static NodeRef getEntryNode(Inverse<const MachineBasicBlock *> G) {
784774
return G.Graph;
785775
}
786-
static inline ChildIteratorType child_begin(NodeType *N) {
776+
static inline ChildIteratorType child_begin(NodeRef N) {
787777
return N->pred_begin();
788778
}
789-
static inline ChildIteratorType child_end(NodeType *N) {
790-
return N->pred_end();
791-
}
779+
static inline ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
792780
};
793781

794782

include/llvm/CodeGen/MachineDominators.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,12 @@ class MachineDominatorTree : public MachineFunctionPass {
271271

272272
template <class Node, class ChildIterator>
273273
struct MachineDomTreeGraphTraitsBase {
274-
typedef Node NodeType;
275274
typedef Node *NodeRef;
276275
typedef ChildIterator ChildIteratorType;
277276

278-
static NodeType *getEntryNode(NodeType *N) { return N; }
279-
static inline ChildIteratorType child_begin(NodeType *N) {
280-
return N->begin();
281-
}
282-
static inline ChildIteratorType child_end(NodeType *N) { return N->end(); }
277+
static NodeRef getEntryNode(NodeRef N) { return N; }
278+
static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
279+
static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
283280
};
284281

285282
template <class T> struct GraphTraits;
@@ -297,7 +294,7 @@ struct GraphTraits<const MachineDomTreeNode *>
297294

298295
template <> struct GraphTraits<MachineDominatorTree*>
299296
: public GraphTraits<MachineDomTreeNode *> {
300-
static NodeType *getEntryNode(MachineDominatorTree *DT) {
297+
static NodeRef getEntryNode(MachineDominatorTree *DT) {
301298
return DT->getRootNode();
302299
}
303300
};

include/llvm/CodeGen/MachineFunction.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,7 @@ class MachineFunction {
614614
//
615615
template <> struct GraphTraits<MachineFunction*> :
616616
public GraphTraits<MachineBasicBlock*> {
617-
static NodeType *getEntryNode(MachineFunction *F) {
618-
return &F->front();
619-
}
617+
static NodeRef getEntryNode(MachineFunction *F) { return &F->front(); }
620618

621619
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
622620
typedef pointer_iterator<MachineFunction::iterator> nodes_iterator;
@@ -630,9 +628,7 @@ template <> struct GraphTraits<MachineFunction*> :
630628
};
631629
template <> struct GraphTraits<const MachineFunction*> :
632630
public GraphTraits<const MachineBasicBlock*> {
633-
static NodeType *getEntryNode(const MachineFunction *F) {
634-
return &F->front();
635-
}
631+
static NodeRef getEntryNode(const MachineFunction *F) { return &F->front(); }
636632

637633
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
638634
typedef pointer_iterator<MachineFunction::const_iterator> nodes_iterator;
@@ -655,13 +651,13 @@ template <> struct GraphTraits<const MachineFunction*> :
655651
//
656652
template <> struct GraphTraits<Inverse<MachineFunction*> > :
657653
public GraphTraits<Inverse<MachineBasicBlock*> > {
658-
static NodeType *getEntryNode(Inverse<MachineFunction*> G) {
654+
static NodeRef getEntryNode(Inverse<MachineFunction *> G) {
659655
return &G.Graph->front();
660656
}
661657
};
662658
template <> struct GraphTraits<Inverse<const MachineFunction*> > :
663659
public GraphTraits<Inverse<const MachineBasicBlock*> > {
664-
static NodeType *getEntryNode(Inverse<const MachineFunction *> G) {
660+
static NodeRef getEntryNode(Inverse<const MachineFunction *> G) {
665661
return &G.Graph->front();
666662
}
667663
};

0 commit comments

Comments
 (0)