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

Chris Lattner lattner at cs.uiuc.edu
Fri Aug 29 00:10:06 PDT 2003


Changes in directory llvm/lib/VMCore:

Constants.cpp updated: 1.50 -> 1.51
Value.cpp updated: 1.32 -> 1.33

---
Log message:

Refactor code to make it useful outside of Constants.cpp


---
Diffs of the changes:

Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.50 llvm/lib/VMCore/Constants.cpp:1.51
--- llvm/lib/VMCore/Constants.cpp:1.50	Thu Aug 21 17:12:47 2003
+++ llvm/lib/VMCore/Constants.cpp	Fri Aug 29 00:09:37 2003
@@ -466,26 +466,6 @@
 //===----------------------------------------------------------------------===//
 //                      Factory Function Implementation
 
-// ReplaceUsesOfWith - This is exactly the same as Value::replaceAllUsesWith,
-// except that it doesn't have all of the asserts.  The asserts fail because we
-// are half-way done resolving types, which causes some types to exist as two
-// different Type*'s at the same time.  This is a sledgehammer to work around
-// this problem.
-//
-static void ReplaceUsesOfWith(Value *Old, Value *New) {
-  while (!Old->use_empty()) {
-    User *Use = Old->use_back();
-    // Must handle Constants specially, we cannot call replaceUsesOfWith on a
-    // constant!
-    if (Constant *C = dyn_cast<Constant>(Use)) {
-      C->replaceUsesOfWithOnConstant(Old, New);
-    } else {
-      Use->replaceUsesOfWith(Old, New);
-    }
-  }
-}
-
-
 // ConstantCreator - A class that is used to create constants by
 // ValueMap*.  This class should be partially specialized if there is
 // something strange that needs to be done to interface to the ctor for the
@@ -596,7 +576,7 @@
     C.push_back(cast<Constant>(getOperand(i)));
   Constant *New = ConstantArray::get(cast<ArrayType>(NewTy), C);
   if (New != this) {
-    ReplaceUsesOfWith(this, New);
+    uncheckedReplaceAllUsesWith(New);
     destroyConstant();    // This constant is now dead, destroy it.
   }
 }
@@ -665,7 +645,7 @@
     C.push_back(cast<Constant>(getOperand(i)));
   Constant *New = ConstantStruct::get(cast<StructType>(NewTy), C);
   if (New != this) {
-    ReplaceUsesOfWith(this, New);
+    uncheckedReplaceAllUsesWith(New);
     destroyConstant();    // This constant is now dead, destroy it.
   }
 }
@@ -706,7 +686,7 @@
   // Make everyone now use a constant of the new type...
   Constant *New = ConstantPointerNull::get(cast<PointerType>(NewTy));
   if (New != this) {
-    ReplaceUsesOfWith(this, New);
+    uncheckedReplaceAllUsesWith(New);
     
     // This constant is now dead, destroy it.
     destroyConstant();
@@ -859,7 +839,7 @@
     New = ConstantExpr::getGetElementPtr(getOperand(0), C);
   }
   if (New != this) {
-    ReplaceUsesOfWith(this, New);
+    uncheckedReplaceAllUsesWith(New);
     destroyConstant();    // This constant is now dead, destroy it.
   }
 }


Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.32 llvm/lib/VMCore/Value.cpp:1.33
--- llvm/lib/VMCore/Value.cpp:1.32	Tue Jun 24 17:20:19 2003
+++ llvm/lib/VMCore/Value.cpp	Fri Aug 29 00:09:37 2003
@@ -66,6 +66,26 @@
   }
 }
 
+// uncheckedReplaceAllUsesWith - This is exactly the same as replaceAllUsesWith,
+// except that it doesn't have all of the asserts.  The asserts fail because we
+// are half-way done resolving types, which causes some types to exist as two
+// different Type*'s at the same time.  This is a sledgehammer to work around
+// this problem.
+//
+void Value::uncheckedReplaceAllUsesWith(Value *New) {
+  while (!Uses.empty()) {
+    User *Use = Uses.back();
+    // Must handle Constants specially, we cannot call replaceUsesOfWith on a
+    // constant!
+    if (Constant *C = dyn_cast<Constant>(Use)) {
+      C->replaceUsesOfWithOnConstant(this, New);
+    } else {
+      Use->replaceUsesOfWith(this, New);
+    }
+  }
+}
+
+
 // refineAbstractType - This function is implemented because we use
 // potentially abstract types, and these types may be resolved to more
 // concrete types after we are constructed.  For the value class, we simply





More information about the llvm-commits mailing list