Search code examples
cllvmintermediate-code

Insert the getelementptr instruction


I want to insert the getelementpr instruction in my code, like the one shown below.

%i1 = getelementptr inbounds [16 x i64]* @Counters, i64 0, i64 %8

How can I insert that? I can insert load and store instructions by using the constructors of LoadInst and StoreInst classes, but the constructor for GetElementPtrInst is declared private, so can't use it. So, my question is how to add this instruction from my code for an LLVM pass.


Solution

  • According to http://llvm.org/doxygen/classllvm_1_1GetElementPtrInst.html you can create the instruction via factory-like GetElementPtrInst::Create() method. Alternatively, you can use IRBuilder to do all low-level stuff for you.