+// 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);
+ }
+ }
+}
+
+