Use DSNodeHandleMap instead to be safe
authorChris Lattner <sabre@nondot.org>
Fri, 8 Nov 2002 05:01:14 +0000 (05:01 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 8 Nov 2002 05:01:14 +0000 (05:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4622 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/DataStructure/DataStructure.cpp
lib/Analysis/DataStructure/Steensgaard.cpp
lib/Analysis/DataStructure/TopDownClosure.cpp

index 8d798e3dc2844c26257413619e8159a1e7c12902..fa1dce41256d4ab43cce2e896e0e3762e8f28645 100644 (file)
@@ -470,11 +470,12 @@ Function &DSCallSite::getCaller() const {
 //===----------------------------------------------------------------------===//
 
 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 @@ void DSGraph::dump() const { print(std::cerr); }
 /// 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 @@ void DSNode::remapLinks(std::map<const DSNode*, DSNode*> &OldNodeMap) {
 //
 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 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
   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 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
     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 @@ void DSGraph::mergeInGraph(DSCallSite &CS, const DSGraph &Graph,
     // 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 88d845559f925373420c1b0618b2a028a5aa78df..028bf919e2f0b535cc3a72d29a2e4d83b9fe82d0 100644 (file)
@@ -124,7 +124,7 @@ bool Steens::run(Module &M) {
     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 bc27b92ccd903a61deb0f76f0780207c84f16a5d..98fec671b56eb3064967be7fbf5a586d48deaef9 100644 (file)
@@ -93,7 +93,7 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) {
   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 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) {
   }
 
   // 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 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) {
     // 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);