[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp Module.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu May 15 14:38:01 PDT 2003


Changes in directory llvm/lib/VMCore:

Constants.cpp updated: 1.38 -> 1.39
Module.cpp updated: 1.35 -> 1.36

---
Log message:

Fix bug: Assembler/2003-05-15-AssemblerProblem.llx


---
Diffs of the changes:

Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.38 llvm/lib/VMCore/Constants.cpp:1.39
--- llvm/lib/VMCore/Constants.cpp:1.38	Wed May 14 12:51:05 2003
+++ llvm/lib/VMCore/Constants.cpp	Thu May 15 14:37:20 2003
@@ -721,9 +721,8 @@
     GlobalValue *OldGV = CPR->getValue();
 
     assert(OldGV == OldV && "Cannot mutate old value if I'm not using it!");
-
-    OldGV->getParent()->mutateConstantPointerRef(OldGV, NewGV);
     Operands[0] = NewGV;
+    OldGV->getParent()->mutateConstantPointerRef(OldGV, NewGV);
     return 1;
   } else {
     Constant *NewC = cast<Constant>(NewV);


Index: llvm/lib/VMCore/Module.cpp
diff -u llvm/lib/VMCore/Module.cpp:1.35 llvm/lib/VMCore/Module.cpp:1.36
--- llvm/lib/VMCore/Module.cpp:1.35	Tue Apr 22 13:02:04 2003
+++ llvm/lib/VMCore/Module.cpp	Thu May 15 14:37:21 2003
@@ -250,6 +250,7 @@
 }
 
 void Module::mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV) {
+  assert(OldGV != NewGV && "Cannot mutate to the same global!");
   GlobalValueRefMap::iterator I = GVRefMap->Map.find(OldGV);
   assert(I != GVRefMap->Map.end() && 
 	 "mutateConstantPointerRef; OldGV not in table!");
@@ -258,6 +259,16 @@
   // Remove the old entry...
   GVRefMap->Map.erase(I);
 
-  // Insert the new entry...
-  GVRefMap->Map.insert(std::make_pair(NewGV, Ref));
+  // Check to see if a CPR already exists for NewGV
+  I = GVRefMap->Map.lower_bound(NewGV);
+
+  if (I == GVRefMap->Map.end() || I->first != NewGV) {
+    // Insert the new entry...
+    GVRefMap->Map.insert(I, std::make_pair(NewGV, Ref));
+  } else {
+    // Otherwise, an entry already exists for the current global value.
+    // Completely replace the old CPR with the existing one...
+    Ref->replaceAllUsesWith(I->second);
+    delete Ref;
+  }
 }





More information about the llvm-commits mailing list