[PATCH] D23704: [GraphTraits] Make nodes_iterator dereference to NodeType*

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 19 10:29:42 PDT 2016


dblaikie accepted this revision.
This revision is now accepted and ready to land.

================
Comment at: include/llvm/Analysis/CallGraph.h:463-500
@@ -462,40 +462,40 @@
       PairTy;
-  typedef std::pointer_to_unary_function<const PairTy &, CallGraphNode &>
+  typedef std::pointer_to_unary_function<const PairTy &, CallGraphNode *>
       DerefFun;
 
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
   typedef mapped_iterator<CallGraph::iterator, DerefFun> nodes_iterator;
   static nodes_iterator nodes_begin(CallGraph *CG) {
     return map_iterator(CG->begin(), DerefFun(CGdereference));
   }
   static nodes_iterator nodes_end(CallGraph *CG) {
     return map_iterator(CG->end(), DerefFun(CGdereference));
   }
 
-  static CallGraphNode &CGdereference(const PairTy &P) { return *P.second; }
+  static CallGraphNode *CGdereference(const PairTy &P) { return P.second.get(); }
 };
 
 template <>
 struct GraphTraits<const CallGraph *> : public GraphTraits<
                                             const CallGraphNode *> {
   static NodeType *getEntryNode(const CallGraph *CGN) {
     return CGN->getExternalCallingNode(); // Start at the external node!
   }
   typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
       PairTy;
-  typedef std::pointer_to_unary_function<const PairTy &, const CallGraphNode &>
+  typedef std::pointer_to_unary_function<const PairTy &, const CallGraphNode *>
       DerefFun;
 
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
   typedef mapped_iterator<CallGraph::const_iterator, DerefFun> nodes_iterator;
   static nodes_iterator nodes_begin(const CallGraph *CG) {
     return map_iterator(CG->begin(), DerefFun(CGdereference));
   }
   static nodes_iterator nodes_end(const CallGraph *CG) {
     return map_iterator(CG->end(), DerefFun(CGdereference));
   }
 
-  static const CallGraphNode &CGdereference(const PairTy &P) {
-    return *P.second;
+  static const CallGraphNode *CGdereference(const PairTy &P) {
+    return P.second.get();
   }
 };
----------------
Same sort of feedback I gave on the equivalent code in Clang (why does the code in Clang look /so/ much the same & could we make some of it common?): A follow up commit to drop the "DerefFun" noise now that we can use decltype, etc.


https://reviews.llvm.org/D23704





More information about the llvm-commits mailing list