ConstantInt is a factory, isn't it? The class has a get method to create a new constant:
00069 static Constant *get(Type *Ty, uint64_t V, bool isSigned = false);
So, I think you cannot modify the existing ConstantInt. If you want to change the IR, you should try to change the pointer to the argument (change the IR itself, but not a permanent object).
Maybe you want something like this (remember, I have no experience with LLVM, and I'm pretty sure the example is wrong).
Instruction *I = ; if (I->getOpcode() == Instruction::Add) { Value *oldvalue = I->getOperand(0); Value *newvalue = ConstantInt::get(oldValue->getType(), 0x1234); I->setOperand(0, newvalue); }
There is a solution for βmodifyingβ one constant (increment and decrement are shown ):
/// AddOne - Add one to a ConstantInt. static Constant *AddOne(Constant *C) { return ConstantExpr::getAdd(C, ConstantInt::get(C->getType(), 1)); } /// SubOne - Subtract one from a ConstantInt. static Constant *SubOne(ConstantInt *C) { return ConstantInt::get(C->getContext(), C->getValue()-1); }
PS, Constant.h has an important comment in begging to create and not delete constants http://llvm.org/docs/doxygen/html/Constant_8h_source.html
00035 /// Note that Constants are immutable (once created they never change) 00036 /// and are fully shared by structural equivalence. This means that two 00037 /// structurally equivalent constants will always have the same address. 00038 /// Constants are created on demand as needed and never deleted: thus clients 00039 /// don't have to worry about the lifetime of the objects. 00040 /// @brief LLVM Constant Representation
source share