[LLVMdev] The question about how to refer an element in a pointer array by a dynamic index by IR

Michael.Kang blackfin.kang at gmail.com
Wed Jun 30 23:45:41 PDT 2010

Now I am trying to use LLVM to write a simulator and take LLVM as IR
to dynamic translate machine code,
I encounter some issues when try to write some IR to express writting
a value to the reigster.
The situation is described as the following description.

write_reg is my function for writing "v" to the register indicated by
"index".  ptr_gpr is the struct pointer for my general register file.

write_reg(cpu_t *cpu, uint32_t index, Value *v,BasicBlock *bb ){
       Value **regs = cpu->ptr_gpr;

If index do not need to do any runtime calculation, I can write the
following sentence to fulfil my requirement.

 new StoreInst(v, regs[index], bb);

But if I need to do some runtime calculation for index such as
modular. How to deal that?
1. Use IR to calculate index by some
"BinaryOperator::Create(Instruction::Add, a, b, "", bb)" sentences.
2. Use the above index to refer the register in "regs".
Should I use GEP in second step ? And how to use it?



More information about the llvm-dev mailing list