[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Oct 13 22:31:05 PDT 2002
Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.31 -> 1.32
---
Log message:
- Dramatically simplify the Constant::mutateReferences implementation,
allowing it to be called on all constant types (structures/arrays)
---
Diffs of the changes:
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.31 llvm/lib/VMCore/Constants.cpp:1.32
--- llvm/lib/VMCore/Constants.cpp:1.31 Sun Oct 13 14:39:16 2002
+++ llvm/lib/VMCore/Constants.cpp Sun Oct 13 22:30:23 2002
@@ -685,27 +685,25 @@
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;
+ }
}
More information about the llvm-commits
mailing list