mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
- 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
This commit is contained in:
parent
c251f9e0ae
commit
28eca8bb56
@ -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...
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user