Tuesday 15 April 2014

Incrementing a variable in LLVM IR -



Incrementing a variable in LLVM IR -

can help me in incrementing value of variable suppose 5 in llvm ir llvm pass. instruction nowadays want increment

%1 = load i32* %k, align 4 %inc = add together nsw i32 %1, 1 store i32 %inc, i32* %k, align 4

in place of 1 in %inc(add) instruction how replace 5.

i tried identifying load instruction by

if(loadinst *ld=dyn_cast<loadinst>instruction)

and

value *five = constantint::get(type::getint32ty(context), 5);

and replacing add together instruction new instruction

instruction *in=binaryoperator::create(instruction::add,ld,five,"inc",some instruction);

i tried casting ld instruction value also, didn't work.

suppose i instruction iterator like

if(i->getopcode()== instruction::add) i->setoperand(1,val *)

llvm

No comments:

Post a Comment