From 34048e2ace447e5bdbd386d599ce768e19e6b18b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 14 Oct 2002 03:30:23 +0000 Subject: [PATCH] - Dramatically simplify the Constant::mutateReferences implementation, allowing it to be called on all constant types (structures/arrays) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4160 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Constant.h | 2 +- include/llvm/Constants.h | 14 -------------- include/llvm/Module.h | 3 ++- lib/VMCore/Constants.cpp | 42 +++++++++++++++++++--------------------- 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/include/llvm/Constant.h b/include/llvm/Constant.h index 3105cea319d..a7ec6331bd5 100644 --- a/include/llvm/Constant.h +++ b/include/llvm/Constant.h @@ -79,7 +79,7 @@ public: // WARNING: Only to be used by Bytecode & Assembly Parsers! USER CODE SHOULD // NOT USE THIS!! // Returns the number of uses of OldV that were replaced. - virtual unsigned mutateReferences(Value* OldV, Value *NewV) { return 0; } + unsigned mutateReferences(Value* OldV, Value *NewV); // END WARNING!! }; diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index a91c1971fa4..ec6345846e3 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -439,12 +439,6 @@ public: static inline bool classof(const Value *V) { return isa(V) && classof(cast(V)); } - - // WARNING: Only to be used by Bytecode & Assembly Parsers! USER CODE SHOULD - // NOT USE THIS!! - // Returns the number of uses of OldV that were replaced. - virtual unsigned mutateReferences(Value* OldV, Value *NewV); - // END WARNING!! }; @@ -502,14 +496,6 @@ public: static inline bool classof(const Value *V) { return isa(V) && classof(cast(V)); } - -public: - // WARNING: Only to be used by Bytecode & Assembly Parsers! USER CODE SHOULD - // NOT USE THIS!! - // Returns the number of uses of OldV that were replaced. - virtual unsigned mutateReferences(Value* OldV, Value *NewV); - // END WARNING!! }; - #endif diff --git a/include/llvm/Module.h b/include/llvm/Module.h index b34c06b9f57..2b8c0ab5d0e 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -59,7 +59,8 @@ private: SymbolTable *SymTab; // Accessor for the underlying GlobalValRefMap... only through the - // ConstantPointerRef class... + // Constant class... + friend class Constant; friend class ConstantPointerRef; void mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV); ConstantPointerRef *getConstantPointerRef(GlobalValue *GV); diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 8464c437fcb..3887e33274a 100644 --- a/lib/VMCore/Constants.cpp +++ b/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(this)) { + GlobalValue *NewGV = cast(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(NewV); - getValue()->getParent()->mutateConstantPointerRef(getValue(), NewGV); - Operands[0] = NewGV; - return 1; -} - - -//---- ConstantPointerExpr::mutateReferences() implementation... -// -unsigned ConstantExpr::mutateReferences(Value* OldV, Value *NewV) { - unsigned NumReplaced = 0; - Constant *NewC = cast(NewV); - for (unsigned i = 0, N = getNumOperands(); i != N; ++i) - if (Operands[i] == OldV) { - ++NumReplaced; - Operands[i] = NewC; - } - return NumReplaced; + assert(OldGV == OldV && "Cannot mutate old value if I'm not using it!"); + + OldGV->getParent()->mutateConstantPointerRef(OldGV, NewGV); + Operands[0] = NewGV; + return 1; + } else { + Constant *NewC = cast(NewV); + unsigned NumReplaced = 0; + for (unsigned i = 0, N = getNumOperands(); i != N; ++i) + if (Operands[i] == OldV) { + ++NumReplaced; + Operands[i] = NewC; + } + return NumReplaced; + } }