[LLVMdev] IR code modification/transformation

Duncan Sands baldrick at free.fr
Thu Aug 11 03:49:16 PDT 2011


Hi Rinaldini Julien,

> I'm iterating over a basicblock and I can get an instruction and print it.
> Now, I want to iterate over the instruction and be able to modify the values of the instruction.
>
> For example, if my instruction is an add "<result>  = add i32 4, %var" I want to transform it in a sub "<result>  = sub i32 4, %var".

create the new sub instruction (insert it before the add), and do:
   AddInst->replaceAllUsesWith(SubInst);
You can then erase the add instruction.

Ciao, Duncan.



More information about the llvm-dev mailing list