Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LLVM IRBuilder: set insert point after a particular instruction

Tags:

llvm

The LLVM IRBuilder function SetInsertPoint (Instruction *I) specifies that created instructions should be inserted before the specified instruction.

How can the insert point be set after a particular instruction? I can't find a function that can do it directly.

like image 496
Prateek Avatar asked Oct 25 '15 07:10

Prateek


1 Answers

The insert point can't be set to be after a given instruction -- instead, you should set it to be before the next instruction.

To get a pointer to the next instruction, you can use the getNextNode() method which is available on Instruction:

Builder.SetInsertPoint(I->getNextNode());

or you could turn the instruction pointer into an iterator and advance it:

BasicBlock::iterator it(I);
it++;
Builder.SetInsertPoint(it);
like image 94
Ismail Badawi Avatar answered Oct 23 '22 21:10

Ismail Badawi