[llvm] r207047 - [LCG] Make the insertion and query paths into the LCG which cannot fail

Chandler Carruth chandlerc at gmail.com
Wed Apr 23 16:20:36 PDT 2014


Author: chandlerc
Date: Wed Apr 23 18:20:36 2014
New Revision: 207047

URL: http://llvm.org/viewvc/llvm-project?rev=207047&view=rev
Log:
[LCG] Make the insertion and query paths into the LCG which cannot fail
return references to better model this property.

No functionality changed.

Modified:
    llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
    llvm/trunk/lib/Analysis/LazyCallGraph.cpp

Modified: llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LazyCallGraph.h?rev=207047&r1=207046&r2=207047&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LazyCallGraph.h (original)
+++ llvm/trunk/include/llvm/Analysis/LazyCallGraph.h Wed Apr 23 18:20:36 2014
@@ -142,9 +142,9 @@ public:
         return NI->get<Node *>();
 
       Function *F = NI->get<Function *>();
-      Node *ChildN = G->get(*F);
-      *NI = ChildN;
-      return ChildN;
+      Node &ChildN = G->get(*F);
+      *NI = &ChildN;
+      return &ChildN;
     }
     pointer operator->() const { return operator*(); }
 
@@ -332,10 +332,10 @@ public:
 
   /// \brief Get a graph node for a given function, scanning it to populate the
   /// graph data as necessary.
-  Node *get(Function &F) {
+  Node &get(Function &F) {
     Node *&N = NodeMap[&F];
     if (N)
-      return N;
+      return *N;
 
     return insertInto(F, N);
   }
@@ -345,7 +345,7 @@ public:
 
   /// \brief Update the call graph after deleting an edge.
   void removeEdge(Function &Caller, Function &Callee) {
-    return removeEdge(*get(Caller), Callee);
+    return removeEdge(get(Caller), Callee);
   }
 
 private:
@@ -387,7 +387,7 @@ private:
 
   /// \brief Helper to insert a new function, with an already looked-up entry in
   /// the NodeMap.
-  Node *insertInto(Function &F, Node *&MappedN);
+  Node &insertInto(Function &F, Node *&MappedN);
 
   /// \brief Helper to update pointers back to the graph object during moves.
   void updateGraphPtrs();

Modified: llvm/trunk/lib/Analysis/LazyCallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyCallGraph.cpp?rev=207047&r1=207046&r2=207047&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyCallGraph.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyCallGraph.cpp Wed Apr 23 18:20:36 2014
@@ -362,8 +362,8 @@ void LazyCallGraph::removeEdge(Node &Cal
   CallerC->removeInternalEdge(*this, CallerN, *CalleeN);
 }
 
-LazyCallGraph::Node *LazyCallGraph::insertInto(Function &F, Node *&MappedN) {
-  return new (MappedN = BPA.Allocate()) Node(*this, F);
+LazyCallGraph::Node &LazyCallGraph::insertInto(Function &F, Node *&MappedN) {
+  return *new (MappedN = BPA.Allocate()) Node(*this, F);
 }
 
 void LazyCallGraph::updateGraphPtrs() {
@@ -435,8 +435,8 @@ LazyCallGraph::SCC *LazyCallGraph::getNe
 
     // Reset the DFS numbering.
     NextDFSNumber = 1;
-    Node *N = get(*SCCEntryNodes.pop_back_val());
-    DFSStack.push_back(std::make_pair(N, N->begin()));
+    Node &N = get(*SCCEntryNodes.pop_back_val());
+    DFSStack.push_back(std::make_pair(&N, N.begin()));
   }
 
   auto SI = DFSStack.rbegin();





More information about the llvm-commits mailing list