From 2bc065b63a8377456ddbe149621b3daf15f052a4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 29 Aug 2003 05:09:37 +0000 Subject: [PATCH] Refactor code to make it useful outside of Constants.cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8205 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Constants.cpp | 28 ++++------------------------ lib/VMCore/Value.cpp | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 7a683483969..7051814a7c0 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -466,26 +466,6 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV) { //===----------------------------------------------------------------------===// // 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(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 @@ void ConstantArray::refineAbstractType(const DerivedType *OldTy, C.push_back(cast(getOperand(i))); Constant *New = ConstantArray::get(cast(NewTy), C); if (New != this) { - ReplaceUsesOfWith(this, New); + uncheckedReplaceAllUsesWith(New); destroyConstant(); // This constant is now dead, destroy it. } } @@ -665,7 +645,7 @@ void ConstantStruct::refineAbstractType(const DerivedType *OldTy, C.push_back(cast(getOperand(i))); Constant *New = ConstantStruct::get(cast(NewTy), C); if (New != this) { - ReplaceUsesOfWith(this, New); + uncheckedReplaceAllUsesWith(New); destroyConstant(); // This constant is now dead, destroy it. } } @@ -706,7 +686,7 @@ void ConstantPointerNull::refineAbstractType(const DerivedType *OldTy, // Make everyone now use a constant of the new type... Constant *New = ConstantPointerNull::get(cast(NewTy)); if (New != this) { - ReplaceUsesOfWith(this, New); + uncheckedReplaceAllUsesWith(New); // This constant is now dead, destroy it. destroyConstant(); @@ -859,7 +839,7 @@ void ConstantExpr::refineAbstractType(const DerivedType *OldTy, New = ConstantExpr::getGetElementPtr(getOperand(0), C); } if (New != this) { - ReplaceUsesOfWith(this, New); + uncheckedReplaceAllUsesWith(New); destroyConstant(); // This constant is now dead, destroy it. } } diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 6cb0b09f520..c3bd28b514b 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -66,6 +66,26 @@ void Value::replaceAllUsesWith(Value *New) { } } +// 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(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 -- 2.34.1