From 22fca38c9c9dac29366250f789e8cb60cd0a4fd0 Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Mon, 22 Aug 2016 21:09:30 +0000 Subject: [PATCH] [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 --- include/llvm/ADT/GraphTraits.h | 11 ++---- include/llvm/Analysis/CallGraph.h | 22 +++++------ include/llvm/Analysis/Interval.h | 20 ++++------ include/llvm/Analysis/LazyCallGraph.h | 16 ++++---- include/llvm/Analysis/LoopInfo.h | 22 +++-------- include/llvm/Analysis/PostDominators.h | 2 +- include/llvm/Analysis/RegionIterator.h | 2 - include/llvm/CodeGen/MachineBasicBlock.h | 36 ++++++------------ include/llvm/CodeGen/MachineDominators.h | 11 ++---- include/llvm/CodeGen/MachineFunction.h | 12 ++---- include/llvm/CodeGen/MachineLoopInfo.h | 22 +++-------- include/llvm/CodeGen/MachineRegionInfo.h | 14 ++++--- include/llvm/CodeGen/ScheduleDAG.h | 7 ++-- include/llvm/CodeGen/SelectionDAGNodes.h | 7 ++-- include/llvm/IR/CFG.h | 46 ++++++++--------------- include/llvm/IR/Dominators.h | 21 ++++------- include/llvm/IR/Type.h | 14 +++---- include/llvm/Transforms/Utils/MemorySSA.h | 20 ++++------ lib/Analysis/BlockFrequencyInfo.cpp | 9 ++--- lib/Analysis/BlockFrequencyInfoImpl.cpp | 9 ++--- lib/CodeGen/MachineBlockFrequencyInfo.cpp | 10 ++--- lib/Transforms/IPO/FunctionAttrs.cpp | 13 ++----- unittests/ADT/SCCIteratorTest.cpp | 11 +++--- unittests/Analysis/CallGraphTest.cpp | 18 ++++----- 24 files changed, 141 insertions(+), 234 deletions(-) diff --git a/include/llvm/ADT/GraphTraits.h b/include/llvm/ADT/GraphTraits.h index 7ca0134f0e6b..29bbcb010eee 100644 --- a/include/llvm/ADT/GraphTraits.h +++ b/include/llvm/ADT/GraphTraits.h @@ -27,15 +27,10 @@ template 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 diff --git a/include/llvm/Analysis/CallGraph.h b/include/llvm/Analysis/CallGraph.h index 54da6e8fc150..58e2a63557fa 100644 --- a/include/llvm/Analysis/CallGraph.h +++ b/include/llvm/Analysis/CallGraph.h @@ -409,50 +409,48 @@ class CallGraphWrapperPass : public ModulePass { // Provide graph traits for tranversing call graphs using standard graph // traversals. template <> struct GraphTraits { - 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 + typedef mapped_iterator 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 { - 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 + typedef mapped_iterator 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 : public GraphTraits { - static NodeType *getEntryNode(CallGraph *CGN) { + static NodeRef getEntryNode(CallGraph *CGN) { return CGN->getExternalCallingNode(); // Start at the external node! } typedef std::pair> @@ -475,7 +473,7 @@ struct GraphTraits : public GraphTraits { template <> struct GraphTraits : 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> diff --git a/include/llvm/Analysis/Interval.h b/include/llvm/Analysis/Interval.h index a904753adaab..d16406f096b1 100644 --- a/include/llvm/Analysis/Interval.h +++ b/include/llvm/Analysis/Interval.h @@ -121,30 +121,26 @@ inline Interval::pred_iterator pred_end(Interval *I) { } template <> struct GraphTraits { - 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 > { - typedef Interval NodeType; + typedef Interval *NodeRef; typedef Interval::pred_iterator ChildIteratorType; - static NodeType *getEntryNode(Inverse G) { return G.Graph; } - static inline ChildIteratorType child_begin(NodeType *N) { + static NodeRef getEntryNode(Inverse 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 diff --git a/include/llvm/Analysis/LazyCallGraph.h b/include/llvm/Analysis/LazyCallGraph.h index 9f62eaa2e9f8..8a09535b3685 100644 --- a/include/llvm/Analysis/LazyCallGraph.h +++ b/include/llvm/Analysis/LazyCallGraph.h @@ -953,20 +953,20 @@ inline LazyCallGraph::Node &LazyCallGraph::Edge::getNode(LazyCallGraph &G) { // Provide GraphTraits specializations for call graphs. template <> struct GraphTraits { - 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 { - 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. diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 52345e4a4806..9fc7016f0dee 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -761,31 +761,21 @@ class LoopInfo : public LoopInfoBase { // Allow clients to walk the list of nested loops... template <> struct GraphTraits { - 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 { - 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. diff --git a/include/llvm/Analysis/PostDominators.h b/include/llvm/Analysis/PostDominators.h index b7638b7776fa..f4bef126e610 100644 --- a/include/llvm/Analysis/PostDominators.h +++ b/include/llvm/Analysis/PostDominators.h @@ -89,7 +89,7 @@ FunctionPass* createPostDomTree(); template <> struct GraphTraits : public GraphTraits { - static NodeType *getEntryNode(PostDominatorTree *DT) { + static NodeRef getEntryNode(PostDominatorTree *DT) { return DT->getRootNode(); } diff --git a/include/llvm/Analysis/RegionIterator.h b/include/llvm/Analysis/RegionIterator.h index 6d3bcd5c44bb..80b752352e93 100644 --- a/include/llvm/Analysis/RegionIterator.h +++ b/include/llvm/Analysis/RegionIterator.h @@ -255,7 +255,6 @@ inline RNSuccIterator succ_end(NodeRef Node) { #define RegionNodeGraphTraits(NodeT, BlockT, RegionT) \ template <> struct GraphTraits { \ - typedef NodeT NodeType; \ typedef NodeT *NodeRef; \ typedef RNSuccIterator ChildIteratorType; \ static NodeRef getEntryNode(NodeRef N) { return N; } \ @@ -267,7 +266,6 @@ inline RNSuccIterator succ_end(NodeRef Node) { } \ }; \ template <> struct GraphTraits> { \ - typedef NodeT NodeType; \ typedef NodeT *NodeRef; \ typedef RNSuccIterator, BlockT, RegionT> \ ChildIteratorType; \ diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h index e789b2e322ae..68a6ef334421 100644 --- a/include/llvm/CodeGen/MachineBasicBlock.h +++ b/include/llvm/CodeGen/MachineBasicBlock.h @@ -728,31 +728,25 @@ struct MBB2NumberFunctor : // template <> struct GraphTraits { - 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 { - 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 @@ -762,33 +756,27 @@ template <> struct GraphTraits { // instead of the successor edges. // template <> struct GraphTraits > { - typedef MachineBasicBlock NodeType; typedef MachineBasicBlock *NodeRef; typedef MachineBasicBlock::pred_iterator ChildIteratorType; - static NodeType *getEntryNode(Inverse G) { + static NodeRef getEntryNode(Inverse 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 > { - typedef const MachineBasicBlock NodeType; typedef const MachineBasicBlock *NodeRef; typedef MachineBasicBlock::const_pred_iterator ChildIteratorType; - static NodeType *getEntryNode(Inverse G) { + static NodeRef getEntryNode(Inverse 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(); } }; diff --git a/include/llvm/CodeGen/MachineDominators.h b/include/llvm/CodeGen/MachineDominators.h index 694c4497459d..7f95b655c7f8 100644 --- a/include/llvm/CodeGen/MachineDominators.h +++ b/include/llvm/CodeGen/MachineDominators.h @@ -271,15 +271,12 @@ class MachineDominatorTree : public MachineFunctionPass { template 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 struct GraphTraits; @@ -297,7 +294,7 @@ struct GraphTraits template <> struct GraphTraits : public GraphTraits { - static NodeType *getEntryNode(MachineDominatorTree *DT) { + static NodeRef getEntryNode(MachineDominatorTree *DT) { return DT->getRootNode(); } }; diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index 8ad04e05e2b6..f34f37671e6e 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -614,9 +614,7 @@ class MachineFunction { // template <> struct GraphTraits : public GraphTraits { - 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 nodes_iterator; @@ -630,9 +628,7 @@ template <> struct GraphTraits : }; template <> struct GraphTraits : public GraphTraits { - 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 nodes_iterator; @@ -655,13 +651,13 @@ template <> struct GraphTraits : // template <> struct GraphTraits > : public GraphTraits > { - static NodeType *getEntryNode(Inverse G) { + static NodeRef getEntryNode(Inverse G) { return &G.Graph->front(); } }; template <> struct GraphTraits > : public GraphTraits > { - static NodeType *getEntryNode(Inverse G) { + static NodeRef getEntryNode(Inverse G) { return &G.Graph->front(); } }; diff --git a/include/llvm/CodeGen/MachineLoopInfo.h b/include/llvm/CodeGen/MachineLoopInfo.h index 308fc942a8c8..200234b21c2d 100644 --- a/include/llvm/CodeGen/MachineLoopInfo.h +++ b/include/llvm/CodeGen/MachineLoopInfo.h @@ -162,31 +162,21 @@ class MachineLoopInfo : public MachineFunctionPass { // Allow clients to walk the list of nested loops... template <> struct GraphTraits { - typedef const MachineLoop NodeType; typedef const MachineLoop *NodeRef; typedef MachineLoopInfo::iterator ChildIteratorType; - static NodeType *getEntryNode(const MachineLoop *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 MachineLoop *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 { - typedef MachineLoop NodeType; typedef MachineLoop *NodeRef; typedef MachineLoopInfo::iterator ChildIteratorType; - static NodeType *getEntryNode(MachineLoop *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(MachineLoop *L) { return L; } + static inline ChildIteratorType child_begin(NodeRef N) { return N->begin(); } + static inline ChildIteratorType child_end(NodeRef N) { return N->end(); } }; } // End llvm namespace diff --git a/include/llvm/CodeGen/MachineRegionInfo.h b/include/llvm/CodeGen/MachineRegionInfo.h index df9823f741dc..13e86dd6cbf0 100644 --- a/include/llvm/CodeGen/MachineRegionInfo.h +++ b/include/llvm/CodeGen/MachineRegionInfo.h @@ -142,10 +142,11 @@ RegionGraphTraits(const MachineRegion, const MachineRegionNode); template <> struct GraphTraits : public GraphTraits > { - typedef df_iterator, false, - GraphTraits > > nodes_iterator; + typedef df_iterator, false, + GraphTraits>> + nodes_iterator; - static NodeType *getEntryNode(MachineRegionInfo *RI) { + static NodeRef getEntryNode(MachineRegionInfo *RI) { return GraphTraits >::getEntryNode(RI->getTopLevelRegion()); } static nodes_iterator nodes_begin(MachineRegionInfo* RI) { @@ -158,10 +159,11 @@ template <> struct GraphTraits template <> struct GraphTraits : public GraphTraits { - typedef df_iterator, false, - GraphTraits > > nodes_iterator; + typedef df_iterator, false, + GraphTraits>> + nodes_iterator; - static NodeType *getEntryNode(MachineRegionInfoPass *RI) { + static NodeRef getEntryNode(MachineRegionInfoPass *RI) { return GraphTraits::getEntryNode(&RI->getRegionInfo()); } static nodes_iterator nodes_begin(MachineRegionInfoPass* RI) { diff --git a/include/llvm/CodeGen/ScheduleDAG.h b/include/llvm/CodeGen/ScheduleDAG.h index f4e7123d88a7..4d62ee56edf1 100644 --- a/include/llvm/CodeGen/ScheduleDAG.h +++ b/include/llvm/CodeGen/ScheduleDAG.h @@ -679,14 +679,13 @@ namespace llvm { }; template <> struct GraphTraits { - typedef SUnit NodeType; typedef SUnit *NodeRef; typedef SUnitIterator ChildIteratorType; - static inline NodeType *getEntryNode(SUnit *N) { return N; } - static inline ChildIteratorType child_begin(NodeType *N) { + static inline NodeRef getEntryNode(SUnit *N) { return N; } + static inline ChildIteratorType child_begin(NodeRef N) { return SUnitIterator::begin(N); } - static inline ChildIteratorType child_end(NodeType *N) { + static inline ChildIteratorType child_end(NodeRef N) { return SUnitIterator::end(N); } }; diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h index b20a889ebd24..8b783b08d3d3 100644 --- a/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/include/llvm/CodeGen/SelectionDAGNodes.h @@ -2055,14 +2055,13 @@ class SDNodeIterator : public std::iterator struct GraphTraits { - typedef SDNode NodeType; typedef SDNode *NodeRef; typedef SDNodeIterator ChildIteratorType; - static inline NodeType *getEntryNode(SDNode *N) { return N; } - static inline ChildIteratorType child_begin(NodeType *N) { + static inline NodeRef getEntryNode(SDNode *N) { return N; } + static inline ChildIteratorType child_begin(NodeRef N) { return SDNodeIterator::begin(N); } - static inline ChildIteratorType child_end(NodeType *N) { + static inline ChildIteratorType child_end(NodeRef N) { return SDNodeIterator::end(N); } }; diff --git a/include/llvm/IR/CFG.h b/include/llvm/IR/CFG.h index 6e31cdc93388..9a3d98494da5 100644 --- a/include/llvm/IR/CFG.h +++ b/include/llvm/IR/CFG.h @@ -154,32 +154,26 @@ struct isPodLike> { // graph of basic blocks... template <> struct GraphTraits { - typedef BasicBlock NodeType; typedef BasicBlock *NodeRef; typedef succ_iterator ChildIteratorType; - static NodeType *getEntryNode(BasicBlock *BB) { return BB; } - static inline ChildIteratorType child_begin(NodeType *N) { + static NodeRef getEntryNode(BasicBlock *BB) { return BB; } + 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 { - typedef const BasicBlock NodeType; typedef const BasicBlock *NodeRef; typedef succ_const_iterator ChildIteratorType; - static NodeType *getEntryNode(const BasicBlock *BB) { return BB; } + static NodeRef getEntryNode(const BasicBlock *BB) { return BB; } - 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); } }; // Provide specializations of GraphTraits to be able to treat a function as a @@ -188,31 +182,23 @@ template <> struct GraphTraits { // instead of the successor edges. // template <> struct GraphTraits > { - typedef BasicBlock NodeType; typedef BasicBlock *NodeRef; typedef pred_iterator ChildIteratorType; - static NodeType *getEntryNode(Inverse G) { return G.Graph; } - static inline ChildIteratorType child_begin(NodeType *N) { + static NodeRef getEntryNode(Inverse 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); } }; template <> struct GraphTraits > { - typedef const BasicBlock NodeType; typedef const BasicBlock *NodeRef; typedef const_pred_iterator ChildIteratorType; - static NodeType *getEntryNode(Inverse G) { - return G.Graph; - } - static inline ChildIteratorType child_begin(NodeType *N) { + static NodeRef getEntryNode(Inverse 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); } }; @@ -226,7 +212,7 @@ template <> struct GraphTraits > { // except that the root node is implicitly the first node of the function. // template <> struct GraphTraits : public GraphTraits { - static NodeType *getEntryNode(Function *F) { return &F->getEntryBlock(); } + static NodeRef getEntryNode(Function *F) { return &F->getEntryBlock(); } // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef pointer_iterator nodes_iterator; @@ -240,7 +226,7 @@ template <> struct GraphTraits : public GraphTraits { }; template <> struct GraphTraits : public GraphTraits { - static NodeType *getEntryNode(const Function *F) {return &F->getEntryBlock();} + static NodeRef getEntryNode(const Function *F) { return &F->getEntryBlock(); } // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef pointer_iterator nodes_iterator; @@ -261,13 +247,13 @@ template <> struct GraphTraits : // template <> struct GraphTraits > : public GraphTraits > { - static NodeType *getEntryNode(Inverse G) { + static NodeRef getEntryNode(Inverse G) { return &G.Graph->getEntryBlock(); } }; template <> struct GraphTraits > : public GraphTraits > { - static NodeType *getEntryNode(Inverse G) { + static NodeRef getEntryNode(Inverse G) { return &G.Graph->getEntryBlock(); } }; diff --git a/include/llvm/IR/Dominators.h b/include/llvm/IR/Dominators.h index c1fb0085d928..276423aee945 100644 --- a/include/llvm/IR/Dominators.h +++ b/include/llvm/IR/Dominators.h @@ -155,24 +155,19 @@ class DominatorTree : public DominatorTreeBase { // iterable by generic graph iterators. template struct DomTreeGraphTraitsBase { - typedef Node NodeType; typedef Node *NodeRef; typedef ChildIterator ChildIteratorType; - typedef df_iterator> nodes_iterator; + typedef df_iterator> nodes_iterator; - 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(); } - static nodes_iterator nodes_begin(NodeType *N) { + static nodes_iterator nodes_begin(NodeRef N) { return df_begin(getEntryNode(N)); } - static nodes_iterator nodes_end(NodeType *N) { - return df_end(getEntryNode(N)); - } + static nodes_iterator nodes_end(NodeRef N) { return df_end(getEntryNode(N)); } }; template <> @@ -186,9 +181,7 @@ struct GraphTraits template <> struct GraphTraits : public GraphTraits { - static NodeType *getEntryNode(DominatorTree *DT) { - return DT->getRootNode(); - } + static NodeRef getEntryNode(DominatorTree *DT) { return DT->getRootNode(); } static nodes_iterator nodes_begin(DominatorTree *N) { return df_begin(getEntryNode(N)); diff --git a/include/llvm/IR/Type.h b/include/llvm/IR/Type.h index e6125a6c6f79..c4044af88b58 100644 --- a/include/llvm/IR/Type.h +++ b/include/llvm/IR/Type.h @@ -429,29 +429,27 @@ template <> struct isa_impl { // graph of sub types. template <> struct GraphTraits { - typedef Type NodeType; typedef Type *NodeRef; typedef Type::subtype_iterator ChildIteratorType; - static inline NodeType *getEntryNode(Type *T) { return T; } - static inline ChildIteratorType child_begin(NodeType *N) { + static inline NodeRef getEntryNode(Type *T) { return T; } + static inline ChildIteratorType child_begin(NodeRef N) { return N->subtype_begin(); } - static inline ChildIteratorType child_end(NodeType *N) { + static inline ChildIteratorType child_end(NodeRef N) { return N->subtype_end(); } }; template <> struct GraphTraits { - typedef const Type NodeType; typedef const Type *NodeRef; typedef Type::subtype_iterator ChildIteratorType; - static inline NodeType *getEntryNode(NodeType *T) { return T; } - static inline ChildIteratorType child_begin(NodeType *N) { + static inline NodeRef getEntryNode(NodeRef T) { return T; } + static inline ChildIteratorType child_begin(NodeRef N) { return N->subtype_begin(); } - static inline ChildIteratorType child_end(NodeType *N) { + static inline ChildIteratorType child_end(NodeRef N) { return N->subtype_end(); } }; diff --git a/include/llvm/Transforms/Utils/MemorySSA.h b/include/llvm/Transforms/Utils/MemorySSA.h index 40b065ed792e..8f6669566b63 100644 --- a/include/llvm/Transforms/Utils/MemorySSA.h +++ b/include/llvm/Transforms/Utils/MemorySSA.h @@ -876,29 +876,25 @@ inline const_memoryaccess_def_iterator MemoryAccess::defs_end() const { /// \brief GraphTraits for a MemoryAccess, which walks defs in the normal case, /// and uses in the inverse case. template <> struct GraphTraits { - using NodeType = MemoryAccess; + using NodeRef = MemoryAccess *; using ChildIteratorType = memoryaccess_def_iterator; - static NodeType *getEntryNode(NodeType *N) { return N; } - static inline ChildIteratorType child_begin(NodeType *N) { + static NodeRef getEntryNode(NodeRef N) { return N; } + static inline ChildIteratorType child_begin(NodeRef N) { return N->defs_begin(); } - static inline ChildIteratorType child_end(NodeType *N) { - return N->defs_end(); - } + static inline ChildIteratorType child_end(NodeRef N) { return N->defs_end(); } }; template <> struct GraphTraits> { - using NodeType = MemoryAccess; + using NodeRef = MemoryAccess *; using ChildIteratorType = MemoryAccess::iterator; - static NodeType *getEntryNode(NodeType *N) { return N; } - static inline ChildIteratorType child_begin(NodeType *N) { + static NodeRef getEntryNode(NodeRef N) { return N; } + static inline ChildIteratorType child_begin(NodeRef N) { return N->user_begin(); } - static inline ChildIteratorType child_end(NodeType *N) { - return N->user_end(); - } + static inline ChildIteratorType child_end(NodeRef N) { return N->user_end(); } }; /// \brief Provide an iterator that walks defs, giving both the memory access, diff --git a/lib/Analysis/BlockFrequencyInfo.cpp b/lib/Analysis/BlockFrequencyInfo.cpp index a20c8fb280d1..08ace6415958 100644 --- a/lib/Analysis/BlockFrequencyInfo.cpp +++ b/lib/Analysis/BlockFrequencyInfo.cpp @@ -60,20 +60,17 @@ namespace llvm { template <> struct GraphTraits { - typedef const BasicBlock NodeType; typedef const BasicBlock *NodeRef; typedef succ_const_iterator ChildIteratorType; typedef pointer_iterator nodes_iterator; - static inline const NodeType *getEntryNode(const BlockFrequencyInfo *G) { + static inline NodeRef getEntryNode(const BlockFrequencyInfo *G) { return &G->getFunction()->front(); } - static ChildIteratorType child_begin(const NodeType *N) { + static ChildIteratorType child_begin(const NodeRef N) { return succ_begin(N); } - static ChildIteratorType child_end(const NodeType *N) { - return succ_end(N); - } + static ChildIteratorType child_end(const NodeRef N) { return succ_end(N); } static nodes_iterator nodes_begin(const BlockFrequencyInfo *G) { return nodes_iterator(G->getFunction()->begin()); } diff --git a/lib/Analysis/BlockFrequencyInfoImpl.cpp b/lib/Analysis/BlockFrequencyInfoImpl.cpp index 9d3045c16a01..9850e02fca22 100644 --- a/lib/Analysis/BlockFrequencyInfoImpl.cpp +++ b/lib/Analysis/BlockFrequencyInfoImpl.cpp @@ -628,15 +628,12 @@ namespace llvm { template <> struct GraphTraits { typedef bfi_detail::IrreducibleGraph GraphT; - typedef const GraphT::IrrNode NodeType; typedef const GraphT::IrrNode *NodeRef; typedef GraphT::IrrNode::iterator ChildIteratorType; - static const NodeType *getEntryNode(const GraphT &G) { - return G.StartIrr; - } - static ChildIteratorType child_begin(NodeType *N) { return N->succ_begin(); } - static ChildIteratorType child_end(NodeType *N) { return N->succ_end(); } + static NodeRef getEntryNode(const GraphT &G) { return G.StartIrr; } + static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); } + static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); } }; } // end namespace llvm diff --git a/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/lib/CodeGen/MachineBlockFrequencyInfo.cpp index 4147e5e1bb68..bda6aa4a2bfc 100644 --- a/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -52,23 +52,19 @@ extern cl::opt ViewHotFreqPercent; namespace llvm { template <> struct GraphTraits { - typedef const MachineBasicBlock NodeType; typedef const MachineBasicBlock *NodeRef; typedef MachineBasicBlock::const_succ_iterator ChildIteratorType; typedef pointer_iterator nodes_iterator; - static inline const NodeType * - getEntryNode(const MachineBlockFrequencyInfo *G) { + static inline NodeRef getEntryNode(const MachineBlockFrequencyInfo *G) { return &G->getFunction()->front(); } - static ChildIteratorType child_begin(const NodeType *N) { + static ChildIteratorType child_begin(const NodeRef N) { return N->succ_begin(); } - static ChildIteratorType child_end(const NodeType *N) { - return N->succ_end(); - } + static ChildIteratorType child_end(const NodeRef N) { return N->succ_end(); } static nodes_iterator nodes_begin(const MachineBlockFrequencyInfo *G) { return nodes_iterator(G->getFunction()->begin()); diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp index ce648e2ea518..6e036664377d 100644 --- a/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/lib/Transforms/IPO/FunctionAttrs.cpp @@ -332,23 +332,18 @@ struct ArgumentUsesTracker : public CaptureTracker { namespace llvm { template <> struct GraphTraits { - typedef ArgumentGraphNode NodeType; typedef ArgumentGraphNode *NodeRef; typedef SmallVectorImpl::iterator ChildIteratorType; - static inline NodeType *getEntryNode(NodeType *A) { return A; } - static inline ChildIteratorType child_begin(NodeType *N) { + static inline NodeRef getEntryNode(NodeRef A) { return A; } + static inline ChildIteratorType child_begin(NodeRef N) { return N->Uses.begin(); } - static inline ChildIteratorType child_end(NodeType *N) { - return N->Uses.end(); - } + static inline ChildIteratorType child_end(NodeRef N) { return N->Uses.end(); } }; template <> struct GraphTraits : public GraphTraits { - static NodeType *getEntryNode(ArgumentGraph *AG) { - return AG->getEntryNode(); - } + static NodeRef getEntryNode(ArgumentGraph *AG) { return AG->getEntryNode(); } static ChildIteratorType nodes_begin(ArgumentGraph *AG) { return AG->begin(); } diff --git a/unittests/ADT/SCCIteratorTest.cpp b/unittests/ADT/SCCIteratorTest.cpp index 597661fd8cc0..62eb0e637f64 100644 --- a/unittests/ADT/SCCIteratorTest.cpp +++ b/unittests/ADT/SCCIteratorTest.cpp @@ -229,15 +229,16 @@ class Graph { template struct GraphTraits > { - typedef typename Graph::NodeType NodeType; typedef typename Graph::NodeType *NodeRef; typedef typename Graph::ChildIterator ChildIteratorType; - static inline NodeType *getEntryNode(const Graph &G) { return G.AccessNode(0); } - static inline ChildIteratorType child_begin(NodeType *Node) { - return Graph::child_begin(Node); + static inline NodeRef getEntryNode(const Graph &G) { + return G.AccessNode(0); + } + static inline ChildIteratorType child_begin(NodeRef Node) { + return Graph::child_begin(Node); } - static inline ChildIteratorType child_end(NodeType *Node) { + static inline ChildIteratorType child_end(NodeRef Node) { return Graph::child_end(Node); } }; diff --git a/unittests/Analysis/CallGraphTest.cpp b/unittests/Analysis/CallGraphTest.cpp index 0c9280446bcb..2d4e63facf3b 100644 --- a/unittests/Analysis/CallGraphTest.cpp +++ b/unittests/Analysis/CallGraphTest.cpp @@ -17,29 +17,29 @@ using namespace llvm; namespace { template void canSpecializeGraphTraitsIterators(Ty *G) { - typedef typename GraphTraits::NodeType NodeTy; + typedef typename GraphTraits::NodeRef NodeRef; auto I = GraphTraits::nodes_begin(G); auto E = GraphTraits::nodes_end(G); auto X = ++I; // Should be able to iterate over all nodes of the graph. - static_assert(std::is_same::value, + static_assert(std::is_same::value, "Node type does not match"); - static_assert(std::is_same::value, + static_assert(std::is_same::value, "Node type does not match"); - static_assert(std::is_same::value, + static_assert(std::is_same::value, "Node type does not match"); - NodeTy *N = GraphTraits::getEntryNode(G); + NodeRef N = GraphTraits::getEntryNode(G); - auto S = GraphTraits::child_begin(N); - auto F = GraphTraits::child_end(N); + auto S = GraphTraits::child_begin(N); + auto F = GraphTraits::child_end(N); // Should be able to iterate over immediate successors of a node. - static_assert(std::is_same::value, + static_assert(std::is_same::value, "Node type does not match"); - static_assert(std::is_same::value, + static_assert(std::is_same::value, "Node type does not match"); }