[LLVMdev] Hello World

John McCall rjmccall at apple.com
Thu Jun 24 15:29:30 PDT 2010


On Jun 24, 2010, at 12:16 PM, FĂ©lix Cloutier wrote:
> First, the way we create instructions confuses me a little. My best experience with factory-like patterns is the JavaScript DOM interface, where you'd do like document.createElement, mess with the new element, then put it back somewhere doing node.appendChild. However, seeing the results from llvm2cpp, it looks like simply creating an instruction is enough to put it somewhere (at the end of the specified basic block, I suppose) unless no parameter is specified. Skimming through the classes reference, I see no 'obvious' way to add an existing "orphan" instruction to a block. What would it be?

The IRBuilder class is more than just a factory;  it's actually designed to write instructions sequentially into the current block.  However, if you don't give it an insertion point, it will just create the instructions as orphans, and you can land them in basic blocks with the APIs that Eli mentioned.

That said, I *strongly* encourage you to use IRBuilder to create instructions sequentially rather than trying to place them all yourself.

John.



More information about the llvm-dev mailing list