Handle the case where OldNodeMap == &ScalarMap correctly
authorChris Lattner <sabre@nondot.org>
Mon, 30 Jun 2003 05:09:29 +0000 (05:09 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 30 Jun 2003 05:09:29 +0000 (05:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7000 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/DataStructure/DataStructure.cpp

index 94ed3487e84bb2728b238e83e1142dc6e7b84ff8..c5e81a71a916c74ddf81c5b6b8df4a84f3c28ccd 100644 (file)
@@ -784,18 +784,14 @@ void DSGraph::cloneInto(const DSGraph &G, ScalarMapTy &OldValMap,
   // Copy the scalar map... merging all of the global nodes...
   for (ScalarMapTy::const_iterator I = G.ScalarMap.begin(),
          E = G.ScalarMap.end(); I != E; ++I) {
-    DSNodeHandle &H = OldValMap[I->first];
     DSNodeHandle &MappedNode = OldNodeMap[I->second.getNode()];
-    H.setOffset(I->second.getOffset()+MappedNode.getOffset());
-    H.setNode(MappedNode.getNode());
+    DSNodeHandle &H = OldValMap[I->first];
+    H.mergeWith(DSNodeHandle(MappedNode.getNode(),
+                             I->second.getOffset()+MappedNode.getOffset()));
 
-    if (isa<GlobalValue>(I->first)) {  // Is this a global?
-      ScalarMapTy::iterator GVI = ScalarMap.find(I->first);
-      if (GVI != ScalarMap.end())     // Is the global value in this fn already?
-        GVI->second.mergeWith(H);
-      else
-        ScalarMap[I->first] = H;      // Add global pointer to this graph
-    }
+    // If this is a global, add the global to this fn or merge if already exists
+    if (isa<GlobalValue>(I->first) && &OldNodeMap != &ScalarMap)
+      ScalarMap[I->first].mergeWith(H);
   }
 
   if (!(CloneFlags & DontCloneCallNodes)) {
@@ -832,8 +828,7 @@ void DSGraph::cloneInto(const DSGraph &G, ScalarMapTy &OldValMap,
 ///
 void DSGraph::mergeInGraph(DSCallSite &CS, Function &F, const DSGraph &Graph,
                            unsigned CloneFlags) {
-  ScalarMapTy OldValMap;
-  ScalarMapTy *ScalarMap = &OldValMap;
+  ScalarMapTy OldValMap, *ScalarMap;
   DSNodeHandle RetVal;
 
   // If this is not a recursive call, clone the graph into this graph...