[llvm-commits] CVS: llvm/lib/Analysis/DataStructure/DataStructure.cpp Steensgaard.cpp TopDownClosure.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Nov 7 23:02:01 PST 2002


Changes in directory llvm/lib/Analysis/DataStructure:

DataStructure.cpp updated: 1.50 -> 1.51
Steensgaard.cpp updated: 1.8 -> 1.9
TopDownClosure.cpp updated: 1.22 -> 1.23

---
Log message:

Use DSNodeHandleMap instead to be safe


---
Diffs of the changes:

Index: llvm/lib/Analysis/DataStructure/DataStructure.cpp
diff -u llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.50 llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.51
--- llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.50	Thu Nov  7 19:21:07 2002
+++ llvm/lib/Analysis/DataStructure/DataStructure.cpp	Thu Nov  7 23:01:14 2002
@@ -470,11 +470,12 @@
 //===----------------------------------------------------------------------===//
 
 DSGraph::DSGraph(const DSGraph &G) : Func(G.Func) {
-  std::map<const DSNode*, DSNode*> NodeMap;
+  std::map<const DSNode*, DSNodeHandle> NodeMap;
   RetNode = cloneInto(G, ScalarMap, NodeMap);
 }
 
-DSGraph::DSGraph(const DSGraph &G, std::map<const DSNode*, DSNode*> &NodeMap)
+DSGraph::DSGraph(const DSGraph &G,
+                 std::map<const DSNode*, DSNodeHandle> &NodeMap)
   : Func(G.Func) {
   RetNode = cloneInto(G, ScalarMap, NodeMap);
 }
@@ -501,9 +502,12 @@
 /// remapLinks - Change all of the Links in the current node according to the
 /// specified mapping.
 ///
