// 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!!
};
static inline bool classof(const Value *V) {
return isa<ConstantPointer>(V) && classof(cast<ConstantPointer>(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!!
};
static inline bool classof(const Value *V) {
return isa<Constant>(V) && classof(cast<Constant>(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
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);
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;
+ }
}