Skip to content

Commit

Permalink
[GraphTraits] Replace all NodeType usage with NodeRef
Browse files Browse the repository at this point in the history
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
  • Loading branch information
timshen91 committed Aug 22, 2016
1 parent d47df87 commit 22fca38
Show file tree
Hide file tree
Showing 24 changed files with 141 additions and 234 deletions.
11 changes: 3 additions & 8 deletions include/llvm/ADT/GraphTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@ template<class GraphType>
struct GraphTraits {
// Elements to provide:

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

// static NodeRef getEntryNode(const GraphType &)
// Return the entry node of the graph
Expand Down
22 changes: 10 additions & 12 deletions include/llvm/Analysis/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,50 +409,48 @@ class CallGraphWrapperPass : public ModulePass {
// Provide graph traits for tranversing call graphs using standard graph
// traversals.
template <> struct GraphTraits<CallGraphNode *> {
typedef CallGraphNode NodeType;
typedef CallGraphNode *NodeRef;

typedef CallGraphNode::CallRecord CGNPairTy;

static NodeType *getEntryNode(CallGraphNode *CGN) { return CGN; }
static NodeRef getEntryNode(CallGraphNode *CGN) { return CGN; }

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

typedef mapped_iterator<NodeType::iterator, decltype(&CGNGetValue)>
typedef mapped_iterator<CallGraphNode::iterator, decltype(&CGNGetValue)>
ChildIteratorType;

static inline ChildIteratorType child_begin(NodeType *N) {
static inline ChildIteratorType child_begin(NodeRef N) {
return ChildIteratorType(N->begin(), &CGNGetValue);
}
static inline ChildIteratorType child_end(NodeType *N) {
static inline ChildIteratorType child_end(NodeRef N) {
return ChildIteratorType(N->end(), &CGNGetValue);
}
};

template <> struct GraphTraits<const CallGraphNode *> {
typedef const CallGraphNode NodeType;
typedef const CallGraphNode *NodeRef;

typedef CallGraphNode::CallRecord CGNPairTy;

static NodeType *getEntryNode(const CallGraphNode *CGN) { return CGN; }
static NodeRef getEntryNode(const CallGraphNode *CGN) { return CGN; }

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

typedef mapped_iterator<NodeType::const_iterator, decltype(&CGNGetValue)>
typedef mapped_iterator<CallGraphNode::const_iterator, decltype(&CGNGetValue)>
ChildIteratorType;

static inline ChildIteratorType child_begin(NodeType *N) {
static inline ChildIteratorType child_begin(NodeRef N) {
return ChildIteratorType(N->begin(), &CGNGetValue);
}
static inline ChildIteratorType child_end(NodeType *N) {
static inline ChildIteratorType child_end(NodeRef N) {
return ChildIteratorType(N->end(), &CGNGetValue);
}
};

template <>
struct GraphTraits<CallGraph *> : public GraphTraits<CallGraphNode *> {
static NodeType *getEntryNode(CallGraph *CGN) {
static NodeRef getEntryNode(CallGraph *CGN) {
return CGN->getExternalCallingNode(); // Start at the external node!
}
typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
Expand All @@ -475,7 +473,7 @@ struct GraphTraits<CallGraph *> : public GraphTraits<CallGraphNode *> {
template <>
struct GraphTraits<const CallGraph *> : public GraphTraits<
const CallGraphNode *> {
static NodeType *getEntryNode(const CallGraph *CGN) {
static NodeRef getEntryNode(const CallGraph *CGN) {
return CGN->getExternalCallingNode(); // Start at the external node!
}
typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
Expand Down
20 changes: 8 additions & 12 deletions include/llvm/Analysis/Interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,26 @@ inline Interval::pred_iterator pred_end(Interval *I) {
}

template <> struct GraphTraits<Interval*> {
typedef Interval NodeType;
typedef Interval *NodeRef;
typedef Interval::succ_iterator ChildIteratorType;

static NodeType *getEntryNode(Interval *I) { return I; }
static NodeRef getEntryNode(Interval *I) { return I; }

/// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
static inline ChildIteratorType child_begin(NodeType *N) {
static inline ChildIteratorType child_begin(NodeRef N) {
return succ_begin(N);
}
static inline ChildIteratorType child_end(NodeType *N) {
return succ_end(N);
}
static inline ChildIteratorType child_end(NodeRef N) { return succ_end(N); }
};

template <> struct GraphTraits<Inverse<Interval*> > {
typedef Interval NodeType;
typedef Interval *NodeRef;
typedef Interval::pred_iterator ChildIteratorType;
static NodeType *getEntryNode(Inverse<Interval *> G) { return G.Graph; }
static inline ChildIteratorType child_begin(NodeType *N) {
static NodeRef getEntryNode(Inverse<Interval *> G) { return G.Graph; }
static inline ChildIteratorType child_begin(NodeRef N) {
return pred_begin(N);
}
static inline ChildIteratorType child_end(NodeType *N) {
return pred_end(N);
}
static inline ChildIteratorType child_end(NodeRef N) { return pred_end(N); }
};

} // End llvm namespace
Expand Down
16 changes: 8 additions & 8 deletions include/llvm/Analysis/LazyCallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -953,20 +953,20 @@ inline LazyCallGraph::Node &LazyCallGraph::Edge::getNode(LazyCallGraph &G) {

// Provide GraphTraits specializations for call graphs.
template <> struct GraphTraits<LazyCallGraph::Node *> {
typedef LazyCallGraph::Node NodeType;
typedef LazyCallGraph::Node *NodeRef;
typedef LazyCallGraph::edge_iterator ChildIteratorType;

static NodeType *getEntryNode(NodeType *N) { return N; }
static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
static NodeRef getEntryNode(NodeRef N) { return N; }
static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
static ChildIteratorType child_end(NodeRef N) { return N->end(); }
};
template <> struct GraphTraits<LazyCallGraph *> {
typedef LazyCallGraph::Node NodeType;
typedef LazyCallGraph::Node *NodeRef;
typedef LazyCallGraph::edge_iterator ChildIteratorType;

static NodeType *getEntryNode(NodeType *N) { return N; }
static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
static NodeRef getEntryNode(NodeRef N) { return N; }
static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
static ChildIteratorType child_end(NodeRef N) { return N->end(); }
};

/// An analysis pass which computes the call graph for a module.
Expand Down
22 changes: 6 additions & 16 deletions include/llvm/Analysis/LoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,31 +761,21 @@ class LoopInfo : public LoopInfoBase<BasicBlock, Loop> {

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

static NodeType *getEntryNode(const Loop *L) { return L; }
static inline ChildIteratorType child_begin(NodeType *N) {
return N->begin();
}
static inline ChildIteratorType child_end(NodeType *N) {
return N->end();
}
static NodeRef getEntryNode(const Loop *L) { return L; }
static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
};

template <> struct GraphTraits<Loop*> {
typedef Loop NodeType;
typedef Loop *NodeRef;
typedef LoopInfo::iterator ChildIteratorType;

static NodeType *getEntryNode(Loop *L) { return L; }
static inline ChildIteratorType child_begin(NodeType *N) {
return N->begin();
}
static inline ChildIteratorType child_end(NodeType *N) {
return N->end();
}
static NodeRef getEntryNode(Loop *L) { return L; }
static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
};

/// \brief Analysis pass that exposes the \c LoopInfo for a function.
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/Analysis/PostDominators.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ FunctionPass* createPostDomTree();

template <> struct GraphTraits<PostDominatorTree*>
: public GraphTraits<DomTreeNode*> {
static NodeType *getEntryNode(PostDominatorTree *DT) {
static NodeRef getEntryNode(PostDominatorTree *DT) {
return DT->getRootNode();
}

Expand Down
2 changes: 0 additions & 2 deletions include/llvm/Analysis/RegionIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ inline RNSuccIterator<NodeRef, BlockT, RegionT> succ_end(NodeRef Node) {

#define RegionNodeGraphTraits(NodeT, BlockT, RegionT) \
template <> struct GraphTraits<NodeT *> { \
typedef NodeT NodeType; \
typedef NodeT *NodeRef; \
typedef RNSuccIterator<NodeRef, BlockT, RegionT> ChildIteratorType; \
static NodeRef getEntryNode(NodeRef N) { return N; } \
Expand All @@ -267,7 +266,6 @@ inline RNSuccIterator<NodeRef, BlockT, RegionT> succ_end(NodeRef Node) {
} \
}; \
template <> struct GraphTraits<FlatIt<NodeT *>> { \
typedef NodeT NodeType; \
typedef NodeT *NodeRef; \
typedef RNSuccIterator<FlatIt<NodeRef>, BlockT, RegionT> \
ChildIteratorType; \
Expand Down
36 changes: 12 additions & 24 deletions include/llvm/CodeGen/MachineBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,31 +728,25 @@ struct MBB2NumberFunctor :
//

template <> struct GraphTraits<MachineBasicBlock *> {
typedef MachineBasicBlock NodeType;
typedef MachineBasicBlock *NodeRef;
typedef MachineBasicBlock::succ_iterator ChildIteratorType;

static NodeType *getEntryNode(MachineBasicBlock *BB) { return BB; }
static inline ChildIteratorType child_begin(NodeType *N) {
static NodeRef getEntryNode(MachineBasicBlock *BB) { return BB; }
static inline ChildIteratorType child_begin(NodeRef N) {
return N->succ_begin();
}
static inline ChildIteratorType child_end(NodeType *N) {
return N->succ_end();
}
static inline ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
};

template <> struct GraphTraits<const MachineBasicBlock *> {
typedef const MachineBasicBlock NodeType;
typedef const MachineBasicBlock *NodeRef;
typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;

static NodeType *getEntryNode(const MachineBasicBlock *BB) { return BB; }
static inline ChildIteratorType child_begin(NodeType *N) {
static NodeRef getEntryNode(const MachineBasicBlock *BB) { return BB; }
static inline ChildIteratorType child_begin(NodeRef N) {
return N->succ_begin();
}
static inline ChildIteratorType child_end(NodeType *N) {
return N->succ_end();
}
static inline ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
};

// Provide specializations of GraphTraits to be able to treat a
Expand All @@ -762,33 +756,27 @@ template <> struct GraphTraits<const MachineBasicBlock *> {
// instead of the successor edges.
//
template <> struct GraphTraits<Inverse<MachineBasicBlock*> > {
typedef MachineBasicBlock NodeType;
typedef MachineBasicBlock *NodeRef;
typedef MachineBasicBlock::pred_iterator ChildIteratorType;
static NodeType *getEntryNode(Inverse<MachineBasicBlock *> G) {
static NodeRef getEntryNode(Inverse<MachineBasicBlock *> G) {
return G.Graph;
}
static inline ChildIteratorType child_begin(NodeType *N) {
static inline ChildIteratorType child_begin(NodeRef N) {
return N->pred_begin();
}
static inline ChildIteratorType child_end(NodeType *N) {
return N->pred_end();
}
static inline ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
};

template <> struct GraphTraits<Inverse<const MachineBasicBlock*> > {
typedef const MachineBasicBlock NodeType;
typedef const MachineBasicBlock *NodeRef;
typedef MachineBasicBlock::const_pred_iterator ChildIteratorType;
static NodeType *getEntryNode(Inverse<const MachineBasicBlock*> G) {
static NodeRef getEntryNode(Inverse<const MachineBasicBlock *> G) {
return G.Graph;
}
static inline ChildIteratorType child_begin(NodeType *N) {
static inline ChildIteratorType child_begin(NodeRef N) {
return N->pred_begin();
}
static inline ChildIteratorType child_end(NodeType *N) {
return N->pred_end();
}
static inline ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
};


Expand Down
11 changes: 4 additions & 7 deletions include/llvm/CodeGen/MachineDominators.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,12 @@ class MachineDominatorTree : public MachineFunctionPass {

template <class Node, class ChildIterator>
struct MachineDomTreeGraphTraitsBase {
typedef Node NodeType;
typedef Node *NodeRef;
typedef ChildIterator ChildIteratorType;

static NodeType *getEntryNode(NodeType *N) { return N; }
static inline ChildIteratorType child_begin(NodeType *N) {
return N->begin();
}
static inline ChildIteratorType child_end(NodeType *N) { return N->end(); }
static NodeRef getEntryNode(NodeRef N) { return N; }
static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
static inline ChildIteratorType child_end(NodeRef N) { return N->end(); }
};

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

template <> struct GraphTraits<MachineDominatorTree*>
: public GraphTraits<MachineDomTreeNode *> {
static NodeType *getEntryNode(MachineDominatorTree *DT) {
static NodeRef getEntryNode(MachineDominatorTree *DT) {
return DT->getRootNode();
}
};
Expand Down
12 changes: 4 additions & 8 deletions include/llvm/CodeGen/MachineFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,7 @@ class MachineFunction {
//
template <> struct GraphTraits<MachineFunction*> :
public GraphTraits<MachineBasicBlock*> {
static NodeType *getEntryNode(MachineFunction *F) {
return &F->front();
}
static NodeRef getEntryNode(MachineFunction *F) { return &F->front(); }

// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
typedef pointer_iterator<MachineFunction::iterator> nodes_iterator;
Expand All @@ -630,9 +628,7 @@ template <> struct GraphTraits<MachineFunction*> :
};
template <> struct GraphTraits<const MachineFunction*> :
public GraphTraits<const MachineBasicBlock*> {
static NodeType *getEntryNode(const MachineFunction *F) {
return &F->front();
}
static NodeRef getEntryNode(const MachineFunction *F) { return &F->front(); }

// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
typedef pointer_iterator<MachineFunction::const_iterator> nodes_iterator;
Expand All @@ -655,13 +651,13 @@ template <> struct GraphTraits<const MachineFunction*> :
//
template <> struct GraphTraits<Inverse<MachineFunction*> > :
public GraphTraits<Inverse<MachineBasicBlock*> > {
static NodeType *getEntryNode(Inverse<MachineFunction*> G) {
static NodeRef getEntryNode(Inverse<MachineFunction *> G) {
return &G.Graph->front();
}
};
template <> struct GraphTraits<Inverse<const MachineFunction*> > :
public GraphTraits<Inverse<const MachineBasicBlock*> > {
static NodeType *getEntryNode(Inverse<const MachineFunction *> G) {
static NodeRef getEntryNode(Inverse<const MachineFunction *> G) {
return &G.Graph->front();
}
};
Expand Down
Loading

0 comments on commit 22fca38

Please sign in to comment.