-void DSNode::remapLinks(std::map<const DSNode*, DSNode*> &OldNodeMap) {
-  for (unsigned i = 0, e = Links.size(); i != e; ++i) 
-    Links[i].setNode(OldNodeMap[Links[i].getNode()]);
+void DSNode::remapLinks(std::map<const DSNode*, DSNodeHandle> &OldNodeMap) {
+  for (unsigned i = 0, e = Links.size(); i != e; ++i) {
+    DSNodeHandle &H = OldNodeMap[Links[i].getNode()];
+    Links[i].setNode(H.getNode());
+    Links[i].setOffset(Links[i].getOffset()+H.getOffset());
+  }
 }
 
 
@@ -515,7 +519,7 @@
 //
 DSNodeHandle DSGraph::cloneInto(const DSGraph &G, 
                                 std::map<Value*, DSNodeHandle> &OldValMap,
-                                std::map<const DSNode*, DSNode*> &OldNodeMap,
+                              std::map<const DSNode*, DSNodeHandle> &OldNodeMap,
                                 AllocaBit StripAllocas) {
   assert(OldNodeMap.empty() && "Returned OldNodeMap should be empty!");
   assert(&G != this && "Cannot clone graph into itself!");
@@ -544,14 +548,14 @@
   for (std::map<Value*, DSNodeHandle>::const_iterator I = G.ScalarMap.begin(),
          E = G.ScalarMap.end(); I != E; ++I) {
     DSNodeHandle &H = OldValMap[I->first];
-    H.setNode(OldNodeMap[I->second.getNode()]);
-    H.setOffset(I->second.getOffset());
+    DSNodeHandle &MappedNode = OldNodeMap[I->second.getNode()];
+    H.setNode(MappedNode.getNode());
+    H.setOffset(I->second.getOffset()+MappedNode.getOffset());
 
     if (isa<GlobalValue>(I->first)) {  // Is this a global?
       std::map<Value*, DSNodeHandle>::iterator GVI = ScalarMap.find(I->first);
       if (GVI != ScalarMap.end()) {   // Is the global value in this fn already?
         GVI->second.mergeWith(H);
-        OldNodeMap[I->second.getNode()] = H.getNode();
       } else {
         ScalarMap[I->first] = H;      // Add global pointer to this graph
       }
@@ -565,7 +569,9 @@
     FunctionCalls.push_back(DSCallSite(G.FunctionCalls[i], OldNodeMap));
 
   // Return the returned node pointer...
-  return DSNodeHandle(OldNodeMap[G.RetNode.getNode()], G.RetNode.getOffset());
+  DSNodeHandle &MappedRet = OldNodeMap[G.RetNode.getNode()];
+  return DSNodeHandle(MappedRet.getNode(),
+                      MappedRet.getOffset()+G.RetNode.getOffset());
 }
 
 /// mergeInGraph - The method is used for merging graphs together.  If the
@@ -584,7 +590,7 @@
     // Clone the callee's graph into the current graph, keeping
     // track of where scalars in the old graph _used_ to point,
     // and of the new nodes matching nodes of the old graph.
-    std::map<const DSNode*, DSNode*> OldNodeMap;
+    std::map<const DSNode*, DSNodeHandle> OldNodeMap;
     
     // The clone call may invalidate any of the vectors in the data
     // structure graph.  Strip locals and don't copy the list of callers


Index: llvm/lib/Analysis/DataStructure/Steensgaard.cpp
diff -u llvm/lib/Analysis/DataStructure/Steensgaard.cpp:1.8 llvm/lib/Analysis/DataStructure/Steensgaard.cpp:1.9
--- llvm/lib/Analysis/DataStructure/Steensgaard.cpp:1.8	Wed Nov  6 12:08:32 2002
+++ llvm/lib/Analysis/DataStructure/Steensgaard.cpp	Thu Nov  7 23:01:14 2002
@@ -124,7 +124,7 @@
     if (!I->isExternal()) {
       std::map<Value*, DSNodeHandle> ValMap;
       {  // Scope to free NodeMap memory ASAP
-        std::map<const DSNode*, DSNode*> NodeMap;
+        std::map<const DSNode*, DSNodeHandle> NodeMap;
         const DSGraph &FDSG = LDS.getDSGraph(*I);
         DSNodeHandle RetNode = ResultGraph->cloneInto(FDSG, ValMap, NodeMap);
 


Index: llvm/lib/Analysis/DataStructure/TopDownClosure.cpp
diff -u llvm/lib/Analysis/DataStructure/TopDownClosure.cpp:1.22 llvm/lib/Analysis/DataStructure/TopDownClosure.cpp:1.23
--- llvm/lib/Analysis/DataStructure/TopDownClosure.cpp:1.22	Thu Nov  7 19:21:07 2002
+++ llvm/lib/Analysis/DataStructure/TopDownClosure.cpp	Thu Nov  7 23:01:14 2002
@@ -93,7 +93,7 @@
   DSGraph &BUGraph = BU.getDSGraph(F);
   
   // Copy the BU graph, keeping a mapping from the BUGraph to the current Graph
-  std::map<const DSNode*, DSNode*> BUNodeMap;
+  std::map<const DSNode*, DSNodeHandle> BUNodeMap;
   Graph = new DSGraph(BUGraph, BUNodeMap);
 
   // We only need the BUMap entries for the nodes that are used in call sites.
@@ -113,12 +113,12 @@
   }
 
   // Loop through te BUNodeMap, keeping only the nodes that are "Needed"
-  for (std::map<const DSNode*, DSNode*>::iterator I = BUNodeMap.begin();
+  for (std::map<const DSNode*, DSNodeHandle>::iterator I = BUNodeMap.begin();
        I != BUNodeMap.end(); )
     if (NeededNodes.count(I->first) && I->first)  // Keep needed nodes...
       ++I;
     else {
-      std::map<const DSNode*, DSNode*>::iterator J = I++;
+      std::map<const DSNode*, DSNodeHandle>::iterator J = I++;
       BUNodeMap.erase(J);
     }
 
@@ -167,7 +167,7 @@
     // These two maps keep track of where scalars in the old graph _used_
     // to point to, and of new nodes matching nodes of the old graph.
     std::map<Value*, DSNodeHandle> OldValMap;
-    std::map<const DSNode*, DSNode*> OldNodeMap;
+    std::map<const DSNode*, DSNodeHandle> OldNodeMap;
 
     // FIXME: Eventually use DSGraph::mergeInGraph here...
     // Graph->mergeInGraph(CallSiteInCG, CG, false);





More information about the llvm-commits mailing list