[LLVMdev] access array problem
Tan Guangming
guangming.tan at gmail.com
Tue May 17 18:39:33 PDT 2011
Hi,
I want to access an array in my instrumentation code. For example:
GlobalVariable:
int *counter; //counter the number of load/store operations in run-time
int *counterArray; //record the load/store addresses
//increase the counter if a load/store is performed
std::vector<Constant *>index(2);
index[0] = Constant::getNullvalue(Type:getInt32Ty(Context));
index[1] = Constant::get(Type::getInt32Ty(Context), 0);
Constant *ElementPtr = ConstantExpr::getGetElementPtr(counter,
&index[0], index.size());
Value *oldcounter = new LoadInst(ElementPtr, "oldcounter", InsertPos);
Value *newcounter = BinaryOperator::Create(Instruction::Add,
oldcounter, ConstantInt::get(Type::getInt64Ty(Context), 1),
"newcounter", InsertPos);
new StoreInst(newcounter, ElmentPtr, InserPos);
//store the memory address to counterArray[oldcounter]
std::vector<Constant*> indexC(2);
indexC[0] = Constant::getNullvalue(Type:getInt32Ty(Context));
indexC[1] = dync_cast(llvm::ConstantInt>(oldcounter);
Constant *ElmentPtr = ConstantExpr::getGetElementPtr(counterArray,
&indexC[0], indexC.size());
......// other codes
Unfortunately, the oldcounter of Value type can not be cast to
ConstantInt, dync_cast returns NULL.
Is there any way to retrieve the integer value from oldcounter?
Thanks!
--
Guangming Tan
More information about the llvm-dev
mailing list