<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><blockquote type="cite" style="font-family: monospace; ">Instruction::insertBefore? Or if you prefer, you can mess with the<br></blockquote><blockquote type="cite" style="font-family: monospace; ">result of BasicBlock::getInstList() directly.<br></blockquote><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">There it is! I was looking for an equivalent to Instruction::insertBefore inside BasicBlock. (Something along the lines of BasicBlock::appendInstruction.)</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; "><br></span><blockquote type="cite" style="font-family: monospace; ">You can cast your pointer to an integer, create an LLVM integer<br></blockquote><blockquote type="cite" style="font-family: monospace; ">constant, and create a constant cast from that to the relevant pointer<br></blockquote><blockquote type="cite" style="font-family: monospace; ">type. Or, you can add an arbitrarily-named Function to the module,<br></blockquote><blockquote type="cite" style="font-family: monospace; ">and map it to the appropriate address with<br></blockquote><blockquote type="cite" style="font-family: monospace; ">ExecutionEngine::addGlobalMapping. Whichever is more convenient...<br></blockquote><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">AddGlobalMapping seems like a better way to go.</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; "><br></span><blockquote type="cite" style="font-family: monospace; ">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.<br></blockquote><blockquote type="cite" style="font-family: monospace; "><br></blockquote><blockquote type="cite" style="font-family: monospace; ">That said, I *strongly* encourage you to use IRBuilder to create instructions sequentially rather than trying to place them all yourself.<br></blockquote><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">At first it scared me a little, but the more I think about it, the more it becomes obvious that the order in which instructions are generated should be about the same as the order in which they're executed.</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">Thanks for your help!</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">Félix Cloutier</span></body></html>