diff options
author | Chris Lattner <sabre@nondot.org> | 2002-10-14 03:30:23 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-10-14 03:30:23 +0000 |
commit | 163b890dfb7811e2ff473d548570823c63d4d598 (patch) | |
tree | 143d59f245e43ea4f78bce9e02218b500783da63 /llvm/lib | |
parent | 8022a0f57cc863c34bf11ebe46562ce12b01c6ae (diff) | |
download | bcm5719-llvm-163b890dfb7811e2ff473d548570823c63d4d598.tar.gz bcm5719-llvm-163b890dfb7811e2ff473d548570823c63d4d598.zip |
- Dramatically simplify the Constant::mutateReferences implementation,
allowing it to be called on all constant types (structures/arrays)
llvm-svn: 4160
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index 8464c437fcb..3887e33274a 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -685,27 +685,25 @@ const char *ConstantExpr::getOpcodeName() const { return Instruction::getOpcodeName(getOpcode()); } +unsigned Constant::mutateReferences(Value *OldV, Value *NewV) { + // Uses of constant pointer refs are global values, not constants! + if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(this)) { + GlobalValue *NewGV = cast<GlobalValue>(NewV); + GlobalValue *OldGV = CPR->getValue(); -//---- ConstantPointerRef::mutateReferences() implementation... -// -unsigned ConstantPointerRef::mutateReferences(Value *OldV, Value *NewV) { - assert(getValue() == OldV && "Cannot mutate old value if I'm not using it!"); - GlobalValue *NewGV = cast<GlobalValue>(NewV); - getValue()->getParent()->mutateConstantPointerRef(getValue(), NewGV); - Operands[0] = NewGV; - return 1; -} + assert(OldGV == OldV && "Cannot mutate old value if I'm not using it!"); - -//---- ConstantPointerExpr::mutateReferences() implementation... -// -unsigned ConstantExpr::mutateReferences(Value* OldV, Value *NewV) { - unsigned NumReplaced = 0; - Constant *NewC = cast<Constant>(NewV); - for (unsigned i = 0, N = getNumOperands(); i != N; ++i) - if (Operands[i] == OldV) { - ++NumReplaced; - Operands[i] = NewC; - } - return NumReplaced; + OldGV->getParent()->mutateConstantPointerRef(OldGV, NewGV); + Operands[0] = NewGV; + return 1; + } else { + Constant *NewC = cast<Constant>(NewV); + unsigned NumReplaced = 0; + for (unsigned i = 0, N = getNumOperands(); i != N; ++i) + if (Operands[i] == OldV) { + ++NumReplaced; + Operands[i] = NewC; + } + return NumReplaced; + } } |