diff options
author | Chris Lattner <sabre@nondot.org> | 2002-10-09 23:12:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-10-09 23:12:59 +0000 |
commit | 28eca8bb5692dced9f51a99c96078cbd67e230c6 (patch) | |
tree | 134a080a1da803ea1464a9e20599adb7fa5e7ac9 /lib/VMCore/Value.cpp | |
parent | c251f9e0ae46dafec666541b8311af878da27f06 (diff) | |
download | external_llvm-28eca8bb5692dced9f51a99c96078cbd67e230c6.zip external_llvm-28eca8bb5692dced9f51a99c96078cbd67e230c6.tar.gz external_llvm-28eca8bb5692dced9f51a99c96078cbd67e230c6.tar.bz2 |
- Make Value::replaceAllUsesWith work with constants correctly. This fixes
bug FuncResolve/2002-08-19-ResolveGlobalVars.ll and gzip looks better.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4103 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Value.cpp')
-rw-r--r-- | lib/VMCore/Value.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 7587535..f343a6c 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -7,6 +7,7 @@ #include "llvm/InstrTypes.h" #include "llvm/SymbolTable.h" #include "llvm/DerivedTypes.h" +#include "llvm/Constant.h" #include "Support/LeakDetector.h" #include <algorithm> @@ -45,23 +46,23 @@ Value::~Value() { LeakDetector::removeGarbageObject(this); } -void Value::replaceAllUsesWith(Value *D) { - assert(D && "Value::replaceAllUsesWith(<null>) is invalid!"); - assert(D != this && "V->replaceAllUsesWith(V) is NOT valid!"); - assert(D->getType() == getType() && + + + +void Value::replaceAllUsesWith(Value *New) { + assert(New && "Value::replaceAllUsesWith(<null>) is invalid!"); + assert(New != this && "this->replaceAllUsesWith(this) is NOT valid!"); + assert(New->getType() == getType() && "replaceAllUses of value with new value of different type!"); while (!Uses.empty()) { User *Use = Uses.back(); -#ifndef NDEBUG - unsigned NumUses = Uses.size(); -#endif - Use->replaceUsesOfWith(this, D); - -#ifndef NDEBUG // only in -g mode... - if (Uses.size() == NumUses) - std::cerr << "Use: " << *Use << "replace with: " << *D; -#endif - assert(Uses.size() != NumUses && "Didn't remove definition!"); + // 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); + } } } @@ -105,6 +106,9 @@ User::User(const Type *Ty, ValueTy vty, const std::string &name) void User::replaceUsesOfWith(Value *From, Value *To) { if (From == To) return; // Duh what? + assert(!isa<Constant>(this) && + "Cannot call User::replaceUsesofWith on a constant!"); + for (unsigned i = 0, E = getNumOperands(); i != E; ++i) if (getOperand(i) == From) { // Is This operand is pointing to oldval? // The side effects of this setOperand call include linking to @@ -113,5 +117,3 @@ void User::replaceUsesOfWith(Value *From, Value *To) { setOperand(i, To); // Fix it now... } } - - |